diff -Naur ns-2.32/mac/mac-802_11.cc modified-ns-2.32/mac/mac-802_11.cc --- ns-2.32/mac/mac-802_11.cc 2006-01-30 13:27:51.000000000 -0800 +++ modified-ns-2.32/mac/mac-802_11.cc 2007-12-10 18:21:52.000000000 -0800 @@ -164,6 +164,8 @@ parent->bind("CWMax_", &CWMax); parent->bind("SlotTime_", &SlotTime); parent->bind("SIFS_", &SIFSTime); + parent->bind("BeaconInterval_", &BeaconInterval); + parent->bind("PreambleLength_", &PreambleLength); parent->bind("PLCPHeaderLength_", &PLCPHeaderLength); parent->bind_bw("PLCPDataRate_", &PLCPDataRate); @@ -179,7 +181,14 @@ parent->bind("RTSThreshold_", &RTSThreshold); parent->bind("ShortRetryLimit_", &ShortRetryLimit); parent->bind("LongRetryLimit_", &LongRetryLimit); + parent->bind("ScanType_", &ScanType); + parent->bind("ProbeDelay_", &ProbeDelay); + parent->bind("MaxChannelTime_", &MaxChannelTime); + parent->bind("MinChannelTime_", &MinChannelTime); + parent->bind("ChannelTime_", &ChannelTime); } + + /* ====================================================================== Mac Class Functions @@ -187,7 +196,7 @@ Mac802_11::Mac802_11() : Mac(), phymib_(this), macmib_(this), mhIF_(this), mhNav_(this), mhRecv_(this), mhSend_(this), - mhDefer_(this), mhBackoff_(this) + mhDefer_(this), mhBackoff_(this), mhBeacon_(this), mhProbe_(this) { nav_ = 0.0; @@ -195,7 +204,12 @@ tx_active_ = 0; eotPacket_ = NULL; pktRTS_ = 0; - pktCTRL_ = 0; + pktCTRL_ = 0; + pktBEACON_ = 0; + pktASSOCREP_ = 0; + pktASSOCREQ_ = 0; + BeaconTxtime_ = 0; + infra_mode_ = 0; cw_ = phymib_.getCWMin(); ssrc_ = slrc_ = 0; // Added by Sushmita @@ -204,6 +218,19 @@ sta_seqno_ = 1; cache_ = 0; cache_node_count_ = 0; + client_list = NULL; + ap_list = NULL; + Pr = 0; + ap_temp = -1; + head = 0; + ap_addr = -1; + associated = 0; + authenticated = 0; + OnMinChannelTime = 0; + OnMaxChannelTime = 0; + Recv_Busy_ = 0; + handoff= 0; +// ssid_ = "0"; // chk if basic/data rates are set // otherwise use bandwidth_ as default; @@ -221,11 +248,11 @@ else dataRate_ = bandwidth_; + bind_bool("bugFix_timer_", &bugFix_timer_); EOTtarget_ = 0; bss_id_ = IBSS_ID; - //printf("bssid in constructor %d\n",bss_id_); } @@ -238,8 +265,26 @@ if (EOTtarget_ == 0) return TCL_ERROR; return TCL_OK; - } else if (strcmp(argv[1], "bss_id") == 0) { - bss_id_ = atoi(argv[2]); + } + if (strcmp(argv[1], "ap") == 0) { + ap_addr = addr(); + bss_id_ = addr(); + infra_mode_ = 1; + mhBeacon_.start((Random::random() % cw_) * + phymib_.getSlotTime()); + return TCL_OK; + } + if (strcmp(argv[1], "ScanType") == 0) { + if (strcmp(argv[2], "ACTIVE") == 0) { + ScanType_ = ACTIVE; + infra_mode_ = 1; + ap_list = NULL; + mhProbe_.start(macmib_.getProbeDelay()); + } else if (strcmp(argv[2], "PASSIVE") == 0) { + ScanType_ = PASSIVE; + mhProbe_.start(macmib_.getChannelTime()); + infra_mode_ = 1; + } return TCL_OK; } else if (strcmp(argv[1], "log-target") == 0) { logtarget_ = (NsObject*) TclObject::lookup(argv[2]); @@ -268,7 +313,6 @@ if (et_ == NULL) return; char *wrk = et_->buffer(); char *nwrk = et_->nbuffer(); - //char *src_nodeaddr = // Address::instance().print_nodeaddr(iph->saddr()); //char *dst_nodeaddr = @@ -327,7 +371,7 @@ fprintf(stderr, "\tpktTx_: %lx, pktRx_: %lx, pktRTS_: %lx, pktCTRL_: %lx, callback: %lx\n", (long) pktTx_, (long) pktRx_, (long) pktRTS_, - (long) pktCTRL_, (long) callback_); + (long) pktCTRL_, (long) pktBEACON_, (long) pktASSOCREQ_, (long) pktASSOCREP_,(long) pktPROBEREQ_, (long) pktPROBEREP_, (long) pktAUTHENTICATE_, (long) callback_); fprintf(stderr, "\tDefer: %d, Backoff: %d (%d), Recv: %d, Timer: %d Nav: %d\n", @@ -348,27 +392,27 @@ struct hdr_mac802_11 *dh = (struct hdr_mac802_11*) hdr; if (dst > -2) { - if ((bss_id() == ((int)IBSS_ID)) || (addr() == bss_id())) { - /* if I'm AP (2nd condition above!), the dh_3a - * is already set by the MAC whilst fwding; if - * locally originated pkt, it might make sense - * to set the dh_3a to myself here! don't know - * how to distinguish between the two here - and - * the info is not critical to the dst station - * anyway! - */ - STORE4BYTE(&dst, (dh->dh_ra)); - } else { - /* in BSS mode, the AP forwards everything; - * therefore, the real dest goes in the 3rd - * address, and the AP address goes in the - * destination address - */ - STORE4BYTE(&bss_id_, (dh->dh_ra)); - STORE4BYTE(&dst, (dh->dh_3a)); - } - } + if (bss_id() == ((int)IBSS_ID)) { + STORE4BYTE(&dst, (dh->dh_ra)); + } else if ( addr() == bss_id_) { + if ( find_client(dst) == 1 || dst == MAC_BROADCAST) { + STORE4BYTE(&dst, (dh->dh_ra)); + } else { + int dst_broadcast; + dst_broadcast = MAC_BROADCAST; + + STORE4BYTE(&dst_broadcast, (dh->dh_ra)); + STORE4BYTE(&dst, (dh->dh_3a)); + dh->dh_fc.fc_to_ds = 1; + dh->dh_fc.fc_from_ds = 1; + } + + } else { + STORE4BYTE(&bss_id_, (dh->dh_ra)); + STORE4BYTE(&dst, (dh->dh_3a)); + } + } return (u_int32_t)ETHER_ADDR(dh->dh_ra); } @@ -423,8 +467,38 @@ switch(mh->dh_fc.fc_type) { case MAC_Type_Management: - drop(p, why); - return; + switch(mh->dh_fc.fc_subtype) { + case MAC_Subtype_Auth: + if((u_int32_t)ETHER_ADDR(mh->dh_ra) == (u_int32_t)index_) { + drop(p, why); + return; + } + break; +// drop(p, why); +// return; + case MAC_Subtype_AssocReq: + if((u_int32_t)ETHER_ADDR(mh->dh_ra) == (u_int32_t)index_) { + drop(p, why); + return; + } + break; + case MAC_Subtype_AssocRep: + break; + case MAC_Subtype_ProbeReq: + if((u_int32_t)ETHER_ADDR(mh->dh_ra) == (u_int32_t)index_) { + drop(p, why); + return; + } + break; + case MAC_Subtype_ProbeRep: + break; + case MAC_Subtype_80211_Beacon: + break; + default: + fprintf(stderr, "invalid MAC Management subtype\n"); + exit(1); + } + break; case MAC_Type_Control: switch(mh->dh_fc.fc_subtype) { case MAC_Subtype_RTS: @@ -452,7 +526,7 @@ (u_int32_t)index_ || (u_int32_t)ETHER_ADDR(mh->dh_ta) == \ (u_int32_t)index_ || - (u_int32_t)ETHER_ADDR(mh->dh_ra) == MAC_BROADCAST) { + ((u_int32_t)ETHER_ADDR(mh->dh_ra) == MAC_BROADCAST && mh->dh_fc.fc_to_ds == 0)) { drop(p,why); return; } @@ -563,6 +637,7 @@ h->handle((Event*) 0); } setTxState(MAC_IDLE); + } void @@ -580,23 +655,113 @@ void Mac802_11::backoffHandler() { + if(addr() != bss_id_ && infra_mode_ == 1) { + if(check_pktPROBEREQ() == 0) + return; + if(check_pktAUTHENTICATE() == 0) + return; + if(check_pktASSOCREQ() == 0) + return; + } + if(pktCTRL_) { assert(mhSend_.busy() || mhDefer_.busy()); return; } + if ( addr() == bss_id_ ) { + if (pktPROBEREP_ && priority_queue[head] == 1) { + if (check_pktPROBEREP() == 0) + return; + } else if (pktBEACON_ && priority_queue[head] == 2) { + if (check_pktBEACON() == 0) { + return; + } + } else if (pktAUTHENTICATE_ && priority_queue[head] == 3) { + if (check_pktAUTHENTICATE() == 0) + return; + } else if(pktASSOCREP_ && priority_queue[head] == 4) { + if (check_pktASSOCREP() == 0) + return; + } + } + if(check_pktRTS() == 0) return; - if(check_pktTx() == 0) return; } void +Mac802_11::BeaconHandler() +{ + + mhBeacon_.start(phymib_.getBeaconInterval()); + sendBEACON(index_); + +} + + +// Probe timer is used for multiple purposes. It can be set to 4 different values +// Probe Delay, MinChannelTime and MaxChannelTime - for Active Scanning +// ChannelTime - Passive Scanning + + + +void +Mac802_11::ProbeHandler() +{ + if (ScanType_ == ACTIVE) { + if ( (bss_id_ == IBSS_ID || handoff == 1) && OnMinChannelTime == 0 && Recv_Busy_ == 0 && OnMaxChannelTime == 0) { + if (strongest_ap() < 0) { // Probe delay over - Active Scan starts here, when the ap_table has not been built yet + sendPROBEREQ(MAC_BROADCAST); + return; + } else { + checkAssocAuthStatus(); // MaxChannelTime Over - Handoff is taking place and ap_table is built, complete authentication and (re)association + return; + } + } + else if (OnMinChannelTime == 1 && Recv_Busy_ == 1 && OnMaxChannelTime == 0) { + // MinChannelTime Over - receiver indicated busy before timer expiry, hence Probe timer should be continued for MaxChannelTime, to reeive all probe responses + OnMinChannelTime = 0; + OnMaxChannelTime = 1; + mhProbe_.start(macmib_.getMaxChannelTime()); + return; + } + else if (OnMinChannelTime == 0 && Recv_Busy_ == 1 && OnMaxChannelTime == 1) { + // MaxChannelTime Over - Active Scanning is over, start authentication and association + OnMaxChannelTime = 0; + Recv_Busy_ = 0; + if (strongest_ap() > -1) + active_scan(); + else + printf("No APs in range\n"); + return; + } + else if (OnMinChannelTime == 1 && Recv_Busy_ == 0 && OnMaxChannelTime == 0) { + //printf("Out of range of any Access Point or channel without APs\n"); + OnMinChannelTime = 0; + deletelist(); // MinChannelTime Over - Delete ap_table + return; + } + } else { + if (ScanType_ == PASSIVE && bss_id_ == IBSS_ID) { + // ChannelTime Over - Passive Scanning is over, start authentication and association + passive_scan(); // + return; + } + } + if (bss_id_ != IBSS_ID && !mhProbe_.busy()) { + // Start Authentication and Association + checkAssocAuthStatus(); + } +} + +void Mac802_11::deferHandler() { assert(pktCTRL_ || pktRTS_ || pktTx_); - + if(check_pktCTRL() == 0) return; assert(mhBackoff_.busy() == 0); @@ -644,10 +809,74 @@ void Mac802_11::send_timer() { + double rTime; switch(tx_state_) { - /* - * Sent a RTS, but did not receive a CTS. - */ + + case MAC_MGMT: + if (pktAUTHENTICATE_) { + assert(pktAUTHENTICATE_); + Packet::free(pktAUTHENTICATE_); + pktAUTHENTICATE_ = 0; + if(addr() == bss_id_) { + if (end() > (head + 1)) { + shift_priority_queue(); + assert(mhBackoff_.busy() == 0); + mhBackoff_.start(cw_, is_idle()); + } else + priority_queue[head] = 0; + } else + checkAssocAuthStatus(); + break; + } + if (pktASSOCREQ_) { + assert(pktASSOCREQ_); + Packet::free(pktASSOCREQ_); + pktASSOCREQ_ = 0; + checkAssocAuthStatus(); + break; + } + if (pktASSOCREP_) { + assert(pktASSOCREP_); + Packet::free(pktASSOCREP_); + pktASSOCREP_ = 0; + if (end() > (head + 1)) { + shift_priority_queue(); + assert(mhBackoff_.busy() == 0); + mhBackoff_.start(cw_, is_idle()); + } else + priority_queue[head] = 0; + break; + } + if (pktPROBEREQ_) { + assert(pktPROBEREQ_); + Packet::free(pktPROBEREQ_); + pktPROBEREQ_ = 0; + break; + } + if (pktPROBEREP_) { + assert(pktPROBEREP_); + Packet::free(pktPROBEREP_); + pktPROBEREP_ = 0; + if (end() > (head + 1)) { + shift_priority_queue(); + assert(mhBackoff_.busy() == 0); + mhBackoff_.start(cw_, is_idle()); + } else + priority_queue[head] = 0; + break; + } + case MAC_BCN: + assert(pktBEACON_); + Packet::free(pktBEACON_); + pktBEACON_ = 0; + if (end() > (head + 1)) { + shift_priority_queue(); + assert(mhBackoff_.busy() == 0); + mhBackoff_.start(cw_, is_idle()); + } else + priority_queue[head] = 0; + break; + case MAC_RTS: RetransmitRTS(); break; @@ -778,6 +1007,7 @@ int Mac802_11::check_pktTx() { + struct hdr_mac802_11 *mh; double timeout; @@ -787,6 +1017,11 @@ return -1; mh = HDR_MAC802_11(pktTx_); + + if (addr() != bss_id_) { + if (handoff == 0) + STORE4BYTE(&bss_id_, (mh->dh_ra)); + } switch(mh->dh_fc.fc_subtype) { case MAC_Subtype_Data: @@ -848,8 +1083,8 @@ rf->rf_fc.fc_protocol_version = MAC_ProtocolVersion; rf->rf_fc.fc_type = MAC_Type_Control; rf->rf_fc.fc_subtype = MAC_Subtype_RTS; - rf->rf_fc.fc_to_ds = 0; - rf->rf_fc.fc_from_ds = 0; + rf->rf_fc.fc_to_ds = 0; + rf->rf_fc.fc_from_ds = 0; rf->rf_fc.fc_more_frag = 0; rf->rf_fc.fc_retry = 0; rf->rf_fc.fc_pwr_mgt = 0; @@ -857,6 +1092,7 @@ rf->rf_fc.fc_wep = 0; rf->rf_fc.fc_order = 0; + //rf->rf_duration = RTS_DURATION(pktTx_); STORE4BYTE(&dst, (rf->rf_ra)); @@ -898,14 +1134,15 @@ cf->cf_fc.fc_type = MAC_Type_Control; cf->cf_fc.fc_subtype = MAC_Subtype_CTS; cf->cf_fc.fc_to_ds = 0; - cf->cf_fc.fc_from_ds = 0; + cf->cf_fc.fc_from_ds = 0; cf->cf_fc.fc_more_frag = 0; cf->cf_fc.fc_retry = 0; cf->cf_fc.fc_pwr_mgt = 0; cf->cf_fc.fc_more_data = 0; cf->cf_fc.fc_wep = 0; cf->cf_fc.fc_order = 0; - + + //cf->cf_duration = CTS_DURATION(rts_duration); STORE4BYTE(&dst, (cf->cf_ra)); @@ -970,7 +1207,7 @@ { hdr_cmn* ch = HDR_CMN(p); struct hdr_mac802_11* dh = HDR_MAC802_11(p); - + u_int32_t dst = ETHER_ADDR(dh->dh_ra); assert(pktTx_ == 0); /* @@ -981,9 +1218,23 @@ dh->dh_fc.fc_protocol_version = MAC_ProtocolVersion; dh->dh_fc.fc_type = MAC_Type_Data; dh->dh_fc.fc_subtype = MAC_Subtype_Data; - - dh->dh_fc.fc_to_ds = 0; - dh->dh_fc.fc_from_ds = 0; + if ( bss_id_ != (int)IBSS_ID ) { + if ( index_ == ap_addr ) { + if (dh->dh_fc.fc_to_ds == 0) { + if (find_client(dst) == 1 || dst == MAC_BROADCAST) { + dh->dh_fc.fc_to_ds = 0; + dh->dh_fc.fc_from_ds = 1; + } + } + } else { + dh->dh_fc.fc_to_ds = 1; + dh->dh_fc.fc_from_ds = 0; + } + } else { + dh->dh_fc.fc_to_ds = 0; + dh->dh_fc.fc_from_ds = 0; + } + dh->dh_fc.fc_more_frag = 0; dh->dh_fc.fc_retry = 0; dh->dh_fc.fc_pwr_mgt = 0; @@ -1099,6 +1350,18 @@ (*rcount)++; + + + if (index_ == 4 && *rcount == 3 && handoff == 0) { + //start handoff process + printf("Client %d: Handoff Attempted\n",index_); + associated = 0; + authenticated = 0; + handoff = 1; + ScanType_ = ACTIVE; + sendPROBEREQ(MAC_BROADCAST); + return; + } if(*rcount >= thresh) { /* IEEE Spec section 9.2.3.5 says this should be greater than or equal */ @@ -1130,6 +1393,125 @@ } } +void +Mac802_11::RetransmitPROBEREP() +{ +double rTime; + + if(mhBackoff_.busy() == 0) { + if(is_idle()) { + if (mhDefer_.busy() == 0) { + /* + * If we are already deferring, there is no + * need to reset the Defer timer. + */ + if (bugFix_timer_) { + mhBackoff_.start(cw_, is_idle(), + phymib_.getDIFS()); + priority_queue[head] = 1; + } + else { + rTime = (Random::random() % cw_) + * (phymib_.getSlotTime()); + mhDefer_.start(phymib_.getDIFS() + + rTime); + } + } + } else { + /* + * If the medium is NOT IDLE, then we start + * the backoff timer. + */ + mhBackoff_.start(cw_, is_idle()); + priority_queue[head] = 1; + + } + + } else { + priority_queue[end()] = 1; + } + +} + +void +Mac802_11::RetransmitAUTHENTICATE() +{ +double rTime; + + if(mhBackoff_.busy() == 0) { + if(is_idle()) { + if (mhDefer_.busy() == 0) { + /* + * If we are already deferring, there is no + * need to reset the Defer timer. + */ + if (bugFix_timer_) { + mhBackoff_.start(cw_, is_idle(), + phymib_.getDIFS()); + priority_queue[head] = 3; + } + else { + rTime = (Random::random() % cw_) + * (phymib_.getSlotTime()); + mhDefer_.start(phymib_.getDIFS() + + rTime); + } + } + } else { + /* + * If the medium is NOT IDLE, then we start + * the backoff timer. + */ + mhBackoff_.start(cw_, is_idle()); + priority_queue[head] = 3; + + } + + } else { + priority_queue[end()] = 3; + } + +} + +void +Mac802_11::RetransmitASSOCREP() +{ +double rTime; + + if(mhBackoff_.busy() == 0) { + if(is_idle()) { + if (mhDefer_.busy() == 0) { + /* + * If we are already deferring, there is no + * need to reset the Defer timer. + */ + if (bugFix_timer_) { + mhBackoff_.start(cw_, is_idle(), + phymib_.getDIFS()); + priority_queue[head] = 4; + } + else { + rTime = (Random::random() % cw_) + * (phymib_.getSlotTime()); + mhDefer_.start(phymib_.getDIFS() + + rTime); + } + } + } else { + /* + * If the medium is NOT IDLE, then we start + * the backoff timer. + */ + mhBackoff_.start(cw_, is_idle()); + priority_queue[head] = 4; + + } + + } else { + priority_queue[end()] = 4; + } + +} /* ====================================================================== Incoming Packet Routines ====================================================================== */ @@ -1158,6 +1540,7 @@ * If the medium is IDLE, we must wait for a DIFS * Space before transmitting. */ + if(mhBackoff_.busy() == 0) { if(is_idle()) { if (mhDefer_.busy() == 0) { @@ -1175,7 +1558,7 @@ mhDefer_.start(phymib_.getDIFS() + rTime); } - } + } } else { /* * If the medium is NOT IDLE, then we start @@ -1184,6 +1567,7 @@ mhBackoff_.start(cw_, is_idle()); } } + } void @@ -1228,6 +1612,11 @@ * Schedule the reception of this packet, in * txtime seconds. */ + if (mhProbe_.busy() && OnMinChannelTime) { + Recv_Busy_ = 1; // Receiver busy indication for Probe Timer + } + + mhRecv_.start(txtime(p)); } else { /* @@ -1250,13 +1639,14 @@ hdr_cmn *ch = HDR_CMN(pktRx_); hdr_mac802_11 *mh = HDR_MAC802_11(pktRx_); u_int32_t dst = ETHER_ADDR(mh->dh_ra); - + u_int32_t ap_dst = ETHER_ADDR(mh->dh_3a); u_int8_t type = mh->dh_fc.fc_type; u_int8_t subtype = mh->dh_fc.fc_subtype; assert(pktRx_); assert(rx_state_ == MAC_RECV || rx_state_ == MAC_COLL); + /* * If the interface is in TRANSMIT mode when this packet * "arrives", then I would never have seen it and should @@ -1323,12 +1713,53 @@ discard(pktRx_, "---"); goto done; } + + + if ( dst == MAC_BROADCAST && mh->dh_fc.fc_to_ds == 1 && mh->dh_fc.fc_from_ds == 1) { + if (addr() != bss_id_) { + discard(pktRx_, "---"); + goto done; + } + if (addr() == bss_id_ && find_client(ap_dst) == 0) { + discard(pktRx_, "---"); + goto done; + } + } + + if ( addr() != bss_id_ && subtype == MAC_Subtype_ProbeReq) { + discard(pktRx_, "---"); + goto done; + } switch(type) { case MAC_Type_Management: - discard(pktRx_, DROP_MAC_PACKET_ERROR); - goto done; + //discard(pktRx_, DROP_MAC_PACKET_ERROR); + switch(subtype) { + case MAC_Subtype_80211_Beacon: + recvBEACON(pktRx_); + break; + case MAC_Subtype_Auth: + recvAUTHENTICATE(pktRx_); + break; + case MAC_Subtype_AssocReq: + recvASSOCREQ(pktRx_); + break; + case MAC_Subtype_AssocRep: + recvASSOCREP(pktRx_); + break; + case MAC_Subtype_ProbeReq: + recvPROBEREQ(pktRx_); + break; + case MAC_Subtype_ProbeRep: + recvPROBEREP(pktRx_); + break; + default: + fprintf(stderr,"recvTimer1:Invalid MAC Management Subtype %x\n", + subtype); + exit(1); + } + break; case MAC_Type_Control: switch(subtype) { case MAC_Subtype_RTS: @@ -1341,7 +1772,7 @@ recvACK(pktRx_); break; default: - fprintf(stderr,"recvTimer1:Invalid MAC Control Subtype %x\n", + fprintf(stderr,"recvTimer2:Invalid MAC Control Subtype %x\n", subtype); exit(1); } @@ -1352,18 +1783,19 @@ recvDATA(pktRx_); break; default: - fprintf(stderr, "recv_timer2:Invalid MAC Data Subtype %x\n", + fprintf(stderr, "recv_timer3:Invalid MAC Data Subtype %x\n", subtype); exit(1); } break; default: - fprintf(stderr, "recv_timer3:Invalid MAC Type %x\n", subtype); + fprintf(stderr, "recv_timer4:Invalid MAC Type %x\n", subtype); exit(1); } done: pktRx_ = 0; rx_resume(); + } @@ -1554,31 +1986,76 @@ * receiver; we finally push the packet towards the * LL to be added back to my queue - accomplish this * by reversing the direction!*/ - - if ((bss_id() == addr()) && ((u_int32_t)ETHER_ADDR(dh->dh_ra)!= MAC_BROADCAST)&& ((u_int32_t)ETHER_ADDR(dh->dh_3a) != ((u_int32_t)addr()))) { + + + + if ((bss_id() == addr()) && ((u_int32_t)ETHER_ADDR(dh->dh_ra)!= MAC_BROADCAST) && ((u_int32_t)ETHER_ADDR(dh->dh_3a) != ((u_int32_t)addr())) && dh->dh_fc.fc_from_ds == 0) { struct hdr_cmn *ch = HDR_CMN(p); + + u_int32_t dst = ETHER_ADDR(dh->dh_3a); u_int32_t src = ETHER_ADDR(dh->dh_ta); /* if it is a broadcast pkt then send a copy up * my stack also */ + if (dst == MAC_BROADCAST) { uptarget_->recv(p->copy(), (Handler*) 0); } ch->next_hop() = dst; - STORE4BYTE(&src, (dh->dh_3a)); + + if (find_client(dst) == 1 || dst == MAC_BROADCAST) { + STORE4BYTE(&src, (dh->dh_3a)); + } else { + STORE4BYTE(&src, (dh->dh_4a)); + } + ch->addr_type() = NS_AF_ILINK; ch->direction() = hdr_cmn::DOWN; + } + + if ((bss_id() == addr()) && dh->dh_fc.fc_to_ds == 1 && dh->dh_fc.fc_from_ds == 1) { + u_int32_t dst = ETHER_ADDR(dh->dh_3a); + u_int32_t src = ETHER_ADDR(dh->dh_4a); + if (find_client(src)) { + update_client_table(src,0,0); // If the source is from another BSS and it is found in this AP's table, delete the node from the table + } + ch->next_hop() = dst; + STORE4BYTE(&src, (dh->dh_3a)); + ch->addr_type() = NS_AF_ILINK; + ch->direction() = hdr_cmn::DOWN; + } uptarget_->recv(p, (Handler*) 0); + } void Mac802_11::recvACK(Packet *p) { + if (tx_state_ == MAC_MGMT) { + mhSend_.stop(); + if (addr() == bss_id_) { + if (pktASSOCREP_ && priority_queue[head] == 4) { + Packet::free(pktASSOCREP_); + pktASSOCREP_ = 0; + update_client_table(associating_node_,1,1); + } + if (pktPROBEREP_ && priority_queue[head] == 1) { + Packet::free(pktPROBEREP_); + pktPROBEREP_ = 0; + } + if (pktAUTHENTICATE_ && priority_queue[head] == 3) { + Packet::free(pktAUTHENTICATE_); + pktAUTHENTICATE_ = 0; + update_client_table(authenticating_node_,1,0); + } + } + goto done; + } if(tx_state_ != MAC_SEND) { discard(p, DROP_MAC_INVALID_STATE); return; @@ -1605,11 +2082,1140 @@ /* * Backoff before sending again. - */ +// */ + assert(mhBackoff_.busy() == 0); mhBackoff_.start(cw_, is_idle()); +done: + if (addr() == bss_id_) { + if (end() > (head + 1)) { + shift_priority_queue(); + assert(mhBackoff_.busy() == 0); + mhBackoff_.start(cw_, is_idle()); + } else + priority_queue[head] = 0; + } + + tx_resume(); + + mac_log(p); +} + + +/* AP's association table funtions +*/ +void Mac802_11::update_client_table(int num, int auth_status, int assoc_status) { + if (client_list == NULL) { + client_list = (struct client_table*)malloc(sizeof(struct client_table)); + client_list->client_id=num; + client_list->auth_status=auth_status; + client_list->assoc_status=assoc_status; + client_list->next=NULL; + } + else { + push(num, auth_status, assoc_status); + } +// printf("Client List for AP %d\n",index_); +// struct client_table *temp; +// temp = client_list; +// +// while (temp != NULL) { +// printf("Client %d: Authenticated = %d Associated = %d\n", temp->client_id,temp->auth_status,temp->assoc_status,NOW); +// temp=temp->next; +// } +// printf("\n"); + +} + +void Mac802_11::push(int num, int auth_status, int assoc_status) { + struct client_table *temp; + temp = client_list; + while (temp != NULL) { + if (temp->client_id == num) { + temp->auth_status=auth_status; + temp->assoc_status=assoc_status; + return; + } + temp=temp->next; + + if (temp == NULL) { + break; + } + } + + temp = client_list; + while (temp->next != NULL) { + temp=temp->next; + } + temp->next = (struct client_table*)malloc(sizeof(struct client_table)); + temp->next->client_id = num; + temp->next->auth_status=auth_status; + temp->next->assoc_status=assoc_status; + temp->next->next = NULL; +} + +int Mac802_11::find_client(int num) { + struct client_table *temp; + temp = client_list; + while (temp != NULL) { + if (temp->client_id == num && temp->auth_status == 1 && temp->assoc_status == 1) { + return 1; + break; + } + + temp=temp->next; + + if (temp == NULL) { + return 0; + } + } +} + +/* Beacon send and Receive functions +*/ +void +Mac802_11::sendBEACON(int src) +{ + Packet *p = Packet::alloc(); + + hdr_cmn* ch = HDR_CMN(p); + struct beacon_frame *bf = (struct beacon_frame*)p->access(hdr_mac::offset_); + double rTime; + pktBEACON_ = 0; + + ch->uid() = 0; + + + ch->ptype() = PT_MAC; + ch->size() = phymib_.getBEACONlen(); + ch->iface() = -2; + ch->error() = 0; + + bzero(bf, MAC_HDR_LEN); + +/* Note: I had to give a different name for MAC_Subtype_80211_Beacon as MAC_Subtype_80211_Beacon as MAC_Subtype_80211_Beacon is already defined for 802.15.4 with a different value!! (See cmu-trace.cc). +*/ + + bf->bf_fc.fc_protocol_version = MAC_ProtocolVersion; + bf->bf_fc.fc_type = MAC_Type_Management; + bf->bf_fc.fc_subtype = MAC_Subtype_80211_Beacon; + bf->bf_fc.fc_to_ds = 0; + bf->bf_fc.fc_from_ds = 0; + bf->bf_fc.fc_more_frag = 0; + bf->bf_fc.fc_retry = 0; + bf->bf_fc.fc_pwr_mgt = 0; + bf->bf_fc.fc_more_data = 0; + bf->bf_fc.fc_wep = 0; + bf->bf_fc.fc_order = 0; + + int dst = MAC_BROADCAST; + STORE4BYTE(&dst, (bf->bf_ra)); + STORE4BYTE(&src, (bf->bf_ta)); + STORE4BYTE(&ap_addr, (bf->bf_3a)); + + bf->bf_timestamp = Scheduler::instance().clock(); + bf->bf_bcninterval = phymib_.getBeaconInterval(); + + /* store beacon tx time */ + + ch->txtime() = txtime(ch->size(), basicRate_); + + /* calculate beacon duration??? */ + bf->bf_duration = 0; + + pktBEACON_ = p; + + BeaconTxtime_ = txtime(phymib_.getBEACONlen(), basicRate_); + + if(mhBackoff_.busy() == 0) { + if(is_idle()) { + if (mhDefer_.busy() == 0) { + + if (bugFix_timer_) { + mhBackoff_.start(cw_, is_idle(), + phymib_.getDIFS()); + priority_queue[head] = 2; + } + else { + rTime = (Random::random() % cw_) + * (phymib_.getSlotTime()); + mhDefer_.start(phymib_.getDIFS() + + rTime); + } + } + } else { + /* + * If the medium is NOT IDLE, then we start + * the backoff timer. + */ + + mhBackoff_.start(cw_, is_idle()); + priority_queue[head] = 2; + } + } else { + priority_queue[end()] = 2; + } + +} + +int +Mac802_11::check_pktBEACON() +{ + struct beacon_frame *bf = (struct beacon_frame*)pktBEACON_->access(hdr_mac::offset_); + bf->bf_timestamp = Scheduler::instance().clock(); + + struct hdr_mac802_11 *mh; + double timeout; + + assert(mhBackoff_.busy() == 0); + + if(pktBEACON_ == 0) + return -1; + mh = HDR_MAC802_11(pktBEACON_); + + switch(mh->dh_fc.fc_subtype) { + case MAC_Subtype_80211_Beacon: + if(! is_idle()) { + inc_cw(); + mhBackoff_.start(cw_, is_idle()); + return 0; + } + setTxState(MAC_BCN); + timeout = txtime(phymib_.getBEACONlen(), basicRate_); + break; + default: + fprintf(stderr, "check_pktBEACON:Invalid MAC Control subtype\n"); + exit(1); + } + transmit(pktBEACON_, timeout); + + return 0; +} + + +void +Mac802_11::recvBEACON(Packet *p) +{ + struct beacon_frame *bf = (struct beacon_frame*)p->access(hdr_mac::offset_); + + if(tx_state_ != MAC_IDLE) { + discard(p, DROP_MAC_BUSY); + return; + } + u_int32_t bss_id, src; + + double timestamp, beaconint; + struct hdr_cmn *ch = HDR_CMN(p); + bss_id = ETHER_ADDR(bf->bf_3a); + src = ETHER_ADDR(bf->bf_ta); + infra_mode_ = 1; + timestamp = bf->bf_timestamp; + Pr = p->txinfo_.RxPr; + if ( addr() != ap_addr && ScanType_ == PASSIVE) { + if (authenticated == 0 && associated == 0) { + if (find_ap(src,Pr) != 1) { + update_ap_table(src,Pr); + } + } + } + + mac_log(p); +} + +void +Mac802_11::passive_scan() +{ + if ( addr() != ap_addr && ScanType_ == PASSIVE) { + if (authenticated == 0 && associated == 0) { + ap_temp = strongest_ap(); + if (!pktAUTHENTICATE_) + sendAUTHENTICATE(ap_temp); + } + + } +} +void +Mac802_11::active_scan() +{ + + if ( addr() != ap_addr && ScanType_ == ACTIVE) { + if (authenticated == 0 && associated == 0) { + ap_temp = strongest_ap(); + sendAUTHENTICATE(ap_temp); + } + + } +} + + +// Association functions + +void +Mac802_11::sendASSOCREQ(int dst) +{ + Packet *p = Packet::alloc(); + hdr_cmn* ch = HDR_CMN(p); + struct assocreq_frame *acrqf =(struct assocreq_frame*)p->access(hdr_mac::offset_); + + double rTime; + pktASSOCREQ_ = 0; + + ch->uid() = 0; + + + ch->ptype() = PT_MAC; + ch->size() = phymib_.getASSOCREQlen(); + ch->iface() = -2; + ch->error() = 0; + + bzero(acrqf, MAC_HDR_LEN); + + acrqf->acrqf_fc.fc_protocol_version = MAC_ProtocolVersion; + acrqf->acrqf_fc.fc_type = MAC_Type_Management; + acrqf->acrqf_fc.fc_subtype = MAC_Subtype_AssocReq; + acrqf->acrqf_fc.fc_to_ds = 0; + acrqf->acrqf_fc.fc_from_ds = 0; + acrqf->acrqf_fc.fc_more_frag= 0; + acrqf->acrqf_fc.fc_retry = 0; + acrqf->acrqf_fc.fc_pwr_mgt = 0; + acrqf->acrqf_fc.fc_more_data= 0; + acrqf->acrqf_fc.fc_wep = 0; + acrqf->acrqf_fc.fc_order = 0; + + STORE4BYTE(&dst, (acrqf->acrqf_ra)); + STORE4BYTE(&index_, (acrqf->acrqf_ta)); + STORE4BYTE(&dst, (acrqf->acrqf_3a)); + + + ch->txtime() = txtime(ch->size(), basicRate_); + acrqf->acrqf_duration = 0; + + + pktASSOCREQ_ = p; + + if(mhBackoff_.busy() == 0) { + if(is_idle()) { + if (mhDefer_.busy() == 0) { + /* + * If we are already deferring, there is no + * need to reset the Defer timer. + */ + if (bugFix_timer_) { + mhBackoff_.start(cw_, is_idle(), + phymib_.getDIFS()); + } + else { + rTime = (Random::random() % cw_) + * (phymib_.getSlotTime()); + mhDefer_.start(phymib_.getDIFS() + + rTime); + } + } + } else { + /* + * If the medium is NOT IDLE, then we start + * the backoff timer. + */ + mhBackoff_.start(cw_, is_idle()); + } + } +} + +int +Mac802_11::check_pktASSOCREQ() +{ + struct hdr_mac802_11 *mh; + double timeout; + + assert(mhBackoff_.busy() == 0); + + if(pktASSOCREQ_ == 0) + return -1; + mh = HDR_MAC802_11(pktASSOCREQ_); + + switch(mh->dh_fc.fc_subtype) { + case MAC_Subtype_AssocReq: + if(! is_idle()) { + inc_cw(); + mhBackoff_.start(cw_, is_idle()); + return 0; + } + setTxState(MAC_MGMT); + timeout = txtime(phymib_.getASSOCREQlen(), basicRate_) + + DSSS_MaxPropagationDelay + + macmib_.getMaxChannelTime() + + txtime(phymib_.getASSOCREPlen(), basicRate_) + + DSSS_MaxPropagationDelay; + break; + default: + fprintf(stderr, "check_pktASSOCREQ:Invalid MAC Control subtype\n"); + exit(1); + } + transmit(pktASSOCREQ_, timeout); + + + return 0; +} + +void +Mac802_11::sendASSOCREP(int dst) +{ + Packet *p = Packet::alloc(); + hdr_cmn* ch = HDR_CMN(p); + struct assocrep_frame *acrpf =(struct assocrep_frame*)p->access(hdr_mac::offset_); + double rTime; + pktASSOCREP_ = 0; + + ch->uid() = 0; + + + ch->ptype() = PT_MAC; + ch->size() = phymib_.getASSOCREPlen(); + ch->iface() = -2; + ch->error() = 0; + + bzero(acrpf, MAC_HDR_LEN); + + acrpf->acrpf_fc.fc_protocol_version = MAC_ProtocolVersion; + acrpf->acrpf_fc.fc_type = MAC_Type_Management; + acrpf->acrpf_fc.fc_subtype = MAC_Subtype_AssocRep; + acrpf->acrpf_fc.fc_to_ds = 0; + acrpf->acrpf_fc.fc_from_ds = 0; + acrpf->acrpf_fc.fc_more_frag= 0; + acrpf->acrpf_fc.fc_retry = 0; + acrpf->acrpf_fc.fc_pwr_mgt = 0; + acrpf->acrpf_fc.fc_more_data= 0; + acrpf->acrpf_fc.fc_wep = 0; + acrpf->acrpf_fc.fc_order = 0; + + STORE4BYTE(&dst, (acrpf->acrpf_ra)); + STORE4BYTE(&index_, (acrpf->acrpf_ta)); + STORE4BYTE(&index_, (acrpf->acrpf_3a)); + + acrpf->acrpf_statuscode = 0; + ch->txtime() = txtime(ch->size(), basicRate_); + acrpf->acrpf_duration = 0; + + + pktASSOCREP_ = p; + + if(mhBackoff_.busy() == 0) { + if(is_idle()) { + if (mhDefer_.busy() == 0) { + /* + * If we are already deferring, there is no + * need to reset the Defer timer. + */ + if (bugFix_timer_) { + mhBackoff_.start(cw_, is_idle(), + phymib_.getDIFS()); + priority_queue[head] = 4; + } + else { + rTime = (Random::random() % cw_) + * (phymib_.getSlotTime()); + mhDefer_.start(phymib_.getDIFS() + + rTime); + } + } + } else { + /* + * If the medium is NOT IDLE, then we start + * the backoff timer. + */ + mhBackoff_.start(cw_, is_idle()); + priority_queue[head] = 4; + + } + + + } else { + priority_queue[end()] = 4; + } + +} + +int +Mac802_11::check_pktASSOCREP() +{ + struct hdr_mac802_11 *mh; + double timeout; + + assert(mhBackoff_.busy() == 0); + if(pktASSOCREP_ == 0) + return -1; + mh = HDR_MAC802_11(pktASSOCREP_); + switch(mh->dh_fc.fc_subtype) { + case MAC_Subtype_AssocRep: + if(!is_idle()) { + inc_cw(); + mhBackoff_.start(cw_, is_idle()); + return 0; + } + + setTxState(MAC_MGMT); + timeout = txtime(phymib_.getASSOCREPlen(), basicRate_) + + DSSS_MaxPropagationDelay + + phymib_.getSIFS() + + txtime(phymib_.getACKlen(), basicRate_) + + DSSS_MaxPropagationDelay; + + break; + default: + fprintf(stderr, "check_pktASSOCREP:Invalid MAC Control subtype\n"); + exit(1); + } + transmit(pktASSOCREP_, timeout); + + return 0; +} + +void +Mac802_11::recvASSOCREQ(Packet *p) +{ + struct assocreq_frame *acrqf = (struct assocreq_frame*)p->access(hdr_mac::offset_); + + if(tx_state_ != MAC_IDLE) { + discard(p, DROP_MAC_BUSY); + return; + } + u_int32_t bss_id, src; + struct hdr_cmn *ch = HDR_CMN(p); + + bss_id = ETHER_ADDR(acrqf->acrqf_3a); + src = ETHER_ADDR(acrqf->acrqf_ta); + + if (!pktASSOCREP_) { + sendASSOCREP(src); + associating_node_ = src; + } else { + discard(p, DROP_MAC_BUSY); + return; + } + tx_resume(); + + mac_log(p); +} + +void +Mac802_11::recvASSOCREP(Packet *p) +{ + struct assocrep_frame *acrpf = (struct assocrep_frame*)p->access(hdr_mac::offset_); + + assert(pktASSOCREQ_); + Packet::free(pktASSOCREQ_); + pktASSOCREQ_ = 0; + mhSend_.stop(); + + u_int32_t bss_id, src; + u_int16_t statuscode; + struct hdr_cmn *ch = HDR_CMN(p); + + + src = ETHER_ADDR(acrpf->acrpf_ta); + statuscode = acrpf->acrpf_statuscode; + + if (statuscode == 0) { + associated = 1; + deletelist(); + if (handoff) { + handoff = 0; //handoff completed + } + sendACK(src); + + } + if(mhSend_.busy() == 0) + tx_resume(); + + mac_log(p); + + +} + +//Authentication functions + +void +Mac802_11::sendAUTHENTICATE(int dst) +{ + Packet *p = Packet::alloc(); + hdr_cmn* ch = HDR_CMN(p); + struct auth_frame *authf =(struct auth_frame*)p->access(hdr_mac::offset_); + + double rTime; + pktAUTHENTICATE_ = 0; + + ch->uid() = 0; + + + ch->ptype() = PT_MAC; + ch->size() = phymib_.getAUTHENTICATElen(); + ch->iface() = -2; + ch->error() = 0; + + bzero(authf, MAC_HDR_LEN); + + authf->authf_fc.fc_protocol_version = MAC_ProtocolVersion; + authf->authf_fc.fc_type = MAC_Type_Management; + authf->authf_fc.fc_subtype = MAC_Subtype_Auth; + authf->authf_fc.fc_to_ds = 0; + authf->authf_fc.fc_from_ds = 0; + authf->authf_fc.fc_more_frag= 0; + authf->authf_fc.fc_retry = 0; + authf->authf_fc.fc_pwr_mgt = 0; + authf->authf_fc.fc_more_data= 0; + authf->authf_fc.fc_wep = 0; + authf->authf_fc.fc_order = 0; + + + STORE4BYTE(&dst, (authf->authf_ra)); + STORE4BYTE(&index_, (authf->authf_ta)); + if (addr() != bss_id_) + STORE4BYTE(&dst, (authf->authf_3a)); + else + STORE4BYTE(&index_, (authf->authf_3a)); + authf->authf_algono = 0; //Open system authentication + + if (addr() != bss_id_) { + authf->authf_seqno = 1; // + } else { + authf->authf_seqno = 2; // + authf->authf_statuscode = 0; + } + + ch->txtime() = txtime(ch->size(), basicRate_); + if (addr() == bss_id_) { + authf->authf_duration = usec(txtime(phymib_.getACKlen(), basicRate_) + + phymib_.getSIFS()); + } else { + authf->authf_duration = 0; + } + + + pktAUTHENTICATE_ = p; + + if(mhBackoff_.busy() == 0) { + if(is_idle()) { + if (mhDefer_.busy() == 0) { + /* + * If we are already deferring, there is no + * need to reset the Defer timer. + */ + if (bugFix_timer_) { + mhBackoff_.start(cw_, is_idle(), + phymib_.getDIFS()); + priority_queue[head] = 3; + } + else { + rTime = (Random::random() % cw_) + * (phymib_.getSlotTime()); + mhDefer_.start(phymib_.getDIFS() + + rTime); + } + } + } else { + /* + * If the medium is NOT IDLE, then we start + * the backoff timer. + */ + mhBackoff_.start(cw_, is_idle()); + priority_queue[head] = 3; + + } + } else { + priority_queue[end()] = 3; + } + +} + +int +Mac802_11::check_pktAUTHENTICATE() +{ + struct hdr_mac802_11 *mh; + double timeout; + + assert(mhBackoff_.busy() == 0); + + if(pktAUTHENTICATE_ == 0) + return -1; + mh = HDR_MAC802_11(pktAUTHENTICATE_); + + switch(mh->dh_fc.fc_subtype) { + case MAC_Subtype_Auth: + if(! is_idle()) { + inc_cw(); + mhBackoff_.start(cw_, is_idle()); + return 0; + } + setTxState(MAC_MGMT); + if (addr() != bss_id_) { + timeout = txtime(phymib_.getAUTHENTICATElen(), basicRate_) + + DSSS_MaxPropagationDelay // XXX + + macmib_.getMaxChannelTime() + + txtime(phymib_.getAUTHENTICATElen(), basicRate_) + + DSSS_MaxPropagationDelay; + } else { + timeout = txtime(phymib_.getAUTHENTICATElen(), basicRate_) + + DSSS_MaxPropagationDelay // XXX + + phymib_.getSIFS() + + txtime(phymib_.getACKlen(), basicRate_) + + DSSS_MaxPropagationDelay; + } + break; + default: + fprintf(stderr, "check_pktAUTHENTICATE:Invalid MAC Control subtype\n"); + exit(1); + } + + transmit(pktAUTHENTICATE_, timeout); + + return 0; +} + +void +Mac802_11::recvAUTHENTICATE(Packet *p) +{ + struct auth_frame *authf = (struct auth_frame*)p->access(hdr_mac::offset_); + + if (addr() != bss_id_) { + assert(pktAUTHENTICATE_); + Packet::free(pktAUTHENTICATE_); + pktAUTHENTICATE_ = 0; + mhSend_.stop(); + } else { + if ( tx_state_ != MAC_IDLE) { + discard(p, DROP_MAC_BUSY); + return; + } + } + + u_int32_t src; + struct hdr_cmn *ch = HDR_CMN(p); + + + src = ETHER_ADDR(authf->authf_ta); + + if (addr() == ap_addr) { + if (authf->authf_seqno == 1) { + if (!pktAUTHENTICATE_) {// AP is not currently involved in Authentication with any other STA + sendAUTHENTICATE(src); + authenticating_node_ = src; + } else { + discard(p, DROP_MAC_BUSY); + return; + } + } else + printf("Out of sequence\n"); + } else if (authf->authf_seqno == 2 && authf->authf_statuscode == 0) { + authenticated = 1; + if (bss_id_ != ETHER_ADDR(authf->authf_3a) && handoff == 1) { + printf("Client %d: Handoff from AP %d to AP %d\n",index_, bss_id_,ETHER_ADDR(authf->authf_3a)); + } + bss_id_ = ETHER_ADDR(authf->authf_3a); + sendACK(src); + mhProbe_.start(phymib_.getSIFS() + txtime(phymib_.getACKlen(), basicRate_) + macmib_.getMaxChannelTime()); + + } + + if(mhSend_.busy() == 0) + tx_resume(); + + mac_log(p); + +} + +// Active Scanning Functions +void +Mac802_11::sendPROBEREQ(int dst) +{ + Packet *p = Packet::alloc(); + hdr_cmn* ch = HDR_CMN(p); + struct probereq_frame *prrqf =(struct probereq_frame*)p->access(hdr_mac::offset_); + + double rTime; + pktPROBEREQ_ = 0; + + ch->uid() = 0; + + + ch->ptype() = PT_MAC; + ch->size() = phymib_.getPROBEREQlen(); + ch->iface() = -2; + ch->error() = 0; + + bzero(prrqf, MAC_HDR_LEN); + + prrqf->prrqf_fc.fc_protocol_version = MAC_ProtocolVersion; + prrqf->prrqf_fc.fc_type = MAC_Type_Management; + prrqf->prrqf_fc.fc_subtype = MAC_Subtype_ProbeReq; + prrqf->prrqf_fc.fc_to_ds = 0; + prrqf->prrqf_fc.fc_from_ds = 0; + prrqf->prrqf_fc.fc_more_frag= 0; + prrqf->prrqf_fc.fc_retry = 0; + prrqf->prrqf_fc.fc_pwr_mgt = 0; + prrqf->prrqf_fc.fc_more_data= 0; + prrqf->prrqf_fc.fc_wep = 0; + prrqf->prrqf_fc.fc_order = 0; + + + STORE4BYTE(&dst, (prrqf->prrqf_ra)); + STORE4BYTE(&index_, (prrqf->prrqf_ta)); + STORE4BYTE(&dst, (prrqf->prrqf_3a)); + + + ch->txtime() = txtime(ch->size(), basicRate_); + prrqf->prrqf_duration = 0; + + + pktPROBEREQ_ = p; + + if(mhBackoff_.busy() == 0) { + if(is_idle()) { + if (mhDefer_.busy() == 0) { + /* + * If we are already deferring, there is no + * need to reset the Defer timer. + */ + if (bugFix_timer_) { + mhBackoff_.start(cw_, is_idle(), + phymib_.getDIFS()); + } + else { + rTime = (Random::random() % cw_) + * (phymib_.getSlotTime()); + mhDefer_.start(phymib_.getDIFS() + + rTime); + } + } + } else { + /* + * If the medium is NOT IDLE, then we start + * the backoff timer. + */ + mhBackoff_.start(cw_, is_idle()); + + } + } +} + + +int +Mac802_11::check_pktPROBEREQ() +{ + struct hdr_mac802_11 *mh; + double timeout; + + assert(mhBackoff_.busy() == 0); + + if(pktPROBEREQ_ == 0) + return -1; + mh = HDR_MAC802_11(pktPROBEREQ_); + + switch(mh->dh_fc.fc_subtype) { + case MAC_Subtype_ProbeReq: + if(! is_idle()) { + inc_cw(); + mhBackoff_.start(cw_, is_idle()); + return 0; + } + setTxState(MAC_MGMT); + timeout = txtime(phymib_.getPROBEREQlen(), basicRate_) + + DSSS_MaxPropagationDelay; // XXX + break; + default: + fprintf(stderr, "check_pktPROBEREQ:Invalid MAC Control subtype\n"); + exit(1); + } + transmit(pktPROBEREQ_, timeout); + mhProbe_.start(macmib_.getMinChannelTime()); + OnMinChannelTime = 1; + return 0; +} + + + +void +Mac802_11::sendPROBEREP(int dst) +{ + Packet *p = Packet::alloc(); + + hdr_cmn* ch = HDR_CMN(p); + struct proberep_frame *prrpf = (struct proberep_frame*)p->access(hdr_mac::offset_); + + pktPROBEREP_ = 0; + + ch->uid() = 0; + + double rTime; + + ch->ptype() = PT_MAC; + ch->size() = phymib_.getPROBEREPlen(); + ch->iface() = -2; + ch->error() = 0; + + bzero(prrpf, MAC_HDR_LEN); + + prrpf->prrpf_fc.fc_protocol_version = MAC_ProtocolVersion; + prrpf->prrpf_fc.fc_type = MAC_Type_Management; + prrpf->prrpf_fc.fc_subtype = MAC_Subtype_ProbeRep; + prrpf->prrpf_fc.fc_to_ds = 0; + prrpf->prrpf_fc.fc_from_ds = 0; + prrpf->prrpf_fc.fc_more_frag= 0; + prrpf->prrpf_fc.fc_retry = 0; + prrpf->prrpf_fc.fc_pwr_mgt = 0; + prrpf->prrpf_fc.fc_more_data= 0; + prrpf->prrpf_fc.fc_wep = 0; + prrpf->prrpf_fc.fc_order = 0; + + STORE4BYTE(&dst, (prrpf->prrpf_ra)); + STORE4BYTE(&index_, (prrpf->prrpf_ta)); + STORE4BYTE(&index_, (prrpf->prrpf_3a)); + +// prrpf->prrpf_timestamp = Scheduler::instance().clock(); + prrpf->prrpf_bcninterval = phymib_.getBeaconInterval(); + + ch->txtime() = txtime(ch->size(), basicRate_); + prrpf->prrpf_duration = 0; + + pktPROBEREP_ = p; + + if(mhBackoff_.busy() == 0) { + if(is_idle()) { + if (mhDefer_.busy() == 0) { + /* + * If we are already deferring, there is no + * need to reset the Defer timer. + */ + if (bugFix_timer_) { + mhBackoff_.start(cw_, is_idle(), + phymib_.getDIFS()); + priority_queue[head] = 1; + } + else { + rTime = (Random::random() % cw_) + * (phymib_.getSlotTime()); + mhDefer_.start(phymib_.getDIFS() + + rTime); + } + } + } else { + /* + * If the medium is NOT IDLE, then we start + * the backoff timer. + */ + mhBackoff_.start(cw_, is_idle()); + priority_queue[head] = 1; + + } + + } else { + priority_queue[end()] = 1; + } + +} + +int +Mac802_11::check_pktPROBEREP() +{ + struct proberep_frame *prrpf = (struct proberep_frame*)pktPROBEREP_->access(hdr_mac::offset_); + prrpf->prrpf_timestamp = Scheduler::instance().clock(); + + struct hdr_mac802_11 *mh; + double timeout; + + assert(mhBackoff_.busy() == 0); + + if(pktPROBEREP_ == 0) + return -1; + mh = HDR_MAC802_11(pktPROBEREP_); + + switch(mh->dh_fc.fc_subtype) { + case MAC_Subtype_ProbeRep: + if(! is_idle()) { + inc_cw(); + mhBackoff_.start(cw_, is_idle()); + return 0; + } + setTxState(MAC_MGMT); + timeout = txtime(phymib_.getPROBEREPlen(), basicRate_) + + DSSS_MaxPropagationDelay // XXX + + phymib_.getSIFS() + + txtime(phymib_.getACKlen(), basicRate_) + + DSSS_MaxPropagationDelay; + break; + default: + fprintf(stderr, "check_pktPROBEREP:Invalid MAC Control subtype\n"); + exit(1); + } + transmit(pktPROBEREP_, timeout); + + + return 0; +} + + +void +Mac802_11::recvPROBEREQ(Packet *p) +{ + struct probereq_frame *prrqf = (struct probereq_frame*)p->access(hdr_mac::offset_); + + if(tx_state_ != MAC_IDLE) { + discard(p, DROP_MAC_BUSY); + return; + } + u_int32_t bss_id, src; + struct hdr_cmn *ch = HDR_CMN(p); + bss_id = ETHER_ADDR(prrqf->prrqf_3a); + src = ETHER_ADDR(prrqf->prrqf_ta); + + if (!pktPROBEREP_) { + sendPROBEREP(src); + } else { + discard(p, DROP_MAC_BUSY); + return; + } + + tx_resume(); + + mac_log(p); +} + +void +Mac802_11::recvPROBEREP(Packet *p) +{ + struct proberep_frame *prrpf = (struct proberep_frame*)p->access(hdr_mac::offset_); + + assert(pktPROBEREQ_); + mhSend_.stop(); + + u_int32_t bss_id, src; + struct hdr_cmn *ch = HDR_CMN(p); + + Pr = p->txinfo_.RxPr; + src = ETHER_ADDR(prrpf->prrpf_ta); + bss_id = ETHER_ADDR(prrpf->prrpf_ta); + + update_ap_table(src,Pr); + + sendACK(src); + + if(mhSend_.busy() == 0) + tx_resume(); + mac_log(p); + + +} + +void Mac802_11::checkAssocAuthStatus() { + if ( addr() != bss_id_ ) { + if (authenticated == 0 && associated == 0) { + + sendAUTHENTICATE(strongest_ap()); + } + if (authenticated == 1 && associated == 0) { + sendASSOCREQ(bss_id_); + } + } +} + +/* STA's beacon power table funtions +*/ +void Mac802_11::update_ap_table(int num, double power) { + if (ap_list == NULL) { + ap_list = (struct ap_table*)malloc(sizeof(struct ap_table)); + ap_list->ap_id=num; + ap_list->ap_power = power; + ap_list->next=NULL; + } + else { + push_ap(num, power); + } + struct ap_table *temp; + temp = ap_list; +// while (temp != NULL) { +// printf("Client %d: AP %d and %f\t", index_, temp->ap_id,temp->ap_power); +// temp=temp->next; +// } +// printf("\n"); +} + +void Mac802_11::push_ap(int num, double power) { + struct ap_table *temp; + temp = ap_list; + while (temp->next != NULL) { + temp=temp->next; + } + temp->next = (struct ap_table*)malloc(sizeof(struct ap_table)); + temp->next->ap_id = num; + temp->next->ap_power= power; + temp->next->next = NULL; +} + +void Mac802_11::deletelist() { + struct ap_table *temp; + while (ap_list != NULL) { + + temp = ap_list; + ap_list = ap_list->next; + free(temp); + } + +} + +int Mac802_11::strongest_ap() { + struct ap_table *temp; + double max_power; + int ap; + temp = ap_list; + if (ap_list == NULL) + return -1; + max_power = 0; + while (temp != NULL) { + if (temp->ap_power > max_power) { + max_power = temp->ap_power; + ap = temp->ap_id; + } + temp = temp->next; + } + + return ap; +} + +int Mac802_11::find_ap(int num, double power) { + struct ap_table *temp; + temp = ap_list; + while (temp != NULL) { + if (temp->ap_id == num && temp->ap_power == power) { + return 1; + } + + temp=temp->next; + + if (temp == NULL) { + return 0; + } + } +} + +int Mac802_11::end() +{ + int end; + end = head; + while (priority_queue[end] != 0) { + end = end + 1; + } + return end; +} + +void Mac802_11::shift_priority_queue() +{ + int i; + i = head; + while (priority_queue[i] != 0) { + priority_queue[i] = priority_queue[i+1]; + i = i + 1; + } } diff -Naur ns-2.32/mac/mac-802_11.h modified-ns-2.32/mac/mac-802_11.h --- ns-2.32/mac/mac-802_11.h 2006-02-22 05:25:43.000000000 -0800 +++ modified-ns-2.32/mac/mac-802_11.h 2007-11-27 17:16:28.000000000 -0800 @@ -70,6 +70,13 @@ #define MAC_Subtype_ACK 0x0D #define MAC_Subtype_Data 0x00 +#define MAC_Subtype_80211_Beacon 0x08 +#define MAC_Subtype_AssocReq 0x00 +#define MAC_Subtype_AssocRep 0x01 +#define MAC_Subtype_Auth 0x0C +#define MAC_Subtype_ProbeReq 0x04 +#define MAC_Subtype_ProbeRep 0x05 + struct frame_control { u_char fc_subtype : 4; @@ -108,6 +115,78 @@ u_char af_fcs[ETHER_FCS_LEN]; }; +struct beacon_frame { + struct frame_control bf_fc; + u_int16_t bf_duration; + u_char bf_ra[ETHER_ADDR_LEN]; + u_char bf_ta[ETHER_ADDR_LEN]; + u_char bf_3a[ETHER_ADDR_LEN]; + u_int16_t bf_scontrol; + double bf_timestamp; + double bf_bcninterval; + u_int8_t bf_datarates[1]; + u_char bf_fcs[ETHER_FCS_LEN]; +}; + +struct assocreq_frame { + struct frame_control acrqf_fc; + u_int16_t acrqf_duration; + u_char acrqf_ra[ETHER_ADDR_LEN]; + u_char acrqf_ta[ETHER_ADDR_LEN]; + u_char acrqf_3a[ETHER_ADDR_LEN]; + u_int16_t acrqf_scontrol; + u_char acrqf_fcs[ETHER_FCS_LEN]; +}; + +struct assocrep_frame { + struct frame_control acrpf_fc; + u_int16_t acrpf_duration; + u_char acrpf_ra[ETHER_ADDR_LEN]; + u_char acrpf_ta[ETHER_ADDR_LEN]; + u_char acrpf_3a[ETHER_ADDR_LEN]; + u_int16_t acrpf_scontrol; + u_int16_t acrpf_statuscode; + u_char acrpf_fcs[ETHER_FCS_LEN]; +}; + +struct auth_frame { + struct frame_control authf_fc; + u_int16_t authf_duration; + u_char authf_ra[ETHER_ADDR_LEN]; + u_char authf_ta[ETHER_ADDR_LEN]; + u_char authf_3a[ETHER_ADDR_LEN]; + u_int16_t authf_scontrol; + u_int16_t authf_algono; + u_int16_t authf_seqno; + u_int16_t authf_statuscode; + u_char authf_fcs[ETHER_FCS_LEN]; +}; + +struct probereq_frame { + struct frame_control prrqf_fc; + u_int16_t prrqf_duration; + u_char prrqf_ra[ETHER_ADDR_LEN]; + u_char prrqf_ta[ETHER_ADDR_LEN]; + u_char prrqf_3a[ETHER_ADDR_LEN]; + u_int16_t prrqf_scontrol; + u_char prrqf_fcs[ETHER_FCS_LEN]; +}; + +struct proberep_frame { + struct frame_control prrpf_fc; + u_int16_t prrpf_duration; + u_char prrpf_ra[ETHER_ADDR_LEN]; + u_char prrpf_ta[ETHER_ADDR_LEN]; + u_char prrpf_3a[ETHER_ADDR_LEN]; + u_int16_t prrpf_scontrol; + double prrpf_timestamp; + double prrpf_bcninterval; + u_int8_t prrpf_datarates[1]; + u_char prrpf_fcs[ETHER_FCS_LEN]; +}; + + + // XXX This header does not have its header access function because it shares // the same header space with hdr_mac. struct hdr_mac802_11 { @@ -116,10 +195,24 @@ u_char dh_ra[ETHER_ADDR_LEN]; u_char dh_ta[ETHER_ADDR_LEN]; u_char dh_3a[ETHER_ADDR_LEN]; + u_char dh_4a[ETHER_ADDR_LEN]; u_int16_t dh_scontrol; u_char dh_body[1]; // size of 1 for ANSI compatibility }; +struct client_table { + int client_id; + int auth_status; + int assoc_status; + struct client_table *next; +}; + +struct ap_table { + int ap_id; + double ap_power; + struct ap_table *next; +}; + /* ====================================================================== Definitions @@ -138,6 +231,7 @@ inline u_int32_t getCWMin() { return(CWMin); } inline u_int32_t getCWMax() { return(CWMax); } inline double getSlotTime() { return(SlotTime); } + inline double getBeaconInterval() { return(BeaconInterval); } inline double getSIFS() { return(SIFSTime); } inline double getPIFS() { return(SIFSTime + SlotTime); } inline double getDIFS() { return(SIFSTime + 2 * SlotTime); } @@ -149,6 +243,7 @@ inline u_int32_t getPreambleLength() { return(PreambleLength); } inline double getPLCPDataRate() { return(PLCPDataRate); } + inline u_int32_t getPLCPhdrLen() { return((PreambleLength + PLCPHeaderLength) >> 3); } @@ -169,16 +264,32 @@ inline u_int32_t getACKlen() { return(getPLCPhdrLen() + sizeof(struct ack_frame)); } - + inline u_int32_t getBEACONlen() { + return(getPLCPhdrLen() + sizeof(struct beacon_frame)); + } + inline u_int32_t getASSOCREQlen() { + return(getPLCPhdrLen() + sizeof(struct assocreq_frame)); + } + inline u_int32_t getASSOCREPlen() { + return(getPLCPhdrLen() + sizeof(struct assocrep_frame)); + } + inline u_int32_t getAUTHENTICATElen() { + return(getPLCPhdrLen() + sizeof(struct auth_frame)); + } + inline u_int32_t getPROBEREQlen() { + return(getPLCPhdrLen() + sizeof(struct probereq_frame)); + } + inline u_int32_t getPROBEREPlen() { + return(getPLCPhdrLen() + sizeof(struct proberep_frame)); + } private: - - u_int32_t CWMin; u_int32_t CWMax; double SlotTime; double SIFSTime; + double BeaconInterval; u_int32_t PreambleLength; u_int32_t PLCPHeaderLength; double PLCPDataRate; @@ -193,6 +304,9 @@ #define MAC_MaxTransmitMSDULifetime 512 // time units #define MAC_MaxReceiveLifetime 512 // time units + + + class MAC_MIB { public: @@ -202,6 +316,12 @@ u_int32_t RTSThreshold; u_int32_t ShortRetryLimit; u_int32_t LongRetryLimit; + u_int32_t ScanType; + double ProbeDelay; + double MaxChannelTime; + double MinChannelTime; + double ChannelTime; + public: u_int32_t FailedCount; u_int32_t RTSFailureCount; @@ -210,6 +330,11 @@ inline u_int32_t getRTSThreshold() { return(RTSThreshold);} inline u_int32_t getShortRetryLimit() { return(ShortRetryLimit);} inline u_int32_t getLongRetryLimit() { return(LongRetryLimit);} + inline u_int32_t getScanType() { return(ScanType);} + inline double getProbeDelay() { return(ProbeDelay);} + inline double getMaxChannelTime() { return(MaxChannelTime);} + inline double getMinChannelTime() { return(MinChannelTime);} + inline double getChannelTime() { return(ChannelTime);} }; @@ -230,7 +355,8 @@ class Mac802_11 : public Mac { friend class DeferTimer; - + friend class BeaconTimer; + friend class ProbeTimer; friend class BackoffTimer; friend class IFTimer; friend class NavTimer; @@ -252,19 +378,47 @@ protected: void backoffHandler(void); void deferHandler(void); + void BeaconHandler(void); + void ProbeHandler(void); void navHandler(void); void recvHandler(void); void sendHandler(void); void txHandler(void); private: - int command(int argc, const char*const* argv); - + void update_client_table(int num, int auth_status, int assoc_status); + void push(int num, int auth_status, int assoc_status); + int find_client(int num); + void update_ap_table(int num, double power); + void push_ap(int num, double power); + int strongest_ap(); + int find_ap(int num, double power); + void deletelist(); + void passive_scan(); + void active_scan(); + int end(); + void shift_priority_queue(); + void checkAssocAuthStatus(); + int command(int argc, const char*const* argv); + /* In support of bug fix described at * http://www.dei.unipd.it/wdyn/?IDsezione=2435 */ int bugFix_timer_; - + int infra_mode_; + double BeaconTxtime_; + int associated; + int authenticated; + int handoff; + double Pr; + int ap_temp; + int ap_addr; + int associating_node_; + int authenticating_node_; + int ScanType_; + int OnMinChannelTime; + int OnMaxChannelTime; + int Recv_Busy_; /* * Called by the timers. */ @@ -273,7 +427,13 @@ int check_pktCTRL(); int check_pktRTS(); int check_pktTx(); - + int check_pktASSOCREQ(); + int check_pktASSOCREP(); + int check_pktBEACON(); + int check_pktAUTHENTICATE(); + int check_pktPROBEREQ(); + int check_pktPROBEREP(); + /* * Packet Transmission Functions. */ @@ -282,8 +442,17 @@ void sendCTS(int dst, double duration); void sendACK(int dst); void sendDATA(Packet *p); + void sendBEACON(int src); + void sendASSOCREQ(int dst); + void sendASSOCREP(int dst); + void sendPROBEREQ(int dst); + void sendPROBEREP(int dst); + void sendAUTHENTICATE(int dst); void RetransmitRTS(); void RetransmitDATA(); + void RetransmitASSOCREP(); + void RetransmitPROBEREP(); + void RetransmitAUTHENTICATE(); /* * Packet Reception Functions. @@ -292,6 +461,12 @@ void recvCTS(Packet *p); void recvACK(Packet *p); void recvDATA(Packet *p); + void recvBEACON(Packet *p); + void recvASSOCREQ(Packet *p); + void recvASSOCREP(Packet *p); + void recvPROBEREQ(Packet *p); + void recvPROBEREP(Packet *p); + void recvAUTHENTICATE(Packet *p); void capture(Packet *p); void collision(Packet *p); @@ -361,12 +536,18 @@ */ int bss_id_; enum {IBSS_ID=MAC_BROADCAST}; - + enum { + PASSIVE = 0, + ACTIVE = 1 + }; private: double basicRate_; double dataRate_; - + struct client_table *client_list; + struct ap_table *ap_list; + int priority_queue[4]; + int head; /* * Mac Timers */ @@ -377,6 +558,8 @@ DeferTimer mhDefer_; // defer timer BackoffTimer mhBackoff_; // backoff timer + BeaconTimer mhBeacon_; // Beacon Timer + ProbeTimer mhProbe_; //Probe timer, /* ============================================================ Internal MAC State @@ -391,6 +574,12 @@ Packet *pktRTS_; // outgoing RTS packet Packet *pktCTRL_; // outgoing non-RTS packet + Packet *pktBEACON_; //outgoing Beacon Packet + Packet *pktASSOCREQ_; //Association request + Packet *pktASSOCREP_; // Association response + Packet *pktAUTHENTICATE_; //Authentication + Packet *pktPROBEREQ_; //Probe Request + Packet *pktPROBEREP_; //Probe Response u_int32_t cw_; // Contention Window u_int32_t ssrc_; // STA Short Retry Count @@ -402,8 +591,6 @@ NsObject* EOTtarget_; // given a copy of packet at TX end - - /* ============================================================ Duplicate Detection state ============================================================ */ diff -Naur ns-2.32/mac/mac.h modified-ns-2.32/mac/mac.h --- ns-2.32/mac/mac.h 2005-07-26 18:13:44.000000000 -0700 +++ modified-ns-2.32/mac/mac.h 2007-11-25 17:16:01.000000000 -0800 @@ -83,9 +83,11 @@ MAC_RECV = 0x0010, MAC_SEND = 0x0100, MAC_RTS = 0x0200, + MAC_BCN = 0x0300, MAC_CTS = 0x0400, MAC_ACK = 0x0800, - MAC_COLL = 0x1000 + MAC_COLL = 0x1000, + MAC_MGMT = 0x1001 }; enum MacFrameType { diff -Naur ns-2.32/mac/mac-timers.cc modified-ns-2.32/mac/mac-timers.cc --- ns-2.32/mac/mac-timers.cc 2006-01-30 13:27:51.000000000 -0800 +++ modified-ns-2.32/mac/mac-timers.cc 2007-11-25 17:16:01.000000000 -0800 @@ -145,6 +145,70 @@ /* ====================================================================== + Beacon Timer + ====================================================================== */ +void +BeaconTimer::start(double time) +{ + Scheduler &s = Scheduler::instance(); + + assert(busy_ == 0); + + busy_ = 1; + paused_ = 0; + stime = s.clock(); + rtime = time; + + assert(rtime >= 0.0); + + s.schedule(this, &intr, rtime); +} + + +void +BeaconTimer::handle(Event *) +{ + busy_ = 0; + paused_ = 0; + stime = 0.0; + rtime = 0.0; + + mac->BeaconHandler(); +} + +/* ====================================================================== + Probe Timer + ====================================================================== */ +void +ProbeTimer::start(double time) +{ + Scheduler &s = Scheduler::instance(); + + assert(busy_ == 0); + + busy_ = 1; + paused_ = 0; + stime = s.clock(); + rtime = time; + + assert(rtime >= 0.0); + + s.schedule(this, &intr, rtime); +} + + +void +ProbeTimer::handle(Event *) +{ + busy_ = 0; + paused_ = 0; + stime = 0.0; + rtime = 0.0; + + mac->ProbeHandler(); +} + +/* ====================================================================== NAV Timer ====================================================================== */ void @@ -233,9 +297,6 @@ stime = s.clock(); rtime = (Random::random() % cw) * mac->phymib_.getSlotTime(); - - - #ifdef USE_SLOT_TIME ROUND_TIME(); #endif @@ -259,14 +320,16 @@ // looks dummy double st = s.clock(); + + double rt = stime + difs_wait; double sr = st - rt; double mst = (mac->phymib_.getSlotTime()); - - + int slots = int (sr/mst); - + + if(slots < 0) slots = 0; assert(busy_ && ! paused_); @@ -274,7 +337,6 @@ paused_ = 1; rtime -= (slots * mac->phymib_.getSlotTime()); - assert(rtime >= 0.0); difs_wait = 0.0; @@ -303,6 +365,7 @@ ROUND_TIME(); #endif */ + assert(rtime + difs_wait >= 0.0); s.schedule(this, &intr, rtime + difs_wait); } diff -Naur ns-2.32/mac/mac-timers.h modified-ns-2.32/mac/mac-timers.h --- ns-2.32/mac/mac-timers.h 2006-01-30 13:27:51.000000000 -0800 +++ modified-ns-2.32/mac/mac-timers.h 2007-11-25 17:16:01.000000000 -0800 @@ -92,6 +92,21 @@ void handle(Event *e); }; +class BeaconTimer : public MacTimer { +public: + BeaconTimer(Mac802_11 *m) : MacTimer(m) {} + + void start(double); + void handle(Event *e); +}; + +class ProbeTimer : public MacTimer { +public: + ProbeTimer(Mac802_11 *m) : MacTimer(m) {} + + void start(double); + void handle(Event *e); +}; class IFTimer : public MacTimer { diff -Naur ns-2.32/tcl/ex/802_11/infra.tcl modified-ns-2.32/tcl/ex/802_11/infra.tcl --- ns-2.32/tcl/ex/802_11/infra.tcl 1969-12-31 16:00:00.000000000 -0800 +++ modified-ns-2.32/tcl/ex/802_11/infra.tcl 2007-12-10 18:51:40.000000000 -0800 @@ -0,0 +1,132 @@ +set val(chan) Channel/WirelessChannel ;#Channel Type +set val(prop) Propagation/TwoRayGround ;# radio-propagation model +set val(netif) Phy/WirelessPhy ;# network interface type +set val(mac) Mac/802_11 ;# MAC type +set val(ifq) Queue/DropTail ;# interface queue type +set val(ll) LL ;# link layer type +set val(ant) Antenna/OmniAntenna ;# antenna model +set val(ifqlen) 50 ;# max packet in ifq +set val(nn) 10 ;# number of mobilenodes +set val(rp) DumbAgent ;# routing protocol +set val(x) 600 +set val(y) 600 + +Mac/802_11 set dataRate_ 11Mb + +#Phy/WirelessPhy set CSThresh_ 10.00e-12 +#Phy/WirelessPhy set RXThresh_ 10.00e-11 +#Phy/WirelessPhy set Pt_ 0.1 +#Phy/WirelessPhy set Pt_ 7.214e-3 + +# Initialize Global Variables +set ns_ [new Simulator] +set tracefd [open infra.tr w] +$ns_ trace-all $tracefd + + +# set up topography object +set topo [new Topography] + +$topo load_flatgrid $val(x) $val(y) + +# Create God +create-god $val(nn) + +# Create channel +set chan_1_ [new $val(chan)] + + +$ns_ node-config -adhocRouting $val(rp) \ + -llType $val(ll) \ + -macType $val(mac) \ + -ifqType $val(ifq) \ + -ifqLen $val(ifqlen) \ + -antType $val(ant) \ + -propType $val(prop) \ + -phyType $val(netif) \ + -topoInstance $topo \ + -agentTrace OFF \ + -routerTrace OFF \ + -macTrace ON \ + -movementTrace ON \ + -channel $chan_1_ + + + for {set i 0} {$i < [expr $val(nn)]} {incr i} { + set node_($i) [$ns_ node] + + $node_($i) random-motion 0 ;# disable random motion + set mac_($i) [$node_($i) getMac 0] + + + $mac_($i) set RTSThreshold_ 3000 + + $node_($i) set X_ $i + $node_($i) set Y_ 0 ;# Horizontal arrangement of nodes + $node_($i) set Z_ 0.0 + + } + +#Set Node 0 and Node $val(nn) as the APs. Thus the APs are the ends of the horizontal line. Each STA receives different power levels. + + +set AP_ADDR1 [$mac_(0) id] +$mac_(0) ap $AP_ADDR1 +set AP_ADDR2 [$mac_([expr $val(nn) - 1]) id] +$mac_([expr $val(nn) - 1]) ap $AP_ADDR2 + +#$mac_([expr $val(nn) - 1]) set BeaconInterval_ 0.2 + + +$mac_(1) ScanType ACTIVE + +for {set i 3} {$i < [expr $val(nn) - 1]} {incr i} { + $mac_($i) ScanType PASSIVE ;#Passive +} + + +$ns_ at 1.0 "$mac_(2) ScanType ACTIVE" + +Application/Traffic/CBR set packetSize_ 1023 +Application/Traffic/CBR set rate_ 256Kb + + +for {set i 1} {$i < [expr $val(nn) - 1]} {incr i} { + set udp1($i) [new Agent/UDP] + + $ns_ attach-agent $node_($i) $udp1($i) + set cbr1($i) [new Application/Traffic/CBR] + $cbr1($i) attach-agent $udp1($i) +} + + +set base0 [new Agent/Null] + +$ns_ attach-agent $node_(1) $base0 + +set base1 [new Agent/Null] + +$ns_ attach-agent $node_(8) $base1 + +$ns_ connect $udp1(4) $base0 +$ns_ connect $udp1(5) $base1 + + +$ns_ at 2.0 "$cbr1(4) start" + +$ns_ at 4.0 "$cbr1(5) start" + +$ns_ at 10.0 "$node_(4) setdest 300.0 1.0 30.0" + +$ns_ at 20.0 "stop" +$ns_ at 20.0 "puts \"NS EXITING...\" ; $ns_ halt" + +proc stop {} { + global ns_ tracefd + $ns_ flush-trace + close $tracefd + exit 0 +} + +puts "Starting Simulation..." +$ns_ run diff -Naur ns-2.32/tcl/lib/ns-default.tcl modified-ns-2.32/tcl/lib/ns-default.tcl --- ns-2.32/tcl/lib/ns-default.tcl 2007-06-17 14:44:46.000000000 -0700 +++ modified-ns-2.32/tcl/lib/ns-default.tcl 2007-11-27 15:58:20.000000000 -0800 @@ -682,6 +682,15 @@ Mac/802_11 set bugFix_timer_ true; # fix for when RTS/CTS not used # details at http://www.dei.unipd.it/wdyn/?IDsezione=2435 + Mac/802_11 set BeaconInterval_ 0.1 ;# 100ms + Mac/802_11 set ScanType_ PASSIVE + Mac/802_11 set ProbeDelay_ 0.0001 ;# 0.1 ms + Mac/802_11 set MaxChannelTime_ 0.011 ;# 11 ms + Mac/802_11 set MinChannelTime_ 0.005 ; # 5 ms + Mac/802_11 set ChannelTime_ 0.12 ;# 120 ms + + + # # Support for Abstract LAN # diff -Naur ns-2.32/tcl/test/test-all-wireless-infra modified-ns-2.32/tcl/test/test-all-wireless-infra --- ns-2.32/tcl/test/test-all-wireless-infra 1969-12-31 16:00:00.000000000 -0800 +++ modified-ns-2.32/tcl/test/test-all-wireless-infra 2007-12-10 17:50:39.000000000 -0800 @@ -0,0 +1,31 @@ +#! /bin/sh + +# +# Copyright (c) 1998 University of Southern California. +# All rights reserved. +# +# Redistribution and use in source and binary forms are permitted +# provided that the above copyright notice and this paragraph are +# duplicated in all such forms and that any documentation, advertising +# materials, and other materials related to such distribution and use +# acknowledge that the software was developed by the University of +# Southern California, Information Sciences Institute. The name of the +# University may not be used to endorse or promote products derived +# from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +# +# To run in quiet mode: "./test-all-wireless-lanquiet". +# +# Please notice that the new script will reuse the reference output +# of wireless lan to make sure that new interface does not change +# the behavior of the protocols +f="wireless-infra" +file="test-suite-$f.tcl" +directory="test-output-wireless-infra" +version="v2" +./test-all-template1 $file $directory $version $@ + diff -Naur ns-2.32/tcl/test/test-all-wireless-infra-mobility modified-ns-2.32/tcl/test/test-all-wireless-infra-mobility --- ns-2.32/tcl/test/test-all-wireless-infra-mobility 1969-12-31 16:00:00.000000000 -0800 +++ modified-ns-2.32/tcl/test/test-all-wireless-infra-mobility 2007-12-10 17:51:03.000000000 -0800 @@ -0,0 +1,32 @@ +#! /bin/sh + +# +# Copyright (c) 1998 University of Southern California. +# All rights reserved. +# +# Redistribution and use in source and binary forms are permitted +# provided that the above copyright notice and this paragraph are +# duplicated in all such forms and that any documentation, advertising +# materials, and other materials related to such distribution and use +# acknowledge that the software was developed by the University of +# Southern California, Information Sciences Institute. The name of the +# University may not be used to endorse or promote products derived +# from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +# +# To run in quiet mode: "./test-all-wireless-lanquiet". +# +# Please notice that the new script will reuse the reference output +# of wireless lan to make sure that new interface does not change +# the behavior of the protocols + +f="wireless-infra-mobility" +file="test-suite-$f.tcl" +directory="test-output-wireless-infra-mobility" +version="v2" +./test-all-template1 $file $directory $version $@ + diff -Naur ns-2.32/tcl/test/test-suite-wireless-infra-mobility.tcl modified-ns-2.32/tcl/test/test-suite-wireless-infra-mobility.tcl --- ns-2.32/tcl/test/test-suite-wireless-infra-mobility.tcl 1969-12-31 16:00:00.000000000 -0800 +++ modified-ns-2.32/tcl/test/test-suite-wireless-infra-mobility.tcl 2007-12-10 18:31:59.000000000 -0800 @@ -0,0 +1,321 @@ +# -*- Mode:tcl; tcl-indent-level:8; tab-width:8; indent-tabs-mode:t -*- +# The default for rfc2988_ is being changed to true. +Mac/802_11 set bugFix_timer_ true; # default changed 2006/1/30 +# +# Copyright (c) 1998,2000 University of Southern California. +# All rights reserved. +# +# Redistribution and use in source and binary forms are permitted +# provided that the above copyright notice and this paragraph are +# duplicated in all such forms and that any documentation, advertising +# materials, and other materials related to such distribution and use +# acknowledge that the software was developed by the University of +# Southern California, Information Sciences Institute. The name of the +# University may not be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +# + +Class TestSuite +Class Test/wireless-infra-mobility -superclass TestSuite + + proc usage {} { + global argv0 + puts stderr "usage: ns $argv0 " + puts "valid Tests: wireless-infra-mobility" + exit 1 + } + + proc default_options {} { + global opt + set opt(chan) Channel/WirelessChannel + set opt(prop) Propagation/TwoRayGround + set opt(netif) Phy/WirelessPhy + set opt(mac) Mac/802_11 + set opt(ifq) Queue/DropTail/PriQueue + set opt(ll) LL + set opt(ant) Antenna/OmniAntenna + set opt(x) 670 ;# X dimension of the topography + set opt(y) 670;# Y dimension of the topography + set opt(ifqlen) 50 ;# max packet in ifq + set opt(seed) 0.0 + set opt(tr) temp.rands ;# trace file + set opt(lm) "OFF" ;# log movement + set opt(eott) "ON" ;# eot trace + + } + + + # ===================================================================== + # Other default settings + + LL set mindelay_ 50us + LL set delay_ 25us + LL set bandwidth_ 0 ;# not used + + Agent/Null set sport_ 0 + Agent/Null set dport_ 0 + + Agent/CBR set sport_ 0 + Agent/CBR set dport_ 0 + + Agent/TCPSink set sport_ 0 + Agent/TCPSink set dport_ 0 + + Agent/TCP set sport_ 0 + Agent/TCP set dport_ 0 + Agent/TCP set packetSize_ 1460 + + Queue/DropTail/PriQueue set Prefer_Routing_Protocols 1 + + # unity gain, omni-directional antennas + # set up the antennas to be centered in the node and 1.5 meters above it + Antenna/OmniAntenna set X_ 0 + Antenna/OmniAntenna set Y_ 0 + Antenna/OmniAntenna set Z_ 1.5 + Antenna/OmniAntenna set Gt_ 1.0 + Antenna/OmniAntenna set Gr_ 1.0 + + # Initialize the SharedMedia interface with parameters to make + # it work like the 914MHz Lucent WaveLAN DSSS radio interface + Phy/WirelessPhy set CPThresh_ 10.0 + Phy/WirelessPhy set CSThresh_ 1.559e-11 + Phy/WirelessPhy set RXThresh_ 3.652e-10 + Phy/WirelessPhy set Rb_ 2*1e6 + Phy/WirelessPhy set Pt_ 0.28183815 + Phy/WirelessPhy set freq_ 914e6 + Phy/WirelessPhy set L_ 1.0 + + # ===================================================================== + + TestSuite instproc init {} { + global opt tracefd topo chan prop + global node_ god_ + $self instvar ns_ testName_ + set ns_ [new Simulator] + set topo [new Topography] + set tracefd [open $opt(tr) w] + + $ns_ trace-all $tracefd + + $topo load_flatgrid $opt(x) $opt(y) + + set god_ [create-god $opt(nn)] + } + + Test/wireless-infra-mobility instproc init {} { + global opt node_ mac_ god_ chan topo + $self instvar ns_ testName_ + set testName_ wireless-infra-mobility + set opt(nn) 10 + set opt(stop) 12.0 + + $self next + + $ns_ node-config -adhocRouting DumbAgent \ + -llType $opt(ll) \ + -macType $opt(mac) \ + -ifqType $opt(ifq) \ + -ifqLen $opt(ifqlen) \ + -antType $opt(ant) \ + -propType $opt(prop) \ + -phyType $opt(netif) \ + -channel [new $opt(chan)] \ + -topoInstance $topo \ + -agentTrace ON \ + -routerTrace OFF \ + -macTrace ON \ + -movementTrace ON \ + -eotTrace $opt(eott) + + + # + # We set some parameters as default values, and some + # we wait until after creating the node. + # + + + Mac/802_11 set BeaconInterval_ 0.2 + Mac/802_11 set dataRate_ 11Mb + + for {set i 0} {$i < $opt(nn) } {incr i} { + set node_($i) [$ns_ node] + $node_($i) random-motion 0 ;# disable random motion + set mac_($i) [$node_($i) getMac 0] + + $mac_($i) set RTSThreshold_ 3000 + + $node_($i) set X_ $i + $node_($i) set Y_ 0.0 + $node_($i) set Z_ 0.0 + } + + # Tell everyone who the AP is + set AP_ADDR1 [$mac_(0) id] + $mac_(0) ap $AP_ADDR1 + set AP_ADDR2 [$mac_([expr $opt(nn) - 1]) id] + $mac_([expr $opt(nn) - 1]) ap $AP_ADDR2 + + $mac_(1) ScanType ACTIVE + + for {set i 3} {$i < [expr $opt(nn) - 1]} {incr i} { + $mac_($i) ScanType PASSIVE ;#Passive + } + + + $ns_ at 1.0 "$mac_(2) ScanType ACTIVE" + + puts "Load complete..." + + $self create-udp-traffic 0 $node_(4) $node_(1) 2.0 + $self create-udp-traffic 1 $node_(5) $node_(8) 2.5 + + $ns_ at 2.4 "$node_(4) setdest 300.0 1.0 30.0" + # + # Tell all the nodes when the simulation ends + # + + for {set i 0} {$i < $opt(nn) } {incr i} { + $ns_ at $opt(stop).000000001 "$node_($i) reset"; + } + + $ns_ at $opt(stop).000000001 "puts \"NS EXITING...\" ;" + $ns_ at $opt(stop).1 "$self finish" + } + + Test/wireless-infra-mobility instproc run {} { + $self instvar ns_ + puts "Starting Simulation..." + $ns_ run + } + + + + TestSuite instproc finish-basenode {} { + $self instvar ns_ + global quiet opt tracefd + + flush $tracefd + close $tracefd + + set tracefd [open $opt(tr) r] + set tracefd2 [open $opt(tr).w w] + + while { [eof $tracefd] == 0 } { + + set line [gets $tracefd] + set items [split $line " "] + if { [lindex $items 0] == "M" } { + puts $tracefd2 $line + } else { + if { [llength $items] > 15} { + puts $tracefd2 $line + } + } + } + + close $tracefd + close $tracefd2 + + exec mv $opt(tr).w $opt(tr) + + puts "finishing.." + exit 0 + } + + TestSuite instproc finish {} { + $self instvar ns_ + global quiet + + $ns_ flush-trace + #if { !$quiet } { + # puts "running nam..." + # exec nam temp.rands.nam & + #} + puts "finishing.." + exit 0 + } + + + #TestSuite instproc log-movement {} { + # global ns + # $self instvar logtimer_ ns_ + # + # set ns $ns_ + # source ../mobility/timer.tcl + # Class LogTimer -superclass Timer + # LogTimer instproc timeout {} { + # global opt node_; + # for {set i 0} {$i < $opt(nn)} {incr i} { + # $node_($i) log-movement + # } + # $self sched 0.1 + # } + # + # set logtimer_ [new LogTimer] + # $logtimer_ sched 0.1 + #} + + TestSuite instproc create-tcp-traffic {id src dst start} { + $self instvar ns_ + set tcp_($id) [new Agent/TCP] + $tcp_($id) set class_ 2 + set sink_($id) [new Agent/TCPSink] + $ns_ attach-agent $src $tcp_($id) + $ns_ attach-agent $dst $sink_($id) + $ns_ connect $tcp_($id) $sink_($id) + set ftp_($id) [new Application/FTP] + $ftp_($id) attach-agent $tcp_($id) + $ns_ at $start "$ftp_($id) start" + + } + + + TestSuite instproc create-udp-traffic {id src dst start} { + $self instvar ns_ + set udp_($id) [new Agent/UDP] + $ns_ attach-agent $src $udp_($id) + set null_($id) [new Agent/Null] + $ns_ attach-agent $dst $null_($id) + set cbr_($id) [new Application/Traffic/CBR] + $cbr_($id) set packetSize_ 512 + $cbr_($id) set rate_ 64Kb + $cbr_($id) attach-agent $udp_($id) + $ns_ connect $udp_($id) $null_($id) + $ns_ at $start "$cbr_($id) start" + + } + + + proc runtest {arg} { + global quiet + set quiet 0 + + set b [llength $arg] + if {$b == 1} { + set test $arg + } elseif {$b == 2} { + set test [lindex $arg 0] + if {[lindex $arg 1] == "QUIET"} { + set quiet 1 + } + } else { + usage + } + set t [new Test/$test] + + + $t run + } + + global argv arg0 + default_options + runtest $argv + + + + + diff -Naur ns-2.32/tcl/test/test-suite-wireless-infra.tcl modified-ns-2.32/tcl/test/test-suite-wireless-infra.tcl --- ns-2.32/tcl/test/test-suite-wireless-infra.tcl 1969-12-31 16:00:00.000000000 -0800 +++ modified-ns-2.32/tcl/test/test-suite-wireless-infra.tcl 2007-12-10 18:31:46.000000000 -0800 @@ -0,0 +1,307 @@ +# -*- Mode:tcl; tcl-indent-level:8; tab-width:8; indent-tabs-mode:t -*- +# The default for rfc2988_ is being changed to true. +Mac/802_11 set bugFix_timer_ true; # default changed 2006/1/30 +# +# Copyright (c) 1998,2000 University of Southern California. +# All rights reserved. +# +# Redistribution and use in source and binary forms are permitted +# provided that the above copyright notice and this paragraph are +# duplicated in all such forms and that any documentation, advertising +# materials, and other materials related to such distribution and use +# acknowledge that the software was developed by the University of +# Southern California, Information Sciences Institute. The name of the +# University may not be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +# + + +Class TestSuite +Class Test/wireless-infra -superclass TestSuite + + proc usage {} { + global argv0 + puts stderr "usage: ns $argv0 " + puts "valid Tests: wireless-infra" + exit 1 + } + + proc default_options {} { + global opt + set opt(chan) Channel/WirelessChannel + set opt(prop) Propagation/TwoRayGround + set opt(netif) Phy/WirelessPhy + set opt(mac) Mac/802_11 + set opt(ifq) Queue/DropTail/PriQueue + set opt(ll) LL + set opt(ant) Antenna/OmniAntenna + set opt(x) 670 ;# X dimension of the topography + set opt(y) 670;# Y dimension of the topography + set opt(ifqlen) 50 ;# max packet in ifq + set opt(seed) 0.0 + set opt(tr) temp.rands ;# trace file + set opt(lm) "OFF" ;# log movement + set opt(eott) "ON" ;# eot trace + + } + + + # ===================================================================== + # Other default settings + + + + # unity gain, omni-directional antennas + # set up the antennas to be centered in the node and 1.5 meters above it + Antenna/OmniAntenna set X_ 0 + Antenna/OmniAntenna set Y_ 0 + Antenna/OmniAntenna set Z_ 1.5 + Antenna/OmniAntenna set Gt_ 1.0 + Antenna/OmniAntenna set Gr_ 1.0 + + # Initialize the SharedMedia interface with parameters to make + # it work like the 914MHz Lucent WaveLAN DSSS radio interface + Phy/WirelessPhy set CPThresh_ 10.0 + Phy/WirelessPhy set CSThresh_ 1.559e-11 + Phy/WirelessPhy set RXThresh_ 3.652e-10 + Phy/WirelessPhy set Rb_ 2*1e6 + Phy/WirelessPhy set Pt_ 0.28183815 + Phy/WirelessPhy set freq_ 914e6 + Phy/WirelessPhy set L_ 1.0 + + # ===================================================================== + + TestSuite instproc init {} { + global opt tracefd topo chan prop + global node_ god_ + $self instvar ns_ testName_ + set ns_ [new Simulator] + set topo [new Topography] + set tracefd [open $opt(tr) w] + + $ns_ trace-all $tracefd + + $topo load_flatgrid $opt(x) $opt(y) + + puts $tracefd "M 0.0 nn:$opt(nn) x:$opt(x) y:$opt(y)" + puts $tracefd "M 0.0 seed:$opt(seed)" + puts $tracefd "M 0.0 prop:$opt(prop) ant:$opt(ant)" + puts $tracefd "M 0.0 eott:$opt(eott)" + + set god_ [create-god $opt(nn)] + } + + Test/wireless-infra instproc init {} { + global opt node_ mac_ god_ chan topo + $self instvar ns_ testName_ + set testName_ wireless-infra + set opt(nn) 10 + set opt(stop) 10.0 + + $self next + + $ns_ node-config -adhocRouting DumbAgent \ + -llType $opt(ll) \ + -macType $opt(mac) \ + -ifqType $opt(ifq) \ + -ifqLen $opt(ifqlen) \ + -antType $opt(ant) \ + -propType $opt(prop) \ + -phyType $opt(netif) \ + -channel [new $opt(chan)] \ + -topoInstance $topo \ + -agentTrace ON \ + -routerTrace OFF \ + -macTrace ON \ + -movementTrace OFF \ + -eotTrace $opt(eott) + + + # + # We set some parameters as default values, and some + # we wait until after creating the node. + + + Mac/802_11 set BeaconInterval_ 0.2 + Mac/802_11 set dataRate_ 11Mb + + for {set i 0} {$i < $opt(nn) } {incr i} { + set node_($i) [$ns_ node] + $node_($i) random-motion 0 ;# disable random motion + set mac_($i) [$node_($i) getMac 0] + + $mac_($i) set RTSThreshold_ 3000 + + $node_($i) set X_ $i + $node_($i) set Y_ 0.0 + $node_($i) set Z_ 0.0 + } + + # Tell everyone who the AP is + set AP_ADDR1 [$mac_(0) id] + $mac_(0) ap $AP_ADDR1 + set AP_ADDR2 [$mac_([expr $opt(nn) - 1]) id] + $mac_([expr $opt(nn) - 1]) ap $AP_ADDR2 + + $mac_(1) ScanType ACTIVE + + for {set i 3} {$i < [expr $opt(nn) - 1]} {incr i} { + $mac_($i) ScanType PASSIVE ;#Passive + } + + + $ns_ at 1.0 "$mac_(2) ScanType ACTIVE" + + puts "Load complete..." + + $self create-udp-traffic 0 $node_(5) $node_(1) 2.0 + $self create-udp-traffic 1 $node_(4) $node_(8) 3.0 + + # + # Tell all the nodes when the simulation ends + # + for {set i 0} {$i < $opt(nn) } {incr i} { + $ns_ at $opt(stop).000000001 "$node_($i) reset"; + } + + $ns_ at $opt(stop).000000001 "puts \"NS EXITING...\" ;" + $ns_ at $opt(stop).1 "$self finish" + } + + Test/wireless-infra instproc run {} { + $self instvar ns_ + puts "Starting Simulation..." + $ns_ run + } + + + + TestSuite instproc finish-basenode {} { + $self instvar ns_ + global quiet opt tracefd + + flush $tracefd + close $tracefd + + set tracefd [open $opt(tr) r] + set tracefd2 [open $opt(tr).w w] + + while { [eof $tracefd] == 0 } { + + set line [gets $tracefd] + set items [split $line " "] + if { [lindex $items 0] == "M" } { + puts $tracefd2 $line + } else { + if { [llength $items] > 15} { + puts $tracefd2 $line + } + } + } + + close $tracefd + close $tracefd2 + + exec mv $opt(tr).w $opt(tr) + + puts "finishing.." + exit 0 + } + + TestSuite instproc finish {} { + $self instvar ns_ + global quiet + + $ns_ flush-trace + #if { !$quiet } { + # puts "running nam..." + # exec nam temp.rands.nam & + #} + puts "finishing.." + exit 0 + } + + + #TestSuite instproc log-movement {} { + # global ns + # $self instvar logtimer_ ns_ + # + # set ns $ns_ + # source ../mobility/timer.tcl + # Class LogTimer -superclass Timer + # LogTimer instproc timeout {} { + # global opt node_; + # for {set i 0} {$i < $opt(nn)} {incr i} { + # $node_($i) log-movement + # } + # $self sched 0.1 + # } + # + # set logtimer_ [new LogTimer] + # $logtimer_ sched 0.1 + #} + + TestSuite instproc create-tcp-traffic {id src dst start} { + $self instvar ns_ + set tcp_($id) [new Agent/TCP] + $tcp_($id) set class_ 2 + set sink_($id) [new Agent/TCPSink] + $ns_ attach-agent $src $tcp_($id) + $ns_ attach-agent $dst $sink_($id) + $ns_ connect $tcp_($id) $sink_($id) + set ftp_($id) [new Application/FTP] + $ftp_($id) attach-agent $tcp_($id) + $ns_ at $start "$ftp_($id) start" + + } + + + TestSuite instproc create-udp-traffic {id src dst start} { + $self instvar ns_ + set udp_($id) [new Agent/UDP] + $ns_ attach-agent $src $udp_($id) + set null_($id) [new Agent/Null] + $ns_ attach-agent $dst $null_($id) + set cbr_($id) [new Application/Traffic/CBR] + $cbr_($id) set packetSize_ 512 + $cbr_($id) set rate_ 64Kb + $cbr_($id) attach-agent $udp_($id) + $ns_ connect $udp_($id) $null_($id) + $ns_ at $start "$cbr_($id) start" + + } + + + proc runtest {arg} { + global quiet + set quiet 0 + + set b [llength $arg] + if {$b == 1} { + set test $arg + } elseif {$b == 2} { + set test [lindex $arg 0] + if {[lindex $arg 1] == "QUIET"} { + set quiet 1 + } + } else { + usage + } + set t [new Test/$test] + + + $t run + } + + global argv arg0 + default_options + runtest $argv + + + + + diff -Naur ns-2.32/trace/cmu-trace.cc modified-ns-2.32/trace/cmu-trace.cc --- ns-2.32/trace/cmu-trace.cc 2006-03-21 14:31:32.000000000 -0800 +++ modified-ns-2.32/trace/cmu-trace.cc 2007-11-25 17:16:01.000000000 -0800 @@ -230,7 +230,6 @@ x = 0.0, y = 0.0, z = 0.0; node_->getLoc(&x, &y, &z); #endif - sprintf(pt_->buffer() + offset, #ifdef LOG_POSITION "%c %.9f %d (%6.2f %6.2f) %3s %4s %d %s %d ", @@ -250,9 +249,10 @@ ch->uid(), // identifier for this event ((ch->ptype() == PT_MAC) ? ( + (mh->dh_fc.fc_type == MAC_Type_Control) ? ( (mh->dh_fc.fc_subtype == MAC_Subtype_RTS) ? "RTS" : (mh->dh_fc.fc_subtype == MAC_Subtype_CTS) ? "CTS" : - (mh->dh_fc.fc_subtype == MAC_Subtype_ACK) ? "ACK" : + (mh->dh_fc.fc_subtype == MAC_Subtype_ACK) ? "ACK": // (mh->dh_fc.fc_subtype == MAC_Subtype_Beacon) ? "BCN" : //Beacon (mh->dh_fc.fc_subtype == MAC_Subtype_Command_AssoReq) ? "CM1" : //CMD: Association request @@ -264,7 +264,15 @@ (mh->dh_fc.fc_subtype == MAC_Subtype_Command_BconReq) ? "CM7" : //CMD: Beacon request (mh->dh_fc.fc_subtype == MAC_Subtype_Command_CoorRea) ? "CM8" : //CMD: Coordinator realignment (mh->dh_fc.fc_subtype == MAC_Subtype_Command_GTSReq) ? "CM9" : //CMD: GTS request - // + "UNKN") : + (mh->dh_fc.fc_type == MAC_Type_Management) ? ( + (mh->dh_fc.fc_subtype == MAC_Subtype_80211_Beacon) ? "BCN" : + (mh->dh_fc.fc_subtype == MAC_Subtype_AssocReq) ? "ACRQ" : + (mh->dh_fc.fc_subtype == MAC_Subtype_AssocRep) ? "ACRP" : + (mh->dh_fc.fc_subtype == MAC_Subtype_Auth) ? "AUTH" : + (mh->dh_fc.fc_subtype == MAC_Subtype_ProbeReq) ? "PRRQ" : + (mh->dh_fc.fc_subtype == MAC_Subtype_ProbeRep) ? "PRRP" : + "UNKN") : "UNKN") : (ch->ptype() == PT_SMAC) ? ( (sh->type == RTS_PKT) ? "RTS" : @@ -918,6 +926,8 @@ (mh->dh_fc.fc_subtype == MAC_Subtype_CTS) ? "CTS" : (mh->dh_fc.fc_subtype == MAC_Subtype_ACK) ? "ACK" : (mh->dh_fc.fc_subtype == MAC_Subtype_Beacon) ? "BCN" : //Beacon + (mh->dh_fc.fc_subtype == MAC_Subtype_AssocReq) ? "ACRQ" : + (mh->dh_fc.fc_subtype == MAC_Subtype_AssocRep) ? "ACRP" : (mh->dh_fc.fc_subtype == MAC_Subtype_Command_AssoReq) ? "CM1" : //CMD: Association request (mh->dh_fc.fc_subtype == MAC_Subtype_Command_AssoRsp) ? "CM2" : //CMD: Association response (mh->dh_fc.fc_subtype == MAC_Subtype_Command_DAssNtf) ? "CM3" : //CMD: Disassociation notification diff -Naur ns-2.32/validate modified-ns-2.32/validate --- ns-2.32/validate 2007-08-14 22:51:59.000000000 -0700 +++ modified-ns-2.32/validate 2007-12-10 18:34:05.000000000 -0800 @@ -75,6 +75,7 @@ mip links linkstate mpls oddBehaviors \ wireless-shadowing wireless-lan-aodv wireless-gridkeeper \ wireless-diffusion wireless-lan-newnode WLtutorial \ +wireless-infra wireless-infra-mobility \ source-routing \ misc tagged-trace message rng xcp wpan \ energy snoop \ diff -Naur ns-2.32/validate-wireless modified-ns-2.32/validate-wireless --- ns-2.32/validate-wireless 2000-10-09 15:46:35.000000000 -0700 +++ modified-ns-2.32/validate-wireless 2007-12-10 17:42:11.000000000 -0800 @@ -38,7 +38,7 @@ for i in lan wireless-lan mip wireless-gridkeeper \ wireless-lan-newnode wireless-lan-tora wireless-lan-aodv \ -wireless-tdma wireless-diffusion energy wireless-shadowing WLtutorial +wireless-tdma wireless-diffusion wireless-infra wireless-infra-mobility energy wireless-shadowing WLtutorial do try ./test-all-$i done