mardi 21 avril 2015

Python - Distance Vector routing simulation

Vote count: 0

I am using python to Simulate Distance vector routing. The goal is to create 4 routers and have them communicate and get the lowest cost.

I have to display each update on each router. Below I have the code for 1 of my routers. I believe this code should work as I have pieced it together from my server client version which worked for just the two communicating.

I am having an issue figuring out how to finish the code and get it to stop after all the updates are complete.

import socket, pickle
import sys

s = socket.socket()

host = ''
port = 50421

try:
    s.bind((host, port))
except (s.error , msg):
    print ('Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1])
    sys.exit()

print ('Socket bind complete')
s.listen(4)

print ('Got connection from', addr)

table = [0,1,3,7]
router = 0;

print ('Router 0:', repr(table))

while 1:
data = router.recv(4095) 
data_arr = pickle.loads(data)

data = router.recv(4095)
otherRouter = pickle.loads(data)

print ('Router'repr(router)':', repr(data_arr))
print (' ')

for i in range(0, 4):
    if data_arr[i] + table[otherRouter] < table[i]: 
        table[i] = data_arr[i] + table[otherRouter]
        print (' ')
    print ('Adjusted Router 0:', repr(table))
    print (' ')
    else 
    print ('Nothing to update')

data_string = pickle.dumps(table)
client.send(data_string)
print (' ')
data_string = pickle.dumps(router)
client.send(data_string)
print (' ')
if 

asked 38 secs ago



Python - Distance Vector routing simulation

Aucun commentaire:

Enregistrer un commentaire