SlideShare une entreprise Scribd logo
1  sur  11
NS2: BindingVariablesNS2: BindingVariables
by Teerawat Issariyakul
http://www.ns2ultimate.com
July 2010
http://www.ns2ultimate.com 1
OutlineOutline
Introduction
Motivation
What we would like to do
Let’s bind the variables
See if it works
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.Why Two 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
C++: Internal mechanism
OTcl: Configuration
Modify C++ class variable from OTcl domain
and vice versa.
http://www.ns2ultimate.com 4
ocount_count_
MyObject MyOTclObject
What we would like to doWhat we would like to do
http://www.ns2ultimate.com 5
C++:
oclass = MyObject
ovariable = count_
OTcl:
oclass = MyOTclObject
ovariable = ocount_
Bind C++ and OTcl
ocount_count_
MyObject MyOTclObject
binding class name
binding variable
Let’s Bind theVariableLet’s Bind theVariable
Binding class name [see here and here]
http://www.ns2ultimate.com 6
static class MyObjectClass : public TclClass {
public:
MyObjectClass() : TclClass("MyOTclObject")
{}
TclObject* create(int, const char*const*) {
return (new MyObject());
}
} class_my_object;
Binding SyntaxBinding Syntax
Put the following command in the C++
constructor:
◦ otcl_var_name = the name of OTcl variable
◦ c_var_name = the name of C++ variable
Example:
http://www.ns2ultimate.com 7
bind(“<otcl_var_name>”,<c_var_name>);
MyObject::MyObject()
{
bind("ocount_",&count_);
count_ = 10;
}
Summary of Key StepsSummary of Key Steps
1. Create file otcl.cc and otcl.h with the
details explained earlier
2. Modify Makefile—including otcl.o into the
compilation list [see detail here]
3. run “make” from the command prompt
4. Create file otcl.tcl for testing
4.1 In the C++ constructor: set count_ to be 10
4.2 Create an OTcl object
4.3 Show the value of count_ on the screen
4.4 Change the C++ constructor: set count_ to be 20
4.5 Repeat 4.2 and 4.3
http://www.ns2ultimate.com 8
File otcl.tcl
Run the file otcl.tcl
See If It WorksSee If It Works
http://www.ns2ultimate.com 9
set ns [new Simulator]
set obj [new MyOTclObject]
puts "The variable count is [$obj set ocount_]"
 Modify the constructor
 Run the file otcl.tcl again
 The change was made in the C++ domain (MyObject::count_); The effect was
carried over to the OTcl domain (MyOTclObject::ocount_)
See If It WorksSee If It Works
http://www.ns2ultimate.com 10
MyObject::MyObject()
{
bind("ocount_",&count_);
count_ = 20;
}
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 11

Contenu connexe

Tendances

Study of aloha protocol using ns2 network java proram
Study of aloha protocol using ns2 network java proramStudy of aloha protocol using ns2 network java proram
Study of aloha protocol using ns2 network java proram
Meenakshi Devi
 
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
Stefan Marr
 

Tendances (20)

Ns tutorial
Ns tutorialNs tutorial
Ns tutorial
 
Ns network simulator
Ns network simulatorNs network simulator
Ns network simulator
 
Study of aloha protocol using ns2 network java proram
Study of aloha protocol using ns2 network java proramStudy of aloha protocol using ns2 network java proram
Study of aloha protocol using ns2 network java proram
 
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
 
iOS Development with Blocks
iOS Development with BlocksiOS Development with Blocks
iOS Development with Blocks
 
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
 
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...
 
Ns 2 Network Simulator An Introduction
Ns 2 Network Simulator An IntroductionNs 2 Network Simulator An Introduction
Ns 2 Network Simulator An Introduction
 
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
 
C++ & Java JIT Optimizations: Finding Prime Numbers
C++ & Java JIT Optimizations: Finding Prime NumbersC++ & Java JIT Optimizations: Finding Prime Numbers
C++ & Java JIT Optimizations: Finding Prime Numbers
 
Yevhen Tatarynov "From POC to High-Performance .NET applications"
Yevhen Tatarynov "From POC to High-Performance .NET applications"Yevhen Tatarynov "From POC to High-Performance .NET applications"
Yevhen Tatarynov "From POC to High-Performance .NET applications"
 
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash course
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash courseCodepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash course
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash course
 
Functional Reactive Programming with RxJS
Functional Reactive Programming with RxJSFunctional Reactive Programming with RxJS
Functional Reactive Programming with RxJS
 
The Big Three
The Big ThreeThe Big Three
The Big Three
 
Concurrency Concepts in Java
Concurrency Concepts in JavaConcurrency Concepts in Java
Concurrency Concepts in Java
 
Actor Concurrency
Actor ConcurrencyActor Concurrency
Actor Concurrency
 
Netty: asynchronous data transfer
Netty: asynchronous data transferNetty: asynchronous data transfer
Netty: asynchronous data transfer
 
Yevhen Tatarynov "My .NET Application Allocates too Much Memory. What Can I Do?"
Yevhen Tatarynov "My .NET Application Allocates too Much Memory. What Can I Do?"Yevhen Tatarynov "My .NET Application Allocates too Much Memory. What Can I Do?"
Yevhen Tatarynov "My .NET Application Allocates too Much Memory. What Can I Do?"
 
F# Presentation for SmartDevs, Hereford
F# Presentation for SmartDevs, HerefordF# Presentation for SmartDevs, Hereford
F# Presentation for SmartDevs, Hereford
 
Oleksandr Kutsan "Using katai struct to describe the process of working with ...
Oleksandr Kutsan "Using katai struct to describe the process of working with ...Oleksandr Kutsan "Using katai struct to describe the process of working with ...
Oleksandr Kutsan "Using katai struct to describe the process of working with ...
 

En vedette (14)

Dynamic UID
Dynamic UIDDynamic UID
Dynamic UID
 
Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34
 
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
 
NS-2 Tutorial
NS-2 TutorialNS-2 Tutorial
NS-2 Tutorial
 
Protocol implementation on NS2
Protocol implementation on NS2Protocol implementation on NS2
Protocol implementation on NS2
 
Ns2
Ns2Ns2
Ns2
 
Programming Haskell Chapter8
Programming Haskell Chapter8Programming Haskell Chapter8
Programming Haskell Chapter8
 
Subprogram
SubprogramSubprogram
Subprogram
 
Algorithms Vs Meta Language
Algorithms Vs Meta LanguageAlgorithms Vs Meta Language
Algorithms Vs Meta Language
 
Intelligent entrepreneurs by Bill Murphy Jr.
Intelligent entrepreneurs by Bill Murphy Jr.Intelligent entrepreneurs by Bill Murphy Jr.
Intelligent entrepreneurs by Bill Murphy Jr.
 
Control structure
Control structureControl structure
Control structure
 
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
 

Similaire à NS2: Binding C++ and OTcl variables

friends functionToshu
friends functionToshufriends functionToshu
friends functionToshu
Sidd Singh
 
MattsonTutorialSC14.pptx
MattsonTutorialSC14.pptxMattsonTutorialSC14.pptx
MattsonTutorialSC14.pptx
gopikahari7
 
websphere cast iron labs
 websphere cast iron labs websphere cast iron labs
websphere cast iron labs
AMIT KUMAR
 
15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docx
15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docx15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docx
15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docx
felicidaddinwoodie
 

Similaire à NS2: Binding C++ and OTcl variables (20)

friends functionToshu
friends functionToshufriends functionToshu
friends functionToshu
 
The Ring programming language version 1.6 book - Part 7 of 189
The Ring programming language version 1.6 book - Part 7 of 189The Ring programming language version 1.6 book - Part 7 of 189
The Ring programming language version 1.6 book - Part 7 of 189
 
Ns2: OTCL - PArt II
Ns2: OTCL - PArt IINs2: OTCL - PArt II
Ns2: OTCL - PArt II
 
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
 
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
 
MattsonTutorialSC14.pptx
MattsonTutorialSC14.pptxMattsonTutorialSC14.pptx
MattsonTutorialSC14.pptx
 
cscript_controller.pdf
cscript_controller.pdfcscript_controller.pdf
cscript_controller.pdf
 
MattsonTutorialSC14.pdf
MattsonTutorialSC14.pdfMattsonTutorialSC14.pdf
MattsonTutorialSC14.pdf
 
chapter-9-constructors.pdf
chapter-9-constructors.pdfchapter-9-constructors.pdf
chapter-9-constructors.pdf
 
websphere cast iron labs
 websphere cast iron labs websphere cast iron labs
websphere cast iron labs
 
Apache Calcite Tutorial - BOSS 21
Apache Calcite Tutorial - BOSS 21Apache Calcite Tutorial - BOSS 21
Apache Calcite Tutorial - BOSS 21
 
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
 
Objective-C Runtime overview
Objective-C Runtime overviewObjective-C Runtime overview
Objective-C Runtime overview
 
The Ring programming language version 1.8 book - Part 95 of 202
The Ring programming language version 1.8 book - Part 95 of 202The Ring programming language version 1.8 book - Part 95 of 202
The Ring programming language version 1.8 book - Part 95 of 202
 
Classes and data abstraction
Classes and data abstractionClasses and data abstraction
Classes and data abstraction
 
C chap16
C chap16C chap16
C chap16
 
computer notes - Reference variables ii
computer notes - Reference variables iicomputer notes - Reference variables ii
computer notes - Reference variables ii
 
Entity Framework v2 Best Practices
Entity Framework v2 Best PracticesEntity Framework v2 Best Practices
Entity Framework v2 Best Practices
 
CS4961-L9.ppt
CS4961-L9.pptCS4961-L9.ppt
CS4961-L9.ppt
 
15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docx
15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docx15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docx
15LLP108_Demo4_LedBlinking.pdf1. Introduction In D.docx
 

Dernier

Dernier (20)

Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
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
 
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
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 

NS2: Binding C++ and OTcl variables

  • 1. NS2: BindingVariablesNS2: BindingVariables by Teerawat Issariyakul http://www.ns2ultimate.com July 2010 http://www.ns2ultimate.com 1
  • 2. OutlineOutline Introduction Motivation What we would like to do Let’s bind the variables See if it works 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.Why Two 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 C++: Internal mechanism OTcl: Configuration Modify C++ class variable from OTcl domain and vice versa. http://www.ns2ultimate.com 4 ocount_count_ MyObject MyOTclObject
  • 5. What we would like to doWhat we would like to do http://www.ns2ultimate.com 5 C++: oclass = MyObject ovariable = count_ OTcl: oclass = MyOTclObject ovariable = ocount_ Bind C++ and OTcl ocount_count_ MyObject MyOTclObject binding class name binding variable
  • 6. Let’s Bind theVariableLet’s Bind theVariable Binding class name [see here and here] http://www.ns2ultimate.com 6 static class MyObjectClass : public TclClass { public: MyObjectClass() : TclClass("MyOTclObject") {} TclObject* create(int, const char*const*) { return (new MyObject()); } } class_my_object;
  • 7. Binding SyntaxBinding Syntax Put the following command in the C++ constructor: ◦ otcl_var_name = the name of OTcl variable ◦ c_var_name = the name of C++ variable Example: http://www.ns2ultimate.com 7 bind(“<otcl_var_name>”,<c_var_name>); MyObject::MyObject() { bind("ocount_",&count_); count_ = 10; }
  • 8. Summary of Key StepsSummary of Key Steps 1. Create file otcl.cc and otcl.h with the details explained earlier 2. Modify Makefile—including otcl.o into the compilation list [see detail here] 3. run “make” from the command prompt 4. Create file otcl.tcl for testing 4.1 In the C++ constructor: set count_ to be 10 4.2 Create an OTcl object 4.3 Show the value of count_ on the screen 4.4 Change the C++ constructor: set count_ to be 20 4.5 Repeat 4.2 and 4.3 http://www.ns2ultimate.com 8
  • 9. File otcl.tcl Run the file otcl.tcl See If It WorksSee If It Works http://www.ns2ultimate.com 9 set ns [new Simulator] set obj [new MyOTclObject] puts "The variable count is [$obj set ocount_]"
  • 10.  Modify the constructor  Run the file otcl.tcl again  The change was made in the C++ domain (MyObject::count_); The effect was carried over to the OTcl domain (MyOTclObject::ocount_) See If It WorksSee If It Works http://www.ns2ultimate.com 10 MyObject::MyObject() { bind("ocount_",&count_); count_ = 20; }
  • 11. 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 11

Notes de l'éditeur

  1. Tip: Add your own speaker notes here.
  2. Tip: Add your own speaker notes here.
  3. Tip: Add your own speaker notes here.
  4. Tip: Add your own speaker notes here.
  5. Tip: Add your own speaker notes here.
  6. Tip: Add your own speaker notes here.
  7. Tip: Add your own speaker notes here.
  8. Tip: Add your own speaker notes here.
  9. Tip: Add your own speaker notes here.