C help for network animator

This is a discussion on C help for network animator within the Tech Board forums, part of the Community Boards category; Hey been trying to get a piece of code working for network animator Code: #Create a simulator object set ns ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    3

    Talking C help for network animator

    Hey been trying to get a piece of code working for network animator

    Code:
    #Create a simulator object
    set ns [new Simulator]
    
    $ns rtproto DV
    Node set multiPath_ 1
    
    
    #Open the nam trace file
    set nf [open out.nam w]
    $ns namtrace-all $nf
    
    #Define a 'finish' procedure
    proc finish {} {
            global ns nf
            $ns flush-trace
        #Close the trace file
            close $nf
        #Execute nam on the trace file
            exec nam out.nam &
            exit 0
    }
    
    #Create six nodes
    for {set i 0} {$i < 8} {in        exit 0
    }
    
    #Create six nodes
    for {set i 0} {$i < 8} {incr i} {
      set n($i) [$ns node]
    }
    
    #set up a link between then
    for {set i 0} {$i < 8} {incr i} {
      $ns duplex-link $n($i) $n([expr ($i+1)%8]) 1Mb 10ms DropTail
    }
    
    #Setting up a flow needs these four steps ---------------
    #1. Create a UDP agent and attach it to node n(i)
    for {set i 0} {$i < 4} {incr i} {
      set udp(i) [new Agent/UDP]
      $ns attach-agent $n(i) $udp(i)
    }
    
    #2. Create a CBR traffic source and attach it to udp(i)
    for {set i 0} {$i < 4} {incr i} {
      set cbr(i) [new Application/Traffic/CBR]
      $cbr(i) set packetSize_ 1000
      $cbr(i) set interval_ 0.05
      $cbr(i) attach-agent $udp(i)
    
    
    #3. Create a Null agent (a traffic sink) and attach it to node(i)
      for {set x i+4} {$x < 8} {incr x} {
          set null(i) [new Agent/Null]
          $ns attach-agent $n(i) $null(x)
    
          set null(i) [new Agent/Null]
          $ns attach-agent $n(x) $null(i)
    
    #4. Connect the traffic source with the traffic sink
          $ns connect $udp(i) $null(i)
      }
    }
    
    #-----------------------------------------------------------
    
    #Schedule events for the CBR agent
    $ns at 0.5  "$cbr0 start"
    $ns at 5.0 "$cbr0 stop"
    
    #Call the finish procedure after 1 second of simulation time
    $ns at 1.0 "finish"
    
    #Run the simulation
    $ns run
    cr i} {
      set n($i) [$ns node]
    }
    
    #set up a link between then
    for {set i 0} {$i < 8} {incr i} {
      $ns duplex-link $n($i) $n([expr ($i+1)%8]) 1Mb 10ms DropTail
    }
    
    #Setting up a flow needs these four steps ---------------
    #1. Create a UDP agent and attach it to node n(i)
    for {set i 0} {$i < 4} {incr i} {
      set udp(i) [new Agent/UDP]
      $ns attach-agent $n(i) $udp(i)
    }
    
    #2. Create a CBR traffic source and attach it to udp(i)
    for {set i 0} {$i < 4} {incr i} {
      set cbr(i) [new Application/Traffic/CBR]
      $cbr(i) set packetSize_ 1000
      $cbr(i) set interval_ 0.05
      $cbr(i) attach-agent $udp(i)
    
    
    #3. Create a Null agent (a traffic sink) and attach it to node(i)
      for {set x i+4} {$x < 8} {incr x} {
          set null(i) [new Agent/Null]
          $ns attach-agent $n(i) $null(x)
    
          set null(i) [new Agent/Null]
          $ns attach-agent $n(x) $null(i)
      
    #4. Connect the traffic source with the traffic sink
          $ns connect $udp(i) $null(i)  
      }
    }
    
    #-----------------------------------------------------------
    
    #Schedule events for the CBR agent
    $ns at 0.5  "$cbr0 start"
    $ns at 5.0 "$cbr0 stop"
    
    #Call the finish procedure after 1 second of simulation time
    $ns at 1.0 "finish"
    
    #Run the simulation
    $ns run
    ------------------------------------------------------

    error

    can't read "n(i)": no such element in array
    while executing
    "$ns attach-agent $n(i) $udp(i)"
    ("for" body line 3)
    invoked from within
    "for {set i 0} {$i < 4} {incr i} {
    set udp(i) [new Agent/UDP]
    $ns attach-agent $n(i) $udp(i)
    }"
    (file "part2q7" line 35)


    dont quite understand what is going on, any help is greatly appreciated!!!!

    Cheers

  2. #2
    Registered User
    Join Date
    Mar 2006
    Posts
    3

    my mistake in code

    sorry posted the code twice!

    Code:
    #Create a simulator object
    set ns [new Simulator]
    
    $ns rtproto DV
    Node set multiPath_ 1
    
    
    #Open the nam trace file
    set nf [open out.nam w]
    $ns namtrace-all $nf
    
    #Define a 'finish' procedure
    proc finish {} {
            global ns nf
            $ns flush-trace
        #Close the trace file
            close $nf
        #Execute nam on the trace file
            exec nam out.nam &
            exit 0
    }
    
    #Create six nodes
    for {set i 0} {$i < 8} {in        exit 0
    }
    
    #Create six nodes
    for {set i 0} {$i < 8} {incr i} {
      set n($i) [$ns node]
    }
    
    #set up a link between then
    for {set i 0} {$i < 8} {incr i} {
      $ns duplex-link $n($i) $n([expr ($i+1)%8]) 1Mb 10ms DropTail
    }
    
    #Setting up a flow needs these four steps ---------------
    #1. Create a UDP agent and attach it to node n(i)
    for {set i 0} {$i < 4} {incr i} {
      set udp(i) [new Agent/UDP]
      $ns attach-agent $n(i) $udp(i)
    }
    
    #2. Create a CBR traffic source and attach it to udp(i)
    for {set i 0} {$i < 4} {incr i} {
      set cbr(i) [new Application/Traffic/CBR]
      $cbr(i) set packetSize_ 1000
      $cbr(i) set interval_ 0.05
      $cbr(i) attach-agent $udp(i)
    
    
    #3. Create a Null agent (a traffic sink) and attach it to node(i)
      for {set x i+4} {$x < 8} {incr x} {
          set null(i) [new Agent/Null]
          $ns attach-agent $n(i) $null(x)
    
          set null(i) [new Agent/Null]
          $ns attach-agent $n(x) $null(i)
    
    #4. Connect the traffic source with the traffic sink
          $ns connect $udp(i) $null(i)
      }
    }
    
    #-----------------------------------------------------------
    
    #Schedule events for the CBR agent
    $ns at 0.5  "$cbr0 start"
    $ns at 5.0 "$cbr0 stop"
    
    #Call the finish procedure after 1 second of simulation time
    $ns at 1.0 "finish"
    
    #Run the simulation
    $ns run
    error

    this is the error it outputs

    can't read "n(i)": no such element in array
    while executing
    "$ns attach-agent $n(i) $udp(i)"
    ("for" body line 3)
    invoked from within
    "for {set i 0} {$i < 4} {incr i} {
    set udp(i) [new Agent/UDP]
    $ns attach-agent $n(i) $udp(i)
    }"
    (file "part2q7" line 35)
    cslin050% ns part2q7
    can't read "n(i)": no such element in array
    while executing
    "$ns attach-agent $n(i) $udp(i)"
    ("for" body line 3)
    invoked from within
    "for {set i 0} {$i < 4} {incr i} {
    set udp(i) [new Agent/UDP]
    $ns attach-agent $n(i) $udp(i)
    }"
    (file "part2q7" line 35)
    cslin050% ns part2q7
    wrong # args: should be "for start test next command"
    while executing
    "for {set i 0} {$i < 8} {in exit 0
    }"
    (file "part2q7" line 24)

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Could the problem be a missing $?
    Code:
      $ns attach-agent $n($i) $udp(i)

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    Your code is nothing like C
    Moved to tech
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Eww is that Perl? I lost interest in it about 10 minutes after starting to learn it. Well started reading about it first and the "write only" comment - as in programs are horrible to read and debug after they've been written, I guess it was right.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  6. #6
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    I enjoy Perl, it makes my job a TON easier. I have Perl scripts like 5k+ lines long. I can change some stuff and make it work for a lot of things. And I don't need to worry about time it takes to compile. And it is easier to make a GUI in. Text manipulation is very easy with it. Granted it doesn't run as fast as a compiled language. It is good for RAD and Parsing, both things I do a lot.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    Looks more like Tcl to me.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,069
    Hehe... how the hell did you write that without knowing what language you were using?
    Sent from my iPadŽ

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with network animator code
    By fastshadow in forum C Programming
    Replies: 1
    Last Post: 03-17-2006, 09:37 AM
  2. Writing a .gif animator software
    By rEtard in forum Windows Programming
    Replies: 5
    Last Post: 09-21-2005, 12:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21