Your SlideShare is downloading. ×
packet destruction in NS2
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

packet destruction in NS2

5,162
views

Published on

Published in: Technology, Business

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

No Downloads
Views
Total Views
5,162
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
132
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
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
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript

    • 1. packetdestruction 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 August 2011 1
    • 2. OUTLINEReview of main packet operationsPacket destruction function• Direct packet destruction (Packet::free(p))• Send to a dropping objectExample packet dropping process 2 www.ns2ultimate.com
    • 3. review of packet operationsThree main operations1.Packet creation2.Packet transmission3.Packet destruction 3 www.ns2ultimate.com
    • 4. review of packet operations Three main operations Operation Class Function allocpkt(),1. Packet construction Agent initpkt()2. Packet forwarding NsObject recv(p,h)3. Packet destruction Packet free() 4 www.ns2ultimate.com
    • 5. Packet Creation Two key functions are ➠ Agent::allocpkt() ➠ Agent::initpkt() void Agent::initpkt(Packet* p) const { hdr_cmn* ch = hdr_cmn::access(p); ch->ptype() = type_; Agent::allocpkt() const ch->size() = size_; { Packet* p = Packet::alloc(); hdr_ip* iph = hdr_ip::access(p); initpkt(p); iph->saddr() = here_.addr_; return (p); iph->sport() = here_.port_; } iph->daddr() = dst_.addr_; iph->dport() = dst_.port_; ... } 5 www.ns2ultimate.com
    • 6. Packet Forwarding Use the following C++ statement d->recv(ppt,h)spt ppt dpt packetNsObject NsObject 6 7 www.ns2ultimate.com
    • 7. OUTLINEReview of main packet operationsPacket destruction function• Direct packet destruction (Packet::free(p))• Send to a dropping objectExample packet dropping process 7 www.ns2ultimate.com
    • 8. Packet DestructionWhen• Packets have reached the final destination (inform the application and drop the packet)• Packets are dropped (e.g., buffer overflow)How? ➠ Two methods1.Direct packet destruction: Function Packet::free(p)2.Send the packet to a dropping object 8 www.ns2ultimate.com
    • 9. Example Scenario Suppose an NsObject S just receive a packet Pfrom an NsObject T Let spt, ppt, and tpt be the correspondingpointers tpt ppt spt packet P T NsObject NsObject S 9 www.ns2ultimate.com
    • 10. Example ScenarioAgain the packet forwarding is carried out byinvoking a C++ statement: spt->recv(ppt,h)From within the scope of the NsObject T tpt ppt spt packet P T NsObject NsObject S 10 www.ns2ultimate.com
    • 11. Example ScenarioNow the packet P is inside the NsObject SSuppose S would like to destroy the packet P, thereare two ways: 1. Direct destruction 2. Send the packet to a dropping object spt ppt P NsObject S packet 11 www.ns2ultimate.com
    • 12. the first method: Direct packet destruction 12
    • 13. 1.Direct Packet DestructionUsage: Let S destroy packet P• From within the scope of the class of S• Execute “free(ppt)”Example of S: spt ppt• Agent/Null• Common dropping object NsObject P S packet 13 www.ns2ultimate.com
    • 14. 1.Direct Packet Destruction Null Agent in the NS2 hierarchy base class NsObject Connector bind Agent Agentderived class C++ OTcl Agent/Null domain domain 14 www.ns2ultimate.com
    • 15. 1.Direct Packet DestructionNull agent has no C++ implementation bind Agent Agent Agent/Null C++ OTcl domain domainIt reuses that of the base class, class Agent 15 www.ns2ultimate.com
    • 16. 1.Direct Packet Destruction void Agent::recv(Packet* p, Handler*) { if (app_) app_->recv(hdr_cmn::access(p)->size()); Packet::free(p); }Direct packet dropping: If the application (app_) Regardless of the exists, exists, inform theexistence of application, application of the size ofdestroy the packet using the received packet “free(p)”. 16 www.ns2ultimate.com
    • 17. 1.Direct DestructionRecap: To drop a packet, S can just invoke Packet::free(ppt)From within its scope spt ppt P NsObject S packet 17 www.ns2ultimate.com
    • 18. the second method: Send toa dropping object 18
    • 19. Modifying The ScenarioDo not let S drop the packetLet S send the packet to a dropping object D spt ppt P NsObject S packet 19 www.ns2ultimate.com
    • 20. 2. Send to a dropping object Do not let S drop the packet Let S send the packet to a dropping object D ➠ Execute “dpt->recv(ppt,h)” spt ppt P NsObjectS packet 20 www.ns2ultimate.com
    • 21. 2. Send to a dropping object Do not let S drop the packet Let S send the packet to a dropping object D ➠ Execute “dpt->recv(ppt,h)” D uses the direction packet dropping spt ppt dpt P P NsObject NsObjectS packet packet D 21 www.ns2ultimate.com
    • 22. 2. Send to a dropping object One last question: Q: How do we get “dpt” from the first place? A: We do it though Tcl/OTcl spt ppt dpt NsObject P NsObjectS packet D 22 www.ns2ultimate.com
    • 23. OUTLINEReview of main packet operationsPacket destruction function• Direct packet destruction (Packet::free(p))• Send to a dropping objectExample packet dropping process 23 www.ns2ultimate.com
    • 24. Example: Connector base class Connector connects to NsObject NsObjects. Common examples of Connector connectors are TcpAgent and Droptail (queue). Agent Let’s try to configure dropping for a connector.derived class 24 www.ns2ultimate.com
    • 25. Configuring Dropping Objects Recall the packet dropping topology spt ppt dpt NsObject P NsObjectS packet D 25 www.ns2ultimate.com
    • 26. Configuring Dropping Objects Recall the packet dropping topology Connector contains A pointer drop_ to a dropping object A pointer target_ to the next downstream object spt ppt drop_ NsObject Connector P Connector NsObjectS packet D 26 www.ns2ultimate.com
    • 27. Configuring Dropping Objects Connector architecture [see previous post]100 5 Network Objects Connector NsObject NsObject target_ Upstream Packet forwarding path Downstream NsObject NsObject drop_ class Connector : public NsObject { Packet dropping public: path NsObject Connector(); Packet Dropping NsObject NsObject* target_;Fig. 5.2. Diagram of a connector: The solid arrows represent NsObject* drop_; pointers, while thedotted arrows show packet forwarding and dropping paths. };Program 5.3 Declaration and function recv(p,h) of class Connector 27 www.ns2ultimate.com
    • 28. Configuring Dropping Objects To drop a packet, “send the packet to the dropping NsObject” void Connector::drop(Packet* p) { if (drop_ != 0) drop_->recv(p); else Packet::free(p); } Send a packet *p to theWhich is exactly NsObject *drop_what we want! 28 www.ns2ultimate.com
    • 29. Configuring Dropping ObjectsSyntax of drop-targetInvoked from the OTcl domain $conn drop-target $drp-objIf $drp-obj exist ➠ set $drp-obj to be adropping object of $connOtherwise, return the dropping object of $conn 29 www.ns2ultimate.com
    • 30. Configuring Dropping Objects Class connector provides an OTcl command drop-target to set the dropping objectvoid Connector::command(int argc, const char*const* argv){ OTcl command if (strcmp(argv[1], "drop-target") == 0) { drop-target drop_ = (NsObject*)TclObject::lookup(argv[2]); ... Store the input in the variable drop_} 30 www.ns2ultimate.com
    • 31. Configuring Dropping Objects Suppose we want • A sending object to S to be an Agent/TCP object • A dropping object D to be a Null Agent object spt ppt drop_ packet P Agent/TCP NsObject Agent/Null NsObjectS D 31 www.ns2ultimate.com
    • 32. Configuring Dropping Objects Here are what we do 1. Create both the object set $s new [Agent/TCP] set $d new[Agent/Null] drop_ Agent/TCP NsObject Agent/Null NsObjectS D 32 www.ns2ultimate.com
    • 33. Configuring Dropping Objects Here are what we do 1. Create both the object set $s new [Agent/TCP] set $d new[Agent/Null] 2. Configure S using “drop-target” $s drop-target $d drop_ Agent/TCP NsObject Agent/Null NsObjectS D 33 www.ns2ultimate.com
    • 34. Configuring Dropping Objects To drop a packet P, execute the following C++ statement from the scope of S drop(ppt); The packet will be forwarded to D for destruction spt ppt drop_ packet P Agent/TCP NsObject Agent/Null NsObjectS D 34 www.ns2ultimate.com
    • 35. 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 35