我想为我的简单网络模拟器创建一个路由表。我需要自动创建路由表。我希望这张表看起来像这样:
[[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])
但这不起作用。而且我真的很困惑我把 # 放在前面的行,因为无论有没有它们,这段代码的工作方式都不同。