diff options
author | vmaffione <[email protected]> | 2017-04-19 17:28:16 +0000 |
---|---|---|
committer | vmaffione <[email protected]> | 2017-04-19 17:28:16 +0000 |
commit | a4879434ae2fc47f1514d1af180ed2191be7cb53 (patch) | |
tree | 4c2a4be14e1aa82cacc6041b28054478087b2284 | |
parent | 558682e5b59e1a62b92368a37d90cd2249e313c3 (diff) | |
parent | 91d22038f85b1f8a9e20772d5f6a6f7ad37963f2 (diff) | |
download | rumba-a4879434ae2fc47f1514d1af180ed2191be7cb53.tar.gz rumba-a4879434ae2fc47f1514d1af180ed2191be7cb53.zip |
Merge branch 'irati-issues' into 'master'
Fixes for issues #4 and #5 (irati plugin and vlans)
See merge request !34
-rw-r--r-- | rumba/prototypes/irati.py | 68 | ||||
-rw-r--r-- | rumba/ssh_support.py | 10 | ||||
-rw-r--r-- | rumba/testbeds/qemu.py | 14 |
3 files changed, 57 insertions, 35 deletions
diff --git a/rumba/prototypes/irati.py b/rumba/prototypes/irati.py index 1965069..e248720 100644 --- a/rumba/prototypes/irati.py +++ b/rumba/prototypes/irati.py @@ -31,6 +31,9 @@ import rumba.prototypes.irati_templates as irati_templates # An experiment over the IRATI implementation +from rumba import ssh_support + + class Experiment(mod.Experiment): @staticmethod @@ -45,6 +48,7 @@ class Experiment(mod.Experiment): mod.Experiment.__init__(self, testbed, nodes) self.manager = False self.conf_files = None + self.shim2vlan = {} if self.testbed.username == 'root': self.sudo = self.fake_sudo @@ -93,6 +97,7 @@ class Experiment(mod.Experiment): print("irati: configuration files generated for all nodes") self.bootstrap_network() print("irati: IPCPs created and enrolled on all nodes") + input('Press ENTER to quit') def process_node(self, node): """ @@ -102,6 +107,14 @@ class Experiment(mod.Experiment): :return: """ name = node.name + + for ipcp in node.ipcps: + if isinstance(ipcp, mod.ShimEthIPCP): + if_name = ipcp.ifname + vlan = self.shim2vlan[ipcp.dif.name] + ssh_support.setup_vlan(self.testbed, node, + vlan, if_name) + gen_files_conf = self.conf_files[node] + ['da.map'] dir_path = os.path.dirname(os.path.abspath(__file__)) gen_files_bin = 'enroll.py' @@ -124,16 +137,12 @@ class Experiment(mod.Experiment): 'installpath': '/usr', 'verb': 'DBG', 'ipcmcomps': ipcm_components} - try: - # TODO: watch out for empty path... - ssh.copy_paths_to_testbed(self.testbed, - node.ssh_config, - gen_files, - '') - except subprocess.CalledProcessError as e: - raise Exception(str(e)) - # TODO: review ssh opts through ssh support + # TODO: watch out for empty path... + ssh.copy_paths_to_testbed(self.testbed, + node.ssh_config, + gen_files, + '') cmds = [self.sudo('hostname %(name)s' % format_args), self.sudo('chmod a+rw /dev/irati'), @@ -141,8 +150,6 @@ class Experiment(mod.Experiment): self.sudo('mv %(genfilesbin)s /usr/bin') % format_args, self.sudo('chmod a+x /usr/bin/enroll.py') % format_args] - # TODO: is the port up on the VM at this point? - cmds += [self.sudo('modprobe rina-default-plugin'), self.sudo('%(installpath)s/bin/ipcm -a \"%(ipcmcomps)s\" ' '-c /etc/%(name)s.ipcm.conf -l %(verb)s &> log &' @@ -168,7 +175,7 @@ class Experiment(mod.Experiment): subprocess.check_call('sleep 2'. split()) # Important! - e_args = {'ldif': e['lower_dif'].name, + e_args = {'ldif': self.dif_name(e['lower_dif']), 'dif': e['dif'].name, 'name': e['enrollee'].name, 'o_name': e['enroller'].name} @@ -187,6 +194,12 @@ class Experiment(mod.Experiment): e['enrollee'].ssh_config, cmd) + def dif_name(self, dif): + try: + return str(self.shim2vlan[dif.name]) + except KeyError: + return dif.name + def write_conf(self): """Write the configuration files""" # Constants and initializations @@ -197,10 +210,22 @@ class Experiment(mod.Experiment): mgmt_dif_name = 'NMS' conf_files = {} # dict of per-nod conf files + # Translating Shim Eth difs to vlan tags. + next_vlan = 10 + for dif in self.dif_ordering: + if isinstance(dif, mod.ShimEthDIF): + try: + vlan = int(dif.name) + self.shim2vlan[dif.name] = vlan + except ValueError: + vlan = next_vlan + next_vlan += 10 + self.shim2vlan[dif.name] = vlan + # TODO: what format are the mappings registered in? Is this ok? app_mappings = [] for node in self.nodes: - app_mappings += [{'name': app, 'dif': dif.name} + app_mappings += [{'name': app, 'dif': self.dif_name(dif)} for app in node.registrations for dif in node.registrations[app]] @@ -262,16 +287,19 @@ class Experiment(mod.Experiment): for ipcp in node.ipcps: # type: mod.ShimEthIPCP if isinstance(ipcp, mod.ShimEthIPCP): shim = ipcp2shim_map[ipcp.name] # type: mod.ShimEthDIF + shim_name = self.dif_name(shim) ipcmconf["ipcProcessesToCreate"].append({ "apName": "eth.%s.IPCP" % ipcp.name, "apInstance": "1", - "difName": shim.name + "difName": shim_name }) - template_file_name = self.conf_dir('shimeth.%s.%s.dif' - % (node.name, shim.name)) + + template_file_name = self.conf_dir( + 'shimeth.%s.%s.dif' + % (node.name, shim_name)) ipcmconf["difConfigurations"].append({ - "name": shim.name, + "name": shim_name, "template": os.path.basename(template_file_name) }) @@ -285,7 +313,8 @@ class Experiment(mod.Experiment): indent=4, sort_keys=True)) fout.close() conf_files.setdefault(node, []).append( - 'shimeth.%s.%s.dif' % (node.name, shim.name)) + 'shimeth.%s.%s.dif' + % (node.name, shim_name)) # Run over dif_ordering array, to make sure each IPCM config has # the correct ordering for the ipcProcessesToCreate list of operations. @@ -310,7 +339,8 @@ class Experiment(mod.Experiment): "difsToRegisterAt": []} for lower_dif in node.dif_registrations[dif]: # type: mod.DIF - normal_ipcp["difsToRegisterAt"].append(lower_dif.name) + normal_ipcp["difsToRegisterAt"].append( + self.dif_name(lower_dif)) ipcmconf["ipcProcessesToCreate"].append(normal_ipcp) diff --git a/rumba/ssh_support.py b/rumba/ssh_support.py index 0179c5d..d41eacb 100644 --- a/rumba/ssh_support.py +++ b/rumba/ssh_support.py @@ -52,7 +52,7 @@ def execute_commands(testbed, ssh_config, commands, time_out=3): ''' ssh_client = get_ssh_client() - if ssh_config.proxycommand != None: + if ssh_config.proxycommand is not None: proxy = paramiko.ProxyCommand(ssh_config.proxycommand) else: proxy = None @@ -96,7 +96,7 @@ def execute_command(testbed, ssh_config, command, time_out=3): @return: stdout resulting from the command ''' o = execute_commands(testbed, ssh_config, [command], time_out) - if o != None: + if o is not None: return o @@ -112,7 +112,7 @@ def copy_file_to_testbed(testbed, ssh_config, text, file_name): ''' ssh_client = get_ssh_client() - if ssh_config.proxycommand != None: + if ssh_config.proxycommand is not None: proxy = paramiko.ProxyCommand(ssh_config.proxycommand) else: proxy = None @@ -214,9 +214,7 @@ def setup_vlan(testbed, node, vlan_id, int_name): args = {'ifname': str(int_name), 'vlan': str(vlan_id)} - cmds = [sudo("ip link set %(ifname)s up" - % args), - sudo("ip link add link %(ifname)s name " + cmds = [sudo("ip link add link %(ifname)s name " "%(ifname)s.%(vlan)s type vlan id %(vlan)s" % args), sudo("ifconfig %(ifname)s.%(vlan)s up" diff --git a/rumba/testbeds/qemu.py b/rumba/testbeds/qemu.py index d998625..40899d7 100644 --- a/rumba/testbeds/qemu.py +++ b/rumba/testbeds/qemu.py @@ -95,16 +95,10 @@ class Testbed(mod.Testbed): node.ssh_config, 'mac2ifname ' + mac) ipcp.ifname = output - try: - vlan = int(port['shim'].name) - except ValueError: - vlan = assigned_vlan.get(port['shim'].name, None) - if vlan is None: - vlan = next_vlan - next_vlan += 10 - assigned_vlan[port['shim'].name] = vlan - ssh_support.setup_vlan(self, node, - vlan, ipcp.ifname) + ssh_support.execute_command( + self, node.ssh_config, + "ip link set %(ifname)s up" + % {'ifname': ipcp.ifname}) def swap_in(self, experiment): """ |