def test_fix_key_value_tie_packet(): packet_common.add_missing_methods_to_thrift() tie_protocol_packet = encoding.ttypes.ProtocolPacket( header=encoding.ttypes.PacketHeader( major_version=packet_common.MAX_U16, minor_version=packet_common.MAX_U16, sender=packet_common.MAX_U64, level=packet_common.MAX_U16 ), content=encoding.ttypes.PacketContent( lie=None, tide=None, tire=None, tie=encoding.ttypes.TIEPacket( header=max_tie_header(), element=encoding.ttypes.TIEElement( node=None, prefixes=None, positive_disaggregation_prefixes=None, negative_disaggregation_prefixes=None, external_prefixes=None, keyvalues=encoding.ttypes.KeyValueTIEElement( keyvalues={ "one": "een", "two": "twee" } ) ) ) ) ) encoded_packet = packet_common.encode_protocol_packet(tie_protocol_packet) decoded_tie_protocol_packet = packet_common.decode_protocol_packet(encoded_packet) assert tie_protocol_packet == decoded_tie_protocol_packet
def test_fix_tire_packet(): packet_common.add_missing_methods_to_thrift() tire_protocol_packet = encoding.ttypes.ProtocolPacket( header=encoding.ttypes.PacketHeader( major_version=packet_common.MAX_U16, minor_version=packet_common.MAX_U16, sender=packet_common.MAX_U64, level=packet_common.MAX_U16 ), content=encoding.ttypes.PacketContent( lie=None, tide=None, tire=encoding.ttypes.TIREPacket( headers=set([ max_tie_header(0), max_tie_header(1), max_tie_header(2) ]) ), tie=None ) ) encoded_packet = packet_common.encode_protocol_packet(tire_protocol_packet) decoded_tire_protocol_packet = packet_common.decode_protocol_packet(encoded_packet) assert tire_protocol_packet == decoded_tire_protocol_packet
def test_fix_lie_packet(): packet_common.add_missing_methods_to_thrift() lie_protocol_packet = encoding.ttypes.ProtocolPacket( header=encoding.ttypes.PacketHeader( major_version=packet_common.MAX_U16, minor_version=packet_common.MAX_U16, sender=packet_common.MAX_U64, level=packet_common.MAX_U16), content=encoding.ttypes.PacketContent(lie=encoding.ttypes.LIEPacket( name="name", local_id=packet_common.MAX_U32, flood_port=packet_common.MAX_U16, link_mtu_size=packet_common.MAX_U32, link_bandwidth=packet_common.MAX_U32, neighbor=encoding.ttypes.Neighbor(originator=packet_common.MAX_U64, remote_id=packet_common.MAX_U32), pod=packet_common.MAX_U32, nonce=packet_common.MAX_U16, last_neighbor_nonce=packet_common.MAX_U16, node_capabilities=encoding.ttypes.NodeCapabilities( flood_reduction=True, hierarchy_indications=common.ttypes.HierarchyIndications. leaf_only), link_capabilities=encoding.ttypes.LinkCapabilities(bfd=False, ), holdtime=packet_common.MAX_U16, not_a_ztp_offer=True, you_are_flood_repeater=True, label=packet_common.MAX_U32), tide=None, tire=None, tie=None)) encoded_packet = packet_common.encode_protocol_packet(lie_protocol_packet) decoded_lie_protocol_packet = packet_common.decode_protocol_packet( encoded_packet) assert lie_protocol_packet == decoded_lie_protocol_packet
def receive_mcast_message(self, message, from_address_and_port): # TODO: Handle decoding errors (does decode_protocol_packet throw an exception in # that case? Try it...) protocol_packet = decode_protocol_packet(message) if self._rx_fail: self.debug(self._tx_log, "Failed receive {}".format(protocol_packet)) return if protocol_packet.header.sender == self._node.system_id: self.debug(self._rx_log, "Looped receive {}".format(protocol_packet)) return self.debug(self._rx_log, "Receive {}".format(protocol_packet)) if not protocol_packet.content: self.warning(self._rx_log, "Received packet without content") return if protocol_packet.content.lie: event_data = (protocol_packet, from_address_and_port) self._fsm.push_event(self.Event.LIE_RECEIVED, event_data) if protocol_packet.content.tide: # TODO: process TIDE pass if protocol_packet.content.tire: # TODO: process TIDE pass if protocol_packet.content.tie: # TODO: process TIDE pass
def test_fix_node_tie_packet(): packet_common.add_missing_methods_to_thrift() tie_protocol_packet = encoding.ttypes.ProtocolPacket( header=encoding.ttypes.PacketHeader( major_version=packet_common.MAX_U16, minor_version=packet_common.MAX_U16, sender=packet_common.MAX_U64, level=packet_common.MAX_U16 ), content=encoding.ttypes.PacketContent( lie=None, tide=None, tire=None, tie=encoding.ttypes.TIEPacket( header=max_tie_header(), element=encoding.ttypes.TIEElement( node=encoding.ttypes.NodeTIEElement( level=packet_common.MAX_U16, neighbors={ max_system_id(0): max_neighbor(), max_system_id(1): max_neighbor(), max_system_id(2): max_neighbor() }, capabilities=encoding.ttypes.NodeCapabilities( flood_reduction=True, hierarchy_indications=common.ttypes.HierarchyIndications.leaf_only ), flags=encoding.ttypes.NodeFlags( overload=True ), name="name" ), prefixes=None, positive_disaggregation_prefixes=None, negative_disaggregation_prefixes=None, external_prefixes=None, keyvalues=None ) ) ) ) encoded_packet = packet_common.encode_protocol_packet(tie_protocol_packet) decoded_tie_protocol_packet = packet_common.decode_protocol_packet(encoded_packet) assert tie_protocol_packet == decoded_tie_protocol_packet
def receive_message_common(self, message, from_address_and_port): (address, port) = from_address_and_port from_str = "{}:{}".format(address, port) protocol_packet = packet_common.decode_protocol_packet(message) if protocol_packet is None: self.rx_error("Could not decode message received from %s", from_str) return None if self._rx_fail: self.rx_debug("Simulated receive failure %s from %s", protocol_packet, from_str) return None if protocol_packet.header.sender == self._node.system_id: self.rx_debug("Looped receive %s from %s", protocol_packet, from_str) return None self.rx_debug("Receive %s from %s", protocol_packet, from_str) if not protocol_packet.content: self.rx_warning("Received packet without content from %s", from_str) return None if protocol_packet.header.major_version != constants.RIFT_MAJOR_VERSION: self.rx_error("Received different major protocol version from %s (local version %d, " "remote version %d)", from_str, constants.RIFT_MAJOR_VERSION, protocol_packet.header.major_version) return None return protocol_packet