Ejemplo n.º 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)
Ejemplo n.º 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)
        ]
Ejemplo n.º 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()) == []
Ejemplo n.º 4
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) ]
Ejemplo n.º 5
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()) == []
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
    def _process_line(self, tmp):
        """Process lines from mabo."""

        from tabi.parallel.input.mabo import MaboTableDumpV2Document
        from tabi.parallel.input.mabo import MaboUpdateDocument

        document = json.loads(tmp)

        if document.get("type", None) == "table_dump_v2":
            abstracted_message = MaboTableDumpV2Document(
                self.parameters["collector_id"], document)

        elif document.get("type", None) == "update":
            abstracted_message = MaboUpdateDocument(
                self.parameters["collector_id"], document)

        else:
            self.parameters["logger"].warning(
                "_process_line(): unknown type %s", document.get("type", None))
            return

        import functools
        keep_asn = functools.partial(is_watched_asn, self.parameters)

        self.parameters["rib"].set_access_time(self.access_time)
        default_messages, route_messages, hijack_messages = tabi.parallel.core.process_message(
            self.parameters["rib"], abstracted_message, keep_asn)
        self.timestamp = abstracted_message.timestamp()

        for message in default_messages:
            self.parameters["results_pipe"].send(
                (DEFAULTS, None, json.dumps(message)))

        for message in route_messages:
            self.parameters["results_pipe"].send(
                (ROUTES, message["asn"], json.dumps(message)))

        for message in hijack_messages:
            if "withdraw" in message:  # XXX: format must be the same !
                asn = message["withdraw"]["asn"]
            else:
                asn = message["conflict_with"]["asn"]
            self.parameters["results_pipe"].send(
                (HIJACKS, asn, json.dumps(message)))