aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvmaffione <v.maffione@gmail.com>2017-01-18 15:15:37 +0000
committervmaffione <v.maffione@gmail.com>2017-01-18 15:15:37 +0000
commite184e2838cc2b65fe9afe1cf7649b01ce4dcf73f (patch)
treecec479b4907b2d69eb8c78a83ed72392e684d339
parenta9674f5a94525cc396141ce7c145bbe63324f368 (diff)
parentb52e886c9042650c70e734be9983614e438b39c8 (diff)
downloadrumba-e184e2838cc2b65fe9afe1cf7649b01ce4dcf73f.tar.gz
rumba-e184e2838cc2b65fe9afe1cf7649b01ce4dcf73f.zip
Merge branch 'master-ex' into 'master'
rhumba: Change example script See merge request !1
-rwxr-xr-xlibarcfire.py154
-rwxr-xr-xmain.py27
-rwxr-xr-xrhumba.py166
3 files changed, 183 insertions, 164 deletions
diff --git a/libarcfire.py b/libarcfire.py
deleted file mode 100755
index e04b667..0000000
--- a/libarcfire.py
+++ /dev/null
@@ -1,154 +0,0 @@
-#
-# A library to manage ARCFIRE experiments
-#
-
-# Base class for DIFs
-#
-# @name [string] DIF name
-# @members [iterable] Nodes belonging to the DIF
-# @appmap [iterable] Application names mapped to this DIF
-#
-class DIF:
- def __init__(self, name, members):
- self.name = name
- self.members = dict()
- if members != None:
- for m in members:
- self.members[m] = m
- self.appmap = set()
-
- def __repr__(self):
- s = "DIF %s: members=%s" % (self.name, str(sorted(self.members)))
- if len(self.appmap) > 0:
- s += " appmap=%s" % self.appmap
- return s
-
- def node_add(self, node_name):
- self.members[node_name] = node_name
-
- def node_del(self, node_name):
- del self.members[node_name]
-
- def appmap_add(self, apname, apinst = None):
- s = apname
- if apinst:
- s += apinst
- self.appmap.add(s)
-
- def appmap_del(self, apname, apinst = None):
- s = apname
- if apinst:
- s += apinst
- self.appmap.discard(s)
-
-
-# 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")
-
-
-# A policy
-#
-# @component: RINA component to which the policy applies to
-# @name: Name of the policy
-# @parameters: A dictionary of (key, values) pairs representing policy-specific
-# parameters
-class Policy:
- def __init__(self, component, name, **kwargs):
- self.component = component
- self.name = name
- self.parameters = kwargs
-
- def __repr__(self):
- s = "%s:%s" % (self.component, self.name)
- if self.parameters:
- s += "%s" % self.parameters
- return s
-
-
-# Normal DIF
-class NormalDIF(DIF):
- def __init__(self, name, members = None):
- DIF.__init__(self, name, members)
- self.policies = dict()
-
- def policy_add(self, policy):
- self.policies[policy.component] = policy
-
- def policy_del(self, component):
- del self.policies[component]
-
- def __repr__(self):
- s = DIF.__repr__(self)
- if self.policies:
- s += " policies=["
- for p in self.policies:
- s += "%s," % self.policies[p]
- if self.policies:
- s += "]"
- return s
-
-
-# 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)
-
-
-# An experiment over the IRATI implementation
-class IRATIExperiment(Experiment):
- def __init__(self, name):
- Experiment.__init__(self, name)
-
- def run(self):
- print("[IRATI experiment %s] start" % self.name)
- print("[IRATI experiment %s] end" % self.name)
-
-
-# An experiment over the RLITE implementation
-class RLITEExperiment(Experiment):
- def __init__(self, name):
- Experiment.__init__(self, name)
-
- def run(self):
- print("[RLITE experiment %s] start" % self.name)
- print("[RLITE experiment %s] end" % self.name)
-
-
-# An experiment over the OUROBOROS implementation
-class OUROBOROSExperiment(Experiment):
- def __init__(self, name):
- Experiment.__init__(self, name)
-
- def run(self):
- print("[OUROBOROS experiment %s] start" % self.name)
- print("[OUROBOROS experiment %s] end" % self.name)
-
diff --git a/main.py b/main.py
index ea7ae17..1b61543 100755
--- a/main.py
+++ b/main.py
@@ -1,19 +1,26 @@
#!/usr/bin/env python
-# An example script using libarcfire.py
+# An example script using rhumba.py
-from libarcfire import *
+from rhumba import *
+n1 = NormalDIF("n1", policies = {"rmt.pff": "lfa",
+ "security-manager": "passwd"})
-exp = IRATIExperiment("prova")
-exp.dif_add(ShimEthDIF("300", 0, ["a", "b"]))
-exp.dif_add(ShimEthDIF("400", 0, ["b", "c"]))
+e1 = ShimEthDIF("e1")
-n1 = NormalDIF("n1", ["a", "b", "c"])
-n1.policy_add(Policy("rmt.pff", "lfa"))
-n1.policy_add(Policy("security-manager", "passwd", passwd="xyz"))
-n1.appmap_add("rina-echo-time.server")
-exp.dif_add(n1)
+a = Node("a",
+ difs = [n1, e1],
+ dif_registrations = {n1 : [e1]},
+ registrations = {"a.crap" : [n1]},
+ bindings = {"a.crap" : "/usr/bin/crap"})
+
+b = Node("b",
+ difs = [e1, n1],
+ dif_registrations = {n1 : [e1]})
+
+exp = IRATIExperiment("paperino",
+ nodes = [a, b])
print(exp)
diff --git a/rhumba.py b/rhumba.py
new file mode 100755
index 0000000..d94cd9e
--- /dev/null
+++ b/rhumba.py
@@ -0,0 +1,166 @@
+#
+# A library to manage ARCFIRE experiments
+#
+
+# Base class for DIFs
+#
+# @name [string] DIF name
+#
+class DIF:
+ def __init__(self, name):
+ self.name = name
+
+ def __repr__(self):
+ s = "DIF %s" % self.name
+ return s
+
+# Shim over Ethernet
+#
+# @link_speed [int] Speed of the Ethernet network, in Mbps
+#
+class ShimEthDIF(DIF):
+ def __init__(self, name, link_speed = 0):
+ DIF.__init__(self, name)
+ self.link_speed = int(link_speed)
+ if self.link_speed < 0:
+ raise ValueError("link_speed must be a non-negative number")
+
+# Normal DIF
+#
+# @policies [dict] Policies of the normal DIF
+#
+class NormalDIF(DIF):
+ def __init__(self, name, policies = dict()):
+ DIF.__init__(self, name)
+ self.policies = policies
+
+ def add_policy(self, comp, pol):
+ self.policies[comp] = pol
+
+ def del_policy(self, comp):
+ del self.policies[comp]
+
+ def __repr__(self):
+ s = DIF.__repr__(self)
+ for comp, pol in self.policies.items():
+ s += "\n Component %s has policy %s" % (comp, pol)
+ return s
+
+# A node in the experiment
+#
+# @difs: DIFs the node will have an IPCP in
+# @dif_registrations: Which DIF is registered in which DIF
+# @registrations: Registrations of names in DIFs
+# @bindings: Binding of names on the processing system
+#
+class Node:
+ def __init__(self, name, difs = set(),
+ dif_registrations = dict(),
+ registrations = dict(),
+ bindings = dict()):
+ self.name = name
+ self.difs = difs
+ self.dif_registrations = dif_registrations
+ self.registrations = registrations
+ self.bindings = bindings
+
+ def __repr__(self):
+ s = "Node " + self.name + ":\n"
+ s += " IPCPs in DIFs: ["
+ for d in self.difs:
+ s += " %s" % d.name
+ s += " ]\n"
+ s += " DIF registrations: [ "
+ for dif_a, difs in self.dif_registrations.items():
+ s += "%s => [" % dif_a.name
+ for dif_b in difs:
+ s += " %s" % dif_b.name
+ s += " ]"
+ s += " ]\n"
+ s += " Name registrations: [ "
+ for name, difs in self.registrations.items():
+ s += "%s => [" % name
+ for dif in difs:
+ s += " %s" % dif.name
+ s += " ]"
+ s += " ]\n"
+ s += " Bindings: [ "
+ for ap, name in self.bindings.items():
+ s += "'%s' => '%s'" % (ap, name)
+ s += " ]\n"
+ return s
+
+ def add_dif_registration(self, dif_a, dif_b):
+ self.dif_registrations[dif_a].append(dif_b)
+
+ def del_dif_registration(self, dif_a, dif_b):
+ self.dif_registrations[dif_a].remove(dif_b)
+
+ def add_registration(self, name, dif):
+ self.dif_registrations[name].append(dif)
+
+ def del_registration(self, name, dif):
+ self.dif_registrations[name].remove(dif)
+
+ def add_binding(self, name, ap):
+ self.dif_bindings[name] = ap
+
+ def del_binding(self, name):
+ del self.dif_bindings[name]
+
+# Base class for ARCFIRE experiments
+#
+# @name [string] Name of the experiment
+# @nodes: Nodes in the experiment
+#
+class Experiment:
+ def __init__(self, name, nodes = set()):
+ self.name = name
+ self.nodes = nodes
+
+ def __repr__(self):
+ s = "%s:" % self.name
+ for n in self.nodes:
+ s += "\n" + str(n)
+
+ return s
+
+ def add_node(self, node):
+ self.nodes.append(node)
+
+ def add_node(self, node):
+ self.nodes.remove(node)
+
+ def run(self):
+ print("[Experiment %s] start" % self.name)
+ print("[Experiment %s] end" % self.name)
+
+
+# An experiment over the IRATI implementation
+class IRATIExperiment(Experiment):
+ def __init__(self, name, nodes = set()):
+ Experiment.__init__(self, name, nodes)
+
+ def run(self):
+ print("[IRATI experiment %s] start" % self.name)
+ print("[IRATI experiment %s] end" % self.name)
+
+
+# An experiment over the RLITE implementation
+class RLITEExperiment(Experiment):
+ def __init__(self, name, nodes = set()):
+ Experiment.__init__(self, name, nodes)
+
+ def run(self):
+ print("[RLITE experiment %s] start" % self.name)
+ print("[RLITE experiment %s] end" % self.name)
+
+
+# An experiment over the Ouroboros implementation
+class OuroborosExperiment(Experiment):
+ def __init__(self, name, nodes = set()):
+ Experiment.__init__(self, name, nodes)
+
+ def run(self):
+ print("[Ouroboros experiment %s] start" % self.name)
+ print("[Ouroboros experiment %s] end" % self.name)