|
@@ -29,38 +29,10 @@ circuit = unpacket(pack)[1]
|
|
|
# send shit out to emulator
|
|
|
for i in circuit.getlink():
|
|
|
sock.sendto(hpacket(rid, i.getlid()).package(), (haddr, hport))
|
|
|
+
|
|
|
|
|
|
-# stores neighbours, topology db, and graph
|
|
|
-neighbours = []
|
|
|
-database = db(5) # change constant here to reflect network size
|
|
|
-graph = graph(5) # same as above
|
|
|
|
|
|
-# listen for network activity
|
|
|
-while (1):
|
|
|
- pack, addr = sock.recvfrom(4096)
|
|
|
- ptype, pack = unpacket(pack)
|
|
|
-
|
|
|
- # hello packet
|
|
|
- if (ptype == 1):
|
|
|
- # save hello in hellodb
|
|
|
- neighbours.append((pack.rid, pack.lid))
|
|
|
- # reply with the links from circuit sent individually as lspdus
|
|
|
- send_links(pack.lid)
|
|
|
- continue
|
|
|
- # lspdu packet
|
|
|
- elif (ptype == 2):
|
|
|
- # add router ID (link source), linkid, cost to db (only if not a dupe)
|
|
|
- conn = connection(pack.sid, pack.rid, None, pack.lid, pack.cost)
|
|
|
- database.insert(conn)
|
|
|
- # otherwise,send to all ppl that hello-d me (except who sent it) (but modify sid and slid)
|
|
|
- continue
|
|
|
- # undefined behaviour
|
|
|
- else:
|
|
|
- print("Recieved unexpected packet. Dropping.")
|
|
|
- continue
|
|
|
-
|
|
|
-print("Unexpected end of program.")
|
|
|
-
|
|
|
+# CLASS AND FUNCTION DEFINITIONS
|
|
|
# sends out our circuit as lspdus over link
|
|
|
def send_links(link):
|
|
|
for i in circuit.getlinks():
|
|
@@ -188,4 +160,37 @@ class graph:
|
|
|
if (mindexsofar == curnode):
|
|
|
break
|
|
|
|
|
|
- print("SSSP: this.sssp")
|
|
|
+ print("SSSP: this.sssp")
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+# stores neighbours, topology db, and graph
|
|
|
+neighbours = []
|
|
|
+database = db(5) # change constant here to reflect network size
|
|
|
+graph = graph(5) # same as above
|
|
|
+
|
|
|
+# listen for network activity
|
|
|
+while (1):
|
|
|
+ pack, addr = sock.recvfrom(4096)
|
|
|
+ ptype, pack = unpacket(pack)
|
|
|
+
|
|
|
+ # hello packet
|
|
|
+ if (ptype == 1):
|
|
|
+ # save hello in hellodb
|
|
|
+ neighbours.append((pack.rid, pack.lid))
|
|
|
+ # reply with the links from circuit sent individually as lspdus
|
|
|
+ send_links(pack.lid)
|
|
|
+ continue
|
|
|
+ # lspdu packet
|
|
|
+ elif (ptype == 2):
|
|
|
+ # add router ID (link source), linkid, cost to db (only if not a dupe)
|
|
|
+ conn = connection(pack.sid, pack.rid, None, pack.lid, pack.cost)
|
|
|
+ database.insert(conn)
|
|
|
+ # otherwise,send to all ppl that hello-d me (except who sent it) (but modify sid and slid)
|
|
|
+ continue
|
|
|
+ # undefined behaviour
|
|
|
+ else:
|
|
|
+ print("Recieved unexpected packet. Dropping.")
|
|
|
+ continue
|
|
|
+
|
|
|
+print("Unexpected end of program.")
|