?? mac-802_16-fsm.cc
字號:
{ if (UpFlowTable[tbindex].debug) printf("SS%d(flow-id %d):beffort_waitformap(%lf): entered with event %d \n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id, Scheduler::instance().clock(),e); switch(e) { case PKT_ARRIVAL:#ifdef TIMINGS// printf("1 %lf %d %d 3\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)) { turn_off_contention(tbindex); UpFlowTable[tbindex].state = BEFFORT_TOSEND; beffort_tosend(tbindex, SEND_PKT, p); } else if ( CanUnicastReqBeSent(tbindex)) { turn_off_contention(tbindex); UpFlowTable[tbindex].state = BEFFORT_TOSENDREQ; beffort_tosendreq(tbindex, SEND_UREQ, p); } else if ( CanContentionReqBeSent(tbindex)) { UpFlowTable[tbindex].state = BEFFORT_CONTENTION; if (UpFlowTable[tbindex].contention_on) beffort_contention(tbindex, CONTENTION_SLOTS, p); else beffort_contention(tbindex, CONTENTION_ON, p); } /*$A11 else if (DataGrantPending(tbindex)) { turn_off_contention(tbindex); UpFlowTable[tbindex].state = BEFFORT_REQSENT; }*/ break; default: printf("SS%d(flow-id %d) BEFFORT-WAITFORMAP state error: Unknown event received\n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id); break; } return 1;}/**************************************************************************************************************************************************/int Mac802_16SS::beffort_tosend(char tbindex, EventType e, Packet* p){ double etime, current_time; Packet* t; if (UpFlowTable[tbindex].debug) printf("SS%d(flow-id %d):beffort_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); current_time = Scheduler::instance().clock(); //TESTE //fprintf(stderr,"beffort_tosend %d em %lf evento %p com delay %f para %lf\n",tbindex,current_time,&UpFlowTable[tbindex].intr,etime,etime+current_time); mhSSSend_.start((Packet *)(&UpFlowTable[tbindex].intr), etime ); 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):beffort_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,"beffort_tosend %d send_timer em %lf\n",tbindex,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 = BEFFORT_DECISION; t = deque_pkt(tbindex); UpFlowTable[tbindex].pkt = t;#ifdef TIMINGS//We will log this next in BEFFORT_DECI// printf("2 %lf %d %d 1\n",Scheduler::instance().clock(),// UpFlowTable[tbindex].upstream_record.flow_id,ss_id); // timingsTrace(t,2);#endif beffort_decision(tbindex, PKT_ARRIVAL, t); } else UpFlowTable[tbindex].state = BEFFORT_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) BEFFORT-TOSEND state error: Unknown event received\n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id); break; } return 1;}/**************************************************************************************************************************************************/int Mac802_16SS::beffort_tosendreq(char tbindex, EventType e, Packet* p){ double etime,current_time; if (UpFlowTable[tbindex].debug) printf("SS%d(flow-id %d) :beffort_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); } mhReq_.start((Packet*)(&UpFlowTable[tbindex].intr), etime); current_time = Scheduler::instance().clock(); 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):beffort_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(); UpFlowTable[tbindex].req_time = 999999.0; UpFlowTable[tbindex].state = BEFFORT_TOSEND; beffort_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"); } // SendReq(tbindex, p); UpFlowTable[tbindex].state = BEFFORT_REQSENT; break; default: printf("SS%d(flow-id %d) BEFFORT-TOSENDREQ state error: Unknown event received\n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id); break; } return 1;} /**************************************************************************************************************************************************/ int Mac802_16SS::beffort_reqsent(char tbindex, EventType e, Packet* p){ if (UpFlowTable[tbindex].debug) printf("SS%d(flow-id %d) BEFFORT_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 = BEFFORT_TOSEND; turn_off_contention(tbindex); beffort_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 = BEFFORT_DECISION; nrtpoll_decision(tbindex, PKT_ARRIVAL, t); } else UpFlowTable[tbindex].state = BEFFORT_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 = BEFFORT_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 = BEFFORT_DECISION; beffort_decision(tbindex, PKT_ARRIVAL, p); }*/ break; default: printf("SS%d(flow-id %d) BEFFORT-REQSENT state error: Unknown event received\n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id); break; } r
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -