Commit 6425980a authored by Robert Ricci's avatar Robert Ricci

Add support for link costs for routing algorithm. These are specified

in the NS file in one of two ways:

$ns cost $nodeA $nodeB 2
or
$link0 cost 3
(The latter form can also be used for LANs)

This information is stored in the database in the cost column of the
virt_lans table.  It's important to note that cost data is _not_
divided between the two sides of the link, as things like delay and
rdelay are. Since there are no physical devices (ie.  delay nodes)
node that this configuration needs to be split up between, doing so
would just be unnecessary work.
parent d820506a
...@@ -874,7 +874,8 @@ CREATE TABLE virt_lans ( ...@@ -874,7 +874,8 @@ CREATE TABLE virt_lans (
member text, member text,
rdelay float(10,2) default NULL, rdelay float(10,2) default NULL,
rbandwidth int(10) unsigned default NULL, rbandwidth int(10) unsigned default NULL,
rlossrate float(10,3) default NULL rlossrate float(10,3) default NULL,
cost float NOT NULL default '1'
) TYPE=MyISAM; ) TYPE=MyISAM;
# #
......
...@@ -134,6 +134,7 @@ LanLink instproc init {s nodes bw d type} { ...@@ -134,6 +134,7 @@ LanLink instproc init {s nodes bw d type} {
$self instvar rdelay $self instvar rdelay
$self instvar loss $self instvar loss
$self instvar rloss $self instvar rloss
$self instvar cost
foreach node $nodes { foreach node $nodes {
set nodepair [list $node [$node add_lanlink $self]] set nodepair [list $node [$node add_lanlink $self]]
...@@ -143,6 +144,7 @@ LanLink instproc init {s nodes bw d type} { ...@@ -143,6 +144,7 @@ LanLink instproc init {s nodes bw d type} {
set rdelay($nodepair) [expr $d / 2.0] set rdelay($nodepair) [expr $d / 2.0]
set loss($nodepair) 0 set loss($nodepair) 0
set rloss($nodepair) 0 set rloss($nodepair) 0
set cost($nodepair) 1
lappend nodelist $nodepair lappend nodelist $nodepair
} }
} }
...@@ -225,6 +227,19 @@ LanLink instproc get_subnet {} { ...@@ -225,6 +227,19 @@ LanLink instproc get_subnet {} {
return [$node ip $port] return [$node ip $port]
} }
#
# Set the routing cost for all interfaces on this LAN
#
LanLink instproc cost {c} {
$self instvar nodelist
$self instvar cost
foreach nodeport $nodelist {
set cost($nodeport) $c
}
}
Link instproc rename {old new} { Link instproc rename {old new} {
$self next $old $new $self next $old $new
...@@ -334,11 +349,12 @@ LanLink instproc updatedb {DB} { ...@@ -334,11 +349,12 @@ LanLink instproc updatedb {DB} {
$self instvar rdelay $self instvar rdelay
$self instvar loss $self instvar loss
$self instvar rloss $self instvar rloss
$self instvar cost
var_import ::GLOBALS::pid var_import ::GLOBALS::pid
var_import ::GLOBALS::eid var_import ::GLOBALS::eid
foreach nodeport $nodelist { foreach nodeport $nodelist {
set nodeportraw [join $nodeport ":"] set nodeportraw [join $nodeport ":"]
sql exec $DB "insert into virt_lans (pid,eid,vname,member,delay,rdelay,bandwidth,rbandwidth,lossrate,rlossrate) values (\"$pid\",\"$eid\",\"$self\",\"$nodeportraw\",$delay($nodeport),$rdelay($nodeport),$bandwidth($nodeport),$rbandwidth($nodeport),$loss($nodeport),$rloss($nodeport))" sql exec $DB "insert into virt_lans (pid,eid,vname,member,delay,rdelay,bandwidth,rbandwidth,lossrate,rlossrate,cost) values (\"$pid\",\"$eid\",\"$self\",\"$nodeportraw\",$delay($nodeport),$rdelay($nodeport),$bandwidth($nodeport),$rbandwidth($nodeport),$loss($nodeport),$rloss($nodeport),$cost($nodeport))"
} }
} }
...@@ -622,3 +622,10 @@ Simulator instproc add_program {prog} { ...@@ -622,3 +622,10 @@ Simulator instproc add_program {prog} {
$self instvar prog_list $self instvar prog_list
set prog_list($prog) {} set prog_list($prog) {}
} }
# cost
# Set the cost for a link
Simulator instproc cost {src dst c} {
set reallink [$self find_link $src $dst]
$reallink set cost([list $src [$reallink get_port $src]]) $c
}
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