aboutsummaryrefslogtreecommitdiff
path: root/libarcfire.py
diff options
context:
space:
mode:
authorVincenzo Maffione <v.maffione@gmail.com>2016-10-23 15:58:41 +0200
committerVincenzo Maffione <v.maffione@gmail.com>2016-10-23 15:58:41 +0200
commitcf63ba6fc8317f43dd5c8a7920296b4ba76d8c97 (patch)
tree6ec18f4ec4f79c5eccc6374cabe7078fc61d6a01 /libarcfire.py
parentb7afda52a74c7ce07e23978445eac17d028febbe (diff)
downloadrumba-cf63ba6fc8317f43dd5c8a7920296b4ba76d8c97.tar.gz
rumba-cf63ba6fc8317f43dd5c8a7920296b4ba76d8c97.zip
libarcfire: add basic classes and test code
Diffstat (limited to 'libarcfire.py')
-rwxr-xr-xlibarcfire.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/libarcfire.py b/libarcfire.py
new file mode 100755
index 0000000..0402b30
--- /dev/null
+++ b/libarcfire.py
@@ -0,0 +1,62 @@
+#
+# A library to manage ARCFIRE experiments
+#
+
+# Base class for DIFs
+#
+# @name [string] DIF name
+# @members [iterable] Nodes belonging to the DIF
+#
+class DIF:
+ def __init__(self, name, members):
+ self.name = name
+ self.members = set() if members == None else set(members)
+
+ def __repr__(self):
+ return "%s: %s" % (self.name, str(sorted(self.members)))
+
+ def node_add(node_name):
+ self.members.add(node_name)
+
+ def node_del(node_name):
+ self.members.discard(node_name)
+
+
+# Shim over Ethernet
+#
+# @link_speed [int] Speed of the Ethernet network, in Mbps
+#
+class ShimEthDIF(DIF):
+ def __init__(self, name, link_speed = 0, members = None):
+ DIF.__init__(self, name, members)
+ self.link_speed = int(link_speed)
+ if self.link_speed < 0:
+ raise ValueError("link_speed must be a non-negative number")
+
+
+# Base class for ARCFIRE experiments
+#
+# @name [string] Name of the experiment
+#
+class Experiment:
+ def __init__(self, name):
+ self.name = name
+ self.difs = dict()
+
+ def __repr__(self):
+ s = "%s:" % self.name
+ for d in self.difs:
+ s += "\n %s" % self.difs[d]
+
+ return s
+
+ def dif_add(self, dif):
+ self.difs[dif.name] = dif
+
+ def dif_del(self, dif_name):
+ del self.difs[dif_name]
+
+ def run(self):
+ print("[experiment %s] start" % self.name)
+ print("[experiment %s] end" % self.name)
+