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

📄 mac-802_16-bs.cc

📁 OPNET 中的Wimax模块, 主要用于wimax 无线网络仿真,以及普通无线网络仿真.
💻 CC
📖 第 1 页 / 共 5 页
字号:
  static int RecvFrameEntered = 0;  This routine will invoke HandleInData or HandleInMgmt ....  \param p A packet that already has been adjusted for all headers  \param concat_flag true if we are being reentered due to a concatonated  frame.  In this case, we've already counted the packet, but we need to count the size.*/void Mac802_16BS::RecvFrame(Packet* p, int concat_flag){  struct hdr_cmn* ch = HDR_CMN(p);  struct hdr_mac802_16* dh = HDR_MAC802_16(p);  int cindex, findex;  int t;  u_char req;  u_int16_t flow_id;    //$A7  if (concat_flag == 0)    total_num_frames_US++;    //	RecvFrameEntered++;    //STATISTICS  ???  //Only the first time we enter  //   if (RecvFrameEntered ==1)  // {  //}    t = ClassifyDataMgmt(p);#ifdef TRACE_BS //---------------------------------------------------------  printf("BS:RecvFrame(%lf): BS receives a 802_16 frame, type %d\n", 	 Scheduler::instance().clock(),t);#endif //--------------------------------------------------------------------  if (t == 0) /* if 0,  the frame contains data */    {#ifdef TRACE_BS //---------------------------------------------------------      printf("BSrecvFrame:Calling HandleInData..\n");#endif //--------------------------------------------------------------------            //Updating statistics      num_pkts++;      total_num_rx_pkts++;      util_total_pkts_US ++;      num_bytes += ch->size();      total_num_rx_bytes += ch->size();      util_total_bytes_US += ch->size(); /* Used for end of run util stat */           util_bytes_US += ch->size();       /* Used for dump802_16UtilStats */           total_num_BW_bytesUP += ch->size();            if (concat_flag)	{	  num_bytes -= upchannel.overhead_bytes;	  total_num_rx_bytes -= upchannel.overhead_bytes;	  util_total_bytes_US -= upchannel.overhead_bytes;/* Used for end of run util stat */     	  util_bytes_US -= upchannel.overhead_bytes;      /* Used for dump802_16UtilStats */     	  total_num_BW_bytesUP -= upchannel.overhead_bytes;	}             if (!concat_flag)	{#ifdef  PACKET_TRACE //--------------------------------------------------------------------	  #ifdef TRACE_BS 	  printf("BS:RecvFrame(%lf): PACKET_TRACE :  received a frame of type %d\n", 		 Scheduler::instance().clock(),t);#endif	  int rc_p=0;	  int ss=0;	  int flow=0;    	  int direction_p = 0;	  	  if(HDR_CMN(p)->direction() == hdr_cmn::DOWN)	    direction_p = 0;	  	  else if(HDR_CMN(p)->direction() == hdr_cmn::UP)	    direction_p = 1;	  	  if(FLOW_ID==0 && SS_ID==0)	    rc_p=packetTrace(p,direction_p);	  	  else	    {	      ss = classify(p, UPSTREAM, &flow); /* BS perspective RecvFrame will always be upstream */	      if ((ss == SS_ID && FLOW_ID == 0)|| 		  (SS_ID == 0 && flow == FLOW_ID)|| 		  (ss == SS_ID && FLOW_ID == flow))		rc_p = packetTrace(p, direction_p);	    }		  if(rc_p!=0)	    printf("BS:PACKET_TRACE: Packet trace monitor failed\n"); 	  /*	    printf("BS:RecvFrame(%lf):PACKET_TRACE: received a frame of type %d\n",	    Scheduler::instance().clock(),t);	  */#endif //----------------------------------------------------------------------------------	}      #ifdef TRACE_BS_UP_DATA //--------------------------------------------------------------------      printf("BSup %lf %f %d\n",	     Scheduler::instance().clock(),total_num_rx_bytes,ch->size());#endif //-------------------------------------------------------------------------------            cindex = classify(p, UPSTREAM, &findex);#ifdef TRACE_BS //--------------------------------------------------------------------      printf("BS:recvFrame: Packet classified on flow-id = %d\n",	     SSRecord[cindex].u_rec[findex].flow_id);#endif //-------------------------------------------------------------------------------      //dump_pkt(p);	      PhUnsupress(p,cindex,findex);            /* cindex - SS index, findex - Flow index */            /* If we have  reentered, set last param to 1 to 	 indicate the PHY OH has been stripped already */      //       if (RecvFrameEntered >1)      //$A7      if (!concat_flag)	total_num_plaindata_pkts_US++;      else	total_num_concatdata_pkts_US++;            HandleInData(p, cindex,findex);      //else      //HandleInData(p, cindex,findex,0);    }  else /*else the frame contains a mac specific header (i.e., a request) */    {#ifdef TRACE_BS //---------------------------------------------------------      printf("BS:RecvFrame:Calling HandleInMgmt..\n");#endif //--------------------------------------------------------------------      HandleInMgmt(p);            if (concat_flag)	{	  num_bytes -= upchannel.overhead_bytes;	  total_num_rx_bytes -= upchannel.overhead_bytes;	  util_total_bytes_US -= upchannel.overhead_bytes;/*Used for end of run util stat*/     	  util_bytes_US -= upchannel.overhead_bytes;      /*Used for dump802_16UtilStats*/     	  total_num_BW_bytesUP -= upchannel.overhead_bytes;	}    }  //if (RecvFrameEntered >0)  //RecvFrameEntered--;    return;}/*****************************************************************************A simple ethernet PDU is carried in the 802_16 payload..No Fragmentation or Concatenation*****************************************************************************//*! A simple ethernet PDU is carried in the 802_16 payload..  No Fragmentation or Concatenation */void Mac802_16BS::PassDownstream(Packet* p){  /* Simply pass the pkt by applying new PHS ... */  struct hdr_cmn * ch = HDR_CMN(p);  int cindex,findex;  double stime;    total_num_appbytesDS += ch->size();  ch->size() += ETHER_HDR_LEN;  ch->size() += MAC802_16_HDR_LEN;    cindex = classify(p, DOWNSTREAM,&findex);  //printf("1...\n");  ApplyPhs(p,cindex,findex);    /* Apply rate-control SendFrame will be called from rate-control */  SSRecord[cindex].d_rec[findex].util_total_bytes_DS += ch->size();  SSRecord[cindex].d_rec[findex].util_total_pkts_DS ++;    //#ifdef RATE_CONTROL //-------------------------------------------------------  if (SSRecord[cindex].d_rec[findex].ratecontrol) /* Rate-control on*/    {      RateControl(p,cindex,findex,MGMT_PKT);      return;    }  //#endif //--------------------------------------------------------------------    /* Send the packet */  SendFrame(p,MGMT_PKT);  return;  }/****************************************************************************** routine:  void Mac802_16BS::HandleInData(Packet *p, int cindex, int findex)* function: *    overHeadBitsStripped is 1 if the packet already has had the OH bits taken off  *    (This occurs when multiple frames are concatonated)*******************************************************************************//*! overHeadBitsStripped is 1 if the packet already has had the OH bits taken off      (This occurs when multiple frames are concatonated) */void Mac802_16BS::HandleInData(Packet *p, int cindex, int findex){  int dst, src, target = 0;  struct hdr_cmn* ch = HDR_CMN(p);  struct hdr_mac802_16* dh = HDR_MAC802_16(p);  struct hdr_mac* mh = HDR_MAC(p);    //$A7  SchedType sclass;  dst = mh->macDA();  src = mh->macSA();  #ifdef TRACE_BS //---------------------------------------------------------  printf("BS:HandleInData(%lf): this frame (size:%d)  has arrived\n", 	 Scheduler::instance().clock(),ch->size());#endif //--------------------------------------------------------------------  //$A7  //	total_num_plaindata_pkts_US++;   sclass = SSRecord[cindex].u_rec[findex].sched_type;    if (sclass == BEST_EFFORT)     total_num_BE_pkts_US++;    else if (sclass == RT_POLL)     total_num_RTVBR_pkts_US++;    else if (sclass == UGS)     total_num_UGS_pkts_US++;      else    total_num_OTHER_pkts_US++;      /* Whether or not the packet is destined for me, I need to check   * whether an extended header containing piggyback req is present   */  ParseExtHdr(p);    /* Not a packet destinated to me. */  if ((dst != MAC_BROADCAST) && (dst != (u_int32_t)index_))     {            /* Forward the packets between the SSs */            /* 	 This shud take care of ARP requests also..i.e ARP requests are passed	 on downstream channel       */      target = find_ss(dst);      if (target) 	{#ifdef TRACE_BS //---------------------------------------------------------	  printf("Forwarding the pkt to ss %d\n",target);	  dump_pkt(p);#endif //--------------------------------------------------------------------	  	  total_num_appbytesUS += ch->size() - ETHER_HDR_LEN - MAC802_16_HDR_LEN- upchannel.overhead_bytes;	  ch->size() -= ETHER_HDR_LEN;	  ch->size() -= MAC802_16_HDR_LEN;	  ch->size() -= upchannel.overhead_bytes;	  ch->num_forwards() += 1;	  	  PassDownstream(p);	  return;	}                }    /*      Will have to decide whether to change the src-mac address when passing ARP      requests down as it is possible that SSs might not be having ip-addresses      of other SSs in their routing table   */    /* Now, simply strip the ethernet , 802_16 header & pass the packet to upper layer */    ch->size() -= ETHER_HDR_LEN;  ch->size() -= MAC802_16_HDR_LEN;    //if (overHeadBitsStripped == 0)  /*      Remove the overhead bytes in any case...We r adding overhead bytes     to all pkts carried in concatenated frame...  */  ch->size() -= upchannel.overhead_bytes;  ch->num_forwards() += 1;    total_num_appbytesUS += ch->size();  #ifdef TRACE_BS //---------------------------------------------------------  printf("BS:HandleInData(%lf): passing to uptarget... size is now: %d\n", 	 Scheduler::instance().clock(),ch->size());#endif //--------------------------------------------------------------------    uptarget_->recv(p, (Handler*) 0);  return;  }/**********************************************************************************************************************************************************/void Mac802_16BS::ParseExtHdr(Packet * p){  struct hdr_cmn* ch = HDR_CMN(p);  struct hdr_mac802_16* dh = HDR_MAC802_16(p);  struct hdr_mac802_16extd* df = HDR_MAC802_16EXTD(p);  int piggy_index = -1;  /* Check if extended header is ON */    if (dh->dshdr_.ehdr_on == 1)    {      for (int i = 0; i < df->num_hdr; i++)	{	  if (df->exthdr_[i].eh_type == 1)	    piggy_index = i;	}      if (piggy_index == -1)	return;            if (df->exthdr_[piggy_index].eh_type == 1) /* Piggyback req */	{	  u_int16_t flow_id;	  u_int16_t req;	  int cindex, findex;	  flow_id = df->exthdr_[piggy_index].eh_data[1];	  req = df->exthdr_[piggy_index].eh_data[0];	  find_flowindex(flow_id,&cindex,&findex);	  #ifdef TRACE_BS //----------------------------------------------------------------	  printf("ParseExtHdr(%lf): Received a Piggyback request for flow-id %d \n",		 Scheduler::instance().clock(),flow_id);#endif //---------------------------------------------------------------------------	  	  // Reduce the size..	  ch->size() -= 3;	  SSStatistics_.num_piggyreq++;	  /*$A25	    HandleReq(req, cindex, findex);*/	  HandleReq(req, cindex, findex, false);	}          }  else    return;}/******************************************************************************  function:  void Mac802_16BS::HandleInMgmt(Packet *p)**  explanation:*   This routine receives a Mgt message of the following types:*    case 2:  request header*    case 3:  Fragmentation frame header *    case 26: Concatenation frame header*    case 1:  RNG msg* *    Note: if it's a concat frame-  this means its a concat request.**  inputs: Packet *p : the packet**  outputs : none*******************************************************************************//*! This routine receives a Mgt message of the following types:    \li \c case 2:  request header    \li \c case 3:  Fragmentation frame header     \li \c case 26: Concatenation frame header    \li \c case 1:  RNG msg 

⌨️ 快捷键说明

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