📄 mac-802_16-bs.cc
字号:
fprintf(stderr,"window_ = %f\n",window_); return;}/**********************************************************************************************************************************************************/int Mac802_16BS::command(int argc, const char*const* argv){#ifdef TRACE_BS_COMMAND //------------------------------------------------ printf("BS:command: entered with command: %s\n",argv[1]);#endif //-------------------------------------------------------------------- if (argc == 3) { if (strcmp(argv[1], "set-SSnodes") == 0) { SizeSSTable = atoi(argv[2]) - 1; AllocMemSSrecord(); return TCL_OK; } else if (strcmp(argv[1],"dump-BW-bs") == 0) { (void)dumpBWBS((char *)argv[2]); return TCL_OK; } } else if (argc == 4) { if (strcmp(argv[1],"dump-802_16-queue-stats") == 0) { (void)dump802_16QueueStats((char *)argv[2], atoi(argv[3])); return TCL_OK; } } else if (argc == 5) { if (strcmp(argv[1],"dump-802_16-util-stats") == 0) { (void)dump802_16UtilStats((char *)argv[2], atoi(argv[3]), atoi(argv[4])); return TCL_OK; } else if (strcmp(argv[1],"dump-final-bs-stats") == 0) { char * a = (char *)argv[2]; fprintf(stderr, "file %s", a ); (void)dumpFinalBSStats((char *)argv[2], atoi(argv[3]), atoi(argv[4])); return TCL_OK; } } else if (argc == 6) { if (strcmp(argv[1],"configure-mgmtparams") == 0) { Conf_Table_.mgtparam.sync_msg_interval = atof(argv[2]); Conf_Table_.mgtparam.rng_msg_interval = atof(argv[3]); Conf_Table_.mgtparam.ucd_msg_interval = atof(argv[4]); qlim_ = atoi(argv[5]); return TCL_OK; } } else if (argc == 10) { if (strcmp(argv[1],"configure-mapparam") == 0) { Conf_Table_.mapparam.time_covered = atof(argv[2]); Conf_Table_.mapparam.map_interval = atof(argv[3]); Conf_Table_.mapparam.num_contention_slots = atoi(argv[4]); Conf_Table_.mapparam.num_sm_slots = atoi(argv[5]); //$A14 //Conf_Table_.mapparam.sgrant_limit = atoi(argv[6]); //Conf_Table_.mapparam.lgrant_limit = atoi(argv[7]); Conf_Table_.mapparam.bkoff_start = atoi(argv[6]); Conf_Table_.mapparam.bkoff_end = atoi(argv[7]); proportion = atof(argv[8]); MAP_LOOKAHEAD = atoi(argv[9]); max_burst_slots = (int)(Conf_Table_.mapparam.time_covered / size_mslots); #ifdef TRACE_BS //--------------------------------------------------------- printf("Map interval = %lf\n",Conf_Table_.mapparam.map_interval); printf("Max burst slots = %d\n",max_burst_slots);#endif //-------------------------------------------------------------------- max_slots_pmap = (int)(Conf_Table_.mapparam.time_covered / size_mslots); #ifdef TRACE_BS //--------------------------------------------------------- printf("max_slots = %lf\n",max_slots_pmap);#endif //-------------------------------------------------------------------- next_map = max_slots_pmap; return TCL_OK; } } else if (argc == 2) { if (strcmp(argv[1],"start") == 0) {//$A13//The MAP time must be at least 1 MAP time in the future. It will be// 1 + ceil((propDelay+MAPtx time)/MAPTime)//map_etime = Scheduler::instance().clock() + 2*Conf_Table_.mapparam.map_interval; MapPropDelay = 1; double MAPMsgTxTime = (SIZE_MGMT_HDR + SIZE_MAP_HDR + 10*4)*8/downchannel.data_rate; double tmp = downchannel.prop_delay + MAPMsgTxTime; MapPropDelay = MapPropDelay + (int) ceil(tmp/Conf_Table_.mapparam.map_interval); map_etime = Scheduler::instance().clock() + MapPropDelay*Conf_Table_.mapparam.map_interval;#ifdef TRACE_BS //--------------------------------------------------------- fprintf(stderr,"data rate = %f prop delay= %f",downchannel.data_rate,downchannel.prop_delay); printf("Starting BS.., MapPropDelay: %d, map_etime:%f\n",MapPropDelay,map_etime); printf("Current time %lf \n",Scheduler::instance().clock()); printf("MAPMsgTxTime:%f,downchannel.prop_delay:%f,MapPropDelay:%d\n", MAPMsgTxTime,downchannel.prop_delay,MapPropDelay);#endif //-------------------------------------------------------------------- ReleaseJobs(); mhMap_.start((Packet*) (&intr),Conf_Table_.mapparam.map_interval); double random_delay = Random::uniform(.01,3); mhUcd_.start((Packet*) (&uintr),Conf_Table_.mgtparam.ucd_msg_interval+random_delay); /* $A4 : add some randomness. This will reduce the frequency but that's ok*/ random_delay = Random::uniform(.01,3); mhRng_.start((Packet*) (&rintr),Conf_Table_.mgtparam.rng_msg_interval+random_delay); random_delay = Random::uniform(.01,3); mhSync_.start((Packet*) (&sintr),Conf_Table_.mgtparam.sync_msg_interval+random_delay); //$A21 - start window, which will help to provide the minimum BW requested. mhWdw_.start((Packet*) (&wintr), Conf_Table_.mapparam.map_interval); fprintf(stderr,"Start window: %f\n", Conf_Table_.mapparam.map_interval); return TCL_OK; } } return Mac802_16::command(argc, argv);}/**********************************************************************************************************************************************************/void Mac802_16BS::AllocMemSSrecord(){ SSRecord = (struct ss_record *) malloc(SizeSSTable*sizeof (struct ss_record)); if (SSRecord == 0) { printf("Mac802_16BS->AllocMemSSrecord: Failed to assign memory, Quiting\n"); exit(1); } return ;}/**********************************************************************************************************************************************************/int Mac802_16BS::register_to_bs(int macaddr, u_int16_t priority, u_char def_up, u_char def_dn, struct upstream_sflow *UpEntry, u_char UpSize, struct downstream_sflow * DownEntry, u_char DownSize){ int i = 0; char f = 0; SSRecord[CurrIndexSSTable].ss_macaddr = macaddr; SSRecord[CurrIndexSSTable].priority = priority; SSRecord[CurrIndexSSTable].SizeDnFlTable = DownSize; SSRecord[CurrIndexSSTable].SizeUpFlTable = UpSize; SSRecord[CurrIndexSSTable].default_upstream_index_ = def_up; SSRecord[CurrIndexSSTable].default_downstream_index_ = def_dn;#ifdef TRACE_BS printf("mac-802_16bs:register_to_bs: registered default flows for SS default US index:%d, DS index: %d (SizeUpFlowTable:%d, SizeDownFlowTable:%d)\n",def_up,def_dn,UpSize,DownSize);#endif for (i = 0; i < UpSize; i++) { SSRecord[CurrIndexSSTable].u_rec[i].sched_type = UpEntry[i].upstream_record.sched_type; SSRecord[CurrIndexSSTable].u_rec[i].gsize = UpEntry[i].upstream_record.gsize; SSRecord[CurrIndexSSTable].u_rec[i].ginterval = UpEntry[i].upstream_record.ginterval; if (bit_on(UpEntry[i].upstream_record.flag, FRAG_ENABLE_BIT)) set_bit(&SSRecord[CurrIndexSSTable].u_rec[i].flag, FRAG_ENABLE_BIT,ON); if (bit_on(UpEntry[i].upstream_record.flag, CONCAT_ENABLE_BIT)) set_bit(&SSRecord[CurrIndexSSTable].u_rec[i].flag, CONCAT_ENABLE_BIT,ON); SSRecord[CurrIndexSSTable].u_rec[i].PHS_profile = UpEntry[i].upstream_record.PHS_profile; SSRecord[CurrIndexSSTable].u_rec[i].flow_id = next_flowid; UpEntry[i].upstream_record.flow_id = next_flowid; /* Send these values in every Map */ /* UpEntry[i].bk_offstart = Conf_Table_.mapparam.bkoff_start; UpEntry[i].bk_offend = Conf_Table_.mapparam.bkoff_end;*/ SSRecord[CurrIndexSSTable].u_rec[i].classifier.src_ip = UpEntry[i].upstream_record.classifier.src_ip; SSRecord[CurrIndexSSTable].u_rec[i].classifier.dst_ip = UpEntry[i].upstream_record.classifier.dst_ip; SSRecord[CurrIndexSSTable].u_rec[i].classifier.pkt_type = UpEntry[i].upstream_record.classifier.pkt_type; //$A21 SSRecord[CurrIndexSSTable].u_rec[i].latency = UpEntry[i].upstream_record.latency; SSRecord[CurrIndexSSTable].u_rec[i].min_bw = UpEntry[i].upstream_record.min_bw; SSRecord[CurrIndexSSTable].u_rec[i].backlogged = 0; SSRecord[CurrIndexSSTable].u_rec[i].granted_bw = 0; next_flowid++;#ifdef TRACE_BS printf("mac-802_16bs:register_to_bs: registered additional US (index:%d,flow_id:%d), sched_type:%d, gsize:%d, ginterval%f\n", i, SSRecord[CurrIndexSSTable].u_rec[i].flow_id, SSRecord[CurrIndexSSTable].u_rec[i].sched_type, SSRecord[CurrIndexSSTable].u_rec[i].gsize, SSRecord[CurrIndexSSTable].u_rec[i].ginterval);#endif } for (i = 0; i < DownSize; i++) { //$A20 SSRecord[CurrIndexSSTable].d_rec[i].sched_type = DownEntry[i].downstream_record.sched_type; SSRecord[CurrIndexSSTable].d_rec[i].gsize = DownEntry[i].downstream_record.gsize; SSRecord[CurrIndexSSTable].d_rec[i].ginterval = DownEntry[i].downstream_record.ginterval; SSRecord[CurrIndexSSTable].d_rec[i].max_qsize = DownEntry[i].downstream_record.max_qsize; SSRecord[CurrIndexSSTable].d_rec[i].PHS_profile = DownEntry[i].downstream_record.PHS_profile; SSRecord[CurrIndexSSTable].d_rec[i].flow_id = next_flowid; SSRecord[CurrIndexSSTable].d_rec[i].latency = DownEntry[i].downstream_record.latency; DownEntry[i].downstream_record.flow_id = next_flowid; SSRecord[CurrIndexSSTable].d_rec[i].classifier.src_ip = DownEntry[i].downstream_record.classifier.src_ip; SSRecord[CurrIndexSSTable].d_rec[i].classifier.dst_ip = DownEntry[i].downstream_record.classifier.dst_ip; SSRecord[CurrIndexSSTable].d_rec[i].classifier.pkt_type = DownEntry[i].downstream_record.classifier.pkt_type; //$A20 SSRecord[CurrIndexSSTable].d_rec[i].packet_list = 0; SSRecord[CurrIndexSSTable].d_rec[i].pkt = 0; SSRecord[CurrIndexSSTable].d_rec[i].alloc_list = 0; SSRecord[CurrIndexSSTable].d_rec[i].state = 0; /* Token bucket support */ //#ifdef RATE_CONTROL //--------------------------------------------------------------------------- SSRecord[CurrIndexSSTable].d_rec[i].ratecontrol = DownEntry[i].downstream_record.ratecontrol; SSRecord[CurrIndexSSTable].d_rec[i].tokenq_ = new PacketQueue; SSRecord[CurrIndexSSTable].d_rec[i].rate_ = DownEntry[i].downstream_record.rate_; /* printf("cindex = %d findex = %d rate = %lf\n", CurrIndexSSTable, i, SSRecord[CurrIndexSSTable].d_rec[i].rate_); */ SSRecord[CurrIndexSSTable].d_rec[i].tokenqlen_ = DownEntry[i].downstream_record.tokenqlen_;; /* printf("cindex = %d findex = %d qlen = %d\n", CurrIndexSSTable, i, SSRecord[CurrIndexSSTable].d_rec[i].tokenqlen_); */ SSRecord[CurrIndexSSTable].d_rec[i].bucket_ = DownEntry[i].downstream_record.bucket_;; /* printf("cindex = %d findex = %d bucket = %d\n", CurrIndexSSTable, i, SSRecord[CurrIndexSSTable].d_rec[i].bucket_); */ SSRecord[CurrIndexSSTable].d_rec[i].tokens_ = 0; SSRecord[CurrIndexSSTable].d_rec[i].init_ = 1; //#endif //---------------------------------------------------------------------------------------- SSRecord[CurrIndexSSTable].d_rec[i].util_total_bytes_DS = 0; SSRecord[CurrIndexSSTable].d_rec[i].util_total_pkts_DS = 0; SSRecord[CurrIndexSSTable].d_rec[i].total_pkts_dropped = 0; SSRecord[CurrIndexSSTable].d_rec[i].dropped_tokenq = 0; SSRecord[CurrIndexSSTable].d_rec[i].dsq_delay = 0; SSRecord[CurrIndexSSTable].d_rec[i].dropped_dsq = 0; SSRecord[CurrIndexSSTable].d_rec[i].num_qsamples = 0; next_flowid++;#ifdef TRACE_BS printf("mac-802_16bs:register_to_bs: registered additional DS flow(%d), sched_type:%d, gsize:%d, ginterval%f\n", SSRecord[CurrIndexSSTable].d_rec[i].flow_id, SSRecord[CurrIndexSSTable].d_rec[i].sched_type, SSRecord[CurrIndexSSTable].d_rec[i].gsize, SSRecord[CurrIndexSSTable].d_rec[i].ginterval);#endif } CurrIndexSSTable++; return index_; } /*****************************************************************************Packet coming up from PHY layer...*****************************************************************************//*! Packet coming up from PHY layer... */void Mac802_16BS::sendUp(Packet* p) { struct hdr_cmn *ch = HDR_CMN(p); #ifdef TRACE_BS //----------------------------------------------------------- printf("BS:sendUp(%.10lf): BS this frame (size:%d) has arrived\n", Scheduler::instance().clock(),ch->size());#endif //---------------------------------------------------------------------- /* Detect if there is any collision happened. should not happen...? */ if (rx_state_ == MAC_IDLE) { SET_RX_STATE(MAC_RECV); /* Change the state to recv. */ pktRx_ = p; /* Save the packet for timer reference. */ /* Schedule the reception of this packet, since we just see the packet header. */ double rxtime = TX_Time(p,UPSTREAM); assert(rxtime >= 0); //printf("rxtime = %.10lfn",rxtime); #ifdef TRACE_BS //------------------------------------------------------------------------ printf("BS:sendUp(%.10lf): Scheduled the rx time for this packet at %.10lf\n", Scheduler::instance().clock(),rxtime);#endif //----------------------------------------------------------------------------------- /* Start the timer for receiving, will end when receiving finishes. */ //printf("BS will finish at %lf\n",Scheduler::instance().clock()+rxtime); mhRxPkt_.start((Packet*) &rxintr_, rxtime); } else { /* Note: we don't take the channel status into account, ie. no collision, as collision should not happen... */#ifdef TRACE_BS //--------------------------------------------------------------------- printf("BS:sendUp(%.10lf): receiving, but the channel is not idle ???\n", Scheduler::instance().clock());#endif //-------------------------------------------------------------------------------- AckTime = Scheduler::instance().clock(); //fprintf(stderr,"collision at %lf\n",Scheduler::instance().clock()); collision = 1; Packet::free(p); }}/**************************************************************************** * void Mac802_16BS::RecvFrame(Packet* p, int concat_flag) * * Function: * Called from the recvHandler when a frame has arrived on the upstream * channel. * Needed to make sure we increment byte stats only once as * this routine is reentered if the frame is concatonated * static int RecvFrameEntered = 0; T This routine will invoke HandleInData or HandleInMgmt .... * * Parameters: * Packet *p: A packet that already has been adjusted for all headers * int 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. * * Design Notes: * * * *************************************************************************//*! Called from the recvHandler when a frame has arrived on the upstream channel. Needed to make sure we increment byte stats only once as this routine is reentered if the frame is concatonated
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -