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

📄 mip-reg.cc

📁 运行于linux上的CIMS套件
💻 CC
📖 第 1 页 / 共 2 页
字号:
		}	   }	  }	  }	  	  	  if (!not_Hawaii()) 	    {	      DEBUG(3) printf("This is Hawaii:");	      if(miph->Pcoa_ < 0) {		printf("power up ->forward Hawaii Messages to the Domain Root Router [%d:1]\n", drr_addr_ );	      genHawaii(HW_Power_Up, miph->haddr_, -1);	      	      }	      else {		if(miph->Pcoa_ != miph->coa_) {		  if(miph->coa_ == nodeaddr){                   printf("BS[%d:%d]:handoff ->forward Hawaii MSF Msg to Old Base-station %d \n",                         nodeaddr, myNodeId, miph->Pcoa_);		  printf("Create routing entry in Foreign BS for MH[%d]:",			 miph->haddr_);		  if( miph->ha_ != nodeaddr ) {		  Tcl::instance().evalf("%s create-route %d", name_,					miph->haddr_);		  }		  printf("\nHandoff Notification to old BS[%d] at %fs",			 miph->Pcoa_, CUR_TIME);		  DEBUG(3) printf("Handoff: oldBS[%d] HA[%d]",				  miph->Pcoa_, miph->ha_);		  		  if( miph->Pcoa_ != miph->ha_ ) {		    Tcl::instance().evalf("%s clear-route %d %d", name_,					  miph->haddr_, miph->Pcoa_);		  }		  		  /* Wan: if this is not MSF, then it's UNF */		  if (hawaii_msf_ == 1) {		    genHawaii(HW_MSF, miph->haddr_, miph->Pcoa_); //MSF		  }		  else 		    genHawaii(HW_Handoff, miph->haddr_, miph->Pcoa_); //UNF		  }		}				else {		  iph->dst() = iph->src();		  miph->type_ = MIPT_REG_REPLY; 		  send(p,0); 		}			      }	      	      	      if(miph->ha_ == nodeaddr) {		send(p,0); 	      }	      	    }	  	  	  break;	case MIPT_REG_REPLY:	  assert(miph->coa_ == nodeaddr);	  tcl.evalf("%s get-link %d %d", name_, nodeaddr, miph->haddr_);	  //	  // XXX hacking mobileip. all this should go away	  // when mobileIP for sun-wired model is no longer reqd.	  //	  obj = (NsObject*)tcl.lookup(objname = tcl.result());	  if (strlen(objname) == 0)	    objname = "XXX";	  tcl.evalf("%s decap-route %d %s %lf", name_, miph->haddr_,		    objname, miph->lifetime_);	  	  iph->src() = iph->dst();	  iph->daddr() = miph->haddr_;	  iph->dport() = 0;	  if (obj == NULL)	    obj = ragent_;	  obj->recv(p, (Handler*)0);	  break;	case MIPT_SOL:	  tcl.evalf("%s get-link %d %d",name_,nodeaddr,miph->haddr_);	  send_ads(miph->haddr_, (NsObject*)tcl.lookup(tcl.result()));	  Packet::free(p);	  break;	default:	  Packet::free(p);	  break;	}	}}void MIPBSAgent::timeout(int ){	send_ads();	timer_.resched(beacon_);}int MIPBSAgent::command(int argc, const char*const* argv){	if (argc == 3) {		if (strcmp(argv[1], "beacon-period") == 0) {			beacon_ = atof(argv[2]);			timer_.resched(Random::uniform(0, beacon_));			return TCL_OK;		}		if (strcmp(argv[1], "bcast-target") == 0) {			bcast_target_ = (NsObject *)TclObject::lookup(argv[2]);			return TCL_OK;		}		if (strcmp(argv[1], "ragent") == 0) {		  ragent_ = (NsObject *)TclObject::lookup(argv[2]);			return TCL_OK;		}	}	return (Agent::command(argc, argv));}void MIPBSAgent::send_ads(int dst, NsObject *target){        Tcl& tcl = Tcl::instance();		if (not_Hawaii()) {	  if(is_HFA()){	  tcl.evalf("%s node-class", name_);	  if(strcmp(tcl.result(),"MobileNode/GFA") == 0) {	  return;	  }	  }	}		Packet *p = allocpkt();	hdr_mip *h = (hdr_mip *)p->access(off_mip_);	hdr_ip *iph = (hdr_ip *)p->access(off_ip_);	h->haddr_ = h->ha_ = -1;	h->coa_ = Address::instance().get_nodeaddr(addr());	h->type_ = MIPT_ADS;	h->lifetime_ = adlftm_;	h->seqno_ = ++seqno_;	if (dst != -1) {	  iph->daddr() = dst;	  iph->dport() = 0;	}	else {	  // if bcast pkt	  sendOutBCastPkt(p);	}	if (target == NULL) {	  if (bcast_target_) bcast_target_->recv(p, (Handler*) 0);	  else if (target_) target_->recv(p, (Handler*) 0);	  else Packet::free(p); // drop; may log in future code	}	else target->recv(p, (Handler*)0);}voidMIPBSAgent::sendOutBCastPkt(Packet *p){  hdr_ip *iph = (hdr_ip*)p->access(off_ip_);  hdr_cmn *hdrc = (hdr_cmn *)p->access (off_cmn_);  hdrc->next_hop_ = IP_BROADCAST;  hdrc->addr_type_ = NS_AF_INET;  iph->daddr() = IP_BROADCAST;  iph->dport() = 0;}void AgtListTimer::expire(Event *) {	a_->timeout(MIP_TIMER_AGTLIST);}static class MIPMHAgentClass : public TclClass {public:	MIPMHAgentClass() : TclClass("Agent/MIPMH") {}	TclObject* create(int, const char*const*) {		return (new MIPMHAgent());	}} class_mipmhagent;/* Wan: add PFANE */MIPMHAgent::MIPMHAgent() : Agent(PT_UDP), ha_(-1), coa_(-1), Pcoa_(-1),        beacon_(1.0),bcast_target_(0),agts_(0),        rtx_timer_(this), agtlist_timer_(this),reglftm_(~0),        adlftm_(0.0), node_ (0){	bind("home_agent_", &ha_);	bind("rreqSize_", &size_);	bind("reg_rtx_", &reg_rtx_);		bind("reg_lifetime_", &reglftm_);	bind("off_mip_", &off_mip_);	bind("off_hawaii_", &off_hawaii_); 	bind("previous_coa_", &Pcoa_); 	size_ = REG_REQUEST_SIZE;	seqno_ = -1;}void MIPMHAgent::recv(Packet* p, Handler *){  int nodeaddr;  	Tcl& tcl = Tcl::instance();	hdr_mip *miph = (hdr_mip *)p->access(off_mip_);        /* Wan: */	nodeaddr = Address::instance().get_nodeaddr(addr());		switch (miph->type_) {	case MIPT_REG_REPLY:		if (miph->coa_ != coa_) break; // not pending  		tcl.evalf("%s update-reg %d", name_, coa_);		/* Wan: also store the confirmed COA for this FA		 * use for PFANE		 */		DEBUG(2) {		  printf("MH:Got a reg reply with COA: %d at time %fs\n",		       miph->coa_, CUR_TIME);		  printf("*******************************************\n");		}		Pcoa_ = miph->coa_;				if (rtx_timer_.status() == TIMER_PENDING)			rtx_timer_.cancel();		break;	case MIPT_ADS:	  {	    AgentList **ppagts = &agts_, *ptr;	    while (*ppagts) {	      if ((*ppagts)->node_ == miph->coa_) break;	      ppagts = &(*ppagts)->next_;	    }	   DEBUG(3) printf("MH[%d]: Got Ads at time %fs with COA:%d\n",		   nodeaddr, CUR_TIME, miph->coa_);	    if(Pcoa_ != miph->coa_) {	DEBUG(3) printf("<<->>MH:Got Ads(Handoff?) at time %fs with COA:%d\n",		       CUR_TIME, miph->coa_);	if (!not_Hawaii()) {		Tcl::instance().evalf("%s myNode", name_);		Tcl::instance().evalf("%s log-movement",				      Tcl::instance().result());	}	    }	    if (*ppagts) {	      ptr = *ppagts;	      *ppagts = ptr->next_;	      ptr->expire_time_ = beacon_ +		Scheduler::instance().clock();	      ptr->lifetime_ = miph->lifetime_;	      ptr->next_ = agts_;	      agts_ = ptr;	      if (coa_ == miph->coa_) {		seqno_++;		reg();	      }	    }	    else { 	      ptr = new AgentList;	      ptr->node_ = miph->coa_;	      ptr->expire_time_ = beacon_ +		Scheduler::instance().clock();	      ptr->lifetime_ = miph->lifetime_;	      ptr->next_ = agts_;	      agts_ = ptr;	      coa_ = miph->coa_;	  	      // The MHagent now should update the Mobilenode	      // about the changed coa_ : node updates its 	      // base-station to new coa_ accordingly.	      if(node_)		node_->set_base_stn(coa_);	      	      adlftm_ = miph->lifetime_;	      seqno_++;	      reg();	    }	  }	  break;	default:	  break;	}	Packet::free(p);}void MIPMHAgent::timeout(int tno){	switch (tno) {	case MIP_TIMER_SIMPLE:		reg();		break;	case MIP_TIMER_AGTLIST:		{			double now = Scheduler::instance().clock();			AgentList **ppagts = &agts_, *ptr;			int coalost = 0;			while (*ppagts) {				if ((*ppagts)->expire_time_ < now) {					ptr = *ppagts;					*ppagts = ptr->next_;					if (ptr->node_ == coa_) {						coa_ = -1;						coalost = 1;					}					delete ptr;				}				else ppagts = &(*ppagts)->next_;			}			agtlist_timer_.resched(beacon_);			if (coalost) {				seqno_++;				reg();			}		}		break;	default:		break;	}}int MIPMHAgent::command(int argc, const char*const* argv){	if (argc == 3) {		if (strcmp(argv[1], "beacon-period") == 0) {			beacon_ = atof(argv[2]);			timeout(MIP_TIMER_AGTLIST);			agtlist_timer_.resched(beacon_);			rtx_timer_.resched(Random::uniform(0, beacon_));			return TCL_OK;		}		else if (strcmp(argv[1], "bcast-target") == 0) {			bcast_target_ = (NsObject *)TclObject::lookup(argv[2]);			return TCL_OK;		}		else if (strcmp (argv[1], "node") == 0) {		  node_ = (MobileNode*)TclObject::lookup(argv[2]);		  if (node_ == 0) {		    fprintf (stderr, "%s: %s lookup of %s failed\n", __FILE__, argv[1], argv[2]);		    return TCL_ERROR;		  }		  return TCL_OK;		}	}	// later: agent solicitation (now done!), start of simulation, ...	return (Agent::command(argc, argv));}void MIPMHAgent::reg(){	rtx_timer_.resched(reg_rtx_);	if (agts_ == 0) {		send_sols();		return;	}	if (coa_ < 0) {		coa_ = agts_->node_;		adlftm_ = agts_->lifetime_;	}	Tcl& tcl = Tcl::instance();	Packet *p = allocpkt();	hdr_ip *iph = (hdr_ip *)p->access(off_ip_);	iph->daddr() = coa_;	iph->dport() = 0;	hdr_mip *h = (hdr_mip *)p->access(off_mip_);	h->haddr_ = Address::instance().get_nodeaddr(addr());	h->ha_ = ha_;	h->coa_ = coa_;	h->Pcoa_ = Pcoa_;	h->type_ = MIPT_REG_REQUEST;	h->lifetime_ = min(reglftm_, adlftm_);	h->seqno_ = seqno_;	tcl.evalf("%s get-link %d %d", name_, h->haddr_, coa_);	NsObject *target = (NsObject *)tcl.lookup(tcl.result());	if (target != NULL)	  ((NsObject *)tcl.lookup(tcl.result()))->recv(p, (Handler*) 0);	else	  send(p, 0);	/* Wan: */	DEBUG(2) printf("MH:Send a Request with COA: %d at time %fs\n",coa_,		       CUR_TIME);}void MIPMHAgent::send_sols(){	Packet *p = allocpkt();	hdr_mip *h = (hdr_mip *)p->access(off_mip_);	h->coa_ = -1;	h->haddr_ = Address::instance().get_nodeaddr(addr());	h->ha_ = ha_;	h->type_ = MIPT_SOL;	h->lifetime_ = reglftm_;	h->seqno_ = seqno_;	sendOutBCastPkt(p);	//Wan:	DEBUG(2) printf("MH[%d] Send out Agent Solicitation at %fs\n",			h->haddr_, CUR_TIME);	fflush(stdout);	if (bcast_target_) 	  bcast_target_->recv(p, (Handler*) 0);	else if (target_) 	  target_->recv(p, (Handler*) 0);	else 	  Packet::free(p); // drop; may log in future code}void MIPMHAgent::sendOutBCastPkt(Packet *p){  hdr_ip *iph = (hdr_ip*)p->access(off_ip_);  hdr_cmn *hdrc = (hdr_cmn *)p->access (off_cmn_);  hdrc->next_hop_ = IP_BROADCAST;  hdrc->addr_type_ = NS_AF_INET;  iph->daddr() = IP_BROADCAST;  iph->dport() = 0;}

⌨️ 快捷键说明

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