我想为我的简单网络模拟器创建一个路由表。我需要自动创建路由表。我希望这个表看起来像这样:
[[destinationInterface, nextHop]
[destinationInterface, nextHop]]
因此,如果路由器引擎获取发往destinationInterface的消息,它会将其发送到nextHop。 我想要做的是:
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])
但这不起作用。而且我真的很困惑我把#放在前面的行,因为这段代码在有或没有它们的情况下会有所不同。