⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netmodel.cc

📁 NS2网络仿真软件是目前最为流行的网络仿真模拟软件
💻 CC
📖 第 1 页 / 共 5 页
字号:
      pno = q->paint();      delete q;    }    /*     * Compute the point at which the dropped packet disappears.     * Let's just make this sufficiently far below the lowest     * thing on the screen.     *     * Watch out for topologies that have all their nodes lined     * up horizontally. In this case, nymin_ == nymax_ == 0.     * Set the bottom to -0.028. This was chosen empirically.     * The nam display was set to the maximum size and the lowest     * position on the display was around -0.028.     */    float bottom;    if (nymin_ - nymax_ < 0.01) {      bottom = nymin_ - 20.0 * ehn->edge->PacketHeight() ;    } else {      bottom = nymin_ - (nymax_ - nymin_);    }        // The drop animation is taken care of by the drop class    Drop * d = new Drop(x, y, bottom, 4 * ehn->edge->PacketHeight(),                        e.time, e.offset, e.pe.pkt);    d->paint(pno);    d->insert(&animations_);    check_monitors(d);    return;  } else {    // direction is BACKWARDS - need to create the packet    Lan *lan = lookupLan(e.pe.src);    if (lan != NULL) {       // We need to remove drop status in lans      lan->remove_drop(e);      //fprintf(stderr, "lan dropped packet %d is removed on lan link %d->%d\n",      //                e.pe.pkt.id, e.pe.src, e.pe.dst);      return;    }  }}//----------------------------------------------------------------------------// Node *// NetModel::addNode(const TraceEvent &e)//   - adds a node to the netmodel getting configuration info from the fields//     in the TraceEvent//----------------------------------------------------------------------------Node *NetModel::addNode(const TraceEvent &e)  {  Node * n = NULL;  char src[32];  if (e.tt == 'n') {    sprintf(src, "%d", e.ne.src);    n = lookupNode(e.ne.src);    // And remove them to be replaced by this node    if (n != NULL) {      fprintf(stderr, "Skipping duplicate node %s definition. \n", src);      //removeNode(n);    }    // Determine Node Type    if (!strncmp(e.ne.mark.shape, "circle",6)) {      n = new CircleNode(src, e.ne.size);    } else if (!strncmp(e.ne.mark.shape, "box", 3) ||                !strncmp(e.ne.mark.shape, "square", 6)) {      n = new BoxNode(src, e.ne.size);    } else if (!strncmp(e.ne.mark.shape, "hexagon",7)) {       n = new HexagonNode(src, e.ne.size);    } else {      return NULL;    }    // Check for wireless node    if (e.ne.wireless) {      n->wireless_ = true;      //fprintf(stderr, "We have wireless nodes :-) !!!\n");    }    // Node Address    //  May need to check for no address passed in    n->setaddr(e.ne.node.addr);    addAddress(n->num(), e.ne.node.addr);    // Node Color    n->init_color(e.ne.node.color);    n->lcolor(e.ne.node.lcolor);    // dlabel initilization    n->dlabel(e.ne.node.dlabel);    // Set X,Y cordinates    n->place(e.ne.x, e.ne.y);        // Add Node to drawables list    n->next_ = nodes_;    nodes_ = n;    n->Animation::insert(&drawables_);    // Set Packet size to be running average of the last 5 nodes (25% of node size)    packet_size_ = (4.0 * packet_size_ + e.ne.size*0.25)/5.0;  }  return (n);}//----------------------------------------------------------------------------// Edge * // NetModel::addEdge(int argc, const char *const *argv)////  <net> link <src> <dst> <bandwidth> <delay> <angle>//  Create a link/edge between the specified source//  and destination. Add it to this NetModel's list//  of drawables and to the source's list of links.//----------------------------------------------------------------------------Edge * NetModel::addEdge(int argc, const char *const *argv) {  Node * src, * dst;  Edge * edge = NULL;  double bandwidth, delay, length, angle;  if (strcmp(argv[1], "link") == 0) {    src = lookupNode(atoi(argv[2]));    dst = lookupNode(atoi(argv[3]));        if (src && dst) {      bandwidth = atof(argv[4]);      delay = atof(argv[5]);      length = atof(argv[6]);      angle = atof(argv[7]);                              //enlarge link if the topology is a mixture of      //wired and wireless network      if (wireless_) {        length = delay * WIRELESS_SCALE ;      }      edge = new Edge(src, dst, packet_size_, bandwidth, delay, length, angle, wireless_);      edge->init_color("black");      enterEdge(edge);      edge->Animation::insert(&drawables_);      src->add_link(edge);    }  }  return edge;}//----------------------------------------------------------------------------////----------------------------------------------------------------------------Edge * NetModel::addEdge(int src_id, int dst_id, const TraceEvent &e) {  Node *src, *dst;  Edge * edge = NULL;  double bandwidth, delay, length, angle;  if (e.tt == 'l') {    src = lookupNode(src_id);    dst = lookupNode(dst_id);        if (src && dst) {      bandwidth = e.le.link.rate;      delay = e.le.link.delay;      length = e.le.link.length;      angle = e.le.link.angle;                              //enlarge link if the topology is a mixture of      //wired and wireless network      if (wireless_) {        length = delay * WIRELESS_SCALE ;      }      edge = new Edge(src, dst, packet_size_, bandwidth, delay, length, angle, wireless_);      edge->init_color("black");      enterEdge(edge);      edge->Animation::insert(&drawables_);      src->add_link(edge);    }  }  return edge;}void NetModel::addView(NetView* p){	p->next_ = views_;	views_ = p;}//----------------------------------------------------------------------// Node * // NetModel::lookupNode(int nn) const//----------------------------------------------------------------------Node *NetModel::lookupNode(int nn) const {  for (Node* n = nodes_; n != 0; n = n->next_)    if (n->num() == nn)      return (n);  return NULL;}//----------------------------------------------------------------------// Edge *// NetModel::lookupEdge(int source, int destination) const//----------------------------------------------------------------------Edge *NetModel::lookupEdge(int source, int destination) const {	EdgeHashNode * edge_hash_node;	edge_hash_node = lookupEdgeHashNode(source, destination);	return edge_hash_node->edge;}void NetModel::removeNode(Node *n) {	Node *p, *q;	// Remove node n from nodes_ list, then delete it	for (p = nodes_; p != 0; q = p, p = p->next_)		if (p == n)			break;	if (p == nodes_)		nodes_ = p->next_;	else		q->next_ = p->next_;	delete p;}Agent *NetModel::lookupAgent(int id) const{	for (Node* n = nodes_; n != 0; n = n->next_) 		for(Agent* a= n->agents(); a != 0; a = a->next_) 			if (a->number() == id) 				return (a);	return (0); }Lan *NetModel::lookupLan(int nn) const{	for (Lan* l = lans_; l != 0; l = l->next_)		if (l->num() == nn)			return (l);	/* XXX */	//fprintf(stderr, "nam: no such lan %d\n", nn);	//exit(1);	return (0);// make visual c++ happy}Packet *NetModel::newPacket(PacketAttr &pkt, Edge *e, double time){  /*this is called when we get a triggered event such as a packet    getting duplicated within a LAN*/  Packet *p = new Packet(e, pkt, time, e->txtime(pkt.size), 0);  p->insert(&animations_);  p->paint(paint_[pkt.attr & paintMask_]);  check_monitors(p);  return p;}Packet *NetModel::lookupPacket(int src, int dst, int id) const{  EdgeHashNode *h = lookupEdgeHashNode(src, dst);  if (h == 0)    return NULL;  int ctr=0;  for (Packet *p=h->edge->packets(); p!=NULL; p=p->next())    {#define PARANOID#ifdef PARANOID      ctr++;      if (ctr>h->edge->no_of_packets()) abort();#endif      if (p->id() == id)	return p;    }  /*have to fail silent or we can't cope with link drops when doing settime*/  return 0;}/* Do not delete groups, because they are not explicitly deleted */int NetModel::add_group(Group *grp){	int newEntry = 1;	Tcl_HashEntry *he = Tcl_CreateHashEntry(grpHash_,	                                        (const char *)grp->addr(), 	                                        &newEntry);	if (he == NULL)		return -1;	if (newEntry) {		Tcl_SetHashValue(he, (ClientData)grp);		nGroup_++;	}	return 0;}Group* NetModel::lookupGroup(unsigned int addr){	Tcl_HashEntry *he = Tcl_FindHashEntry(grpHash_, (const char *)addr);	if (he == NULL)		return NULL;	return (Group *)Tcl_GetHashValue(he);}// Remove a view from the views link, but not delete itvoid NetModel::remove_view(View *v){	View *p, *q;	p = q = views_;	if (p == v) {		views_ = p->next_;		return;	}	while (p != NULL) {		q = p;		p = p->next_;		if (p == v) {			q->next_ = p->next_;			return;		}	}}//----------------------------------------------------------------------// int// NetModel::command(int argc, const char *const *argv)//   - Parses tcl commands (hook to enter c++ code from tcl)//----------------------------------------------------------------------int NetModel::command(int argc, const char *const *argv) {	Tcl& tcl = Tcl::instance();	int i;	Node * node;	double time;		if (argc == 2) {		if (strcmp(argv[1], "layout") == 0) {			/*			 * <net> layout			 * Compute reasonable defaults for missing node or edge			 * sizes based on the maximum link delay. Lay out the			 * nodes and edges as specified in the layout file.			 */			scale_estimate();			placeEverything();			return (TCL_OK);		}		if (strcmp(argv[1], "showtrees") == 0) {			/*			 * <net> showtrees			 */			color_subtrees();			for (View* p = views_; p != 0; p = p->next_) {				p->draw();			}			return (TCL_OK);		}		if (strcmp(argv[1],"resetFilter")==0) {		        resetf_ = 1 ;	                selectedSrc_ = -1 ;		        selectedDst_ = -1 ;		        selectedFid_ = -1 ;	                colorSrc_ = -1 ;		        colorDst_ = -1 ;		        colorFid_ = -1 ;	                hideSrc_ = -1 ;		        hideDst_ = -1 ;		        hideFid_ = -1 ;	                for (i = 0; i < PTYPELEN; ++i) {	                   selectedTraffic_[i] = '\0' ;	                   colorTraffic_[i] = '\0' ;	                   hideTraffic_[i] = '\0' ;                        }			return (TCL_OK);		}	} else if (argc == 3) {		if (strcmp(argv[1], "incr-nodesize") == 0) {			/*			 * <net> incr-nodesize <factor>			 */			node_sizefac_ *= atof(argv[2]);			for (Node *n = nodes_; n != 0; n = n->next_)				for (Edge *e=n->links(); e != 0; e = e->next_)					e->unmark();			scale_estimate();			placeEverything();			for (View *p = views_; p != 0; p = p->next_)				if ((p->width() > 0) && (p->height() > 0)) {					p->redrawModel();					p->draw();				}			return (TCL_OK);		}		if (strcmp(argv[1], "decr-nodesize") == 0) {			node_sizefac_ /= atof(argv[2]);			for (Node *n = nodes_; n != 0; n = n->next_)				for (Edge *e=n->links(); e != 0; e = e->next_)					e->unmark();			scale_estimate();			placeEverything();			for (View *p = views_; p != 0; p = p->next_)				if ((p->width() > 0) && (p->height() > 0)) {					p->redrawModel();					p->draw();				}			return(TCL_OK);		}		if (strcmp(argv[1], "updateNodePositions") == 0) {			time = strtod(argv[2], NULL);			for (node = nodes_; node; node = node->next_) {				node->updatePositionAt(time);				moveNode(node);  // This updates the links and agents connected to the node			}			return TCL_OK;		}		if (strcmp(argv[1], "view") == 0) {			/*			 * <net> view <viewName>			 * Create the window for the network layout/topology.			 * Used for nam editor			 */			EditView *v = new EditView(argv[2], this, 300, 700);			v->next_ = views_;			views_ = v;			return (TCL_OK);		}		if (strcmp(argv[1], "psview") == 0) {			/*			 * <net> PSView <fileName>			 * Print the topology to a file			 */			PSView *v = new PSView(argv[2], this);			v->render();			delete(v);			return (TCL_OK);		}		if (strcmp(argv[1], "testview") == 0) {			/*			 * Added for nam validation test 			 */			TestView *v = new TestView(argv[2], this);			v->render();			delete(v);			return (TCL_OK);		}		if (strcmp(argv[1], "editview") == 0) {			/*			 * <net> editview <viewname>			 */			EditView *v = new EditView(argv[2], this);			v->next_ = views_;			views_ = v;			return (TCL_OK);		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -