From bb243a6803f0c69ac5d763fd7caf726ce5994b81 Mon Sep 17 00:00:00 2001 From: Mike Hibler Date: Fri, 26 Mar 2010 14:49:23 -0600 Subject: [PATCH] First crack at getting elabinelab attributes (options) from end to end. Add all the NS parsing and DB foo. --- db/Experiment.pm.in | 1 + db/VirtExperiment.pm.in | 3 ++- db/xmlconvert.in | 5 ++++- sql/database-create.sql | 15 +++++++++++++++ sql/updates/4/193 | 27 +++++++++++++++++++++++++++ tbsetup/ns2ir/firewall.tcl | 4 +--- tbsetup/ns2ir/sim.tcl.in | 16 +++++++++++++++- tbsetup/ns2ir/tb_compat.tcl.in | 30 ++++++++++++++++++++++++++---- 8 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 sql/updates/4/193 diff --git a/db/Experiment.pm.in b/db/Experiment.pm.in index 3d92c46ca..6aee2927a 100644 --- a/db/Experiment.pm.in +++ b/db/Experiment.pm.in @@ -108,6 +108,7 @@ my $EXPT_RESOURCESHOSED = 0; "event_groups", "virt_firewalls", "firewall_rules", + "elabinelab_attributes", "virt_tiptunnels", "ipsubnets"); diff --git a/db/VirtExperiment.pm.in b/db/VirtExperiment.pm.in index 4c6c4538d..42f5b13a2 100644 --- a/db/VirtExperiment.pm.in +++ b/db/VirtExperiment.pm.in @@ -1,7 +1,7 @@ #!/usr/bin/perl -wT # # EMULAB-COPYRIGHT -# Copyright (c) 2009 University of Utah and the Flux Group. +# Copyright (c) 2009, 2010 University of Utah and the Flux Group. # All rights reserved. # package VirtExperiment; @@ -69,6 +69,7 @@ my $debug = 0; "event_groups" => [ "group_name", "agent_name" ], "virt_firewalls" => [ "fwname", "type", "style" ], "firewall_rules" => [ "fwname", "ruleno", "rule" ], + "elabinelab_attributes" => [ "role", "attrkey", "order" ], "virt_tiptunnels" => [ "host", "vnode" ], "virt_parameters" => [ "name", "value" ], ); diff --git a/db/xmlconvert.in b/db/xmlconvert.in index f7534e6f7..78e4754f5 100644 --- a/db/xmlconvert.in +++ b/db/xmlconvert.in @@ -2,7 +2,7 @@ # # EMULAB-COPYRIGHT -# Copyright (c) 2000-2009 University of Utah and the Flux Group. +# Copyright (c) 2000-2010 University of Utah and the Flux Group. # All rights reserved. # @@ -110,6 +110,9 @@ my %virtual_tables = "firewall_rules" => { rows => undef, tag => "firewall_rules", row => "firewall_rule"}, + "elabinelab_attributes" => { rows => undef, + tag => "elabinelab_attributes", + row => "attribute"}, "virt_tiptunnels" => { rows => undef, tag => "tiptunnels", row => "tiptunnel"}, diff --git a/sql/database-create.sql b/sql/database-create.sql index 985ebc685..0d84e4e12 100644 --- a/sql/database-create.sql +++ b/sql/database-create.sql @@ -421,6 +421,21 @@ CREATE TABLE `deltas` ( PRIMARY KEY (`delta_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; +-- +-- Table structure for table `elabinelab_attributes` +-- + +CREATE TABLE `elabinelab_attributes` ( + `pid` varchar(12) NOT NULL default '', + `eid` varchar(32) NOT NULL default '', + `exptidx` int(11) NOT NULL default '0', + `role` enum('boss','router','ops','fs','node') NOT NULL default 'node', + `attrkey` varchar(32) NOT NULL default '', + `attrvalue` tinytext NOT NULL, + `order` smallint(5) unsigned NOT NULL default '0', + PRIMARY KEY (`exptidx`,`role`,`attrkey`,`order`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + -- -- Table structure for table `elabinelab_vlans` -- diff --git a/sql/updates/4/193 b/sql/updates/4/193 new file mode 100644 index 000000000..104ceb2ce --- /dev/null +++ b/sql/updates/4/193 @@ -0,0 +1,27 @@ +# +# Add the elabinelab_attributes table. +# +use strict; +use libdb; + +sub DoUpdate($$$) +{ + my ($dbhandle, $dbname, $version) = @_; + + if (!DBTableExists("elabinelab_attributes")) { + DBQueryFatal("CREATE TABLE `elabinelab_attributes` ( ". + " `pid` varchar(12) NOT NULL default '', ". + " `eid` varchar(32) NOT NULL default '', ". + " `exptidx` int(11) NOT NULL default '0', ". + " `role` enum('boss','router','ops','fs','node') NOT NULL default 'node', ". + " `attrkey` varchar(32) NOT NULL default '', ". + " `attrvalue` tinytext NOT NULL, ". + " `order` smallint(5) unsigned NOT NULL default '0', ". + " PRIMARY KEY (`exptidx`,`role`,`attrkey`,`order`) ". + ") ENGINE=MyISAM DEFAULT CHARSET=latin1"); + } + + # Initialize new table. + return 0; +} +1; diff --git a/tbsetup/ns2ir/firewall.tcl b/tbsetup/ns2ir/firewall.tcl index 4e7d88cbe..650d12ee9 100644 --- a/tbsetup/ns2ir/firewall.tcl +++ b/tbsetup/ns2ir/firewall.tcl @@ -1,7 +1,7 @@ # -*- tcl -*- # # EMULAB-COPYRIGHT -# Copyright (c) 2004, 2005 University of Utah and the Flux Group. +# Copyright (c) 2004, 2005, 2010 University of Utah and the Flux Group. # All rights reserved. # @@ -148,8 +148,6 @@ Firewall instproc child-of {pfw} { # updatedb DB Firewall instproc updatedb {DB} { - var_import ::GLOBALS::pid - var_import ::GLOBALS::eid $self instvar rules $self instvar sim $self instvar type diff --git a/tbsetup/ns2ir/sim.tcl.in b/tbsetup/ns2ir/sim.tcl.in index 8a20a8a1c..b673f891d 100644 --- a/tbsetup/ns2ir/sim.tcl.in +++ b/tbsetup/ns2ir/sim.tcl.in @@ -1,7 +1,7 @@ # -*- tcl -*- # # EMULAB-COPYRIGHT -# Copyright (c) 2000-2007 University of Utah and the Flux Group. +# Copyright (c) 2000-2007, 2010 University of Utah and the Flux Group. # All rights reserved. # @@ -398,6 +398,7 @@ Simulator instproc run {} { var_import ::GLOBALS::elabinelab_eid var_import ::GLOBALS::elabinelab_cvstag var_import ::GLOBALS::elabinelab_singlenet + var_import ::TBCOMPAT::elabinelab_attributes var_import ::GLOBALS::security_level var_import ::GLOBALS::explicit_firewall var_import ::GLOBALS::sourcefile_list @@ -700,6 +701,19 @@ Simulator instproc run {} { $self spitxml_data "external_sourcefiles" [list "pathname" ] [list $sourcefile ] } + if {$elab_in_elab} { + foreach attr $elabinelab_attributes { + set fields [list "role" "attrkey" "attrvalue" "order"] + set values [split $attr ","] + + # XXX this shouldn't be needed + lappend fields [list "pid" "eid"] + lappend values [list $pid $eid] + + $self spitxml_data "elabinelab_attributes" $fields $values + } + } + $self spitxml_finish } diff --git a/tbsetup/ns2ir/tb_compat.tcl.in b/tbsetup/ns2ir/tb_compat.tcl.in index 0ba6f1b3a..741e9cbb2 100644 --- a/tbsetup/ns2ir/tb_compat.tcl.in +++ b/tbsetup/ns2ir/tb_compat.tcl.in @@ -132,7 +132,7 @@ namespace eval TBCOMPAT { # Elabinelab attribute stuff. variable elabinelab_attributes - array set elabinelab_attributes {} + set elabinelab_attributes {} variable EINEROLE {^(boss|ops|fs|router)$} variable EINEKEY {^(\w[-\w\.]+)$} variable EINEVALUE {^([-\w\s\.\,\/]+)$} @@ -1760,8 +1760,14 @@ proc tb-elabinelab-singlenet {args} { # tb-unset-elabinelab-attribute # proc tb-set-elabinelab-attribute {role key value {order 0}} { + var_import ::TBCOMPAT::EINEROLE; + var_import ::TBCOMPAT::EINEKEY; + var_import ::TBCOMPAT::EINEVALUE; + var_import ::TBCOMPAT::EINEORDER; + var_import ::TBCOMPAT::elabinelab_attributes; + if {[regexp $EINEROLE $role] == 0} { - perror "\[tb-set-elabinelab-attribute] - $role is not a valid elabinelab role" + perror "\[tb-set-elabinelab-attribute] - \"$role\" is not a valid elabinelab role" return } if {[regexp $EINEKEY $key] == 0} { @@ -1773,13 +1779,29 @@ proc tb-set-elabinelab-attribute {role key value {order 0}} { return } if {[regexp $EINEORDER $order] == 0} { - perror "\[tb-set-elabinelab-attribute] - $order is not a valid elabinelab order" + perror "\[tb-set-elabinelab-attribute] - \"$order\" is not a valid elabinelab order" return } - + lappend elabinelab_attributes "$role,$key,$value,$order" } proc tb-unset-elabinelab-attribute {role key} { + var_import ::TBCOMPAT::EINEROLE; + var_import ::TBCOMPAT::EINEKEY; + var_import ::TBCOMPAT::elabinelab_attributes; + + if {[regexp $EINEROLE $role] == 0} { + perror "\[tb-unset-elabinelab-attribute] - \"$role\" is not a valid elabinelab role" + return + } + if {[regexp $EINEKEY $key] == 0} { + perror "\[tb-unset-elabinelab-attribute] - \"$key\" is not a valid elabinelab key" + return + } + while {[lsearch -glob $elabinelab_attributes "$role,$key,*"] > 0} { + set i [lsearch -glob $elabinelab_attributes "$role,$key,*"] + set elabinelab_attributes [lreplace $elabinelab_attributes $i $i] + } } # -- GitLab