Commit 67f0aa3e authored by Leigh Stoller's avatar Leigh Stoller

A fix to make sure that during an update, we do not assign a new sshd

port to a vnode. This can lead to confusion in the experiment if the
user does not reboot all the nodes. This fix turned out to be more
complicated then I thought, and I have not figured out how to apply it
to trafgens port numbers.
parent f08acc14
......@@ -4230,6 +4230,20 @@ sub SetPortRange($$)
DBQueryWarn("unlock tables");
return ($newlow, $newhigh);
}
sub GetPortRange($)
{
my ($self) = @_;
my $idx = $self->idx();
my $query_result =
DBQueryWarn("select low,high from ipport_ranges where exptidx=$idx");
return undef
if (!defined($query_result) || !$query_result->numrows);
my ($low,$high) = $query_result->fetchrow_array();
return ($low, $high);
}
#
# Reserve all of the shared BW we need. The vinterfaces table has
......
......@@ -4649,7 +4649,8 @@ sub AllocNodes($)
# Routing table id for each vnode on a pnode. Do not use 0.
$pnode->_rtabid(1);
# For assigning dynamic ports.
$pnode->_portnext(TBDB_LOWVPORT);
$pnode->_portarray(undef);
$pnode->_portlow(TBDB_LOWVPORT);
$pnode->_porthigh(TBDB_MAXVPORT);
# To avoid unitialized access.
$pnode->_reuse("used");
......@@ -4727,7 +4728,13 @@ sub AllocNodes($)
$vpnode->isremotenode() || $vpnode->_onsharednode()) {
my $pnodename = $self->solution_v2p()->{$vnodename};
my $pnode = $self->pnodes()->{$pnodename};
my $sshdport = nextipportnum($pnode);
my $default = 0;
if (exists($self->current_v2v()->{$vnodename})) {
$default = $vpnode->sshdport();
$self->printdb("Reusing port $default on $vpnode for sshd\n");
}
my $sshdport = nextipportnum($pnode, $default);
return -1
if ($sshdport < 0);
......@@ -4991,7 +4998,7 @@ sub AllocVirtNodes($)
return -1;
}
$self->solution_v2v()->{$virtual} = $virtphys;
$self->solution_v2v()->{$virtual} = $virtphys;
$self->printdb(" Mapping $virtual to $virtphys on $physical\n");
#
......@@ -7432,6 +7439,7 @@ sub array_diff($$)
sub SetPortRange($)
{
my ($self) = @_;
my ($newhigh, $newlow);
#
# See if any virtual nodes. If not, no need to do anything since
......@@ -7441,12 +7449,20 @@ sub SetPortRange($)
if (! scalar(keys(%{ $self->solution_v2v() })));
#
# Otherwise find a free slot in the table.
# Use existing port range when updating, or else find a free slot.
#
my ($newlow,$newhigh) =
$self->experiment()->SetPortRange($self->impotent() ||
$self->alloconly());
if ($self->updating()) {
($newlow,$newhigh) = $self->experiment()->GetPortRange();
}
else {
($newlow,$newhigh) =
$self->experiment()->SetPortRange($self->impotent() ||
$self->alloconly());
}
if (!defined($newlow)) {
tberror("Could not set the portrange!\n");
return -1;
}
$self->printdb("SetPortRange: $newlow,$newhigh\n");
#
......@@ -7462,9 +7478,11 @@ sub SetPortRange($)
my $pnodename = $self->solution_v2p()->{$vnodename};
my $pnode = $self->pnodes()->{$pnodename};
$vpnode->_portnext($newlow + 10);
$vpnode->_portarray(undef);
$vpnode->_portlow($newlow);
$vpnode->_porthigh($newhigh);
$pnode->_portnext($newlow + 10);
$pnode->_portarray(undef);
$pnode->_portlow($newlow);
$pnode->_porthigh($newhigh);
# We only set the vpnodes. tmcd sends that to the client.
......@@ -7480,16 +7498,48 @@ sub SetPortRange($)
# Bump and return the IP port number for a node. This is
# required for multiplexing virtual nodes on a physical node.
#
sub nextipportnum($)
sub nextipportnum($;$)
{
my ($pnode) = @_;
my $port = $pnode->_portnext();
my ($pnode, $default) = @_;
my $portarray = $pnode->_portarray();
my $port = 0;
if ($port >= $pnode->_porthigh()) {
if (!defined($portarray)) {
$portarray = [];
for (my $i = 0, my $port = $pnode->_portlow();
$i < $pnode->_porthigh() - $pnode->_portlow(); $i++,$port++) {
$portarray->[$i] = ($i < 10 ? $port : 0 - $port)
}
$pnode->_portarray($portarray);
}
if ($default) {
if ($default < $pnode->_portlow() || $default > $pnode->_porthigh()) {
tberror("Dynamic port $default out of range on $pnode!\n");
return -1;
}
my $idx = $default - $pnode->_portlow();
if ($portarray->[$idx] < 0) {
$port = $portarray->[$idx] = $default;
}
else {
tberror("Dynamic port $default already in use on $pnode!\n");
return -1;
}
}
else {
for (my $i = 0; $i < $pnode->_porthigh() - $pnode->_portlow(); $i++) {
if ($portarray->[$i] < 0) {
$port = 0 - $portarray->[$i];
$portarray->[$i] = $port;
last;
}
}
}
if (!$port) {
tberror("No more dynamic ports available for $pnode!\n");
return -1;
}
$pnode->_portnext($port + 1);
return $port;
}
......
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