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