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

📄 netmodel.cc

📁 NS2网络仿真软件是目前最为流行的网络仿真模拟软件
💻 CC
📖 第 1 页 / 共 5 页
字号:
	// Returns a "newed" MonState	ms = a->monitor_state();	if (ms == NULL) {		return;	}	for(m = monitors_; m != NULL; m = m->next()) {		if ((m->mon_state_ != NULL) &&				(m->mon_state_->type = ms->type)) {			switch (ms->type) {				case MON_PACKET:					if (m->mon_state_->pkt.id == ms->pkt.id) {						m->anim(a);						delete ms;					  return;					}					break;				case MON_ROUTE: 					if ((m->mon_state_->route.src == ms->route.src)&&							(m->mon_state_->route.group == ms->route.group)) {						m->anim(a);						delete ms;						return;					}					break;			}		}	}//  What happens to ms after the end of this function?  Maybe the memory leak?//	fprintf(stderr, "Reached outside of check_monitors\n");}void NetModel::delete_monitor(int monitor){  /*this version of delete_monitor is called from the GUI*/  /*given a monitor, remove it from the model's monitor list*/  Monitor *tm1, *tm2;  if (monitors_==NULL)    return;  tm1=monitors_;  tm2=monitors_;  while ((tm1!=NULL)&&(tm1->monitor_number()!=monitor))    {      tm2=tm1;      tm1=tm1->next();    }  if (tm1!=NULL)    {      tm2->next(tm1->next());      if (tm1==monitors_)	monitors_=tm1->next();      if (tm1->anim()!=NULL)	tm1->anim()->remove_monitor();      delete tm1;    }}void NetModel::delete_monitor(Monitor *m){  /*given a monitor, remove it from a node's agent list*/  Monitor *tm1, *tm2;  if (monitors_==NULL)    return;  tm1=monitors_;  tm2=monitors_;  while ((tm1!=m)&&(tm1!=NULL))    {      tm2=tm1;      tm1=tm1->next();    }  if (tm1!=NULL)    {      tm2->next(tm1->next());      if (tm1==monitors_)	monitors_=tm1->next();      tm1->anim()->remove_monitor();      delete tm1;    }}void NetModel::delete_monitor(Animation *a){  /*given a monitor, remove it from a node's agent list*/  /*this version gets called when an animation deletes itself*/  /*XXX animations sometimes get deleted when the packet changed link*/  Monitor *tm1, *tm2;  if (monitors_==NULL)    return;  tm1=monitors_;  tm2=monitors_;  while ((tm1!=NULL)&&(tm1->anim()!=a))    {      tm2=tm1;      tm1=tm1->next();    }  if (tm1!=NULL)    {      tm2->next(tm1->next());      if (tm1==monitors_)	monitors_=tm1->next();      delete tm1;    }}void NetModel::saveState(double tim){	State* state = State::instance();	StateInfo min;	min.time = 10e6;	min.offset = 0;	Animation *a, *n;	StateInfo si;	/*	 * Update the animation list first to remove any unnecessary	 * objects in the list.	 */	for (a = animations_; a != 0; a = n) {		n = a->next();		a->update(tim);	}	for (a = animations_; a != 0; a = n) {		n = a->next();		si = a->stateInfo();		if (si.time < min.time)			min = si;	}	if (min.offset)		state->set(tim, min);}//---------------------------------------------------------------------// void // NetModel::handle(const TraceEvent& e, double now, int direction)//   - Trace event handler.//---------------------------------------------------------------------void NetModel::handle(const TraceEvent& e, double now, int direction) {  QueueItem *q;  EdgeHashNode *ehn, *ehnrev;  Edge* ep;  Node *n;  //Packet *p;  Route *r;  Agent *a;  Feature *f;  float x, y;  int pno;  double txtime;  bool do_relayout = false;  if (e.time > State::instance()->next())    saveState(e.time);  switch (e.tt) {    case 'T':      // Dummy event no-op used for realtime time synchronization      break;                  case 'v': {        // 'variable' -- just execute it as a tcl command       if (nam_ == 0) {        fprintf(stderr, "Couldn't evaluate %s without animator\n",          e.image);        break;      }      const char *p = e.image + e.ve.str;      char *q = new char[strlen(nam_->name()) + strlen(p) + 2];      sprintf(q, "%s %s", nam_->name(), p);      Tcl::instance().eval(q);      delete []q;      break;    }        case 'h':      // traffic filter      if (wireless_) {        if (strcmp(e.pe.pkt.wtype,"AGT") == 0 ) return ;         if (!showData_) { // filter out data packet           if ((strcmp(e.pe.pkt.wtype,"RTR") == 0 ) ||               (strcmp(e.pe.pkt.wtype,"MAC") == 0 )) {              if (((strcmp(e.pe.pkt.type,"cbr") == 0) ||                   (strcmp(e.pe.pkt.type,"tcp") == 0) ||                   (strcmp(e.pe.pkt.type,"ack") == 0)))               return ;           }        }        if (!showRouting_){ // filter out routing packet           if (strcmp(e.pe.pkt.wtype,"RTR") == 0 ) {              if (!((strcmp(e.pe.pkt.type,"cbr") == 0)||                   (strcmp(e.pe.pkt.type,"tcp") == 0)   ||                   (strcmp(e.pe.pkt.type,"ack") == 0)))               return ;           }        }        if (!showMac_){ // filter out routing packet           if (strcmp(e.pe.pkt.wtype,"MAC") == 0 ) {              if (!((strcmp(e.pe.pkt.type,"cbr") == 0)||                   (strcmp(e.pe.pkt.type,"tcp") == 0)   ||                   (strcmp(e.pe.pkt.type,"ack") == 0)))               return ;           }        }      }      // show only packet with same chracteristics as selected packet      if (selectedSrc_ != -1) { //filter being trigger        if (e.pe.pkt.esrc != selectedSrc_ ) return ;      }      if (selectedDst_ != -1) {         if (e.pe.pkt.edst != selectedDst_ ) return ;      }      if (selectedFid_ != -1) {         if (atoi(e.pe.pkt.convid) != selectedFid_ ) return ;      }      if (selectedTraffic_[0] != '\0') {         if (strcmp(e.pe.pkt.type,selectedTraffic_) != 0 ) return ;      }      // hide packet with same chracteristics as selected packet      if (hideSrc_ != -1) { // filter being trigger        if (e.pe.pkt.esrc == hideSrc_ ) return ;      }      if (hideDst_ != -1) {         if (e.pe.pkt.edst == hideDst_ ) return ;      }      if (hideFid_ != -1) {         if (atoi(e.pe.pkt.convid) == hideFid_ ) return ;      }      if (hideTraffic_[0] != '\0') {         if (strcmp(e.pe.pkt.type,hideTraffic_) == 0 ) return ;      }      //change the packet color on the fly      if (selectedColor_ < 0 ) {        Paint *paint = Paint::instance();        selectedColor_ = paint->lookup("black",1);      }      if (colorSrc_ != -1) {         if (e.pe.pkt.esrc == colorSrc_ )           paint_[atoi(e.pe.pkt.convid)] = selectedColor_  ;      }      if (colorDst_ != -1) {         if (e.pe.pkt.edst == colorDst_ )           paint_[atoi(e.pe.pkt.convid)] = selectedColor_  ;      }      if (colorFid_ != -1) {         if (atoi(e.pe.pkt.convid) == colorFid_ )           paint_[atoi(e.pe.pkt.convid)] = selectedColor_  ;      }      if (colorTraffic_[0] != '\0') {         if (strcmp(e.pe.pkt.type,colorTraffic_) == 0 )             paint_[atoi(e.pe.pkt.convid)] = selectedColor_  ;      }      if (resetf_)          paint_[atoi(e.pe.pkt.convid)] = oldpaint_[atoi(e.pe.pkt.convid)] ;      if (direction==BACKWARDS)        break;      if (e.pe.dst == -1) { //broadcasting        //a quick hack to give fixed transmission + delay time for        //broadcasting packet        if (e.time + BPACKET_TXT_TIME < now)          break ;        n = lookupNode(e.pe.src);        BPacket * p = new BPacket(n->x(), n->y(),e.pe.pkt,                                  e.time,e.offset,direction,				  e.pe.pkt.wBcastDuration				  	? e.pe.pkt.wBcastDuration					: bcast_duration_,				  e.pe.pkt.wBcastRadius				  	? e.pe.pkt.wBcastRadius					: bcast_radius_);        p->insert(&animations_);        p->paint(paint_[e.pe.pkt.attr & paintMask_]);        check_monitors(p);        break;      }      ehn = lookupEdgeHashNode(e.pe.src, e.pe.dst);      if (ehn == 0 || (ep = ehn->edge) == 0)        return;      /*       * If the current packet will arrive at its destination       * at a later time, insert the arrival into the queue       * of animations and set its paint id (id for X graphics       * context.       */      txtime = ep->txtime(e.pe.pkt.size);      if (e.time + txtime + ep->delay() >= now) {        /* XXX */        Packet *p = new Packet(ep, e.pe.pkt, e.time,                               txtime, e.offset);        p->insert(&animations_);        p->paint(paint_[e.pe.pkt.attr & paintMask_]);        check_monitors(p);       // fprintf(stderr, "packet %d sent from %d towards %d\n",       //         e.pe.pkt.id, e.pe.src, e.pe.dst);      }      break;    case 'a':      n = lookupNode(e.ae.src);      if (n == 0)        return;      a = n->find_agent((char *) e.ae.agent.name);      if ((direction==FORWARDS)&&(e.ae.agent.expired==0)) {        if (a == NULL) {          // will only create an agent if there isn't one already           // there with the same name          a = new BoxAgent(e.ae.agent.name, n->size());          a->Animation::insert(&animations_);          n->add_agent(a);          placeAgent(a, n);        }      } else {        if (a != NULL) {          n->delete_agent(a);          delete a;        }      }      break;    case 'f':      // We don't need any redraw for this, because it's always       // displayed in monitors in a separate pane      n = lookupNode(e.fe.src);      if (n == 0)        return;      a = n->find_agent((char *)e.fe.feature.agent);      if (a == 0)        return;      f = a->find_feature((char *)e.fe.feature.name);      if (f == 0) {        switch (e.fe.feature.type) {        case 'v':          f = new VariableFeature(a, e.fe.feature.name);          break;        case 'l':          f = new ListFeature(a, e.fe.feature.name);          break;        case 's':        case 'u':        case 'd':          f = new TimerFeature(a, e.fe.feature.name);          break;        }        a->add_feature(f);      }      if (((direction==FORWARDS) && (e.fe.feature.expired == 0)) ||          ((direction==BACKWARDS) && (strlen(e.fe.feature.oldvalue) > 0))) {        char *value;        double time_set;        if (direction==FORWARDS) {          value=(char *)e.fe.feature.value;          time_set=now;        } else {          value=(char *)e.fe.feature.oldvalue;          /*XXX need an extra value here*/          time_set=0.0;        }        switch (e.fe.feature.type) {          case 'v':          case 'l':            f->set_feature(value);            break;          case 's':            f->set_feature(atof(value), TIMER_STOPPED, time_set);            break;          case 'u':            f->set_feature(atof(value), TIMER_UP, time_set);            break;          case 'd':            f->set_feature(atof(value), TIMER_DOWN, time_set);            break;        }      } else {        a->delete_feature(f);        delete f;      }      break;    case 'r':      if (direction == FORWARDS)        break;      if (e.pe.dst == -1) { //broadcasting        //a quick hack to give fixed transmission + delay time for        //broadcasting packet        if (e.time - BPACKET_TXT_TIME > now)          break ;        n = lookupNode(e.pe.src);        BPacket * p = new BPacket(n->x(), n->y(),e.pe.pkt,                                  e.time,e.offset,direction,				  e.pe.pkt.wBcastDuration				  	? e.pe.pkt.wBcastDuration					: bcast_duration_,				  e.pe.pkt.wBcastRadius				  	? e.pe.pkt.wBcastRadius					: bcast_radius_);        p->insert(&animations_);        p->paint(paint_[e.pe.pkt.attr & paintMask_]);        check_monitors(p);        break;      }      ehn = lookupEdgeHashNode(e.pe.src, e.pe.dst);      if (ehn == 0 || (ep = ehn->edge) == 0)        return;      /*       * If the current packet will arrive at its destination       * at a later time, insert the arrival into the queue       * of animations and set its paint id (id for X graphics       * context.       */      txtime = ep->txtime(e.pe.pkt.size);      if (e.time - (txtime + ep->delay()) <= now) {        /* XXX */        Packet *p = new Packet(ep, e.pe.pkt,                               e.time-(ep->delay() + txtime),                               txtime, e.offset);        p->insert(&animations_);        p->paint(paint_[e.pe.pkt.attr & paintMask_]);        check_monitors(p);      }      break;    case '+':      ehn = lookupEdgeHashNode(e.pe.src, e.pe.dst);      if (direction == FORWARDS) {        if (ehn != 0 && ehn->queue != 0) {          QueueItem *qi = new QueueItem(e.pe.pkt, e.time,                                        e.offset);          qi->paint(paint_[e.pe.pkt.attr & paintMask_]);          ehn->queue->enque(qi,QUEUE_TAIL);          qi->insert(&animations_);          check_monitors(qi);        }      } else {        if (ehn != 0 && ehn->queue != 0) {          q = ehn->queue->remove(e.pe.pkt);          delete q;        }      }      break;    case '-':

⌨️ 快捷键说明

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