Commit 561f17aa authored by Jonathon Duerig's avatar Jonathon Duerig

Merge stitching changes

parents 29da8250 a22713d5
......@@ -3864,6 +3864,7 @@ use libdb;
use libtestbed;
use English;
use Lan;
use GeniHRN;
use overload ('""' => 'Stringify');
#
......@@ -3873,13 +3874,21 @@ sub Lookup($$)
{
my ($class, $arg) = @_;
# Always sanity check before hitting the DB.
return undef
if (! ($arg =~ /^[-\w]*$/));
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;
}
my $query_result =
DBQueryWarn("select * from external_networks ".
"where node_id='$arg' or network_id='$arg'");
return undef
if (!$query_result || !$query_result->numrows);
......
......@@ -2335,7 +2335,7 @@ sub GetTicketAuxAux($$$$$$$$$)
}
print $fh GeniXML::Serialize($rspec);
close($fh);
my $networkid = $network->node_id();
my $networkid = $network->network_id();
system("$RESERVEVLANS ".
"'$slice_urn' '$linkname' '$networkid' $filename");
if ($CHILD_ERROR) {
......@@ -6416,22 +6416,40 @@ sub findStitchPoint
#
my $edgeurn = GetHopLinkID($edgehop);
my $edgewire = Interface::Wire->Lookup($edgeurn);
if (!defined($edgewire)) {
return (undef, undef, undef,
GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"$lanname: unknown ".
"external_interface for ".
$edgeurn));
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,
"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)) {
......@@ -6444,8 +6462,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,8 +1463,9 @@ CREATE TABLE `external_networks` (
`min_vlan` int(11) NOT NULL default '256',
`max_vlan` int(11) NOT NULL default '1000',
`external_manager` tinytext,
PRIMARY KEY (`network_id`),
UNIQUE KEY `node_id` (`node_id`)
`external_interface` tinytext,
`external_wire` tinytext,
PRIMARY KEY (`network_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
......
......@@ -13,4 +13,5 @@ sub DoUpdate($$$)
return 0;
}
1;
#
# Node in external_networks should no longer be a unique key. Demote it.
#
use strict;
use libdb;
my $impotent = 0;
sub DoUpdate($$$)
{
my ($dbhandle, $dbname, $version) = @_;
DBQueryFatal("alter table external_networks drop index `node_id`");
return 0;
}
1;
#
# 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;
......@@ -369,11 +369,13 @@ my %external_ifaces;
my %external_links;
my %contact_nodes;
my %contact_ifaces;
my %stitch_points;
$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, e.external_interface, e.external_wire ".
"from wires as w ".
"left join external_networks as e ".
"on w.node_id1=e.node_id or w.node_id2=e.node_id ".
......@@ -382,7 +384,9 @@ $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) {
$maxLan, $external_manager_urn,
$external_network_id, $external_network_iface_urn,
$external_network_link_urn) = $result->fetchrow_array) {
if ($external eq $cnode) {
my $temp;
$temp = $cnode; $cnode = $enode; $enode = $temp;
......@@ -390,18 +394,32 @@ while (my ($cnode, $ccard, $cport, $ciface, $enode, $ecard, $eport, $eiface,
$temp = $cport; $cport = $eport; $eport = $temp;
$temp = $ciface; $ciface = $eiface; $eiface = $temp;
}
$stitch_points{"$cnode:$enode"} = 1;
$enode = $external_network_id;
if (! defined($eiface)) {
$eiface = "$ecard.$eport";
}
if (! defined($ciface)) {
$ciface = "$ccard.$cport";
}
if (! defined($external_iface_urn)) {
$external_iface_urn = $external_network_iface_urn;
}
if (! defined($external_link_urn)) {
$external_link_urn = $external_network_link_urn;
}
$external_nodes{$enode} = "$minLan-$maxLan";
$external_managers{"$cnode:$enode"} = $external_manager_urn;
$external_ifaces{"$cnode:$enode"} = $external_iface_urn;
$external_links{"$cnode:$enode"} = $external_link_urn;
$contact_nodes{$cnode} = $enode;
$contact_ifaces{"$cnode:$enode"} = $ciface;
if (exists($contact_nodes{$cnode})) {
push(@{ $contact_nodes{$cnode} }, $enode);
} else {
$contact_nodes{$cnode} = [$enode];
}
$contact_ifaces{"$cnode:$enode"} = GeniHRN::GenerateInterface($OURDOMAIN,
$cnode,
$ciface);
}
print_header();
......@@ -2038,13 +2056,14 @@ sub print_footer {
foreach my $node (keys(%contact_nodes)) {
my $external = $contact_nodes{$node};
my $vlans = $external_nodes{$external};
if (defined($external_links{"$node:$external"})) {
foreach my $external (@{ $contact_nodes{$node} }) {
my $vlans = $external_nodes{$external};
if (defined($external_links{"$node:$external"})) {
print_stitch_node($node,
$contact_ifaces{"$node:$external"},
$external_ifaces{"$node:$external"},
1000000, $vlans, 0);
}
}
}
print "</aggregate>\n";
......@@ -2218,10 +2237,11 @@ sub add_stitch_point
foreach my $key (keys(%$stitch_ifaces)) {
if ($key =~ /([^:]+):([^:]+)/) {
if ($name eq $1 || $name eq $2) {
my $foundCount = grep $_ eq $stitch_ifaces->{$key},
my (undef, undef, $iface) = GeniHRN::ParseInterface($stitch_ifaces->{$key});
my $foundCount = grep $_ eq $iface,
@$interfaces;
if ($foundCount == 0) {
push(@$interfaces, $stitch_ifaces->{$key});
push(@$interfaces, $iface);
}
}
}
......@@ -2535,7 +2555,7 @@ sub print_named_link_ptop
. "$dest_full $bw $delay $loss 1 " . join(" ", @proto) . "\n";
}
sub print_named_link_xml
sub print_named_link_xml_geni
{
my $name = shift(@_);
my $source = shift(@_);
......@@ -2547,7 +2567,6 @@ sub print_named_link_xml
my $loss = shift(@_);
my @proto = @{ shift(@_) };
my $is_interconnect = shift(@_);
my $proto_count = scalar(@proto);
my $source_urn = GeniHRN::GenerateInterface($OURDOMAIN, $source,
$source_if);
my $dest_urn = GeniHRN::GenerateInterface($OURDOMAIN, $dest,
......@@ -2557,24 +2576,58 @@ sub print_named_link_xml
($dest eq "instageni-nc7" && $dest_if ne "eth5"))) {
return;
}
if ($genimode ne $NO_GENI) {
$name =~ s/:/\/\//g;
my $external_manager_urn;
my $urn = GeniHRN::Generate($OURDOMAIN, "link", $name);
if (exists($external_ifaces{"$source:$dest"})) {
$source_urn = GeniHRN::GenerateInterface($OURDOMAIN, $source,
$contact_ifaces{"$source:$dest"});
$dest_urn = $external_ifaces{"$source:$dest"};
$urn = $external_links{"$source:$dest"};
$external_manager_urn = $external_managers{"$source:$dest"};
} elsif (exists($external_ifaces{"$dest:$source"})) {
$source_urn = $external_ifaces{"$dest:$source"};
$dest_urn = GeniHRN::GenerateInterface($OURDOMAIN, $dest,
$contact_ifaces{"$dest:$source"});
$urn = $external_links{"$dest:$source"};
$external_manager_urn = $external_managers{"$dest:$source"};
}
(undef, undef, $name) = GeniHRN::Parse($urn);
my $contact;
my %source_ifaces;
my %dest_ifaces;
if (exists($stitch_points{"$source:$dest"})) {
$contact = $source;
%source_ifaces = %contact_ifaces;
%dest_ifaces = %external_ifaces;
} elsif (exists($stitch_points{"$dest:$source"})) {
$contact = $dest;
%source_ifaces = %external_ifaces;
%dest_ifaces = %contact_ifaces;
}
if (defined($contact)) {
foreach my $external (@{ $contact_nodes{$contact} }) {
$source_urn = $source_ifaces{"$contact:$external"};
$dest_urn = $dest_ifaces{"$contact:$external"};
$urn = $external_links{"$contact:$external"};
$external_manager_urn = $external_managers{"$contact:$external"};
print_single_link_xml_geni($source, $source_if, $dest, $dest_if,
$bw, $delay, $loss, \@proto, $is_interconnect,
$urn, $source_urn, $dest_urn,
$external_manager_urn);
}
} else {
print_single_link_xml_geni($source, $source_if, $dest, $dest_if,
$bw, $delay, $loss, \@proto, $is_interconnect,
$urn, $source_urn, $dest_urn,
$external_manager_urn);
}
}
sub print_single_link_xml_geni
{
my $source = shift(@_);
my $source_if = shift(@_);
my $dest = shift(@_);
my $dest_if = shift(@_);
my $bw = shift(@_);
my $delay = shift(@_);
my $loss = shift(@_);
my @proto = @{ shift(@_) };
my $is_interconnect = shift(@_);
my $urn = shift(@_);
my $source_urn = shift(@_);
my $dest_urn = shift(@_);
my $external_manager_urn = shift(@_);
my $proto_count = scalar(@proto);
my (undef, undef, $name) = GeniHRN::Parse($urn);
print "<link ";
my $cmurn = GeniHRN::Generate($OURDOMAIN, "authority", "cm");
if ($genimode eq $V_0_1 || $genimode eq $V_0_2) {
......@@ -2595,17 +2648,7 @@ sub print_named_link_xml
}
print_interface($source, $source_urn);
print_interface($dest, $dest_urn);
} else {
print "<link name=\"$name\">\n";
print " <source_interface><interface>\n";
print_interface_contents($source, $source_if);
print " </interface></source_interface>\n";
print " <destination_interface><interface>\n";
print_interface_contents($dest, $dest_if);
print " </interface></destination_interface>\n";
}
if ($genimode eq $NO_GENI || $genimode eq $V_0_1 || $genimode eq $V_0_2)
{
if ($genimode eq $V_0_1 || $genimode eq $V_0_2) {
print " <bandwidth>$bw</bandwidth>\n";
print " <latency>$delay</latency>\n";
print " <packet_loss>$loss</packet_loss>\n";
......@@ -2617,10 +2660,7 @@ sub print_named_link_xml
}
my $i = 0;
for (; $i < $proto_count; ++$i) {
if ($genimode eq $NO_GENI) {
print " <link_type><type_name>" . $proto[$i]
. "</type_name></link_type>\n";
} elsif ($genimode eq $V_0_1 || $genimode eq $V_0_2) {
if ($genimode eq $V_0_1 || $genimode eq $V_0_2) {
print " <link_type type_name=\"" . $proto[$i] . "\" />\n";
} elsif ($genimode eq $V_2 || $genimode eq $V_3) {
print " <link_type name=\"" . $proto[$i] . "\" />\n";
......@@ -2629,6 +2669,46 @@ sub print_named_link_xml
print "</link>\n\n";
}
sub print_named_link_xml_plain
{
my $name = shift(@_);
my $source = shift(@_);
my $source_if = shift(@_);
my $dest = shift(@_);
my $dest_if = shift(@_);
my $bw = shift(@_);
my $delay = shift(@_);
my $loss = shift(@_);
my @proto = @{ shift(@_) };
my $is_interconnect = shift(@_);
my $proto_count = scalar(@proto);
my $source_urn = GeniHRN::GenerateInterface($OURDOMAIN, $source,
$source_if);
my $dest_urn = GeniHRN::GenerateInterface($OURDOMAIN, $dest,
$dest_if);
if (defined($MAINSITE) && $MAINSITE &&
(($source eq "instageni-nc7" && $source_if ne "eth5") ||
($dest eq "instageni-nc7" && $dest_if ne "eth5"))) {
return;
}
print "<link name=\"$name\">\n";
print " <source_interface><interface>\n";
print_interface_contents($source, $source_if);
print " </interface></source_interface>\n";
print " <destination_interface><interface>\n";
print_interface_contents($dest, $dest_if);
print " </interface></destination_interface>\n";
print " <bandwidth>$bw</bandwidth>\n";
print " <latency>$delay</latency>\n";
print " <packet_loss>$loss</packet_loss>\n";
my $i = 0;
for (; $i < $proto_count; ++$i) {
print " <link_type><type_name>" . $proto[$i]
. "</type_name></link_type>\n";
}
print "</link>\n\n";
}
sub print_interface
{
my ($node, $interfaceUrn) = @_;
......@@ -2664,8 +2744,10 @@ sub print_named_link
{
if (!$do_xml) {
print_named_link_ptop(@_, 0);
} elsif ($do_xml && $genimode eq $NO_GENI) {
print_named_link_xml_plain(@_, 0);
} elsif ($do_xml) {
print_named_link_xml(@_, 0);
print_named_link_xml_geni(@_, 0);
}
}
......@@ -2673,8 +2755,10 @@ sub print_named_interconnect
{
if (!$do_xml) {
print_named_link_ptop(@_, 1);
} elsif ($do_xml && $genimode eq $NO_GENI) {
print_named_link_xml_plain(@_, 1);
} elsif ($do_xml) {
print_named_link_xml(@_, 1);
print_named_link_xml_geni(@_, 1);
}
}
......@@ -2693,12 +2777,12 @@ sub print_type_relation
sub print_stitch_node
{
my ($node, $iface, $remote_iface_urn, $capacity,
my ($node, $iface_urn, $remote_iface_urn, $capacity,
$vlans, $vlan_will_translate) = @_;
my (undef, undef, $iface) = GeniHRN::ParseInterface($iface_urn);
my $node_urn = GeniHRN::Generate($OURDOMAIN, "node", $node);
my $port_urn = GeniHRN::Generate($OURDOMAIN, "stitchport",
$node . "//" . $iface);
my $iface_urn = GeniHRN::GenerateInterface($OURDOMAIN, $node, $iface);
# Capacity is in kilobits/sec but needs to be converted to bits/sec
my $bits = $capacity * 1000;
my $vlan_translate = "false";
......
......@@ -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