Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

MacTdma Class Reference

#include <mac-tdma.h>

Inheritance diagram for MacTdma:

Inheritance graph
[legend]
Collaboration diagram for MacTdma:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 MacTdma (PHY_MIB *p)
void recv (Packet *p, Handler *h)
int hdr_dst (char *hdr, int dst=-2)
int hdr_src (char *hdr, int src=-2)
int hdr_type (char *hdr, u_int16_t type=0)
void slotHandler (Event *e)
void recvHandler (Event *e)
void sendHandler (Event *e)
virtual void recv (Packet *p, const char *s)
virtual void resume (Packet *p=0)
virtual void installTap (Tap *t)
double txtime (int bytes)
double txtime (Packet *p)
double bandwidth () const
int addr ()
MacState state ()
MacState state (int m)
NsObjectuptarget ()
NsObjectdowntarget ()
virtual void drop (Packet *p)
virtual void recvOnly (Packet *)
virtual void delay_bind_init_all ()
virtual int delay_bind_dispatch (const char *varName, const char *localName, TclObject *tracer)
int isdebug () const
virtual void debug (const char *fmt,...)

Protected Member Functions

virtual void sendDown (Packet *p, Handler *h)
virtual void sendUp (Packet *p, Handler *h)
virtual int initialized ()
virtual void drop (Packet *p, const char *s)
virtual void reset ()
void handle (Event *)

Protected Attributes

PHY_MIBphymib_
int slot_packet_len_
int max_node_num_
int index_
double bandwidth_
double delay_
int abstract_
Phynetif_
Taptap_
LLll_
Channelchannel_
Handlercallback_
MacHandlerResume hRes_
MacHandlerSend hSend_
Event intr_
MacState state_
PacketpktRx_
PacketpktTx_
NsObjectuptarget_
NsObjectdowntarget_
NsObjectdrop_
int debug_

Private Member Functions

int command (int argc, const char *const *argv)
void re_schedule ()
void makePreamble ()
void radioSwitch (int i)
void sendUp (Packet *p)
void sendDown (Packet *p)
void recvDATA (Packet *p)
void send ()
int is_idle (void)
void trace_pkt (Packet *p)
void dump (char *fname)
void mac_log (Packet *p)
double TX_Time (Packet *p)
u_int16_t usec (double t)

Private Attributes

SlotTdmaTimer mhSlot_
TxPktTdmaTimer mhTxPkt_
RxPktTdmaTimer mhRxPkt_
MacState rx_state_
MacState tx_state_
int radio_active_
int tx_active_
NsObjectlogtarget_
int slot_num_
int slot_count_

Static Private Attributes

int max_slot_num_ = 0
double slot_time_ = 0
double start_time_ = 0
int active_node_ = 0
int * tdma_schedule_ = NULL
int * tdma_preamble_ = NULL
int tdma_ps_ = 0
int tdma_pr_ = 0

Friends

class SlotTdmaTimer
class TxPktTdmaTimer
class RxPktTdmaTimer

Constructor & Destructor Documentation

MacTdma::MacTdma PHY_MIB p  ) 
 

Definition at line 147 of file mac-tdma.cc.

References active_node_, DATA_Time, FIRST_ROUND, Mac::intr_, MAC_IDLE, max_node_num_, max_slot_num_, mhSlot_, NOTHING_TO_SEND, phymib_, radio_active_, re_schedule(), rx_state_, slot_count_, slot_num_, slot_packet_len_, slot_time_, MacTdmaTimer::start(), tdma_preamble_, tdma_schedule_, tx_active_, and tx_state_.

00147                            : 
00148         Mac(), mhSlot_(this), mhTxPkt_(this), mhRxPkt_(this){
00149         /* Global variables setting. */
00150         // Setup the phy specs.
00151         phymib_ = p;
00152         
00153         /* Get the parameters of the link (which in bound in mac.cc, 2M by default),
00154            the packet length within one TDMA slot (1500 byte by default), 
00155            and the max number of nodes (64) in the simulations.*/
00156         bind("slot_packet_len_", &slot_packet_len_);
00157         bind("max_node_num_", &max_node_num_);
00158         
00159         //  slot_packet_len_ = 1500;
00160         //  max_node_num_ = 64;
00161         // Calculate the slot time based on the MAX allowed data length.
00162         slot_time_ = DATA_Time(slot_packet_len_);
00163         
00164         /* Calsulate the max slot num within on frame from max node num.
00165            In the simple case now, they are just equal. 
00166         */
00167         max_slot_num_ = max_node_num_;
00168         
00169         /* Much simplified centralized scheduling algorithm for single hop
00170            topology, like WLAN etc. 
00171         */
00172         // Initualize the tdma schedule and preamble data structure.
00173         tdma_schedule_ = new int[max_slot_num_];
00174         tdma_preamble_ = new int[max_slot_num_];
00175 
00176         /* Do each node's initialization. */
00177         // Record the initial active node number.
00178         active_node_++;
00179 
00180         if (active_node_ > max_node_num_) {
00181                 printf("Too many nodes taking part in the simulations, aborting...\n");
00182                 exit(-1);
00183         }
00184     
00185         // Initial channel / transceiver states. 
00186         tx_state_ = rx_state_ = MAC_IDLE;
00187         tx_active_ = 0;
00188 
00189         // Initialy, the radio is off. NOTE: can't use radioSwitch(OFF) here.
00190         radio_active_ = 0;
00191 
00192         // Do slot scheduling.
00193         re_schedule();
00194 
00195         /* Deal with preamble. */
00196         // Can't send anything in the first frame.
00197         slot_count_ = FIRST_ROUND;
00198         tdma_preamble_[slot_num_] = NOTHING_TO_SEND;
00199 
00200         //Start the Slot timer..
00201         mhSlot_.start((Packet *) (& intr_), 0);  
00202 }

Here is the call graph for this function:


Member Function Documentation

int Mac::addr  )  [inline, inherited]
 

Definition at line 190 of file mac.h.

References Mac::index_.

Referenced by Mac::command(), MacClassifier::recv(), SatLL::sendDown(), and LL::sendDown().

00190 { return index_; }

double Mac::bandwidth  )  const [inline, inherited]
 

Definition at line 188 of file mac.h.

References Mac::bandwidth_.

Referenced by MultihopMac::pollTxtime().

00188 { return bandwidth_; }

int MacTdma::command int  argc,
const char *const *  argv
[private, virtual]
 

Reimplemented from Mac.

Definition at line 205 of file mac-tdma.cc.

References Mac::command(), and logtarget_.

00206 {
00207         if (argc == 3) {
00208                 if (strcmp(argv[1], "log-target") == 0) {
00209                         logtarget_ = (NsObject*) TclObject::lookup(argv[2]);
00210                         if(logtarget_ == 0)
00211                                 return TCL_ERROR;
00212                         return TCL_OK;
00213                 }
00214         }
00215         return Mac::command(argc, argv);
00216 }

Here is the call graph for this function:

void NsObject::debug const char *  fmt,
... 
[virtual, inherited]
 

Definition at line 102 of file object.cc.

References NsObject::debug_.

00103 {
00104         if (!debug_)
00105                 return;
00106         va_list ap;
00107         va_start(ap, fmt);
00108         vprintf(fmt, ap);
00109 }

int NsObject::delay_bind_dispatch const char *  varName,
const char *  localName,
TclObject tracer
[virtual, inherited]
 

Reimplemented in BayFullTcpAgent, Agent, MPLSAddressClassifier, LDPAgent, FullTcpAgent, SackFullTcpAgent, RFC793eduTcpAgent, TcpSink, TcpAgent, and VegasTcpAgent.

Definition at line 63 of file object.cc.

References NsObject::debug_.

Referenced by MPLSAddressClassifier::delay_bind_dispatch(), and Agent::delay_bind_dispatch().

00064 {
00065         if (delay_bind_bool(varName, localName, "debug_", &debug_, tracer)) 
00066                 return TCL_OK;
00067         return TclObject::delay_bind_dispatch(varName, localName, tracer);
00068 }

void NsObject::delay_bind_init_all  )  [virtual, inherited]
 

Reimplemented in BayFullTcpAgent, Agent, MPLSAddressClassifier, LDPAgent, FullTcpAgent, SackFullTcpAgent, RFC793eduTcpAgent, TcpSink, TcpAgent, and VegasTcpAgent.

Definition at line 57 of file object.cc.

Referenced by MPLSAddressClassifier::delay_bind_init_all(), and Agent::delay_bind_init_all().

00058 {
00059         delay_bind_init_one("debug_");
00060 }

NsObject* BiConnector::downtarget  )  [inline, inherited]
 

Definition at line 49 of file bi-connector.h.

References BiConnector::downtarget_.

Referenced by SatLL::channel().

00049 { return downtarget_; }

void BiConnector::drop Packet p,
const char *  s
[protected, virtual, inherited]
 

Definition at line 144 of file bi-connector.cc.

References BiConnector::drop_, Packet::free(), and NsObject::recv().

00145 {
00146         if (drop_ != 0)
00147                 drop_->recv(p, s);
00148         else
00149                 Packet::free(p);
00150 }

Here is the call graph for this function:

void BiConnector::drop Packet p  )  [virtual, inherited]
 

Definition at line 135 of file bi-connector.cc.

References BiConnector::drop_, Packet::free(), and NsObject::recv().

Referenced by Mac802_3::collision(), Mac802_11::discard(), SMAC::drop_CTS(), SMAC::drop_DATA(), SMAC::drop_RTS(), SMAC::drop_SYNC(), UnslottedAlohaMac::end_of_contention(), recvHandler(), Mac::resume(), MacCsma::resume(), UnslottedAlohaMac::sendUp(), SatMac::sendUp(), Mac::sendUp(), TX_Time(), and Mac802_11::txtime().

00136 {
00137         if (drop_ != 0)
00138                 drop_->recv(p);
00139         else
00140                 Packet::free(p);
00141 }

Here is the call graph for this function:

void MacTdma::dump char *  fname  )  [private]
 

Definition at line 234 of file mac-tdma.cc.

References Mac::callback_, Mac::index_, Scheduler::instance(), is_idle(), Mac::pktRx_, Mac::pktTx_, rx_state_, and tx_state_.

00235 {
00236         fprintf(stderr, "\n%s --- (INDEX: %d, time: %2.9f)\n", fname, 
00237                 index_, Scheduler::instance().clock());
00238         
00239         fprintf(stderr, "\ttx_state_: %x, rx_state_: %x, idle: %d\n", 
00240                 tx_state_, rx_state_, is_idle());
00241         fprintf(stderr, "\tpktTx_: %x, pktRx_: %x, callback: %x\n", 
00242                 (int) pktTx_, (int) pktRx_, (int) callback_);
00243 }

Here is the call graph for this function:

void NsObject::handle Event  )  [protected, virtual, inherited]
 

Implements Handler.

Reimplemented in LinkDelay, LL, AckRecons, and Snoop.

Definition at line 91 of file object.cc.

References NsObject::recv().

00092 {
00093         recv((Packet*)e);
00094 }

Here is the call graph for this function:

int MacTdma::hdr_dst char *  hdr,
int  dst = -2
[inline, virtual]
 

Reimplemented from Mac.

Definition at line 249 of file mac-tdma.cc.

References dh, ETHER_ADDR, and STORE4BYTE.

00250 {
00251         struct hdr_mac_tdma *dh = (struct hdr_mac_tdma*) hdr;
00252         if(dst > -2)
00253                 STORE4BYTE(&dst, (dh->dh_da));
00254         return ETHER_ADDR(dh->dh_da);
00255 }

int MacTdma::hdr_src char *  hdr,
int  src = -2
[inline, virtual]
 

Reimplemented from Mac.

Definition at line 257 of file mac-tdma.cc.

References dh, ETHER_ADDR, and STORE4BYTE.

00258 {
00259         struct hdr_mac_tdma *dh = (struct hdr_mac_tdma*) hdr;
00260         if(src > -2)
00261                 STORE4BYTE(&src, (dh->dh_sa));
00262   
00263         return ETHER_ADDR(dh->dh_sa);
00264 }

int MacTdma::hdr_type char *  hdr,
u_int16_t  type = 0
[inline, virtual]
 

Reimplemented from Mac.

Definition at line 266 of file mac-tdma.cc.

References dh, GET2BYTE, and STORE2BYTE.

00267 {
00268         struct hdr_mac_tdma *dh = (struct hdr_mac_tdma*) hdr;
00269         if(type)
00270                 STORE2BYTE(&type,(dh->dh_body));
00271         return GET2BYTE(dh->dh_body);
00272 }

virtual int Mac::initialized  )  [inline, protected, virtual, inherited]
 

Reimplemented in Mac802_11, and SMAC.

Definition at line 223 of file mac.h.

References BiConnector::downtarget_, Mac::netif_, and BiConnector::uptarget_.

Referenced by Mac802_11::initialized(), and Mac802_3::sendDown().

00223                                   { 
00224                 return (netif_ && uptarget_ && downtarget_); 
00225         }

virtual void Mac::installTap Tap t  )  [inline, virtual, inherited]
 

Definition at line 179 of file mac.h.

References Mac::tap_.

Referenced by DSRAgent::command().

00179 { tap_ = t; }

int MacTdma::is_idle void   )  [inline, private]
 

Definition at line 275 of file mac-tdma.cc.

References MAC_IDLE, rx_state_, and tx_state_.

Referenced by dump(), and send().

00275                      {
00276         if(rx_state_ != MAC_IDLE)
00277                 return 0;
00278         if(tx_state_ != MAC_IDLE)
00279                 return 0;
00280         return 1;
00281 }

int NsObject::isdebug  )  const [inline, inherited]
 

Definition at line 61 of file object.h.

References NsObject::debug_.

00061 { return debug_; }

void MacTdma::mac_log Packet p  )  [inline, private]
 

Reimplemented from Mac.

Definition at line 258 of file mac-tdma.h.

References logtarget_, and NsObject::recv().

00258                           {
00259     logtarget_->recv(p, (Handler*) 0);
00260   }

Here is the call graph for this function:

void MacTdma::makePreamble  )  [private]
 

Definition at line 470 of file mac-tdma.cc.

References dh, ETHER_ADDR, HDR_MAC_TDMA, NOTHING_TO_SEND, Mac::pktTx_, slot_num_, tdma_preamble_, and u_int32_t.

Referenced by slotHandler().

00471 {
00472         u_int32_t dst;
00473         struct hdr_mac_tdma* dh;
00474         
00475         // If there is a packet buffered, file its destination to preamble.
00476         if (pktTx_) {
00477                 dh = HDR_MAC_TDMA(pktTx_);  
00478                 dst = ETHER_ADDR(dh->dh_da);
00479                 //printf("<%d>, %f, write %d to slot %d in preamble\n", index_, NOW, dst, slot_num_);
00480                 tdma_preamble_[slot_num_] = (char) dst;
00481         } else {
00482                 //printf("<%d>, %f, write NO_PKT to slot %d in preamble\n", index_, NOW, slot_num_);
00483                 tdma_preamble_[slot_num_] = (char) NOTHING_TO_SEND;
00484         }
00485 }

void MacTdma::radioSwitch int  i  )  [private]
 

Definition at line 448 of file mac-tdma.cc.

References Node::energy_model(), Mac::netif_, Phy::node(), OFF, ON, radio_active_, EnergyModel::set_node_sleep(), and EnergyModel::sleep().

Referenced by recvHandler(), send(), sendHandler(), and slotHandler().

00449 {
00450         radio_active_ = i;
00451         EnergyModel *em = netif_->node()->energy_model();
00452         if (i == ON) {
00453                 if (em && em->sleep())
00454                         em->set_node_sleep(0);
00455                 //    printf("<%d>, %f, turn radio ON\n", index_, NOW);
00456                 return;
00457         }
00458 
00459         if (i == OFF) {
00460                 if (em && !em->sleep()) {
00461                         em->set_node_sleep(1);
00462                         //    netif_->node()->set_node_state(INROUTE);
00463                 };
00464                 //    printf("<%d>, %f, turn radio OFF\n", index_, NOW);
00465                 return;
00466         }
00467 }

Here is the call graph for this function:

void MacTdma::re_schedule  )  [private]
 

Definition at line 286 of file mac-tdma.cc.

References Mac::index_, NOW, slot_num_, start_time_, and tdma_schedule_.

Referenced by MacTdma().

00286                           {
00287         static int slot_pointer = 0;
00288         // Record the start time of the new schedule.
00289         start_time_ = NOW;
00290         /* Seperate slot_num_ and the node id: 
00291            we may have flexibility as node number changes.
00292         */
00293         slot_num_ = slot_pointer++;
00294         tdma_schedule_[slot_num_] = (char) index_;
00295 }

void NsObject::recv Packet p,
const char *  s
[virtual, inherited]
 

Reimplemented in CMUTrace.

Definition at line 96 of file object.cc.

References Packet::free().

00097 {
00098         Packet::free(p);
00099 }

Here is the call graph for this function:

void MacTdma::recv Packet p,
Handler h
[virtual]
 

Reimplemented from Mac.

Definition at line 298 of file mac-tdma.cc.

References Mac::callback_, HDR_CMN, MAC_SEND, radio_active_, sendDown(), sendUp(), Mac::state(), and hdr_cmn::UP.

00298                                         {
00299         struct hdr_cmn *ch = HDR_CMN(p);
00300         
00301         /* Incoming packets from phy layer, send UP to ll layer. 
00302            Now, it is in receiving mode. 
00303         */
00304         if (ch->direction() == hdr_cmn::UP) {
00305                 // Since we can't really turn the radio off at lower level, 
00306                 // we just discard the packet.
00307                 if (!radio_active_) {
00308                         free(p);
00309                         //printf("<%d>, %f, I am sleeping...\n", index_, NOW);
00310                         return;
00311                 }
00312 
00313                 sendUp(p);
00314                 //printf("<%d> packet recved: %d\n", index_, tdma_pr_++);
00315                 return;
00316         }
00317         
00318         /* Packets coming down from ll layer (from ifq actually),
00319            send them to phy layer. 
00320            Now, it is in transmitting mode. */
00321         callback_ = h;
00322         state(MAC_SEND);
00323         sendDown(p);
00324         //printf("<%d> packet sent down: %d\n", index_, tdma_ps_++);
00325 }

Here is the call graph for this function:

void MacTdma::recvDATA Packet p  )  [private]
 

Definition at line 358 of file mac-tdma.cc.

References ETHER_HDR_LEN, HDR_CMN, NsObject::recv(), and BiConnector::uptarget_.

Referenced by recvHandler().

00358                                {
00359         /*Adjust the MAC packet size: strip off the mac header.*/
00360         struct hdr_cmn *ch = HDR_CMN(p);
00361         ch->size() -= ETHER_HDR_LEN;
00362         ch->num_forwards() += 1;
00363 
00364         /* Pass the packet up to the link-layer.*/
00365         uptarget_->recv(p, (Handler*) 0);
00366 }

Here is the call graph for this function:

void MacTdma::recvHandler Event e  ) 
 

Definition at line 539 of file mac-tdma.cc.

References dh, BiConnector::drop(), ETHER_ADDR, HDR_CMN, HDR_MAC_TDMA, Mac::index_, MAC_BROADCAST, MAC_COLL, MAC_IDLE, OFF, Mac::pktRx_, radioSwitch(), recvDATA(), rx_state_, SET_RX_STATE, and u_int32_t.

Referenced by RxPktTdmaTimer::handle().

00540 {
00541         u_int32_t dst, src; 
00542         int size;
00543         struct hdr_cmn *ch = HDR_CMN(pktRx_);
00544         struct hdr_mac_tdma *dh = HDR_MAC_TDMA(pktRx_);
00545 
00546         /* Check if any collision happened while receiving. */
00547         if (rx_state_ == MAC_COLL) 
00548                 ch->error() = 1;
00549 
00550         SET_RX_STATE(MAC_IDLE);
00551   
00552         /* check if this packet was unicast and not intended for me, drop it.*/   
00553         dst = ETHER_ADDR(dh->dh_da);
00554         src = ETHER_ADDR(dh->dh_sa);
00555         size = ch->size();
00556 
00557         //printf("<%d>, %f, recv a packet [from %d to %d], size = %d\n", index_, NOW, src, dst, size);
00558 
00559         // Turn the radio off after receiving the whole packet
00560         radioSwitch(OFF);
00561 
00562         /* Ordinary operations on the incoming packet */
00563         // Not a pcket destinated to me.
00564         if ((dst != MAC_BROADCAST) && (dst != (u_int32_t)index_)) {
00565                 drop(pktRx_);
00566                 return;
00567         }
00568   
00569         /* Now forward packet upwards. */
00570         recvDATA(pktRx_);
00571 }

Here is the call graph for this function:

virtual void NsObject::recvOnly Packet  )  [inline, virtual, inherited]
 

Reimplemented in Agent, and Trace.

Definition at line 56 of file object.h.

Referenced by Trace::recvOnly().

00056 {};

void NsObject::reset  )  [protected, virtual, inherited]
 

Reimplemented in BayFullTcpAgent, HashClassifier, IvsSource, dsREDQueue, DiffusionRate, SinkAgent, DiffusionAgent, FloodingAgent, OmniMcastAgent, LinkDelay, CBQueue, DropTail, ErrorModel, PIQueue, Queue< T >, RedPDQueue, REDQueue, REMQueue, RIOQueue, Snoop, FackTcpAgent, FullTcpAgent, SackFullTcpAgent, RFC793eduTcpAgent, Sack1TcpAgent, TcpSink, DelAckSink, TcpAgent, VegasTcpAgent, toraAgent, and Queue< T >.

Definition at line 70 of file object.cc.

Referenced by NsObject::command().

00071 {
00072 }

void Mac::resume Packet p = 0  )  [virtual, inherited]
 

Reimplemented in MacCsma.

Definition at line 173 of file mac.cc.

References Mac::callback_, BiConnector::drop(), Handler::handle(), Mac::intr_, MAC_IDLE, and Mac::state().

Referenced by UnslottedAlohaMac::backoff(), UnslottedAlohaMac::end_of_contention(), and MacHandlerResume::handle().

00174 {
00175         if (p != 0)
00176                 drop(p);
00177         state(MAC_IDLE);
00178         callback_->handle(&intr_);
00179 }

Here is the call graph for this function:

void MacTdma::send  )  [private]
 

Definition at line 406 of file mac-tdma.cc.

References Packet::copy(), dh, BiConnector::downtarget_, ETHER_ADDR, HDR_CMN, HDR_MAC_TDMA, Mac::index_, is_idle(), MAC_SEND, mhTxPkt_, NOW, ON, Mac::pktTx_, radioSwitch(), NsObject::recv(), SET_TX_STATE, MacTdmaTimer::start(), TX_Time(), and u_int32_t.

Referenced by slotHandler().

00407 {
00408         u_int32_t dst, src, size;
00409         struct hdr_cmn* ch;
00410         struct hdr_mac_tdma* dh;
00411         double stime;
00412 
00413         /* Check if there is any packet buffered. */
00414         if (!pktTx_) {
00415                 printf("<%d>, %f, no packet buffered.\n", index_, NOW);
00416                 return;
00417         }
00418 
00419         /* Perform carrier sence...should not be collision...? */
00420         if(!is_idle()) {
00421                 /* Note: we don't take the channel status into account, ie. no collision,
00422                    as collision should not happen...
00423                 */
00424                 printf("<%d>, %f, transmitting, but the channel is not idle...???\n", index_, NOW);
00425                 return;
00426         }
00427 
00428         ch = HDR_CMN(pktTx_);
00429         dh = HDR_MAC_TDMA(pktTx_);  
00430 
00431         dst = ETHER_ADDR(dh->dh_da);
00432         src = ETHER_ADDR(dh->dh_sa);
00433         size = ch->size();
00434         stime = TX_Time(pktTx_);
00435 
00436         /* Turn on the radio and transmit! */
00437         SET_TX_STATE(MAC_SEND);                                              
00438         radioSwitch(ON);
00439 
00440         /* Start a timer that expires when the packet transmission is complete. */
00441         mhTxPkt_.start(pktTx_->copy(), stime);
00442         downtarget_->recv(pktTx_, this);        
00443 
00444         pktTx_ = 0;
00445 }

Here is the call graph for this function:

virtual void BiConnector::sendDown Packet p,
Handler h
[inline, protected, virtual, inherited]
 

Reimplemented in Mac802_3.

Definition at line 55 of file bi-connector.h.

References BiConnector::downtarget_, and NsObject::recv().

Referenced by BiConnector::recv().

00056                 { downtarget_->recv(p, h); }

Here is the call graph for this function:

void MacTdma::sendDown Packet p  )  [private, virtual]
 

Reimplemented from Mac.

Definition at line 370 of file mac-tdma.cc.

References DATA_DURATION, dh, ETHER_ADDR, ETHER_HDR_LEN, HDR_CMN, HDR_MAC_TDMA, MAC_BROADCAST, MAC_ProtocolVersion, MAC_Subtype_Data, MAC_Type_Data, Mac::pktTx_, and u_int32_t.

Referenced by recv().

00370                                 {
00371         u_int32_t dst, src, size;
00372   
00373         struct hdr_cmn* ch = HDR_CMN(p);
00374         struct hdr_mac_tdma* dh = HDR_MAC_TDMA(p);
00375 
00376         /* Update the MAC header, same as 802.11 */
00377         ch->size() += ETHER_HDR_LEN;
00378 
00379         dh->dh_fc.fc_protocol_version = MAC_ProtocolVersion;
00380         dh->dh_fc.fc_type       = MAC_Type_Data;
00381         dh->dh_fc.fc_subtype    = MAC_Subtype_Data;
00382         
00383         dh->dh_fc.fc_to_ds      = 0;
00384         dh->dh_fc.fc_from_ds    = 0;
00385         dh->dh_fc.fc_more_frag  = 0;
00386         dh->dh_fc.fc_retry      = 0;
00387         dh->dh_fc.fc_pwr_mgt    = 0;
00388         dh->dh_fc.fc_more_data  = 0;
00389         dh->dh_fc.fc_wep        = 0;
00390         dh->dh_fc.fc_order      = 0;
00391 
00392         if((u_int32_t)ETHER_ADDR(dh->dh_da) != MAC_BROADCAST)
00393                 dh->dh_duration = DATA_DURATION;
00394         else
00395                 dh->dh_duration = 0;
00396 
00397         dst = ETHER_ADDR(dh->dh_da);
00398         src = ETHER_ADDR(dh->dh_sa);
00399         size = ch->size();
00400 
00401         /* buffer the packet to be sent. */
00402         pktTx_ = p;
00403 }

void MacTdma::sendHandler Event e  ) 
 

Definition at line 574 of file mac-tdma.cc.

References Mac::callback_, Packet::free(), Handler::handle(), MAC_IDLE, OFF, radioSwitch(), and SET_TX_STATE.

Referenced by TxPktTdmaTimer::handle().

00575 {
00576         //  printf("<%d>, %f, send a packet finished.\n", index_, NOW);
00577 
00578         /* Once transmission is complete, drop the packet. 
00579            p  is just for schedule a event. */
00580         SET_TX_STATE(MAC_IDLE);
00581         Packet::free((Packet *)e);
00582   
00583         // Turn off the radio after sending the whole packet
00584         radioSwitch(OFF);
00585 
00586         /* unlock IFQ. */
00587         if(callback_) {
00588                 Handler *h = callback_;
00589                 callback_ = 0;
00590                 h->handle((Event*) 0);
00591         } 
00592 }

Here is the call graph for this function:

virtual void BiConnector::sendUp Packet p,
Handler h
[inline, protected, virtual, inherited]
 

Reimplemented in Mac802_3.

Definition at line 57 of file bi-connector.h.

References NsObject::recv(), and BiConnector::uptarget_.

Referenced by BiConnector::recv().

00058                 { uptarget_->recv(p, h); }

Here is the call graph for this function:

void MacTdma::sendUp Packet p  )  [private, virtual]
 

Reimplemented from Mac.

Definition at line 327 of file mac-tdma.cc.

References HDR_CMN, Mac::index_, MAC_IDLE, MAC_RECV, mhRxPkt_, Mac::pktRx_, rx_state_, SET_RX_STATE, MacTdmaTimer::start(), tx_state_, and TX_Time().

Referenced by recv().

00328 {
00329         struct hdr_cmn *ch = HDR_CMN(p);
00330 
00331         /* Can't receive while transmitting. Should not happen...?*/
00332         if (tx_state_ && ch->error() == 0) {
00333                 printf("<%d>, can't receive while transmitting!\n", index_);
00334                 ch->error() = 1;
00335         };
00336 
00337         /* Detect if there is any collision happened. should not happen...?*/
00338         if (rx_state_ == MAC_IDLE) {
00339                 SET_RX_STATE(MAC_RECV);     // Change the state to recv.
00340                 pktRx_ = p;                 // Save the packet for timer reference.
00341 
00342                 /* Schedule the reception of this packet, 
00343                    since we just see the packet header. */
00344                 double rtime = TX_Time(p);
00345                 assert(rtime >= 0);
00346 
00347                 /* Start the timer for receiving, will end when receiving finishes. */
00348                 mhRxPkt_.start(p, rtime);
00349         } else {
00350                 /* Note: we don't take the channel status into account, 
00351                    as collision should not happen...
00352                 */
00353                 printf("<%d>, receiving, but the channel is not idle....???\n", index_);
00354         }
00355 }

Here is the call graph for this function:

void MacTdma::slotHandler Event e  ) 
 

Definition at line 493 of file mac-tdma.cc.

References active_node_, FIRST_ROUND, Mac::index_, MAC_BROADCAST, makePreamble(), mhSlot_, NOTHING_TO_SEND, OFF, ON, radioSwitch(), send(), slot_count_, slot_num_, slot_time_, MacTdmaTimer::start(), tdma_preamble_, and u_int32_t.

Referenced by SlotTdmaTimer::handle().

00494 {
00495         // Restart timer for next slot.
00496         mhSlot_.start((Packet *)e, slot_time_);
00497 
00498         // Make a new presamble for next frame.
00499         if ((slot_count_ == active_node_) || (slot_count_ == FIRST_ROUND)) {
00500                 //printf("<%d>, %f, make the new preamble now.\n", index_, NOW);
00501                 // We should turn the radio on for the whole slot time.
00502                 radioSwitch(ON);
00503 
00504                 makePreamble();
00505                 slot_count_ = 0;
00506                 return;
00507         }
00508 
00509         // If it is the sending slot for me.
00510         if (slot_count_ == slot_num_) {
00511                 //printf("<%d>, %f, time to send.\n", index_, NOW);
00512                 // We have to check the preamble first to avoid the packets coming in the middle.
00513                 if (tdma_preamble_[slot_num_] != NOTHING_TO_SEND)
00514                         send();
00515                 else
00516                         radioSwitch(OFF);
00517 
00518                 slot_count_++;
00519                 return;
00520         }
00521  
00522         // If I am supposed to listen in this slot
00523         if ((tdma_preamble_[slot_count_] == index_) || ((u_int32_t)tdma_preamble_[slot_count_] == MAC_BROADCAST)) {
00524                 //printf("<%d>, %f, preamble[%d]=%d, I am supposed to receive now.\n", index_, NOW, slot_count_, tdma_preamble_[slot_count_]);
00525                 slot_count_++;
00526 
00527                 // Wake up the receive packets.
00528                 radioSwitch(ON);
00529                 return;
00530         }
00531 
00532         // If I dont send / recv, do nothing.
00533         //printf("<%d>, %f, preamble[%d]=%d, nothing to do now.\n", index_, NOW, slot_count_, tdma_preamble_[slot_count_]);
00534         radioSwitch(OFF);
00535         slot_count_++;
00536         return;
00537 }

Here is the call graph for this function:

MacState Mac::state int  m  )  [inline, inherited]
 

Definition at line 192 of file mac.h.

References MacState, and Mac::state_.

00192 { return state_ = (MacState) m; }

MacState Mac::state  )  [inline, inherited]
 

Definition at line 191 of file mac.h.

References MacState, and Mac::state_.

Referenced by Mac::recv(), recv(), Mac::resume(), MacCsma::resume(), and Mac::sendUp().

00191 { return state_; }

void MacTdma::trace_pkt Packet p  )  [private]
 

Definition at line 222 of file mac-tdma.cc.

References dh, ETHER_ADDR, HDR_CMN, HDR_MAC_TDMA, Mac::index_, p_info::name(), packet_info, and u_int16_t.

00223 {
00224         struct hdr_cmn *ch = HDR_CMN(p);
00225         struct hdr_mac_tdma* dh = HDR_MAC_TDMA(p);
00226         u_int16_t *t = (u_int16_t*) &dh->dh_fc;
00227 
00228         fprintf(stderr, "\t[ %2x %2x %2x %2x ] %x %s %d\n",
00229                 *t, dh->dh_duration,
00230                 ETHER_ADDR(dh->dh_da), ETHER_ADDR(dh->dh_sa),
00231                 index_, packet_info.name(ch->ptype()), ch->size());
00232 }

Here is the call graph for this function:

double MacTdma::TX_Time Packet p  )  [inline, private]
 

Definition at line 262 of file mac-tdma.h.

References DATA_Time, BiConnector::drop(), and HDR_CMN.

Referenced by send(), and sendUp().

00262                                    {
00263     double t = DATA_Time((HDR_CMN(p))->size());
00264 
00265     //    printf("<%d>, packet size: %d, tx-time: %f\n", index_, (HDR_CMN(p))->size(), t);
00266     if(t < 0.0) {
00267       drop(p, "XXX");
00268       exit(1);
00269     }
00270     return t;
00271   }

Here is the call graph for this function:

double Mac::txtime Packet p  )  [inline, inherited]
 

Reimplemented in Mac802_11, and SMAC.

Definition at line 184 of file mac.h.

References Mac::bandwidth_, HDR_CMN, and MAC_HDR_LEN.

00184                                         {
00185                 return 8. * (MAC_HDR_LEN + \
00186                              (HDR_CMN(p))->size()) / bandwidth_;
00187         }

double Mac::txtime int  bytes  )  [inline, inherited]
 

Reimplemented in Mac802_11.

Definition at line 181 of file mac.h.

References Mac::bandwidth_.

Referenced by MacCsma::endofContention(), MultihopMac::send(), UnslottedAlohaMac::sendDown(), SatMac::sendDown(), Mac::sendDown(), and Mac802_3::transmit().

00181                                         {
00182                 return (8. * bytes / bandwidth_);
00183         }

NsObject* BiConnector::uptarget  )  [inline, inherited]
 

Definition at line 48 of file bi-connector.h.

References BiConnector::uptarget_.

Referenced by SatChannel::find_peer_mac_addr().

00048 { return uptarget_; }

u_int16_t MacTdma::usec double  t  )  [inline, private]
 

Definition at line 273 of file mac-tdma.h.

References u_int16_t.

00273                                   {
00274     u_int16_t us = (u_int16_t)ceil(t *= 1e6);
00275     return us;
00276   };


Friends And Related Function Documentation

friend class RxPktTdmaTimer [friend]
 

Definition at line 214 of file mac-tdma.h.

friend class SlotTdmaTimer [friend]
 

Definition at line 212 of file mac-tdma.h.

friend class TxPktTdmaTimer [friend]
 

Definition at line 213 of file mac-tdma.h.


Member Data Documentation

int Mac::abstract_ [protected, inherited]
 

Definition at line 229 of file mac.h.

Referenced by Mac::Mac(), Mac::sendDown(), and Mac::sendUp().

int MacTdma::active_node_ = 0 [static, private]
 

Definition at line 324 of file mac-tdma.h.

Referenced by MacTdma(), and slotHandler().

double Mac::bandwidth_ [protected, inherited]
 

Definition at line 227 of file mac.h.

Referenced by Mac::bandwidth(), Mac::Mac(), Mac802_11::Mac802_11(), UnslottedAlohaMac::sendDown(), SatMac::sendDown(), and Mac::txtime().

Handler* Mac::callback_ [protected, inherited]
 

Definition at line 236 of file mac.h.

Referenced by dump(), Mac802_11::dump(), UnslottedAlohaMac::end_of_contention(), Mac::recv(), recv(), MultihopMac::recv(), Mac::resume(), MacCsma::resume(), Mac802_3::resume(), MultihopMac::send(), Mac802_11::send(), Mac802_3::sendDown(), sendHandler(), SMAC::sendMsg(), Mac802_3::transmit(), Mac802_11::tx_resume(), and SMAC::txMsgDone().

Channel* Mac::channel_ [protected, inherited]
 

Definition at line 234 of file mac.h.

Referenced by MacCsma::backoff(), Mac::command(), MacCsmaCd::endofContention(), MacCsma::endofContention(), MultihopMac::send(), MacCsmaCa::send(), and MacCsma::send().

int NsObject::debug_ [protected, inherited]
 

Reimplemented in FECModel, FloodAgent, and LandmarkAgent.

Definition at line 66 of file object.h.

Referenced by REDQueue::command(), RedPDQueue::command(), PushbackQueue::command(), NsObject::debug(), NsObject::delay_bind_dispatch(), RedPDQueue::enque(), PushbackQueue::enque(), NsObject::isdebug(), NsObject::NsObject(), TfrcAgent::recv(), PushbackQueue::reportDrop(), and REDQueue::reset().

double Mac::delay_ [protected, inherited]
 

Definition at line 228 of file mac.h.

Referenced by UnslottedAlohaMac::end_of_contention(), Mac::Mac(), MultihopMac::recv(), SatMac::sendUp(), and Mac::sendUp().

NsObject* BiConnector::downtarget_ [protected, inherited]
 

Definition at line 63 of file bi-connector.h.

Referenced by Phy::command(), BiConnector::command(), BiConnector::downtarget(), WirelessPhy::initialized(), WiredPhy::initialized(), SMAC::initialized(), Mac::initialized(), FECModel::recv(), send(), UnslottedAlohaMac::sendDown(), SatMac::sendDown(), Mac::sendDown(), BiConnector::sendDown(), SMAC::transmit(), and Mac802_3::transmit().

NsObject* BiConnector::drop_ [protected, inherited]
 

Definition at line 64 of file bi-connector.h.

Referenced by BiConnector::command(), and BiConnector::drop().

MacHandlerResume Mac::hRes_ [protected, inherited]
 

Definition at line 237 of file mac.h.

Referenced by MacCsma::endofContention(), SatMac::sendDown(), and Mac::sendDown().

MacHandlerSend Mac::hSend_ [protected, inherited]
 

Definition at line 238 of file mac.h.

Referenced by MacCsmaCd::endofContention(), MacCsmaCa::send(), and MacCsma::send().

int Mac::index_ [protected, inherited]
 

Definition at line 226 of file mac.h.

Referenced by Mac::addr(), Mac802_11::discard(), SMAC::drop_CTS(), SMAC::drop_DATA(), SMAC::drop_RTS(), dump(), Mac802_11::dump(), UnslottedAlohaMac::end_of_contention(), SMAC::handleACK(), SMAC::handleCTS(), SMAC::handleDATA(), SMAC::handleGeneTimer(), SMAC::handleRTS(), SMAC::handleSYNC(), Mac::Mac(), re_schedule(), SMAC::recv(), Mac::recv(), Mac802_3::recv_complete(), Mac802_11::recv_timer(), recvHandler(), send(), SMAC::sendACK(), SMAC::sendCTS(), SMAC::sendRTS(), Mac802_11::sendRTS(), SMAC::sendSYNC(), UnslottedAlohaMac::sendUp(), SatMac::sendUp(), Mac::sendUp(), sendUp(), SMAC::setMySched(), slotHandler(), trace_pkt(), Mac802_11::trace_pkt(), and Mac802_3::transmit().

Event Mac::intr_ [protected, inherited]
 

Definition at line 239 of file mac.h.

Referenced by MacTdma(), Mac::resume(), MacCsma::resume(), MultihopMac::send(), SatMac::sendDown(), and Mac::sendDown().

LL* Mac::ll_ [protected, inherited]
 

Definition at line 233 of file mac.h.

NsObject* MacTdma::logtarget_ [private]
 

Reimplemented from Mac.

Definition at line 292 of file mac-tdma.h.

Referenced by command(), and mac_log().

int MacTdma::max_node_num_ [protected]
 

Definition at line 233 of file mac-tdma.h.

Referenced by MacTdma().

int MacTdma::max_slot_num_ = 0 [static, private]
 

Definition at line 325 of file mac-tdma.h.

Referenced by MacTdma().

RxPktTdmaTimer MacTdma::mhRxPkt_ [private]
 

Definition at line 281 of file mac-tdma.h.

Referenced by sendUp().

SlotTdmaTimer MacTdma::mhSlot_ [private]
 

Definition at line 279 of file mac-tdma.h.

Referenced by MacTdma(), and slotHandler().

TxPktTdmaTimer MacTdma::mhTxPkt_ [private]
 

Definition at line 280 of file mac-tdma.h.

Referenced by send().

Phy* Mac::netif_ [protected, inherited]
 

Definition at line 231 of file mac.h.

Referenced by Mac802_3::collision(), Mac::command(), Mac8023HandlerSend::handle(), SMAC::initialized(), Mac::initialized(), radioSwitch(), Mac802_3::recv_complete(), Mac802_11::recv_timer(), MacHandlerRetx::schedule(), Mac802_11::send(), Mac802_3::sendDown(), Mac802_3::sendUp(), and Mac802_3::transmit().

PHY_MIB* MacTdma::phymib_ [protected]
 

Definition at line 229 of file mac-tdma.h.

Referenced by MacTdma().

Packet* Mac::pktRx_ [protected, inherited]
 

Reimplemented in SMAC.

Definition at line 245 of file mac.h.

Referenced by Mac802_11::collision(), dump(), Mac802_11::dump(), Mac802_11::recv(), Mac802_11::recv_timer(), recvHandler(), Mac802_11::rx_resume(), and sendUp().

Packet* Mac::pktTx_ [protected, inherited]
 

Reimplemented in SMAC.

Definition at line 246 of file mac.h.

Referenced by Mac802_11::check_pktTx(), Mac802_11::deferHandler(), dump(), Mac802_11::dump(), makePreamble(), Mac802_11::recvACK(), Mac802_11::recvCTS(), Mac802_11::RetransmitDATA(), Mac802_11::RetransmitRTS(), send(), Mac802_11::sendDATA(), sendDown(), Mac802_11::sendRTS(), and Mac802_11::tx_resume().

int MacTdma::radio_active_ [private]
 

Definition at line 288 of file mac-tdma.h.

Referenced by MacTdma(), radioSwitch(), and recv().

MacState MacTdma::rx_state_ [private]
 

Definition at line 284 of file mac-tdma.h.

Referenced by dump(), is_idle(), MacTdma(), recvHandler(), and sendUp().

int MacTdma::slot_count_ [private]
 

Definition at line 315 of file mac-tdma.h.

Referenced by MacTdma(), and slotHandler().

int MacTdma::slot_num_ [private]
 

Definition at line 310 of file mac-tdma.h.

Referenced by MacTdma(), makePreamble(), re_schedule(), and slotHandler().

int MacTdma::slot_packet_len_ [protected]
 

Definition at line 232 of file mac-tdma.h.

Referenced by MacTdma().

double MacTdma::slot_time_ = 0 [static, private]
 

Definition at line 322 of file mac-tdma.h.

Referenced by MacTdma(), and slotHandler().

double MacTdma::start_time_ = 0 [static, private]
 

Definition at line 323 of file mac-tdma.h.

Referenced by re_schedule().

MacState Mac::state_ [protected, inherited]
 

Reimplemented in SMAC.

Definition at line 244 of file mac.h.

Referenced by Mac802_3::collision(), Mac802_3::resume(), Mac802_3::sendUp(), Mac::state(), and Mac802_3::transmit().

Tap* Mac::tap_ [protected, inherited]
 

Definition at line 232 of file mac.h.

Referenced by Mac::installTap(), and Mac802_11::recv_timer().

int MacTdma::tdma_pr_ = 0 [static, private]
 

Definition at line 330 of file mac-tdma.h.

int * MacTdma::tdma_preamble_ = NULL [static, private]
 

Definition at line 327 of file mac-tdma.h.

Referenced by MacTdma(), makePreamble(), and slotHandler().

int MacTdma::tdma_ps_ = 0 [static, private]
 

Definition at line 329 of file mac-tdma.h.

int * MacTdma::tdma_schedule_ = NULL [static, private]
 

Definition at line 326 of file mac-tdma.h.

Referenced by MacTdma(), and re_schedule().

int MacTdma::tx_active_ [private]
 

Definition at line 290 of file mac-tdma.h.

Referenced by MacTdma().

MacState MacTdma::tx_state_ [private]
 

Definition at line 285 of file mac-tdma.h.

Referenced by dump(), is_idle(), MacTdma(), and sendUp().

NsObject* BiConnector::uptarget_ [protected, inherited]
 

Definition at line 60 of file bi-connector.h.

Referenced by BiConnector::command(), Phy::dump(), UnslottedAlohaMac::end_of_contention(), WirelessPhy::initialized(), WiredPhy::initialized(), SMAC::initialized(), Mac::initialized(), God::initialized(), RepeaterPhy::recv(), Phy::recv(), FECModel::recv(), Mac802_3::recv_complete(), recvDATA(), Mac802_11::recvDATA(), SMAC::rxMsgDone(), SatMac::sendUp(), Mac::sendUp(), BiConnector::sendUp(), and BiConnector::uptarget().


The documentation for this class was generated from the following files:
Generated on Tue Apr 20 12:58:46 2004 for NS2.26SourcesOriginal by doxygen 1.3.3