aboutsummaryrefslogtreecommitdiff
path: root/rumba/prototypes/irati.py
diff options
context:
space:
mode:
authorMarco Capitani <m.capitani@nextworks.it>2017-04-11 15:53:49 +0200
committerMarco Capitani <m.capitani@nextworks.it>2017-04-11 15:53:49 +0200
commit46310717c3293054324cc6a0271d855b638df0ff (patch)
tree69b27a68b2d97962f3bcbdee40d412453285eea2 /rumba/prototypes/irati.py
parent7f5054816fc68bca1d9d4901d1e365b57a278542 (diff)
downloadrumba-46310717c3293054324cc6a0271d855b638df0ff.tar.gz
rumba-46310717c3293054324cc6a0271d855b638df0ff.zip
Resolving node_id issue and general cleanup
Diffstat (limited to 'rumba/prototypes/irati.py')
-rw-r--r--rumba/prototypes/irati.py98
1 files changed, 60 insertions, 38 deletions
diff --git a/rumba/prototypes/irati.py b/rumba/prototypes/irati.py
index c4c30c7..9c8b004 100644
--- a/rumba/prototypes/irati.py
+++ b/rumba/prototypes/irati.py
@@ -2,6 +2,7 @@
# Commands to setup and instruct IRATI
#
# Vincenzo Maffione <v.maffione@nextworks.it>
+# Marco Capitani <m.capitani@nextworks.it>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -62,10 +63,17 @@ class ConfBuilder(object):
:type experiment: Experiment
:param experiment: the experiment to be configured
"""
+ # Constants and initializations
ipcmconfs = dict()
+ difconfs = dict()
+ ipcp2shim_map = {}
+ node2id_map = {}
+ manager = False
+ mgmt_dif_name = 'NMS'
# TODO ask: what are these, and how are they represented in experiment?
- # Are these bindings or registration (in node)? In gen.py these are given on a per-dif basis...
+ # Are these bindings or registration (in node)?
+ # In gen.py these are given on a per-dif basis...
app_mappings = []
# If some app directives were specified, use those to build da.map.
@@ -73,20 +81,21 @@ class ConfBuilder(object):
# the DIF with the highest rank.
if len(app_mappings) == 0:
if len(experiment.dif_ordering) > 0:
- for adm in irati_templates.da_map_base["applicationToDIFMappings"]:
+ for adm in \
+ irati_templates.da_map_base["applicationToDIFMappings"]:
adm["difName"] = "%s" % (experiment.dif_ordering[-1],)
# else:
# irati_templates.da_map_base["applicationToDIFMappings"] = []
# for apm in app_mappings:
- # irati_templates.da_map_base["applicationToDIFMappings"].append({
+ # irati_templates.da_map_base["applicationToDIFMappings"]\
+ # .append({
# "encodedAppName": apm['name'],
# "difName": "%s.DIF" % (apm['dif'])
# })
- # TODO ask: I guess this will need to be added, and in that case we should add it to the qemu plugin too...
+ # TODO ask: I guess this will need to be added,
+ # and in that case we should add it to the qemu plugin too...
# Where should we take it in input?
- manager = False
- mgmt_dif_name = 'NMS'
if manager:
# Add MAD/Manager configuration
@@ -101,20 +110,24 @@ class ConfBuilder(object):
}
}
+ node_number = 1
for node in experiment.nodes: # type: mod.Node
+ node2id_map[node.name] = node_number
+ node_number += 1
ipcmconfs[node.name] = copy.deepcopy(irati_templates.ipcmconf_base)
if manager:
- ipcmconfs[node.name]["addons"]["mad"]["managerAppName"] = "%s.mad-1--" % (node.name)
+ ipcmconfs[node.name]["addons"]["mad"]["managerAppName"] \
+ = "%s.mad-1--" % (node.name,)
- difconfs = dict()
- ipcp2shim_map = {} # We will need it in a sec
for dif in experiment.dif_ordering: # type: mod.DIF
if isinstance(dif, mod.ShimEthDIF):
ipcp2shim_map.update({ipcp.name: dif for ipcp in dif.ipcps})
elif isinstance(dif, mod.NormalDIF):
difconfs[dif.name] = dict()
for node in dif.members:
- difconfs[dif.name][node.name] = copy.deepcopy(irati_templates.normal_dif_base)
+ difconfs[dif.name][node.name] = copy.deepcopy(
+ irati_templates.normal_dif_base
+ )
for node in experiment.nodes: # type: mod.Node
ipcmconf = ipcmconfs[node.name]
@@ -129,27 +142,29 @@ class ConfBuilder(object):
"difName": shim.name
})
- template_file_name = 'shimeth.%s.%s.dif' % (node_name, shim.name)
+ template_file_name = 'shimeth.%s.%s.dif' \
+ % (node_name, shim.name)
ipcmconf["difConfigurations"].append({
"name": shim.name,
"template": template_file_name
})
fout = open(template_file_name, 'w')
- fout.write(json.dumps({"difType": "shim-eth-vlan",
- "configParameters": {
- "interface-name": "ifc%d" % (int(port_id),)
- }
- },
- indent=4, sort_keys=True))
+ fout.write(json.dumps(
+ {"difType": "shim-eth-vlan",
+ "configParameters": {
+ "interface-name": "ifc%d" % (int(port_id),)
+ }
+ },
+ indent=4, sort_keys=True))
fout.close()
# Run over dif_ordering array, to make sure each IPCM config has
# the correct ordering for the ipcProcessesToCreate list of operations.
# If we iterated over the difs map, the order would be randomic, and so
- # some IPCP registrations in lower DIFs may fail. This would happen because
- # at the moment of registration, it may be that the IPCP of the lower DIF
- # has not been created yet.
+ # some IPCP registrations in lower DIFs may fail.
+ # This would happen because at the moment of registration,
+ # it may be that the IPCP of the lower DIF has not been created yet.
shims = ipcp2shim_map.values()
for dif in experiment.dif_ordering: # type: mod.NormalDIF
@@ -159,10 +174,8 @@ class ConfBuilder(object):
for node in dif.members: # type: mod.Node
node_name = node.name
- node_id = int(node.full_name.split(':')[1]) - 2222
ipcmconf = ipcmconfs[node_name]
- # TODO ask: here was vm['id']. Does the name work or does it have to be the id (sequential from 1)?
normal_ipcp = {"apName": "%s.%s.IPCP" % (dif.name, node_name),
"apInstance": "1",
"difName": "%s" % (dif.name,),
@@ -178,35 +191,44 @@ class ConfBuilder(object):
"template": "normal.%s.%s.dif" % (node_name, dif.name,)
})
- # Fill in the map of IPCP addresses. This could be moved at difconfs
- # deepcopy-time
- # TODO what to do for id? Get it from full_name (i.e.: address:port)? Ugly, but might work
+ # Fill in the map of IPCP addresses.
+ # This could be moved at difconfs
for other_node in dif.members: # type: mod.Node
- difconfs[dif.name][other_node.name]["knownIPCProcessAddresses"].append({
- "apName": "%s.%s.IPCP" % (dif.name, node_name),
- "apInstance": "1",
- "address": 16 + node_id
- })
+ difconfs[dif.name][other_node.name] \
+ ["knownIPCProcessAddresses"].append({
+ "apName": "%s.%s.IPCP" % (dif.name, node_name),
+ "apInstance": "1",
+ "address": 16 + node2id_map[node_name]})
for path, ps in dif.policies.items():
# if policy['nodes'] == [] or vmname in policy['nodes']:
- # TODO: policies can be applied per-node (and not just per-dif)? With what syntax?
- irati_templates.translate_policy(difconfs[dif.name][node_name], path,
- ps, parms=[])
- # TODO: what is the syntax for the policy parameters?
+ # TODO: policies can be applied per-node
+ # (and not just per-dif) in rumba? With what syntax?
+ irati_templates.translate_policy(
+ difconfs[dif.name][node_name], path, ps, parms=[])
# Dump the DIF Allocator map
with open('da.map', 'w') as da_map_file:
- json.dump(irati_templates.da_map_base, da_map_file, indent=4, sort_keys=True)
+ json.dump(irati_templates.da_map_base,
+ da_map_file,
+ indent=4,
+ sort_keys=True)
for node in experiment.nodes:
# Dump the IPCM configuration files
with open('%s.ipcm.conf' % (node.name,), 'w') as node_file:
- json.dump(ipcmconfs[node.name], node_file, indent=4, sort_keys=True)
+ json.dump(ipcmconfs[node.name],
+ node_file,
+ indent=4,
+ sort_keys=True)
for dif in experiment.dif_ordering: # type: mod.DIF
dif_conf = difconfs.get(dif.name, None)
if dif_conf:
# Dump the normal DIF configuration files
for node in dif.members:
- with open('normal.%s.%s.dif' % (node.name, dif.name), 'w') as dif_conf_file:
- json.dump(dif_conf[node.name], dif_conf_file, indent=4, sort_keys=True)
+ with open('normal.%s.%s.dif' % (node.name, dif.name), 'w') \
+ as dif_conf_file:
+ json.dump(dif_conf[node.name],
+ dif_conf_file,
+ indent=4,
+ sort_keys=True)