Пример #1
0
def test_add_prefix_tie():
    packet_common.add_missing_methods_to_thrift()
    test_node = make_test_node()
    prefix_tie_packet_1 = packet_common.make_prefix_tie_packet(
        direction=common.ttypes.TieDirectionType.South,
        originator=222,
        tie_nr=333,
        seq_nr=444)
    timestamp = common.ttypes.IEEE802_1ASTimeStampType(AS_sec=12345)
    monotonic_clock = common.ttypes.PrefixSequenceType(timestamp=timestamp)
    packet_common.add_ipv4_prefix_to_prefix_tie(
        prefix_tie_packet_1, packet_common.make_ipv4_prefix("1.2.3.0/24"), 2,
        [77, 88], monotonic_clock)
    packet_common.add_ipv6_prefix_to_prefix_tie(
        prefix_tie_packet_1, packet_common.make_ipv6_prefix("1234:abcd::/64"),
        3)
    test_node.store_tie_packet(prefix_tie_packet_1, 555)
    prefix_tie_packet_2 = packet_common.make_prefix_tie_packet(
        direction=common.ttypes.TieDirectionType.North,
        originator=777,
        tie_nr=888,
        seq_nr=999)
    packet_common.add_ipv4_prefix_to_prefix_tie(
        prefix_tie_packet_2, packet_common.make_ipv4_prefix("0.0.0.0/0"), 10)
    test_node.store_tie_packet(prefix_tie_packet_2, 0)
    db_packet_info = test_node.find_tie_packet_info(
        prefix_tie_packet_1.header.tieid)
    db_tie_packet = db_packet_info.protocol_packet.content.tie
    assert db_tie_packet == prefix_tie_packet_1
    db_packet_info = test_node.find_tie_packet_info(
        prefix_tie_packet_2.header.tieid)
    db_tie_packet = db_packet_info.protocol_packet.content.tie
    assert db_tie_packet == prefix_tie_packet_2
    missing_tie_id = encoding.ttypes.TIEID(
        direction=common.ttypes.TieDirectionType.South,
        originator=321,
        tietype=common.ttypes.TIETypeType.PrefixTIEType,
        tie_nr=654)
    assert test_node.find_tie_packet_info(missing_tie_id) is None
    tab = test_node.tie_db_table()
    tab_str = tab.to_string()
    assert (
        tab_str ==
        "+-----------+------------+--------+--------+--------+----------+------------------------+\n"
        "| Direction | Originator | Type   | TIE Nr | Seq Nr | Lifetime | Contents               |\n"
        "+-----------+------------+--------+--------+--------+----------+------------------------+\n"
        "| South     | 222        | Prefix | 333    | 444    | 555      | Prefix: 1.2.3.0/24     |\n"
        "|           |            |        |        |        |          |   Metric: 2            |\n"
        "|           |            |        |        |        |          |   Tag: 77              |\n"
        "|           |            |        |        |        |          |   Tag: 88              |\n"
        "|           |            |        |        |        |          |   Monotonic-clock:     |\n"
        "|           |            |        |        |        |          |     Timestamp: 12345   |\n"
        "|           |            |        |        |        |          | Prefix: 1234:abcd::/64 |\n"
        "|           |            |        |        |        |          |   Metric: 3            |\n"
        "+-----------+------------+--------+--------+--------+----------+------------------------+\n"
        "| North     | 777        | Prefix | 888    | 999    | 0        | Prefix: 0.0.0.0/0      |\n"
        "|           |            |        |        |        |          |   Metric: 10           |\n"
        "+-----------+------------+--------+--------+--------+----------+------------------------+\n"
    )
Пример #2
0
def test_add_prefix_tie():
    packet_common.add_missing_methods_to_thrift()
    test_node = make_test_node()
    prefix_tie_packet_1 = packet_common.make_prefix_tie_packet(
        direction=common.ttypes.TieDirectionType.South,
        originator=222,
        tie_nr=333,
        seq_nr=444,
        lifetime=555)
    packet_common.add_ipv4_prefix_to_prefix_tie(
        prefix_tie_packet_1, packet_common.make_ipv4_prefix("1.2.3.0/24"), 2,
        [77, 88], 12345)
    packet_common.add_ipv6_prefix_to_prefix_tie(
        prefix_tie_packet_1, packet_common.make_ipv6_prefix("1234:abcd::/64"),
        3)
    test_node.store_tie_packet(prefix_tie_packet_1)
    prefix_tie_packet_2 = packet_common.make_prefix_tie_packet(
        direction=common.ttypes.TieDirectionType.North,
        originator=777,
        tie_nr=888,
        seq_nr=999,
        lifetime=0)
    packet_common.add_ipv4_prefix_to_prefix_tie(
        prefix_tie_packet_2, packet_common.make_ipv4_prefix("0.0.0.0/0"), 10)
    test_node.store_tie_packet(prefix_tie_packet_2)
    assert test_node.find_tie_meta(
        prefix_tie_packet_1.header.tieid).tie_packet == prefix_tie_packet_1
    assert test_node.find_tie_meta(
        prefix_tie_packet_2.header.tieid).tie_packet == prefix_tie_packet_2
    missing_tie_id = encoding.ttypes.TIEID(
        direction=common.ttypes.TieDirectionType.South,
        originator=321,
        tietype=common.ttypes.TIETypeType.PrefixTIEType,
        tie_nr=654)
    assert test_node.find_tie_meta(missing_tie_id) is None
    tab = test_node.tie_db_table()
    tab_str = tab.to_string()
    assert (
        tab_str ==
        "+-----------+------------+--------+--------+--------+----------+--------------------------+\n"
        "| Direction | Originator | Type   | TIE Nr | Seq Nr | Lifetime | Contents                 |\n"
        "+-----------+------------+--------+--------+--------+----------+--------------------------+\n"
        "| South     | 222        | Prefix | 333    | 444    | 555      | Prefix: 1.2.3.0/24       |\n"
        "|           |            |        |        |        |          |   Metric: 2              |\n"
        "|           |            |        |        |        |          |   Tag: 77                |\n"
        "|           |            |        |        |        |          |   Tag: 88                |\n"
        "|           |            |        |        |        |          |   Monotonic-clock: 12345 |\n"
        "|           |            |        |        |        |          | Prefix: 1234:abcd::/64   |\n"
        "|           |            |        |        |        |          |   Metric: 3              |\n"
        "+-----------+------------+--------+--------+--------+----------+--------------------------+\n"
        "| North     | 777        | Prefix | 888    | 999    | 0        | Prefix: 0.0.0.0/0        |\n"
        "|           |            |        |        |        |          |   Metric: 10             |\n"
        "+-----------+------------+--------+--------+--------+----------+--------------------------+\n"
    )
Пример #3
0
def make_test_node(db_tie_info_list=None):
    if db_tie_info_list is None:
        db_tie_info_list = []
    config = {
        "name": "test",
        "systemid": MY_SYSTEM_ID,
        "skip-self-orginated-ties": True
    }
    test_node = node.Node(config)
    for db_tie_info in db_tie_info_list:
        (direction, origin, tietype, tie_nr, seq_nr, lifetime) = db_tie_info
        if tietype == NODE:
            db_tie_packet = packet_common.make_node_tie_packet(
                name=MY_NAME,
                level=MY_LEVEL,
                direction=direction,
                originator=origin,
                tie_nr=tie_nr,
                seq_nr=seq_nr)
        elif tietype == PREFIX:
            db_tie_packet = packet_common.make_prefix_tie_packet(
                direction, origin, tie_nr, seq_nr)
        else:
            assert False
        test_node.store_tie_packet(db_tie_packet, lifetime)
    return test_node
Пример #4
0
def make_rx_tie_packet(header_info):
    (direction, origin, prefixtype, tie_nr, seq_nr, _lifetime,
     _disposition) = header_info
    if prefixtype == NODE:
        rx_tie_packet = packet_common.make_node_tie_packet(name=MY_NAME,
                                                           level=MY_LEVEL,
                                                           direction=direction,
                                                           originator=origin,
                                                           tie_nr=tie_nr,
                                                           seq_nr=seq_nr)
    elif prefixtype == PREFIX:
        rx_tie_packet = packet_common.make_prefix_tie_packet(
            direction, origin, tie_nr, seq_nr)
    else:
        assert False
    return rx_tie_packet