aboutsummaryrefslogtreecommitdiff
path: root/libarcfire.py
blob: 0993d6680c82a97a4c9c09af74765ecf9ecdf26c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#
# 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 = dict()
        if members != None:
            for m in members:
                self.members[m] = m

    def __repr__(self):
        return "%s: %s" % (self.name, str(sorted(self.members)))

    def node_add(node_name):
        self.members[node_name] = node_name

    def node_del(node_name):
        del self.members[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")


# 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)