SlideShare une entreprise Scribd logo
1  sur  24
NS2: Shadow ObjectNS2: Shadow Object
ConstructionConstruction
by Teerawat Issariyakul
http://www.ns2ultimate.com
October 2010
http://www.ns2ultimate.com 1
OutlineOutline
Introduction
Creating an OTcl object
Shadow Object Construction Process
Summary
http://www.ns2ultimate.com 2
IntroductionIntroduction
This is a series on how NS2 binds C++ and OTcl together.This is the
second topic of the series:
1.WhyTwo Languages?
2. Binding C++ and OTcl classes
3. Variable binding
4. OTcl command: Invoking C++ statements from the OTcl domain
5. Eval and result: Invoking OTcl statements from the C++ domain
6. Object binding and object construction process.
http://www.ns2ultimate.com 3
MotivationMotivation
http://www.ns2ultimate.com 4
 NS2 consists of 2 languages:
◦ OTcl: A user interface language used to create objects
◦ C++: A language defining the created objects’ attributes and
behaviors
 Objects in NS2
◦ A user creates an object from the OTcl domain
◦ NS2 automatically creates a “shadow” object in the C++ domain
 From the user perspective, these two objects are the same.
Suppose we have two bound classes
We are going to learn how EXACTLY
NS2 auto. create a shadow object.
What We Would Like to Do?What We Would Like to Do?
http://www.ns2ultimate.com 5
TCPAgent
C++
Agent/TCP
OTcl
bound
user
obj
create
c_obj
Auto. construction by NS2
shadow object
OutlineOutline
Introduction
Creating an OTcl object
Shadow Object Construction Process
Summary
http://www.ns2ultimate.com 6
Creating an OTcl ObjectCreating an OTcl Object
http://www.ns2ultimate.com 7
 An OTcl is created using the following syntax
<className> create <var> [<args>]
◦ Create an object of class <className>
◦ Store the created object in the variable <var>
◦ <args>]is optional input argument for object construction.
 There are two key steps when invoking new
◦ Executing instproc “alloc” to allocate memory to hold the object
◦ Executing instproc “init” (i.e., the constructor) to initialize class variables
Instproc “Instproc “initinit””
http://www.ns2ultimate.com 8
It initializes class variables
It is referred to as “the constructor”
OOP structure
◦ Call the constructor of the base class first
◦ Use the instproc next
Instproc “Instproc “nextnext””
http://www.ns2ultimate.com 9
Instproc “next” executes the instproc with the
same name located in the parent class.
Example
◦ Class Agent/TCP derives from class Agent
◦ When we see
◦ the statement “eval $self next” executes “Agent
init {}”.
Agent/TCP instproc init
{} {
eval $self next
…
}
OutlineOutline
Introduction
Creating an OTcl object
Shadow Object Construction Process
Summary
http://www.ns2ultimate.com 10
Shadow Object ConstructionShadow Object Construction
The process consists of two part
◦ Part I: OTcl—Creating an object using “new”
◦ Part II: C++—Shadow object construction
http://www.ns2ultimate.com 11
Part I: OTcl Part II: C++
Shadow Object ConstructionShadow Object Construction
Let’s use the following example
◦ OTcl class: Agent/TCP
◦ C++ class: TcpAgent
In OTcl, create an object using
new Agent/TCP
In C++, create a shadow TcpAgent
object
http://www.ns2ultimate.com 12
Part I: OTclPart I: OTcl
Main steps of Part I:
The OTcl statement new <classname> [<args>]
The OTcl statement $classname create $o $args
The instproc alloc of the OTcl class <classname>
The instproc init of the OTcl class <classname>
The instproc init of the OTcl class SplitObject
The OTcl statement $self create-shadow $args
http://www.ns2ultimate.com 13
Part I: OTclPart I: OTcl
1. The OTcl statement new <classname>
[<args>]Execute a global procedure
“new”
http://www.ns2ultimate.com 14
proc new { className args } {
set o [SplitObject getid]
if [catch "$className create $o $args" msg] {
...
}
return $o
}
step 2
Part I: OTclPart I: OTcl
2.The OTcl statement $classname create
$o $args
Again, the instproc create invokes two
instprocs in Steps 3 and 4.
3.The instproc alloc of the OTcl class
<classname>: Memory allocation
http://www.ns2ultimate.com 15
Part I: OTclPart I: OTcl
4.The instproc init of the OTcl class
<classname>
A general structure of the the instproc init is
to invoke the instproc init of the base class until
reaching the top level class, e.g.,
The top level class is class SplitObject 
Step 5
http://www.ns2ultimate.com 16
Agent/TCP instproc init
{} {
eval $self next
…
}
Part I: OTclPart I: OTcl
5. The instproc init of the OTcl class SplitObject
6. The OTcl statement $self create-shadow
$args:
 This executes, for example, instproc create-shadow
of class Agent/TCP
http://www.ns2ultimate.com 17
SplitObject instproc init args {
$self next
if [catch "$self create-shadow $args"] {
error "__FAILED_SHADOW_OBJECT_" ""
}
}
Part II: C++Part II: C++
http://www.ns2ultimate.com 18
Part I completes with the OTcl command
create-shadow.
In Part II, we are moving to the C++ domain.
Part I: OTcl Part II: C++
Part II: C++Part II: C++
http://www.ns2ultimate.com 19
Let’s use an example of class TcpAgent
Main steps of Part II:
Step 6 in Part I
The C++ function create-shadow(...) of
class TclClass
 The C++ function create(...) of class
TcpClass
The C++ statement new TcpAgent()
Part II: C++Part II: C++
http://www.ns2ultimate.com 20
1. Step 6 in Part I:
The OTcl command create-shadow is bound to
The C++ function create-shadow(...) of class
TclClass
2.The C++ function create-shadow(...) of
class TclClass
3.The C++ function create(...) of class
TcpClass
Part II: C++Part II: C++
http://www.ns2ultimate.com 21
3.The C++ function create(...) of class
TcpClass
4. The C++ statement new TcpAgent(): Create
a shadow object
static class TcpClass : public TclClass {
public:
TcpClass() : TclClass("Agent/TCP") {}
TclObject* create(int , const char*const*) {
return (new TcpAgent());
}
} class_tcp;
Step 4
OutlineOutline
Introduction
Creating an OTcl object
Shadow Object Construction Process
Summary
http://www.ns2ultimate.com 22
SummarySummary
In NS2, a user creates an object from the OTcl
domain using a global procedure “new”
NS2 automatically creates a so-called shadow
object in the C++ domain.
The shadow object construction consists of 2
parts:
◦ Part 1: Execute OTcl constructors
◦ Part II: Create a shadow object in the C++ domain.
http://www.ns2ultimate.com 23
For more information aboutFor more information about
NS 2NS 2
Please see this book from Springer
T. Issaraiyakul and E. Hossain, “Introduction to
Network Simulator NS2”, Springer 2009
http://www.ns2ultimate.com 24

Contenu connexe

Tendances

iOS Development with Blocks
iOS Development with BlocksiOS Development with Blocks
iOS Development with BlocksJeff Kelley
 
Virtual machine and javascript engine
Virtual machine and javascript engineVirtual machine and javascript engine
Virtual machine and javascript engineDuoyi Wu
 
Gor Nishanov, C++ Coroutines – a negative overhead abstraction
Gor Nishanov,  C++ Coroutines – a negative overhead abstractionGor Nishanov,  C++ Coroutines – a negative overhead abstraction
Gor Nishanov, C++ Coroutines – a negative overhead abstractionSergey Platonov
 
ConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyIván López Martín
 
Actor Concurrency
Actor ConcurrencyActor Concurrency
Actor ConcurrencyAlex Miller
 
ooc - OSDC 2010 - Amos Wenger
ooc - OSDC 2010 - Amos Wengerooc - OSDC 2010 - Amos Wenger
ooc - OSDC 2010 - Amos WengerAmos Wenger
 
Start Wrap Episode 11: A New Rope
Start Wrap Episode 11: A New RopeStart Wrap Episode 11: A New Rope
Start Wrap Episode 11: A New RopeYung-Yu Chen
 
Arduino C maXbox web of things slide show
Arduino C maXbox web of things slide showArduino C maXbox web of things slide show
Arduino C maXbox web of things slide showMax Kleiner
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and DestructorsKeyur Vadodariya
 
Swift Sequences & Collections
Swift Sequences & CollectionsSwift Sequences & Collections
Swift Sequences & CollectionsCocoaHeads France
 
Writing native bindings to node.js in C++
Writing native bindings to node.js in C++Writing native bindings to node.js in C++
Writing native bindings to node.js in C++nsm.nikhil
 
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"OdessaJS Conf
 
Building High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low EffortBuilding High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low EffortStefan Marr
 
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...Stefan Marr
 
AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokusHamletDRC
 

Tendances (20)

iOS Development with Blocks
iOS Development with BlocksiOS Development with Blocks
iOS Development with Blocks
 
MFC Message Handling
MFC Message HandlingMFC Message Handling
MFC Message Handling
 
Node.js extensions in C++
Node.js extensions in C++Node.js extensions in C++
Node.js extensions in C++
 
Extending Node.js using C++
Extending Node.js using C++Extending Node.js using C++
Extending Node.js using C++
 
Virtual machine and javascript engine
Virtual machine and javascript engineVirtual machine and javascript engine
Virtual machine and javascript engine
 
Gor Nishanov, C++ Coroutines – a negative overhead abstraction
Gor Nishanov,  C++ Coroutines – a negative overhead abstractionGor Nishanov,  C++ Coroutines – a negative overhead abstraction
Gor Nishanov, C++ Coroutines – a negative overhead abstraction
 
ConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with Groovy
 
Actor Concurrency
Actor ConcurrencyActor Concurrency
Actor Concurrency
 
Constructors & destructors
Constructors & destructorsConstructors & destructors
Constructors & destructors
 
ooc - OSDC 2010 - Amos Wenger
ooc - OSDC 2010 - Amos Wengerooc - OSDC 2010 - Amos Wenger
ooc - OSDC 2010 - Amos Wenger
 
Nicety of Java 8 Multithreading
Nicety of Java 8 MultithreadingNicety of Java 8 Multithreading
Nicety of Java 8 Multithreading
 
Start Wrap Episode 11: A New Rope
Start Wrap Episode 11: A New RopeStart Wrap Episode 11: A New Rope
Start Wrap Episode 11: A New Rope
 
Arduino C maXbox web of things slide show
Arduino C maXbox web of things slide showArduino C maXbox web of things slide show
Arduino C maXbox web of things slide show
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
Swift Sequences & Collections
Swift Sequences & CollectionsSwift Sequences & Collections
Swift Sequences & Collections
 
Writing native bindings to node.js in C++
Writing native bindings to node.js in C++Writing native bindings to node.js in C++
Writing native bindings to node.js in C++
 
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
 
Building High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low EffortBuilding High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low Effort
 
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
 
AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokus
 

En vedette

En vedette (9)

Dynamic UID
Dynamic UIDDynamic UID
Dynamic UID
 
Trump-Style Negotiation: Powerful Strategies and Tactics for Mastering Every ...
Trump-Style Negotiation: Powerful Strategies and Tactics for Mastering Every ...Trump-Style Negotiation: Powerful Strategies and Tactics for Mastering Every ...
Trump-Style Negotiation: Powerful Strategies and Tactics for Mastering Every ...
 
Intelligent entrepreneurs by Bill Murphy Jr.
Intelligent entrepreneurs by Bill Murphy Jr.Intelligent entrepreneurs by Bill Murphy Jr.
Intelligent entrepreneurs by Bill Murphy Jr.
 
Ns-2.35 Installation
Ns-2.35 InstallationNs-2.35 Installation
Ns-2.35 Installation
 
20111107 ns2-required cygwinpkg
20111107 ns2-required cygwinpkg20111107 ns2-required cygwinpkg
20111107 ns2-required cygwinpkg
 
NS2: Events and Handlers
NS2: Events and HandlersNS2: Events and Handlers
NS2: Events and Handlers
 
NS2--Event Scheduler
NS2--Event SchedulerNS2--Event Scheduler
NS2--Event Scheduler
 
20111126 ns2 installation
20111126 ns2 installation20111126 ns2 installation
20111126 ns2 installation
 
LinkedIn powerpoint
LinkedIn powerpointLinkedIn powerpoint
LinkedIn powerpoint
 

Similaire à NS2 Object Construction

TomcatCon: from a cluster to the cloud
TomcatCon: from a cluster to the cloudTomcatCon: from a cluster to the cloud
TomcatCon: from a cluster to the cloudJean-Frederic Clere
 
Integrating cloud stack with puppet
Integrating cloud stack with puppetIntegrating cloud stack with puppet
Integrating cloud stack with puppetPuppet
 
Install Project INK
Install Project INKInstall Project INK
Install Project INKIshanJoshi36
 
The Ring programming language version 1.5.2 book - Part 68 of 181
The Ring programming language version 1.5.2 book - Part 68 of 181The Ring programming language version 1.5.2 book - Part 68 of 181
The Ring programming language version 1.5.2 book - Part 68 of 181Mahmoud Samir Fayed
 
Tomcat from a cluster to the cloud on RP3
Tomcat from a cluster to the cloud on RP3Tomcat from a cluster to the cloud on RP3
Tomcat from a cluster to the cloud on RP3Jean-Frederic Clere
 
Untitled presentation(4)
Untitled presentation(4)Untitled presentation(4)
Untitled presentation(4)chan20kaur
 
MattsonTutorialSC14.pptx
MattsonTutorialSC14.pptxMattsonTutorialSC14.pptx
MattsonTutorialSC14.pptxgopikahari7
 
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdfSelvaraj Seerangan
 
Mastering Terraform and the Provider for OCI
Mastering Terraform and the Provider for OCIMastering Terraform and the Provider for OCI
Mastering Terraform and the Provider for OCIGregory GUILLOU
 
Ns2: OTCL - PArt II
Ns2: OTCL - PArt IINs2: OTCL - PArt II
Ns2: OTCL - PArt IIAjit Nayak
 
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...Andrey Karpov
 
The Ring programming language version 1.10 book - Part 83 of 212
The Ring programming language version 1.10 book - Part 83 of 212The Ring programming language version 1.10 book - Part 83 of 212
The Ring programming language version 1.10 book - Part 83 of 212Mahmoud Samir Fayed
 
droidcon Transylvania - Kotlin Coroutines
droidcon Transylvania - Kotlin Coroutinesdroidcon Transylvania - Kotlin Coroutines
droidcon Transylvania - Kotlin CoroutinesArthur Nagy
 
38199728 multi-player-tutorial
38199728 multi-player-tutorial38199728 multi-player-tutorial
38199728 multi-player-tutorialalfrecaay
 
The Ring programming language version 1.7 book - Part 82 of 196
The Ring programming language version 1.7 book - Part 82 of 196The Ring programming language version 1.7 book - Part 82 of 196
The Ring programming language version 1.7 book - Part 82 of 196Mahmoud Samir Fayed
 
Getting-Started-with-Containers-and-Kubernetes_-March-2020-CNCF-Webinar.pdf
Getting-Started-with-Containers-and-Kubernetes_-March-2020-CNCF-Webinar.pdfGetting-Started-with-Containers-and-Kubernetes_-March-2020-CNCF-Webinar.pdf
Getting-Started-with-Containers-and-Kubernetes_-March-2020-CNCF-Webinar.pdfssuser348b1c
 
The Ring programming language version 1.2 book - Part 51 of 84
The Ring programming language version 1.2 book - Part 51 of 84The Ring programming language version 1.2 book - Part 51 of 84
The Ring programming language version 1.2 book - Part 51 of 84Mahmoud Samir Fayed
 

Similaire à NS2 Object Construction (20)

TomcatCon: from a cluster to the cloud
TomcatCon: from a cluster to the cloudTomcatCon: from a cluster to the cloud
TomcatCon: from a cluster to the cloud
 
Integrating cloud stack with puppet
Integrating cloud stack with puppetIntegrating cloud stack with puppet
Integrating cloud stack with puppet
 
Juggva cloud
Juggva cloudJuggva cloud
Juggva cloud
 
Install Project INK
Install Project INKInstall Project INK
Install Project INK
 
The Ring programming language version 1.5.2 book - Part 68 of 181
The Ring programming language version 1.5.2 book - Part 68 of 181The Ring programming language version 1.5.2 book - Part 68 of 181
The Ring programming language version 1.5.2 book - Part 68 of 181
 
Tomcat from a cluster to the cloud on RP3
Tomcat from a cluster to the cloud on RP3Tomcat from a cluster to the cloud on RP3
Tomcat from a cluster to the cloud on RP3
 
Untitled presentation(4)
Untitled presentation(4)Untitled presentation(4)
Untitled presentation(4)
 
Qt coin3d soqt
Qt coin3d soqtQt coin3d soqt
Qt coin3d soqt
 
MattsonTutorialSC14.pptx
MattsonTutorialSC14.pptxMattsonTutorialSC14.pptx
MattsonTutorialSC14.pptx
 
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
 
Mastering Terraform and the Provider for OCI
Mastering Terraform and the Provider for OCIMastering Terraform and the Provider for OCI
Mastering Terraform and the Provider for OCI
 
Ns2: OTCL - PArt II
Ns2: OTCL - PArt IINs2: OTCL - PArt II
Ns2: OTCL - PArt II
 
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
 
The Ring programming language version 1.10 book - Part 83 of 212
The Ring programming language version 1.10 book - Part 83 of 212The Ring programming language version 1.10 book - Part 83 of 212
The Ring programming language version 1.10 book - Part 83 of 212
 
droidcon Transylvania - Kotlin Coroutines
droidcon Transylvania - Kotlin Coroutinesdroidcon Transylvania - Kotlin Coroutines
droidcon Transylvania - Kotlin Coroutines
 
38199728 multi-player-tutorial
38199728 multi-player-tutorial38199728 multi-player-tutorial
38199728 multi-player-tutorial
 
Learning Docker with Thomas
Learning Docker with ThomasLearning Docker with Thomas
Learning Docker with Thomas
 
The Ring programming language version 1.7 book - Part 82 of 196
The Ring programming language version 1.7 book - Part 82 of 196The Ring programming language version 1.7 book - Part 82 of 196
The Ring programming language version 1.7 book - Part 82 of 196
 
Getting-Started-with-Containers-and-Kubernetes_-March-2020-CNCF-Webinar.pdf
Getting-Started-with-Containers-and-Kubernetes_-March-2020-CNCF-Webinar.pdfGetting-Started-with-Containers-and-Kubernetes_-March-2020-CNCF-Webinar.pdf
Getting-Started-with-Containers-and-Kubernetes_-March-2020-CNCF-Webinar.pdf
 
The Ring programming language version 1.2 book - Part 51 of 84
The Ring programming language version 1.2 book - Part 51 of 84The Ring programming language version 1.2 book - Part 51 of 84
The Ring programming language version 1.2 book - Part 51 of 84
 

Dernier

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 

Dernier (20)

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 

NS2 Object Construction

  • 1. NS2: Shadow ObjectNS2: Shadow Object ConstructionConstruction by Teerawat Issariyakul http://www.ns2ultimate.com October 2010 http://www.ns2ultimate.com 1
  • 2. OutlineOutline Introduction Creating an OTcl object Shadow Object Construction Process Summary http://www.ns2ultimate.com 2
  • 3. IntroductionIntroduction This is a series on how NS2 binds C++ and OTcl together.This is the second topic of the series: 1.WhyTwo Languages? 2. Binding C++ and OTcl classes 3. Variable binding 4. OTcl command: Invoking C++ statements from the OTcl domain 5. Eval and result: Invoking OTcl statements from the C++ domain 6. Object binding and object construction process. http://www.ns2ultimate.com 3
  • 4. MotivationMotivation http://www.ns2ultimate.com 4  NS2 consists of 2 languages: ◦ OTcl: A user interface language used to create objects ◦ C++: A language defining the created objects’ attributes and behaviors  Objects in NS2 ◦ A user creates an object from the OTcl domain ◦ NS2 automatically creates a “shadow” object in the C++ domain  From the user perspective, these two objects are the same.
  • 5. Suppose we have two bound classes We are going to learn how EXACTLY NS2 auto. create a shadow object. What We Would Like to Do?What We Would Like to Do? http://www.ns2ultimate.com 5 TCPAgent C++ Agent/TCP OTcl bound user obj create c_obj Auto. construction by NS2 shadow object
  • 6. OutlineOutline Introduction Creating an OTcl object Shadow Object Construction Process Summary http://www.ns2ultimate.com 6
  • 7. Creating an OTcl ObjectCreating an OTcl Object http://www.ns2ultimate.com 7  An OTcl is created using the following syntax <className> create <var> [<args>] ◦ Create an object of class <className> ◦ Store the created object in the variable <var> ◦ <args>]is optional input argument for object construction.  There are two key steps when invoking new ◦ Executing instproc “alloc” to allocate memory to hold the object ◦ Executing instproc “init” (i.e., the constructor) to initialize class variables
  • 8. Instproc “Instproc “initinit”” http://www.ns2ultimate.com 8 It initializes class variables It is referred to as “the constructor” OOP structure ◦ Call the constructor of the base class first ◦ Use the instproc next
  • 9. Instproc “Instproc “nextnext”” http://www.ns2ultimate.com 9 Instproc “next” executes the instproc with the same name located in the parent class. Example ◦ Class Agent/TCP derives from class Agent ◦ When we see ◦ the statement “eval $self next” executes “Agent init {}”. Agent/TCP instproc init {} { eval $self next … }
  • 10. OutlineOutline Introduction Creating an OTcl object Shadow Object Construction Process Summary http://www.ns2ultimate.com 10
  • 11. Shadow Object ConstructionShadow Object Construction The process consists of two part ◦ Part I: OTcl—Creating an object using “new” ◦ Part II: C++—Shadow object construction http://www.ns2ultimate.com 11 Part I: OTcl Part II: C++
  • 12. Shadow Object ConstructionShadow Object Construction Let’s use the following example ◦ OTcl class: Agent/TCP ◦ C++ class: TcpAgent In OTcl, create an object using new Agent/TCP In C++, create a shadow TcpAgent object http://www.ns2ultimate.com 12
  • 13. Part I: OTclPart I: OTcl Main steps of Part I: The OTcl statement new <classname> [<args>] The OTcl statement $classname create $o $args The instproc alloc of the OTcl class <classname> The instproc init of the OTcl class <classname> The instproc init of the OTcl class SplitObject The OTcl statement $self create-shadow $args http://www.ns2ultimate.com 13
  • 14. Part I: OTclPart I: OTcl 1. The OTcl statement new <classname> [<args>]Execute a global procedure “new” http://www.ns2ultimate.com 14 proc new { className args } { set o [SplitObject getid] if [catch "$className create $o $args" msg] { ... } return $o } step 2
  • 15. Part I: OTclPart I: OTcl 2.The OTcl statement $classname create $o $args Again, the instproc create invokes two instprocs in Steps 3 and 4. 3.The instproc alloc of the OTcl class <classname>: Memory allocation http://www.ns2ultimate.com 15
  • 16. Part I: OTclPart I: OTcl 4.The instproc init of the OTcl class <classname> A general structure of the the instproc init is to invoke the instproc init of the base class until reaching the top level class, e.g., The top level class is class SplitObject  Step 5 http://www.ns2ultimate.com 16 Agent/TCP instproc init {} { eval $self next … }
  • 17. Part I: OTclPart I: OTcl 5. The instproc init of the OTcl class SplitObject 6. The OTcl statement $self create-shadow $args:  This executes, for example, instproc create-shadow of class Agent/TCP http://www.ns2ultimate.com 17 SplitObject instproc init args { $self next if [catch "$self create-shadow $args"] { error "__FAILED_SHADOW_OBJECT_" "" } }
  • 18. Part II: C++Part II: C++ http://www.ns2ultimate.com 18 Part I completes with the OTcl command create-shadow. In Part II, we are moving to the C++ domain. Part I: OTcl Part II: C++
  • 19. Part II: C++Part II: C++ http://www.ns2ultimate.com 19 Let’s use an example of class TcpAgent Main steps of Part II: Step 6 in Part I The C++ function create-shadow(...) of class TclClass  The C++ function create(...) of class TcpClass The C++ statement new TcpAgent()
  • 20. Part II: C++Part II: C++ http://www.ns2ultimate.com 20 1. Step 6 in Part I: The OTcl command create-shadow is bound to The C++ function create-shadow(...) of class TclClass 2.The C++ function create-shadow(...) of class TclClass 3.The C++ function create(...) of class TcpClass
  • 21. Part II: C++Part II: C++ http://www.ns2ultimate.com 21 3.The C++ function create(...) of class TcpClass 4. The C++ statement new TcpAgent(): Create a shadow object static class TcpClass : public TclClass { public: TcpClass() : TclClass("Agent/TCP") {} TclObject* create(int , const char*const*) { return (new TcpAgent()); } } class_tcp; Step 4
  • 22. OutlineOutline Introduction Creating an OTcl object Shadow Object Construction Process Summary http://www.ns2ultimate.com 22
  • 23. SummarySummary In NS2, a user creates an object from the OTcl domain using a global procedure “new” NS2 automatically creates a so-called shadow object in the C++ domain. The shadow object construction consists of 2 parts: ◦ Part 1: Execute OTcl constructors ◦ Part II: Create a shadow object in the C++ domain. http://www.ns2ultimate.com 23
  • 24. For more information aboutFor more information about NS 2NS 2 Please see this book from Springer T. Issaraiyakul and E. Hossain, “Introduction to Network Simulator NS2”, Springer 2009 http://www.ns2ultimate.com 24

Notes de l'éditeur

  1. Tip: Add your own speaker notes here.
  2. Tip: Add your own speaker notes here.
  3. Tip: Add your own speaker notes here.
  4. Tip: Add your own speaker notes here.
  5. Tip: Add your own speaker notes here.
  6. Tip: Add your own speaker notes here.
  7. Tip: Add your own speaker notes here.
  8. Tip: Add your own speaker notes here.
  9. Tip: Add your own speaker notes here.
  10. Tip: Add your own speaker notes here.
  11. Tip: Add your own speaker notes here.
  12. Tip: Add your own speaker notes here.
  13. Tip: Add your own speaker notes here.
  14. Tip: Add your own speaker notes here.
  15. Tip: Add your own speaker notes here.
  16. Tip: Add your own speaker notes here.
  17. Tip: Add your own speaker notes here.
  18. Tip: Add your own speaker notes here.
  19. Tip: Add your own speaker notes here.
  20. Tip: Add your own speaker notes here.
  21. Tip: Add your own speaker notes here.
  22. Tip: Add your own speaker notes here.