12.07.2015 Views

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

14.5 MAC Class<strong>The</strong> Mac object simul<strong>at</strong>es the medium access protocols th<strong>at</strong> are necessary in the shared medium environment such as thewireless <strong>and</strong> local area networks. Since the sending <strong>and</strong> receiving mechanisms are tightly coupled in most types of MAClayers, it is essential for the Mac object to be duplex.On the sending side, the Mac object is respo<strong>ns</strong>ible for adding the MAC header <strong>and</strong> tra<strong>ns</strong>mitting the packet onto the channel.On the receiving side, the Mac object asynchronously receives packets from the classifier of the physical layer. After MACprotocol processing, it passes the d<strong>at</strong>a packet to the link layer.14.5.1 Mac St<strong>at</strong>e<strong>The</strong> C++ class Mac class contai<strong>ns</strong> enough internal st<strong>at</strong>e to simul<strong>at</strong>e the particular MAC protocol. It also exports thefollowing OTcl configur<strong>at</strong>ion parameter:b<strong>and</strong>width_hlen_label_modul<strong>at</strong>ion r<strong>at</strong>e of the MACadditional bytes added to packet for MAC headerMAC address14.5.2 Mac Methods<strong>The</strong> class Mac class added several Tcl methods for configur<strong>at</strong>ion, in particular, linking with other simul<strong>at</strong>ion objects:channelclassifiermaclistspecify the channel for tra<strong>ns</strong>missionthe classifier th<strong>at</strong> deliver packets to receiving MACa link list of MAC interfaces on the same node14.5.3 Mac Class in C++In C++, the Mac class derives from Connector. When the recv() method gets a packet, it identifies the direction ofthe packet based on the presence of a callback h<strong>and</strong>ler. If there is a callback h<strong>and</strong>ler, the packet is outgoing, otherwise, it isincoming.class Mac : public Connector {public:Mac();virtual void recv(Packet* p, H<strong>and</strong>ler* h);virtual void send(Packet* p);virtual void resume(Packet* p = 0);. . .};When a Mac object receives a packet via its recv() method, it checks whether the packet is outgoing or incoming. Foran outgoing packet, it assumes th<strong>at</strong> the link-layer of the sender has obtained the destin<strong>at</strong>ion MAC address <strong>and</strong> filled in themacDA_ field of the MAC header, hdr_mac. <strong>The</strong> Mac object fills in the rest of the MAC header with the source MAC address135

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!