NS2: Binding C++ and OTcl variables

14,099 views

Published on

Published in: Education, Technology, Business
0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
14,099
On SlideShare
0
From Embeds
0
Number of Embeds
1,520
Actions
Shares
0
Downloads
0
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide
  • Tip: Add your own speaker notes here.
  • Tip: Add your own speaker notes here.
  • Tip: Add your own speaker notes here.
  • Tip: Add your own speaker notes here.
  • Tip: Add your own speaker notes here.
  • Tip: Add your own speaker notes here.
  • Tip: Add your own speaker notes here.
  • Tip: Add your own speaker notes here.
  • Tip: Add your own speaker notes here.
  • NS2: Binding C++ and OTcl variables

    1. 1. NS2: BindingVariablesNS2: BindingVariables by Teerawat Issariyakul http://www.ns2ultimate.com July 2010 http://www.ns2ultimate.com 1
    2. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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

    ×