-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
82 lines (70 loc) · 1.93 KB
/
main.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
from node0 import Node0
from node1 import Node1
from node2 import Node2
from node3 import Node3
import time
def tolayer2(rtpkt):
#unpack the packet
sourceID = rtpkt.sourceID
destID = rtpkt.destID
minCost = rtpkt.minCost
#call the appropriate rtupdate function
if destID == 0:
node0.rtupdate0(rtpkt)
elif destID == 1:
node1.rtupdate1(rtpkt)
elif destID == 2:
node2.rtupdate2(rtpkt)
elif destID == 3:
node3.rtupdate3(rtpkt)
def printNodes():
print("****************************************************")
node0.printDistanceTable()
node1.printDistanceTable()
node2.printDistanceTable()
node3.printDistanceTable()
print("****************************************************")
# time.sleep(1)
################ MAIN ##################
#create nodes
node0 = Node0()
node1 = Node1()
node2 = Node2()
node3 = Node3()
#set up node neighbors
node0.addNeighbors(node1,node2,node3)
node1.addNeighbors(node0,node2)
node2.addNeighbors(node0,node1,node3)
node3.addNeighbors(node0,node2)
#init the nodes
node0.rtinit0()
node1.rtinit1()
node2.rtinit2()
node3.rtinit3()
# print(node0.distanceTable[0][3]) # prints 7
# print(node1.distanceTable)
isProgramRunning = True
while (isProgramRunning):
if len(node0.myPacketsToSend) != 0:
while len(node0.myPacketsToSend) > 0:
packet = node0.myPacketsToSend.pop(0)
tolayer2(packet)
printNodes()
elif len(node1.myPacketsToSend) != 0:
while len(node1.myPacketsToSend) > 0:
packet = node1.myPacketsToSend.pop(0)
tolayer2(packet)
printNodes()
elif len(node2.myPacketsToSend) != 0:
while len(node2.myPacketsToSend) > 0:
packet = node2.myPacketsToSend.pop(0)
tolayer2(packet)
printNodes()
elif len(node3.myPacketsToSend) != 0:
while len(node3.myPacketsToSend) > 0:
packet = node3.myPacketsToSend.pop(0)
tolayer2(packet)
printNodes()
else:
break
print("-------------------Program done------------------")