Ejemplo n.º 1
0
def test_put_del_route_unreachable():
    kern = Kernel(simulated_interfaces=False,
                  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 = make_ip_prefix("99.99.99.99/32")
    nhops = []
    rte = 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 = [NextHop(False, "lo", make_ip_address("127.0.0.1"), None)]
    rte = 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 test_cli_route_prefix_table():
    kern = Kernel(simulated_interfaces=False,
                  log=None,
                  log_id="",
                  table_name="main")
    if not kern.platform_supported:
        return
    # We assume that the main route table always has a default route, and we look for this:
    # +--------------------------+------------------+
    # | Table                    | Main             |
    # | Address Family           | IPv4             |
    # | Destination              | 0.0.0.0/0        |
    # | Type                     | Unicast          |
    # | Protocol                 | Boot             | << or Dhcp in some deployments
    # | Scope                    | Universe         |
    # | Next-hops                | eth0 172.17.0.1  |
    # | Priority                 |                  |
    # | Preference               |                  |
    # | Preferred Source Address |                  |
    # | Source                   |                  |
    # | Flow                     |                  |
    # | Encapsulation Type       |                  |
    # | Encapsulation            |                  |
    # | Metrics                  |                  |
    # | Type of Service          | 0                |
    # | Flags                    | 0                |
    # +--------------------------+------------------+
    default_prefix = make_ip_prefix("0.0.0.0/0")
    tab_str = kern.cli_route_prefix_table(254, default_prefix).to_string()
    pattern = (r"[|] Table +[|] Main +[|]\n"
               r"[|] Address Family +[|] IPv4 +[|]\n"
               r"[|] Destination +[|] 0\.0\.0\.0/0 +[|]\n"
               r"[|] Type +[|] Unicast +[|]\n"
               r"[|] Protocol +[|] (Boot|Dhcp) +[|]\n"
               r"[|] Scope +[|] Universe +[|]\n")
    assert re.search(pattern, tab_str) is not None