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...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

14.6 LL (link-layer) Class<strong>The</strong> link-layer object is respo<strong>ns</strong>ible for simul<strong>at</strong>ing the d<strong>at</strong>a link protocols. Many protocols can be implemented within thislayer such as packet fragment<strong>at</strong>ion <strong>and</strong> reassembly, <strong>and</strong> reliable link protocol.Another important function of the link layer is setting the MAC destin<strong>at</strong>ion address in the MAC header of the packet. In thecurrent implement<strong>at</strong>ion this task involves two separ<strong>at</strong>e issues: finding the next–hop–node’s IP address (routing) <strong>and</strong> resolvingthis IP address into the correct MAC address (ARP). For simplicity, the default mapping between MAC <strong>and</strong> IP addresses isone–to–one, which mea<strong>ns</strong> th<strong>at</strong> IP addresses are re–used <strong>at</strong> the MAC layer.14.6.1 LL Class in C++<strong>The</strong> C++ class LL derives from the LinkDelay class. Since it is a duplex object, it keeps a separ<strong>at</strong>e pointer for the sendtarget, sendtarget, <strong>and</strong> the receive target, recvtarget. It also defines the methods recvfrom() <strong>and</strong> sendto() toh<strong>and</strong>le the incoming <strong>and</strong> outgoing packets respectively.class LL : public LinkDelay {public:LL();virtual void recv(Packet* p, H<strong>and</strong>ler* h);virtual Packet* sendto(Packet* p, H<strong>and</strong>ler* h = 0);virtual Packet* recvfrom(Packet* p);inline int seqno() return seqno_;inline int ackno() return ackno_;inline int macDA() return macDA_;inline Queue *ifq() return ifq_;inline NsObject* sendtarget() return sendtarget_;inline NsObject* recvtarget() return recvtarget_;protected:int comm<strong>and</strong>(int argc, co<strong>ns</strong>t char*co<strong>ns</strong>t* argv);void h<strong>and</strong>le(Event* e) recv((Packet*)e, 0);inline virtual int arp (int ip_addr) return ip_addr;int seqno_; // link-layer sequence numberint ackno_; // ACK received so farint macDA_; // destin<strong>at</strong>ion MAC addressQueue* ifq_; // interface queueNsObject* sendtarget_; // for outgoing packetNsObject* recvtarget_; // for incoming packet};LanRouter* lanrouter_; // for lookups of the next hop14.6.2 Example: Link Layer configur<strong>at</strong>io<strong>ns</strong>et ll_ [new LL]set ifq_ [new Queue/DropTail]$ll_ lanrouter [new LanRouter $<strong>ns</strong> $lan] # LanRouter is one object137

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

Saved successfully!

Ooh no, something went wrong!