Ejemplo n.º 1
0
    def test_update4_process(self, update=update4_1, test_prefix="1.2.3.0/24"):
        """Check if IPv4 UPDATES are correcty processed."""

        rib = EmulatedRIB()
        rib.set_access_time(2807)

        # Process
        route = Route(rib)
        message = route.process(update)

        # Compare the message that was returned
        if update == update4_1:
            assert message == [expected_message4]
        elif update == update6:
            assert message == [expected_message6]
        else:
            assert None == "Unknown abstracted BGP UPDATE !"

        # Retrieve the node from the radix tee
        node = rib.search_exact(test_prefix)

        # The node is in the tree
        assert node != None

        # Verify the internal structure integrity
        route_key = dict()
        route_key[RouteInformation(64497, 64496, "127.0.0.1")] = 2807
        assert node.data.get("routes_information", None) == route_key
Ejemplo n.º 2
0
  def test_update4_process(self, update=update4_1, test_prefix="1.2.3.0/24"):
    """Check if IPv4 UPDATES are correcty processed."""

    rib = EmulatedRIB()
    rib.set_access_time(2807)

    # Process
    route = Route(rib)
    message = route.process(update)
  
    # Compare the message that was returned
    if update == update4_1:
      assert message == [ expected_message4 ]
    elif update == update6:
      assert message == [ expected_message6 ]
    else:
      assert None == "Unknown abstracted BGP UPDATE !"

    # Retrieve the node from the radix tee
    node = rib.search_exact(test_prefix)

    # The node is in the tree
    assert node != None

    # Verify the internal structure integrity
    route_key = dict()
    route_key[RouteInformation(64497, 64496, "127.0.0.1")] = 2807
    assert node.data.get("routes_information", None) == route_key
Ejemplo n.º 3
0
  def test_update_ipv4_several_origins_hijacks(self):
    """Check if hijacks against different origins are correcty processed."""

    rib = EmulatedRIB()

    # Process the update message
    route = Route(rib)
    route.process(update4_2)
    route.process(update4_3)

    # Process the hijack
    hijack = Hijack(rib, "F")
    messages = hijack.process(hijack4_specific)

    assert messages == [ expected_message4_specific_2, expected_message4_specific_3 ]
Ejemplo n.º 4
0
  def test_bview_fake_withdraw_nothing(self):
    """Check the bview_fake_withdraw() behavior when there is nothing to do."""

    rib = EmulatedRIB()
    rib.set_access_time(0)

    # Process an UPDATE
    route = Route(rib)
    route.process(update4)

    # Pretend to do a withdraw
    route_messages, hijack_messages = bview_fake_withdraw(rib, "collector", 0, 42)

    assert len(route_messages) == 0
    assert len(hijack_messages) == 0
    assert len(rib.nodes()) == 1
Ejemplo n.º 5
0
  def test_regular_withdraw(self):
    """Check that a WITHDRAW is correctly processed."""

    rib = EmulatedRIB()

    # Process an UPDATE
    route = Route(rib)
    route.process(update4)

    # Process a WITHDRAW
    withdraw = Withdraw(rib)
    route_messages, hijack_messages = withdraw.process(withdraw4)

    assert route_messages == [ expected_regular_withdraw4 ]
    assert len(hijack_messages) == 0
    assert len(rib.nodes()) == 0
Ejemplo n.º 6
0
  def test_bview_fake_withdraw_route(self):
    """Check the bview_fake_withdraw() behavior with regular routes."""

    rib = EmulatedRIB()
    rib.set_access_time(0)

    # Process an UPDATE
    route = Route(rib)
    route.process(update4)

    # Pretend to do a withdraw
    route_messages, hijack_messages = bview_fake_withdraw(rib, "collector", 1, 42)

    assert len(route_messages) == 1
    assert route_messages[0] == expected_fake_withdraw_route
    assert len(hijack_messages) == 0

    assert len(rib.nodes()) == 0
Ejemplo n.º 7
0
  def test_useless_withdraw(self):
    """Check that a useless WITHDRAW does nothing."""

    rib = EmulatedRIB()

    # Process an UPDATE
    route = Route(rib)
    route.process(update4)

    # Process a hijack
    hijack = Hijack(rib, 0)
    hijack.process(hijack4_specific)

    # Process a uselss WITHDRAW
    withdraw = Withdraw(rib)
    route_messages, hijack_messages = withdraw.process(useless_withdraw4)

    assert len(route_messages + hijack_messages) == 0
Ejemplo n.º 8
0
  def test_update_ipv4_hijack(self):
    """Check if IPv4 hijacks are correcty processed."""

    # Setup the internal objects
    rib = EmulatedRIB()
    route = Route(rib)
    route.process(update4_1)

    # Process the exact hijack
    hijack = Hijack(rib, "F")
    messages = hijack.process(hijack4_exact)

    assert messages == [ expected_message4_exact_1 ]

    # Process the specific hijack
    messages = hijack.process(hijack4_specific)

    assert messages == [ expected_message4_specific_1 ]
Ejemplo n.º 9
0
  def test_route_and_hijack_withdraw(self):
    """Check that a WITHDRAW concerning a route and a hijack is correctly processed."""

    rib = EmulatedRIB()

    # Process an UPDATE
    route = Route(rib)
    route.process(update4)

    # Process the hijack
    hijack = Hijack(rib, "F")
    hijack.process(hijack4)

    # Process a WITHDRAW
    withdraw = Withdraw(rib)
    route_messages, hijack_messages = withdraw.process(withdraw4)

    assert route_messages == [ expected_regular_withdraw4 ]
    assert hijack_messages == [ expected_hijack_withdraw4 ]
    assert len(rib.nodes()) == 0
Ejemplo n.º 10
0
  def test_hijack_withdraw(self):
    """Check that a WITHDRAW concerning a hijack is correctly processed."""

    rib = EmulatedRIB()
    rib.set_access_time(0)

    # Process an UPDATE
    route = Route(rib)
    route.process(update4)

    # Process the hijack
    hijack = Hijack(rib, "F")
    hijack.process(hijack4_specific)

    # Process a WITHDRAW
    withdraw = Withdraw(rib)
    route_messages, hijack_messages = withdraw.process(withdraw4_2)

    assert len(route_messages) == 0
    assert hijack_messages == [ expected_specific_hijack_withdraw4 ]

    ri = RouteInformation(origin_asn=64497, peer_as=64496, peer_ip='127.0.0.1')
    nodes_data = map(lambda x: (x.prefix, x.data), rib.nodes())
    assert nodes_data == [ ("1.2.3.0/24", { "routes_information": { ri: 0 } }) ]
Ejemplo n.º 11
0
    def test_update4_origins_process(self):
        """Check if IPv4 UPDATES from several origins are correcty processed."""

        rib = EmulatedRIB()
        rib.set_access_time(2807)

        # Process then retrieve the node from the radix tee
        route = Route(rib)
        route.process(update4_1)

        # Process the same UPDATE and pretend that it was inserted later
        route = Route(rib)
        route.process(update4_2)
        node = rib.search_exact("1.2.3.0/24")

        # Verify the internal structure integrity
        route_keys = dict()
        route_keys[RouteInformation(64497, 64496, "127.0.0.1")] = 2807
        route_keys[RouteInformation(64500, 64496, "127.0.0.1")] = 2807
        assert node.data.get("routes_information", None) == route_keys
Ejemplo n.º 12
0
  def test_withdraw_different_peers(self):
    """Check that a WITHDRAW only applies to a peer."""

    rib = EmulatedRIB()

    # Process an UPDATE
    route = Route(rib)
    route.process(update4)
    route.process(update4_2)

    # Process a WITHDRAW
    withdraw = Withdraw(rib)
    route_messages, hijack_messages = withdraw.process(withdraw4)

    assert route_messages == [ expected_regular_withdraw4 ]
    assert len(hijack_messages) == 0
    assert len(rib.nodes()) == 1
Ejemplo n.º 13
0
  def test_update4_origins_process(self):
    """Check if IPv4 UPDATES from several origins are correcty processed."""

    rib = EmulatedRIB()
    rib.set_access_time(2807)

    # Process then retrieve the node from the radix tee
    route = Route(rib)
    route.process(update4_1)

    # Process the same UPDATE and pretend that it was inserted later
    route = Route(rib)
    route.process(update4_2)
    node = rib.search_exact("1.2.3.0/24")

    # Verify the internal structure integrity
    route_keys = dict()
    route_keys[RouteInformation(64497, 64496, "127.0.0.1")] = 2807
    route_keys[RouteInformation(64500, 64496, "127.0.0.1")] = 2807
    assert node.data.get("routes_information", None) == route_keys
Ejemplo n.º 14
0
  def test_update_ipv6_message(self):
    """Check the format of the output message with the IPv6 prefix."""

    route = Route(EmulatedRIB())
    assert route.message(update6) == expected_message6
Ejemplo n.º 15
0
  def test_hijacks_untracked(self):
    """Check if hijacks from an untracked AS are correctly processed."""

    # Setup the internal objects
    rib = EmulatedRIB()
    route = Route(rib)
    hijack = Hijack(rib, "U")
    withdraw = Withdraw(rib)

    # Process the /32 update
    untracked_update1 = InternalMessage(0, "collector", 0, "127.0.0.1",
                                              "2011:db8::/32", 10, "0 10")
    expected_untracked_update1 = collections.OrderedDict([ ("timestamp", 0),
                                         ("collector", "collector"),
                                         ("peer_as", 0), ("peer_ip", "127.0.0.1"),
                                         ("action", "A"),
                                         ("prefix", "2011:db8::/32"), 
                                         ("as_path", "0 10"), ("asn", 10)])
    messages = route.process(untracked_update1)
    assert messages == [ expected_untracked_update1 ]
    assert len(rib.nodes()) == 1

    # Process the /48 update
    untracked_update2 = InternalMessage(1, "collector", 0, "127.0.0.1",
                                              "2011:db8:10::/48", 11, "0 11")
    expected_untracked_hijack2 = collections.OrderedDict([ ("timestamp", 1),
                                         ("collector", "collector"),
                                         ("peer_as", 0), ("peer_ip", "127.0.0.1"),
                                         ("type", "U"),
                                         ("announce", collections.OrderedDict([ ("prefix", "2011:db8:10::/48"), 
                                             ("asn", 11), ("as_path", "0 11") ])),
                                         ("conflict_with", collections.OrderedDict([ ("prefix", "2011:db8::/32"),
                                             ("asn", 10) ])), ("asn", 10) ] )
    assert hijack.process(untracked_update2) == [ expected_untracked_hijack2 ]
    assert len(rib.nodes()) == 2

    # Process the /32 withdraw
    untracked_update3 = InternalMessage(2, "collector", 0, "127.0.0.1",
                                              "2011:db8::/32", 10, "0 10")
    expected_untracked_update3 = collections.OrderedDict([ ("timestamp", 2),
                                         ("collector", "collector"),
                                         ("peer_as", 0), ("peer_ip", "127.0.0.1"),
                                         ("action", "W"),
                                         ("prefix", "2011:db8::/32"), 
                                         ("asn", 10)])
    route_messages, hijack_messages = withdraw.process(untracked_update3)
    assert route_messages == [ expected_untracked_update3 ]
    assert hijack_messages == []
    assert len(rib.nodes()) == 1

    # Process the /48 withdraw
    untracked_update4 = InternalMessage(3, "collector", 0, "127.0.0.1",
                                        "2011:db8:10::/48", 11, "0 11")
    expected_untracked_update4 = collections.OrderedDict([ ("timestamp", 3),
                                         ("collector", "collector"),
                                         ("peer_as", 0), ("peer_ip", "127.0.0.1"),
                                         ("type", "W"),
                                         ("withdraw", collections.OrderedDict([("prefix", "2011:db8:10::/48"), ("asn", 11)])),
                                         ("asn", 10)])
    route_messages, hijack_messages = withdraw.process(untracked_update4)
    assert route_messages == []
    assert hijack_messages == [ expected_untracked_update4 ]
    assert len(rib.nodes()) == 0
Ejemplo n.º 16
0
  def test_hijacks_different_peers(self):
    """Check if hijacks from different peers are correctly processed."""

    # Setup the internal objects
    rib = EmulatedRIB()
    route = Route(rib)
    hijack = Hijack(rib, "U")
    withdraw = Withdraw(rib)

    # A prefix is seen from peer_as 0
    different_peers_update1 = InternalMessage(0, "collector", 0, "127.0.0.1",
                                              "2011:db8::/32", 10, "0 10")
    expected_different_peers_update1 = collections.OrderedDict([ ("timestamp", 0),
                                         ("collector", "collector"),
                                         ("peer_as", 0), ("peer_ip", "127.0.0.1"),
                                         ("action", "A"),
                                         ("prefix", "2011:db8::/32"), 
                                         ("as_path", "0 10"), ("asn", 10)])
    messages = route.process(different_peers_update1)
    assert messages == [ expected_different_peers_update1 ]

    # The same prefix is seen from peer_as 1
    different_peers_update2 = InternalMessage(0, "collector", 1, "127.0.0.2",
                                              "2011:db8::/32", 10, "1 10")
    expected_different_peers_update2 = collections.OrderedDict([ ("timestamp", 0),
                                         ("collector", "collector"),
                                         ("peer_as", 1), ("peer_ip", "127.0.0.2"),
                                         ("action", "A"),
                                         ("prefix", "2011:db8::/32"), 
                                         ("as_path", "1 10"), ("asn", 10)])
    messages = route.process(different_peers_update2)
    assert messages == [ expected_different_peers_update2 ]

    # A more specific prefix is seen from peer_as 0
    different_peers_update3 = InternalMessage(1, "collector", 0, "127.0.0.1",
                                              "2011:db8:10::/48", 11, "0 11")
    expected_different_peers_update3 = collections.OrderedDict([ ("timestamp", 1),
                                         ("collector", "collector"),
                                         ("peer_as", 0), ("peer_ip", "127.0.0.1"),
                                         ("action", "A"),
                                         ("prefix", "2011:db8:10::/48"), 
                                         ("as_path", "0 11"), ("asn", 11)])
    expected_different_peers_hijack3 = collections.OrderedDict([ ("timestamp", 1),
                                         ("collector", "collector"),
                                         ("peer_as", 0), ("peer_ip", "127.0.0.1"),
                                         ("type", "U"),
                                         ("announce", collections.OrderedDict([ ("prefix", "2011:db8:10::/48"), 
                                             ("asn", 11), ("as_path", "0 11") ])),
                                         ("conflict_with", collections.OrderedDict([ ("prefix", "2011:db8::/32"),
                                             ("asn", 10) ])), ("asn", 10) ] )
    messages = route.process(different_peers_update3)
    assert messages == [ expected_different_peers_update3 ]
    assert hijack.process(different_peers_update3) == [ expected_different_peers_hijack3 ]

    # A more specific prefix is seen from peer_as 1
    different_peers_update4 = InternalMessage(1, "collector", 1, "127.0.0.2",
                                              "2011:db8:10::/48", 11, "1 11")
    expected_different_peers_update4 = collections.OrderedDict([ ("timestamp", 1),
                                         ("collector", "collector"),
                                         ("peer_as", 1), ("peer_ip", "127.0.0.2"),
                                         ("action", "A"),
                                         ("prefix", "2011:db8:10::/48"), 
                                         ("as_path", "1 11"), ("asn", 11)])
    expected_different_peers_hijack4 = collections.OrderedDict([ ("timestamp", 1),
                                         ("collector", "collector"),
                                         ("peer_as", 1), ("peer_ip", "127.0.0.2"),
                                         ("type", "U"),
                                         ("announce", collections.OrderedDict([ ("prefix", "2011:db8:10::/48"), 
                                             ("asn", 11), ("as_path", "1 11") ])),
                                         ("conflict_with", collections.OrderedDict([ ("prefix", "2011:db8::/32"),
                                             ("asn", 10) ])), ("asn", 10) ] )
    messages = route.process(different_peers_update4)
    assert messages == [ expected_different_peers_update4 ]
    assert hijack.process(different_peers_update4) == [ expected_different_peers_hijack4 ]


    # A withdraw is received from the /32 on peer_as 0
    different_peers_withdraw5 = InternalMessage(2, "collector", 0, "127.0.0.1",
                                                "2011:db8::/32", 10, "0 10")
    expected_different_peers_withdraw5 = collections.OrderedDict([("timestamp", 2),
                                           ("collector", "collector"),
                                           ("peer_as", 0), ("peer_ip", "127.0.0.1"),
                                           ("action", "W"),
                                           ("prefix", "2011:db8::/32"), ("asn", 10)])
    route_messages, hijack_messages =  withdraw.process(different_peers_withdraw5)
    assert route_messages == [ expected_different_peers_withdraw5 ]
    assert hijack_messages == []

    # A withdraw is received from the /32 on peer_as 1
    different_peers_withdraw6 = InternalMessage(2, "collector", 1, "127.0.0.2",
                                                "2011:db8::/32", 10, "1 10")
    expected_different_peers_withdraw6 = collections.OrderedDict([("timestamp", 2),
                                           ("collector", "collector"),
                                           ("peer_as", 1), ("peer_ip", "127.0.0.2"),
                                           ("action", "W"),
                                           ("prefix", "2011:db8::/32"), ("asn", 10)])
    route_messages, hijack_messages =  withdraw.process(different_peers_withdraw6)
    assert route_messages == [ expected_different_peers_withdraw6 ]
    assert hijack_messages == []

    # A withdraw is received from the /48 on peer_as 0
    different_peers_withdraw6= InternalMessage(3, "collector", 0, "127.0.0.1",
                                                 "2011:db8:10::/48", 11, "0 11")
    expected_different_peers_withdraw6 = collections.OrderedDict([("timestamp", 3),
                                          ("collector", "collector"),
                                          ("peer_as", 0), ("peer_ip", "127.0.0.1"),
                                          ("action", "W"),
                                          ("prefix", "2011:db8:10::/48"), ("asn", 11)])
    expected_different_peers_withdraw6_hijack = collections.OrderedDict([("timestamp", 3),
                                                  ("collector", "collector"),
                                                  ("peer_as", 0), ("peer_ip", "127.0.0.1"),
                                                  ("type", "W"),
                                                  ("withdraw", collections.OrderedDict([("prefix", "2011:db8:10::/48"), ("asn", 11)])),
                                                  ("asn", 10)])
    route_messages, hijack_messages = withdraw.process(different_peers_withdraw6)
    assert route_messages == [ expected_different_peers_withdraw6 ]
    assert hijack_messages == [ expected_different_peers_withdraw6_hijack]

    # A withdraw is received from the /48 on peer_as 1
    different_peers_withdraw7= InternalMessage(3, "collector", 1, "127.0.0.2",
                                                 "2011:db8:10::/48", 11, "1 11")
    expected_different_peers_withdraw7 = collections.OrderedDict([("timestamp", 3),
                                          ("collector", "collector"),
                                          ("peer_as", 1), ("peer_ip", "127.0.0.2"),
                                          ("action", "W"),
                                          ("prefix", "2011:db8:10::/48"), ("asn", 11)])
    expected_different_peers_withdraw7_hijack = collections.OrderedDict([("timestamp", 3),
                                                  ("collector", "collector"),
                                                  ("peer_as", 1), ("peer_ip", "127.0.0.2"),
                                                  ("type", "W"),
                                                  ("withdraw", collections.OrderedDict([("prefix", "2011:db8:10::/48"), ("asn", 11)])),
                                                  ("asn", 10)])
    route_messages, hijack_messages = withdraw.process(different_peers_withdraw7)
    assert route_messages == [ expected_different_peers_withdraw7 ]
    assert hijack_messages == [ expected_different_peers_withdraw7_hijack]

    assert len(rib.nodes()) == 0
Ejemplo n.º 17
0
    def test_update_ipv6_message(self):
        """Check the format of the output message with the IPv6 prefix."""

        route = Route(EmulatedRIB())
        assert route.message(update6) == expected_message6