Commit 46cc97e0 authored by Leigh B. Stoller's avatar Leigh B. Stoller

A set of changes for allocating globally unique subnets to lans that

have a remote node as a member. Since we share remotes nodes and set
up tunnels, we cannot let two experiments have the same subnet
numbers. I use 10.0.0 nets and a DB table to allocate them with a
autoincrement field.
parent f333fa2f
......@@ -171,6 +171,7 @@ LanLink instproc get_port {node} {
LanLink instproc fill_ips {} {
$self instvar nodelist
$self instvar sim
set isremote 0
# Determined a subnet (if possible) and any used IP addresses in it.
# ips is a set which contains all used IP addresses in this LanLink.
......@@ -179,7 +180,11 @@ LanLink instproc fill_ips {} {
set node [lindex $nodeport 0]
set port [lindex $nodeport 1]
set ip [$node ip $port]
set isremote [expr $isremote + [$node set isremote]]
if {$ip != {}} {
if {$isremote} {
perror "Not allowed to specify IP subnet of a remote lan!"
}
set subnet [join [lrange [split $ip .] 0 2] .]
set ips($ip) 1
}
......@@ -187,7 +192,11 @@ LanLink instproc fill_ips {} {
# If we couldn't find a subnet we ask the Simulator for one.
if {$subnet == {}} {
set subnet [$sim get_subnet]
if {$isremote} {
set subnet [$sim get_subnet_remote]
} else {
set subnet [$sim get_subnet]
}
}
# Now we assign IP addresses to any node:port's without them.
......
......@@ -39,6 +39,9 @@ Node instproc init {s} {
# The type of the node.
$self set type "pc"
# Is remote flag. Used when we do IP assignment later.
$self set isremote 0
# If osid remains blank when updatedb is called it is changed
# to the default OS based on it's type (taken from node_types
# table).
......@@ -239,6 +242,17 @@ Node instproc add-route {dst nexthop} {
set routelist($dst) $nexthop
}
#
# Set the type/isremote for a node. Called from tb_compat.
#
Node instproc set_hwtype {hwtype isrem} {
$self instvar type
$self instvar isremote
set type $hwtype
set isremote $isrem
}
#
# Update DB with routes
#
......
......@@ -769,6 +769,25 @@ Simulator instproc get_subnet {} {
perror "Ran out of subnets."
}
# get_subnet_remote
# This is called by lanlinks. When called get_subnet will find an available
# IP subnet, mark it as used, and return it to the caller.
Simulator instproc get_subnet_remote {} {
var_import ::GLOBALS::DB
var_import ::GLOBALS::pid
var_import ::GLOBALS::eid
sql exec $DB "insert into ipsubnets values ('$pid','$eid', NULL)"
sql endquery $DB
sql query $DB "select LAST_INSERT_ID() from ipsubnets"
set row [sql fetchrow $DB]
sql endquery $DB
set b [expr [expr $row & 0xff00] >> 8]
set c [expr $row & 0xff]
return 10.$b.$c
}
# use_subnet
# This is called by the ip method of nodes. It marks the passed subnet
# as used and thus should never be returned by get_subnet.
......
......@@ -43,14 +43,23 @@ namespace eval TBCOMPAT {
# Let's set up a hwtypes table that contains all valid hardware types.
variable hwtypes
sql query $DB "select type from node_types"
variable isremote
sql query $DB "select type,isremotenode from node_types"
while {[set row [sql fetchrow $DB]] != ""} {
set hwtypes($row) 1
set type [lindex $row 0]
set isrem [lindex $row 1]
set hwtypes($type) 1
set isremote($type) $isrem
}
sql endquery $DB
sql query $DB "select class from node_types"
sql query $DB "select class,isremotenode from node_types"
while {[set row [sql fetchrow $DB]] != ""} {
set hwtypes($row) 1
set type [lindex $row 0]
set isrem [lindex $row 1]
set hwtypes($type) 1
set isremote($type) $isrem
}
sql endquery $DB
......@@ -130,6 +139,7 @@ proc tb-set-ip-link {src link ip} {
# Node state routines.
proc tb-set-hardware {node type args} {
var_import ::TBCOMPAT::hwtypes
var_import ::TBCOMPAT::isremote
var_import ::GLOBALS::vtypes
if {(! [info exists hwtypes($type)]) &&
(! [info exists vtypes($type)])} {
......@@ -154,7 +164,11 @@ proc tb-set-hardware {node type args} {
return
}
}
$node set type $type
set remote 0
if {[info exists isremote($type)]} {
set remote $isremote($type)
}
$node set_hwtype $type $remote
}
proc tb-set-node-os {node os} {
......@@ -361,6 +375,9 @@ proc tb-make-soft-vtype {name types} {
if {! [info exists hwtypes($type)]} {
perror "\[tb-make-soft-vtype] Invalid hardware type $type."
}
if {$isremote($type)} {
perror "\[tb-make-soft-vtype] Remote type $type not allowed."
}
}
set vtypes($name) [Vtype $name $default_soft_vtype_weight $types]
}
......@@ -374,6 +391,9 @@ proc tb-make-hard-vtype {name types} {
if {! [info exists hwtypes($type)]} {
perror "\[tb-make-hard-vtype] Invalid hardware type $type."
}
if {$isremote($type)} {
perror "\[tb-make-hard-vtype] Remote type $type not allowed."
}
}
set vtypes($name) [Vtype $name $default_hard_vtype_weight $types]
}
......@@ -385,7 +405,10 @@ proc tb-make-weighted-vtype {name weight types} {
foreach type $types {
if {! [info exists hwtypes($type)]} {
perror "\[tb-make-hard-vtype] Invalid hardware type $type."
perror "\[tb-make-weighted-vtype] Invalid hardware type $type."
}
if {$isremote($type)} {
perror "\[tb-make-weighted-vtype] Remote type $type not allowed."
}
}
if {([regexp $FLOAT $weight] == 0) ||
......
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