0

i want to create a routing table for my simple network simulator. I need routing tables to be created automatically. I want this table to look this way:

[[destinationInterface, nextHop]
[destinationInterface, nextHop]]

So if router engine gets message addressed to destinationInterface, it sends it to nextHop. What I'm trying to do is this:

    for h in self.creator.interfaceList: #checking my all interfaces
        for c in h.connectionList: #checking my interfaces connections
            self.routingTable.append([c,c]) #add connection as reachable via c
            for ic in c.creator.interfaceList: #check all interfeces of c creator
                for i in ic.connectionList: # check all connections of interfaces of c
                    self.routingTable.append([i,c]) #add i as reachable via c, since one of my interfaces is connected to c
                    #and so on...

                    for ij in i.creator.interfaceList: 
                        for j in ij.connectionList:
                            #if self.creator.name=="ap2":
                             #   print j.name
                            self.routingTable.append([j,c])
                            for ih in h.creator.interfaceList: 
                                for y in ih.connectionList:
                                    self.routingTable.append([y,c])

But this doesn't work. And I'm really confused about lines that I've put # in front, because this code works different with or without them.

Kevin
  • 74,910
  • 12
  • 133
  • 166
tobi
  • 75
  • 1
  • 7
  • a few remarks, trying to be constructive here: - use variable names other than i, j, ij, ih, ic, c, .... - does not work is not too clear, a bit of diagnosing could help - the part with the #and so on might better be done using recursion? – ShadowFlame May 23 '13 at 12:10
  • I would also suggest breaking out your for loops into separate functions. Anytime you are this deep in nested for loops, you are too deep. – pedram May 23 '13 at 12:24
  • Thx for comments. I know that it would be much better to not use so many loops but i don't know how to use recursion here. And where it comes to names like ij i, ic, c etc these are names of interfeces, and with every for loop im going further so i dont know how to name them.For it works only for certain amount of nodes in network, but obviolusly its only beceuse i don't know how to make it better. – tobi May 23 '13 at 12:38

0 Answers0