Commit 1efef41b authored by Leigh Stoller's avatar Leigh Stoller

Another set of changes for removing card,port from interfaces and

interface_state tables.
parent 0d4f2d5e
...@@ -251,6 +251,9 @@ sub port($) ...@@ -251,6 +251,9 @@ sub port($)
} }
return $self->{'PORT'}; return $self->{'PORT'};
} }
# These are for the updatewires script.
sub card_saved($) { return field($_[0], 'card_saved'); }
sub port_saved($) { return field($_[0], 'port_saved'); }
# Wires table # Wires table
sub wire($) { return $_[0]->{'WIRE'}; } sub wire($) { return $_[0]->{'WIRE'}; }
sub wiredup($) { return (defined($_[0]->{'WIRE'}) ? 1 : 0); } sub wiredup($) { return (defined($_[0]->{'WIRE'}) ? 1 : 0); }
...@@ -425,14 +428,16 @@ sub Create($$$) ...@@ -425,14 +428,16 @@ sub Create($$$)
"longer supported!\n"; "longer supported!\n";
return undef; return undef;
} }
if (exists($argref->{'card'})) {
print STDERR "*** Interface->Create(): ignoring card/port, these ".
"are now set with the wire.\n";
}
my $node_id = $node->node_id(); my $node_id = $node->node_id();
my $MAC = $argref->{'MAC'} || $argref->{'mac'}; my $MAC = $argref->{'MAC'} || $argref->{'mac'};
my $IP = $argref->{'IP'}; my $IP = $argref->{'IP'};
my $mask = $argref->{'mask'}; my $mask = $argref->{'mask'};
my $card = $argref->{'card'};
my $port = $argref->{'port'};
my $iftype = $argref->{'type'} || $argref->{'interface_type'}; my $iftype = $argref->{'type'} || $argref->{'interface_type'};
my $ifrole = $argref->{'role'}; my $ifrole = $argref->{'role'};
my $uuid = $argref->{'uuid'}; my $uuid = $argref->{'uuid'};
...@@ -443,10 +448,6 @@ sub Create($$$) ...@@ -443,10 +448,6 @@ sub Create($$$)
my $trunk = $argref->{'trunk'}; my $trunk = $argref->{'trunk'};
my $auto = $argref->{'autocreated'}; my $auto = $argref->{'autocreated'};
$iface = "eth$card"
if (!defined($iface));
$port = 1
if (!defined($port));
$IP = "" $IP = ""
if (!defined($IP)); if (!defined($IP));
$mask = "" $mask = ""
...@@ -468,8 +469,7 @@ sub Create($$$) ...@@ -468,8 +469,7 @@ sub Create($$$)
return undef; return undef;
} }
} }
if (! (defined($card) && defined($ifrole) && defined($MAC) && if (! (defined($ifrole) && defined($MAC) && defined($IP) &&
defined($IP) && defined($port) &&
defined($iftype) && defined($iface) && defined($max_speed) && defined($iftype) && defined($iface) && defined($max_speed) &&
defined($duplex) && defined($uuid))) { defined($duplex) && defined($uuid))) {
print STDERR "Interface::Create: Missing fields in arguments:\n"; print STDERR "Interface::Create: Missing fields in arguments:\n";
...@@ -477,6 +477,13 @@ sub Create($$$) ...@@ -477,6 +477,13 @@ sub Create($$$)
return undef; return undef;
} }
# Lets make keep the special characters to a reasonable set.
# Mike says no commas please.
if ($iface !~ /^[-\w\/\.:]+$/) {
print STDERR "Interface::Create: illegal characters in iface:\n";
return undef;
}
# #
# Lock the tables to prevent concurrent creation # Lock the tables to prevent concurrent creation
# #
...@@ -493,11 +500,10 @@ sub Create($$$) ...@@ -493,11 +500,10 @@ sub Create($$$)
# #
my $query_result = my $query_result =
DBQueryWarn("select node_id from interfaces ". DBQueryWarn("select node_id from interfaces ".
"where node_id='$node_id' and ". "where node_id='$node_id' and iface='$iface'");
" card='$card' and port='$port'");
if ($query_result->numrows) { if ($query_result->numrows) {
DBQueryWarn("unlock tables"); DBQueryWarn("unlock tables");
return Interface->Lookup($node_id, $card, $port); return Interface->Lookup($node_id, $iface);
} }
# #
...@@ -528,7 +534,7 @@ sub Create($$$) ...@@ -528,7 +534,7 @@ sub Create($$$)
if (!DBQueryWarn("insert into interfaces set ". if (!DBQueryWarn("insert into interfaces set ".
" node_id='$node_id', logical='$logical', " . " node_id='$node_id', logical='$logical', " .
" card=$card, port=$port, role='$ifrole', ". " role='$ifrole', ".
" mac='$MAC', IP='$IP', autocreated='$auto', " . " mac='$MAC', IP='$IP', autocreated='$auto', " .
(defined($mask) ? "mask='$mask', " : "") . (defined($mask) ? "mask='$mask', " : "") .
($trunk ? "trunk='1', " : "") . ($trunk ? "trunk='1', " : "") .
...@@ -542,7 +548,7 @@ sub Create($$$) ...@@ -542,7 +548,7 @@ sub Create($$$)
if (!DBQueryWarn("insert into interface_state set ". if (!DBQueryWarn("insert into interface_state set ".
" node_id='$node_id', " . " node_id='$node_id', " .
($trunk ? "remaining_bandwidth='$max_speed', " : "") . ($trunk ? "remaining_bandwidth='$max_speed', " : "") .
" card=$card, port=$port, iface='$iface'")) { " iface='$iface'")) {
DBQueryWarn("delete from interfaces ". DBQueryWarn("delete from interfaces ".
"where node_id='$node_id' and iface='$iface' "); "where node_id='$node_id' and iface='$iface' ");
DBQueryWarn("unlock tables"); DBQueryWarn("unlock tables");
...@@ -570,7 +576,7 @@ sub Delete($;$) ...@@ -570,7 +576,7 @@ sub Delete($;$)
return -1 return -1
if (!DBQueryWarn("delete from interface_state ". if (!DBQueryWarn("delete from interface_state ".
"where node_id='$node_id' iface='$iface'")); "where node_id='$node_id' and iface='$iface'"));
return -1 return -1
if (!DBQueryWarn("delete from port_counters ". if (!DBQueryWarn("delete from port_counters ".
"where node_id='$node_id' and iface='$iface'")); "where node_id='$node_id' and iface='$iface'"));
...@@ -659,6 +665,7 @@ sub MakeFake($$$) ...@@ -659,6 +665,7 @@ sub MakeFake($$$)
sub LookupByIface($$$) sub LookupByIface($$$)
{ {
my ($class, $nodeid, $iface) = @_; my ($class, $nodeid, $iface) = @_;
my $interface = {};
my $state_row; my $state_row;
$nodeid = $nodeid->node_id() $nodeid = $nodeid->node_id()
...@@ -699,10 +706,14 @@ sub LookupByIface($$$) ...@@ -699,10 +706,14 @@ sub LookupByIface($$$)
# Remove card,port in the results in preparation for removal # Remove card,port in the results in preparation for removal
# from the table. # from the table.
# #
if (exists($rowref->{'card'})) {
$rowref->{'card_saved'} = $rowref->{'card'};
delete($rowref->{'card'}) delete($rowref->{'card'})
if (exists($rowref->{'card'})); }
if (exists($rowref->{'port'})) {
$rowref->{'port_saved'} = $rowref->{'port'};
delete($rowref->{'port'}) delete($rowref->{'port'})
if (exists($rowref->{'port'})); }
# #
# And the interface_state table. # And the interface_state table.
...@@ -742,7 +753,6 @@ sub LookupByIface($$$) ...@@ -742,7 +753,6 @@ sub LookupByIface($$$)
# Does not have to exist. # Does not have to exist.
my $wire = Interface::Wire->LookupAnyByIface($nodeid, $iface); my $wire = Interface::Wire->LookupAnyByIface($nodeid, $iface);
my $interface = {};
$interface->{"DBROW"} = $rowref; $interface->{"DBROW"} = $rowref;
$interface->{'STATE'} = $state_row; $interface->{'STATE'} = $state_row;
$interface->{'WIRE'} = undef; $interface->{'WIRE'} = undef;
...@@ -1326,7 +1336,7 @@ sub Lookup($$) ...@@ -1326,7 +1336,7 @@ sub Lookup($$)
DBQueryWarn("select * from wires ". DBQueryWarn("select * from wires ".
"where external_interface='$interface'"); "where external_interface='$interface'");
} else { } else {
my ($node_id1,$card1,$port1); my ($node_id1,$card1,$port1,$iface1);
if (!ref($interface)) { if (!ref($interface)) {
# Allow "nodeid:card:port" argument. # Allow "nodeid:card:port" argument.
...@@ -1334,6 +1344,11 @@ sub Lookup($$) ...@@ -1334,6 +1344,11 @@ sub Lookup($$)
$node_id1 = $1; $node_id1 = $1;
$card1 = $2; $card1 = $2;
$port1 = $3; $port1 = $3;
$query_result =
DBQueryWarn("select * from wires ".
"where node_id1='$node_id1' and ".
" card1='$card1' and port1='$port1'");
} }
else { else {
return undef; return undef;
...@@ -1341,13 +1356,13 @@ sub Lookup($$) ...@@ -1341,13 +1356,13 @@ sub Lookup($$)
} }
else { else {
$node_id1 = $interface->node_id(); $node_id1 = $interface->node_id();
$card1 = $interface->card(); $iface1 = $interface->iface();
$port1 = $interface->port();
}
$query_result = $query_result =
DBQueryWarn("select * from wires ". DBQueryWarn("select * from wires ".
"where node_id1='$node_id1' and ". "where node_id1='$node_id1' and ".
" card1='$card1' and port1='$port1'"); " iface1='$iface1'");
}
} }
return undef return undef
...@@ -1382,13 +1397,18 @@ sub Create($$$$$) ...@@ -1382,13 +1397,18 @@ sub Create($$$$$)
my ($self, $interface1, $interface2, $type, $argref) = @_; my ($self, $interface1, $interface2, $type, $argref) = @_;
my $node_id1 = $interface1->node_id(); my $node_id1 = $interface1->node_id();
my $card1 = $interface1->card();
my $port1 = $interface1->port();
my $iface1 = $interface1->iface(); my $iface1 = $interface1->iface();
my $node_id2 = $interface2->node_id(); my $node_id2 = $interface2->node_id();
my $card2 = $interface2->card();
my $port2 = $interface2->port();
my $iface2 = $interface2->iface(); my $iface2 = $interface2->iface();
my $card1 = $argref->{'card1'};
my $port1 = $argref->{'port1'};
my $card2 = $argref->{'card2'};
my $port2 = $argref->{'port2'};
if (! (defined($card1) && defined($port1) &&
defined($card2) && defined($port2))) {
print STDERR "*** Interface::Wire->Create(): missing arguments\n";
return undef;
}
my $command = "insert into wires set". my $command = "insert into wires set".
" type='$type', " . " type='$type', " .
...@@ -1409,7 +1429,7 @@ sub Create($$$$$) ...@@ -1409,7 +1429,7 @@ sub Create($$$$$)
DBQueryWarn($command) or DBQueryWarn($command) or
return undef; return undef;
return Interface::Wire->Lookup($interface1); return Interface::Wire->LookupByIface($node_id1, $iface1);
} }
# #
...@@ -1443,6 +1463,9 @@ sub LookupAny($$$;$) ...@@ -1443,6 +1463,9 @@ sub LookupAny($$$;$)
{ {
my ($class, $nodeid, $card, $port) = @_; my ($class, $nodeid, $card, $port) = @_;
$nodeid = $nodeid->node_id()
if (ref($nodeid));
my $query_result = my $query_result =
DBQueryWarn("select * from wires ". DBQueryWarn("select * from wires ".
"where (node_id1='$nodeid' and ". "where (node_id1='$nodeid' and ".
...@@ -1462,6 +1485,9 @@ sub LookupAnyByIface($$$) ...@@ -1462,6 +1485,9 @@ sub LookupAnyByIface($$$)
{ {
my ($class, $nodeid, $iface) = @_; my ($class, $nodeid, $iface) = @_;
$nodeid = $nodeid->node_id()
if (ref($nodeid));
my $query_result = my $query_result =
DBQueryWarn("select * from wires ". DBQueryWarn("select * from wires ".
"where (node_id1='$nodeid' and iface1='$iface') or ". "where (node_id1='$nodeid' and iface1='$iface') or ".
...@@ -1479,6 +1505,9 @@ sub LookupByIface($$$) ...@@ -1479,6 +1505,9 @@ sub LookupByIface($$$)
{ {
my ($class, $nodeid, $iface) = @_; my ($class, $nodeid, $iface) = @_;
$nodeid = $nodeid->node_id()
if (ref($nodeid));
my $query_result = my $query_result =
DBQueryWarn("select * from wires ". DBQueryWarn("select * from wires ".
"where (node_id1='$nodeid' and iface1='$iface')"); "where (node_id1='$nodeid' and iface1='$iface')");
...@@ -1496,6 +1525,11 @@ sub LookupAnyByIfaces($$$$$) ...@@ -1496,6 +1525,11 @@ sub LookupAnyByIfaces($$$$$)
{ {
my ($class, $nodeid1, $iface1, $nodeid2, $iface2) = @_; my ($class, $nodeid1, $iface1, $nodeid2, $iface2) = @_;
$nodeid1 = $nodeid1->node_id()
if (ref($nodeid1));
$nodeid2 = $nodeid2->node_id()
if (ref($nodeid2));
my $query_result = my $query_result =
DBQueryWarn("select * from wires ". DBQueryWarn("select * from wires ".
"where ((node_id1='$nodeid1' and iface1='$iface1') and ". "where ((node_id1='$nodeid1' and iface1='$iface1') and ".
...@@ -1684,8 +1718,8 @@ sub ExperimentLogicalWires($$$) ...@@ -1684,8 +1718,8 @@ sub ExperimentLogicalWires($$$)
my $query_result = my $query_result =
DBQueryWarn("select r.node_id,w.card1,w.port1 from reserved as r ". DBQueryWarn("select r.node_id,w.card1,w.port1 from reserved as r ".
"left join interfaces as i on i.node_id=r.node_id ". "left join interfaces as i on i.node_id=r.node_id ".
"left join wires as w on w.node_id1=r.node_id and ". "left join wires as w on w.node_id1=i.node_id and ".
" w.card1=i.card and w.port1=i.port ". " w.iface1=i.iface ".
"where i.logical=1 and r.exptidx='$exptidx' and ". "where i.logical=1 and r.exptidx='$exptidx' and ".
" card1 is not null"); " card1 is not null");
return -1 return -1
......
...@@ -2785,8 +2785,6 @@ sub CreateVnodes($$$) ...@@ -2785,8 +2785,6 @@ sub CreateVnodes($$$)
if ($isjailed && !$isremote) { if ($isjailed && !$isremote) {
my $ifaceargs = { my $ifaceargs = {
"node_id" => $vnodeid, "node_id" => $vnodeid,
"card" => 0,
"port" => 1,
"iface" => "eth0", "iface" => "eth0",
"role" => TBDB_IFACEROLE_CONTROL(), "role" => TBDB_IFACEROLE_CONTROL(),
"MAC" => "genfake", "MAC" => "genfake",
......
...@@ -33,7 +33,7 @@ use Data::Dumper; ...@@ -33,7 +33,7 @@ use Data::Dumper;
sub usage() sub usage()
{ {
print STDERR "Usage: addinterface [-b speed | -t ifacetype] [-m mac] ". print STDERR "Usage: addinterface [-b speed | -t ifacetype] [-m mac] ".
"[-r role] portinfo node_id [iface_id]\n"; "[-r role] node_id iface_id\n";
print STDERR "Usage: addinterface -r <node_id> <iface_id>\n"; print STDERR "Usage: addinterface -r <node_id> <iface_id>\n";
print STDERR "Usage: addinterface -i <node_id> <iface_id>\n"; print STDERR "Usage: addinterface -i <node_id> <iface_id>\n";
print STDERR "Options:\n"; print STDERR "Options:\n";
...@@ -46,10 +46,7 @@ sub usage() ...@@ -46,10 +46,7 @@ sub usage()
print STDERR " -m mac - Optional MAC address. 0123456789AB format.\n"; print STDERR " -m mac - Optional MAC address. 0123456789AB format.\n";
print STDERR " -b speed - Interface speed; 100Mb,1Gb,10Gb,40Gb,100Gb\n"; print STDERR " -b speed - Interface speed; 100Mb,1Gb,10Gb,40Gb,100Gb\n";
print STDERR " -t type - Interface type instead of generic based on speed\n"; print STDERR " -t type - Interface type instead of generic based on speed\n";
print STDERR " portinfo - card,port (for now, might change later)\n"; print STDERR " iface_id - eth0, eth1, 1/69, 1.6:1, Po4.5/9:1, etc.\n";
print STDERR " iface_id - eth0, eth1, 1/69, 1/6/9. If you do not specify,\n";
print STDERR " one will be constructed for you (ethXX).\n";
exit(-1); exit(-1);
} }
my $optlist = "b:t:nvfm:re:i"; my $optlist = "b:t:nvfm:re:i";
...@@ -172,59 +169,25 @@ elsif ($info) { ...@@ -172,59 +169,25 @@ elsif ($info) {
} }
usage() usage()
if (@ARGV < 2 || !defined($type)); if (@ARGV != 2 || !defined($type));
my $portinfo = $ARGV[0]; my $node_id = $ARGV[0];
my $node_id = $ARGV[1]; my $iface_id = $ARGV[1];
my $iface_id = $ARGV[2] if (@ARGV == 3);
# Sanity check node/portinfo. # Sanity check node/portinfo.
my $node = Node->Lookup($node_id); my $node = Node->Lookup($node_id);
if (!defined($node)) { if (!defined($node)) {
fatal("No such node $node_id"); fatal("No such node $node_id");
} }
if ($portinfo =~ /^(\d+),(\d+)$/) { my $interface = Interface->LookupByIface($node_id, $iface_id);
$card = $1;
$port = $2;
}
else {
fatal("Invalid portinfo; must be in card,port format");
}
my $interface = Interface->Lookup($node_id, $card, $port);
if (defined($interface)) { if (defined($interface)) {
fatal("Interface already exists for $card,$port");
}
if (defined($iface_id)) {
$interface = Interface->LookupByIface($node_id, $iface_id);
if (defined($interface)) {
fatal("Interface already exists for $iface_id"); fatal("Interface already exists for $iface_id");
}
}
else {
if ($node->role() eq "testnode") {
if ($node->isswitch()) {
$iface_id = sprintf("eth%02d%02d", $card, $port);
}
else {
$iface_id = "eth${card}";
}
}
else {
$iface_id = "${card}/${port}";
}
print "Will use iface: $iface_id\n";
$interface = Interface->LookupByIface($node_id, $iface_id);
if (defined($interface)) {
fatal("Interface already exists for generated $iface_id");
}
} }
# #
# Create the interface. # Create the interface.
# #
my $ifaceargs = { my $ifaceargs = {
"node_id" => $node_id, "node_id" => $node_id,
"card" => $card,
"port" => $port,
"iface" => $iface_id, "iface" => $iface_id,
"role" => $role, "role" => $role,
"type" => $type->type(), "type" => $type->type(),
......
...@@ -237,6 +237,14 @@ if (defined($switchinfo)) { ...@@ -237,6 +237,14 @@ if (defined($switchinfo)) {
if (!defined($switch)) { if (!defined($switch)) {
fatal("Could not lookup switch in the database"); fatal("Could not lookup switch in the database");
} }
my $switchiface = $switchcard . "/" . $switchport;
# Lets check consistency.
my $tmp = Interface->LookupByIface($switch, $switchiface);
my $wire = Interface::Wire->LookupAnyByIface($switch, $switchiface);
if (defined($tmp) && defined($wire)) {
fatal("Switch Interface already exists and is wired up: $wire");
}
} }
my $isipmi = ($type =~ /^ipmi/ ? 1 : 0); my $isipmi = ($type =~ /^ipmi/ ? 1 : 0);
...@@ -267,7 +275,7 @@ if (defined($interface)) { ...@@ -267,7 +275,7 @@ if (defined($interface)) {
fatal("Inconsistent ip in $interface") fatal("Inconsistent ip in $interface")
if ($interface->IP() ne $IP); if ($interface->IP() ne $IP);
if (defined($switchinfo)) { if (defined($switchinfo) && $interface->wiredup()) {
fatal("Inconsistent switch_id in $interface") fatal("Inconsistent switch_id in $interface")
if ($interface->switch_id() ne $switchid); if ($interface->switch_id() ne $switchid);
fatal("Inconsistent switch_port in $interface") fatal("Inconsistent switch_port in $interface")
...@@ -278,8 +286,6 @@ if (defined($interface)) { ...@@ -278,8 +286,6 @@ if (defined($interface)) {
} }
else { else {
my $ifaceargs = { my $ifaceargs = {
"card" => 99, # XXX Bogus.
"port" => 1,
"iface" => $type, "iface" => $type,
"role" => TBDB_IFACEROLE_MANAGEMENT(), "role" => TBDB_IFACEROLE_MANAGEMENT(),
"MAC" => $mac, "MAC" => $mac,
...@@ -292,21 +298,28 @@ else { ...@@ -292,21 +298,28 @@ else {
} }
if (defined($switchinfo)) { if (defined($switchinfo)) {
my $switchiface = $switchcard . "/" . $switchport; my $switchiface = $switchcard . "/" . $switchport;
my $switch_interface;
# Lets not create it again.
$switch_interface = Interface->LookupByIface($switch, $switchiface);
if (!defined($switch_interface)) {
$ifaceargs = { $ifaceargs = {
"card" => $switchcard,
"port" => $switchport,
"iface" => $switchiface, "iface" => $switchiface,
"role" => TBDB_IFACEROLE_OTHER(), "role" => TBDB_IFACEROLE_OTHER(),
"type" => "generic", "type" => "generic",
"trunk" => 0, "trunk" => 0,
"mac" => "000000000000", "mac" => "000000000000",
}; };
my $switch_interface = Interface->Create($switch, $ifaceargs); $switch_interface = Interface->Create($switch, $ifaceargs);
if (!defined($interface)) { if (!defined($switch_interface)) {
fatal("Could not create switch interface entry"); fatal("Could not create switch interface entry");
} }
}
my $wireargs = { my $wireargs = {
"card1" => 99, # XXX Bogus.
"port1" => 1,
"card2" => $switchcard,
"port2" => $switchport,
}; };
$wireargs->{"cable"} = $cable if (defined($cable)); $wireargs->{"cable"} = $cable if (defined($cable));
$wireargs->{"length"} = $cablelen if (defined($cablelen)); $wireargs->{"length"} = $cablelen if (defined($cablelen));
......
...@@ -139,7 +139,6 @@ fatal( "Node already has an interface named $iface_id2" ) ...@@ -139,7 +139,6 @@ fatal( "Node already has an interface named $iface_id2" )
# Add the interfaces. # Add the interfaces.
# #
my $ifaceargs = { my $ifaceargs = {
"card" => $card1,
"iface" => $iface_id1, "iface" => $iface_id1,
"role" => TBDB_IFACEROLE_EXPERIMENT(), "role" => TBDB_IFACEROLE_EXPERIMENT(),
"type" => "P2PLTE", "type" => "P2PLTE",
...@@ -155,7 +154,6 @@ if (!$impotent) { ...@@ -155,7 +154,6 @@ if (!$impotent) {
} }
$ifaceargs = { $ifaceargs = {
"card" => $card2,
"iface" => $iface_id2, "iface" => $iface_id2,
"role" => TBDB_IFACEROLE_EXPERIMENT(), "role" => TBDB_IFACEROLE_EXPERIMENT(),
"type" => "P2PLTE", "type" => "P2PLTE",
...@@ -171,7 +169,11 @@ if (!$impotent) { ...@@ -171,7 +169,11 @@ if (!$impotent) {
} }
my $wireargs = { my $wireargs = {
"external_wire"=> $path, "card1" => $card1,
"port1" => 1,
"card2" => $card2,
"port2" => 1,
"external_wire" => $path,
}; };
if (!$impotent) { if (!$impotent) {
Interface::Wire->Create($interface1, $interface2, 'Node', $wireargs) Interface::Wire->Create($interface1, $interface2, 'Node', $wireargs)
......
...@@ -262,31 +262,21 @@ if (defined($wire)) { ...@@ -262,31 +262,21 @@ if (defined($wire)) {
# #
# Add the interfaces. # Add the interfaces.
# #
my $type; my $type = Interface::Type->GenericType($speed);
my $max_speed; if (!defined($type)) {
if( $speed eq "100Mb" ) { # default is 1G for backward compatibility
$type = "generic"; $type = Interface::Type->Lookup("generic_1G");
$max_speed = "100"; if (!defined($type)) {
} elsif( $speed eq "10Gb" ) { fatal("Could not find a generic type for $speed");
$type = "generic_10G"; }
$max_speed = "10000";
} elsif( $speed eq "40Gb" ) {
$type = "generic_40G";
$max_speed = "40000";
} elsif( $speed eq "100Gb" ) {
$type = "generic_100G";
$max_speed = "100000";
} else { # default is 1G for backward compatibility
$type = "generic_1G";
$max_speed = "1000";
} }
my $ifaceargs1 = { my $ifaceargs1 = {
"card" => $switchcard, "card" => $switchcard,
"port" => $switchport, "port" => $switchport,
"iface" => $switchcard . "/" . $switchport, "iface" => $switchcard . "/" . $switchport,
"role" => TBDB_IFACEROLE_OTHER(), "role" => TBDB_IFACEROLE_OTHER(),
"type" => $type, "type" => $type->type(),
"max_speed" => $max_speed, "max_speed" => $type->max_speed(),
"mac" => "000000000000", "mac" => "000000000000",
}; };
print "Creating switch interface with arguments:\n"; print "Creating switch interface with arguments:\n";
...@@ -300,8 +290,8 @@ my $ifaceargs2 = { ...@@ -300,8 +290,8 @@ my $ifaceargs2 = {
"card" => $nodecard, "card" => $nodecard,
"iface" => $iface_id, "iface" => $iface_id,
"role" => TBDB_IFACEROLE_EXPERIMENT(), "role" => TBDB_IFACEROLE_EXPERIMENT(),
"type" => $type, "type" => $type->type(),
"max_speed" => $max_speed, "max_speed" => $type->max_speed(),
"trunk" => ($node->IsReserved() && "trunk" => ($node->IsReserved() &&
$node->erole() eq "sharedhost" ? 1 : 0), $node->erole() eq "sharedhost" ? 1 : 0),
"mac" => "000000000000", "mac" => "000000000000",
...@@ -313,6 +303,12 @@ if (!$impotent) { ...@@ -313,6 +303,12 @@ if (!$impotent) {
or fatal("Could not create interface entry"); or fatal("Could not create interface entry");
} }
if (!$impotent) { if (!$impotent) {
my $wireargs = {
"card1" => $switchcard,
"port1" => $switchport,
"card2" => $nodecard,
"port2" => 1,
};
print "Creating wire for $interface1,$interface2:\n"; print "Creating wire for $interface1,$interface2:\n";
$wire = Interface::Wire->Create($interface1, $interface2, 'Node', {}) $wire = Interface::Wire->Create($interface1, $interface2, 'Node', {})
or fatal("Could not create wire"); or fatal("Could not create wire");
......
...@@ -32,7 +32,7 @@ use Data::Dumper; ...@@ -32,7 +32,7 @@ use Data::Dumper;
sub usage() sub usage()
{ {
print STDERR "Usage: addwire [-t type] [-c id [-l len]] ". print STDERR "Usage: addwire [-t type] [-c id [-l len]] ".
"node1:iface1 node2:iface2\n"; "node1:iface1 portinfo1 node2:iface2 portinfo2\n";
print STDERR "Usage: addwire -r node1:iface1 node2:iface2\n"; print STDERR "Usage: addwire -r node1:iface1 node2:iface2\n";
print STDERR "Options:\n"; print STDERR "Options:\n";
print STDERR " -v - Turn on debugging\n"; print STDERR " -v - Turn on debugging\n";
...@@ -42,6 +42,7 @@ sub usage() ...@@ -42,6 +42,7 @@ sub usage()
print STDERR " -c cable - Cable ID\n"; print STDERR " -c cable - Cable ID\n";
print STDERR " -l len - Cable length\n"; print STDERR " -l len - Cable length\n";
print STDERR " -t type - Wire type (defaults to Unused)\n"; print STDERR " -t type - Wire type (defaults to Unused)\n";
print STDERR " portinfo - card,port (for now, might change later)\n";
exit(-1); exit(-1);
} }
...@@ -53,11 +54,11 @@ my $force = 0; ...@@ -53,11 +54,11 @@ my $force = 0;
my $type = "other"; my $type = "other";
my $cable; my $cable;
my $cablelen; my $cablelen;
my ($node_id1,$iface_id1,$node_id2,$iface_id2); my ($node_id1,$iface_id1,$card1,$port1,$node_id2,$iface_id2,$card2,$port2);
# Protos # Protos
sub fatal($); sub fatal($);
sub RemoveWire($); sub RemoveWire($$);