SlideShare a Scribd company logo
1 of 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 create 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>]
which creates an object of class <className> and store the
created object in the variable <var>. Note, [<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.
E.g., Class Agent/TCP derives from class Agent
When we see
the statement “eval $self next” executes to
“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>]
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:
1. Step 6 in Part I
2. The C++ function create-shadow(...) of
class TclClass
3. The C++ function create(...) of class
TcpClass
4. 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

More Related Content

What's hot

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
 
iOS Development with Blocks
iOS Development with BlocksiOS Development with Blocks
iOS Development with BlocksJeff Kelley
 
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
 
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
 
AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokusHamletDRC
 
Operator overloading2
Operator overloading2Operator overloading2
Operator overloading2zindadili
 
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
 
Inheritance patterns
Inheritance patternsInheritance patterns
Inheritance patternsLuke Smith
 
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
 
ooc - OSDC 2010 - Amos Wenger
ooc - OSDC 2010 - Amos Wengerooc - OSDC 2010 - Amos Wenger
ooc - OSDC 2010 - Amos WengerAmos Wenger
 
Python and GObject Introspection
Python and GObject IntrospectionPython and GObject Introspection
Python and GObject IntrospectionYuren Ju
 
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
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency GotchasAlex Miller
 
One Year of Clean Architecture - The Good, The Bad and The Bob
One Year of Clean Architecture - The Good, The Bad and The BobOne Year of Clean Architecture - The Good, The Bad and The Bob
One Year of Clean Architecture - The Good, The Bad and The BobOCTO Technology
 
The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84Mahmoud Samir Fayed
 
AST Transformations
AST TransformationsAST Transformations
AST TransformationsHamletDRC
 
The Ring programming language version 1.10 book - Part 102 of 212
The Ring programming language version 1.10 book - Part 102 of 212The Ring programming language version 1.10 book - Part 102 of 212
The Ring programming language version 1.10 book - Part 102 of 212Mahmoud Samir Fayed
 

What's hot (20)

ConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with Groovy
 
C++ idioms.pptx
C++ idioms.pptxC++ idioms.pptx
C++ idioms.pptx
 
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
 
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
 
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
 
강의자료8
강의자료8강의자료8
강의자료8
 
AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokus
 
Operator overloading2
Operator overloading2Operator overloading2
Operator overloading2
 
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
 
Inheritance patterns
Inheritance patternsInheritance patterns
Inheritance patterns
 
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...
 
ooc - OSDC 2010 - Amos Wenger
ooc - OSDC 2010 - Amos Wengerooc - OSDC 2010 - Amos Wenger
ooc - OSDC 2010 - Amos Wenger
 
Python and GObject Introspection
Python and GObject IntrospectionPython and GObject Introspection
Python and GObject Introspection
 
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++
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency Gotchas
 
One Year of Clean Architecture - The Good, The Bad and The Bob
One Year of Clean Architecture - The Good, The Bad and The BobOne Year of Clean Architecture - The Good, The Bad and The Bob
One Year of Clean Architecture - The Good, The Bad and The Bob
 
The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.2 book - Part 5 of 84
 
AST Transformations
AST TransformationsAST Transformations
AST Transformations
 
The Ring programming language version 1.10 book - Part 102 of 212
The Ring programming language version 1.10 book - Part 102 of 212The Ring programming language version 1.10 book - Part 102 of 212
The Ring programming language version 1.10 book - Part 102 of 212
 

Viewers also liked

Viewers also liked (9)

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
 
Dynamic UID
Dynamic UIDDynamic UID
Dynamic UID
 
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
 

Similar to NS2 Shadow 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
 
Untitled presentation(4)
Untitled presentation(4)Untitled presentation(4)
Untitled presentation(4)chan20kaur
 
Ns2: OTCL - PArt II
Ns2: OTCL - PArt IINs2: OTCL - PArt II
Ns2: OTCL - PArt IIAjit Nayak
 
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
 
droidcon Transylvania - Kotlin Coroutines
droidcon Transylvania - Kotlin Coroutinesdroidcon Transylvania - Kotlin Coroutines
droidcon Transylvania - Kotlin CoroutinesArthur Nagy
 
MattsonTutorialSC14.pptx
MattsonTutorialSC14.pptxMattsonTutorialSC14.pptx
MattsonTutorialSC14.pptxgopikahari7
 
Install Project INK
Install Project INKInstall Project INK
Install Project INKIshanJoshi36
 
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
 
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
 
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
 
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdfSelvaraj Seerangan
 
New c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNew c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNico Ludwig
 
Working in the multi-cloud with libcloud
Working in the multi-cloud with libcloudWorking in the multi-cloud with libcloud
Working in the multi-cloud with libcloudGrig Gheorghiu
 
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
 
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
 
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
 

Similar to NS2 Shadow 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
 
Juggva cloud
Juggva cloudJuggva cloud
Juggva cloud
 
Integrating cloud stack with puppet
Integrating cloud stack with puppetIntegrating cloud stack with puppet
Integrating cloud stack with puppet
 
Untitled presentation(4)
Untitled presentation(4)Untitled presentation(4)
Untitled presentation(4)
 
Qt coin3d soqt
Qt coin3d soqtQt coin3d soqt
Qt coin3d soqt
 
Ns2: OTCL - PArt II
Ns2: OTCL - PArt IINs2: OTCL - PArt II
Ns2: OTCL - PArt II
 
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
 
droidcon Transylvania - Kotlin Coroutines
droidcon Transylvania - Kotlin Coroutinesdroidcon Transylvania - Kotlin Coroutines
droidcon Transylvania - Kotlin Coroutines
 
MattsonTutorialSC14.pptx
MattsonTutorialSC14.pptxMattsonTutorialSC14.pptx
MattsonTutorialSC14.pptx
 
Install Project INK
Install Project INKInstall Project INK
Install Project INK
 
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
 
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...
 
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
 
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
 
New c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNew c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_i
 
Shadow Objects
Shadow ObjectsShadow Objects
Shadow Objects
 
Working in the multi-cloud with libcloud
Working in the multi-cloud with libcloudWorking in the multi-cloud with libcloud
Working in the multi-cloud with libcloud
 
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
 
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
 
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
 

Recently uploaded

KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
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
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
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
 

Recently uploaded (20)

KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
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
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
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
 

NS2 Shadow 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 create 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>] which creates an object of class <className> and store the created object in the variable <var>. Note, [<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. E.g., Class Agent/TCP derives from class Agent When we see the statement “eval $self next” executes to “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>] 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: 1. Step 6 in Part I 2. The C++ function create-shadow(...) of class TclClass 3. The C++ function create(...) of class TcpClass 4. 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

Editor's Notes

  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.