def check_process_tire_common(test_node, header_info_list): # pylint:disable=too-many-locals # Prepare the TIRE packet tire = packet_common.make_tire_packet() for header_info in header_info_list: (direction, originator, _prefixtype, tie_nr, seq_nr, lifetime, _disposition) = header_info tie_header = packet_common.make_tie_header(direction, originator, PREFIX, tie_nr, seq_nr, lifetime) packet_common.add_tie_header_to_tire(tire, tie_header) # Process the TIRE packet result = test_node.process_received_tire_packet(tire) (request_tie_headers, start_sending_tie_headers, acked_tie_headers) = result # Check results compare_header_lists( tie_headers_with_disposition(test_node, header_info_list, [REQUEST_OLDER]), request_tie_headers) compare_header_lists( tie_headers_with_disposition(test_node, header_info_list, [START_NEWER]), start_sending_tie_headers) compare_header_lists( tie_headers_with_disposition(test_node, header_info_list, [ACK]), acked_tie_headers)
def check_process_tide_common(test_node, start_range, end_range, header_info_list): # pylint:disable=too-many-locals # Prepare the TIDE packet tide_packet = packet_common.make_tide_packet(start_range, end_range) for header_info in header_info_list: (direction, originator, _prefixtype, tie_nr, seq_nr, lifetime, disposition) = header_info # START_EXTRA refers to a TIE-ID which is only in the TIE-DB and not in the TIDE, so don't # add those. if disposition != START_EXTRA: tie_header = packet_common.make_tie_header(direction, originator, PREFIX, tie_nr, seq_nr, lifetime) packet_common.add_tie_header_to_tide(tide_packet, tie_header) # Process the TIDE packet result = test_node.process_received_tide_packet(tide_packet) (request_tie_headers, start_sending_tie_headers, stop_sending_tie_headers) = result # Check results compare_header_lists( tie_headers_with_disposition(test_node, header_info_list, [REQUEST_MISSING, REQUEST_OLDER]), request_tie_headers) compare_header_lists( tie_headers_with_disposition(test_node, header_info_list, [START_EXTRA, START_NEWER]), start_sending_tie_headers) compare_header_lists( tie_headers_with_disposition(test_node, header_info_list, [STOP_SAME]), stop_sending_tie_headers)
def tie_headers_with_disposition(test_node, header_info_list, filter_dispositions): tie_headers = [] for header_info in header_info_list: (direction, originator, _tietype, tie_nr, seq_nr, lifetime, disposition) = header_info if disposition in filter_dispositions: if disposition in [START_EXTRA, START_NEWER]: tie_id = packet_common.make_tie_id(direction, originator, PREFIX, tie_nr) seq_nr = test_node.ties[tie_id].header.seq_nr lifetime = test_node.ties[tie_id].header.remaining_lifetime elif disposition == REQUEST_MISSING: seq_nr = 0 lifetime = 0 tie_header = packet_common.make_tie_header(direction, originator, PREFIX, tie_nr, seq_nr, lifetime) tie_headers.append(tie_header) return tie_headers
def test_generate_tide_packet(): packet_common.add_missing_methods_to_thrift() db_tie_info_list = [ # pylint:disable=bad-whitespace # Direction Origin Type TieNr SeqNr Lifetime Allowed in TIDE (SOUTH, 55, PREFIX, 2, 4, 600 ), # No : Non-node S-TIE to S, not self-originated (SOUTH, MY_SYSTEM_ID, PREFIX, 18, 903, 400) ] # Yes: Non-node S-TIE to S, self-originated test_node = make_test_node(db_tie_info_list) tide_packet = test_node.generate_tide_packet( neighbor_direction=SOUTH, neighbor_system_id=55, neighbor_level=8, neighbor_is_top_of_fabric=False, my_level=MY_LEVEL, i_am_top_of_fabric=True) assert tide_packet.start_range == node.Node.MIN_TIE_ID assert tide_packet.end_range == node.Node.MAX_TIE_ID assert len(tide_packet.headers) == 1 expected_header = packet_common.make_tie_header(SOUTH, MY_SYSTEM_ID, PREFIX, 18, 903, 400) assert tide_packet.headers[0] == expected_header
def test_is_flood_allowed(): # pylint:disable=too-many-locals packet_common.add_missing_methods_to_thrift() test_node = make_test_node() # Node 66 is same level as me node_66_tie = packet_common.make_node_tie_packet(name="node66", level=MY_LEVEL, direction=SOUTH, originator=66, tie_nr=5, seq_nr=7, lifetime=300) test_node.store_tie(node_66_tie) # Node 77 has higher level than me node_77_tie = packet_common.make_node_tie_packet(name="node77", level=MY_LEVEL + 1, direction=SOUTH, originator=77, tie_nr=3, seq_nr=2, lifetime=400) test_node.store_tie(node_77_tie) # Node 88 has lower level than me node_88_tie = packet_common.make_node_tie_packet(name="node88", level=MY_LEVEL - 1, direction=SOUTH, originator=88, tie_nr=7, seq_nr=3, lifetime=400) test_node.store_tie(node_88_tie) tx_tie_info_list = [ # pylint:disable=bad-whitespace # Neighbor Neighbor I am Allowed Reason # Direction Originator Type, Tie-Nr Seq-Nr Lifetime Direction System-ID ToF (SOUTH, 66, NODE, 5, 7, 400, SOUTH, 22, False, True, "Node S-TIE to S: originator level is same as from-node"), (SOUTH, 77, NODE, 3, 2, 300, SOUTH, 18, False, False, "Node S-TIE to S: originator level is not same as from-node"), (SOUTH, 55, NODE, 8, 12, 500, NORTH, 17, False, False, "Node S-TIE to N: could not determine originator level"), (SOUTH, 77, NODE, 3, 3, 200, NORTH, 17, True, True, "Node S-TIE to N: originator level is higher than from-node"), (SOUTH, 88, NODE, 7, 3, 400, NORTH, 19, False, False, "Node S-TIE to N: originator level is not higher than from-node"), (SOUTH, 55, NODE, 8, 12, 550, EW, 19, True, False, "Node S-TIE to EW: from-node is top of fabric"), (SOUTH, 55, NODE, 8, 12, 550, EW, 19, False, True, "Node S-TIE to EW: from-node is not top of fabric"), (SOUTH, 55, NODE, 8, 12, 550, None, 19, False, False, "Node S-TIE to ?: never flood"), (SOUTH, MY_SYSTEM_ID, PREFIX, 4, 7, 200, SOUTH, 20, False, True, "Non-node S-TIE to S: self-originated"), (SOUTH, 55, PREFIX, 2, 4, 600, SOUTH, 20, True, False, "Non-node S-TIE to S: not self-originated"), (SOUTH, MY_SYSTEM_ID, PREFIX, 18, 903, 400, SOUTH, 33, True, True, "Non-node S-TIE to S: self-originated"), (SOUTH, 55, PREFIX, 2, 4, 600, NORTH, 55, False, True, "Non-node S-TIE to N: to-node is originator of TIE"), (SOUTH, 55, PREFIX, 2, 4, 600, NORTH, 33, False, False, "Non-node S-TIE to N: to-node is not originator of TIE"), (SOUTH, 55, PREFIX, 2, 4, 600, EW, 33, True, False, "Non-node S-TIE to EW: this top of fabric"), (SOUTH, MY_SYSTEM_ID, PREFIX, 18, 903, 400, EW, 33, False, True, "Non-node S-TIE to EW: self-originated and not top of fabric"), (SOUTH, 55, PREFIX, 2, 4, 600, EW, 33, False, False, "Non-node S-TIE to EW: not self-originated"), (SOUTH, 55, PREFIX, 2, 4, 600, None, 33, True, False, "None-node S-TIE to ?: never flood"), (NORTH, 55, NODE, 3, 3, 500, SOUTH, 20, False, False, "N-TIE to S: never flood"), (NORTH, 55, PREFIX, 2, 4, 500, SOUTH, 20, True, False, "N-TIE to S: never flood"), (NORTH, 55, NODE, 3, 3, 500, NORTH, 20, False, True, "N-TIE to N: always flood"), (NORTH, 55, PREFIX, 2, 4, 500, NORTH, 20, True, True, "N-TIE to N: always flood"), (NORTH, 55, NODE, 3, 3, 500, EW, 20, True, True, "N-TIE to EW: top of fabric"), (NORTH, 55, NODE, 3, 3, 500, EW, 20, False, False, "N-TIE to EW: not top of fabric"), (NORTH, 55, NODE, 3, 3, 500, None, 20, False, False, "N-TIE to ?: never flood") ] for tx_tie_info in tx_tie_info_list: (direction, originator, tietype, tie_nr, seq_nr, lifetime, neighbor_direction, neighbor_system_id, i_am_top_of_fabric, expected_allowed, expected_reason) = tx_tie_info tie_header = packet_common.make_tie_header(direction, originator, tietype, tie_nr, seq_nr, lifetime) (allowed, reason) = test_node.is_flood_allowed( tie_header=tie_header, to_node_direction=neighbor_direction, to_node_system_id=neighbor_system_id, from_node_system_id=MY_SYSTEM_ID, from_node_level=MY_LEVEL, from_node_is_top_of_fabric=i_am_top_of_fabric) assert allowed == expected_allowed, expected_reason assert reason == expected_reason
def test_compare_tie_header(): # Exactly same header1 = packet_common.make_tie_header(direction=NORTH, originator=1, tie_type=PREFIX, tie_nr=6, seq_nr=7, lifetime=500) header2 = packet_common.make_tie_header(direction=NORTH, originator=1, tie_type=PREFIX, tie_nr=6, seq_nr=7, lifetime=500) assert node.compare_tie_header_age(header1, header2) == 0 # Almost same, lifetime is different but close enough to call it same (within 300 seconds) header1 = packet_common.make_tie_header(direction=NORTH, originator=1, tie_type=PREFIX, tie_nr=6, seq_nr=7, lifetime=1) header2 = packet_common.make_tie_header(direction=NORTH, originator=1, tie_type=PREFIX, tie_nr=6, seq_nr=7, lifetime=300) assert node.compare_tie_header_age(header1, header2) == 0 # Different: lifetime is the tie breaker (more than 300 seconds difference) header1 = packet_common.make_tie_header(direction=NORTH, originator=1, tie_type=PREFIX, tie_nr=6, seq_nr=7, lifetime=1) header2 = packet_common.make_tie_header(direction=NORTH, originator=1, tie_type=PREFIX, tie_nr=6, seq_nr=7, lifetime=600) assert node.compare_tie_header_age(header1, header2) == -1 assert node.compare_tie_header_age(header2, header1) == 1 # Different: lifetime is the tie breaker; the difference is less than 300 but one is zero and # the other is non-zero. The one with zero lifetime is considered older. header1 = packet_common.make_tie_header(direction=NORTH, originator=1, tie_type=PREFIX, tie_nr=6, seq_nr=7, lifetime=0) header2 = packet_common.make_tie_header(direction=NORTH, originator=1, tie_type=PREFIX, tie_nr=6, seq_nr=7, lifetime=299) assert node.compare_tie_header_age(header1, header2) == -1 assert node.compare_tie_header_age(header2, header1) == 1 # Different: seq_nr is the tie breaker. header1 = packet_common.make_tie_header(direction=NORTH, originator=1, tie_type=PREFIX, tie_nr=6, seq_nr=20, lifetime=1) header2 = packet_common.make_tie_header(direction=NORTH, originator=1, tie_type=PREFIX, tie_nr=6, seq_nr=19, lifetime=600) assert node.compare_tie_header_age(header1, header2) == 1 assert node.compare_tie_header_age(header2, header1) == -1