-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulator_dist_vect_routing.py
99 lines (72 loc) · 2.47 KB
/
simulator_dist_vect_routing.py
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
import simpy
from device import Host
from device import Router
from link import Link
from graphing import Graph
env = simpy.Environment()
# Simulates 4 Routers
'''
r0
- -
- -
r3 - r1
- -
- -
-r2
'''
data1 = 1024 * 1000
links = [Link(link_rate=(2.578 * 10 ** 11), link_delay=1, max_buffer_size=64000, env=env), \
Link(link_rate=(2.578 * 10 ** 11), link_delay=1, max_buffer_size=64000, env=env), \
Link(link_rate=(2.578 * 10 ** 11), link_delay=1, max_buffer_size=64000, env=env), \
Link(link_rate=(2.578 * 10 ** 11), link_delay=1, max_buffer_size=64000, env=env)]
devices = [Router(ip=0), Router(ip=1), Router(ip=2), Router(ip=3)]
devices[0].add_link(links[0])
devices[0].add_link(links[3])
devices[1].add_link(links[0])
devices[1].add_link(links[1])
devices[2].add_link(links[1])
devices[2].add_link(links[2])
devices[3].add_link(links[3])
devices[3].add_link(links[2])
links[0].add_device(devices[0])
links[0].add_device(devices[1])
links[1].add_device(devices[1])
links[1].add_device(devices[2])
links[2].add_device(devices[2])
links[2].add_device(devices[3])
links[3].add_device(devices[3])
links[3].add_device(devices[0])
# def flow(data, start, source, destination, sim_env):
# yield sim_env.timeout(start)
# sim_env.process(devices[source].start_flow(data=data, destination=destination, env=sim_env))
# p = env.process(flow(data1, 1000, 0, 1, env))
def bell_it_up(env):
for i in range(200): # run 20 iterations
for router in devices:
router.send_router(env)
yield env.timeout(100)
def print_routing_table(router):
print('-------------')
print('router ' + str(router.ip))
for ip in router.routing_table:
print('destination: ' + str(ip) + ' link: ' + str(links.index(router.routing_table[ip])) + ' cost: ' + str(router.distance_table[ip]))
for router in devices:
print_routing_table(router)
print('LINK 0 COST INCREASE !!!!!')
links[0].link_rate = 1
for i in range(200): # run 20 iterations
for router in devices:
router.send_router(env)
yield env.timeout(100)
for router in devices:
print_routing_table(router)
p = env.process(bell_it_up(env))
env.run()
for device in devices:
device_name = "Device " + str(device.ip)
# device.graph_wsize.set_name(device_name)
# device.graph_wsize.plot()
for l in range(0, len(device.links)):
link = device.links[l]
link.graph_buffocc.set_name(device_name + " " + "Link " + str(l))
link.graph_buffocc.plot()