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

📄 mac-802_16-fsm.cc

📁 OPNET 中的Wimax模块, 主要用于wimax 无线网络仿真,以及普通无线网络仿真.
💻 CC
📖 第 1 页 / 共 5 页
字号:
	{	  turn_off_contention(tbindex);	  UpFlowTable[tbindex].state = NRTPOLL_REQSENT;	  }*/      break;          default:      printf("SS%d(flow-id %d) NRTPOLL-WAITFORMAP state error: Unknown event received: %d\n",	     ss_id,UpFlowTable[tbindex].upstream_record.flow_id,e);      break;          }  return 1;}/**************************************************************************************************************************************************/int Mac802_16SS::nrtpoll_tosend(char tbindex, EventType e, Packet* p){  double etime, current_time;  Packet* t;    if (UpFlowTable[tbindex].debug)    printf("SS%d(flow-id %d):nrtpoll_tosend(%lf): event :%d \n", 	   ss_id,UpFlowTable[tbindex].upstream_record.flow_id, 	   Scheduler::instance().clock(),e);    switch(e)     {    case SEND_PKT:      /* Function to find out the first data grant big enough 	 for this packet (indicated by 0) */            etime = timer_expiration(tbindex, p, DATA_GRANT);            if (etime == -1.0)	{	  printf("SS%d(flow-id %d) Timer expiration error: exiting..\n",		 ss_id,UpFlowTable[tbindex].upstream_record.flow_id);	  exit(1);	}            if (UpFlowTable[tbindex].debug)	printf("SS%d(flow-id %d)Starting snd timer..\n", 	       ss_id,UpFlowTable[tbindex].upstream_record.flow_id);            //printf("etime = %lf\n",etime);      //TESTE      //fprintf(stderr,"nrtpoll_tosend em %lf evento %p com delay %f  para %lf\n",current_time,&UpFlowTable[tbindex].intr,etime,etime+current_time);      mhSSSend_.start((Packet *)(&UpFlowTable[tbindex].intr), etime );            current_time = Scheduler::instance().clock();      insert_sndlist(current_time + etime, tbindex);      break;          case PKT_ARRIVAL:#ifdef TIMINGS//      printf("1 %lf %d %d 4\n",Scheduler::instance().clock(),//			UpFlowTable[tbindex].upstream_record.flow_id,ss_id);       timingsTrace(p,1);#endif      insert_pkt(p,tbindex);      break;          case MAP_ARRIVAL:      UpdateAllocationTable(tbindex);            if (UpFlowTable[tbindex].debug)	{	  printf("SS%d(flow-id %d):nrtpoll_tosend(%lf): MAP arrival\n", 		 ss_id,UpFlowTable[tbindex].upstream_record.flow_id, 		 Scheduler::instance().clock());	  print_alloclist(tbindex);	}      break;          case SEND_TIMER:      /* Senddown shud set pkt to NULL  & free the pkt */      //deque_pkt(tbindex);#ifdef TIMINGS//	printf("4 %lf %d %d 1\n",Scheduler::instance().clock(),//			UpFlowTable[tbindex].upstream_record.flow_id,ss_id);         timingsTrace(p,4);#endif      //TESTE      //fprintf(stderr,"nrtpoll_tosend send_timer em %lf\n",Scheduler::instance().clock());      SendData(p,tbindex);            if (!bit_on(UpFlowTable[tbindex].upstream_record.flag,FRAG_ON_BIT) && 	  ((!bit_on(UpFlowTable[tbindex].upstream_record.flag,PIGGY_ENABLE_BIT)) || 	   ((bit_on(UpFlowTable[tbindex].upstream_record.flag,PIGGY_ENABLE_BIT)) && 	    (bit_on(UpFlowTable[tbindex].upstream_record.flag,PIGGY_NOT_SEND)))))		{	  /* This 'if' will be entered only if frag is off 	     and piggyback request has not been sent */	  	  UpFlowTable[tbindex].pkt = 0;	  	  if ((len_queue(UpFlowTable[tbindex].packet_list)) > 0) 	    {	      UpFlowTable[tbindex].state = NRTPOLL_DECISION;	      t = deque_pkt(tbindex);	      UpFlowTable[tbindex].pkt = t;#ifdef TIMINGS//We will log this next in NRTPOLL_DECI//	printf("2 %lf %d %d 1\n",Scheduler::instance().clock(),//			UpFlowTable[tbindex].upstream_record.flow_id,ss_id); //        timingsTrace(t,2);#endif	      nrtpoll_decision(tbindex, PKT_ARRIVAL, t);	    }		  else	    UpFlowTable[tbindex].state = NRTPOLL_IDLE;	  	  /* Turn-off this bit, as the info has been used */	  set_bit(&UpFlowTable[tbindex].upstream_record.flag, PIGGY_NOT_SEND,OFF);	  	}      break;          default:      printf("SS%d(flow-id %d) NRTPOLL-TOSEND state error: Unknown event received %d\n",	     ss_id,UpFlowTable[tbindex].upstream_record.flow_id,e);      break;    }  return 1;}/**************************************************************************************************************************************************/int Mac802_16SS::nrtpoll_tosendreq(char tbindex, EventType e, Packet* p){  double etime,current_time;    if (UpFlowTable[tbindex].debug)    printf("SS%d(flow-id %d) :nrtpoll_tosendreq(%lf):  Entered with event : %d \n",	   ss_id,UpFlowTable[tbindex].upstream_record.flow_id, 	   Scheduler::instance().clock(),e);  switch(e)     {    case SEND_UREQ:      /* Function to find out the first Unicast req grant for	 this flow (indicated by 1) */      etime = timer_expiration(tbindex, p, UREQ_GRANT);            if (etime == -1.0)	{	  printf("SS%d(flow-id %d) Timer expiration error: exiting..\n",		 ss_id,UpFlowTable[tbindex].upstream_record.flow_id);	  exit(1);	}            //TESTE      //fprintf(stderr,"nrtpoll_tosendreq em %lf evento %p para %lf\n",current_time,&UpFlowTable[tbindex].intr,etime+current_time);      mhReq_.start((Packet*)(&UpFlowTable[tbindex].intr), etime);      current_time = Scheduler::instance().clock();      printf("nrtPS vai enviar u-req em %f\n",current_time+etime);      insert_reqlist(current_time + etime, tbindex);      break;          case PKT_ARRIVAL:#ifdef TIMINGS//      printf("1 %lf %d %d 5\n",Scheduler::instance().clock(),//			UpFlowTable[tbindex].upstream_record.flow_id,ss_id);       timingsTrace(p,1);#endif      insert_pkt(p,tbindex);      break;          case MAP_ARRIVAL:      UpdateAllocationTable(tbindex);            if (UpFlowTable[tbindex].debug)	{	  printf("SS%d(flow-id %d):nrtpoll_tosendreq(%lf): MAP ARRIVAL: allocation table:\n", 		 ss_id,UpFlowTable[tbindex].upstream_record.flow_id, 		 Scheduler::instance().clock());	  print_alloclist(tbindex);	}            if (CanBeSent(UpFlowTable[tbindex].alloc_list,p,tbindex))	{	  mhReq_.stop((Packet*)(&UpFlowTable[tbindex].intr));	  //$A8	  refresh_reqlist(tbindex);	  UpFlowTable[tbindex].req_time = 999999.0;	  UpFlowTable[tbindex].state = NRTPOLL_TOSEND;	  nrtpoll_tosend(tbindex, SEND_PKT, p);	}      break;          case REQ_TIMER:      /* Send_Request shud mark the slot as used..sendDown shud mark 	 the slot as used*/                     //$A2      //On error, reinsert request and assume a collision      if(!SendReq(tbindex, p)){          reinsert_reqlist(tbindex);                                    if(UpFlowTable[tbindex].num_retries == 1){            turn_off_contention(tbindex);            UpFlowTable[tbindex].bk_offwin = UpFlowTable[tbindex].bk_offstart;         }         else {           total_num_collisions--;           UpFlowTable[tbindex].bk_offwin = UpFlowTable[tbindex].bk_offwin / 2;           UpFlowTable[tbindex].num_retries--;         } //                           printf("Request not sent\n");      }             //TESTE      //fprintf(stderr,"nrtpoll_tosendreq send_timer em %lf\n",Scheduler::instance().clock());      //      SendReq(tbindex, p);      UpFlowTable[tbindex].state = NRTPOLL_REQSENT;      break;          default:      printf("SS%d(flow-id %d) NRTPOLL-TOSENDREQ state error: Unknown event received %d\n",	     ss_id,UpFlowTable[tbindex].upstream_record.flow_id,e);      break;    }  return 1;}			/**************************************************************************************************************************************************/			int Mac802_16SS::nrtpoll_reqsent(char tbindex, EventType e, Packet* p){  if (UpFlowTable[tbindex].debug)    printf("SS%d(flow-id %d) NRTPOLL_REQSENT state \n",	   ss_id,UpFlowTable[tbindex].upstream_record.flow_id);	  switch(e)     {    case PKT_ARRIVAL:#ifdef TIMINGS//      printf("1 %lf %d %d 6\n",Scheduler::instance().clock(),//			UpFlowTable[tbindex].upstream_record.flow_id,ss_id);       timingsTrace(p,1);#endif      insert_pkt(p,tbindex);      break;          case MAP_ARRIVAL:      UpdateAllocationTable(tbindex);            if(UpFlowTable[tbindex].debug)	{	  printf("SS%d(flow-id %d)Allocation table \n",		 ss_id,UpFlowTable[tbindex].upstream_record.flow_id);	  print_alloclist(tbindex);	}            if(CanBeSent(UpFlowTable[tbindex].alloc_list,p,tbindex))	{	  UpFlowTable[tbindex].state = NRTPOLL_TOSEND;	  turn_off_contention(tbindex);	  nrtpoll_tosend(tbindex, SEND_PKT, p);	}      //$A11 $A13      else if ((Scheduler::instance().clock() - UpFlowTable[tbindex].req_time) >= T16_TIMER)	{	  if (UpFlowTable[tbindex].contention_on)	    {	      /* Request lost in collision */	      int max_retries_reached = back_off(tbindex,p);	      // incluir as mudancas de estado	      if (max_retries_reached)		{		  if (UpFlowTable[tbindex].debug)		    printf("Dropping the packet as maximum number of retries is exceeded\n");		  total_packets_dropped++; 		  UpFlowTable[tbindex].total_collision_drops++;		  drop(p);		  turn_off_contention(tbindex);		  if (bit_on(UpFlowTable[tbindex].upstream_record.flag,FRAG_ON_BIT))		    {		      set_bit(&UpFlowTable[tbindex].upstream_record.flag, FRAG_ON_BIT,OFF);		      UpFlowTable[tbindex].frag_data = 0;		      UpFlowTable[tbindex].frag_pkt = 0;		    }		  UpFlowTable[tbindex].pkt = 0;		  if ((len_queue(UpFlowTable[tbindex].packet_list)) > 0)		    {		      Packet* t;		      t = deque_pkt(tbindex);		      UpFlowTable[tbindex].pkt = t;		      UpFlowTable[tbindex].state = NRTPOLL_DECISION;		      nrtpoll_decision(tbindex, PKT_ARRIVAL, t);		    }			  else		    UpFlowTable[tbindex].state = NRTPOLL_IDLE; 		}	      else		beffort_decision(tbindex, PKT_ARRIVAL, p);	      	    } 	  else	    {	      if (UpFlowTable[tbindex].debug)		printf("SS%d(flow-id %d) Request denied at %lf\n", 		       ss_id,UpFlowTable[tbindex].upstream_record.flow_id,		       Scheduler::instance().clock());	      	      /* Data grant, requested through unicast opportunity, denied by BS */	      UpFlowTable[tbindex].state = NRTPOLL_DECISION;	      nrtpoll_decision(tbindex, PKT_ARRIVAL, p);	    }	} 	        /*else if ((UpFlowTable[tbindex].contention_on) &&	       ( !DataGrantPending(tbindex)) && 	       (MapSentAfterReq(tbindex)))	{	  // Request lost in collision 	  back_off(tbindex,p);	}      else if ((UpFlowTable[tbindex].contention_on) &&	       ( DataGrantPending(tbindex)) && 	       (MapSentAfterReq(tbindex)))	{	  //Contention request succesfully sent	  turn_off_contention(tbindex);	}      else if ((!UpFlowTable[tbindex].contention_on) &&	       ( !DataGrantPending(tbindex)) && 	       (MapSentAfterReq(tbindex)))	{	  if (UpFlowTable[tbindex].debug)	    printf("SS%d(flow-id %d) Request denied at %lf\n", 		   ss_id,UpFlowTable[tbindex].upstream_record.flow_id,		   Scheduler::instance().clock());	  	  // Data grant denied by BS	  UpFlowTable[tbindex].state = NRTPOLL_DECISION;	  nrtpoll_decision(tbindex, PKT_ARRIVAL, p);	}*/	            break;          default:      printf("SS%d(flow-id %d) NRTPOLL-REQSENT state error: Unknown event received %d\n",	     ss_id,UpFlowTable[tbindex].upstream_record.flow_id,e);      break;          }  return 1;}/**************************************************************************** * Method: int Mac802_16SS::nrtpoll_contention(char tbindex, EventType e, Packet* p) * * Function:    * * Parameters: *    char tbindex: *    EventType e:  TODO:  Explain this *    Packet *p:  The frame that already has bee adjusted for all headers * * Design Notes: *   TODO:  I see us get in here but we end up waiting for the next map *           even though there is possibly a contention req opportunity in *           the very near future (with the current MAP) ????? * * **********************************************************************//*! \param p The frame that already has bee adjusted for all headers */int Mac802_16SS::nrtpoll_contention(char tbindex, EventType e, Packet* p){  int ran, n;  double etime, current_time;    if (UpFlowTable[tbindex].debug)    printf("SS%d(flow-id %d):nrtpoll_contention(%lf):  Entered with event %d \n",	   ss_id,UpFlowTable[tbindex].upstream_record.flow_id,	   Scheduler::instance().clock(),e);    switch(e)     {    case CONTENTION_ON:      //printf("req %lf CONTENTION\n",Scheduler::instance().clock());            ran = rng_->uniform((int)UpFlowTable[tbindex].bk_offstart);            if (UpFlowTable[tbindex].debug)	printf("SS%d(flow-id %d):nrtpoll_contention:Entering contention phase,will skip %d slots(bk_offstart:%d)\n",

⌨️ 快捷键说明

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