aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Capitani <m.capitani@nextworks.it>2018-03-26 16:52:30 +0200
committerMarco Capitani <m.capitani@nextworks.it>2018-03-26 16:56:14 +0200
commit9e499fec0ca6e2940717bce45388c59960f9bdc3 (patch)
tree307b7636cccbc7f38f3e14acb0ba616e05307c80
parent81dfe735a72683b7dc87f329d9a25a1868fe74f1 (diff)
downloadrumba-9e499fec0ca6e2940717bce45388c59960f9bdc3.tar.gz
rumba-9e499fec0ca6e2940717bce45388c59960f9bdc3.zip
model: make DIFs scriptable
DIFs instances can now be referenced inside .rsb files. Also changed Node.set_link_state function to accept a DIF as opposed to an IPCP, since IPCPs are not given a name nor mentioned is user scripts.
-rw-r--r--examples/example-script.rsb4
-rw-r--r--rumba/model.py7
-rw-r--r--rumba/storyboard.py18
3 files changed, 21 insertions, 8 deletions
diff --git a/examples/example-script.rsb b/examples/example-script.rsb
index 8b5c714..f00ff42 100644
--- a/examples/example-script.rsb
+++ b/examples/example-script.rsb
@@ -33,7 +33,9 @@ echo2, 18 &ev4| $sb run_client_of $Server.server_b
1.2 &ev5| run_client_of $Server.server_c
# Events need _not_ be in temporal order
# if no object ($ handle) is provided, the storyboard
-# is assumed as the object/
+# is assumed as the object
+
+14 | $Node.node_a set_link_state $ShimEthDIF.e1 'up'
diff --git a/rumba/model.py b/rumba/model.py
index 20f8215..e12bddd 100644
--- a/rumba/model.py
+++ b/rumba/model.py
@@ -145,6 +145,10 @@ class ShimUDPDIF(DIF):
# @link_speed [int] Speed of the Ethernet network, in Mbps
#
class ShimEthDIF(DIF):
+
+ def get_e_id(self):
+ return "ShimEthDIF." + self.name
+
def __init__(self, name, members=None, link_speed=0):
DIF.__init__(self, name, members)
self.link_speed = int(link_speed)
@@ -360,7 +364,8 @@ class Node(object):
def fetch_file(self, path, destination, sudo=False):
self.executor.fetch_files(self, path, destination, sudo)
- def set_link_state(self, ipcp, state):
+ def set_link_state(self, dif, state):
+ ipcp = self.get_ipcp_by_dif(dif)
self.execute_command('ip link set dev ' + ipcp.ifname + ' ' + state,
as_root=True)
diff --git a/rumba/storyboard.py b/rumba/storyboard.py
index e38a102..ea0c51e 100644
--- a/rumba/storyboard.py
+++ b/rumba/storyboard.py
@@ -339,6 +339,7 @@ class StoryBoard(SBEntity):
self.start_time = None
self.commands_list = {}
self.node_map = {}
+ self.shims = {}
self._build_nodes_lists()
# The following must be last, because it needs the info from
# _build_nodes_list
@@ -355,6 +356,9 @@ class StoryBoard(SBEntity):
if self.experiment is not None:
for node in self.experiment.nodes:
self.node_map[node.name] = node
+ for dif in self.experiment.dif_ordering:
+ if isinstance(dif, model.ShimEthDIF):
+ self.shims[dif.name] = dif
def _validate_and_add_server(self, s, n=None):
if len(s.clients) == 0:
@@ -722,8 +726,8 @@ class StoryBoard(SBEntity):
if self._script is None:
self._script = _Script(self)
- for ipcp in dif.ipcps:
- action = functools.partial(ipcp.node.set_link_state, ipcp, state)
+ for node in dif.members:
+ action = functools.partial(node.set_link_state, dif, state)
self._script.add_event(Event(action, ev_time=t))
def set_link_up(self, t, dif):
@@ -739,10 +743,10 @@ class StoryBoard(SBEntity):
if self._script is None:
self._script = _Script(self)
- for ipcp in node.ipcps:
- if not isinstance(ipcp, model.ShimEthIPCP):
+ for dif in node.difs:
+ if not isinstance(dif, model.ShimEthDIF):
continue
- action = functools.partial(ipcp.node.set_link_state, ipcp, state)
+ action = functools.partial(node.set_link_state, dif, state)
self._script.add_event(Event(action, ev_time=t))
def set_node_up(self, t, node):
@@ -965,6 +969,7 @@ class _Script(object):
self._servers = self._storyboard.server_apps
self._clients = self._storyboard.client_apps
self._processes = {}
+ self._shims = self._storyboard.shims
self._entities = {
'sb': self._storyboard,
'storyboard': self._storyboard,
@@ -973,7 +978,8 @@ class _Script(object):
'Node': self._nodes,
'Server': self._servers,
'Client': self._clients,
- 'ClientProcess': self._processes
+ 'ClientProcess': self._processes,
+ 'ShimEthDIF': self._shims
}
def add_process(self, process):