Hi Pedro,

Did you bind the C++ class to the OTcl class? Please read the following
blog post to see how to bind C++ classes:

http://www.ns2ultimate.com/post/689847378/c-and-otcl-linkage-binding-c-and-otcl-classes

and

http://www.ns2ultimate.com/post/720424694/c-and-otcl-linkage-binding-c-and-otcl-classes

Best Wishes,

Teerawat Issariyakul
http://www.ns2ultimate.com/
http://www.ece.ubc.ca/~teerawat
http://www.t-issariyakul.blogspot.com
http://www.facebook.com/pages/Teerawat-Issariyakul/358240861417
http://twitter.com/T_Bear




On 8/24/2010, "pedro chaparro" <pdr...@gmail.com> wrote:

>*hi guys, i'm implementing a new block to insert into the SimpleLink
>strucutre , * between queue_ and link_. blocks, i create a new class call
>SKlink from class connector, it is simple i just wanna use the recv function
>to for now just print a message each time a packet is transmitted over the
>link. i achieve to compile everythink ok , but when i run my tcl script (at
>the end of this page) , i got and error i show below. i following the 14.1
>section  of  Teerawat Issariyakul book, i suppose i'm missing something,
>i'll appreciate a lot any help.
>thabks
>*
>skmod.cc*
>
>#include "skmod.h"
>void SKHandler::handle(Event*){}
>SKlink::SKlink() : skh_(*this)
>{
>pkt_=0;
>qh_=0;
>
>
>};
>
>void SKlink::recv(Packet* p, Handler* h)
>{
>
>printf("inside recv SK function \n");
>send(p,&skh_);
>
>}
>
>*skmod.h*
>#include "connector.h"
>#include "random.h"
>#include "timer-handler.h"
>#include "ranvar.h"
>
>class SKlink;
>
>class SKHandler : public Handler {
>public:
>        SKHandler(SKlink& sk) : sk_link_(sk) {}
>       void handle(Event*);
>private:
>        SKlink& sk_link_;
>};
>
>class SKlink : public Connector {
>  public:
>    SKlink();
>     //int command(int argc, const char*const* argv);
>     void recv(Packet* p, Handler* h);
>
>
>  protected:
>    SKHandler skh_;
>    Packet* pkt_;
>    Handler* qh_;
>};
>*
>ns-link.tcl*
>SimpleLink instproc link-skt {} {
>$self instvar link_ queue_ drophead_
>$self instvar SKlk_
>set SKlk_ [new SKlink]
>queue_ target $SKlk_
>$SKlk_ target $link_
>$SKlk_ drop-target $drophead_
>}
>
>*ns-lib.tcl*
>Simulator instproc link-skt {from to} {
>set link [$self link $from $to]
>$link link-skt
>}
>-- 
>
>*Error i get*
>
>r...@hobbes:/home/pdro7/Desktop/nsCOSIM/ns-2.34# ./ns testTCP.tcl
>invalid command name "SKlink"
>    while executing
>"SKlink create _o38 "
>    invoked from within
>"catch "$className create $o $args" msg"
>    invoked from within
>"if [catch "$className create $o $args" msg] {
>if [string match "__FAILED_SHADOW_OBJECT_" $msg] {
>delete $o
>return ""
>}
>global errorInfo
>error "class $..."
>    (procedure "new" line 3)
>    invoked from within
>"new SKlink"
>    (procedure "_o29" line 4)
>    (SimpleLink link-skt line 4)
>    invoked from within
>"$link link-skt"
>    (procedure "_o3" line 3)
>    (Simulator link-skt line 3)
>    invoked from within
>"$ns link-skt $n0 $n1"
>    (file "testTCP.tcl" line 41)
>
>
>Scrip Tlc
>
># This script is created by NSG2 beta1
># <http://wushoupong.googlepages.com/nsg>
>
>#===================================
>#     Simulation parameters setup
>#===================================
>set val(stop)   13.0                         ;# time of simulation end
>
>#===================================
>#        Initialization
>#===================================
>#Create a ns simulator
>set ns [new Simulator]
>
>#Open the NS trace file
>set tracefile [open out.tr w]
>$ns trace-all $tracefile
>
>#Open the NAM trace file
>set namfile [open out.nam w]
>$ns namtrace-all $namfile
>
>#===================================
>#        Nodes Definition
>#===================================
>#Create 2 nodes
>set n0 [$ns node]
>set n1 [$ns node]
>
>set n2 [$ns node]
>set n3 [$ns node]
>set n4 [$ns node]
>set n5 [$ns node]
>
>#===================================
>#        Links Definition
>#===================================
>#Createlinks between nodes
>$ns simplex-link $n0 $n1 1000.0Mb 0.00001ms DropTail
>$ns queue-limit $n0 $n1 50
>*$ns link-skt $n0 $n1*
>$ns simplex-link $n2 $n0 1000.0Mb 0.00001ms DropTail
>$ns queue-limit $n2 $n0 50
>
>$ns simplex-link $n1 $n3 1000.0Mb 0.00001ms DropTail
>$ns queue-limit $n1 $n3 50
>
>
>$ns simplex-link $n4 $n0 1000.0Mb 0.00001ms DropTail
>$ns queue-limit $n4 $n0 50
>
>$ns simplex-link $n1 $n5 1000.0Mb 0.00001ms DropTail
>$ns queue-limit $n1 $n5 50
>#Give node position (for NAM)
>#$ns duplex-link-op $n0 $n1 orient right
>
>#===================================
>#        Agents Definition
>#===================================
>#Setup a TCP connection
>set tcp0 [new Agent/UDP]
>$ns attach-agent $n2 $tcp0
>set sink1 [new Agent/Null]
>$ns attach-agent $n3 $sink1
>$ns connect $tcp0 $sink1
>$tcp0 set packetSize_ 1500
>
>
>set tcp1 [new Agent/UDP]
>$ns attach-agent $n4 $tcp1
>set sink2 [new Agent/Null]
>$ns attach-agent $n5 $sink2
>$ns connect $tcp1 $sink2
>$tcp1 set packetSize_ 1500
>
>#===================================
>#        Applications Definition
>#===================================
>#Setup a CBR Application over TCP connection
>set cbr0 [new Application/Traffic/CBR]
>$cbr0 attach-agent $tcp0
>$cbr0 set packetSize_ 1000
>$cbr0 set rate_ 1.0Mb
>$cbr0 set random_ null
>$ns at 1.0 "$cbr0 start"
>$ns at 11.5 "$cbr0 stop"
>
>set cbr1 [new Application/Traffic/CBR]
>$cbr1 attach-agent $tcp0
>$cbr1 set packetSize_ 1000
>$cbr1 set rate_ 1.0Mb
>$cbr1 set random_ null
>$ns at 1.2 "$cbr1 start"
>$ns at 11.8 "$cbr1 stop"
>
>
>
>#===================================
>#        Termination
>#===================================
>#Define a 'finish' procedure
>proc finish {} {
>    global ns tracefile namfile
>    $ns flush-trace
>    close $tracefile
>    close $namfile
>    #exec nam out.nam &
>    exit 0
>}
>#$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
>$ns at $val(stop) "finish"
>$ns at $val(stop) "puts \"done\" ; $ns halt"
>$ns run
>
>
>Pedro Alonso Chaparro Valero R&D Engineer
>Ciudad Politecnica de la Innovación
>iTEAM - Mobile Communications Group
>Polytechnic University of Valencia
>C\ Camino de Vera S/N, Edificio 8G
>46022 Valencia, Spain

Reply via email to