def route_new(self, lvl, dst, gw, rem, event_wait=None): if not self.multipath and self.maproute.node_get(lvl, dst).nroutes_synced() >= 1: # We don't have multipath and we've already set one route. return nip = self.maproute.lvlid_to_nip(lvl, dst) ip = self.maproute.nip_to_ip(nip) ipstr = ip_to_str(ip) neigh = self.neigh.id_to_neigh(gw) dev = neigh.bestdev[0] gwipstr = ip_to_str(neigh.ip) neigh_node = self.maproute.node_get(*self.maproute.routeneigh_get(neigh)) if neigh_node.nroutes() > 1: # Let's wait to add the neighbour first while 1: ev_neigh = event_wait[(self.neigh.events, 'NEIGH_NEW')]() if neigh == ev_neigh[0]: # found break if neigh_node.routes_tobe_synced > 0: # The routes to neigh are still to be synced, let's wait while 1: ev_neigh = event_wait[(self.events, 'KRNL_NEIGH_NEW')]() if neigh == ev_neigh[0]: # found break # We can add the route in the kernel KRoute.add(ipstr, lvl_to_bits(lvl), dev, gwipstr) self.maproute.node_get(lvl, dst).routes_tobe_synced-=1
def neigh_new(self, neigh): ipstr = ip_to_str(neigh.ip) dev = neigh.bestdev[0] gwipstr = ipstr KRoute.add(ipstr, lvl_to_bits(0), dev, gwipstr) self.events.send('KRNL_NEIGH_NEW', (neigh, ))
def neigh_new(self, neigh): ipstr = ip_to_str(neigh.ip) dev = neigh.bestdev[0] gwipstr = ipstr KRoute.add(ipstr, lvl_to_bits(0), dev, gwipstr) self.events.send('KRNL_NEIGH_NEW', (neigh,))
def route_deleted(self, lvl, dst, gw): nip = self.maproute.lvlid_to_nip(lvl, dst) ip = self.maproute.nip_to_ip(nip) ipstr = ip_to_str(ip) neigh = self.neigh.id_to_neigh(gw) dev = neigh.bestdev[0] gwipstr = ip_to_str(neigh.ip) KRoute.delete(ipstr, lvl_to_bits(lvl), gateway=gwipstr)
def run(self): if not self.simulated: Route.ip_forward(enable=True) for nic in self.nic_manager: self.nic_manager[nic].filtering(enable=False) rpc.MicroUDPServer(self, ('', 269), nic, self.simnet, self.simme, self.simsock) rpc.MicroTCPServer(self, ('', 269), None, self.simnet, self.simme, self.simsock) self.radar.run() self.hook.hook()
def route_new(self, lvl, dst, gw, rem, event_wait=None): if not self.multipath and self.maproute.node_get( lvl, dst).nroutes_synced() >= 1: # We don't have multipath and we've already set one route. return nip = self.maproute.lvlid_to_nip(lvl, dst) ip = self.maproute.nip_to_ip(nip) ipstr = ip_to_str(ip) neigh = self.neigh.id_to_neigh(gw) dev = neigh.bestdev[0] gwipstr = ip_to_str(neigh.ip) neigh_node = self.maproute.node_get( *self.maproute.routeneigh_get(neigh)) if neigh_node.nroutes() > 1: # Let's wait to add the neighbour first while 1: ev_neigh = event_wait[(self.neigh.events, 'NEIGH_NEW')]() if neigh == ev_neigh[0]: # found break if neigh_node.routes_tobe_synced > 0: # The routes to neigh are still to be synced, let's wait while 1: ev_neigh = event_wait[(self.events, 'KRNL_NEIGH_NEW')]() if neigh == ev_neigh[0]: # found break # We can add the route in the kernel KRoute.add(ipstr, lvl_to_bits(lvl), dev, gwipstr) self.maproute.node_get(lvl, dst).routes_tobe_synced -= 1
def neigh_deleted(self, neigh): ipstr = ip_to_str(neigh.ip) KRoute.delete(ipstr, lvl_to_bits(0))
def testEnableIPForwarding(self): ''' Test enable ip forwarding ''' Route.ip_forward()
def testFlushCache(self): ''' Test flush cache ''' Route.flush_cache()
def testFlushRoutes(self): ''' Test flush routes from `ntk' table ''' self.testAddRoute() Route.flush()
def testDeleteRoute(self): ''' Test remove a route ''' Route.delete(self.ip, self.cidr, dev='eth0')
def testAddRoute(self): ''' Test add a new route ''' Route.add(self.ip, self.cidr, dev='eth0')