Commit f4cf886d authored by Shashi Guruprasad's avatar Shashi Guruprasad

NSE based traffic generation went into bitrot. This fixes it. Nothing

major but it now works.
parent 361ee691
......@@ -182,6 +182,28 @@ proc readroutes {} {
}
}
proc readtrafgens {} {
global CLIENTVARDIR
global tbtrafgens
set tmcctrafgens [open $CLIENTVARDIR/boot/tmcc.trafgens r]
set tmcctraf [read $tmcctrafgens]
close $tmcctrafgens
set trafgenlist [split $tmcctraf "\n"]
set formatstr {TRAFGEN=%s MYNAME=%s MYPORT=%u PEERNAME=%s PEERPORT=%u PROTO=%s ROLE=%s GENERATOR=%s}
foreach trafgen $trafgenlist {
if { $trafgen == {} } {
continue
}
scan $trafgen $formatstr traf myname myport peername peerport proto role gen
if { $gen != "NSE" || $proto != "tcp" } {
continue
}
set tbtrafgens($traf) "$myname:$myport:$peername:$peerport"
}
}
# call it after evaluating nseconfigs
# This will parse tmcc routelist and
# store a list of routes for all source nodes that are
......@@ -213,6 +235,9 @@ readifconfig
# Routes
readroutes
# Traffic Generators used only if NSE based traffic generators are present
readtrafgens
# the name of the simulator instance variable might not
# always be 'ns', coming from the TB parser
set ns [Simulator instance]
......@@ -222,16 +247,10 @@ set ipnetcommon [new Network/IP]
$ipnetcommon open writeonly
# configuring NSE FullTcp traffic generators
set objnamelist ""
if { $nsetrafgen_present == 1 } {
# The following nodes are present
set n0_FullTcp [$ns node]
set n1_FullTcp [$ns node]
# required hack for now or FullTcp timer cancels cause aborts
# otherwise, we just need 1 node
$ns duplex-link $n0_FullTcp $n1_FullTcp 100Mb 0ms DropTail
# set sysctl tcp blackhole to 2
exec sysctl -w net.inet.tcp.blackhole=2
......@@ -241,7 +260,12 @@ if { $nsetrafgen_present == 1 } {
lappend tcpclasses $tcpsubclass
}
# for each entry in `tmcc trafgens` that has NSE as the generator
# configure that object to connect to a newly created
# TCPTap along with the required Live and RAW IP objects. Set the filter and interface
# after learning it from tmcc commands and other scripts in /var/emulab
set i 0
foreach tcpclass $tcpclasses {
set tcpobjs [$tcpclass info instances]
......@@ -253,95 +277,50 @@ if { $nsetrafgen_present == 1 } {
# of the FullTcp objects could be created as
# as a result of a combined simulation and
# emulation scenario
if { [$tcpobj set objname] != {} } {
set tcptbname [$tcpobj set tbname]
if { $tcptbname != {} } {
$ns attach-agent $n0_FullTcp $tcpobj
#lappend objnamelist [$tcpobj set objname]
}
}
}
foreach ftpobj [Application/FTP info instances] {
# objname is a instance variable that was put
# by TB parser on objects instantiated by it.
# we are concerned only with those. the rest
# of the FullTcp objects could be created as
# as a result of a combined simulation and
# emulation scenario
if { [$ftpobj set objname] != {} } {
#lappend objnamelist [$ftpobj set objname]
}
}
foreach telnetobj [Application/Telnet info instances] {
# objname is a instance variable that was put
# by TB parser on objects instantiated by it.
# we are concerned only with those. the rest
# of the FullTcp objects could be created as
# as a result of a combined simulation and
# emulation scenario
if { [$telnetobj set objname] != {} } {
#lappend objnamelist [$telnetobj set objname]
}
}
# for each entry in `tmcc trafgens` that has NSE as the generator
# configure that object to connect to a newly created
# TCPTap along with the required Live and RAW IP objects. Set the filter and interface
# after learning it from tmcc commands and other scripts in /var/emulab
set tmcctrafgens [open $CLIENTVARDIR/boot/tmcc.trafgens r]
set tmcctraf [read $tmcctrafgens]
close $tmcctrafgens
set trafgenlist [split $tmcctraf "\n"]
set formatstr {TRAFGEN=%s MYNAME=%s MYPORT=%u PEERNAME=%s PEERPORT=%u PROTO=%s ROLE=%s GENERATOR=%s}
variable i 0
foreach trafgen $trafgenlist {
scan $trafgen $formatstr trafgen myname myport peername peerport proto role gen
if { $gen != "NSE" || $proto != "tcp" } {
continue
}
# if the variable in $trafgen exists, we create a bunch of taps
# first do the tap part
if { [info exists $trafgen] == 1 } {
# convert myname and peername to corresponding ipaddresses
# using the getipaddr helper subroutine
set myipaddr [getipaddr $myname]
set peeripaddr [getipaddr $peername]
# find interface name with a helper subroutine
set interface [getif $myipaddr]
# one TCPTap object per TCP class that we have instantiated
set tcptap($i) [new Agent/TCPTap]
$tcptap($i) nsipaddr $myipaddr
$tcptap($i) nsport $myport
$tcptap($i) extipaddr $peeripaddr
$tcptap($i) extport $peerport
set trafrecord [split $tbtrafgens($tcptbname) ":"]
set myname [lindex $trafrecord 0]
set myport [lindex $trafrecord 1]
set peername [lindex $trafrecord 2]
set peerport [lindex $trafrecord 3]
# convert myname and peername to corresponding ipaddresses
# using the getipaddr helper subroutine
set myipaddr [getipaddr $myname]
set peeripaddr [getipaddr $peername]
# open the bpf, set the filter for capturing incoming packets towards
# the current tcp object
set bpf_tcp($i) [new Network/Pcap/Live]
set dev_tcp($i) [$bpf_tcp($i) open readonly $interface]
$bpf_tcp($i) filter "tcp and dst $myipaddr and dst port $myport and src $peeripaddr and src port $peerport"
# find interface name with a helper subroutine
set interface [getif $myipaddr]
# one TCPTap object per TCP class that we have instantiated
set tcptap($i) [new Agent/TCPTap]
$tcptap($i) nsipaddr $myipaddr
$tcptap($i) nsport $myport
$tcptap($i) extipaddr $peeripaddr
$tcptap($i) extport $peerport
# associate the 2 network objects in the TCPTap object
$tcptap($i) network-incoming $bpf_tcp($i)
$tcptap($i) network-outgoing $ipnetcommon
# open the bpf, set the filter for capturing incoming packets towards
# the current tcp object
set bpf_tcp($i) [new Network/Pcap/Live]
set dev_tcp($i) [$bpf_tcp($i) open readonly $interface]
$bpf_tcp($i) filter "tcp and dst $myipaddr and dst port $myport and src $peeripaddr and src port $peerport"
# attach the TCPTap agent to node n1_FullTcp
$ns attach-agent $n1_FullTcp $tcptap($i)
# associate the 2 network objects in the TCPTap object
$tcptap($i) network-incoming $bpf_tcp($i)
$tcptap($i) network-outgoing $ipnetcommon
# connect this tap and the particular tcp agent
set tcpagent($i) [expr \$$trafgen]
$ns connect $tcpagent($i) $tcptap($i)
# attach the TCPTap agent to node n1_FullTcp
$ns attach-agent $n0_FullTcp $tcptap($i)
incr i
# connect this tap and the particular tcp agent
$ns connect $tcpobj $tcptap($i)
incr i
}
}
}
}
......@@ -468,9 +447,6 @@ set nseswap_cmdline "$CLIENTBINDIR/tevc -s $boss -e $pid/$eid now $simobjname NS
set evsink [new TbEventSink]
$evsink event-server "elvin://$boss"
$evsink nseswap_cmdline $nseswap_cmdline
#if { $objnamelist != {} } {
# $evsink objnamelist [join $objnamelist ","]
#}
$evsink logfile $logpath
[$ns set scheduler_] tbevent-sink $evsink
......
......@@ -77,14 +77,11 @@ Node instproc init {s} {
$self set failureaction "fatal"
$self set fixed ""
$self set nseconfig ""
$self set realtime 0
var_import ::GLOBALS::simulated
if { $simulated == 1 } {
if { ${::GLOBALS::simulated} == 1 } {
$self set simulated 1
} else {
$self set simulated 0
$self set realtime 0
}
$self set nsenode_vportlist {}
}
......@@ -128,11 +125,12 @@ Node instproc updatedb {DB} {
$self instvar agentlist
$self instvar routelist
$self instvar sim
$self instvar realtime
$self instvar isvirt
$self instvar virthost
$self instvar issubnode
$self instvar desirelist
$self instvar nseconfig
$self instvar simulated
var_import ::TBCOMPAT::default_osids
var_import ::GLOBALS::pid
var_import ::GLOBALS::eid
......@@ -184,6 +182,26 @@ Node instproc updatedb {DB} {
foreach agent $agentlist {
$agent updatedb $DB
# The following is for NSE traffic generation
# Simulated nodes in make-simulated should not be doing this
if { $simulated != 1 } {
append nseconfig [$agent get_nseconfig]
}
}
if {$nseconfig != {}} {
set nsecfg_script ""
set simu [lindex [Simulator info instances] 0]
append nsecfg_script "set $simu \[new Simulator]\n"
append nsecfg_script "\$$simu set tbname \{$simu\}\n"
append nsecfg_script "\$$simu use-scheduler RealTime\n\n"
append nseconfig "set nsetrafgen_present 1\n\n"
append nsecfg_script $nseconfig
# update the per-node nseconfigs table in the DB
$sim spitxml_data "nseconfigs" [list "vname" "nseconfig"] [list "$self" "$nsecfg_script"]
}
$self add_routes_to_DB $DB
......
......@@ -49,6 +49,18 @@ namespace eval GLOBALS {
set new_classes(Application/Traffic/CBR) {}
set new_classes(Application/FTP) {}
set new_classes(Application/Telnet) {}
# When generating NSE Traffic Generator code, need to ignore
# testbed specific variables
set ignore_nsetrafgen_classvars(destination) {}
set ignore_nsetrafgen_classvars(application) {}
set ignore_nsetrafgen_classvars(role) {}
set ignore_nsetrafgen_classvars(proto) {}
set ignore_nsetrafgen_classvars(port) {}
set ignore_nsetrafgen_classvars(node) {}
set ignore_nsetrafgen_classvars(simulated) {}
set ignore_nsetrafgen_classvars(generator) {}
set ignore_nsetrafgen_classvars(osid) {}
}
# Agent
......@@ -65,8 +77,7 @@ Agent instproc init {} {
$self set generator "TG"
global ::GLOBALS::last_class
set ::GLOBALS::last_class $self
var_import ::GLOBALS::simulated
if { $simulated == 1 } {
if { ${::GLOBALS::simulated} == 1 } {
$self set simulated 1
} else {
$self set simulated 0
......@@ -229,7 +240,7 @@ Agent/TCP/FullTcp instproc updatedb {DB} {
$self instvar generator
$self instvar port
$self instvar link
$self instvar simulated
var_import ::GLOBALS::simulated
if {$node == {}} {
perror "\[updatedb] $self is not attached to a node."
......@@ -276,7 +287,7 @@ Agent/TCP/FullTcp instproc get_nseconfig {} {
$self instvar role
$self instvar simulated
$self instvar application
$self set objname $self
var_import ::GLOBALS::ignore_nsetrafgen_classvars
set nseconfig ""
......@@ -289,23 +300,26 @@ Agent/TCP/FullTcp instproc get_nseconfig {} {
# we set a global variable to indicate that NSE trafgen
# is present so that nseinput.tcl can take appropriate
# action
append nseconfig "set nsetrafgen_present 1\n\n"
if { ($tcptype == "") || ($tcptype == "Reno") } {
append nseconfig "set $self \[new Agent/TCP/FullTcp]\n"
} else {
append nseconfig "set $self \[new Agent/TCP/FullTcp/$tcptype]\n"
}
append nseconfig "\$\{$self\} set tbname \{$self\}\n"
if { $role == "sink" } {
append nseconfig "\$$self listen\n\n"
append nseconfig "\$\{$self\} listen\n\n"
}
# We end up including variables present only in TB parser. However
# that does not matter coz all NS variables end with _ character
# Pruning can be done later
foreach var [$self info vars] {
if { [info exists ignore_nsetrafgen_classvars($var)] } {
continue
}
if { [$self set $var] != {} } {
append nseconfig "\$$self set $var [$self set $var]\n"
append nseconfig "\$\{$self\} set $var [$self set $var]\n"
}
}
append nseconfig "\n"
......@@ -329,9 +343,7 @@ Agent/TCP/FullTcp instproc connect {dst} {
$self set proto "tcp"
$dst set proto "tcp"
$node set osid "FBSD-STD"
$node set realtime 1
$dst set osid "FBSD-STD"
$dst set realtime 1
}
# Agent/Null
......@@ -432,10 +444,10 @@ Application/FTP instproc get_nseconfig {} {
$self instvar agent
set nseconfig "set $self \[new Application/FTP]\n"
append nseconfig "\$$self set objname $self\n"
append nseconfig "\$\{$self\} set tbname \{$self\}\n"
if { $agent != {} } {
append nseconfig "\$$self attach-agent \$$agent\n"
append nseconfig "\$\{$self\} attach-agent \$$agent\n"
}
append nseconfig "\n"
......@@ -468,11 +480,11 @@ Application/Telnet instproc get_nseconfig {} {
set nseconfig "set $self \[new Application/Telnet]\n"
append nseconfig "\$$self set objname $self\n"
append nseconfig "\$\{$self\} set tbname \{$self\}\n"
append nseconfig "\$$self set interval_ $interval_\n"
append nseconfig "\$\{$self\} set interval_ $interval_\n"
if { $agent != {} } {
append nseconfig "\$$self attach-agent \$$agent\n"
append nseconfig "\$\{$self\} attach-agent \$$agent\n"
}
append nseconfig "\n"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment