Beispiel #1
0
    def setUp(self, *_):
        """
        Starts the thread which launches ryu apps

        Create a testing bridge, add a port, setup the port interfaces. Then
        launch the ryu apps for testing pipelined. Gets the references
        to apps launched by using futures.
        """
        cls = ArpTableTestRouterIP
        add_to_ip_blocks_list('1.1.1.0/24')
        add_to_ip_blocks_list('2.2.2.2')

        warnings.simplefilter('ignore')
        cls.service_manager = create_service_manager([], ['arpd'])
        cls._tbl_num = cls.service_manager.get_table_num(ArpController.APP_NAME)

        arp.mobilityd_list_ip_blocks = mocked_mobilityd_list_ip_blocks
        arp_controller_reference = Future()
        testing_controller_reference = Future()
        test_setup = TestSetup(
            apps=[
                PipelinedController.Arp,
                PipelinedController.Testing,
                PipelinedController.StartupFlows
            ],
            references={
                PipelinedController.Arp:
                    arp_controller_reference,
                PipelinedController.Testing:
                    testing_controller_reference,
                PipelinedController.StartupFlows:
                    Future(),
            },
            config={
                'setup_type': 'LTE',
                'allow_unknown_arps': False,
                'bridge_name': cls.BRIDGE,
                'bridge_ip_address': cls.BRIDGE_IP,
                'ovs_gtp_port_number': 32768,
                'virtual_mac': cls.VIRTUAL_MAC,
                'local_ue_eth_addr': True,
                'quota_check_ip': '1.2.3.4',
                'clean_restart': True,
                'enable_nat': False,
                'mtr_ip': cls.MTR_IP,
                'mtr_mac': cls.MTR_MAC,
            },
            mconfig=PipelineD(
                ue_ip_block=cls.UE_BLOCK,
            ),
            loop=None,
            service_manager=cls.service_manager,
            integ_test=False,
        )

        BridgeTools.create_bridge(cls.BRIDGE, cls.IFACE)

        cls.thread = start_ryu_app_thread(test_setup)
        cls.arp_controller = arp_controller_reference.result()
        cls.testing_controller = testing_controller_reference.result()
Beispiel #2
0
def create_service_manager(services: List[int],
                           static_services: List[str] = None):
    """
    Creates a service manager from the given list of services.
    Args:
        services ([int]): Enums of the service from mconfig proto
    Returns:
        A service manager instance from the given config
    """
    mconfig = PipelineD(services=services)
    magma_service = MagicMock()
    magma_service.mconfig = mconfig
    if static_services is None:
        static_services = []
    magma_service.config = {
        'static_services': static_services,
        '5G_feature_set': {
            'enable': False
        }
    }
    # mock the get_default_client function used to return a fakeredis object
    func_mock = MagicMock(return_value=fakeredis.FakeStrictRedis())
    with mock.patch('magma.pipelined.rule_mappers.get_default_client',
                    func_mock):
        service_manager = ServiceManager(magma_service)

    # Workaround as we don't use redis in unit tests
    service_manager.rule_id_mapper._rule_nums_by_rule = {}
    service_manager.rule_id_mapper._rules_by_rule_num = {}
    service_manager.session_rule_version_mapper._version_by_imsi_and_rule = {}
    service_manager.interface_to_prefix_mapper._prefix_by_interface = {}
    service_manager.tunnel_id_mapper._tunnel_map = {}

    return service_manager
Beispiel #3
0
 def setUpClass(cls):
     magma_service_mock = MagicMock()
     magma_service_mock.mconfig = PipelineD()
     magma_service_mock.mconfig.services.extend(
         [PipelineD.ENFORCEMENT, PipelineD.DPI, PipelineD.METERING])
     magma_service_mock.config = {'static_apps': ['arpd', 'access_control']}
     cls.service_manager = ServiceManager(magma_service_mock)
    def setUpClass(cls, *_):
        """
        Starts the thread which launches ryu apps

        Create a testing bridge, add a port, setup the port interfaces. Then
        launch the ryu apps for testing pipelined. Gets the references
        to apps launched by using futures.
        """
        super(IPV6RouterSolicitationTableTest, cls).setUpClass()
        warnings.simplefilter('ignore')
        cls.service_manager = create_service_manager(
            [],
            ['ipv6_solicitation'],
        )
        cls._tbl_num = cls.service_manager.get_table_num(
            IPV6SolicitationController.APP_NAME)

        ipv6_controller_reference = Future()
        testing_controller_reference = Future()
        test_setup = TestSetup(
            apps=[
                PipelinedController.IPV6RouterSolicitation,
                PipelinedController.Testing,
                PipelinedController.StartupFlows,
            ],
            references={
                PipelinedController.IPV6RouterSolicitation:
                ipv6_controller_reference,
                PipelinedController.Testing: testing_controller_reference,
                PipelinedController.StartupFlows: Future(),
            },
            config={
                'setup_type': 'LTE',
                'allow_unknown_arps': False,
                'bridge_name': cls.BRIDGE,
                'bridge_ip_address': cls.BRIDGE_IP,
                'ovs_gtp_port_number': 32768,
                'virtual_interface': cls.BRIDGE,
                'local_ue_eth_addr': True,
                'quota_check_ip': '1.2.3.4',
                'ipv6_router_addr': 'd88d:aba4:472f:fc95:7e7d:8457:5301:ebce',
                'clean_restart': True,
                'virtual_mac': 'd6:34:bc:81:5d:40',
                'enable_nat': True,
            },
            mconfig=PipelineD(ue_ip_block=cls.UE_BLOCK, ),
            loop=None,
            service_manager=cls.service_manager,
            integ_test=False,
        )

        BridgeTools.create_bridge(cls.BRIDGE, cls.IFACE)

        cls.thread = start_ryu_app_thread(test_setup)
        cls.solicitation_controller = ipv6_controller_reference.result()
        cls.testing_controller = testing_controller_reference.result()

        cls._prefix_dict = {}
        cls.solicitation_controller._prefix_mapper._prefix_by_interface = \
            cls._prefix_dict
Beispiel #5
0
def create_service_manager(services: List[int],
                           static_services: List[str] = None):
    """
    Creates a service manager from the given list of services.
    Args:
        services ([int]): Enums of the service from mconfig proto
    Returns:
        A service manager instance from the given config
    """
    mconfig = PipelineD(services=services)
    magma_service = MagicMock()
    magma_service.mconfig = mconfig
    if static_services is None:
        static_services = []
    magma_service.config = {
        'static_services': static_services,
        '5G_feature_set': {
            'enable': False
        }
    }
    service_manager = ServiceManager(magma_service)

    # Workaround as we don't use redis in unit tests
    service_manager.rule_id_mapper._rule_nums_by_rule = {}
    service_manager.rule_id_mapper._rules_by_rule_num = {}
    service_manager.session_rule_version_mapper._version_by_imsi_and_rule = {}
    service_manager.interface_to_prefix_mapper._prefix_by_interface = {}
    service_manager.tunnel_id_mapper._tunnel_map = {}

    return service_manager
Beispiel #6
0
    def setUpClass(cls):
        """
        Starts the thread which launches ryu apps

        Create a testing bridge, add a port, setup the port interfaces. Then
        launch the ryu apps for testing pipelined. Gets the references
        to apps launched by using futures.
        """
        super(TunnelLearnTest, cls).setUpClass()
        warnings.simplefilter('ignore')
        cls.service_manager = create_service_manager(
            [],
            ['ue_mac', 'tunnel_learn'],
        )
        cls._tbl_num = cls.service_manager.get_table_num(
            TunnelLearnController.APP_NAME, )

        tunnel_learn_controller_reference = Future()
        testing_controller_reference = Future()
        test_setup = TestSetup(
            apps=[
                PipelinedController.TunnelLearnController,
                PipelinedController.Testing,
                PipelinedController.StartupFlows,
            ],
            references={
                PipelinedController.TunnelLearnController:
                tunnel_learn_controller_reference,
                PipelinedController.Testing: testing_controller_reference,
                PipelinedController.StartupFlows: Future(),
            },
            config={
                'setup_type': 'CWF',
                'allow_unknown_arps': False,
                'bridge_name': cls.BRIDGE,
                'bridge_ip_address': cls.BRIDGE_IP,
                'internal_ip_subnet': '192.168.0.0/16',
                'nat_iface': 'eth2',
                'enodeb_iface': 'eth1',
                'qos': {
                    'enable': False
                },
                'clean_restart': True,
                'access_control': {
                    'ip_blocklist': [],
                },
            },
            mconfig=PipelineD(allowed_gre_peers=[], ),
            loop=None,
            service_manager=cls.service_manager,
            integ_test=False,
        )

        BridgeTools.create_bridge(cls.BRIDGE, cls.IFACE)

        cls.thread = start_ryu_app_thread(test_setup)
        cls.tunnel_learn_controller = \
            tunnel_learn_controller_reference.result()
        cls.testing_controller = testing_controller_reference.result()
Beispiel #7
0
    def setUpClass(cls, *_):
        """
        Starts the thread which launches ryu apps

        Create a testing bridge, add a port, setup the port interfaces. Then
        launch the ryu apps for testing pipelined. Gets the references
        to apps launched by using futures, mocks the redis policy_dictionary
        of gy_controller
        """
        super(GYTableTest, cls).setUpClass()
        warnings.simplefilter('ignore')
        cls.service_manager = create_service_manager([PipelineD.ENFORCEMENT],
                                                     ['arpd'])
        cls._tbl_num = cls.service_manager.get_table_num(GYController.APP_NAME)

        gy_controller_reference = Future()
        testing_controller_reference = Future()
        test_setup = TestSetup(
            apps=[
                PipelinedController.GY, PipelinedController.Arp,
                PipelinedController.Testing, PipelinedController.StartupFlows
            ],
            references={
                PipelinedController.GY: gy_controller_reference,
                PipelinedController.Arp: Future(),
                PipelinedController.Testing: testing_controller_reference,
                PipelinedController.StartupFlows: Future(),
            },
            config={
                'setup_type': 'CWF',
                'allow_unknown_arps': False,
                'bridge_name': cls.BRIDGE,
                'bridge_ip_address': '192.168.128.1',
                'internal_ip_subnet': '192.168.0.0/16',
                'nat_iface': 'eth2',
                'enodeb_iface': 'eth1',
                'enable_queue_pgm': False,
                'local_ue_eth_addr': False,
                'qos': {
                    'enable': False
                },
                'dpi': {
                    'enable': False
                },
                'clean_restart': True,
            },
            mconfig=PipelineD(ue_ip_block='192.168.128.0/24'),
            loop=None,
            service_manager=cls.service_manager,
            integ_test=False)

        BridgeTools.create_bridge(cls.BRIDGE, cls.IFACE)

        cls.thread = start_ryu_app_thread(test_setup)

        cls.gy_controller = gy_controller_reference.result()
        cls.testing_controller = testing_controller_reference.result()

        cls.gy_controller._redirect_manager._save_redirect_entry = MagicMock()
Beispiel #8
0
    def setUpClass(cls, *_):
        """
        Starts the thread which launches ryu apps

        Create a testing bridge, add a port, setup the port interfaces. Then
        launch the ryu apps for testing pipelined. Gets the references
        to apps launched by using futures.
        """
        he.activate_he_urls_for_ue = mocked_activate_he_urls_for_ue
        he.deactivate_he_urls_for_ue = mocked_deactivate_he_urls_for_ue

        super(HeTableTest, cls).setUpClass()
        warnings.simplefilter('ignore')
        cls.service_manager = create_service_manager([], ['proxy'])
        cls._tbl_num = cls.service_manager.get_table_num(HeaderEnrichmentController.APP_NAME)

        BridgeTools.create_veth_pair(cls.VETH, cls.VETH_NS)
        BridgeTools.create_bridge(cls.BRIDGE, cls.IFACE)
        BridgeTools.add_ovs_port(cls.BRIDGE, cls.VETH, cls.PROXY_PORT)

        he_controller_reference = Future()
        testing_controller_reference = Future()

        test_setup = TestSetup(
            apps=[
                PipelinedController.HeaderEnrichment,
                PipelinedController.Testing,
                PipelinedController.StartupFlows,
            ],
            references={
                PipelinedController.HeaderEnrichment:
                    he_controller_reference,
                PipelinedController.Testing:
                    testing_controller_reference,
                PipelinedController.StartupFlows:
                    Future(),
            },
            config={
                'setup_type': 'LTE',
                'bridge_name': cls.BRIDGE,
                'bridge_ip_address': cls.BRIDGE_IP,
                'uplink_port': 20,
                'proxy_port_name': cls.VETH,
                'clean_restart': True,
                'enable_nat': True,
                'ovs_gtp_port_number': 10,
            },
            mconfig=PipelineD(
                ue_ip_block=cls.UE_BLOCK,
            ),
            loop=None,
            service_manager=cls.service_manager,
            integ_test=False,
        )

        cls.thread = start_ryu_app_thread(test_setup)
        cls.he_controller = he_controller_reference.result()
        cls.testing_controller = testing_controller_reference.result()
Beispiel #9
0
    def setUpClass(cls):
        """
        Starts the thread which launches ryu apps
        Create a testing bridge, add a port, setup the port interfaces. Then
        launch the ryu apps for testing pipelined. Gets the references
        to apps launched by using futures, mocks the redis policy_dictionary
        of enforcement_controller
        """
        super(EnforcementTableTest, cls).setUpClass()
        warnings.simplefilter('ignore')
        cls._static_rule_dict = {}
        cls.service_manager = create_service_manager([PipelineD.ENFORCEMENT])
        cls._tbl_num = cls.service_manager.get_table_num(
            EnforcementController.APP_NAME,
        )

        enforcement_controller_reference = Future()
        testing_controller_reference = Future()
        test_setup = TestSetup(
            apps=[
                PipelinedController.Enforcement,
                PipelinedController.Testing,
                PipelinedController.StartupFlows,
            ],
            references={
                PipelinedController.Enforcement:
                    enforcement_controller_reference,
                PipelinedController.Testing:
                    testing_controller_reference,
                PipelinedController.StartupFlows:
                    Future(),
            },
            config={
                'bridge_name': cls.BRIDGE,
                'bridge_ip_address': '192.168.128.1',
                'nat_iface': 'eth2',
                'enodeb_iface': 'eth1',
                'qos': {'enable': False},
                'clean_restart': True,
                'uplink_port': 20,
                'enable_nat': True,
                'ovs_gtp_port_number': 10,
                'setup_type': 'LTE',
            },
            mconfig=PipelineD(),
            loop=None,
            service_manager=cls.service_manager,
            integ_test=False,
        )

        BridgeTools.create_bridge(cls.BRIDGE, cls.IFACE)

        cls.thread = start_ryu_app_thread(test_setup)

        cls.enforcement_controller = enforcement_controller_reference.result()
        cls.testing_controller = testing_controller_reference.result()

        cls.enforcement_controller._policy_dict = cls._static_rule_dict
Beispiel #10
0
 def setUp(self):
     magma_service_mock = MagicMock()
     magma_service_mock.mconfig = PipelineD()
     magma_service_mock.mconfig.services.extend(
         [PipelineD.ENFORCEMENT, PipelineD.DPI])
     magma_service_mock.config = {
         'static_services': ['arpd', 'access_control', 'ipfix']
     }
     self.service_manager = ServiceManager(magma_service_mock)
Beispiel #11
0
    def setUpClass(cls, *_):
        """
        Starts the thread which launches ryu apps

        Create a testing bridge, add a port, setup the port interfaces. Then
        launch the ryu apps for testing pipelined. Gets the references
        to apps launched by using futures.
        """
        super(UEMacAddressTest, cls).setUpClass()
        warnings.simplefilter('ignore')
        cls.service_manager = create_service_manager([], include_ue_mac=True)
        cls._tbl_num = cls.service_manager.get_table_num(
            UEMacAddressController.APP_NAME)
        cls._ingress_tbl_num = cls.service_manager.get_table_num(INGRESS)
        cls._egress_tbl_num = cls.service_manager.get_table_num(EGRESS)

        inout_controller_reference = Future()
        ue_mac_controller_reference = Future()
        testing_controller_reference = Future()
        test_setup = TestSetup(
            apps=[PipelinedController.InOut,
                  PipelinedController.Arp,
                  PipelinedController.UEMac,
                  PipelinedController.Testing],
            references={
                PipelinedController.InOut:
                    inout_controller_reference,
                PipelinedController.Arp:
                    Future(),
                PipelinedController.UEMac:
                    ue_mac_controller_reference,
                PipelinedController.Testing:
                    testing_controller_reference
            },
            config={
                'setup_type': 'CWF',
                'allow_unknown_arps': False,
                'bridge_name': cls.BRIDGE,
                'bridge_ip_address': cls.BRIDGE_IP,
                'ovs_gtp_port_number': 32768,
                'virtual_interface': 'testing_br',
                'local_ue_eth_addr': False,
            },
            mconfig=PipelineD(
                ue_ip_block="192.168.128.0/24",
            ),
            loop=None,
            service_manager=cls.service_manager,
            integ_test=False,
        )

        BridgeTools.create_bridge(cls.BRIDGE, cls.IFACE)

        cls.thread = start_ryu_app_thread(test_setup)
        cls.ue_mac_controller = ue_mac_controller_reference.result()
        cls.testing_controller = testing_controller_reference.result()
Beispiel #12
0
 def get_mconfig(cls):
     return PipelineD(allowed_gre_peers=[
         {
             'ip': '2.2.2.2/24'
         },
         {
             'ip': '1.2.3.4/24',
             'key': 123
         },
     ], )
Beispiel #13
0
 def setUp(self):
     magma_service_mock = MagicMock()
     magma_service_mock.mconfig = PipelineD()
     magma_service_mock.mconfig.services.extend(
         [PipelineD.ENFORCEMENT, PipelineD.DPI, PipelineD.METERING])
     magma_service_mock.config = {
         'static_services': ['arpd', 'access_control']
     }
     # Hack since service manager is supposed to be a singleton.
     ServiceManager._instance = None
     self.service_manager = ServiceManager(magma_service_mock)
Beispiel #14
0
    def setUpClass(cls, *_):
        """
        Starts the thread which launches ryu apps

        Create a testing bridge, add a port, setup the port interfaces. Then
        launch the ryu apps for testing pipelined. Gets the references
        to apps launched by using futures.
        """
        super(UEMacAddressTest, cls).setUpClass()
        warnings.simplefilter('ignore')
        cls.service_manager = create_service_manager([], include_ue_mac=True)
        check_quota_controller_reference = Future()
        testing_controller_reference = Future()
        test_setup = TestSetup(
            apps=[PipelinedController.CheckQuotaController,
                  PipelinedController.Arp,
                  PipelinedController.Testing,
                  PipelinedController.StartupFlows],
            references={
                PipelinedController.CheckQuotaController:
                    check_quota_controller_reference,
                PipelinedController.Testing:
                    testing_controller_reference,
                PipelinedController.Arp:
                    Future(),
                PipelinedController.StartupFlows:
                    Future(),
            },
            config={
                'setup_type': 'CWF',
                'allow_unknown_arps': False,
                'bridge_name': cls.BRIDGE,
                'bridge_ip_address': cls.BRIDGE_IP,
                'ovs_gtp_port_number': 32768,
                'has_quota_port': 50001,
                'no_quota_port': 50002,
                'quota_check_ip': '1.2.3.4',
                'local_ue_eth_addr': False,
                'clean_restart': True,
            },
            mconfig=PipelineD(
                ue_ip_block='192.168.128.0/24',
            ),
            loop=None,
            service_manager=cls.service_manager,
            integ_test=False,
        )

        BridgeTools.create_bridge(cls.BRIDGE, cls.IFACE)

        cls.thread = start_ryu_app_thread(test_setup)
        cls.check_quota_controller = check_quota_controller_reference.result()
        cls.check_quota_controller._setup_fake_ip_arp = MagicMock()
        cls.testing_controller = testing_controller_reference.result()
Beispiel #15
0
    def setUpClass(cls, *_):
        """
        Starts the thread which launches ryu apps

        Create a testing bridge, add a port, setup the port interfaces. Then
        launch the ryu apps for testing pipelined. Gets the references
        to apps launched by using futures.
        """
        super(GTPTrafficTest, cls).setUpClass()
        warnings.simplefilter('ignore')
        cls.service_manager = create_service_manager([], ['classifier'])
        cls._tbl_num = cls.service_manager.get_table_num(Classifier.APP_NAME)

        testing_controller_reference = Future()
        classifier_reference = Future()
        test_setup = TestSetup(
            apps=[PipelinedController.Classifier,
                  PipelinedController.Testing,
                  PipelinedController.StartupFlows],
            references={
                PipelinedController.Classifier:
                    classifier_reference,
                PipelinedController.Testing:
                    testing_controller_reference,
                PipelinedController.StartupFlows:
                    Future(),
            },
            config={
                'bridge_name': cls.BRIDGE,
                'bridge_ip_address': cls.BRIDGE_IP,
                'internal_ip_subnet': '192.168.0.0/16',
                'ovs_gtp_port_number': 32768,
                'ovs_mtr_port_number': 15577,
                'mtr_ip': cls.MTR_IP,
                'ovs_internal_sampling_port_number': 15578,
                'ovs_internal_sampling_fwd_tbl_number': 201,
                'ovs_internal_conntrack_port_number': 15579,
                'ovs_internal_conntrack_fwd_tbl_number': 202,
                'clean_restart': True,
                'ovs_multi_tunnel': False,
                'paging_timeout': 30,
                'classifier_controller_id': 5,
            },
            mconfig=PipelineD(),
            loop=None,
            service_manager=cls.service_manager,
            integ_test=False,
            rpc_stubs={'sessiond_setinterface': MagicMock()}
        )

        BridgeTools.create_bridge(cls.BRIDGE, cls.IFACE)
        cls.thread = start_ryu_app_thread(test_setup)
        cls.classifier_controller = classifier_reference.result()
        cls.testing_controller = testing_controller_reference.result()
Beispiel #16
0
    def setUpClass(cls):
        """
        Starts the thread which launches ryu apps

        Create a testing bridge, add a port, setup the port interfaces. Then
        launch the ryu apps for testing pipelined. Gets the references
        to apps launched by using futures, mocks the redis policy_dictionary
        of enforcement_controller
        """
        super(RedirectTest, cls).setUpClass()
        warnings.simplefilter('ignore')
        cls.service_manager = create_service_manager([PipelineD.ENFORCEMENT])
        cls._tbl_num = cls.service_manager.get_table_num(
            EnforcementController.APP_NAME)

        enforcement_controller_reference = Future()
        testing_controller_reference = Future()
        test_setup = TestSetup(
            apps=[
                PipelinedController.Enforcement, PipelinedController.Testing,
                PipelinedController.StartupFlows
            ],
            references={
                PipelinedController.Enforcement:
                enforcement_controller_reference,
                PipelinedController.Testing: testing_controller_reference,
                PipelinedController.StartupFlows: Future(),
            },
            config={
                'bridge_name': cls.BRIDGE,
                'bridge_ip_address': cls.BRIDGE_IP_ADDRESS,
                'nat_iface': 'eth2',
                'enodeb_iface': 'eth1',
                'qos': {
                    'enable': False
                },
                'clean_restart': True,
            },
            mconfig=PipelineD(relay_enabled=True),
            loop=None,
            service_manager=cls.service_manager,
            integ_test=False,
        )

        BridgeTools.create_bridge(cls.BRIDGE, cls.IFACE)

        cls.thread = start_ryu_app_thread(test_setup)

        cls.enforcement_controller = enforcement_controller_reference.result()
        cls.testing_controller = testing_controller_reference.result()

        cls.enforcement_controller._redirect_manager._save_redirect_entry =\
            MagicMock()
 def setUp(self):
     magma_service_mock = MagicMock()
     magma_service_mock.mconfig = PipelineD()
     magma_service_mock.mconfig.services.extend(
         [PipelineD.ENFORCEMENT, PipelineD.DPI])
     magma_service_mock.config = {
         'static_services': ['arpd', 'access_control', 'ipfix', 'proxy'],
         '5G_feature_set': {
             'enable': False
         }
     }
     self.service_manager = ServiceManager(magma_service_mock)
Beispiel #18
0
    def setUpClass(cls, *_):
        """
        Starts the thread which launches ryu apps

        Create a testing bridge, add a port, setup the port interfaces. Then
        launch the ryu apps for testing pipelined. Gets the references
        to apps launched by using futures.
        """
        super(ArpTableTest, cls).setUpClass()
        warnings.simplefilter('ignore')
        cls.service_manager = create_service_manager([PipelineD.ENFORCEMENT])
        cls._tbl_num = cls.service_manager.get_table_num(ArpController.APP_NAME)

        arp_controller_reference = Future()
        testing_controller_reference = Future()
        test_setup = TestSetup(
            apps=[
                PipelinedController.Arp,
                PipelinedController.Testing,
                PipelinedController.StartupFlows
            ],
            references={
                PipelinedController.Arp:
                    arp_controller_reference,
                PipelinedController.Testing:
                    testing_controller_reference,
                PipelinedController.StartupFlows:
                    Future(),
            },
            config={
                'setup_type': 'LTE',
                'allow_unknown_arps': False,
                'bridge_name': cls.BRIDGE,
                'bridge_ip_address': cls.BRIDGE_IP,
                'ovs_gtp_port_number': 32768,
                'virtual_interface': cls.BRIDGE,
                'local_ue_eth_addr': True,
                'clean_restart': True,
            },
            mconfig=PipelineD(
                ue_ip_block=cls.UE_BLOCK,
            ),
            loop=None,
            service_manager=cls.service_manager,
            integ_test=False,
        )

        BridgeTools.create_bridge(cls.BRIDGE, cls.IFACE)

        cls.thread = start_ryu_app_thread(test_setup)
        cls.arp_controller = arp_controller_reference.result()
        cls.testing_controller = testing_controller_reference.result()
Beispiel #19
0
def create_service_manager(services=list):
    """
    Creates a service manager from the given list of services.
    Args:
        services ([int]): Enums of the service from mconfig proto
    Returns:
        A service manager instance from the given config
    """
    mconfig = PipelineD(relay_enabled=True, services=services)
    magma_service = MagicMock()
    magma_service.mconfig = mconfig
    magma_service.config = {'static_services': ['arpd', 'access_control']}
    return ServiceManager(magma_service)
Beispiel #20
0
 def setUp(self):
     magma_service_mock = MagicMock()
     magma_service_mock.mconfig = PipelineD()
     magma_service_mock.mconfig.services.extend(
         [PipelineD.ENFORCEMENT, PipelineD.DPI])
     magma_service_mock.config = {
         'static_services': ['arpd', 'access_control', 'ipfix', 'proxy'],
         '5G_feature_set': {'enable': False}
     }
     # mock the get_default_client function used to return a fakeredis object
     func_mock = MagicMock(return_value=fakeredis.FakeStrictRedis())
     with mock.patch(
         'magma.pipelined.rule_mappers.get_default_client',
         func_mock):
         self.service_manager = ServiceManager(magma_service_mock)
Beispiel #21
0
def create_service_manager(services: List[int], include_ue_mac=False):
    """
    Creates a service manager from the given list of services.
    Args:
        services ([int]): Enums of the service from mconfig proto
    Returns:
        A service manager instance from the given config
    """
    mconfig = PipelineD(relay_enabled=True, services=services)
    magma_service = MagicMock()
    magma_service.mconfig = mconfig

    static_services = (['ue_mac', 'arpd', 'access_control', 'tunnel_learn']
                       if include_ue_mac else ['arpd', 'access_control'])
    magma_service.config = {'static_services': static_services}
    return ServiceManager(magma_service)
def create_service_manager(services: List[int],
                           static_services: List[str] = None):
    """
    Creates a service manager from the given list of services.
    Args:
        services ([int]): Enums of the service from mconfig proto
    Returns:
        A service manager instance from the given config
    """
    mconfig = PipelineD(relay_enabled=True, services=services)
    magma_service = MagicMock()
    magma_service.mconfig = mconfig
    if static_services is None:
        static_services = []
    magma_service.config = {'static_services': static_services}
    return ServiceManager(magma_service)
Beispiel #23
0
    def setUp(self):
        """
        Starts the thread which launches ryu apps

        Create a testing bridge, add a port, setup the port interfaces. Then
        launch the ryu apps for testing pipelined. Gets the references
        to apps launched by using futures.

        Mocks the redis policy_dictionary of enforcement_controller.
        Mocks the loop for testing EnforcementStatsController
        """
        super(EnforcementStatsTest, self).setUpClass()
        warnings.simplefilter('ignore')
        self._static_rule_dict = {}
        self.service_manager = create_service_manager([PipelineD.ENFORCEMENT])
        self._main_tbl_num = self.service_manager.get_table_num(
            EnforcementController.APP_NAME)

        enforcement_controller_reference = Future()
        testing_controller_reference = Future()
        enf_stat_ref = Future()
        """
        Enforcement_stats reports data by using loop.call_soon_threadsafe, but
        as we don't have an eventloop in testing, just directly call the stats
        handling function

        Here is how the mocked function is used in EnforcementStatsController:
        self.loop.call_soon_threadsafe(self._handle_flow_stats, ev.msg.body)
        """
        def mock_thread_safe(cmd, body):
            cmd(body)

        loop_mock = MagicMock()
        loop_mock.call_soon_threadsafe = mock_thread_safe

        test_setup = TestSetup(apps=[
            PipelinedController.Enforcement,
            PipelinedController.Enforcement_stats, PipelinedController.Testing,
            PipelinedController.StartupFlows
        ],
                               references={
                                   PipelinedController.Enforcement:
                                   enforcement_controller_reference,
                                   PipelinedController.Testing:
                                   testing_controller_reference,
                                   PipelinedController.Enforcement_stats:
                                   enf_stat_ref,
                                   PipelinedController.StartupFlows: Future(),
                               },
                               config={
                                   'bridge_name': self.BRIDGE,
                                   'bridge_ip_address': '192.168.128.1',
                                   'enforcement': {
                                       'poll_interval': 2
                                   },
                                   'nat_iface': 'eth2',
                                   'enodeb_iface': 'eth1',
                                   'qos': {
                                       'enable': False
                                   },
                                   'clean_restart': True,
                               },
                               mconfig=PipelineD(),
                               loop=loop_mock,
                               service_manager=self.service_manager,
                               integ_test=False,
                               rpc_stubs={'sessiond': MagicMock()})

        BridgeTools.create_bridge(self.BRIDGE, self.IFACE)

        self.thread = start_ryu_app_thread(test_setup)

        self.enforcement_stats_controller = enf_stat_ref.result()
        self._scratch_tbl_num = self.enforcement_stats_controller.tbl_num
        self.enforcement_controller = enforcement_controller_reference.result()
        self.testing_controller = testing_controller_reference.result()

        self.enforcement_stats_controller._policy_dict = self._static_rule_dict
        self.enforcement_stats_controller._report_usage = MagicMock()

        self.enforcement_controller._policy_dict = self._static_rule_dict
        self.enforcement_controller._redirect_manager._save_redirect_entry = \
            MagicMock()
    def setUpClass(cls):
        """
        Starts the thread which launches ryu apps

        Create a testing bridge, add a port, setup the port interfaces. Then
        launch the ryu apps for testing pipelined. Gets the references
        to apps launched by using futures, mocks the redis policy_dictionary
        of dpi_controller
        """
        super(InternalPktIpfixExportTest, cls).setUpClass()
        warnings.simplefilter('ignore')
        cls._static_rule_dict = {}
        cls.service_manager = create_service_manager(
            [PipelineD.DPI],
            ['ue_mac', 'ipfix'],
        )
        cls._tbl_num = cls.service_manager.get_table_num(
            DPIController.APP_NAME, )

        ue_mac_controller_reference = Future()
        dpi_controller_reference = Future()
        ipfix_controller_reference = Future()
        testing_controller_reference = Future()
        test_setup = TestSetup(
            apps=[
                PipelinedController.UEMac,
                PipelinedController.DPI,
                PipelinedController.IPFIX,
                PipelinedController.Testing,
                PipelinedController.StartupFlows,
            ],
            references={
                PipelinedController.UEMac: ue_mac_controller_reference,
                PipelinedController.DPI: dpi_controller_reference,
                PipelinedController.Arp: Future(),
                PipelinedController.IPFIX: ipfix_controller_reference,
                PipelinedController.Testing: testing_controller_reference,
                PipelinedController.StartupFlows: Future(),
            },
            config={
                'bridge_name': cls.BRIDGE,
                'bridge_ip_address': '192.168.128.1',
                'internal_ip_subnet': '192.168.0.0/16',
                'nat_iface': 'eth2',
                'enodeb_iface': 'eth1',
                'enable_queue_pgm': False,
                'clean_restart': True,
                'setup_type': 'CWF',
                'dpi': {
                    'enabled': True,
                    'mon_port': 'mon1',
                    'mon_port_number': 32769,
                    'idle_timeout': 42,
                },
                'ipfix': {
                    'enabled': True,
                    'probability': 65,
                    'collector_set_id': 1,
                    'collector_ip': '1.1.1.1',
                    'collector_port': 65010,
                    'cache_timeout': 60,
                    'obs_domain_id': 1,
                    'obs_point_id': 1,
                },
                'conntrackd': {
                    'enabled': True,
                },
                'ovs_gtp_port_number': 32768,
            },
            mconfig=PipelineD(),
            loop=None,
            service_manager=cls.service_manager,
            integ_test=False,
        )

        BridgeTools.create_bridge(cls.BRIDGE, cls.IFACE)
        BridgeTools.create_internal_iface(
            cls.BRIDGE,
            cls.DPI_PORT,
            cls.DPI_IP,
        )

        cls.thread = start_ryu_app_thread(test_setup)

        cls.ue_mac_controller = ue_mac_controller_reference.result()
        cls.dpi_controller = dpi_controller_reference.result()
        cls.ipfix_controller = ipfix_controller_reference.result()
        cls.testing_controller = testing_controller_reference.result()

        cls.dpi_controller._policy_dict = cls._static_rule_dict
Beispiel #25
0
    def setUpClass(cls):
        """
        Starts the thread which launches ryu apps

        Create a testing bridge, add a port, setup the port interfaces. Then
        launch the ryu apps for testing pipelined. Gets the references
        to apps launched by using futures, mocks the redis policy_dictionary
        of enforcement_controller
        """
        super(RestartResilienceTest, cls).setUpClass()
        warnings.simplefilter('ignore')
        cls._static_rule_dict = {}
        cls.service_manager = create_service_manager([PipelineD.ENFORCEMENT])
        cls._enforcement_tbl_num = cls.service_manager.get_table_num(
            EnforcementController.APP_NAME)
        cls._tbl_num = cls.service_manager.get_table_num(
            EnforcementController.APP_NAME)

        enforcement_controller_reference = Future()
        testing_controller_reference = Future()
        enf_stat_ref = Future()
        startup_flows_ref = Future()

        def mock_thread_safe(cmd, body):
            cmd(body)

        loop_mock = MagicMock()
        loop_mock.call_soon_threadsafe = mock_thread_safe

        test_setup = TestSetup(apps=[
            PipelinedController.Enforcement, PipelinedController.Testing,
            PipelinedController.Enforcement_stats,
            PipelinedController.StartupFlows
        ],
                               references={
                                   PipelinedController.Enforcement:
                                   enforcement_controller_reference,
                                   PipelinedController.Testing:
                                   testing_controller_reference,
                                   PipelinedController.Enforcement_stats:
                                   enf_stat_ref,
                                   PipelinedController.StartupFlows:
                                   startup_flows_ref,
                               },
                               config={
                                   'bridge_name': cls.BRIDGE,
                                   'bridge_ip_address': cls.BRIDGE_IP_ADDRESS,
                                   'enforcement': {
                                       'poll_interval': 5
                                   },
                                   'nat_iface': 'eth2',
                                   'enodeb_iface': 'eth1',
                                   'qos': {
                                       'enable': False
                                   },
                                   'clean_restart': False,
                               },
                               mconfig=PipelineD(),
                               loop=loop_mock,
                               service_manager=cls.service_manager,
                               integ_test=False,
                               rpc_stubs={'sessiond': MagicMock()})

        BridgeTools.create_bridge(cls.BRIDGE, cls.IFACE)

        cls.thread = start_ryu_app_thread(test_setup)

        cls.enforcement_controller = enforcement_controller_reference.result()
        cls.enforcement_stats_controller = enf_stat_ref.result()
        cls.startup_flows_contoller = startup_flows_ref.result()
        cls.testing_controller = testing_controller_reference.result()

        cls.enforcement_stats_controller._policy_dict = cls._static_rule_dict
        cls.enforcement_stats_controller._report_usage = MagicMock()

        cls.enforcement_controller._policy_dict = cls._static_rule_dict
        cls.enforcement_controller._redirect_manager._save_redirect_entry =\
            MagicMock()
Beispiel #26
0
    def setUpClass(cls):
        """
        Starts the thread which launches ryu apps

        Create a testing bridge, add a port, setup the port interfaces. Then
        launch the ryu apps for testing pipelined. Gets the references
        to apps launched by using futures, mocks the redis policy_dictionary
        of enforcement_controller
        """
        super(EnforcementTableHeTest, cls).setUpClass()
        warnings.simplefilter('ignore')
        cls.service_manager = create_service_manager([PipelineD.ENFORCEMENT],
                                                     ['proxy'])
        cls._tbl_num = cls.service_manager.get_table_num(
            EnforcementController.APP_NAME)
        BridgeTools.create_bridge(cls.BRIDGE, cls.IFACE)

        BridgeTools.create_veth_pair(cls.VETH, cls.VETH_NS)
        BridgeTools.add_ovs_port(cls.BRIDGE, cls.VETH, cls.PROXY_PORT)

        enforcement_controller_reference = Future()
        testing_controller_reference = Future()
        he.activate_he_urls_for_ue = mocked_activate_he_urls_for_ue
        he.deactivate_he_urls_for_ue = mocked_deactivate_he_urls_for_ue

        test_setup = TestSetup(apps=[
            PipelinedController.Enforcement,
            PipelinedController.HeaderEnrichment, PipelinedController.Testing,
            PipelinedController.StartupFlows
        ],
                               references={
                                   PipelinedController.Enforcement:
                                   enforcement_controller_reference,
                                   PipelinedController.HeaderEnrichment:
                                   cls.he_controller_reference,
                                   PipelinedController.Testing:
                                   testing_controller_reference,
                                   PipelinedController.StartupFlows: Future(),
                               },
                               config={
                                   'bridge_name': cls.BRIDGE,
                                   'bridge_ip_address': '192.168.128.1',
                                   'nat_iface': 'eth2',
                                   'enodeb_iface': 'eth1',
                                   'qos': {
                                       'enable': False
                                   },
                                   'clean_restart': True,
                                   'uplink_port': 20,
                                   'proxy_port_name': cls.VETH,
                                   'enable_nat': True,
                                   'ovs_gtp_port_number': 10,
                               },
                               mconfig=PipelineD(),
                               loop=None,
                               service_manager=cls.service_manager,
                               integ_test=False)

        cls.thread = start_ryu_app_thread(test_setup)

        cls.enforcement_controller = enforcement_controller_reference.result()
        cls.testing_controller = testing_controller_reference.result()
Beispiel #27
0
    def setUpClass(cls, *_):
        """
        Starts the thread which launches ryu apps

        Create a testing bridge, add a port, setup the port interfaces. Then
        launch the ryu apps for testing pipelined. Gets the references
        to apps launched by using futures.
        """
        super(UEMacAddressTest, cls).setUpClass()
        ingress.get_virtual_iface_mac = mocked_get_virtual_iface_mac
        middle.get_virtual_iface_mac = mocked_get_virtual_iface_mac
        egress.get_virtual_iface_mac = mocked_get_virtual_iface_mac
        warnings.simplefilter('ignore')
        cls.service_manager = create_service_manager([], ['ue_mac', 'arpd'])
        cls._tbl_num = cls.service_manager.get_table_num(
            UEMacAddressController.APP_NAME, )
        cls._ingress_tbl_num = cls.service_manager.get_table_num(INGRESS)
        cls._egress_tbl_num = cls.service_manager.get_table_num(EGRESS)

        ingress_controller_reference = Future()
        middle_controller_reference = Future()
        egress_controller_reference = Future()
        ue_mac_controller_reference = Future()
        testing_controller_reference = Future()
        test_setup = TestSetup(
            apps=[
                PipelinedController.Ingress,
                PipelinedController.Middle,
                PipelinedController.Egress,
                PipelinedController.Arp,
                PipelinedController.UEMac,
                PipelinedController.Testing,
                PipelinedController.StartupFlows,
            ],
            references={
                PipelinedController.Ingress: ingress_controller_reference,
                PipelinedController.Middle: middle_controller_reference,
                PipelinedController.Egress: egress_controller_reference,
                PipelinedController.Arp: Future(),
                PipelinedController.UEMac: ue_mac_controller_reference,
                PipelinedController.Testing: testing_controller_reference,
                PipelinedController.StartupFlows: Future(),
            },
            config={
                'setup_type': 'CWF',
                'allow_unknown_arps': False,
                'bridge_name': cls.BRIDGE,
                'bridge_ip_address': cls.BRIDGE_IP,
                'internal_ip_subnet': '192.168.0.0/16',
                'ovs_gtp_port_number': 32768,
                'virtual_interface': 'testing_br',
                'local_ue_eth_addr': False,
                'quota_check_ip': '1.2.3.4',
                'clean_restart': True,
                'dpi': {
                    'enabled': False,
                    'mon_port': 'mon1',
                    'mon_port_number': 32769,
                    'idle_timeout': 42,
                },
                'uplink_port': OFPP_LOCAL,
            },
            mconfig=PipelineD(ue_ip_block="192.168.128.0/24", ),
            loop=None,
            service_manager=cls.service_manager,
            integ_test=False,
        )

        BridgeTools.create_bridge(cls.BRIDGE, cls.IFACE)
        BridgeTools.create_internal_iface(
            cls.BRIDGE,
            cls.DPI_PORT,
            cls.DPI_IP,
        )

        cls.thread = start_ryu_app_thread(test_setup)
        cls.ue_mac_controller = ue_mac_controller_reference.result()
        cls.ingress_controller = ingress_controller_reference.result()
        cls.middle_controller = middle_controller_reference.result()
        cls.egress_controller = egress_controller_reference.result()
        cls.testing_controller = testing_controller_reference.result()
    def setUpClass(cls):
        """
        Starts the thread which launches ryu apps

        Create a testing bridge, add a port, setup the port interfaces. Then
        launch the ryu apps for testing pipelined. Gets the references
        to apps launched by using futures.
        """
        super(AccessControlTestLTE, cls).setUpClass()
        warnings.simplefilter('ignore')
        cls.service_manager = create_service_manager([],
            ['access_control'])
        cls._tbl_num = cls.service_manager.get_table_num(
            AccessControlController.APP_NAME)

        access_control_controller_reference = Future()
        testing_controller_reference = Future()
        test_setup = TestSetup(
            apps=[PipelinedController.AccessControl,
                  PipelinedController.Testing,
                  PipelinedController.StartupFlows],
            references={
                PipelinedController.AccessControl:
                    access_control_controller_reference,
                PipelinedController.Testing:
                    testing_controller_reference,
                PipelinedController.StartupFlows:
                    Future(),
            },
            config={
                'setup_type': 'LTE',
                'allow_unknown_arps': False,
                'bridge_name': cls.BRIDGE,
                'bridge_ip_address': cls.BRIDGE_IP,
                'nat_iface': 'eth2',
                'enodeb_iface': 'eth1',
                'enable_queue_pgm': False,
                'access_control': {
                    'ip_blacklist': [
                        {
                            'ip': cls.INBOUND_TEST_IP,
                            'direction': 'inbound',
                        },
                        {
                            'ip': cls.OUTBOUND_TEST_IP,
                            'direction': 'outbound',
                        },
                        {
                            'ip': cls.BOTH_DIR_TEST_IP,
                        },
                    ]
                },
                'clean_restart': True,
            },
            mconfig=PipelineD(
                allowed_gre_peers=[{'ip': '1.2.3.4/24', 'key': 123}],
            ),
            loop=None,
            service_manager=cls.service_manager,
            integ_test=False,
        )

        BridgeTools.create_bridge(cls.BRIDGE, cls.IFACE)

        cls.thread = start_ryu_app_thread(test_setup)
        cls.access_control_controller = \
            access_control_controller_reference.result()
        cls.testing_controller = testing_controller_reference.result()
    def setUpClass(cls, *_):
        """
        Starts the thread which launches ryu apps

        Create a testing bridge, add a port, setup the port interfaces. Then
        launch the ryu apps for testing pipelined. Gets the references
        to apps launched by using futures, mocks the redis policy_dictionary
        of ue_mac_controller
        """
        super(CWFRestartResilienceTest, cls).setUpClass()
        warnings.simplefilter('ignore')
        cls.service_manager = create_service_manager([], ['ue_mac', 'arpd'])

        ue_mac_controller_reference = Future()
        testing_controller_reference = Future()

        def mock_thread_safe(cmd, body):
            cmd(body)

        loop_mock = MagicMock()
        loop_mock.call_soon_threadsafe = mock_thread_safe

        test_setup = TestSetup(
            apps=[
                PipelinedController.UEMac,
                PipelinedController.Arp,
                PipelinedController.Testing,
                PipelinedController.StartupFlows,
            ],
            references={
                PipelinedController.UEMac: ue_mac_controller_reference,
                PipelinedController.Arp: Future(),
                PipelinedController.Testing: testing_controller_reference,
                PipelinedController.StartupFlows: Future(),
            },
            config={
                'setup_type': 'CWF',
                'bridge_name': cls.BRIDGE,
                'bridge_ip_address': cls.BRIDGE_IP_ADDRESS,
                'enforcement': {
                    'poll_interval': 5
                },
                'internal_ip_subnet': '192.168.0.0/16',
                'nat_iface': 'eth2',
                'local_ue_eth_addr': False,
                'allow_unknown_arps': False,
                'enodeb_iface': 'eth1',
                'qos': {
                    'enable': False
                },
                'clean_restart': False,
                'quota_check_ip': '1.2.3.4',
                'enable_nat': False,
                'dpi': {
                    'enabled': False,
                    'mon_port': 'mon1',
                    'mon_port_number': 32769,
                    'idle_timeout': 42,
                },
            },
            mconfig=PipelineD(ue_ip_block=cls.UE_BLOCK, ),
            loop=loop_mock,
            service_manager=cls.service_manager,
            integ_test=False,
        )

        BridgeTools.create_bridge(cls.BRIDGE, cls.IFACE)
        BridgeTools.create_internal_iface(cls.BRIDGE, cls.DPI_PORT, cls.DPI_IP)

        cls.thread = start_ryu_app_thread(test_setup)

        cls.ue_mac_controller = ue_mac_controller_reference.result()
        cls.testing_controller = testing_controller_reference.result()
Beispiel #30
0
    def setUpClass(cls, *_):
        """
        Starts the thread which launches ryu apps

        Create a testing bridge, add a port, setup the port interfaces. Then
        launch the ryu apps for testing pipelined. Gets the references
        to apps launched by using futures.
        """
        super(UEMacAddressTest, cls).setUpClass()
        warnings.simplefilter('ignore')
        cls.service_manager = create_service_manager(
            [],
            ['ue_mac', 'arpd', 'check_quota'],
        )
        check_quota_controller_reference = Future()
        testing_controller_reference = Future()
        arp_controller_reference = Future()
        test_setup = TestSetup(
            apps=[
                PipelinedController.UEMac,
                PipelinedController.Arp,
                PipelinedController.CheckQuotaController,
                PipelinedController.Testing,
                PipelinedController.StartupFlows,
            ],
            references={
                PipelinedController.CheckQuotaController:
                    check_quota_controller_reference,
                PipelinedController.Testing:
                    testing_controller_reference,
                PipelinedController.UEMac:
                    Future(),
                PipelinedController.Arp:
                    arp_controller_reference,
                PipelinedController.StartupFlows:
                    Future(),
            },
            config={
                'setup_type': 'CWF',
                'allow_unknown_arps': False,
                'bridge_name': cls.BRIDGE,
                'bridge_ip_address': cls.BRIDGE_IP,
                'internal_ip_subnet': '192.168.0.0/16',
                'ovs_gtp_port_number': 32768,
                'has_quota_port': 50001,
                'no_quota_port': 50002,
                'quota_check_ip': '1.2.3.4',
                'local_ue_eth_addr': False,
                'clean_restart': True,
                'dpi': {
                    'enabled': False,
                    'mon_port': 'mon1',
                    'mon_port_number': 32769,
                    'idle_timeout': 42,
                },
            },
            mconfig=PipelineD(
                ue_ip_block='192.168.128.0/24',
            ),
            loop=None,
            service_manager=cls.service_manager,
            integ_test=False,
        )

        BridgeTools.create_bridge(cls.BRIDGE, cls.IFACE)
        BridgeTools.create_internal_iface(
            cls.BRIDGE, cls.DPI_PORT,
            cls.DPI_IP,
        )

        cls.thread = start_ryu_app_thread(test_setup)
        cls.check_quota_controller = check_quota_controller_reference.result()
        cls.arp_controlelr = arp_controller_reference.result()
        cls.testing_controller = testing_controller_reference.result()