aboutsummaryrefslogtreecommitdiff
path: root/rhumba.py
blob: d94cd9e6afa9366067b06f5077a0a5dec599b4cd (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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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)