All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

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

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

interface_state tables.
parent 0d4f2d5e
......@@ -251,6 +251,9 @@ sub 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
sub wire($) { return $_[0]->{'WIRE'}; }
sub wiredup($) { return (defined($_[0]->{'WIRE'}) ? 1 : 0); }
......@@ -425,14 +428,16 @@ sub Create($$$)
"longer supported!\n";
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 $MAC = $argref->{'MAC'} || $argref->{'mac'};
my $IP = $argref->{'IP'};
my $mask = $argref->{'mask'};
my $card = $argref->{'card'};
my $port = $argref->{'port'};
my $iftype = $argref->{'type'} || $argref->{'interface_type'};
my $ifrole = $argref->{'role'};
my $uuid = $argref->{'uuid'};
......@@ -443,10 +448,6 @@ sub Create($$$)
my $trunk = $argref->{'trunk'};
my $auto = $argref->{'autocreated'};
$iface = "eth$card"
if (!defined($iface));
$port = 1
if (!defined($port));
$IP = ""
if (!defined($IP));
$mask = ""
......@@ -468,8 +469,7 @@ sub Create($$$)
return undef;
}
}
if (! (defined($card) && defined($ifrole) && defined($MAC) &&
defined($IP) && defined($port) &&
if (! (defined($ifrole) && defined($MAC) && defined($IP) &&
defined($iftype) && defined($iface) && defined($max_speed) &&
defined($duplex) && defined($uuid))) {
print STDERR "Interface::Create: Missing fields in arguments:\n";
......@@ -477,6 +477,13 @@ sub Create($$$)
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
#
......@@ -493,11 +500,10 @@ sub Create($$$)
#
my $query_result =
DBQueryWarn("select node_id from interfaces ".
"where node_id='$node_id' and ".
" card='$card' and port='$port'");
"where node_id='$node_id' and iface='$iface'");
if ($query_result->numrows) {
DBQueryWarn("unlock tables");
return Interface->Lookup($node_id, $card, $port);
return Interface->Lookup($node_id, $iface);
}
#
......@@ -528,7 +534,7 @@ sub Create($$$)
if (!DBQueryWarn("insert into interfaces set ".
" node_id='$node_id', logical='$logical', " .
" card=$card, port=$port, role='$ifrole', ".
" role='$ifrole', ".
" mac='$MAC', IP='$IP', autocreated='$auto', " .
(defined($mask) ? "mask='$mask', " : "") .
($trunk ? "trunk='1', " : "") .
......@@ -542,7 +548,7 @@ sub Create($$$)
if (!DBQueryWarn("insert into interface_state set ".
" node_id='$node_id', " .
($trunk ? "remaining_bandwidth='$max_speed', " : "") .
" card=$card, port=$port, iface='$iface'")) {
" iface='$iface'")) {
DBQueryWarn("delete from interfaces ".
"where node_id='$node_id' and iface='$iface' ");
DBQueryWarn("unlock tables");
......@@ -570,7 +576,7 @@ sub Delete($;$)
return -1
if (!DBQueryWarn("delete from interface_state ".
"where node_id='$node_id' iface='$iface'"));
"where node_id='$node_id' and iface='$iface'"));
return -1
if (!DBQueryWarn("delete from port_counters ".
"where node_id='$node_id' and iface='$iface'"));
......@@ -659,6 +665,7 @@ sub MakeFake($$$)
sub LookupByIface($$$)
{
my ($class, $nodeid, $iface) = @_;
my $interface = {};
my $state_row;
$nodeid = $nodeid->node_id()
......@@ -699,10 +706,14 @@ sub LookupByIface($$$)
# Remove card,port in the results in preparation for removal
# from the table.
#
if (exists($rowref->{'card'})) {
$rowref->{'card_saved'} = $rowref->{'card'};
delete($rowref->{'card'})
if (exists($rowref->{'card'}));
}
if (exists($rowref->{'port'})) {
$rowref->{'port_saved'} = $rowref->{'port'};
delete($rowref->{'port'})
if (exists($rowref->{'port'}));
}
#
# And the interface_state table.
......@@ -742,7 +753,6 @@ sub LookupByIface($$$)
# Does not have to exist.
my $wire = Interface::Wire->LookupAnyByIface($nodeid, $iface);
my $interface = {};
$interface->{"DBROW"} = $rowref;
$interface->{'STATE'} = $state_row;
$interface->{'WIRE'} = undef;
......@@ -1326,7 +1336,7 @@ sub Lookup($$)
DBQueryWarn("select * from wires ".
"where external_interface='$interface'");
} else {
my ($node_id1,$card1,$port1);
my ($node_id1,$card1,$port1,$iface1);
if (!ref($interface)) {
# Allow "nodeid:card:port" argument.
......@@ -1334,6 +1344,11 @@ sub Lookup($$)
$node_id1 = $1;
$card1 = $2;
$port1 = $3;
$query_result =
DBQueryWarn("select * from wires ".
"where node_id1='$node_id1' and ".
" card1='$card1' and port1='$port1'");
}
else {
return undef;
......@@ -1341,13 +1356,13 @@ sub Lookup($$)
}
else {
$node_id1 = $interface->node_id();
$card1 = $interface->card();
$port1 = $interface->port();
}
$iface1 = $interface->iface();
$query_result =
DBQueryWarn("select * from wires ".
"where node_id1='$node_id1' and ".
" card1='$card1' and port1='$port1'");
" iface1='$iface1'");
}
}
return undef
......@@ -1382,13 +1397,18 @@ sub Create($$$$$)
my ($self, $interface1, $interface2, $type, $argref) = @_;
my $node_id1 = $interface1->node_id();
my $card1 = $interface1->card();
my $port1 = $interface1->port();
my $iface1 = $interface1->iface();
my $node_id2 = $interface2->node_id();
my $card2 = $interface2->card();
my $port2 = $interface2->port();
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".
" type='$type', " .
......@@ -1409,7 +1429,7 @@ sub Create($$$$$)
DBQueryWarn($command) or
return undef;
return Interface::Wire->Lookup($interface1);
return Interface::Wire->LookupByIface($node_id1, $iface1);
}
#
......@@ -1443,6 +1463,9 @@ sub LookupAny($$$;$)
{
my ($class, $nodeid, $card, $port) = @_;
$nodeid = $nodeid->node_id()
if (ref($nodeid));
my $query_result =
DBQueryWarn("select * from wires ".
"where (node_id1='$nodeid' and ".
......@@ -1462,6 +1485,9 @@ sub LookupAnyByIface($$$)
{
my ($class, $nodeid, $iface) = @_;
$nodeid = $nodeid->node_id()
if (ref($nodeid));
my $query_result =
DBQueryWarn("select * from wires ".
"where (node_id1='$nodeid' and iface1='$iface') or ".
......@@ -1479,6 +1505,9 @@ sub LookupByIface($$$)
{
my ($class, $nodeid, $iface) = @_;
$nodeid = $nodeid->node_id()
if (ref($nodeid));
my $query_result =
DBQueryWarn("select * from wires ".
"where (node_id1='$nodeid' and iface1='$iface')");
......@@ -1496,6 +1525,11 @@ sub LookupAnyByIfaces($$$$$)
{
my ($class, $nodeid1, $iface1, $nodeid2, $iface2) = @_;
$nodeid1 = $nodeid1->node_id()
if (ref($nodeid1));
$nodeid2 = $nodeid2->node_id()
if (ref($nodeid2));
my $query_result =
DBQueryWarn("select * from wires ".
"where ((node_id1='$nodeid1' and iface1='$iface1') and ".
......@@ -1684,8 +1718,8 @@ sub ExperimentLogicalWires($$$)
my $query_result =
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 wires as w on w.node_id1=r.node_id and ".
" w.card1=i.card and w.port1=i.port ".
"left join wires as w on w.node_id1=i.node_id and ".
" w.iface1=i.iface ".
"where i.logical=1 and r.exptidx='$exptidx' and ".
" card1 is not null");
return -1
......
......@@ -2785,8 +2785,6 @@ sub CreateVnodes($$$)
if ($isjailed && !$isremote) {
my $ifaceargs = {
"node_id" => $vnodeid,
"card" => 0,
"port" => 1,
"iface" => "eth0",
"role" => TBDB_IFACEROLE_CONTROL(),
"MAC" => "genfake",
......
......@@ -33,7 +33,7 @@ use Data::Dumper;
sub usage()
{
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 -i <node_id> <iface_id>\n";
print STDERR "Options:\n";
......@@ -46,10 +46,7 @@ sub usage()
print STDERR " -m mac - Optional MAC address. 0123456789AB format.\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 " portinfo - card,port (for now, might change later)\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";
print STDERR " iface_id - eth0, eth1, 1/69, 1.6:1, Po4.5/9:1, etc.\n";
exit(-1);
}
my $optlist = "b:t:nvfm:re:i";
......@@ -172,59 +169,25 @@ elsif ($info) {
}
usage()
if (@ARGV < 2 || !defined($type));
if (@ARGV != 2 || !defined($type));
my $portinfo = $ARGV[0];
my $node_id = $ARGV[1];
my $iface_id = $ARGV[2] if (@ARGV == 3);
my $node_id = $ARGV[0];
my $iface_id = $ARGV[1];
# Sanity check node/portinfo.
my $node = Node->Lookup($node_id);
if (!defined($node)) {
fatal("No such node $node_id");
}
if ($portinfo =~ /^(\d+),(\d+)$/) {
$card = $1;
$port = $2;
}
else {
fatal("Invalid portinfo; must be in card,port format");
}
my $interface = Interface->Lookup($node_id, $card, $port);
my $interface = Interface->LookupByIface($node_id, $iface_id);
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");
}
}
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.
#
my $ifaceargs = {
"node_id" => $node_id,
"card" => $card,
"port" => $port,
"iface" => $iface_id,
"role" => $role,
"type" => $type->type(),
......
......@@ -237,6 +237,14 @@ if (defined($switchinfo)) {
if (!defined($switch)) {
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);
......@@ -267,7 +275,7 @@ if (defined($interface)) {
fatal("Inconsistent ip in $interface")
if ($interface->IP() ne $IP);
if (defined($switchinfo)) {
if (defined($switchinfo) && $interface->wiredup()) {
fatal("Inconsistent switch_id in $interface")
if ($interface->switch_id() ne $switchid);
fatal("Inconsistent switch_port in $interface")
......@@ -278,8 +286,6 @@ if (defined($interface)) {
}
else {
my $ifaceargs = {
"card" => 99, # XXX Bogus.
"port" => 1,
"iface" => $type,
"role" => TBDB_IFACEROLE_MANAGEMENT(),
"MAC" => $mac,
......@@ -292,21 +298,28 @@ else {
}
if (defined($switchinfo)) {
my $switchiface = $switchcard . "/" . $switchport;
my $switch_interface;
# Lets not create it again.
$switch_interface = Interface->LookupByIface($switch, $switchiface);
if (!defined($switch_interface)) {
$ifaceargs = {
"card" => $switchcard,
"port" => $switchport,
"iface" => $switchiface,
"role" => TBDB_IFACEROLE_OTHER(),
"type" => "generic",
"trunk" => 0,
"mac" => "000000000000",
};
my $switch_interface = Interface->Create($switch, $ifaceargs);
if (!defined($interface)) {
$switch_interface = Interface->Create($switch, $ifaceargs);
if (!defined($switch_interface)) {
fatal("Could not create switch interface entry");
}
}
my $wireargs = {
"card1" => 99, # XXX Bogus.
"port1" => 1,
"card2" => $switchcard,
"port2" => $switchport,
};
$wireargs->{"cable"} = $cable if (defined($cable));
$wireargs->{"length"} = $cablelen if (defined($cablelen));
......
......@@ -139,7 +139,6 @@ fatal( "Node already has an interface named $iface_id2" )
# Add the interfaces.
#
my $ifaceargs = {
"card" => $card1,
"iface" => $iface_id1,
"role" => TBDB_IFACEROLE_EXPERIMENT(),
"type" => "P2PLTE",
......@@ -155,7 +154,6 @@ if (!$impotent) {
}
$ifaceargs = {
"card" => $card2,
"iface" => $iface_id2,
"role" => TBDB_IFACEROLE_EXPERIMENT(),
"type" => "P2PLTE",
......@@ -171,7 +169,11 @@ if (!$impotent) {
}
my $wireargs = {
"external_wire"=> $path,
"card1" => $card1,
"port1" => 1,
"card2" => $card2,
"port2" => 1,
"external_wire" => $path,
};
if (!$impotent) {
Interface::Wire->Create($interface1, $interface2, 'Node', $wireargs)
......
......@@ -262,31 +262,21 @@ if (defined($wire)) {
#
# Add the interfaces.
#
my $type;
my $max_speed;
if( $speed eq "100Mb" ) {
$type = "generic";
$max_speed = "100";
} elsif( $speed eq "10Gb" ) {
$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 $type = Interface::Type->GenericType($speed);
if (!defined($type)) {
# default is 1G for backward compatibility
$type = Interface::Type->Lookup("generic_1G");
if (!defined($type)) {
fatal("Could not find a generic type for $speed");
}
}
my $ifaceargs1 = {
"card" => $switchcard,
"port" => $switchport,
"iface" => $switchcard . "/" . $switchport,
"role" => TBDB_IFACEROLE_OTHER(),
"type" => $type,
"max_speed" => $max_speed,
"type" => $type->type(),
"max_speed" => $type->max_speed(),
"mac" => "000000000000",
};
print "Creating switch interface with arguments:\n";
......@@ -300,8 +290,8 @@ my $ifaceargs2 = {
"card" => $nodecard,
"iface" => $iface_id,
"role" => TBDB_IFACEROLE_EXPERIMENT(),
"type" => $type,
"max_speed" => $max_speed,
"type" => $type->type(),
"max_speed" => $type->max_speed(),
"trunk" => ($node->IsReserved() &&
$node->erole() eq "sharedhost" ? 1 : 0),
"mac" => "000000000000",
......@@ -313,6 +303,12 @@ if (!$impotent) {
or fatal("Could not create interface entry");
}
if (!$impotent) {
my $wireargs = {
"card1" => $switchcard,
"port1" => $switchport,
"card2" => $nodecard,
"port2" => 1,
};
print "Creating wire for $interface1,$interface2:\n";
$wire = Interface::Wire->Create($interface1, $interface2, 'Node', {})
or fatal("Could not create wire");
......
......@@ -32,7 +32,7 @@ use Data::Dumper;
sub usage()
{
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 "Options:\n";
print STDERR " -v - Turn on debugging\n";
......@@ -42,6 +42,7 @@ sub usage()
print STDERR " -c cable - Cable ID\n";
print STDERR " -l len - Cable length\n";
print STDERR " -t type - Wire type (defaults to Unused)\n";
print STDERR " portinfo - card,port (for now, might change later)\n";
exit(-1);
}
......@@ -53,11 +54,11 @@ my $force = 0;
my $type = "other";
my $cable;
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
sub fatal($);
sub RemoveWire($);
sub RemoveWire($$);
#
# Configure variables
......@@ -136,8 +137,11 @@ if (! defined($this_user)) {
if (!$this_user->IsAdmin()) {
fatal("You are not a testbed administrator!");
}
if ($remove) {
exit(RemoveWire($ARGV[0],$ARGV[1]));
}
usage()
if (@ARGV != 2);
if (@ARGV != 4);
if ($ARGV[0] =~ /^([-\w]+):(.+)$/) {
$node_id1 = $1;
......@@ -146,20 +150,26 @@ if ($ARGV[0] =~ /^([-\w]+):(.+)$/) {
else {
fatal("Invalid argument for interface: " . $ARGV[0]);
}
if ($ARGV[1] =~ /^([-\w]+):(.+)$/) {
if ($ARGV[1] =~ /^(\d+),(\d+)$/) {
$card1 = $1;
$port1 = $2;
}
else {
fatal("Invalid argument for portinfo: " . $ARGV[1]);
}
if ($ARGV[2] =~ /^([-\w]+):(.+)$/) {
$node_id2 = $1;
$iface_id2 = $2;
}
else {
fatal("Invalid argument for interface: " . $ARGV[1]);
fatal("Invalid argument for interface: " . $ARGV[2]);
}
if ($remove) {
my $wire = Interface::Wire->LookupAnyByIfaces($node_id1, $iface_id1,
$node_id2, $iface_id2);
if (!defined($wire)) {
fatal("No such wire");
}
exit(RemoveWire($wire));
if ($ARGV[3] =~ /^(\d+),(\d+)$/) {
$card2 = $1;
$port2 = $2;
}
else {
fatal("Invalid argument for portinfo: " . $ARGV[3]);
}
#
......@@ -202,6 +212,10 @@ if (defined($wire)) {
# Create the wire.
#
my $wireargs = {
"card1" => $card1,
"port1" => $port1,
"card2" => $card2,
"port2" => $port2,
};
$wireargs->{"cable"} = $cable if (defined($cable));
$wireargs->{"length"} = $cablelen if (defined($cablelen));
......@@ -232,11 +246,32 @@ sub fatal($)
#
# Remove a wire.
#
sub RemoveWire($)
sub RemoveWire($$)
{
my ($wire) = @_;
my ($arg1, $arg2) = @_;
if ($arg1 =~ /^([-\w]+):(.+)$/) {
$node_id1 = $1;
$iface_id1 = $2;
}
else {
fatal("Invalid argument for interface: " . $arg1);
}
if ($arg2 =~ /^([-\w]+):(.+)$/) {
$node_id2 = $1;
$iface_id2 = $2;
}
else {
fatal("Invalid argument for interface: " . $arg2);
}
my $wire = Interface::Wire->LookupAnyByIfaces($node_id1, $iface_id1,
$node_id2, $iface_id2);
if (!defined($wire)) {
fatal("No such wire");
}
my $interface = Interface->LookupByIface($wire->node_id1(), $wire->iface1());
my $interface = Interface->LookupByIface($wire->node_id1(),
$wire->iface1());
if (defined($interface)) {
if (Lan->FindLansByMember($interface->node_id(), $interface->iface())) {
if ($force) {
......@@ -249,7 +284,8 @@ sub RemoveWire($)
}
}
}
$interface = Interface->LookupByIface($wire->node_id2(), $wire->iface2());
$interface = Interface->LookupByIface($wire->node_id2(),
$wire->iface2());
if (defined($interface)) {
if (Lan->FindLansByMember($interface->node_id(), $interface->iface())) {
if ($force) {
......
......@@ -519,8 +519,6 @@ NODE: foreach my $node_id (@node_ids) {
}
my $ifaceargs = {
"node_id" => $node_id,
"card" => $card,
"port" => $port,
"mac" => $MAC,
"IP" => $iface_IP,
"type" => $iface_type,
......@@ -555,8 +553,6 @@ NODE: foreach my $node_id (@node_ids) {
}
$ifaceargs = {
"node_id" => $switch_id,
"card" => $switch_card,
"port" => $switch_port,
"type" => $itype->type(),
"iface" => $switch_card . "/" . $switch_port,
"max_speed" => $max_speed / 1000,
......@@ -570,7 +566,12 @@ NODE: foreach my $node_id (@node_ids) {
}