コード例 #1
0
def test_recover_default_next_hop_with_subnet_disagg():
    rib = Rib()
    default_route = RibRoute(default_prefix, S_SPF, default_next_hops)
    rib.put_route(default_route)
    first_disagg_route = RibRoute(first_negative_disagg_prefix, S_SPF, [], first_negative_disagg_next_hops)
    rib.put_route(first_disagg_route)
    subnet_disagg_route = RibRoute(subnet_disagg_prefix, S_SPF, [], subnet_negative_disagg_next_hops)
    rib.put_route(subnet_disagg_route)
    default_route_fail = RibRoute(default_prefix, S_SPF, ['S1', 'S2', 'S4'])
    rib.put_route(default_route_fail)
    default_route_recover = RibRoute(default_prefix, S_SPF, ['S1', 'S2', 'S3', 'S4'])
    rib.put_route(default_route_recover)
    # Test for default
    assert rib.destinations.get(default_prefix).best_route == default_route_recover
    assert rib.destinations.get(default_prefix).best_route.positive_next_hops == {'S1', 'S2', 'S3', 'S4'}
    assert rib.destinations.get(default_prefix).best_route.negative_next_hops == set()
    assert rib.destinations.get(default_prefix).best_route.next_hops == {'S1', 'S2', 'S3', 'S4'}
    assert rib.fib.routes[default_prefix].next_hops == default_route_recover.next_hops
    assert rib.fib.kernel.routes[default_prefix] == default_route_recover.next_hops
    # Test for 10.0.0.0/16
    assert rib.destinations.get(first_negative_disagg_prefix).best_route.positive_next_hops == set()
    assert rib.destinations.get(first_negative_disagg_prefix).best_route.negative_next_hops == {'S1'}
    assert rib.destinations.get(first_negative_disagg_prefix).best_route.next_hops == {'S2', 'S3', 'S4'}
    assert rib.fib.kernel.routes[first_negative_disagg_prefix] == first_disagg_route.next_hops
    # Test for 10.0.10.0/24
    assert rib.destinations.get(subnet_disagg_prefix).best_route.positive_next_hops == set()
    assert rib.destinations.get(subnet_disagg_prefix).best_route.negative_next_hops == {'S2'}
    assert rib.destinations.get(subnet_disagg_prefix).best_route.next_hops == {'S3', 'S4'}
    assert rib.fib.kernel.routes[subnet_disagg_prefix] == subnet_disagg_route.next_hops
コード例 #2
0
def test_remove_default_route():
    rib = Rib()
    default_route = RibRoute(default_prefix, S_SPF, default_next_hops)
    rib.put_route(default_route)
    first_disagg_route = RibRoute(first_negative_disagg_prefix, S_SPF, [], first_negative_disagg_next_hops)
    rib.put_route(first_disagg_route)
    subnet_disagg_route = RibRoute(subnet_disagg_prefix, S_SPF, [], subnet_negative_disagg_next_hops)
    rib.put_route(subnet_disagg_route)
    rib.del_route(default_prefix, S_SPF)
    # Test for default
    assert not rib.destinations.has_key(default_prefix)
    assert default_prefix not in rib.fib.routes
    assert default_prefix not in rib.fib.kernel.routes
    # Test for 10.0.0.0/16
    assert rib.destinations.get(first_negative_disagg_prefix).parent_prefix_dest is None
    assert rib.destinations.get(first_negative_disagg_prefix).best_route.positive_next_hops == set()
    assert rib.destinations.get(first_negative_disagg_prefix).best_route.negative_next_hops == {'S1'}
    assert rib.destinations.get(first_negative_disagg_prefix).best_route.next_hops == set()
    assert rib.fib.routes[first_negative_disagg_prefix].next_hops == set()
    assert rib.fib.kernel.routes[first_negative_disagg_prefix] == "unreachable"
    # Test for 10.0.10.0/24
    assert rib.destinations.get(subnet_disagg_prefix).best_route.positive_next_hops == set()
    assert rib.destinations.get(subnet_disagg_prefix).best_route.negative_next_hops == {'S2'}
    assert rib.destinations.get(subnet_disagg_prefix).best_route.next_hops == set()
    assert rib.fib.routes[subnet_disagg_prefix].next_hops == set()
    assert rib.fib.kernel.routes[subnet_disagg_prefix] == "unreachable"
コード例 #3
0
def test_add_two_route_same_destination_with_subnet_and_remove_one():
    rib = Rib()
    default_route = RibRoute(default_prefix, N_SPF, default_next_hops)
    rib.put_route(default_route)
    best_default_route = RibRoute(default_prefix, S_SPF, ["S1", "S2", "S3"])
    rib.put_route(best_default_route)
    first_disagg_route = RibRoute(first_negative_disagg_prefix, S_SPF, [], first_negative_disagg_next_hops)
    rib.put_route(first_disagg_route)
    subnet_disagg_route = RibRoute(subnet_disagg_prefix, S_SPF, [], subnet_negative_disagg_next_hops)
    rib.put_route(subnet_disagg_route)
    rib.del_route(default_prefix, S_SPF)
    # Test for default
    assert rib.destinations.get(default_prefix).best_route == default_route
    assert rib.destinations.get(default_prefix).best_route.positive_next_hops == {'S1', 'S2', 'S3', 'S4'}
    assert rib.destinations.get(default_prefix).best_route.negative_next_hops == set()
    assert rib.destinations.get(default_prefix).best_route.next_hops == {'S1', 'S2', 'S3', 'S4'}
    assert rib.fib.routes[default_prefix].next_hops == default_route.next_hops
    assert rib.fib.kernel.routes[default_prefix] == default_route.next_hops
    # Test for 10.0.0.0/16
    assert rib.destinations.get(first_negative_disagg_prefix).best_route == first_disagg_route
    assert rib.destinations.get(first_negative_disagg_prefix).best_route.positive_next_hops == set()
    assert rib.destinations.get(first_negative_disagg_prefix).best_route.negative_next_hops == {'S1'}
    assert rib.destinations.get(first_negative_disagg_prefix).best_route.next_hops == {'S2', 'S3', 'S4'}
    assert rib.fib.routes[first_negative_disagg_prefix].next_hops == first_disagg_route.next_hops
    assert rib.fib.kernel.routes[first_negative_disagg_prefix] == first_disagg_route.next_hops
    # Test for 10.0.10.0/24
    assert rib.destinations.get(subnet_disagg_prefix).best_route == subnet_disagg_route
    assert rib.destinations.get(subnet_disagg_prefix).best_route.positive_next_hops == set()
    assert rib.destinations.get(subnet_disagg_prefix).best_route.negative_next_hops == {'S2'}
    assert rib.destinations.get(subnet_disagg_prefix).best_route.next_hops == {'S3', 'S4'}
    assert rib.fib.routes[subnet_disagg_prefix].next_hops == subnet_disagg_route.next_hops
    assert rib.fib.kernel.routes[subnet_disagg_prefix] == subnet_disagg_route.next_hops
コード例 #4
0
def test_remove_default_next_hop():
    rib = Rib()
    default_route = RibRoute(default_prefix, S_SPF, default_next_hops)
    rib.put_route(default_route)
    first_disagg_route = RibRoute(first_negative_disagg_prefix, S_SPF, [], first_negative_disagg_next_hops)
    rib.put_route(first_disagg_route)
    second_disagg_route = RibRoute(second_negative_disagg_prefix, S_SPF, [], second_negative_disagg_next_hops)
    rib.put_route(second_disagg_route)
    default_route_fail = RibRoute(default_prefix, S_SPF, ['S1', 'S3', 'S4'])
    rib.put_route(default_route_fail)
    # Test for default
    assert rib.destinations.get(default_prefix).best_route == default_route_fail
    assert rib.destinations.get(default_prefix).best_route.positive_next_hops == {'S1', 'S3', 'S4'}
    assert rib.destinations.get(default_prefix).best_route.negative_next_hops == set()
    assert rib.destinations.get(default_prefix).best_route.next_hops == {'S1', 'S3', 'S4'}
    assert rib.fib.routes[default_prefix].next_hops == default_route_fail.next_hops
    assert rib.fib.kernel.routes[default_prefix] == default_route_fail.next_hops
    # Test for 10.0.0.0/16
    assert rib.destinations.get(first_negative_disagg_prefix).best_route.positive_next_hops == set()
    assert rib.destinations.get(first_negative_disagg_prefix).best_route.negative_next_hops == {'S1'}
    assert rib.destinations.get(first_negative_disagg_prefix).best_route.next_hops == {'S3', 'S4'}
    assert rib.fib.kernel.routes[first_negative_disagg_prefix] == first_disagg_route.next_hops
    # Test for 10.1.0.0/16
    assert rib.destinations.get(second_negative_disagg_prefix).best_route.positive_next_hops == set()
    assert rib.destinations.get(second_negative_disagg_prefix).best_route.negative_next_hops == {'S4'}
    assert rib.destinations.get(second_negative_disagg_prefix).best_route.next_hops == {'S1', 'S3'}
    assert rib.fib.kernel.routes[second_negative_disagg_prefix] == second_disagg_route.next_hops
コード例 #5
0
def test_str():
    route = RibRoute("1.0.0.0/8", ["nh1", "nh2"], ["nh3", "nh4"])
    assert str(route) == "1.0.0.0/8 -> nh1, nh2, ~nh3, ~nh4"
    route = RibRoute("1.2.0.0/16", ["nh3", "nh1"], ["nh4", "nh2"])
    assert str(route) == "1.2.0.0/16 -> nh1, ~nh2, nh3, ~nh4"
    route = RibRoute("1.2.3.0/24", ["nh1"], [])
    assert str(route) == "1.2.3.0/24 -> nh1"
    route = RibRoute("1.2.3.4/32", [], ["nh1"])
    assert str(route) == "1.2.3.4/32 -> ~nh1"
    route = RibRoute("0.0.0.0/0", [], [])
    assert str(route) == "0.0.0.0/0 -> "
コード例 #6
0
def test_pos_neg_disagg():
    rib = Rib()
    default_route = RibRoute(default_prefix, S_SPF, default_next_hops)
    rib.put_route(default_route)
    leaf_route = RibRoute(leaf_prefix, S_SPF, leaf_prefix_positive_next_hops, leaf_prefix_negative_next_hops)
    rib.put_route(leaf_route)
    assert rib.destinations.get(leaf_prefix).best_route.positive_next_hops == {"M4"}
    assert rib.destinations.get(leaf_prefix).best_route.negative_next_hops == {"M3"}
    assert rib.destinations.get(leaf_prefix).best_route.next_hops == {"S4", "S3", "M4", "S2", "S1"}
    assert rib.fib.routes[leaf_prefix].next_hops == leaf_route.next_hops
    assert rib.fib.kernel.routes[leaf_prefix] == {"S4", "S3", "M4", "S2", "S1"}
コード例 #7
0
def test_neg_disagg_fib_unreachable():
    rib = Rib()
    default_route = RibRoute(default_prefix, S_SPF, default_next_hops)
    rib.put_route(default_route)
    unreachable_route = RibRoute(unreachable_prefix, S_SPF, [], unreachable_negative_next_hops)
    rib.put_route(unreachable_route)
    assert rib.destinations.get(unreachable_prefix).best_route.positive_next_hops == set()
    assert rib.destinations.get(unreachable_prefix).best_route.negative_next_hops == {'S1', 'S2', 'S3', 'S4'}
    assert rib.destinations.get(unreachable_prefix).best_route.next_hops == set()
    assert rib.fib.routes[unreachable_prefix].next_hops == unreachable_route.next_hops
    assert rib.fib.kernel.routes[unreachable_prefix] == "unreachable"
コード例 #8
0
def test_remove_superfluous_subnet():
    rib = Rib()
    default_route = RibRoute(default_prefix, S_SPF, default_next_hops)
    rib.put_route(default_route)
    first_disagg_route = RibRoute(first_negative_disagg_prefix, S_SPF, [], first_negative_disagg_next_hops)
    rib.put_route(first_disagg_route)
    subnet_disagg_route = RibRoute(subnet_disagg_prefix, S_SPF, [], subnet_negative_disagg_next_hops)
    rib.put_route(subnet_disagg_route)
    rib.del_route(subnet_disagg_prefix, S_SPF)
    assert not rib.destinations.has_key(subnet_disagg_prefix)
    assert subnet_disagg_prefix not in rib.fib.routes
    assert subnet_disagg_prefix not in rib.fib.kernel.routes
コード例 #9
0
def test_add_negative_disaggregation():
    rib = Rib()
    default_route = RibRoute(default_prefix, S_SPF, default_next_hops)
    rib.put_route(default_route)
    neg_route = RibRoute(first_negative_disagg_prefix, S_SPF, [], first_negative_disagg_next_hops)
    rib.put_route(neg_route)
    assert rib.destinations.get(first_negative_disagg_prefix).best_route == neg_route
    assert rib.destinations.get(first_negative_disagg_prefix).best_route.positive_next_hops == set()
    assert rib.destinations.get(first_negative_disagg_prefix).best_route.negative_next_hops == {'S1'}
    assert rib.destinations.get(first_negative_disagg_prefix).best_route.next_hops == {'S2', 'S3', 'S4'}
    assert rib.fib.routes[first_negative_disagg_prefix].next_hops == neg_route.next_hops
    assert rib.fib.kernel.routes[first_negative_disagg_prefix] == neg_route.next_hops
コード例 #10
0
def test_add_two_route_same_destination():
    rib = Rib()
    default_route = RibRoute(default_prefix, N_SPF, default_next_hops)
    rib.put_route(default_route)
    best_default_route = RibRoute(default_prefix, S_SPF, ['S1'])
    rib.put_route(best_default_route)
    assert rib.destinations.get(default_prefix).best_route == best_default_route
    assert rib.destinations.get(default_prefix).best_route.positive_next_hops == {'S1'}
    assert rib.destinations.get(default_prefix).best_route.negative_next_hops == set()
    assert rib.destinations.get(default_prefix).best_route.next_hops == {'S1'}
    assert rib.fib.routes[default_prefix].next_hops == best_default_route.next_hops
    assert rib.fib.kernel.routes[default_prefix] == best_default_route.next_hops
コード例 #11
0
def test_remove_best_route():
    rib = Rib()
    default_route = RibRoute(default_prefix, N_SPF, default_next_hops)
    rib.put_route(default_route)
    best_default_route = RibRoute(default_prefix, S_SPF, ['S1'])
    rib.put_route(best_default_route)
    rib.del_route(default_prefix, S_SPF)
    assert rib.destinations.get(default_prefix).best_route == default_route
    assert rib.destinations.get(default_prefix).best_route.positive_next_hops == {'S1', 'S2', 'S3', 'S4'}
    assert rib.destinations.get(default_prefix).best_route.negative_next_hops == set()
    assert rib.destinations.get(default_prefix).best_route.next_hops == {'S1', 'S2', 'S3', 'S4'}
    assert rib.fib.routes[default_prefix].next_hops == default_route.next_hops
    assert rib.fib.kernel.routes[default_prefix] == default_route.next_hops
コード例 #12
0
def test_pos_neg_disagg_recursive():
    rib = Rib()
    default_route = RibRoute(default_prefix, S_SPF, default_next_hops)
    rib.put_route(default_route)
    first_disagg_route = RibRoute(first_negative_disagg_prefix, S_SPF, [], first_negative_disagg_next_hops)
    rib.put_route(first_disagg_route)
    subnet_disagg_route = RibRoute(subnet_disagg_prefix, S_SPF, ["S1"], subnet_negative_disagg_next_hops)
    rib.put_route(subnet_disagg_route)
    assert rib.destinations.get(subnet_disagg_prefix).best_route.positive_next_hops == {"S1"}
    assert rib.destinations.get(subnet_disagg_prefix).best_route.negative_next_hops == {"S2"}
    assert rib.destinations.get(subnet_disagg_prefix).best_route.next_hops == {"S1", "S3", "S4"}
    assert rib.fib.routes[subnet_disagg_prefix].next_hops == subnet_disagg_route.next_hops
    assert rib.fib.kernel.routes[subnet_disagg_prefix] == {"S1", "S3", "S4"}
コード例 #13
0
def test_add_subnet_disagg_to_first_negative_disagg():
    rib = Rib()
    default_route = RibRoute(default_prefix, S_SPF, default_next_hops)
    rib.put_route(default_route)
    first_disagg_route = RibRoute(first_negative_disagg_prefix, S_SPF, [], first_negative_disagg_next_hops)
    rib.put_route(first_disagg_route)
    subnet_disagg_route = RibRoute(subnet_disagg_prefix, S_SPF, [], subnet_negative_disagg_next_hops)
    rib.put_route(subnet_disagg_route)
    assert rib.destinations.get(subnet_disagg_prefix).best_route.positive_next_hops == set()
    assert rib.destinations.get(subnet_disagg_prefix).best_route.negative_next_hops == {'S2'}
    assert rib.destinations.get(subnet_disagg_prefix).best_route.next_hops == {'S3', 'S4'}
    assert rib.fib.routes[subnet_disagg_prefix].next_hops == subnet_disagg_route.next_hops
    assert rib.fib.kernel.routes[subnet_disagg_prefix] == subnet_disagg_route.next_hops
コード例 #14
0
def test_add_default_route():
    rib = Rib()
    default_route = RibRoute(default_prefix, S_SPF, default_next_hops)
    rib.put_route(default_route)
    assert rib.destinations.get(default_prefix).best_route == default_route
    assert rib.destinations.get(default_prefix).best_route.next_hops == {'S1', 'S2', 'S3', 'S4'}
    assert rib.fib.routes[default_prefix].next_hops == default_route.next_hops
    assert rib.fib.kernel.routes[default_prefix] == default_route.next_hops
コード例 #15
0
def test_add_subnet_disagg_recursive_unreachable():
    rib = Rib()
    default_route = RibRoute(default_prefix, S_SPF, default_next_hops)
    rib.put_route(default_route)
    first_disagg_route = RibRoute(first_negative_disagg_prefix, S_SPF, [], first_negative_disagg_next_hops)
    rib.put_route(first_disagg_route)
    subnet_disagg_route = RibRoute(subnet_disagg_prefix, S_SPF, [], subnet_negative_disagg_next_hops)
    rib.put_route(subnet_disagg_route)
    first_neg_unreach = RibRoute(first_negative_disagg_prefix, S_SPF, [], unreachable_negative_next_hops)
    rib.put_route(first_neg_unreach)
    assert rib.destinations.get(first_negative_disagg_prefix).best_route.positive_next_hops == set()
    assert rib.destinations.get(first_negative_disagg_prefix).best_route.negative_next_hops == {'S1', 'S2', 'S3', 'S4'}
    assert rib.destinations.get(first_negative_disagg_prefix).best_route.next_hops == set()
    assert rib.fib.routes[first_negative_disagg_prefix].next_hops == first_neg_unreach.next_hops
    assert rib.fib.kernel.routes[first_negative_disagg_prefix] == "unreachable"
    assert not rib.destinations.has_key(subnet_disagg_prefix)
    assert subnet_disagg_prefix not in rib.fib.routes
コード例 #16
0
def test_remove_superfluous_subnet_recursive():
    rib = Rib()
    default_route = RibRoute(default_prefix, S_SPF, default_next_hops)
    rib.put_route(default_route)
    first_disagg_route = RibRoute(first_negative_disagg_prefix, S_SPF, [], first_negative_disagg_next_hops)
    rib.put_route(first_disagg_route)
    subnet_disagg_route = RibRoute(subnet_disagg_prefix, S_SPF, [], subnet_negative_disagg_next_hops)
    rib.put_route(subnet_disagg_route)
    rib.del_route(first_negative_disagg_prefix, S_SPF)
    assert not rib.destinations.has_key(first_negative_disagg_prefix)
    assert first_negative_disagg_prefix not in rib.fib.routes
    assert first_negative_disagg_prefix not in rib.fib.kernel.routes
    assert rib.destinations.get(subnet_disagg_prefix).best_route.positive_next_hops == set()
    assert rib.destinations.get(subnet_disagg_prefix).best_route.negative_next_hops == {'S2'}
    assert rib.destinations.get(subnet_disagg_prefix).best_route.next_hops == {'S1', 'S3', 'S4'}
    assert rib.fib.routes[subnet_disagg_prefix].next_hops == subnet_disagg_route.next_hops
    assert rib.fib.kernel.routes[subnet_disagg_prefix] == subnet_disagg_route.next_hops
    assert rib.destinations.get(subnet_disagg_prefix).parent_prefix_dest == rib.destinations.get(default_prefix)
    def put_route(self, prefix, positive_nexthops, negative_nexthops=None):

        # Put the route in the RIB.
        if negative_nexthops is None:
            negative_nexthops = []
        route = RibRoute(prefix, positive_nexthops, negative_nexthops)
        self._routes[prefix] = route

        # Gather the entire subtree of prefixes (children, grandchildren, ...) below the given
        # prefix (including the prefix itself). We rely on the fact that PyTricia.children always
        # returns parent aggregate routes before child more specific routes (although the PyTricia
        # documentation doesn't guarantee this).
        subtree_prefixes = [prefix] + self._routes.children(prefix)

        # Recompute the computed nexthops of child routes in the subtree and update the FIB
        # accordingly.
        self._recompute_subtree_nexthops(subtree_prefixes)
コード例 #18
0
def test_property_prefix():
    route = RibRoute("1.0.0.0/8", ["nh1", "nh2"], ["nh3", "nh4"])
    assert route.prefix == "1.0.0.0/8"
コード例 #19
0
def test_prop_deep_nesting():
    # Deep nesting of more specific routes: parent, child, grand child, grand-grand child, ...
    rib = Rib()
    # Default route
    new_default_next_hops = ['S1', 'S2', 'S3', 'S4', 'S5']
    new_default_route = RibRoute(default_prefix, S_SPF, new_default_next_hops)
    rib.put_route(new_default_route)
    # Child route
    child_prefix = '1.0.0.0/8'
    child_route = RibRoute(child_prefix, S_SPF, [], ['S1'])
    rib.put_route(child_route)
    # Grand child route
    g_child_prefix = '1.128.0.0/9'
    g_child_route = RibRoute(g_child_prefix, S_SPF, [], ['S2'])
    rib.put_route(g_child_route)
    # Grand-grand child route
    gg_child_prefix = '1.192.0.0/10'
    gg_child_route = RibRoute(gg_child_prefix, S_SPF, [], ['S3'])
    rib.put_route(gg_child_route)
    # Grand-grand-grand child route
    ggg_child_prefix = '1.224.0.0/11'
    ggg_child_route = RibRoute(ggg_child_prefix, S_SPF, [], ['S4'])
    rib.put_route(ggg_child_route)
    # Grand-grand-grand-grand child route
    gggg_child_prefix = '1.240.0.0/12'
    gggg_child_route = RibRoute(gggg_child_prefix, S_SPF, [], ['S5'])
    rib.put_route(gggg_child_route)

    # Default route asserts
    assert rib.destinations.get(default_prefix).best_route == new_default_route
    assert rib.destinations.get(default_prefix).best_route.next_hops == {'S1', 'S2', 'S3', 'S4', 'S5'}
    assert rib.fib.routes[default_prefix].next_hops == new_default_route.next_hops
    assert rib.fib.kernel.routes[default_prefix] == new_default_route.next_hops
    # Child route asserts
    assert rib.destinations.get(child_prefix).best_route == child_route
    assert rib.destinations.get(child_prefix).best_route.next_hops == {'S2', 'S3', 'S4', 'S5'}
    assert rib.fib.routes[child_prefix].next_hops == child_route.next_hops
    assert rib.fib.kernel.routes[child_prefix] == child_route.next_hops
    # Grand-child route asserts
    assert rib.destinations.get(g_child_prefix).best_route == g_child_route
    assert rib.destinations.get(g_child_prefix).best_route.next_hops == {'S3', 'S4', 'S5'}
    assert rib.fib.routes[g_child_prefix].next_hops == g_child_route.next_hops
    assert rib.fib.kernel.routes[g_child_prefix] == g_child_route.next_hops
    # Grand-grand child route asserts
    assert rib.destinations.get(gg_child_prefix).best_route == gg_child_route
    assert rib.destinations.get(gg_child_prefix).best_route.next_hops == {'S4', 'S5'}
    assert rib.fib.routes[gg_child_prefix].next_hops == gg_child_route.next_hops
    assert rib.fib.kernel.routes[gg_child_prefix] == gg_child_route.next_hops
    # Grand-grand-grand child route asserts
    assert rib.destinations.get(ggg_child_prefix).best_route == ggg_child_route
    assert rib.destinations.get(ggg_child_prefix).best_route.next_hops == {'S5'}
    assert rib.fib.routes[ggg_child_prefix].next_hops == ggg_child_route.next_hops
    assert rib.fib.kernel.routes[ggg_child_prefix] == ggg_child_route.next_hops
    # Grand-grand-grand-grand child route asserts
    assert rib.destinations.get(gggg_child_prefix).best_route == gggg_child_route
    assert rib.destinations.get(gggg_child_prefix).best_route.next_hops == set()
    assert rib.fib.routes[gggg_child_prefix].next_hops == gggg_child_route.next_hops
    assert rib.fib.kernel.routes[gggg_child_prefix] == 'unreachable'

    # Delete S3 from default route
    new_default_route = RibRoute(default_prefix, S_SPF, ['S1', 'S2', 'S4', 'S5'])
    rib.put_route(new_default_route)

    # Default route asserts
    assert rib.destinations.get(default_prefix).best_route == new_default_route
    assert rib.destinations.get(default_prefix).best_route.next_hops == {'S1', 'S2', 'S4', 'S5'}
    assert rib.fib.routes[default_prefix].next_hops == new_default_route.next_hops
    assert rib.fib.kernel.routes[default_prefix] == new_default_route.next_hops
    # Child route asserts
    assert rib.destinations.get(child_prefix).best_route == child_route
    assert rib.destinations.get(child_prefix).best_route.next_hops == {'S2', 'S4', 'S5'}
    assert rib.fib.routes[child_prefix].next_hops == child_route.next_hops
    assert rib.fib.kernel.routes[child_prefix] == child_route.next_hops
    # Grand-child route asserts
    assert rib.destinations.get(g_child_prefix).best_route == g_child_route
    assert rib.destinations.get(g_child_prefix).best_route.next_hops == {'S4', 'S5'}
    assert rib.fib.routes[g_child_prefix].next_hops == g_child_route.next_hops
    assert rib.fib.kernel.routes[g_child_prefix] == g_child_route.next_hops
    # Grand-grand child route asserts
    assert rib.destinations.get(gg_child_prefix).best_route == gg_child_route
    assert rib.destinations.get(gg_child_prefix).best_route.next_hops == {'S4', 'S5'}
    assert rib.fib.routes[gg_child_prefix].next_hops == gg_child_route.next_hops
    assert rib.fib.kernel.routes[gg_child_prefix] == gg_child_route.next_hops
    # Grand-grand-grand child route asserts
    assert rib.destinations.get(ggg_child_prefix).best_route == ggg_child_route
    assert rib.destinations.get(ggg_child_prefix).best_route.next_hops == {'S5'}
    assert rib.fib.routes[ggg_child_prefix].next_hops == ggg_child_route.next_hops
    assert rib.fib.kernel.routes[ggg_child_prefix] == ggg_child_route.next_hops
    # Grand-grand-grand-grand child route asserts
    assert rib.destinations.get(gggg_child_prefix).best_route == gggg_child_route
    assert rib.destinations.get(gggg_child_prefix).best_route.next_hops == set()
    assert rib.fib.routes[gggg_child_prefix].next_hops == gggg_child_route.next_hops
    assert rib.fib.kernel.routes[gggg_child_prefix] == 'unreachable'

    rib.del_route(default_prefix, S_SPF)
    # Default route asserts
    assert not rib.destinations.has_key(default_prefix)
    # Child route asserts
    assert rib.destinations.get(child_prefix).best_route == child_route
    assert rib.destinations.get(child_prefix).best_route.next_hops == set()
    assert rib.fib.routes[child_prefix].next_hops == set()
    assert rib.fib.kernel.routes[child_prefix] == 'unreachable'
    # Grand-child route asserts
    assert rib.destinations.get(g_child_prefix).best_route == g_child_route
    assert rib.destinations.get(g_child_prefix).best_route.next_hops == set()
    assert rib.fib.routes[g_child_prefix].next_hops == set()
    assert rib.fib.kernel.routes[g_child_prefix] == 'unreachable'
    # Grand-grand child route asserts
    assert rib.destinations.get(gg_child_prefix).best_route == gg_child_route
    assert rib.destinations.get(gg_child_prefix).best_route.next_hops == set()
    assert rib.fib.routes[gg_child_prefix].next_hops ==  set()
    assert rib.fib.kernel.routes[gg_child_prefix] == 'unreachable'
    # Grand-grand-grand child route asserts
    assert rib.destinations.get(ggg_child_prefix).best_route == ggg_child_route
    assert rib.destinations.get(ggg_child_prefix).best_route.next_hops == set()
    assert rib.fib.routes[ggg_child_prefix].next_hops == set()
    assert rib.fib.kernel.routes[ggg_child_prefix] == 'unreachable'
    # Grand-grand-grand-grand child route asserts
    assert rib.destinations.get(gggg_child_prefix).best_route == gggg_child_route
    assert rib.destinations.get(gggg_child_prefix).best_route.next_hops == set()
    assert rib.fib.routes[gggg_child_prefix].next_hops == set()
    assert rib.fib.kernel.routes[gggg_child_prefix] == 'unreachable'

    rib.del_route(child_prefix, S_SPF)
    # Child route asserts
    assert not rib.destinations.has_key(child_prefix)
    # Grand-child route asserts
    assert rib.destinations.get(g_child_prefix).best_route == g_child_route
    assert rib.destinations.get(g_child_prefix).best_route.next_hops == set()
    assert rib.fib.routes[g_child_prefix].next_hops == set()
    assert rib.fib.kernel.routes[g_child_prefix] == 'unreachable'
    # Grand-grand child route asserts
    assert rib.destinations.get(gg_child_prefix).best_route == gg_child_route
    assert rib.destinations.get(gg_child_prefix).best_route.next_hops == set()
    assert rib.fib.routes[gg_child_prefix].next_hops ==  set()
    assert rib.fib.kernel.routes[gg_child_prefix] == 'unreachable'
    # Grand-grand-grand child route asserts
    assert rib.destinations.get(ggg_child_prefix).best_route == ggg_child_route
    assert rib.destinations.get(ggg_child_prefix).best_route.next_hops == set()
    assert rib.fib.routes[ggg_child_prefix].next_hops == set()
    assert rib.fib.kernel.routes[ggg_child_prefix] == 'unreachable'
    # Grand-grand-grand-grand child route asserts
    assert rib.destinations.get(gggg_child_prefix).best_route == gggg_child_route
    assert rib.destinations.get(gggg_child_prefix).best_route.next_hops == set()
    assert rib.fib.routes[gggg_child_prefix].next_hops == set()
    assert rib.fib.kernel.routes[gggg_child_prefix] == 'unreachable'

    rib.del_route(g_child_prefix, S_SPF)
    # Grand-child route asserts
    assert not rib.destinations.has_key(g_child_prefix)
    # Grand-grand child route asserts
    assert rib.destinations.get(gg_child_prefix).best_route == gg_child_route
    assert rib.destinations.get(gg_child_prefix).best_route.next_hops == set()
    assert rib.fib.routes[gg_child_prefix].next_hops ==  set()
    assert rib.fib.kernel.routes[gg_child_prefix] == 'unreachable'
    # Grand-grand-grand child route asserts
    assert rib.destinations.get(ggg_child_prefix).best_route == ggg_child_route
    assert rib.destinations.get(ggg_child_prefix).best_route.next_hops == set()
    assert rib.fib.routes[ggg_child_prefix].next_hops == set()
    assert rib.fib.kernel.routes[ggg_child_prefix] == 'unreachable'
    # Grand-grand-grand-grand child route asserts
    assert rib.destinations.get(gggg_child_prefix).best_route == gggg_child_route
    assert rib.destinations.get(gggg_child_prefix).best_route.next_hops == set()
    assert rib.fib.routes[gggg_child_prefix].next_hops == set()
    assert rib.fib.kernel.routes[gggg_child_prefix] == 'unreachable'

    rib.del_route(gg_child_prefix, S_SPF)
    # Grand-child route asserts
    assert not rib.destinations.has_key(gg_child_prefix)
    # Grand-grand-grand child route asserts
    assert rib.destinations.get(ggg_child_prefix).best_route == ggg_child_route
    assert rib.destinations.get(ggg_child_prefix).best_route.next_hops == set()
    assert rib.fib.routes[ggg_child_prefix].next_hops == set()
    assert rib.fib.kernel.routes[ggg_child_prefix] == 'unreachable'
    # Grand-grand-grand-grand child route asserts
    assert rib.destinations.get(gggg_child_prefix).best_route == gggg_child_route
    assert rib.destinations.get(gggg_child_prefix).best_route.next_hops == set()
    assert rib.fib.routes[gggg_child_prefix].next_hops == set()
    assert rib.fib.kernel.routes[gggg_child_prefix] == 'unreachable'

    rib.del_route(ggg_child_prefix, S_SPF)
    # Grand-child route asserts
    assert not rib.destinations.has_key(ggg_child_prefix)
    # Grand-grand-grand-grand child route asserts
    assert rib.destinations.get(gggg_child_prefix).best_route == gggg_child_route
    assert rib.destinations.get(gggg_child_prefix).best_route.next_hops == set()
    assert rib.fib.routes[gggg_child_prefix].next_hops == set()
    assert rib.fib.kernel.routes[gggg_child_prefix] == 'unreachable'

    rib.del_route(gggg_child_prefix, S_SPF)
    # Grand-grand-grand-grand child route asserts
    assert not rib.destinations.has_key(gggg_child_prefix)

    assert not rib.destinations.keys()
    assert not rib.fib.routes.keys()
    assert not rib.fib.kernel.routes.keys()
コード例 #20
0
def test_constructor():
    _route = RibRoute("1.0.0.0/8", ["nh1", "nh2"], ["nh3", "nh4"])
コード例 #21
0
def test_set_computed_nexthops():
    route = RibRoute("1.0.0.0/8", ["nh1", "nh2"], ["nh3", "nh4"])
    assert route.computed_nexthops is None
    route.set_computed_nexthops(["n1", "nh2", "nh5", "nh6"])
    assert route.computed_nexthops == set(["n1", "nh2", "nh5", "nh6"])
コード例 #22
0
def test_property_computed_nexthops():
    route = RibRoute("1.0.0.0/8", ["nh1", "nh2"], ["nh3", "nh4"])
    assert route.computed_nexthops is None
コード例 #23
0
def test_property_negative_nexthops():
    route = RibRoute("1.0.0.0/8", ["nh1", "nh2"], ["nh3", "nh4"])
    assert route.positive_nexthops == set(["nh1", "nh2"])
コード例 #24
0
ファイル: route_table.py プロジェクト: jadedeane/rift-python
 def cli_table(self):
     table = Table()
     table.add_row(RibRoute.cli_summary_headers())
     for rib_route in self.all_routes():
         table.add_row(rib_route.cli_summary_attributes())
     return table
コード例 #25
0
subnet_disagg_prefix = "10.0.10.0/24"
subnet_negative_disagg_next_hops = ['S2']

unreachable_prefix = "200.0.0.0/16"
unreachable_negative_next_hops = ['S1', 'S2', 'S3', 'S4']

leaf_prefix = "20.0.0.0/16"
leaf_prefix_positive_next_hops = ["M4"]
leaf_prefix_negative_next_hops = ["M3"]

N_SPF = 1
S_SPF = 2

rib = Rib()
print("Slide 55: Adding default route to RIB")
default_route = RibRoute(default_prefix, S_SPF, default_next_hops)
rib.put_route(default_route)
print(rib)
input("Press Enter to continue...\n\n")

print("Slide 56: Adding negative disaggregation for %s via S1" %
      first_negative_disagg_prefix)
first_disagg_route = RibRoute(first_negative_disagg_prefix, S_SPF, [],
                              first_negative_disagg_next_hops)
rib.put_route(first_disagg_route)
print(rib)
input("Press Enter to continue...\n\n")

print("Slide 57: Adding negative disaggregation for %s via S4" %
      second_negative_disagg_prefix)
second_disagg_route = RibRoute(second_negative_disagg_prefix, S_SPF, [],
コード例 #26
0
ファイル: test_rib_fib.py プロジェクト: jadedeane/rift-python
def mkr(prefix_str, owner, next_hops=None):
    if next_hops is None:
        next_hops = []
    return RibRoute(mkp(prefix_str), owner, next_hops)
コード例 #27
0
def test_prop_nesting_with_siblings():

    # Deep nesting of more specific routes using the following tree:
    #
    #   1.0.0.0/8 -> S1, S2, S3, S4, S5, S6, S7
    #    |
    #    +--- 1.1.0.0/16 -> ~S1
    #    |     |
    #    |     +--- 1.1.1.0/24 -> ~S2
    #    |     |
    #    |     +--- 1.1.2.0/24 -> ~S3
    #    |
    #    +--- 1.2.0.0/16 -> ~S4
    #          |
    #          +--- 1.2.1.0/24 -> ~S5
    #          |
    #          +--- 1.2.2.0/24 -> ~S6
    #
    # Note: we add the routes in a random order

    rib = Rib()

    rib.put_route(RibRoute("1.2.1.0/24", S_SPF, [], ["S5"]))
    rib.put_route(RibRoute("1.1.2.0/24", S_SPF, [], ["S3"]))
    rib.put_route(RibRoute("1.1.0.0/16", S_SPF, [], ['S1']))
    rib.put_route(RibRoute("1.1.1.0/24", S_SPF, [], ['S2']))
    rib.put_route(RibRoute("1.2.0.0/16", S_SPF, [], ['S4']))
    rib.put_route(RibRoute("1.0.0.0/8", S_SPF, ['S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7']))
    rib.put_route(RibRoute("1.2.2.0/24", S_SPF, [], ['S6']))

    # Testing only rib, fib and kernel next hops
    assert rib.destinations.get('1.0.0.0/8').best_route.next_hops == {'S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7'}
    assert rib.fib.routes['1.0.0.0/8'].next_hops == {'S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7'}
    assert rib.fib.kernel.routes['1.0.0.0/8'] == {'S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7'}

    assert rib.destinations.get('1.1.0.0/16').best_route.negative_next_hops == {'S1'}
    assert rib.destinations.get('1.1.0.0/16').best_route.next_hops == {'S2', 'S3', 'S4', 'S5', 'S6', 'S7'}
    assert rib.fib.routes['1.1.0.0/16'].next_hops == {'S2', 'S3', 'S4', 'S5', 'S6', 'S7'}
    assert rib.fib.kernel.routes['1.1.0.0/16'] == {'S2', 'S3', 'S4', 'S5', 'S6', 'S7'}

    assert rib.destinations.get('1.1.1.0/24').best_route.negative_next_hops == {'S2'}
    assert rib.destinations.get('1.1.1.0/24').best_route.next_hops == {'S3', 'S4', 'S5', 'S6', 'S7'}
    assert rib.fib.routes['1.1.1.0/24'].next_hops == {'S3', 'S4', 'S5', 'S6', 'S7'}
    assert rib.fib.kernel.routes['1.1.1.0/24'] == {'S3', 'S4', 'S5', 'S6', 'S7'}


    assert rib.destinations.get('1.1.2.0/24').best_route.negative_next_hops == {'S3'}
    assert rib.destinations.get('1.1.2.0/24').best_route.next_hops == {'S2', 'S4', 'S5', 'S6', 'S7'}
    assert rib.fib.routes['1.1.2.0/24'].next_hops == {'S2', 'S4', 'S5', 'S6', 'S7'}
    assert rib.fib.kernel.routes['1.1.2.0/24'] == {'S2', 'S4', 'S5', 'S6', 'S7'}

    assert rib.destinations.get('1.2.0.0/16').best_route.negative_next_hops == {'S4'}
    assert rib.destinations.get('1.2.0.0/16').best_route.next_hops == {'S1', 'S2', 'S3', 'S5', 'S6', 'S7'}
    assert rib.fib.routes['1.2.0.0/16'].next_hops == {'S1', 'S2', 'S3', 'S5', 'S6', 'S7'}
    assert rib.fib.kernel.routes['1.2.0.0/16'] == {'S1', 'S2', 'S3', 'S5', 'S6', 'S7'}

    assert rib.destinations.get('1.2.1.0/24').best_route.negative_next_hops == {'S5'}
    assert rib.destinations.get('1.2.1.0/24').best_route.next_hops == {'S1', 'S2', 'S3', 'S6', 'S7'}
    assert rib.fib.routes['1.2.1.0/24'].next_hops == {'S1', 'S2', 'S3', 'S6', 'S7'}
    assert rib.fib.kernel.routes['1.2.1.0/24'] == {'S1', 'S2', 'S3', 'S6', 'S7'}

    assert rib.destinations.get('1.2.2.0/24').best_route.negative_next_hops == {'S6'}
    assert rib.destinations.get('1.2.2.0/24').best_route.next_hops == {'S1', 'S2', 'S3', 'S5', 'S7'}
    assert rib.fib.routes['1.2.2.0/24'].next_hops == {'S1', 'S2', 'S3', 'S5', 'S7'}
    assert rib.fib.kernel.routes['1.2.2.0/24'] == {'S1', 'S2', 'S3', 'S5', 'S7'}

    # Delete nexthop S3 from the parent route 0.0.0.0/0.
    rib.put_route(RibRoute('1.0.0.0/8', S_SPF, ['S1', 'S2', 'S4', 'S5', 'S6', 'S7']))

    # Testing only rib, fib and kernel next hops
    assert rib.destinations.get('1.0.0.0/8').best_route.next_hops == {'S1', 'S2', 'S4', 'S5', 'S6', 'S7'}
    assert rib.fib.routes['1.0.0.0/8'].next_hops == {'S1', 'S2', 'S4', 'S5', 'S6', 'S7'}
    assert rib.fib.kernel.routes['1.0.0.0/8'] == {'S1', 'S2', 'S4', 'S5', 'S6', 'S7'}

    assert rib.destinations.get('1.1.0.0/16').best_route.negative_next_hops == {'S1'}
    assert rib.destinations.get('1.1.0.0/16').best_route.next_hops == {'S2', 'S4', 'S5', 'S6', 'S7'}
    assert rib.fib.routes['1.1.0.0/16'].next_hops == {'S2', 'S4', 'S5', 'S6', 'S7'}
    assert rib.fib.kernel.routes['1.1.0.0/16'] == {'S2', 'S4', 'S5', 'S6', 'S7'}

    assert rib.destinations.get('1.1.1.0/24').best_route.negative_next_hops == {'S2'}
    assert rib.destinations.get('1.1.1.0/24').best_route.next_hops == {'S4', 'S5', 'S6', 'S7'}
    assert rib.fib.routes['1.1.1.0/24'].next_hops == {'S4', 'S5', 'S6', 'S7'}
    assert rib.fib.kernel.routes['1.1.1.0/24'] == {'S4', 'S5', 'S6', 'S7'}

    assert rib.destinations.get('1.1.2.0/24').best_route.negative_next_hops == {'S3'}
    assert rib.destinations.get('1.1.2.0/24').best_route.next_hops == {'S2', 'S4', 'S5', 'S6', 'S7'}
    assert rib.fib.routes['1.1.2.0/24'].next_hops == {'S2', 'S4', 'S5', 'S6', 'S7'}
    assert rib.fib.kernel.routes['1.1.2.0/24'] == {'S2', 'S4', 'S5', 'S6', 'S7'}

    assert rib.destinations.get('1.2.0.0/16').best_route.negative_next_hops == {'S4'}
    assert rib.destinations.get('1.2.0.0/16').best_route.next_hops == {'S1', 'S2', 'S5', 'S6', 'S7'}
    assert rib.fib.routes['1.2.0.0/16'].next_hops == {'S1', 'S2', 'S5', 'S6', 'S7'}
    assert rib.fib.kernel.routes['1.2.0.0/16'] == {'S1', 'S2', 'S5', 'S6', 'S7'}

    assert rib.destinations.get('1.2.1.0/24').best_route.negative_next_hops == {'S5'}
    assert rib.destinations.get('1.2.1.0/24').best_route.next_hops == {'S1', 'S2', 'S6', 'S7'}
    assert rib.fib.routes['1.2.1.0/24'].next_hops == {'S1', 'S2', 'S6', 'S7'}
    assert rib.fib.kernel.routes['1.2.1.0/24'] == {'S1', 'S2', 'S6', 'S7'}

    assert rib.destinations.get('1.2.2.0/24').best_route.negative_next_hops == {'S6'}
    assert rib.destinations.get('1.2.2.0/24').best_route.next_hops == {'S1', 'S2', 'S5', 'S7'}
    assert rib.fib.routes['1.2.2.0/24'].next_hops == {'S1', 'S2', 'S5', 'S7'}
    assert rib.fib.kernel.routes['1.2.2.0/24'] == {'S1', 'S2', 'S5', 'S7'}

    # Delete all routes from the RIB.
    rib.del_route("1.0.0.0/8", S_SPF)
    rib.del_route("1.1.0.0/16", S_SPF)
    rib.del_route("1.1.1.0/24", S_SPF)
    rib.del_route("1.1.2.0/24", S_SPF)
    rib.del_route("1.2.0.0/16", S_SPF)
    rib.del_route("1.2.1.0/24", S_SPF)
    rib.del_route("1.2.2.0/24", S_SPF)

    assert not rib.destinations.keys()
    assert not rib.fib.routes.keys()
    assert not rib.fib.kernel.routes.keys()