From b4a1c65e541f0815436941aeccac4397ac5eeb26 Mon Sep 17 00:00:00 2001 From: Vincenzo Maffione Date: Sun, 23 Oct 2016 18:52:18 +0200 Subject: libarcfire: add Policy and normal DIF --- libarcfire.py | 42 ++++++++++++++++++++++++++++++++++++++++++ main.py | 8 +++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/libarcfire.py b/libarcfire.py index e9b7adc..60bce47 100755 --- a/libarcfire.py +++ b/libarcfire.py @@ -37,6 +37,48 @@ class ShimEthDIF(DIF): 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 diff --git a/main.py b/main.py index 88effbb..7777a93 100755 --- a/main.py +++ b/main.py @@ -6,7 +6,13 @@ from libarcfire import * exp = Experiment("prova") -exp.dif_add(ShimEthDIF("300", 0, ["a", "b", "c"])) +exp.dif_add(ShimEthDIF("300", 0, ["a", "b"])) +exp.dif_add(ShimEthDIF("400", 0, ["b", "c"])) + +n1 = NormalDIF("n1", ["a", "b", "c"]) +n1.policy_add(Policy("rmt.pff", "lfa")) +n1.policy_add(Policy("security-manager", "passwd", passwd="xyz")) +exp.dif_add(n1) print(exp) -- cgit v1.2.3