diff options
author | Vincenzo Maffione <[email protected]> | 2016-10-23 15:58:41 +0200 |
---|---|---|
committer | Vincenzo Maffione <[email protected]> | 2016-10-23 15:58:41 +0200 |
commit | cf63ba6fc8317f43dd5c8a7920296b4ba76d8c97 (patch) | |
tree | 6ec18f4ec4f79c5eccc6374cabe7078fc61d6a01 | |
parent | b7afda52a74c7ce07e23978445eac17d028febbe (diff) | |
download | rumba-cf63ba6fc8317f43dd5c8a7920296b4ba76d8c97.tar.gz rumba-cf63ba6fc8317f43dd5c8a7920296b4ba76d8c97.zip |
libarcfire: add basic classes and test code
-rwxr-xr-x | libarcfire.py | 62 | ||||
-rwxr-xr-x | main.py | 13 |
2 files changed, 75 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) + @@ -0,0 +1,13 @@ +#!/usr/bin/env python + +# An example script using libarcfire.py + +from libarcfire import * + + +exp = Experiment("prova") +exp.dif_add(ShimEthDIF("300", 0, ["a", "b", "c"])) + +print(exp) + +exp.run() |