示例#1
0
    def test_update3(self):
        """Check the abstraction of an UPDATE JSON document containing withdraws"""

        # Get the abstract BGP message
        abstracted = MaboUpdateDocument("collector", json_update3)

        # There is no announces
        assert list(abstracted.announces()) == []

        # Check each withdraw
        messages = list(abstracted.withdraws())
        assert len(messages) == 2
        assert messages.pop(0) == InternalMessage(timestamp=0,
                                                  collector="collector",
                                                  peer_as=1234,
                                                  peer_ip="1.2.3.4",
                                                  prefix="0.0.0.0/0",
                                                  asn=None,
                                                  as_path=None)
        assert messages.pop(0) == InternalMessage(timestamp=0,
                                                  collector="collector",
                                                  peer_as=1234,
                                                  peer_ip="1.2.3.4",
                                                  prefix="::/0",
                                                  asn=None,
                                                  as_path=None)
示例#2
0
    def test_update4(self):
        """Check the abstraction of an UPDATE JSON document containing withdraws & announces"""

        # Get the abstract BGP message
        abstracted = MaboUpdateDocument("collector", json_update4)

        # Check announces
        assert list(abstracted.announces()) == [
            InternalMessage(timestamp=0,
                            collector="collector",
                            peer_as=1234,
                            peer_ip="1.2.3.4",
                            prefix="1.1.1.1/32",
                            asn=5678,
                            as_path="1234 5678")
        ]

        # Check withdraws
        assert list(abstracted.withdraws()) == [
            InternalMessage(timestamp=0,
                            collector="collector",
                            peer_as=1234,
                            peer_ip="1.2.3.4",
                            prefix="2.2.2.2/32",
                            asn=None,
                            as_path=None)
        ]
示例#3
0
    def test_update2(self):
        """Check the abstraction of an UPDATE JSON document containing an AS_SET."""

        # Get the abstract BGP message
        abstracted = MaboUpdateDocument("collector", json_update2)

        # Check each announces
        messages = list(abstracted.announces())
        assert len(messages) == 2
        assert messages.pop(0) == InternalMessage(timestamp=0,
                                                  collector="collector",
                                                  peer_as=1234,
                                                  peer_ip="1.2.3.4",
                                                  prefix="::/0",
                                                  asn=5678,
                                                  as_path="1234 {5678,91011}")
        assert messages.pop(0) == InternalMessage(timestamp=0,
                                                  collector="collector",
                                                  peer_as=1234,
                                                  peer_ip="1.2.3.4",
                                                  prefix="::/0",
                                                  asn=91011,
                                                  as_path="1234 {5678,91011}")

        # There is no withraws
        assert list(abstracted.withdraws()) == []
示例#4
0
 def withdraws(self):
     """Return abstracted withdraws, i.e an empty list."""
     for prefix in self.message.get("withdraw", []):
         internal = InternalMessage(self.message["timestamp"],
                                    self.collector,
                                    int(self.message.get("peer_as", None)),
                                    self.message.get("peer_ip", None),
                                    prefix, None, None)
         yield internal
示例#5
0
    def announces(self):
        """Return abstracted announces, i.e an empty list."""

        for element in self.elements():
            internal = InternalMessage(self.message["timestamp"],
                                       self.collector, element.peer_as,
                                       element.peer_ip, self.message["prefix"],
                                       element.asn, element.as_path)
            yield internal
示例#6
0
    def announces(self):
        """Return abstracted announces, i.e an empty list."""

        for prefix in self.message.get("announce", []):
            for asn in self.get_as_origins():
                internal = InternalMessage(
                    self.message["timestamp"], self.collector,
                    int(self.message.get("peer_as", None)),
                    self.message.get("peer_ip", None), prefix, asn,
                    self.message.get("as_path", None))
                yield internal
示例#7
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
示例#8
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
示例#9
0
import collections

from tabi.parallel.core import InternalMessage, Route, Hijack, Withdraw
from tabi.parallel.rib import EmulatedRIB


# Abstracted BGP UPDATE messages
update4_1 = InternalMessage(2807, "collector", 64496, "127.0.0.1",
                            "1.2.0.0/16", 64497, "64496 64499 64497")
update4_2 = InternalMessage(2807, "collector", 64496, "127.0.0.1",
                            "1.0.0.0/8", 64497, "64496 64499 64497")
update4_3 = InternalMessage(2807, "collector", 64496, "127.0.0.1",
                            "1.0.0.0/8", 64498, "64496 64499 64498")

hijack4_exact = InternalMessage(2807, "collector", 64496, "127.0.0.1",
                                "1.2.0.0/16", 666, "64496 64499 666")

hijack4_specific = InternalMessage(2807, "collector", 64496, "127.0.0.1",
                                   "1.2.3.0/24", 666, "64496 64499 666")

hijack4_peer = InternalMessage(2807, "collector", 64500, "127.0.0.2",
                               "1.0.0.0/8", 666, "64500 64499 666")


# Expected output messages
conflict_with4_1 = collections.OrderedDict([ ("prefix", "1.2.0.0/16"),  
                                           ("asn", 64497) ])      
conflict_with4_2 = collections.OrderedDict([ ("prefix", "1.0.0.0/8"),  
                                           ("asn", 64497) ])      
conflict_with4_3 = collections.OrderedDict([ ("prefix", "1.0.0.0/8"),  
                                           ("asn", 64498) ])      
示例#10
0
import collections

from tabi.parallel.core import InternalMessage, RouteInformation, HijackInformation, Route, Hijack, Withdraw, bview_fake_withdraw
from tabi.parallel.rib import EmulatedRIB


# Abstracted BGP UPDATE messages
update4 = InternalMessage(2807, "collector", 64496, "127.0.0.1",
                          "1.2.3.0/24", 64497, "64496 64499 64497")

update4_2 = InternalMessage(2807, "collector", 64498, "127.0.0.2",
                            "1.2.3.0/24", 64497, "64498 64499 64497")

withdraw4 = InternalMessage(2807, "collector", 64496, "127.0.0.1",
                            "1.2.3.0/24", None, None)

useless_withdraw4 = InternalMessage(2807, "collector", 64496, "127.0.0.1",
                                    "2.0.0.0/8", None, None)

withdraw4_2 = InternalMessage(2807, "collector", 64496, "127.0.0.1",
                              "1.2.3.4/32", None, None)

hijack4_specific = InternalMessage(2807, "collector", 64496, "127.0.0.1",
                                   "1.2.3.4/32", 666, "64496 64499 666")

hijack4 = InternalMessage(2807, "collector", 64496, "127.0.0.1",
                          "1.2.3.0/24", 666, "64496 64499 666")


# Expected output messages
expected_regular_withdraw4 = collections.OrderedDict([ ("timestamp", 2807),
示例#11
0
import collections

from tabi.parallel.core import InternalMessage, Route, RouteInformation
from tabi.parallel.rib import EmulatedRIB

# Abstracted BGP UPDATE messages
update4_1 = InternalMessage(2807, "collector", 64496, "127.0.0.1",
                            "1.2.3.0/24", 64497, "64496 64499 64497")
update4_2 = InternalMessage(2807, "collector", 64496, "127.0.0.1",
                            "1.2.3.0/24", 64500, "64496 64499 64500")

update6 = InternalMessage(2807, "collector", 64496, "127.0.0.1",
                          "2001:db8::/32", 64497, "64496 64499 64497")

# Expected output messages
expected_message4 = collections.OrderedDict([("timestamp", 2807),
                                             ("collector", "collector"),
                                             ("peer_as", 64496),
                                             ("peer_ip", "127.0.0.1"),
                                             ("action", "A"),
                                             ("prefix", "1.2.3.0/24"),
                                             ("as_path", "64496 64499 64497"),
                                             ("asn", 64497)])
expected_message6 = collections.OrderedDict([("timestamp", 2807),
                                             ("collector", "collector"),
                                             ("peer_as", 64496),
                                             ("peer_ip", "127.0.0.1"),
                                             ("action", "A"),
                                             ("prefix", "2001:db8::/32"),
                                             ("as_path", "64496 64499 64497"),
                                             ("asn", 64497)])
示例#12
0
    def test_TableDumpV2(self):
        """Check that a TableDumpV2 JSON document from mabo is correctly abstracted."""

        # Get the abstract BGP message
        abstracted = MaboTableDumpV2Document("collector", json_TableDumpV2)

        # Check each element
        elements = abstracted.elements()
        assert len(elements) == 5

        element1 = elements.pop(0)
        assert element1 == TableDumpV2Element(asn=5678,
                                              as_path="1234 5678",
                                              peer_as=1234,
                                              peer_ip="1.2.3.4")

        element2 = elements.pop(0)
        assert element2 == TableDumpV2Element(asn=910112,
                                              as_path="5678 910112",
                                              peer_as=5678,
                                              peer_ip="5.6.7.8")

        element3 = elements.pop(0)
        assert element3 == TableDumpV2Element(asn=13141516,
                                              as_path="89101112 13141516",
                                              peer_as=89101112,
                                              peer_ip="8.9.10.11")

        element4 = elements.pop(0)
        assert element4 == TableDumpV2Element(asn=123,
                                              as_path="89101112 {123,456}",
                                              peer_as=89101112,
                                              peer_ip="8.9.10.11")

        element5 = elements.pop(0)
        assert element5 == TableDumpV2Element(asn=456,
                                              as_path="89101112 {123,456}",
                                              peer_as=89101112,
                                              peer_ip="8.9.10.11")

        # There is no withdraws
        assert abstracted.withdraws() == []

        # Check announces
        assert list(abstracted.announces()) == [
            InternalMessage(timestamp=2807,
                            collector="collector",
                            peer_as=1234,
                            peer_ip="1.2.3.4",
                            prefix="10.11.12.0/24",
                            asn=5678,
                            as_path="1234 5678"),
            InternalMessage(timestamp=2807,
                            collector="collector",
                            peer_as=5678,
                            peer_ip="5.6.7.8",
                            prefix="10.11.12.0/24",
                            asn=910112,
                            as_path="5678 910112"),
            InternalMessage(timestamp=2807,
                            collector="collector",
                            peer_as=89101112,
                            peer_ip="8.9.10.11",
                            prefix="10.11.12.0/24",
                            asn=13141516,
                            as_path="89101112 13141516"),
            InternalMessage(timestamp=2807,
                            collector="collector",
                            peer_as=89101112,
                            peer_ip="8.9.10.11",
                            prefix="10.11.12.0/24",
                            asn=123,
                            as_path="89101112 {123,456}"),
            InternalMessage(timestamp=2807,
                            collector="collector",
                            peer_as=89101112,
                            peer_ip="8.9.10.11",
                            prefix="10.11.12.0/24",
                            asn=456,
                            as_path="89101112 {123,456}")
        ]
示例#13
0
import collections

from tabi.parallel.core import InternalMessage, DefaultRoute

# Abstracted BGP UPDATE messages
default_update4 = InternalMessage(2807, "collector", 64496, "127.0.0.1",
                                  "0.0.0.0/0", 64497, "64497 64497 64497")
default_update6 = InternalMessage(2807, "collector", 64496, "127.0.0.1",
                                  "::/0", 64497, "64497 64497 64497")
non_default_update = InternalMessage(2807, "collector", 64496, "127.0.0.1",
                                     "1.0.0.0/1", 64497, "64497 64497 64497")

# Expected output messages
expected_message_announce4 = collections.OrderedDict([("prefix", "0.0.0.0/0"),
                                                      (
                                                          "asn",
                                                          64497,
                                                      ),
                                                      ("as_path",
                                                       "64497 64497 64497")])
expected_message_announce6 = collections.OrderedDict([("prefix", "::/0"),
                                                      (
                                                          "asn",
                                                          64497,
                                                      ),
                                                      ("as_path",
                                                       "64497 64497 64497")])
expected_message4 = collections.OrderedDict([("timestamp", 2807),
                                             ("collector", "collector"),
                                             ("peer_as", 64496),
                                             ("peer_ip", "127.0.0.1"),