aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rumba/model.py84
-rw-r--r--rumba/prototypes/irati.py2
-rw-r--r--rumba/prototypes/ouroboros.py2
-rw-r--r--rumba/prototypes/rlite.py2
4 files changed, 53 insertions, 37 deletions
diff --git a/rumba/model.py b/rumba/model.py
index 0346a8c..23db86f 100644
--- a/rumba/model.py
+++ b/rumba/model.py
@@ -64,40 +64,27 @@ class Link:
#
class P2PLink(Link):
def __init__(self, name, node_a, node_b,
- int_a = Interface(),
- int_b = Interface()):
+ int_a = None,
+ int_b = None):
Link.__init__(self, name)
self.node_a = node_a
self.node_b = node_b
+ if int_a is None:
+ int_a = Interface()
self.int_a = int_a
+ if int_b is None:
+ int_b = Interface()
self.int_b = int_b
-def get_links(nodes):
- difs = set()
- links = list()
- for node in nodes:
- for dif in node.difs:
- if type(dif) is ShimEthDIF:
- difs.add(dif)
-
- for dif in difs:
- # Point-to-point link
- if len(dif.members) == 2:
- node_a = dif.members[0]
- node_b = dif.members[1]
- link = P2PLink(node_a.name + "-" + node_b.name,
- node_a, node_b)
- links.append(link)
-
- return links
-
# Base class for DIFs
#
# @name [string] DIF name
#
class DIF:
- def __init__(self, name, members = list()):
+ def __init__(self, name, members = None):
self.name = name
+ if members is None:
+ members = list()
self.members = members
def __repr__(self):
@@ -113,7 +100,7 @@ class DIF:
# Shim over UDP
#
class ShimUDPDIF(DIF):
- def __init__(self, name, members = list()):
+ def __init__(self, name, members = None):
DIF.__init__(self, name, members)
# Shim over Ethernet
@@ -121,7 +108,7 @@ class ShimUDPDIF(DIF):
# @link_speed [int] Speed of the Ethernet network, in Mbps
#
class ShimEthDIF(DIF):
- def __init__(self, name, members = list(), link_speed = 0):
+ def __init__(self, name, members = None, link_speed = 0):
DIF.__init__(self, name, members)
self.link_speed = int(link_speed)
if self.link_speed < 0:
@@ -132,8 +119,10 @@ class ShimEthDIF(DIF):
# @policies [dict] Policies of the normal DIF
#
class NormalDIF(DIF):
- def __init__(self, name, members = list(), policies = dict()):
+ def __init__(self, name, members = None, policies = None):
DIF.__init__(self, name, members)
+ if policies is None:
+ policies = dict()
self.policies = policies
def add_policy(self, comp, pol):
@@ -156,16 +145,24 @@ class NormalDIF(DIF):
# @bindings: Binding of names on the processing system
#
class Node:
- def __init__(self, name, difs = list(),
- dif_registrations = dict(),
- registrations = dict(),
- bindings = dict()):
+ def __init__(self, name, difs = None,
+ dif_registrations = None,
+ registrations = None,
+ bindings = None):
self.name = name
+ if difs is None:
+ difs = list()
self.difs = difs
- for dif in difs:
+ for dif in self.difs:
dif.add_member(self)
+ if dif_registrations is None:
+ dif_registrations = dict()
self.dif_registrations = dif_registrations
+ if registrations is None:
+ registrations = dict()
self.registrations = registrations
+ if bindings is None:
+ bindings = dict()
self.bindings = bindings
self.full_name = name
@@ -227,7 +224,9 @@ class Node:
# @nodes: Nodes in the experiment
#
class Experiment:
- def __init__(self, testbed, nodes = list()):
+ def __init__(self, testbed, nodes = None):
+ if nodes is None:
+ nodes = list()
self.nodes = nodes
self.testbed = testbed
@@ -238,6 +237,25 @@ class Experiment:
return s
+ def get_links(self):
+ difs = set()
+ links = list()
+ for node in self.nodes:
+ for dif in node.difs:
+ if type(dif) is ShimEthDIF:
+ difs.add(dif)
+
+ for dif in difs:
+ # Point-to-point link
+ if len(dif.members) == 2:
+ node_a = dif.members[0]
+ node_b = dif.members[1]
+ link = P2PLink(node_a.name + "-" + node_b.name,
+ node_a, node_b)
+ links.append(link)
+
+ return links
+
def add_node(self, node):
self.nodes.append(node)
@@ -246,10 +264,8 @@ class Experiment:
# Realize the experiment, using a testbed-specific setup
def swap_in(self):
- self.links = get_links(self.nodes)
- self.testbed.create_experiment(self.nodes, self.links)
+ self.testbed.create_experiment(self.nodes, self.get_links())
@abc.abstractmethod
def run(self):
raise Exception('run() method not implemented')
-
diff --git a/rumba/prototypes/irati.py b/rumba/prototypes/irati.py
index 28f8ab3..90d0861 100644
--- a/rumba/prototypes/irati.py
+++ b/rumba/prototypes/irati.py
@@ -23,7 +23,7 @@ import rumba.model as mod
# An experiment over the IRATI implementation
class Experiment(mod.Experiment):
- def __init__(self, testbed, nodes = list()):
+ def __init__(self, testbed, nodes = None):
mod.Experiment.__init__(self, testbed, nodes)
def setup(self):
diff --git a/rumba/prototypes/ouroboros.py b/rumba/prototypes/ouroboros.py
index 172d69a..4359f19 100644
--- a/rumba/prototypes/ouroboros.py
+++ b/rumba/prototypes/ouroboros.py
@@ -23,7 +23,7 @@ import rumba.model as mod
# An experiment over the Ouroboros implementation
class Experiment(mod.Experiment):
- def __init__(self, testbed, nodes = list()):
+ def __init__(self, testbed, nodes = None):
mod.Experiment.__init__(self, testbed, nodes)
def setup_ouroboros(self):
diff --git a/rumba/prototypes/rlite.py b/rumba/prototypes/rlite.py
index adb0036..5fa2c37 100644
--- a/rumba/prototypes/rlite.py
+++ b/rumba/prototypes/rlite.py
@@ -23,7 +23,7 @@ import rumba.model as mod
# An experiment over the RLITE implementation
class Experiment(mod.Experiment):
- def __init__(self, testbed, nodes = list()):
+ def __init__(self, testbed, nodes = None):
mod.Experiment.__init__(self, testbed, nodes)
def setup(self):