Revision a395aaa8

View differences:

BGPpysim/README.md
1
Internet on FIRE BGP py simulator
2
===
3

  
4
## Intro
5

  
6
This is a python simulator for BGP, and the main purpose of this simulator 
7
is to reproduce the results presented in the [Fabrikant paper
8
](https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=5935139)
9

  
10
## Execution
11

  
12
A general fabrikant graphml file needs to be provided to the simulator to replicate the environment.
13

  
14
A general fabrikant graphml could be produced with the script in the `topos` folder with the following command:
15

  
16
`python3 topos/genFABREXfig1.py`
17

  
18
It will produce the file `test.graphml` that can be used to create a simulation.
19

  
20
Now is possible to run a simulation with the command:
21

  
22
`python3 bgpSimulator.py -g test.graphml -w outputDir`
23

  
24
Pay attention, the output dir must exist, in case you did not create it you can 
25
use the command `mkdir outputDir`
26

  
27
Now in the output directory you will find the simulation files produced by the environment.
28

  
29
A more deep explanation of the simulator is available in the `bgpSim_documentation` folder
30

  
31
## Repeated execution
32

  
33
For simplicity to execute more experiments on the same topology is possible to use 
34
the bash file provided, it's called `nSimulations.bash` it only needs the number of 
35
simulations to repeat, the graph file and the output dire, follow this example:
36

  
37
`./nSimulations.bash 50 test.graphml outDir`
38

  
39
Obviously the output dir must exist. 
BGPpysim/topos/genFABREXfig1.py
1 1
#!/usr/bin/python
2 2

  
3
import code
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation, either version 3 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
#
16
# Copyright (C) 2019  Mattia Milani <mattia.milani@studenti.unitn.it> & Lorenzo Ghiro <lorenzo.ghiro@unitn.it>
17

  
18

  
4 19
import networkx as nx
5 20
from collections import defaultdict
6 21

  
7 22

  
8
def edge(e1, e2, etype, mrai1=30, mrai2=30, customer=None):
23
def edge(e1, e2, etype, mrai1=30.0, mrai2=30.0, customer=None):
24
    """
25
    Function to set the edge information
26
    :param e1: first part of the edge
27
    :param e2: second node of the edge
28
    :param etype: Type of the edge
29
    :param mrai1: MRAI that controls the connection e1->e2
30
    :param mrai2: MRAI that controls the connection e2->e1
31
    :param customer: Parameter that identifies which node is the customer in the relation
32
    :return: the edge with all the parameters configured
33
    """
9 34
    if etype == 'peer':
10
        assert customer == None
35
        assert customer is None
11 36
    elif etype == 'transit':
12 37
        assert customer == e1 or customer == e2
13 38
    redge = (e1, e2, {'type': etype, 'termination1': e1, 'termination2': e2,
......
18 43
G = nx.DiGraph()
19 44

  
20 45
etype = 'transit'
21
myedges = []
22
myedges.append(edge('X4', 'Y3', etype, customer='X4', mrai1=8.0, mrai2=8.0))
23
myedges.append(edge('X4', 'X3', etype, customer='X4', mrai1=8.0, mrai2=8.0))
24
myedges.append(edge('Y3', 'X3', etype, customer='Y3', mrai1=8.0, mrai2=8.0))
25

  
26
myedges.append(edge('X3', 'Y2', etype, customer='X3', mrai1=4.0, mrai2=4.0))
27
myedges.append(edge('X3', 'X2', etype, customer='X3', mrai1=4.0, mrai2=4.0))
28
myedges.append(edge('Y2', 'X2', etype, customer='Y2', mrai1=4.0, mrai2=4.0))
29

  
30
myedges.append(edge('X2', 'Y1', etype, customer='X2', mrai1=2.0, mrai2=2.0))
31
myedges.append(edge('X2', 'X1', etype, customer='X2', mrai1=2.0, mrai2=2.0))
32
myedges.append(edge('Y1', 'X1', etype, customer='Y1', mrai1=2.0, mrai2=2.0))
33

  
46
myedges = [edge('X4', 'Y3', etype, customer='Y3', mrai1=8.0, mrai2=8.0),
47
           edge('X4', 'X3', etype, customer='X3', mrai1=8.0, mrai2=8.0),
48
           edge('Y3', 'X3', etype, customer='X3', mrai1=8.0, mrai2=8.0),
49
           edge('X3', 'Y2', etype, customer='Y2', mrai1=4.0, mrai2=4.0),
50
           edge('X3', 'X2', etype, customer='X2', mrai1=4.0, mrai2=4.0),
51
           edge('Y2', 'X2', etype, customer='X2', mrai1=4.0, mrai2=4.0),
52
           edge('X2', 'Y1', etype, customer='Y1', mrai1=2.0, mrai2=2.0),
53
           edge('X2', 'X1', etype, customer='X1', mrai1=2.0, mrai2=2.0),
54
           edge('Y1', 'X1', etype, customer='X1', mrai1=2.0, mrai2=2.0)]
34 55

  
35 56
G.add_edges_from(myedges)
36 57

  
......
47 68
nx.set_node_attributes(G, attrs)
48 69

  
49 70
nx.write_graphml(G, 'test.graphml')
50
#code.interact(local=dict(globals(), **locals()))
BGPpysim/util/EventScheduler.py
1
#!/usr/bin/python
2

  
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation, either version 3 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
#
16
# Copyright (C) 2019  Mattia Milani <mattia.milani@studenti.unitn.it> & Lorenzo Ghiro <lorenzo.ghiro@unitn.it>
17

  
1 18
import heapq
2 19
import random
3 20

  
21

  
4 22
class EventScheduler:
5
        def __init__(self):
6
                self.queue = []
7
                self.time = 0
8
                self.last = 0
9
                self._step = 0
10
                self.counter = 0
11

  
12
        def jitter(self, positive=True):
13
            if positive:
14
                return random.uniform(0, 0.1)
15
            else:
16
                return [-1, 1][random.randrange(2)]*random.uniform(0, 0.866)
17

  
18
        def schedule_event(self, interval, e):
19
                t = self.time + interval
20
                if t > self.last:
21
                    self.last = t
22
                heapq.heappush(self.queue, (t, e))
23

  
24
        def pop_event(self):
25
                e = heapq.heappop(self.queue)
26
                self._step = e[0] - self.time
27
                self.time = e[0]
28
                self.counter += 1
29
                return e[1]
30

  
31
        def elapsed_time(self):
32
                return self.time
33

  
34
        def last_event_time(self):
35
                return self.last
36

  
37
        def step(self):
38
            return self._step
39

  
40
        def processed_events(self):
41
            return self.counter
23
    """
24
    Class used to schedule events in an event discrete space
25
    """
26

  
27
    def __init__(self):
28
        self.queue = []
29
        self.time = 0
30
        self.last = 0
31
        self._step = 0
32
        self.counter = 0
33

  
34
    def jitter(self, positive=True):
35
        """
36
        Function to introduce a jitter in the a jitter in the event
37
        :param positive: if true it will introduce the jitter
38
        :return:
39
        """
40
        if positive:
41
            return random.uniform(0, 0.1)
42
        else:
43
            return [-1, 1][random.randrange(2)] * random.uniform(0, 0.866)
44

  
45
    def schedule_event(self, interval, e):
46
        """
47
        Function to schedule an event after a certain interval
48
        :param interval: After how much the event will be scheduled
49
        :param e: event to schedule
50
        """
51
        t = self.time + interval
52
        if t > self.last:
53
            self.last = t
54
        heapq.heappush(self.queue, (t, e))
55

  
56
    def pop_event(self):
57
        """
58
        Function to take the next event in the queue
59
        :return: the next event in the queue
60
        """
61
        e = heapq.heappop(self.queue)
62
        self._step = e[0] - self.time
63
        self.time = e[0]
64
        self.counter += 1
65
        return e[1]
66

  
67
    def elapsed_time(self):
68
        """
69
        Function to know how much time is elapsed
70
        :return: the actual time
71
        """
72
        return self.time
73

  
74
    def last_event_time(self):
75
        """
76
        Function to know when the last event will happen
77
        :return: the time of the last event
78
        """
79
        return self.last
80

  
81
    def step(self):
82
        """
83
        Function to get the step time
84
        :return: the step time
85
        """
86
        return self._step
87

  
88
    def processed_events(self):
89
        """
90
        Function to get the total amount of events processed
91
        :return: number of events
92
        """
93
        return self.counter
BGPpysim/util/event_log.py
1
#!/usr/bin/python
2

  
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation, either version 3 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
#
16
# Copyright (C) 2019  Mattia Milani <mattia.milani@studenti.unitn.it> & Lorenzo Ghiro <lorenzo.ghiro@unitn.it>
17

  
18

  
1 19
class EventLog(object):
20
    """
21
    Class EventLog, used to log events in a given format
22
    """
2 23

  
3 24
    def __init__(self, time, evType, evFrom, prefix, as_path, binPref='ND'):
25
        """
26
        Initialization on an eventLog element
27
        :param time: when the event happen
28
        :param evType: type of the event
29
        :param evFrom: who trigger the event
30
        :param prefix: Prefix that trigger the event
31
        :param as_path: Path in the packet of the event
32
        :param binPref: given fabrikant path
33
        """
4 34
        self.time = time
5 35
        self.evType = evType
6 36
        self.evFrom = evFrom
......
9 39
        self.binPref = binPref
10 40

  
11 41
    def to_dict(self):
12
        return self.__dict__
42
        return self.__dict__

Also available in: Unified diff