File: node.h

package info (click to toggle)
nam 1.15-3.1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 29,092 kB
  • ctags: 2,746
  • sloc: cpp: 17,338; tcl: 10,655; sh: 2,997; ansic: 1,252; makefile: 139; perl: 66
file content (323 lines) | stat: -rw-r--r-- 9,614 bytes parent folder | download | duplicates (8)
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
/*
 * 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/node.h,v 1.40 2006/09/28 06:25:03 tom_henderson Exp $ (LBL)
 */

#ifndef nam_node_h
#define nam_node_h

class Queue;
class Edge;
class Agent;
class Route;
class Monitor;
class NetView;
//class PSView;
class EditView;
class Lan;

#include <math.h>
#include <string.h>
#include <tcl.h>
#include <tclcl.h>

#include "animation.h"

struct NodeMark {
	NodeMark() { name = NULL; color = 0; next = 0; }
	NodeMark(char *str) {
		name = new char[strlen(str)+1];
		strcpy(name, str);
		color = 0;
		next = 0;
	}
	~NodeMark() { delete []name; }

	char *name;
	int color;
	int shape;
	struct NodeMark *next;
};

const float NodeMarkScale = 0.15;
const int NodeMarkCircle = 0;
const int NodeMarkSquare = 4;
const int NodeMarkHexagon = 6;

class MovementElement {
public:
	MovementElement(double time, double x, double y);
	MovementElement(double time, double x, double y,
	                double x_velocity, double y_velocity, double duration);
	~MovementElement();

	bool contains(double time, double duration);  // returns true if time >= time_ 
	                                              // and < time_ + duration_

	MovementElement * next_;
	double time_;
	double x_, y_;
	double x_velocity_, y_velocity_;
	double duration_;
};

// This is a list to keep track of node movements
class MovementList {
public:
	MovementList();
	~MovementList();

	void clear();
	MovementElement * head() {return head_;}

	MovementElement * add(double x, double y, double time);
	void remove(double time);

	void setList(char * list_string);

	int getListString(char* buffer, int buffer_size);
	bool isMoving(double time);
	double lastStopMovement();

	void getPositionAt(double time, double & x, double & y);

private:
	MovementElement * head_;
	int size_;
};




class Node : public Animation, public TclObject {
public:
	virtual ~Node();

	virtual int classid() const { return ClassNodeID; }
	inline const char* name() const { return (label_); }
	inline char* ncolor() const { return (ncolor_); }
	inline int num() const { return (nn_); }
	inline int number() const { return (nn_); }
	inline int addr() const { return (addr_); }
	inline double size() const { return (size_); }
	inline float nsize() const { return (nsize_); }
	inline Agent* agents() const { return (agents_); }
	virtual void size(double s);
	virtual void reset(double);
	inline double x() const { return (x_); }
	inline double y() const { return (y_); }
	virtual double x(Edge *) const { return (x_); }
	virtual double y(Edge *) const { return (y_); }
	inline double dx() const { return (dx_); }
	inline double dy() const { return (dy_); }
	void displace(double dx, double dy) {
		dx_ = dx; dy_ = dy;
	}
	virtual void move(EditView *v, float dwx, float dwy);
	void updatePositionAt(double time);
	virtual float distance(float x, float y) const;
	inline double distance(Node &n) const { 
		return sqrt((x_-n.x_)*(x_-n.x_) + (y_-n.y_)*(y_-n.y_));
	}
	inline double angle(Node &n) const {
		return atan2(n.y_-y_, n.x_-x_);
	}

	void setstart(double t) { starttime_ = t;}
	void setend(double t) { endtime_ = t;}
	void setvelocity(double x, double y) { x_vel_=x; y_vel_=y;}
	void placeorig(double x, double y) { xorig_=x; yorig_=y;}

	MovementElement * addMovementDestination(double world_x, 
	                                         double world_y,
	                                         double time);
	void removeMovementDestination(double time);
	int getMovementTimeList(char * buffer, int buffer_size);
	double getMaximumX();
	double getMaximumY();

	void setaddr(int addr) { addr_ = addr; }
	virtual void place(double x, double y);
	void label(const char* name, int anchor);
	void dlabel(const char* name);
	void lcolor(const char* name);
	void dcolor(const char* name);
	void ncolor(const char* name);
	void direction(const char* name);
	inline int anchor() const { return (anchor_); }
	inline void anchor(int v) { anchor_ = v; }
	void add_link(Edge*);
	void delete_link(Edge*);
	void add_agent(Agent*);
	void add_route(Route*);
	void delete_route(Route*);
	void place_route(Route*);
	void place_all_routes();
	void clear_routes();
	void delete_agent(Agent*);
	Route *find_route(Edge *e, int group, int pktsrc, int oif) const;
	Agent *find_agent(char *name) const;
	Edge *find_edge(int dst) const;
	int no_of_routes(Edge *e) const;
	virtual int inside(double t, float px, float py) const { 
		return Animation::inside(t, px, py);
	}
	const char* info() const;
	const char* property();
	const char* getname() const;
	void monitor(Monitor *m, double now, char *result, int len);
	inline Edge* links() const { return (links_); }
	inline int marked() const { return (mark_); }
	inline void mark(int v) { mark_ = v; }
	inline int mass() const { return mass_; }
	inline void mass(int m) {mass_=m;}
	virtual char *style() {return 0;}
	virtual void update(double now);

	void init_color(const char *clr);
	void set_down(char *color);
	void set_up();
	inline int isdown() const { return (state_ == DOWN); }

	NodeMark* find_mark(char *name);
	int add_mark(char *name, char *color, char *shape);
	void delete_mark(char *name);
	virtual void arrive_packet(Packet *, Edge *, double) {/*do nothing*/}
	virtual void delete_packet(Packet *) {/*do nothing*/}
	int save(FILE *file);
	int writeNsScript(FILE *file);
	int writeNsMovement(FILE *file);

	Node* next_;
	Queue *queue_;
	Queue* queue() { return queue_; }
	void add_sess_queue(unsigned int grp, Queue *q);
	char * getTclScript();
	char * getTclScriptLabel();
	void setTclScript(const char * label, const char * script);

	int command(int argc, const char * const * argv);

protected:
	Node(const char* name, double size);
	void update_bb();
	void drawlabel(View*) const;

	int mass_; //mass used in AutoNetModel

	double size_;
	float nsize_;
	double x_, y_;
	double xorig_, yorig_;
	double x_vel_,y_vel_;
	double starttime_, endtime_;
	Edge* links_;
	Route* routes_;
	Agent* agents_;
	int anchor_;
	int mark_;
	char* label_;
	int nn_;	// Node id
	int addr_;	// Node address
	int state_;

	NodeMark *nm_;
	int nMark_;
	void draw_mark(View *) const;
	char* dlabel_;  // Label to be drawn beneath the node
	char* lcolor_;  // Inside label color
	char* dcolor_;  // label color
	char* ncolor_;  // node color
	int direction_;

	double dx_, dy_; // displacements used in AutoNetModel

	char * tcl_script_label_; // Text for tcl_script info button
	char * tcl_script_; // Tcl script to be executed when 
	                    // tcl_script info button is pressed
	MovementList movement_list;

public:
	bool wireless_; // Indicates if this is a wireless node or not;
};

class BoxNode : public Node {
public:
	BoxNode(const char* name, double size);
	virtual void size(double s);
	virtual void draw(View*, double now);
	virtual void place(double x, double y);
	char *style() {return "box";}
private:
	float x0_, y0_;
	float x1_, y1_;
};

class CircleNode : public Node {
public:
	CircleNode(const char* name, double size);
	virtual void size(double s);
	virtual void draw(View*, double now);
	char *style() {return "circle";}
private:
	float radius_;
};

class HexagonNode : public Node {
public:
	HexagonNode(const char* name, double size);
	virtual void size(double s);
	virtual void draw(View*, double now);
	virtual void place(double x, double y);
	char *style() {return "hexagon";}
private:
	float ypoly_[6];
	float xpoly_[6];
};

class VirtualNode : public Node {
public:
	VirtualNode(const char* name, Lan *lan);
	virtual void size(double s);
	virtual void draw(View*, double now);
	virtual void place(double x, double y);
	virtual void arrive_packet(Packet *p, Edge *e, double atime);
	virtual void delete_packet(Packet *p);
	virtual double x(Edge *e) const;
	virtual double y(Edge *e) const;
	char *style() {return "virtual";}
private:
	Lan *lan_;
};

#endif