SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 

Kürzlich hochgeladen (20)

How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.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

Hinweis der Redaktion

  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.