Commit 7c038e0e authored by Leigh B. Stoller's avatar Leigh B. Stoller

Add backlinks to the vinterfaces table. Rather jump through really silly

hoops to find the virt_lan and vlan that a vinterface is associated with,
lets just store a backpointer. It also makes my next round of changes for
lans easier to transition to.
parent 8dbbfbdd
......@@ -3200,6 +3200,8 @@ CREATE TABLE `vinterfaces` (
`iface` varchar(10) default NULL,
`rtabid` smallint(5) unsigned NOT NULL default '0',
`vnode_id` varchar(32) default NULL,
`virtlanidx` int(11) NOT NULL default '0',
`vlanid` int(11) NOT NULL default '0',
PRIMARY KEY (`node_id`,`unit`),
KEY `bynode` (`node_id`,`iface`),
KEY `type` (`type`)
......
#
# EMULAB-COPYRIGHT
# Copyright (c) 2003-2007 University of Utah and the Flux Group.
# Copyright (c) 2003-2008 University of Utah and the Flux Group.
# All rights reserved.
#
# Anytime you change database-create.sql, but sure to put any special
......@@ -4209,3 +4209,20 @@ last_net_act,last_cpu_act,last_ext_act);
insert into table_regex values \
('virt_lans','fixed_iface','text','redirect','default:tinytext',0,0,'');
4.138: Add backpointers from vinterfaces to its virt_lan and underlying vlan to
avoid problems upcoming cutover to new lans stuff. Besides, the
join hoops we jump through are kinda silly.
alter table vinterfaces add `virtlanidx` int(11) NOT NULL default '0';
alter table vinterfaces add `vlanid` int(11) NOT NULL default '0';
update vinterfaces as vi left join reserved as r on
if(vi.vnode_id is
null,r.node_id=vi.node_id,r.node_id=vi.vnode_id) left join
virt_lans as vl on vl.exptidx=r.exptidx and vl.vnode=r.vname
and vl.ip=vi.IP left join virt_lan_lans as vll on
vll.exptidx=vl.exptidx and vll.vname=vl.vname left join vlans
as vn on vn.exptidx=vl.exptidx and vn.virtual=vl.vname set
vi.virtlanidx=vll.idx,vi.vlanid=vn.id;
\ No newline at end of file
......@@ -329,6 +329,7 @@ my %virt_lans = ();
sub virtlanexists($) { return exists($virt_lans{$_[0]}); }
sub virtlanname($) { return $virt_lans{$_[0]}->{"VNAME"}; }
sub virtlanidx($) { return $virt_lans{$_[0]}->{"IDX"}; }
sub virtlanmembers($) { return @{$virt_lans{$_[0]}->{"MEMBERLIST"}}; }
sub virtlanmustdelay($) { return $virt_lans{$_[0]}->{"MUSTDELAY"}; }
sub virtlanemulated($) { return $virt_lans{$_[0]}->{"EMULATED"}; }
......@@ -3142,6 +3143,7 @@ sub nextipportnum($) {
# Vlan stuff.
#
my %vlantable = ();
my %lantovlan = ();
my $vlanid = 0;
#
......@@ -3158,6 +3160,7 @@ sub AddVlan($$$;$)
# Start a list of nodeports in the vlan.
if (! defined($vlantable{$lan})) {
$vlantable{$lan} = [$nodeportA];
$lantovlan{$lan} = $lan;
printdb " $lan, \[" . $nodeportA . "\]\n";
return;
}
......@@ -3184,6 +3187,7 @@ sub AddVlan($$$;$)
my $newid = "s$lan:" . $vlanid++;
$vlantable{$newid} = [$nodeportA, $nodeportB];
$lantovlan{$lan} = $newid;
printdb " $newid (SVLAN), \[$nodeportA, $nodeportB\]\n";
}
......@@ -3192,6 +3196,7 @@ sub AddVlan($$$;$)
# Generate a new vlan of two members.
#
$vlantable{$lan} = [$nodeportA, $nodeportB];
$lantovlan{$lan} = $lan;
printdb " $lan, \[$nodeportA, $nodeportB\]\n";
}
......@@ -3231,6 +3236,13 @@ sub UploadVlans()
push(@{$vlantable{$keyA}}, $memberB);
}
}
# Retarget lantovlan since the vlan was merged.
foreach my $lan (keys(%lantovlan)) {
my $vlan = $lantovlan{$lan};
if ($vlan eq $keyB) {
$lantovlan{$lan} = $keyA;
}
}
delete($vlantable{$keyB});
goto again;
}
......@@ -3251,11 +3263,28 @@ sub UploadVlans()
my $memberlist = join(" ", @{$vlantable{$lanid}});
printdb " $lan - $memberlist\n";
DBQueryFatal("insert into vlans (id,exptidx,pid,eid,virtual,members) ".
"values (0, '$experiment_idx', ".
" '$pid', '$eid', '$lan', '$memberlist')")
if (!$impotent);
if (!$impotent) {
my $query_result =
DBQueryFatal("insert into vlans ".
" (id,exptidx,pid,eid,virtual,members) ".
"values (0, '$experiment_idx', ".
" '$pid', '$eid', '$lan', '$memberlist')");
fatal("Failed to insert new vlan")
if (!$query_result);
my $newid = $query_result->insertid;
foreach my $virtlan (keys(%lantovlan)) {
if ($lantovlan{$virtlan} eq $lanid) {
my $vidx = virtlanidx($virtlan);
printdb("Update vinterfaces on $virtlan: ".
"$vidx -> $newid\n");
DBQueryFatal("update vinterfaces set vlanid='$newid' ".
"where virtlanidx='$vidx'")
}
}
}
}
}
......@@ -3319,6 +3348,7 @@ sub NewVirtIface($$$;$)
my $mask = virtlannetmask($lan);
my $rtabid = getrtabid($vnode, $pnode);
my $encap = virtlanencapstyle($lan);
my $vllidx = virtlanidx($lan);
my $vvnode;
my $newvif;
my $isvnode;
......@@ -3389,10 +3419,10 @@ sub NewVirtIface($$$;$)
my $query_result =
DBQueryFatal("insert into vinterfaces ".
"(node_id, unit, mac, IP, mask, type, iface, ".
" rtabid, vnode_id) ".
" rtabid, vnode_id, virtlanidx) ".
"values ('$pnode', 0, '$mac', '$ip', '$mask', '$type', ".
(defined($pport) ? "'$pport'" : "NULL") . ", ".
"'$rtabid', $vvnode)");
"'$rtabid', $vvnode, '$vllidx')");
my $newid = $query_result->insertid;
$newvif = $type . $newid;
......@@ -4054,13 +4084,16 @@ sub LoadVirtLans()
printdb "Loading virt_lans.\n";
my $query_result =
DBQueryFatal("select * from virt_lans ".
"where pid='$pid' and eid='$eid' ".
"order by vname,member");
DBQueryFatal("select v.*,vll.idx from virt_lans as v ".
"left join virt_lan_lans as vll on ".
" vll.exptidx=v.exptidx and vll.vname=v.vname ".
"where v.pid='$pid' and v.eid='$eid' ".
"order by v.vname,v.member");
while (my $rowref = $query_result->fetchrow_hashref()) {
my $vname = $rowref->{"vname"};
my $member = $rowref->{"member"};
my $vidx = $rowref->{"idx"};
my ($node, $port) = split(":",$member);
#
......@@ -4071,6 +4104,7 @@ sub LoadVirtLans()
$rec->{"MEMBERS"} = {};
$rec->{"MEMBERLIST"} = [];
$rec->{"VNAME"} = $vname;
$rec->{"IDX"} = $vidx;
$virt_lans{$vname} = $rec;
}
$virt_lans{$vname}->{"MEMBERS"}->{$member} = $rowref;
......
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2000-2007 University of Utah and the Flux Group.
* Copyright (c) 2000-2008 University of Utah and the Flux Group.
* All rights reserved.
*/
......@@ -1564,19 +1564,14 @@ COMMAND_PROTOTYPE(doifconfig)
* Find all the virtual interfaces.
*/
res = mydb_query("select v.unit,v.IP,v.mac,i.mac,v.mask,v.rtabid, "
" v.type,vl.vname,vll.idx,vn.tag "
" v.type,vll.vname,v.virtlanidx,vn.tag "
" from vinterfaces as v "
"left join interfaces as i on "
" i.node_id=v.node_id and i.iface=v.iface "
"left join virt_lans as vl on "
" vl.pid='%s' and vl.eid='%s' and "
" vl.vnode='%s' and vl.ip=v.IP "
"left join virt_lan_lans as vll on "
" vll.pid=vl.pid and vll.eid=vl.eid and "
" vll.vname=vl.vname "
" vll.idx=v.virtlanidx "
"left join vlans as vn on "
" vn.pid=vl.pid and vn.eid=vl.eid and "
" vn.virtual=vl.vname "
" vn.id=v.vlanid "
"where v.node_id='%s' and %s",
10, reqp->pid, reqp->eid, reqp->nickname,
reqp->pnodeid, buf);
......
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