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

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
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
“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
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
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
 
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
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 

Recently uploaded (20)

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
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
“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...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
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
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
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
 
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...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 

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.