aboutsummaryrefslogtreecommitdiff
path: root/libarcfire.py
blob: e9b7adc8f2d866b2eb3dffd41ed01e639903987d (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
#
# 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")


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