Basic Packet Forwarding in NS2

10,097 views

Published on

0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
10,097
On SlideShare
0
From Embeds
0
Number of Embeds
2,808
Actions
Shares
0
Downloads
0
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Basic Packet Forwarding in NS2

    1. 1. Basic packetforwarding in NS2 N S 2 U l t i m a t e . c o m b yT e e r a w a t I s s a r i y a k u l
    2. 2. OUTLINEBefore you begin...NsObjectPacket forwardingExample Class Connector Class QueueQuestions? www.ns2ultimate.com
    3. 3. Before you Begin ... In NS2: • NO such thing as transmission • RECEIVE ONLY www.ns2ultimate.com
    4. 4. What we are going to do hereSuppose you’d like to send a packet from oneNsObject to anotherWhat’s NsObject? ➠ See [ this link ] packetNsObject NsObject www.ns2ultimate.com
    5. 5. NSObjectsInherited Functionalities: Class TclObject ➠ OTcl interface Class Handler ➠ Default actionsNew Functionalities: Receive packet ➠ function recv(p,h) www.ns2ultimate.com
    6. 6. This section gives an overview of C++ class hierarchies. The entire hierarchy NSObjects: Inheritedconsists of over 100 C++ classes and struct data types. Here, we only showa part of the hierarchy (in Fig. 5.1). The readers are referred to [18] for the functionalitiescomplete class hierarchy. OTcl Interface Default Action TclObject Handler Simulator PacketQueue NsObject AtHandler QueueHandler RoutingModule Network Component Classifier Connector LanRouter Uni-directional Point-to- point Object Connector Queue Agent ErrorModel LinkDelay Trace www.ns2ultimate.comFig. 5.1. A part of NS2 C++ class hierarchy (this chapter emphasizes on classes
    7. 7. NSObject: New functionalityclass NsObject : public TclObject, public Handler {public: NsObject(); virtual void recv(Packet*, Handler*) = 0;}; www.ns2ultimate.com
    8. 8. NSObject: New functionalityclass NsObject : public TclObject, public Handler {public: NsObject(); virtual void recv(Packet*, Handler*) = 0;}; TclObject NsObject Handler www.ns2ultimate.com
    9. 9. NSObject: New functionalityclass NsObject : public TclObject, public Handler {public: NsObject(); virtual void recv(Packet*, Handler*) = 0;};packet reception functionInput = a pointer to a Packet objectInput = a pointer to a Handler objectabstract function www.ns2ultimate.com
    10. 10. packet forwardingNS2 refers to most objects using pointersIncluding NsObjects and PacketsExample “p” = a pointer “*p” = a place where the pointer “p” pointer to www.ns2ultimate.com
    11. 11. packet forwardingTask: An object “*s” sends packet “*p” to anobject “*d” s p d packetNsObject NsObject www.ns2ultimate.com
    12. 12. C++ StatementFrom within “*s”, execute one of the followingtwo C++ Statements: Given a handler *h: “d->recv(p,h)” Handler does not exists: “d->recv(p)” s p d packetNsObject NsObject www.ns2ultimate.com
    13. 13. Chapter 15. Examples5.1.2 C++ Class HierarchyThis section gives an overview of C++ class hierarchies. The entire hierarchyconsists of over 100 C++ classes and struct data types. Here, we only showa part of the hierarchy (in Fig. 5.1). The readers are referred to [18] for theSix main categoriescomplete class hierarchy. OTcl Interface Default Action TclObject Handler Simulator PacketQueue NsObject AtHandler QueueHandler RoutingModule Network Component Classifier Connector LanRouter Uni-directional Point-to- point Object Connector Queue Agent ErrorModel LinkDelay TraceFig. 5.1. A part of NS2 C++ class hierarchy (this chapter emphasizes on classesin boxes with thick solid lines). www.ns2ultimate.com
    14. 14. Example: Class Connectorclass Connector : public NsObject {public: Connector(); NsObject* target_; NsObject* drop_;}; • Class variable • A pointer to NsObject www.ns2ultimate.com
    15. 15. Class ConnectorExample configuration target_ points to the next NsObject drop_ points to an NsObject responsible for dropping a packet 100 5 Network Objects Connector NsObject NsObject target_ Upstream Packet forwarding path Downstream NsObject NsObject drop_ Packet dropping path NsObject Packet Dropping NsObject www.ns2ultimate.com
    16. 16. Class ConnectorTo drop a packet, “send the packet to thedropping NsObject” void Connector::drop(Packet* p) { if (drop_ != 0) drop_->recv(p); else Packet::free(p); } Send a packet *p to the NsObject *drop_ www.ns2ultimate.com
    17. 17. 5.1.2 C++ Class Hierarchy Another example:This section gives an overview of C++ class hierarchies. The entire hierarchyconsists of over 100 C++ classes and struct data types. Here, we only show Class Queuea part of the hierarchy (in Fig. 5.1). The readers are referred to [18] for thecomplete class hierarchy. OTcl Interface Default Action TclObject Handler Simulator PacketQueue NsObject AtHandler QueueHandler RoutingModule Network Component Classifier Connector LanRouter Uni-directional Point-to- point Object Connector Derive from class Connector Queue Agent ErrorModel LinkDelay TraceFig. 5.1. A part of NS2 C++ class hierarchy (this chapter emphasizes on classes Contain pointers target_ and drop_.in boxes with thick solid lines). www.ns2ultimate.com
    18. 18. Another example: Class Queuevoid Queue::recv(Packet* p, Handler*){ double now = Scheduler::instance().clock(); enque(p); if (!blocked_) { p = deque(); if (p != 0) { blocked_ = 1; target_->recv(p, &qh_); } }} Send a packet *p to the NsObject *target_ with a handler qh_ www.ns2ultimate.com
    19. 19. Questions?How doNetwork Objectsa topology like this? 100 5 we setup Connector NsObject NsObject target_ Upstream Packet forwarding path Downstream NsObject NsObject drop_ Packet dropping path NsObject Packet Dropping NsObject Fig. 5.2. Diagram of a connector: The solid arrows represent pointers, while theWhat about handler? What is it? What are its dotted arrows show packet forwarding and dropping paths.implications? Program 5.3 Declaration and function recv(p,h) of class Connector //~/ns/common/connector.h 1 class Connector : public NsObject { www.ns2ultimate.com
    20. 20. Stay Tune!I’ll discuss these in the following posts!
    21. 21. For more information about NS2 P l e a s e s e e t h i s b o o k f r o m S p r i n g e rT. Issaraiyakul and E. Hossain, “Introduction to Network Simulator NS2”, Springer 2009 or visit www.ns2ultimate.com

    ×