From fbbc602d9efd9f88ce35b09c02f1226881c32bfb Mon Sep 17 00:00:00 2001 From: Marco Capitani Date: Fri, 14 Apr 2017 11:57:47 +0200 Subject: Bugfixing for IRATI prototype and QEMU testbed --- rumba/prototypes/enroll.py | 117 ++++++++++++++ rumba/prototypes/irati.py | 3 +- rumba/prototypes/irati_rsa | 27 ++++ rumba/prototypes/irati_templates.py | 313 +++++++++++++++++++----------------- rumba/testbeds/qemu.py | 27 ++-- 5 files changed, 326 insertions(+), 161 deletions(-) create mode 100755 rumba/prototypes/enroll.py create mode 100644 rumba/prototypes/irati_rsa (limited to 'rumba') diff --git a/rumba/prototypes/enroll.py b/rumba/prototypes/enroll.py new file mode 100755 index 0000000..458736a --- /dev/null +++ b/rumba/prototypes/enroll.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python + +# +# Author: Vincenzo Maffione +# + +import argparse +import socket +import time +import re + +def printalo(byt): + print(repr(byt).replace('\\n', '\n')) + + +def get_response(s): + data = bytes() + while 1: + data += s.recv(1024) + lines = str(data).replace('\\n', '\n').split('\n') + #print(lines) + if lines[-1].find("IPCM") != -1: + return lines[:len(lines)-1] + + +description = "Python script to enroll IPCPs" +epilog = "2016 Vincenzo Maffione " + +argparser = argparse.ArgumentParser(description = description, + epilog = epilog) +argparser.add_argument('--ipcm-conf', help = "Path to the IPCM configuration file", + type = str, required = True) +argparser.add_argument('--enrollee-name', help = "Name of the enrolling IPCP", + type = str, required = True) +argparser.add_argument('--dif', help = "Name of DIF to enroll to", + type = str, required = True) +argparser.add_argument('--lower-dif', help = "Name of the lower level DIF", + type = str, required = True) +argparser.add_argument('--enroller-name', help = "Name of the remote neighbor IPCP to enroll to", + type = str, required = True) +args = argparser.parse_args() + +socket_name = None + +fin = open(args.ipcm_conf, 'r') +while 1: + line = fin.readline() + if line == '': + break + + m = re.search(r'"(\S+ipcm-console.sock)', line) + if m != None: + socket_name = m.group(1) + break +fin.close() + +if socket_name == None: + print('Cannot find %s' % (socket_name)) + quit(1) + +s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + +connected = False +trials = 0 +while trials < 4: + try: + s.connect(socket_name) + connected = True + break + except: + pass + trials += 1 + time.sleep(1) + +if connected: + try: + # Receive the banner + get_response(s) + + # Send the IPCP list command + cmd = 'list-ipcps\n' + s.sendall(bytes(cmd, 'ascii')) + + # Get the list of IPCPs and parse it to look for the enroller ID + print('Looking up identifier for IPCP %s' % args.enrollee_name) + lines = get_response(s) + print(lines) + enrollee_id = None + for line in lines: + rs = r'^\s*(\d+)\s*\|\s*' + args.enrollee_name.replace('.', '\\.') + m = re.match(rs, line) + if m != None: + enrollee_id = m.group(1) + + if enrollee_id == None: + print('Could not find the ID of enrollee IPCP %s' \ + % args.enrollee_name) + raise Exception() + + # Send the enroll command + cmd = 'enroll-to-dif %s %s %s %s 1\n' \ + % (enrollee_id, args.dif, args.lower_dif, args.enroller_name) + print(cmd) + + s.sendall(bytes(cmd, 'ascii')) + + # Get the enroll command answer + lines = get_response(s) + print(lines) + except: + s.close() + raise + +else: + print('Failed to connect to "%s"' % socket_name) + +s.close() diff --git a/rumba/prototypes/irati.py b/rumba/prototypes/irati.py index 44eadb0..dd7086e 100644 --- a/rumba/prototypes/irati.py +++ b/rumba/prototypes/irati.py @@ -114,7 +114,8 @@ class Experiment(mod.Experiment): gen_files = ' '.join([gen_files_conf, gen_files_bin_full]) sshopts = ('-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' - ' -o IdentityFile=buildroot/irati_rsa') + ' -o IdentityFile=%s' + % (os.path.join(dir_path, 'irati_rsa',))) format_args = {'name': name, 'ssh': node.ssh_config.port, 'username': self.testbed.username, diff --git a/rumba/prototypes/irati_rsa b/rumba/prototypes/irati_rsa new file mode 100644 index 0000000..8119a76 --- /dev/null +++ b/rumba/prototypes/irati_rsa @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAAKCAQEAyfuwhIYMa2pCcbLYfeDblxaXNxLcJS8aJFjpwPVdXQ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jKvV9ChWbDVjnSXkA4J2MhRRnqne3RbIK/GfbHSy +ysn46iy9taXbRhCTn3JaeT/MIbne9YoqP7jdD+6glbQaNQrdpQ+8ec4Uf7vjF6IZ +a+vMrzewsGvntTfs1VbAPQKBgQCl+8LRkrISQnzzEOfFFWtoYIUENxxgFxCiadhb +3k2Vhmm32EKr+Xv18vv3pjd7se1xo6UbBD/phfiHatZMR8Ahjpwh3q7Qpe1uXaz8 +ZNt/HVMW7BADF5HyJB7J/T1ivjzaZVj1VWlVC24XIfHQSTjs9rfFqRRH6ya/H75H +apS23QKBgCj4TWnRtMsEaZZIamgzxMw1eUdYH27ZeaG0Do+hZ1XGixq4CWxCqxVg +nwbXRkRYwqI+2zzsaeNji4OX6wJdO7lZntuk4v6O0WeY9aJxGaLkYaRk5eF2TLyW +IVQbpcC/q1fnCo3HjWxR3w8QYmsQi97AC7xUMsjqwntIGV1QrR7s +-----END RSA PRIVATE KEY----- diff --git a/rumba/prototypes/irati_templates.py b/rumba/prototypes/irati_templates.py index 0f3ef05..b8d9788 100644 --- a/rumba/prototypes/irati_templates.py +++ b/rumba/prototypes/irati_templates.py @@ -35,189 +35,197 @@ da_map_base = { # Template for a normal DIF configuration file -normal_dif_base = { - "difType" : "normal-ipc", - "dataTransferConstants" : { - "addressLength" : 2, - "cepIdLength" : 2, - "lengthLength" : 2, - "portIdLength" : 2, - "qosIdLength" : 2, - "rateLength" : 4, - "frameLength" : 4, - "sequenceNumberLength" : 4, - "ctrlSequenceNumberLength" : 4, - "maxPduSize" : 10000, - "maxPduLifetime" : 60000 +normal_dif_base = { + "difType": "normal-ipc", + "dataTransferConstants": { + "addressLength": 2, + "cepIdLength": 2, + "lengthLength": 2, + "portIdLength": 2, + "qosIdLength": 2, + "rateLength": 4, + "frameLength": 4, + "sequenceNumberLength": 4, + "ctrlSequenceNumberLength": 4, + "maxPduSize": 10000, + "maxPduLifetime": 60000 }, - "qosCubes" : [ { - "name" : "unreliablewithflowcontrol", - "id" : 1, - "partialDelivery" : False, - "orderedDelivery" : True, - "efcpPolicies" : { - "dtpPolicySet" : { - "name" : "default", - "version" : "0" + "qosCubes": [ + { + "name": "unreliablewithflowcontrol", + "id": 1, + "partialDelivery": False, + "orderedDelivery": True, + "efcpPolicies": { + "dtpPolicySet": { + "name": "default", + "version": "0" }, - "initialATimer" : 0, - "dtcpPresent" : True, - "dtcpConfiguration" : { - "dtcpPolicySet" : { - "name" : "default", - "version" : "0" + "initialATimer": 0, + "dtcpPresent": True, + "dtcpConfiguration": { + "dtcpPolicySet": { + "name": "default", + "version": "0" }, - "rtxControl" : False, - "flowControl" : True, - "flowControlConfig" : { - "rateBased" : False, - "windowBased" : True, - "windowBasedConfig" : { - "maxClosedWindowQueueLength" : 10, - "initialCredit" : 200 + "rtxControl": False, + "flowControl": True, + "flowControlConfig": { + "rateBased": False, + "windowBased": True, + "windowBasedConfig": { + "maxClosedWindowQueueLength": 10, + "initialCredit": 200 } } } } }, { - "name" : "reliablewithflowcontrol", - "id" : 2, - "partialDelivery" : False, - "orderedDelivery" : True, + "name": "reliablewithflowcontrol", + "id": 2, + "partialDelivery": False, + "orderedDelivery": True, "maxAllowableGap": 0, - "efcpPolicies" : { - "dtpPolicySet" : { - "name" : "default", - "version" : "0" + "efcpPolicies": { + "dtpPolicySet": { + "name": "default", + "version": "0" }, - "initialATimer" : 0, - "dtcpPresent" : True, - "dtcpConfiguration" : { - "dtcpPolicySet" : { - "name" : "default", - "version" : "0" + "initialATimer": 0, + "dtcpPresent": True, + "dtcpConfiguration": { + "dtcpPolicySet": { + "name": "default", + "version": "0" }, - "rtxControl" : True, - "rtxControlConfig" : { - "dataRxmsNmax" : 5, - "initialRtxTime" : 1000 + "rtxControl": True, + "rtxControlConfig": { + "dataRxmsNmax": 5, + "initialRtxTime": 1000 }, - "flowControl" : True, - "flowControlConfig" : { - "rateBased" : False, - "windowBased" : True, - "windowBasedConfig" : { - "maxClosedWindowQueueLength" : 10, - "initialCredit" : 200 + "flowControl": True, + "flowControlConfig": { + "rateBased": False, + "windowBased": True, + "windowBasedConfig": { + "maxClosedWindowQueueLength": 10, + "initialCredit": 200 } } } } - } ], + } + ], "knownIPCProcessAddresses": [], - "addressPrefixes" : [ { - "addressPrefix" : 0, - "organization" : "N.Bourbaki" + "addressPrefixes": [ + { + "addressPrefix": 0, + "organization": "N.Bourbaki" }, { - "addressPrefix" : 16, - "organization" : "IRATI" - } ], - - "rmtConfiguration" : { - "pffConfiguration" : { - "policySet" : { - "name" : "default", - "version" : "0" + "addressPrefix": 16, + "organization": "IRATI" + } + ], + + "rmtConfiguration": { + "pffConfiguration": { + "policySet": { + "name": "default", + "version": "0" } }, - "policySet" : { - "name" : "default", - "version" : "1" + "policySet": { + "name": "default", + "version": "1" } }, - "enrollmentTaskConfiguration" : { - "policySet" : { - "name" : "default", - "version" : "1", - "parameters" : [ { - "name" : "enrollTimeoutInMs", - "value" : "10000" - }, { - "name" : "watchdogPeriodInMs", - "value" : "30000" - }, { - "name" : "declaredDeadIntervalInMs", - "value" : "120000" - }, { - "name" : "neighborsEnrollerPeriodInMs", - "value" : "0" - }, { - "name" : "maxEnrollmentRetries", - "value" : "0" - } ] + "enrollmentTaskConfiguration": { + "policySet": { + "name": "default", + "version": "1", + "parameters": [ + { + "name": "enrollTimeoutInMs", + "value": "10000" + }, { + "name": "watchdogPeriodInMs", + "value": "30000" + }, { + "name": "declaredDeadIntervalInMs", + "value": "120000" + }, { + "name": "neighborsEnrollerPeriodInMs", + "value": "0" + }, { + "name": "maxEnrollmentRetries", + "value": "0" + } + ] } - }, + }, - "flowAllocatorConfiguration" : { - "policySet" : { - "name" : "default", - "version" : "1" + "flowAllocatorConfiguration": { + "policySet": { + "name": "default", + "version": "1" } }, - "namespaceManagerConfiguration" : { - "policySet" : { - "name" : "default", - "version" : "1" + "namespaceManagerConfiguration": { + "policySet": { + "name": "default", + "version": "1" } }, - "securityManagerConfiguration" : { - "policySet" : { - "name" : "default", - "version" : "1" + "securityManagerConfiguration": { + "policySet": { + "name": "default", + "version": "1" } }, - "resourceAllocatorConfiguration" : { - "pduftgConfiguration" : { - "policySet" : { - "name" : "default", - "version" : "0" + "resourceAllocatorConfiguration": { + "pduftgConfiguration": { + "policySet": { + "name": "default", + "version": "0" } } }, - "routingConfiguration" : { - "policySet" : { - "name" : "link-state", - "version" : "1", - "parameters" : [ { - "name" : "objectMaximumAge", - "value" : "10000" - },{ - "name" : "waitUntilReadCDAP", - "value" : "5001" - },{ - "name" : "waitUntilError", - "value" : "5001" - },{ - "name" : "waitUntilPDUFTComputation", - "value" : "103" - },{ - "name" : "waitUntilFSODBPropagation", - "value" : "101" - },{ - "name" : "waitUntilAgeIncrement", - "value" : "997" - },{ - "name" : "routingAlgorithm", - "value" : "Dijkstra" - }] + "routingConfiguration": { + "policySet": { + "name": "link-state", + "version": "1", + "parameters": [ + { + "name": "objectMaximumAge", + "value": "10000" + }, { + "name": "waitUntilReadCDAP", + "value": "5001" + }, { + "name": "waitUntilError", + "value": "5001" + }, { + "name": "waitUntilPDUFTComputation", + "value": "103" + }, { + "name": "waitUntilFSODBPropagation", + "value": "101" + }, { + "name": "waitUntilAgeIncrement", + "value": "997" + }, { + "name": "routingAlgorithm", + "value": "Dijkstra" + } + ] } } } @@ -237,10 +245,12 @@ def ps_set(d, k, v, parms): d[k]["parameters"][i]["value"] = value break else: - d[k]["parameters"].append({ 'name': name, 'value': value }) + d[k]["parameters"].append({'name': name, 'value': value}) elif len(parms) > 0: - d[k]["parameters"] = [ { 'name': p.split('=')[0], 'value': p.split('=')[1]} for p in parms ] + d[k]["parameters"] = [ + {'name': p.split('=')[0], 'value': p.split('=')[1]} + for p in parms] d[k]["name"] = v @@ -252,7 +262,8 @@ def dtp_ps_set(d, v, parms): def dtcp_ps_set(d, v, parms): for i in range(len(d["qosCubes"])): - ps_set(d["qosCubes"][i]["efcpPolicies"]["dtcpConfiguration"], "dtcpPolicySet", v, parms) + ps_set(d["qosCubes"][i]["efcpPolicies"]["dtcpConfiguration"], + "dtcpPolicySet", v, parms) policy_translator = { @@ -267,7 +278,8 @@ policy_translator = { d["namespaceManagerConfiguration"], "policySet", v, p), 'security-manager': lambda d, v, p: ps_set( d["securityManagerConfiguration"], "policySet", v, p), - 'routing': lambda d, v, p: ps_set(d["routingConfiguration"], "policySet", v, p), + 'routing': lambda d, v, p: ps_set( + d["routingConfiguration"], "policySet", v, p), 'resource-allocator.pduftg': lambda d, v, p: ps_set( d["resourceAllocatorConfiguration"], "policySet", v, p), 'efcp.*.dtcp': None, @@ -308,7 +320,7 @@ def translate_security_path(d, path, ps, parms): ps_set(d["default"], tr[component], ps, parms) - else: # profile is the name of a DIF + else: # profile is the name of a DIF if "specific" not in d: d["specific"] = [] j = -1 @@ -317,14 +329,14 @@ def translate_security_path(d, path, ps, parms): j = i break - if j == -1: # We need to create an entry for the new DIF - d["specific"].append({"underlyingDIF" : profile + ".DIF"}) + if j == -1: # We need to create an entry for the new DIF + d["specific"].append({"underlyingDIF": profile + ".DIF"}) ps_set(d["specific"][j], tr[component], ps, parms) def translate_policy(difconf, path, ps, parms): - if path =='efcp.*.dtcp': + if path == 'efcp.*.dtcp': dtcp_ps_set(difconf, ps, parms) elif path == 'efcp.*.dtp': @@ -335,4 +347,3 @@ def translate_policy(difconf, path, ps, parms): else: policy_translator[path](difconf, ps, parms) - diff --git a/rumba/testbeds/qemu.py b/rumba/testbeds/qemu.py index d3e1698..8ccc704 100644 --- a/rumba/testbeds/qemu.py +++ b/rumba/testbeds/qemu.py @@ -76,6 +76,8 @@ class Testbed(mod.Testbed): results_queue.put("Command chain ran with %d errors" % errors) def recover_if_names(self, experiment): + next_vlan = 10 + assigned_vlan = {} for node in experiment.nodes: for ipcp in node.ipcps: if isinstance(ipcp, mod.ShimEthIPCP): @@ -88,16 +90,20 @@ class Testbed(mod.Testbed): mac = '00:0a:0a:0a:%02x:%02x' % (vm_id, port_id) print('DEBUG: recovering ifname for port: ' + port['tap_id'] + '.') - output = ssh_support.return_commands( + output = ssh_support.execute_command( self, node.ssh_config, - ['mac2ifname ' + mac]) - print('DEBUG: output is %s' % output) - if not hasattr(output, '__len__') or len(output) != 1: - raise Exception("Could not retrieve ifname for ipcp %s." - % ipcp.name) - ipcp.ifname = output[0] - args = {'vlan': int(port['shim'].name), 'port': ipcp.ifname} + '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 + args = {'vlan': vlan, 'port': ipcp.ifname} cmds = ['ip link set %(port)s up' % args, 'ip link add link %(port)s name %(port)s.%(vlan)s ' @@ -109,7 +115,6 @@ class Testbed(mod.Testbed): node.ssh_config, cmds) - def swap_in(self, experiment): """ :type experiment mod.Experiment @@ -303,6 +308,10 @@ class Testbed(mod.Testbed): print('Sleeping %s secs waiting for the last VMs to boot' % tsleep) time.sleep(tsleep) + # TODO: to be removed, we should loop in the ssh part + print('Sleeping 5 seconds, just to be on the safe side') + time.sleep(5) + self.recover_if_names(experiment) def swap_out(self, experiment): -- cgit v1.2.3