示例#1
0
 def setUpTestData(cls):
     cls.local_as = AutonomousSystem.objects.create(
         asn=64500, name="Autonomous System 1", affiliated=True)
     cls.a_s = AutonomousSystem.objects.create(asn=64501,
                                               name="Autonomous System 1")
     cls.ix = InternetExchange.objects.create(
         local_autonomous_system=cls.local_as,
         name="Internet Exchange 1",
         slug="ix-1",
     )
     cls.useless_ix = InternetExchange.objects.create(
         local_autonomous_system=cls.local_as,
         name="Internet Exchange 2",
         slug="ix-2",
     )
     InternetExchangePeeringSession.objects.bulk_create([
         InternetExchangePeeringSession(
             autonomous_system=cls.a_s,
             internet_exchange=cls.ix,
             ip_address="192.0.2.1",
             multihop_ttl=2,
         ),
         InternetExchangePeeringSession(
             autonomous_system=cls.a_s,
             internet_exchange=cls.ix,
             ip_address="192.0.2.2",
             enabled=False,
         ),
         InternetExchangePeeringSession(
             autonomous_system=cls.a_s,
             internet_exchange=cls.ix,
             ip_address="192.0.2.3",
             is_route_server=True,
         ),
     ])
    def setUpTestData(cls):
        local_as = AutonomousSystem.objects.create(asn=64501,
                                                   name="Autonomous System 1",
                                                   affiliated=True)
        cls.a_s = AutonomousSystem.objects.create(asn=64502,
                                                  name="Autonomous System 2")
        cls.ixp = InternetExchange.objects.create(
            name="Internet Exchange 1",
            slug="ix-1",
            local_autonomous_system=local_as)
        cls.ixp_connection = Connection.objects.create(
            vlan=2000, internet_exchange_point=cls.ixp)
        InternetExchangePeeringSession.objects.bulk_create([
            InternetExchangePeeringSession(
                autonomous_system=cls.a_s,
                ixp_connection=cls.ixp_connection,
                ip_address="192.0.2.1",
            ),
            InternetExchangePeeringSession(
                autonomous_system=cls.a_s,
                ixp_connection=cls.ixp_connection,
                ip_address="192.0.2.2",
            ),
            InternetExchangePeeringSession(
                autonomous_system=cls.a_s,
                ixp_connection=cls.ixp_connection,
                ip_address="192.0.2.3",
            ),
        ])

        cls.form_data = {
            "autonomous_system": cls.a_s.pk,
            "internet_exchange": cls.ixp.pk,
            "ixp_connection": cls.ixp_connection.pk,
            "ip_address": ipaddress.ip_address("2001:db8::4"),
            "multihop_ttl": 1,
            "password": None,
            "encrypted_password": None,
            "is_route_server": False,
            "enabled": True,
            "export_routing_policies": [],
            "import_routing_policies": [],
            "bgp_state": None,
            "last_established_state": None,
            "advertised_prefix_count": 0,
            "received_prefix_count": 0,
            "comments": "",
            "tags": [],
        }
        cls.bulk_edit_data = {
            "is_route_server": True,
            "enabled": False,
            "comments": "New comments",
        }
    def setUpTestData(cls):
        local_autonomous_system = AutonomousSystem.objects.create(
            asn=201281, name="Guillaume Mazoyer", affiliated=True)
        autonomous_system = AutonomousSystem.objects.create(asn=64500,
                                                            name="Dummy")
        ixp = InternetExchange.objects.create(
            name="Test",
            slug="test",
            local_autonomous_system=local_autonomous_system)
        ixp_connection = Connection.objects.create(vlan=2000,
                                                   internet_exchange_point=ixp)

        InternetExchangePeeringSession.objects.bulk_create([
            InternetExchangePeeringSession(
                autonomous_system=autonomous_system,
                ixp_connection=ixp_connection,
                ip_address="2001:db8::1",
                password="******",
            ),
            InternetExchangePeeringSession(
                autonomous_system=autonomous_system,
                ixp_connection=ixp_connection,
                ip_address="2001:db8::2",
            ),
            InternetExchangePeeringSession(
                autonomous_system=autonomous_system,
                ixp_connection=ixp_connection,
                ip_address="2001:db8::3",
            ),
        ])
        cls.create_data = [
            {
                "service_reference": "IXP-0001",
                "autonomous_system": autonomous_system.pk,
                "ixp_connection": ixp_connection.pk,
                "ip_address": "198.51.100.1",
            },
            {
                "autonomous_system": autonomous_system.pk,
                "ixp_connection": ixp_connection.pk,
                "ip_address": "198.51.100.2",
            },
            {
                "autonomous_system": autonomous_system.pk,
                "ixp_connection": ixp_connection.pk,
                "ip_address": "198.51.100.3",
            },
        ]
示例#4
0
    def test_does_exist(self):
        # No session, must expect None
        self.assertIsNone(InternetExchangePeeringSession.does_exist())

        # Prepare objects and create a peering session
        autonomous_system0 = AutonomousSystem.objects.create(asn=64500, name="Test")
        internet_exchange0 = InternetExchange.objects.create(name="Test0", slug="test0")
        peering_session0 = InternetExchangePeeringSession.objects.create(
            autonomous_system=autonomous_system0,
            internet_exchange=internet_exchange0,
            ip_address="2001:db8::1",
        )

        # Make sure that the session has been created
        self.assertIsNotNone(peering_session0)
        # Make sure that the session is returned by calling does_exist()
        # without arguments (only one session in the database)
        self.assertIsNotNone(InternetExchangePeeringSession.does_exist())
        # Make sure we can retrieve the session with its IP
        self.assertEqual(
            peering_session0,
            InternetExchangePeeringSession.does_exist(ip_address="2001:db8::1"),
        )
        # Make sure we can retrieve the session with its IX
        self.assertEqual(
            peering_session0,
            InternetExchangePeeringSession.does_exist(
                internet_exchange=internet_exchange0
            ),
        )
        # Make sure we can retrieve the session with AS
        self.assertEqual(
            peering_session0,
            InternetExchangePeeringSession.does_exist(
                autonomous_system=autonomous_system0
            ),
        )

        # Create another peering session
        peering_session1 = InternetExchangePeeringSession.objects.create(
            autonomous_system=autonomous_system0,
            internet_exchange=internet_exchange0,
            ip_address="192.168.1.1",
        )

        # Make sure that the session has been created
        self.assertIsNotNone(peering_session1)
        # More than one session, must expect None
        self.assertIsNone(InternetExchangePeeringSession.does_exist())
        # Make sure we can retrieve the session with its IP
        self.assertEqual(
            peering_session1,
            InternetExchangePeeringSession.does_exist(ip_address="192.168.1.1"),
        )
        # Make sure it returns None when using a field that the two sessions
        # have in common
        self.assertIsNone(
            InternetExchangePeeringSession.does_exist(
                internet_exchange=internet_exchange0
            )
        )

        # Create a new IX
        internet_exchange1 = InternetExchange.objects.create(name="Test1", slug="test1")

        # Make sure it returns None when there is no session
        self.assertIsNone(
            InternetExchangePeeringSession.does_exist(
                internet_exchange=internet_exchange1
            )
        )

        # Create a new session with a already used IP in another OX
        peering_session2 = InternetExchangePeeringSession.objects.create(
            autonomous_system=autonomous_system0,
            internet_exchange=internet_exchange1,
            ip_address="2001:db8::1",
        )

        # Make sure that the session has been created
        self.assertIsNotNone(peering_session2)
        # Make sure we have None, because two sessions will be found
        self.assertIsNone(
            InternetExchangePeeringSession.does_exist(ip_address="2001:db8::1")
        )
        # But if we narrow the search with the IX we must have the proper
        # session
        self.assertEqual(
            peering_session2,
            InternetExchangePeeringSession.does_exist(
                ip_address="2001:db8::1", internet_exchange=internet_exchange1
            ),
        )