Ejemplo n.º 1
0
def test_put_del_route_unreachable():
    kern = kernel.Kernel(log=None, log_id="", table_name="main")
    if not kern.platform_supported:
        return
    # Add unreachable prefix in the kernel routing table (no next hops)
    prefix = packet_common.make_ip_prefix("99.99.99.99/32")
    nhops = []
    rte = fib_route.FibRoute(prefix, nhops)
    assert kern.put_route(rte)
    tab_str = kern.cli_route_prefix_table(254, prefix).to_string()
    pattern = (r"[|] Table +[|] Main +[|]\n"
               r"[|] Address Family +[|] IPv4 +[|]\n"
               r"[|] Destination +[|] 99\.99\.99\.99/32 +[|]\n"
               r"[|] Type +[|] Unreachable +[|]\n"
               r"[|] Protocol +[|] RIFT +[|]\n"
               r"[|] Scope +[|] Universe +[|]\n"
               r"[|] Next-hops +[|]  +[|]\n"
               r"[|] Priority +[|] 199 +[|]\n")
    assert re.search(pattern, tab_str) is not None
    # Replace unreachable route with a route containing one next hop
    new_nhops = [next_hop.NextHop("lo", packet_common.make_ip_address("127.0.0.1"))]
    rte = fib_route.FibRoute(prefix, new_nhops)
    assert kern.put_route(rte)
    tab_str = kern.cli_route_prefix_table(254, prefix).to_string()
    pattern = (r"[|] Table +[|] Main +[|]\n"
               r"[|] Address Family +[|] IPv4 +[|]\n"
               r"[|] Destination +[|] 99\.99\.99\.99/32 +[|]\n"
               r"[|] Type +[|] Unicast +[|]\n"
               r"[|] Protocol +[|] RIFT +[|]\n"
               r"[|] Scope +[|] Universe +[|]\n"
               r"[|] Next-hops +[|] lo 127.0.0.1 +[|]\n"
               r"[|] Priority +[|] 199 +[|]\n")
    assert re.search(pattern, tab_str) is not None
    # Delete next hops
    assert kern.del_route(prefix)
Ejemplo n.º 2
0
def test_put_del_route():
    kern = Kernel(simulated_interfaces=False,
                  log=None,
                  log_id="",
                  table_name="5")
    if not kern.platform_supported:
        return
    # Put route with one next-hop (with interface but no address)
    prefix = make_ip_prefix("99.99.99.99/32")
    nhops = [NextHop(False, "lo", None, None)]
    rte = FibRoute(prefix, nhops)
    assert kern.put_route(rte)
    # Delete route just added
    assert kern.del_route(prefix)
    # Put route with one next-hop (with interface and address)
    prefix = make_ip_prefix("99.99.99.99/32")
    address = make_ip_address("127.0.0.1")
    nhops = [NextHop(False, "lo", address, None)]
    rte = FibRoute(prefix, nhops)
    assert kern.put_route(rte)
    # Delete route just added
    assert kern.del_route(prefix)
    # Put ECMP route with multiple next-hop (with interface and address)
    prefix = make_ip_prefix("99.99.99.99/32")
    address1 = make_ip_address("127.0.0.1")
    address2 = make_ip_address("127.0.0.2")
    nhops = [
        NextHop(False, "lo", address1, None),
        NextHop(False, "lo", address2, None)
    ]
    rte = FibRoute(prefix, nhops)
    assert kern.put_route(rte)
    # Do we display the ECMP route properly?
    tab_str = kern.cli_route_prefix_table(5, prefix).to_string()
    pattern = (r"[|] Table +[|] 5 +[|]\n"
               r"[|] Address Family +[|] IPv4 +[|]\n"
               r"[|] Destination +[|] 99\.99\.99\.99/32 +[|]\n"
               r"[|] Type +[|] Unicast +[|]\n"
               r"[|] Protocol +[|] RIFT +[|]\n"
               r"[|] Scope +[|] Universe +[|]\n"
               r"[|] Next-hops +[|] lo 127\.0\.0\.1 1 +[|]\n"
               r"[|] +[|] lo 127\.0\.0\.2 1 +[|]\n")
    assert re.search(pattern, tab_str) is not None
    # Delete route just added
    assert kern.del_route(prefix)
Ejemplo n.º 3
0
def mknh(interface_str, address_str):
    if address_str is None:
        address = None
    else:
        address = packet_common.make_ip_address(address_str)
    return next_hop.NextHop(interface_str, address)
Ejemplo n.º 4
0
def mknh(interface_str, address_str):
    if address_str is None:
        address = None
    else:
        address = make_ip_address(address_str)
    return NextHop(False, interface_str, address, None)