File: trace.h

package info (click to toggle)
nam 1.15-5
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 29,240 kB
  • sloc: cpp: 17,338; tcl: 10,655; sh: 2,997; ansic: 1,252; makefile: 139; perl: 66
file content (353 lines) | stat: -rw-r--r-- 7,987 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
/*
 * Copyright (c) 1991,1993 Regents of the University of California.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the Computer Systems
 *	Engineering Group at Lawrence Berkeley Laboratory.
 * 4. Neither the name of the University nor of the Laboratory may be used
 *    to endorse or promote products derived from this software without
 *    specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * @(#) $Header: /cvsroot/nsnam/nam-1/trace.h,v 1.38 2003/01/28 03:22:38 buchheim Exp $ (LBL)
 */

#ifndef nam_trace_h
#define nam_trace_h

#include "tclcl.h"
#include "animator.h"
#include "parser.h"
class NamStream;
//class ParseTable;

#define TRACE_LINE_MAXLEN 256

/*
 * 'packet' events (hop, enqueue, dequeue & drop) all have the same
 * format:  the src & dst node and a description of the packet.
 */

#define PTYPELEN 16
#define CONVLEN 32

#define FORWARDS 1
#define BACKWARDS -1

#define TIME_EOF -1
#define TIME_BOF -2

struct PacketAttr {
	int size;
	int attr;
  int id;
	int energy ;
	int esrc ;
	int edst ;
	double wBcastDuration;
	double wBcastRadius;
	char type[PTYPELEN];
	char wtype[PTYPELEN]; //AGT,RTR or MAC
	char convid[CONVLEN];
};

struct PacketEvent {
	int src;
	int dst;
	PacketAttr pkt;
	PacketAttr namgraph_flags; // for ignoring namgraph flags
};

struct VarEvent {
	/* Var event stuff */
	int str;
	//char * str;
};

/*XXX don't really want these fixed size*/
#define MAXNAME 20
#define MAXVALUE 256

struct AgentAttr {
  char name[MAXNAME];
  int expired;
};
  
struct AgentEvent {
  /*Agent event stuff*/
  int src;
  /*dst is only set if it's an interface agent*/
  int dst;
  AgentAttr agent;
};

struct FeatureAttr {
  char name[MAXNAME];
  char value[MAXVALUE];
  char oldvalue[MAXVALUE];
  char agent[MAXNAME];
  int expired;
  char type;
};

struct FeatureEvent {
  int src;
  /*XXX not sure we need dst here*/
  int dst;
  FeatureAttr feature;
};
  
struct LinkAttr {
  double rate;              // Link Bandwith (Rate)
  double delay;             // Link Delay
  double length;            // length
  double angle;             // orientation

  char state[MAXVALUE];
  char color[MAXNAME];
  char oldColor[MAXNAME];
  char dlabel[MAXNAME];     // label beneath a link
  char odlabel[MAXNAME];    // old dlabel
  char direction[MAXNAME];  // direction of the label 
  char odirection[MAXNAME]; 
  char dcolor[MAXNAME];      // label color
  char odcolor[MAXNAME];
};

struct LinkEvent {
  int src;
  int dst;
  LinkAttr link;
};

struct LanLinkEvent {
  int src;
  int dst;
  double angle;
};

struct LayoutLanEvent {
	char name[MAXVALUE];
  double rate;
  double delay;
  double angle;
};

struct NodeMarkAttr {
	char name[MAXVALUE];
	char shape[MAXNAME];
	char color[MAXNAME];
	int expired;
};

struct NodeMarkEvent {
	int src;
	NodeMarkAttr mark;
};

struct NodeAttr {
int addr;
  char state[MAXNAME];
  char dlabel[MAXNAME];      // label beneath a node
  char odlabel[MAXNAME];     // old dlabel
  char color[MAXNAME];
  char oldColor[MAXNAME];
  char direction[MAXNAME];   // direction of the label 
  char odirection[MAXNAME];
  char lcolor[MAXNAME];      // inside label color
  char olcolor[MAXNAME];
  char dcolor[MAXNAME];      // label color
  char odcolor[MAXNAME];
};

struct NodeEvent {
  int src;
  /*dst is only set if it's an interface event*/
  int dst;
  NodeAttr node;
  NodeMarkAttr mark;  // Added for dynamic nodes
  double x;
  double y;
  double z;  // Not fully implemented
  double x_vel_;
  double y_vel_;
  double stoptime;
  double size;
  int wireless;
};

const int GROUP_EVENT_JOIN = 1;
const int GROUP_EVENT_LEAVE = 2;

struct GroupAttr {
	char name[MAXNAME];
	int flag; 	/* 1: join, 2: leave, 3: create new group */
	int mbr;
};

struct GroupEvent {
	int src;	/* group address */
	GroupAttr grp;
};

struct RouteAttr {
  int expired;
  int neg;
  double timeout;
  int pktsrc;
  int group;
  char mode[MAXVALUE];
};

struct RouteEvent {
  int src;
  int dst;
  RouteAttr route;
};

struct HierarchicalAddressEvent {
  int hierarchy;
  int portshift;
  char portmask[MAXNAME];
  int multicast_shift;
  int multicast_mask;
  
  int nodeshift;
  int nodemask;
};

struct ColorEvent {
  int id;
  char color[MAXNAME];
};

struct QueueEvent {
  int src;
  int dst;
  double angle;
};

struct WirelessEvent {
  int x;
  int y;
};

struct TrafficSourceEvent {
  int id;
  int agent_id; 
};

struct TraceEvent {
    double time;		/* event time */
    long offset;		/* XXX trace file offset */
    int lineno;	  	/* XXX trace file line no. */
    int tt;			    /* type: h,+,-,d */
    union {
      PacketEvent pe;
      VarEvent ve;
      AgentEvent ae;
      FeatureEvent fe;
      LinkEvent le;
      LanLinkEvent lle;
      LayoutLanEvent layoutle;
      NodeEvent ne;
      RouteEvent re;
      NodeMarkEvent me;
      GroupEvent ge;
      HierarchicalAddressEvent hae;
      ColorEvent ce;
      QueueEvent qe;
      WirelessEvent we;
    };

    char version[MAXNAME];
    int dummy;  // Used for variables that are discarded
    char dummy_str[MAXNAME];  // Used for variables that are discarded
    bool valid;
    char image[TRACE_LINE_MAXLEN];
};


class TraceHandler : public TclObject {
public:
  TraceHandler() : nam_(0) {}
  TraceHandler(const char *animator) {
    nam_ = (NetworkAnimator *)TclObject::lookup(animator);
  }
  virtual void update(double) = 0;
  virtual void reset(double) = 0;
  virtual void handle(const TraceEvent&, double now, int direction) = 0;
  inline NetworkAnimator* nam() { return nam_; }
protected:
  NetworkAnimator *nam_;
};


struct TraceHandlerList {
	TraceHandler* th;
	TraceHandlerList* next;
};


class Trace : public TclObject {
 public:
	Trace(const char * fname, const char * animator);
	~Trace();
	int command(int argc, const char*const* argv);
	int ReadEvent(double, TraceEvent&);
	void scan();
	void rewind(long);
	int nextLine();
	double nextTime() { return (pending_.time); }
	double Maxtime() { return (maxtime_); }
	double Mintime() { return (mintime_); }
	int valid();
	NetworkAnimator* nam() { return nam_; }

	Trace* next_;
 private:
	void addHandler(TraceHandler*);
	void settime(double now, int timeSliderClicked);
	void findLastLine();

	TraceHandlerList* handlers_;
	int lineno_;
	double maxtime_;
	double mintime_;
	double now_;
	NamStream *nam_stream_;
	int direction_;  //  1 = Forwards, -1 = Backwards
	double last_event_time_; // Used for reporting trace syntax timing errors
	TraceEvent pending_;
	char fileName_[256];
	NetworkAnimator * nam_;

	int skipahead_mode_; 
	int count_;
  
	ParseTable * parse_table_;
};

#endif