Commit 69721257 authored by Jonathon Duerig's avatar Jonathon Duerig

Support for multiple stitchpoints attached to a single fake node.

parent dc84b7c9
...@@ -3860,6 +3860,7 @@ use libdb; ...@@ -3860,6 +3860,7 @@ use libdb;
use libtestbed; use libtestbed;
use English; use English;
use Lan; use Lan;
use GeniHRN;
use overload ('""' => 'Stringify'); use overload ('""' => 'Stringify');
# #
...@@ -3869,13 +3870,21 @@ sub Lookup($$) ...@@ -3869,13 +3870,21 @@ sub Lookup($$)
{ {
my ($class, $arg) = @_; my ($class, $arg) = @_;
# Always sanity check before hitting the DB. my $query_result;
return undef if (GeniHRN::IsValid($arg)) {
if (! ($arg =~ /^[-\w]*$/)); # If it is a URN, lookup by external_interface
$query_result =
DBQueryWarn("select * from external_networks ".
"where external_interface='$arg'");
} elsif ($arg =~ /^[-\w]*$/) {
# Otherwise it must be a node or network id
$query_result =
DBQueryWarn("select * from external_networks ".
"where node_id='$arg' or network_id='$arg'");
} else {
return undef;
}
my $query_result =
DBQueryWarn("select * from external_networks ".
"where node_id='$arg' or network_id='$arg'");
return undef return undef
if (!$query_result || !$query_result->numrows); if (!$query_result || !$query_result->numrows);
......
...@@ -6424,22 +6424,40 @@ sub findStitchPoint ...@@ -6424,22 +6424,40 @@ sub findStitchPoint
# #
my $edgeurn = GetHopLinkID($edgehop); my $edgeurn = GetHopLinkID($edgehop);
my $edgewire = Interface::Wire->Lookup($edgeurn); my $edgewire = Interface::Wire->Lookup($edgeurn);
if (!defined($edgewire)) { my $network;
return (undef, undef, undef, my $edgenodeid;
GeniResponse->Create(GENIRESPONSE_ERROR, undef, my $edgecard;
"$lanname: unknown ". my $edgeport;
"external_interface for ".
$edgeurn)); #
# The external network may contain the edge URN directly.
#
$network = ExternalNetwork->Lookup($edgeurn);
if (defined($network)) {
$edgenodeid = $network->node_id();
my @networkIfs = ();
Interface->LookupAll($edgenodeid, \@networkIfs);
if (scalar(@networkIfs) == 1) {
$edgecard = $networkIfs[0]->card();
$edgeport = $networkIfs[0]->port();
} else {
return (undef, undef, undef,
GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"Internal Error. Ambiguous stitchpoint ".
"for external_interface " . $edgeurn));
}
} }
# #
# Look in the external networks table to get the hop # The external network may be attached to node_id1
# details.
# #
my $edgenodeid = $edgewire->node_id1(); if (! defined($network) && defined($edgewire)) {
my $edgecard = $edgewire->card1(); $edgenodeid = $edgewire->node_id1();
my $edgeport = $edgewire->port1(); $edgecard = $edgewire->card1();
my $network = ExternalNetwork->Lookup($edgenodeid); $edgeport = $edgewire->port1();
$network = ExternalNetwork->Lookup($edgenodeid);
}
# The external network may be attached to node_id2 # The external network may be attached to node_id2
if (! defined($network)) { if (! defined($network)) {
...@@ -6452,8 +6470,7 @@ sub findStitchPoint ...@@ -6452,8 +6470,7 @@ sub findStitchPoint
return (undef, undef, undef, return (undef, undef, undef,
GeniResponse->Create(GENIRESPONSE_ERROR, undef, GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"$lanname: unknown network for ". "$lanname: unknown network for ".
$edgewire->node_id1() . " and ". "external_interface " . $edgeurn));
$edgewire->node_id2()));
} }
# #
......
...@@ -1463,6 +1463,8 @@ CREATE TABLE `external_networks` ( ...@@ -1463,6 +1463,8 @@ CREATE TABLE `external_networks` (
`min_vlan` int(11) NOT NULL default '256', `min_vlan` int(11) NOT NULL default '256',
`max_vlan` int(11) NOT NULL default '1000', `max_vlan` int(11) NOT NULL default '1000',
`external_manager` tinytext, `external_manager` tinytext,
`external_interface` tinytext,
`external_wire` tinytext,
PRIMARY KEY (`network_id`), PRIMARY KEY (`network_id`),
UNIQUE KEY `node_id` (`node_id`) UNIQUE KEY `node_id` (`node_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1; ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
......
#
# Add external_interface and external_wire columns to external_networks table.
#
use strict;
use libdb;
my $impotent = 0;
sub DoUpdate($$$)
{
my ($dbhandle, $dbname, $version) = @_;
if (!DBSlotExists("external_networks", "external_interface")) {
DBQueryFatal("alter table external_networks add ".
" `external_interface` tinytext");
}
if (!DBSlotExists("external_networks", "external_wire")) {
DBQueryFatal("alter table external_networks add ".
" `external_wire` tinytext");
}
return 0;
}
1;
...@@ -376,7 +376,8 @@ my %contact_ifaces; ...@@ -376,7 +376,8 @@ my %contact_ifaces;
$result = DBQueryFatal("select w.node_id1, w.card1, w.port1, i1.iface, ". $result = DBQueryFatal("select w.node_id1, w.card1, w.port1, i1.iface, ".
"w.node_id2, w.card2, w.port2, i2.iface, ". "w.node_id2, w.card2, w.port2, i2.iface, ".
"w.external_interface, w.external_wire, ". "w.external_interface, w.external_wire, ".
"e.node_id, e.min_vlan, e.max_vlan, e.external_manager ". "e.node_id, e.min_vlan, e.max_vlan, ".
"e.external_manager, e.network_id ".
"from wires as w ". "from wires as w ".
"left join external_networks as e ". "left join external_networks as e ".
"on w.node_id1=e.node_id or w.node_id2=e.node_id ". "on w.node_id1=e.node_id or w.node_id2=e.node_id ".
...@@ -385,14 +386,16 @@ $result = DBQueryFatal("select w.node_id1, w.card1, w.port1, i1.iface, ". ...@@ -385,14 +386,16 @@ $result = DBQueryFatal("select w.node_id1, w.card1, w.port1, i1.iface, ".
"where e.node_id is not null"); "where e.node_id is not null");
while (my ($cnode, $ccard, $cport, $ciface, $enode, $ecard, $eport, $eiface, while (my ($cnode, $ccard, $cport, $ciface, $enode, $ecard, $eport, $eiface,
$external_iface_urn, $external_link_urn, $external, $minLan, $external_iface_urn, $external_link_urn, $external, $minLan,
$maxLan, $external_manager_urn) = $result->fetchrow_array) { $maxLan, $external_manager_urn,
if ($external eq $cnode) { $external_network_id) = $result->fetchrow_array) {
if ($enode eq $cnode) {
my $temp; my $temp;
$temp = $cnode; $cnode = $enode; $enode = $temp; $temp = $cnode; $cnode = $enode; $enode = $temp;
$temp = $ccard; $ccard = $ecard; $ecard = $temp; $temp = $ccard; $ccard = $ecard; $ecard = $temp;
$temp = $cport; $cport = $eport; $eport = $temp; $temp = $cport; $cport = $eport; $eport = $temp;
$temp = $ciface; $ciface = $eiface; $eiface = $temp; $temp = $ciface; $ciface = $eiface; $eiface = $temp;
} }
$enode = $external_network_id;
if (! defined($eiface)) { if (! defined($eiface)) {
$eiface = "$ecard.$eport"; $eiface = "$ecard.$eport";
} }
......
...@@ -31,13 +31,13 @@ use File::Temp qw(tempfile); ...@@ -31,13 +31,13 @@ use File::Temp qw(tempfile);
# #
sub usage() sub usage()
{ {
print STDERR "Usage: addexternalnetwork [-d] [-n] <network_id> <node_id> <external_manager> <minvlan>-<maxvlan>\n"; print STDERR "Usage: addexternalnetwork [-d] [-n] [-w external_wire_urn] [-i external_interface_urn] <network_id> <node_id> <external_manager> <minvlan>-<maxvlan>\n";
print STDERR "Options:\n"; print STDERR "Options:\n";
print STDERR " -d - Turn on debugging\n"; print STDERR " -d - Turn on debugging\n";
print STDERR " -n - Dry run mode\n"; print STDERR " -n - Dry run mode\n";
exit(-1); exit(-1);
} }
my $optlist = "hdn"; my $optlist = "hdnw:i:";
my $debug = 0; my $debug = 0;
my $impotent = 0; my $impotent = 0;
my $network; my $network;
...@@ -46,6 +46,8 @@ my $external; ...@@ -46,6 +46,8 @@ my $external;
my $vlans; my $vlans;
my $minvlan; my $minvlan;
my $maxvlan; my $maxvlan;
my $wire;
my $iface;
# Protos # Protos
sub fatal($); sub fatal($);
...@@ -93,6 +95,12 @@ if (defined($options{'d'})) { ...@@ -93,6 +95,12 @@ if (defined($options{'d'})) {
if (defined($options{'n'})) { if (defined($options{'n'})) {
$impotent = 1; $impotent = 1;
} }
if (defined($options{'w'})) {
$wire = $options{'w'};
}
if (defined($options{'i'})) {
$iface = $options{'i'};
}
usage() usage()
if (scalar(@ARGV) != 4); if (scalar(@ARGV) != 4);
...@@ -144,6 +152,14 @@ $maxvlan = DBQuoteSpecial($maxvlan); ...@@ -144,6 +152,14 @@ $maxvlan = DBQuoteSpecial($maxvlan);
my $query = "REPLACE INTO external_networks SET node_id=$node_id, ". my $query = "REPLACE INTO external_networks SET node_id=$node_id, ".
"node_type=$type, min_vlan=$minvlan, max_vlan=$maxvlan, ". "node_type=$type, min_vlan=$minvlan, max_vlan=$maxvlan, ".
"external_manager=$external, network_id=$network"; "external_manager=$external, network_id=$network";
if (defined($wire)) {
$wire = DBQuoteSpecial($wire);
$query = $query . ", external_wire=$wire";
}
if (defined($iface)) {
$iface = DBQuoteSpecial($iface);
$query = $query . ", external_interface=$iface";
}
if ($debug) { if ($debug) {
print STDERR $query . "\n"; print STDERR $query . "\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