?? mac-802_16-ss.cc
字號:
/****************************************************************************** * WiMAX module * * Copyright (C) 2008 Juliana Freitag Borin, Flavio Kubota and Nelson L. * S. da Fonseca - wimaxgroup@lrc.ic.unicamp.br * * This program is a free result: you can redistribute it and/or modify * it under the terms of the UOL Public License Version 1 or (at your * option) any later version. The license terms are available at * http://bolsapesquisa.uol.com.br/lpu.jhtm. * * This file contains the SS object class method implementations * * Revisions: * $A0: 4/2/03: changed total_num_sent_bytes and * total_num_rx_bytes to doubles. * (changed all printf formats) * $A1: 6/23/2003: Needed to fprintf the app bytes counts as a * double instead of an integer * $A2: 7/16/04: Stat counters for #ACKs and #ACKs filtered * $A3: 9/4/04: Need to have the SS send a rng-req randomly * (before fixed time- caused lots collisions) * $A4 9/28/04 : Changed ch->ptype_ from PT_MAC to a PT_802_16xxx * $A5 2/17/2005 upstream rate control (Viraj) * $A6 3/5/05: changed meaning/use of max-concat-thresh param * It now represents the max number of packets * that can be inserted in a concat frame. A * value of 1 is the same as turning off concat. * $A7 3/8/05: in SendReq, the slots is a u_char but it temporarily * might need to be > 255. Changed to u int and made sure * to set mac_param to uchar * $A8 3/9/05: Added packetTrace capability (just like in BS) * Note: currently won't trace fragments- * To see changes, search for PACKET_TRACE * $A9 3/11/05: TODO: We currently might send a piggybacked concat request- * I am checking to see if this is allowed. * $A10 3/11/05: NOW define the CONCAT_THRESHOLD parameter as the max * number of packets allowed to be carried in a concatonated frame. * If this param is 0 or 1, it disables concatonation. * $A11 03/23/05: We were deleting the MAP packet too early. * $A12: 03/26/05: Fixed jitter calculation * $A13: 03/27/05: Bug with default upstream index * $A14: 04/30/05: Added TIMINGS.dat trace. See the method below * timingsTrace() for documentation. * SEarch for TIMINGS to see all code that was changed in this file. * $A15: 03/15/06: (J. Freitag) included non-real-time service * $A16: 03/31/06: (J. Freitag) included downlink QoS services * $A17: 08/30/06: (J. Freitag) QoS parameters (latency and minimum bandwidth) for scheduling services * $A18: 09/19/06: (J. Freitag) included incremental bandwidth request * $A19: 10/12/06: (J. Freitag) changed the code to permit rtPS and nrtPS to send concatenated packets * $A20: 10/19/06: (J. Freitag) before sending concatenated packets it must be checked how many slots * were allocated for the current grant. In the previus implementation the * SS would send as many packets as it requested bw for in the previous SendReq. * $A21: 11/22/06: (J. Freitag) replaced u_char mac_param; by u_int16_t mac_param; in 802_16_frame_hdr * in order to permit bw requests greater than 255 slots * $A22: 04/27/07: (J. Freitag) included extended-real-time service * $A23: 05/07/07: (J. Freitag) changed bandwidht requests so that they are made in terms of the number of * bytes, instead of the number of slots. * $A24: 06/12/07: (J. Freitag) excluded function set-default() and simplified the way we set the default * upstream connection * $A25: 07/10/07: (J. Freitag) included periodic aggregate bandwidth request * $A26: 08/13/07: (J. Freitag) excluded the DataGrantPending, since in the 802.16 standard * the SSs has no knowledge about the pending grants in the BS queues. *****************************************************************************//*! \file mac-802_16-ss.cc This file contains the SS object class method implementations */ #include "mac-802_16.h"#include "random.h"#include <stdio.h>#include "ping.h"/*===============================MACROS=========================*///$A5#define US_RATE_CONTROL 1//Turns on timing logs//#define TIMINGS 1//Note: this will trace MAC message data, but no framing layer overhead//#define TRACE_SS_UP_DATA 0//#define TRACE_SS_DOWN_DATA 0//To turn on packet tracing//#define PACKET_TRACE 1//Define this to 1 so the final stats are 1 line rather than4 lines of text...#define SHORT_STATS 1extern int lan_num;extern Mac802_16BS* bs_arr[NUM_802_16_LANS];#define SET_RX_STATE(x) \{ \ rx_state_ = (x); \}#define SET_TX_STATE(x) \{ \ tx_state_ = (x); \}/*===============================END MACROS=============================*//************************************************************************* TCL Hooks for the simulator*************************************************************************//*! TCL Hooks for the simulator */static class Mac802_16SSClass : public TclClass {public: Mac802_16SSClass() : TclClass("Mac/802_16SS") {} TclObject* create(int, const char*const*) { return (new Mac802_16SS); }} class_mac_802_16ss;/*************************************************************************CONSTRUCTOR FUNCTION*************************************************************************//*! Constructor Function */Mac802_16SS::Mac802_16SS() : Mac802_16(), mhSSRng_(this), mhSSSend_(this), mhReq_(this){ /* Will not be having service-flow information here...So, using command function to set the service-flow parameters... */ collision = 0; SizeUpFlowTable = 0; SizeDownFlowTable = 0; default_upstream_index_ = 0; default_dstream_index_ = 0; map_acktime = -1.0; debug_ss = 0; priority = 0; SndList = 0; ReqList = 0; last_dmptime = 0; rng_ = new RNG; rng_->set_seed(RNG::HEURISTIC_SEED_SOURCE); UGSswitch[0] = &Mac802_16SS::ugs_idle; UGSswitch[1] = &Mac802_16SS::ugs_decision; UGSswitch[2] = &Mac802_16SS::ugs_tosend; UGSswitch[3] = &Mac802_16SS::ugs_waitformap; RTPOLLswitch[0] = &Mac802_16SS::rtpoll_idle; RTPOLLswitch[1] = &Mac802_16SS::rtpoll_decision; RTPOLLswitch[2] = &Mac802_16SS::rtpoll_tosend; RTPOLLswitch[3] = &Mac802_16SS::rtpoll_waitformap; RTPOLLswitch[4] = &Mac802_16SS::rtpoll_tosendreq; //$A26 RTPOLLswitch[5] = &Mac802_16SS::rtpoll_reqsent; //$A22 ERTPOLLswitch[0] = &Mac802_16SS::ertpoll_idle; ERTPOLLswitch[1] = &Mac802_16SS::ertpoll_decision; ERTPOLLswitch[2] = &Mac802_16SS::ertpoll_tosend; ERTPOLLswitch[3] = &Mac802_16SS::ertpoll_waitformap; ERTPOLLswitch[4] = &Mac802_16SS::ertpoll_tosendreq; //$A15 NRTPOLLswitch[0] = &Mac802_16SS::nrtpoll_idle; NRTPOLLswitch[1] = &Mac802_16SS::nrtpoll_decision; NRTPOLLswitch[2] = &Mac802_16SS::nrtpoll_tosend; NRTPOLLswitch[3] = &Mac802_16SS::nrtpoll_waitformap; NRTPOLLswitch[4] = &Mac802_16SS::nrtpoll_tosendreq; NRTPOLLswitch[5] = &Mac802_16SS::nrtpoll_reqsent; NRTPOLLswitch[6] = &Mac802_16SS::nrtpoll_contention; BEFFORTswitch[0] = &Mac802_16SS::beffort_idle; BEFFORTswitch[1] = &Mac802_16SS::beffort_decision; BEFFORTswitch[2] = &Mac802_16SS::beffort_tosend; BEFFORTswitch[3] = &Mac802_16SS::beffort_waitformap; BEFFORTswitch[4] = &Mac802_16SS::beffort_tosendreq; BEFFORTswitch[5] = &Mac802_16SS::beffort_reqsent; BEFFORTswitch[6] = &Mac802_16SS::beffort_contention; //$A5 //BEFFORTswitch[7] = &Mac802_16SS::beffort_ratecheck; // //STATISTICS num_pkts = 0; num_bytes = 0; total_num_sent_pkts =0; /* total Num of packets sent */ total_num_sent_bytes =0; /* total Num of bytes received */ total_num_rx_pkts =0; /* total Num of packets received */ total_num_rx_bytes =0; /* total Num of bytes received */ total_num_BW_bytesDOWN =0; total_num_BW_bytesUP =0; total_num_appbytesUS = 0; /* Total num of upper-layer data transmitted on US at SS*/ total_num_appbytesDS = 0; /* Total num of upper-layer data received on DS at SS*/ total_num_frag = 0; total_num_collisions = 0; last_BWCalcTime = Scheduler::instance().clock(); total_packets_dropped =0; /* total Num of packets dropped */ total_collision_drops = 0; /* Total num of packets dropped due to transmission attempt exceeding 16 */ total_queue_drops = 0; /* Total num of packets dropped due to service-flow queue overflow */ my_lan = lan_num - 1; #ifdef TCP_DELAY_BIND_ALL //--------------------------------------------------#else //---------------------------------------------------------------------- bind("total_SS_bytes_sent", &total_num_sent_bytes); //bind("total_SS_pkts_sent", &total_num_sent_bytes);#endif//----------------------------------------------------------------------}/**************************************************************************************************************************************************/int Mac802_16SS::command(int argc, const char*const* argv){ char f = 0; char k; //printf("\nmac-802_16ss:command: entered argc this many: %d, last arg is :%s",argc,argv[1]); if (argc == 21) { //SizeUpFlowTable on entry is 0 and on exit will be the number of flows for this SS if (strcmp(argv[1], "insert-upflow") == 0) { Initialize_entry(0, SizeUpFlowTable); UpFlowTable[SizeUpFlowTable].upstream_record.sched_type = (SchedType)atoi(argv[2]); UpFlowTable[SizeUpFlowTable].upstream_record.classifier.src_ip = atoi(argv[3]); UpFlowTable[SizeUpFlowTable].upstream_record.classifier.dst_ip = atoi( argv[4]); UpFlowTable[SizeUpFlowTable].upstream_record.classifier.pkt_type = (packet_t) atoi(argv[5]); UpFlowTable[SizeUpFlowTable].upstream_record.PHS_profile = (PhsType) atoi(argv[6]); // printf("\nmac-802_16ss:command: flow sched_type:%d, src_ip:%d, dst_ip:%d, pkt_type:%d",// UpFlowTable[SizeUpFlowTable].upstream_record.sched_type,// UpFlowTable[SizeUpFlowTable].upstream_record.classifier.src_ip,// UpFlowTable[SizeUpFlowTable].upstream_record.classifier.dst_ip,// UpFlowTable[SizeUpFlowTable].upstream_record.classifier.pkt_type); f = atoi(argv[7]); if (f) set_bit(&UpFlowTable[SizeUpFlowTable].upstream_record.flag, FRAG_ENABLE_BIT,ON); f = atoi(argv[8]); if (f) set_bit(&UpFlowTable[SizeUpFlowTable].upstream_record.flag, CONCAT_ENABLE_BIT,ON); //$A10 UpFlowTable[SizeUpFlowTable].max_concat_threshhold = ((u_int16_t) atoi(argv[9])-1); //If CONCAT_THRESHOLD-1 is <= 0, just turn off CONCATONATION. if (bit_on(UpFlowTable[SizeUpFlowTable].upstream_record.flag,CONCAT_ENABLE_BIT) && (UpFlowTable[SizeUpFlowTable].max_concat_threshhold <= 0)) {//$A10 set_bit(&UpFlowTable[SizeUpFlowTable].upstream_record.flag, CONCAT_ENABLE_BIT,OFF);// printf(" WARNING: TURNING OFF CONCATONATION since max_concat_threshhold =%d\n",// UpFlowTable[SizeUpFlowTable].max_concat_threshhold); // printf("Incorrect value for max_concat_threshhold specified, exiting\n");// exit(1); } f = atoi(argv[10]); if (f) set_bit(&UpFlowTable[SizeUpFlowTable].upstream_record.flag, PIGGY_ENABLE_BIT,ON); UpFlowTable[SizeUpFlowTable].upstream_record.gsize = (u_int16_t) atoi(argv[11]); UpFlowTable[SizeUpFlowTable].upstream_record.ginterval = (double) atof(argv[12]); //$A17 UpFlowTable[SizeUpFlowTable].upstream_record.latency = (double) atof(argv[13]); UpFlowTable[SizeUpFlowTable].upstream_record.min_bw = (u_int32_t) atoi(argv[14]); UpFlowTable[SizeUpFlowTable].upstream_record.min_bw /= 8; //$A25 UpFlowTable[SizeUpFlowTable].aggreqinterval = (u_int16_t) atoi(argv[15]);//$A13// if (f)// {// set_default(SizeUpFlowTable);// } //$A24 //set_default(); f = atoi(argv[16]); if (f) { if (debug_ss) printf("Mac802_16SS:set_default: Find default upstream flow: SizeUpFlowTable:%d\n",SizeUpFlowTable); default_upstream_index_ = SizeUpFlowTable; } UpFlowTable[SizeUpFlowTable].packet_list = 0; UpFlowTable[SizeUpFlowTable].max_qsize = atoi(argv[17]); UpFlowTable[SizeUpFlowTable].debug = atoi(argv[18]); //$A5 UpFlowTable[SizeUpFlowTable].ratecontrol = (char)(atoi(argv[19])); UpFlowTable[SizeUpFlowTable].rate_ = (double) atof(argv[20]); UpFlowTable[SizeUpFlowTable].state = 0; UpFlowTable[SizeUpFlowTable].not_requested_pkts = 0; UpFlowTable[SizeUpFlowTable].req_counter = 0;//Make sure this is at the end SizeUpFlowTable++; return TCL_OK; } } else if (argc == 2) { if (strcmp(argv[1],"start") == 0) { if (debug_ss) printf("SS%d :Starting\n",ss_id); bs_addr = bs_arr[my_lan]->register_to_bs(index_, priority, default_upstream_index_, default_dstream_index_, UpFlowTable, SizeUpFlowTable, DownFlowTable, SizeDownFlowTable); if (debug_ss) { printf("SS%d :Flows\n",ss_id); print_classifiers(); } /* Start the timer to send Ranging requests...*/ /* $A3 : add some randomness. This will reduce the frequency but that's ok */ double random_delay = Random::uniform(.01,3); mhSSRng_.start((Packet *) (&rintr), (rng_freq+random_delay)); return TCL_OK; } } else if (argc == 3) { if (strcmp(argv[1],"BS") == 0) { return TCL_OK; } else if (strcmp(argv[1],"dump-BW-ss") == 0) { (void)dumpBWSS((char *)argv[2]); return TCL_OK; } else if (strcmp(argv[1],"dump-final-ss-stats") == 0) { (void)dumpFinalSSStats((char *)argv[2]); return TCL_OK; } else if (strcmp(argv[1],"dump-jitter-ss") == 0) { return TCL_OK; } /*Modification included by Juliana Freitag else if(strcmp(argv[1], "nodes") == 0) { if(cache_) return TCL_ERROR; cache_node_count_ = atoi(argv[2]); cache_ = new Host[cache_node_count_ + 1]; assert(cache_); bzero(cache_, sizeof(Host) * (cache_node_count_+1 )); return TCL_OK;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -