def test_eq(self, route1, route2, result): route1 = Route.fromString(route1) route2 = Route.fromString(route2) if result: assert route1 == route2 else: assert not (route1 == route2)
def test_lt(self, route1, route2, lt_1): route1 = Route.fromString(route1) route2 = Route.fromString(route2) if lt_1: assert route1 < route2 else: assert not (route1 < route2)
def test_copy(self, route1): route = Route.fromString(route1) route_copy = copy.copy(route) assert not id(route) == id(route_copy) assert id(route.addr) == id(route_copy.addr) assert id(route.nh) == id(route_copy.nh) assert id(route.policy_value) == id(route_copy.policy_value)
def __evaluate_pkt(self, row_value: str) -> str: """__evaluate_pkt. Evaluate a single pkt row of the DF, it will return the compressed string corresponding to the row, A{ID} for an advertisement or W{ID} for a withdraw, the id corresponds to the route in the route_to_id DataFrame :param row_value: row of the dataframe that contains a packet that needs to be analyzed :type row_value: str :rtype: str """ # Get the packet and the route transmitted packet = Packet.fromString(row_value) route = Route.fromString(packet.content) tmp_pv = PolicyValue(0) route.policy_value = tmp_pv # If the route is not in the DataFrane of routes add it if hash(route) not in self.routes.index: self.routes.loc[hash(route)] = self.__get_route_data(route) # Check the packet type and return the corresponding compressed version if packet.packet_type == Packet.UPDATE: return "A" + str( self.routes.loc[hash(route)][NodeAnalyzer.ROUTES_COLUMNS[1]]) if packet.packet_type == Packet.WITHDRAW: return "W" + str( self.routes.loc[hash(route)][NodeAnalyzer.ROUTES_COLUMNS[1]]) print("Something very bad happened") sys.exit(2)
def test_deepcopy(self, route1): route = Route.fromString(route1) route_copy = copy.deepcopy(route) assert not id(route) == id(route_copy) assert not id(route.addr) == id(route_copy.addr) assert not id(route.path) == id(route_copy.path) assert not id(route.policy_value) == id(route_copy.policy_value) route_copy.nh=150 assert route.nh != route_copy.nh
def __evaluate_figure_of_merit_event(self, time: str, value: str) -> None: obj = ast.literal_eval(value) route = Route.fromString(obj[0]) figure_of_merit = obj[1] _id = hash(str(route.addr) + str(route.nh)) self.rfd = self.rfd.append(dict( zip(NodeAnalyzer.RFD_COLUMNS, [_id, time, route, figure_of_merit, False])), ignore_index=True)
def __statate_swap_variation(self, rx_value: str, new_state: set) -> set: pkt = Packet.fromString(rx_value) route = Route.fromString(pkt.content) route.policy_value = PolicyValue(0) self.experiment_actual_state = new_state.copy() new_state = self.actual_state.copy() for row_value, row_nh in zip( self.routes[NodeAnalyzer.ROUTES_COLUMNS[1]], self.routes[NodeAnalyzer.ROUTES_COLUMNS[3]]): if row_nh == route.nh: if row_value in new_state: new_state.remove(row_value) new_state.add( self.routes.loc[hash(route)][NodeAnalyzer.ROUTES_COLUMNS[1]]) return new_state
def __statate_incremental_variation(self, rx_value: str, new_state: set) -> set: pkt = Packet.fromString(rx_value) route = Route.fromString(pkt.content) route.policy_value = PolicyValue(0) if pkt.packet_type == Packet.UPDATE: self.experiment_actual_state = new_state.copy() new_state = self.actual_state.copy() new_state.add( self.routes.loc[hash(route)][NodeAnalyzer.ROUTES_COLUMNS[1]]) elif pkt.packet_type == Packet.WITHDRAW: self.experiment_actual_state = new_state.copy() new_state = self.actual_state.copy() new_state.remove( self.routes.loc[hash(route)][NodeAnalyzer.ROUTES_COLUMNS[1]]) return new_state
def __evaluate_rfd_state(self, time: float, event: int, value: str) -> None: route = Route.fromString(value) if event == Events.ROUTE_REUSABLE or event == Events.END_T_HOLD: # The route is now usable again, set every element after as suppressed False suppressed = False else: # The route has been suppressed suppressed = True _id = hash(str(route.addr) + str(route.nh)) self.rfd.suppressed[(self.rfd.id == _id) & (self.rfd.time >= time)] = suppressed if len(self.rfd[(self.rfd.time == time)].index) > 1: self.rfd.suppressed.loc[self.rfd[( self.rfd.time == time)].index[0]] = not suppressed
def test_fromString(self, addr, path, nh, str_version): ipaddr = ipaddress.ip_network(addr) route = Route(ipaddr, path, nh) route_str = Route.fromString(str_version) assert route == Route.fromString(str(route)) assert route == route_str