Example #1
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(UplinkBridgeWithNonNATTestVlan, cls).setUpClass()
        warnings.simplefilter('ignore')
        cls.service_manager = create_service_manager([])

        uplink_bridge_controller_reference = Future()
        testing_controller_reference = Future()
        test_setup = TestSetup(
            apps=[
                PipelinedController.UplinkBridge,
                PipelinedController.Testing,
                PipelinedController.StartupFlows,
            ],
            references={
                PipelinedController.UplinkBridge:
                    uplink_bridge_controller_reference,
                PipelinedController.Testing:
                    testing_controller_reference,
                PipelinedController.StartupFlows:
                    Future(),
            },
            config={
                'bridge_name': cls.BRIDGE,
                'bridge_ip_address': cls.BRIDGE_IP,
                'ovs_gtp_port_number': 32768,
                'clean_restart': True,
                'enable_nat': False,
                'uplink_bridge': cls.UPLINK_BRIDGE,
                'uplink_eth_port_name': cls.UPLINK_ETH_PORT,
                'virtual_mac': '02:bb:5e:36:06:4b',
                'uplink_patch': cls.UPLINK_PATCH,
                'uplink_dhcp_port': cls.UPLINK_DHCP,
                'sgi_management_iface_vlan': cls.VLAN_TAG,
                'dev_vlan_in': cls.VLAN_DEV_IN,
                'dev_vlan_out': cls.VLAN_DEV_OUT,
                'sgi_management_iface_ip_addr': '1.1.11.1',
                'sgi_management_iface_ipv6_addr': 'fe80::48a3:2cff:fe1a:dd47/10',
            },
            mconfig=None,
            loop=None,
            service_manager=cls.service_manager,
            integ_test=False,
        )

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

        BridgeTools.create_veth_pair(
            cls.VLAN_DEV_IN,
            cls.VLAN_DEV_OUT,
        )
        # Add to OVS,
        BridgeTools.add_ovs_port(
            cls.UPLINK_BRIDGE,
            cls.VLAN_DEV_IN, "70",
        )
        BridgeTools.add_ovs_port(
            cls.UPLINK_BRIDGE,
            cls.VLAN_DEV_OUT, "71",
        )

        # validate vlan id set
        vlan = "10"
        BridgeTools.create_bridge(cls.UPLINK_BRIDGE, cls.UPLINK_BRIDGE)

        BridgeTools.create_internal_iface(
            cls.UPLINK_BRIDGE,
            cls.UPLINK_DHCP, None,
        )
        BridgeTools.create_internal_iface(
            cls.UPLINK_BRIDGE,
            cls.UPLINK_PATCH, None,
        )
        BridgeTools.create_internal_iface(
            cls.UPLINK_BRIDGE,
            cls.UPLINK_ETH_PORT, None,
        )

        cls.thread = start_ryu_app_thread(test_setup)
        cls.uplink_br_controller = uplink_bridge_controller_reference.result()

        cls.testing_controller = testing_controller_reference.result()
Example #2
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.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':
                                       2,
                                       'default_drop_flow_name':
                                       cls.DEFAULT_DROP_FLOW_NAME
                                   },
                                   '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._report_usage = MagicMock()
        cls.enforcement_controller._redirect_manager._save_redirect_entry =\
            MagicMock()
 def tearDown(self):
     stop_ryu_app_thread(self.thread)
     BridgeTools.destroy_bridge(self.BRIDGE)
Example #4
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(ConntrackTest, cls).setUpClass()
        warnings.simplefilter('ignore')
        cls.service_manager = create_service_manager(
            [],
            ['ue_mac', 'conntrack'],
        )
        cls._tbl_num = cls.service_manager.get_table_num(
            ConntrackController.APP_NAME, )

        conntrack_controller_reference = Future()
        testing_controller_reference = Future()
        test_setup = TestSetup(
            apps=[
                PipelinedController.Conntrack,
                PipelinedController.Testing,
                PipelinedController.StartupFlows,
            ],
            references={
                PipelinedController.Conntrack: conntrack_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': [],
                },
                'conntrackd': {
                    'zone': 897,
                },
            },
            mconfig=PipelineD(allowed_gre_peers=[], ),
            loop=None,
            service_manager=cls.service_manager,
            integ_test=False,
        )

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

        cls.thread = start_ryu_app_thread(test_setup)
        cls.conntrack_controller = \
            conntrack_controller_reference.result()
        cls.testing_controller = testing_controller_reference.result()
Example #5
0
    def testSanityTrafficClass(self):
        intf = 'qt'
        BRIDGE = 'qtbr0'
        BridgeTools.create_bridge(BRIDGE, BRIDGE)
        BridgeTools.create_internal_iface(BRIDGE, intf, None)

        parent_qid = 2
        qid = 3
        apn_ambr = 1000000
        bearer_mbr = 500000
        bearer_gbr = 250000
        TrafficClass.init_qdisc(intf, show_error=False)

        # create APN level ambr
        TrafficClass.create_class(intf, qid=parent_qid, max_bw=apn_ambr)

        # create child queue
        TrafficClass.create_class(
            intf,
            qid=qid,
            rate=bearer_gbr,
            max_bw=bearer_mbr,
            parent_qid=parent_qid,
        )

        # check if the filters installed for leaf class only
        filter_output = subprocess.check_output(
            ['tc', 'filter', 'show', 'dev', intf])
        filter_list = filter_output.decode('utf-8').split("\n")
        filter_list = [ln for ln in filter_list if 'classid' in ln]
        assert ('classid 1:{qid}'.format(qid=parent_qid) in filter_list[0])
        assert ('classid 1:{qid}'.format(qid=qid) in filter_list[1])

        # check if classes are installed with appropriate bandwidth limits
        class_output = subprocess.check_output(
            ['tc', 'class', 'show', 'dev', intf])
        class_list = class_output.decode('utf-8').split("\n")
        for info in class_list:
            if 'class htb 1:{qid}'.format(qid=qid) in info:
                child_class = info

            if 'class htb 1:{qid}'.format(qid=parent_qid) in info:
                parent_class = info

        assert (parent_class and 'ceil 1Mbit' in parent_class)
        assert (child_class and 'rate 250Kbit ceil 500Kbit' in child_class)

        # check if fq_codel is associated only with the leaf class
        qdisc_output = subprocess.check_output(
            ['tc', 'qdisc', 'show', 'dev', intf])

        # check if read_all_classes work
        qid_list = TrafficClass.read_all_classes(intf)
        assert ((qid, parent_qid) in qid_list)

        # delete leaf class
        TrafficClass.delete_class(intf, 3)

        # check class for qid 3 removed
        class_output = subprocess.check_output(
            ['tc', 'class', 'show', 'dev', intf])
        class_list = class_output.decode('utf-8').split("\n")
        assert (not [
            info for info in class_list
            if 'class htb 1:{qid}'.format(qid=qid, ) in info
        ])

        # delete APN AMBR class
        TrafficClass.delete_class(intf, 2)

        # verify that parent class is removed
        class_output = subprocess.check_output(
            ['tc', 'class', 'show', 'dev', intf])
        class_list = class_output.decode('utf-8').split("\n")
        assert (not [
            info for info in class_list
            if 'class htb 1:{qid}'.format(qid=parent_qid, ) in info
        ])

        # check if no fq_codel nor filter exists
        qdisc_output = subprocess.check_output(
            ['tc', 'qdisc', 'show', 'dev', intf])
        filter_output = subprocess.check_output(
            ['tc', 'filter', 'show', 'dev', intf])
        filter_list = filter_output.decode('utf-8').split("\n")
        filter_list = [ln for ln in filter_list if 'classid' in ln]
        qdisc_list = qdisc_output.decode('utf-8').split("\n")
        qdisc_list = [ln for ln in qdisc_list if 'fq_codel' in ln]
        assert (not filter_list and not qdisc_list)

        # destroy all qos on intf
        run_cmd(['tc qdisc del dev {intf} root'.format(intf=intf)])
Example #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(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',
                'qos': {
                    'enable': False
                },
                'access_control': {
                    'ip_blocklist': [
                        {
                            '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()
Example #7
0
 def tearDown(self):
     self._dhcp_allocator.ip_allocator.stop_dhcp_sniffer()
     BridgeTools.destroy_bridge(self._br)
Example #8
0
def main():
    """
    Loads the Ryu apps we want to run from the config file.
    This should exit on keyboard interrupt.
    """

    # Run asyncio loop in a greenthread so we can evaluate other eventlets
    # TODO: Remove once Ryu migrates to asyncio
    asyncio.set_event_loop_policy(aioeventlet.EventLoopPolicy())

    service = MagmaService('pipelined', mconfigs_pb2.PipelineD())
    service_config = service.config

    if environment.is_dev_mode():
        of_rest_server.configure(service_config)

    # Set Ryu config params
    cfg.CONF.ofp_listen_host = "127.0.0.1"

    # override mconfig using local config.
    # TODO: move config compilation to separate module.
    enable_nat = service.config.get('enable_nat', service.mconfig.nat_enabled)
    service.config['enable_nat'] = enable_nat
    logging.info("Nat: %s", enable_nat)
    vlan_tag = service.config.get('sgi_management_iface_vlan',
                                  service.mconfig.sgi_management_iface_vlan)
    service.config['sgi_management_iface_vlan'] = vlan_tag

    sgi_ip = service.config.get('sgi_management_iface_ip_addr',
                                service.mconfig.sgi_management_iface_ip_addr)
    service.config['sgi_management_iface_ip_addr'] = sgi_ip

    sgi_gateway_ip = service.config.get('sgi_management_iface_gw',
                                        service.mconfig.sgi_management_iface_gw)
    service.config['sgi_management_iface_gw'] = sgi_gateway_ip

    if 'virtual_mac' not in service.config:
        service.config['virtual_mac'] = get_if_hwaddr(service.config.get('bridge_name'))

    # this is not read from yml file.
    service.config['uplink_port'] = OFPP_LOCAL
    uplink_port_name = service.config.get('ovs_uplink_port_name', None)
    if enable_nat is False and uplink_port_name is not None:
        service.config['uplink_port'] = BridgeTools.get_ofport(uplink_port_name)

    service.config['proxy_port_name'] = PROXY_PORT_NAME

    # Load the ryu apps
    service_manager = ServiceManager(service)
    service_manager.load()

    def callback(returncode):
        if returncode != 0:
            logging.error(
                "Failed to set MASQUERADE: %d", returncode
            )

    # TODO fix this hack for XWF
    if enable_nat is True or service.config.get('setup_type') == 'XWF':
        call_process('iptables -t nat -A POSTROUTING -o %s -j MASQUERADE'
                     % service.config['nat_iface'],
                     callback,
                     service.loop
                     )

    service.loop.create_task(monitor_ifaces(
        service.config['monitored_ifaces'],
        service.loop),
    )

    manager = AppManager.get_instance()
    # Add pipelined rpc servicer
    pipelined_srv = PipelinedRpcServicer(
        service.loop,
        manager.applications.get('GYController', None),
        manager.applications.get('EnforcementController', None),
        manager.applications.get('EnforcementStatsController', None),
        manager.applications.get('DPIController', None),
        manager.applications.get('UEMacAddressController', None),
        manager.applications.get('CheckQuotaController', None),
        manager.applications.get('IPFIXController', None),
        manager.applications.get('VlanLearnController', None),
        manager.applications.get('TunnelLearnController', None),
        manager.applications.get('Classifier', None),
        service.config,
        service_manager)
    pipelined_srv.add_to_server(service.rpc_server)

    if service.config['setup_type'] == 'CWF':
        bridge_ip = service.config['bridge_ip_address']
        has_quota_port = service.config['has_quota_port']
        no_quota_port = service.config['no_quota_port']

        def on_exit_server_thread():
            service.StopService(None, None)

        # For CWF start quota check servers
        start_check_quota_server(run_flask, bridge_ip, has_quota_port, True,
                                 on_exit_server_thread)
        start_check_quota_server(run_flask, bridge_ip, no_quota_port, False,
                                 on_exit_server_thread)

    if service.config['setup_type'] == 'LTE':
        polling_interval = service.config.get('ovs_gtp_stats_polling_interval',
                                              MIN_OVSDB_DUMP_POLLING_INTERVAL)
        collector = GTPStatsCollector(
            polling_interval,
            service.loop)
        collector.start()

    # Run the service loop
    service.run()

    # Cleanup the service
    service.close()
    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()
        arp_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: arp_controller_reference,
                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()
        cls.arp_controller = arp_controller_reference.result()
        cls.arp_controller.add_arp_response_flow = MagicMock()
Example #10
0
 def tearDown(self):
     cls = ArpTableTestRouterIP
     stop_ryu_app_thread(cls.thread)
     BridgeTools.destroy_bridge(cls.BRIDGE)
Example #11
0
def main():
    """
    Loads the Ryu apps we want to run from the config file.
    This should exit on keyboard interrupt.
    """

    # Run asyncio loop in a greenthread so we can evaluate other eventlets
    # TODO: Remove once Ryu migrates to asyncio
    asyncio.set_event_loop_policy(aioeventlet.EventLoopPolicy())

    service = MagmaService('pipelined', mconfigs_pb2.PipelineD())

    # Optionally pipe errors to Sentry
    sentry_init(service_name=service.name)

    service_config = service.config

    if environment.is_dev_mode():
        of_rest_server.configure(service_config)

    # Set Ryu config params
    cfg.CONF.ofp_listen_host = "127.0.0.1"

    # override mconfig using local config.
    # TODO: move config compilation to separate module.
    enable_nat = service.config.get('enable_nat', service.mconfig.nat_enabled)
    service.config['enable_nat'] = enable_nat
    logging.info("Nat: %s", enable_nat)
    vlan_tag = service.config.get(
        'sgi_management_iface_vlan',
        service.mconfig.sgi_management_iface_vlan,
    )
    service.config['sgi_management_iface_vlan'] = vlan_tag

    sgi_ip = service.config.get(
        'sgi_management_iface_ip_addr',
        service.mconfig.sgi_management_iface_ip_addr,
    )
    service.config['sgi_management_iface_ip_addr'] = sgi_ip

    sgi_gateway_ip = service.config.get(
        'sgi_management_iface_gw',
        service.mconfig.sgi_management_iface_gw,
    )
    service.config['sgi_management_iface_gw'] = sgi_gateway_ip

    # Keep router mode off for smooth upgrade path
    service.config['dp_router_enabled'] = service.config.get(
        'dp_router_enabled',
        False,
    )
    if 'virtual_mac' not in service.config:
        if service.config['dp_router_enabled']:
            up_bridge_name = service.config.get(
                'uplink_bridge',
                UPLINK_OVS_BRIDGE_NAME,
            )
            mac_addr = get_if_hwaddr(up_bridge_name)
        else:
            mac_addr = get_if_hwaddr(service.config.get('bridge_name'))

        service.config['virtual_mac'] = mac_addr

    # this is not read from yml file.
    service.config['uplink_port'] = OFPP_LOCAL
    uplink_port_name = service.config.get('ovs_uplink_port_name', None)
    if enable_nat is False and uplink_port_name is not None:
        service.config['uplink_port'] = BridgeTools.get_ofport(
            uplink_port_name, )

    # header enrichment related configuration.
    service.config['proxy_port_name'] = PROXY_PORT_NAME
    he_enabled_flag = False
    if service.mconfig.he_config:
        he_enabled_flag = service.mconfig.he_config.enable_header_enrichment
    he_enabled = service.config.get('he_enabled', he_enabled_flag)
    service.config['he_enabled'] = he_enabled

    # tune datapath according to config
    tune_datapath(service.config)

    # monitoring related configuration
    mtr_interface = service.config.get('mtr_interface', None)
    if mtr_interface:
        mtr_ip = get_ip_from_if(mtr_interface)
        service.config['mtr_ip'] = mtr_ip

    # Load the ryu apps
    service_manager = ServiceManager(service)
    service_manager.load()

    def callback(returncode):
        if returncode != 0:
            logging.error(
                "Failed to set MASQUERADE: %d",
                returncode,
            )

    # TODO fix this hack for XWF
    if enable_nat is True or service.config.get('setup_type') == 'XWF':
        ip_table_rule = 'POSTROUTING -o %s -j MASQUERADE' % service.config[
            'nat_iface']
        check_and_add = 'iptables -t nat -C %s || iptables -t nat -A %s' % \
                (ip_table_rule, ip_table_rule)
        logging.debug("check_and_add: %s", check_and_add)
        call_process(
            check_and_add,
            callback,
            service.loop,
        )

    service.loop.create_task(
        monitor_ifaces(service.config['monitored_ifaces'], ), )

    manager = AppManager.get_instance()
    # Add pipelined rpc servicer
    pipelined_srv = PipelinedRpcServicer(
        service.loop,
        manager.applications.get('GYController', None),
        manager.applications.get('EnforcementController', None),
        manager.applications.get('EnforcementStatsController', None),
        manager.applications.get('DPIController', None),
        manager.applications.get('UEMacAddressController', None),
        manager.applications.get('CheckQuotaController', None),
        manager.applications.get('IPFIXController', None),
        manager.applications.get('VlanLearnController', None),
        manager.applications.get('TunnelLearnController', None),
        manager.applications.get('Classifier', None),
        manager.applications.get('InOutController', None),
        manager.applications.get('NGServiceController', None),
        service.config,
        service_manager,
    )
    pipelined_srv.add_to_server(service.rpc_server)

    if service.config['setup_type'] == 'CWF':
        bridge_ip = service.config['bridge_ip_address']
        has_quota_port = service.config['has_quota_port']
        no_quota_port = service.config['no_quota_port']

        def on_exit_server_thread():
            service.StopService(None, None)

        # For CWF start quota check servers
        start_check_quota_server(
            run_flask,
            bridge_ip,
            has_quota_port,
            True,
            on_exit_server_thread,
        )
        start_check_quota_server(
            run_flask,
            bridge_ip,
            no_quota_port,
            False,
            on_exit_server_thread,
        )

    if service.config['setup_type'] == 'LTE':
        polling_interval = service.config.get(
            'ovs_gtp_stats_polling_interval',
            MIN_OVSDB_DUMP_POLLING_INTERVAL,
        )
        collector = GTPStatsCollector(
            polling_interval,
            service.loop,
        )
        collector.start()

    # Run the service loop
    service.run()

    # Cleanup the service
    service.close()
Example #12
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(UplinkBridgeWithNonNatUplinkConnect_Test, cls).setUpClass()
        warnings.simplefilter('ignore')
        cls.service_manager = create_service_manager([])

        BridgeTools.create_bridge(cls.UPLINK_BRIDGE, cls.UPLINK_BRIDGE)
        br_mac = BridgeTools.get_mac_address(cls.UPLINK_BRIDGE)

        cls._setup_vlan_network("0", br_mac)

        BridgeTools.create_internal_iface(
            cls.UPLINK_BRIDGE,
            cls.UPLINK_DHCP, None,
        )
        BridgeTools.create_internal_iface(
            cls.UPLINK_BRIDGE,
            cls.UPLINK_PATCH, None,
        )
        flush_ip_cmd = [
            "ip",
            "addr", "flush",
            "dev",
            cls.UPLINK_BRIDGE,
        ]
        subprocess.check_call(flush_ip_cmd)

        set_ip_cmd = [
            "ip",
            "addr", "replace",
            "fe80::b0a6:34ff:fee0:b640",
            "dev",
            cls.UPLINK_BRIDGE,
        ]
        subprocess.check_call(set_ip_cmd)

        check_connectivity(cls.ROUTER_IP, cls.UPLINK_ETH_PORT)

        BridgeTools.add_ovs_port(cls.UPLINK_BRIDGE, cls.UPLINK_ETH_PORT, "200")

        # this is setup after AGW boot up in NATed mode.
        uplink_bridge_controller_reference = Future()
        testing_controller_reference = Future()
        test_setup = TestSetup(
            apps=[
                PipelinedController.UplinkBridge,
                PipelinedController.Testing,
                PipelinedController.StartupFlows,
            ],
            references={
                PipelinedController.UplinkBridge:
                    uplink_bridge_controller_reference,
                PipelinedController.Testing:
                    testing_controller_reference,
                PipelinedController.StartupFlows:
                    Future(),
            },
            config={
                'bridge_name': cls.BRIDGE,
                'bridge_ip_address': cls.BRIDGE_IP,
                'ovs_gtp_port_number': 32768,
                'clean_restart': True,
                'enable_nat': False,
                'uplink_bridge': cls.UPLINK_BRIDGE,
                'uplink_eth_port_name': cls.UPLINK_ETH_PORT,
                'virtual_mac': '02:bb:5e:36:06:4b',
                'uplink_patch': cls.UPLINK_PATCH,
                'uplink_dhcp_port': cls.UPLINK_DHCP,
                'sgi_management_iface_vlan': "",
                'ovs_vlan_workaround': True,
                'dev_vlan_in': "testv1_in",
                'dev_vlan_out': "testv1_out",
                'sgi_ip_monitoring': False,
            },
            mconfig=None,
            loop=None,
            service_manager=cls.service_manager,
            integ_test=False,
        )

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

        cls.thread = start_ryu_app_thread(test_setup)
        cls.uplink_br_controller = uplink_bridge_controller_reference.result()

        cls.testing_controller = testing_controller_reference.result()
Example #13
0
 def tearDownClass(cls):
     stop_ryu_app_thread(cls.thread)
     BridgeTools.destroy_bridge(cls.BRIDGE)
     BridgeTools.destroy_bridge(cls.UPLINK_BRIDGE)
     BridgeTools.destroy_bridge(cls.NET_SW_BR)
     subprocess.check_call(["ip", "link", "del", "dev", "testv1_in"])
Example #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(UplinkBridgeWithNonNATTest_IP_VLAN_GW, cls).setUpClass()
        warnings.simplefilter('ignore')
        cls.service_manager = create_service_manager([])

        uplink_bridge_controller_reference = Future()
        testing_controller_reference = Future()
        test_setup = TestSetup(
            apps=[
                PipelinedController.UplinkBridge,
                PipelinedController.Testing,
                PipelinedController.StartupFlows,
            ],
            references={
                PipelinedController.UplinkBridge:
                    uplink_bridge_controller_reference,
                PipelinedController.Testing:
                    testing_controller_reference,
                PipelinedController.StartupFlows:
                    Future(),
            },
            config={
                'bridge_name': cls.BRIDGE,
                'bridge_ip_address': cls.BRIDGE_IP,
                'ovs_gtp_port_number': 32768,
                'clean_restart': True,
                'enable_nat': False,
                'uplink_bridge': cls.UPLINK_BRIDGE,
                'uplink_eth_port_name': cls.UPLINK_ETH_PORT,
                'virtual_mac': '02:bb:5e:36:06:4b',
                'uplink_patch': cls.UPLINK_PATCH,
                'uplink_dhcp_port': cls.UPLINK_DHCP,
                'sgi_management_iface_vlan': cls.VLAN_TAG,
                'sgi_management_iface_ip_addr': cls.SGi_IP,
                'sgi_management_iface_gw': cls.SGi_GW,
                'sgi_management_iface_ipv6_gw': cls.SGi_IPv6_GW,
                'dev_vlan_in': "test_v_in",
                'dev_vlan_out': "test_v_out",
                'sgi_management_iface_ipv6_addr': 'fe80::48a3:2cff:aaaa:dd47/10',
            },
            mconfig=None,
            loop=None,
            service_manager=cls.service_manager,
            integ_test=False,
        )

        BridgeTools.create_bridge(cls.BRIDGE, cls.BRIDGE)
        # validate vlan id set
        vlan = "10"
        BridgeTools.create_bridge(cls.UPLINK_BRIDGE, cls.UPLINK_BRIDGE)
        subprocess.Popen([
            "ovs-vsctl", "set", "port", cls.UPLINK_BRIDGE,
            "tag=" + vlan,
        ]).wait()
        assert get_ovsdb_port_tag(cls.UPLINK_BRIDGE) == vlan

        set_ip_cmd = [
            "ip",
            "addr", "replace",
            "2.33.44.6",
            "dev",
            cls.UPLINK_BRIDGE,
        ]
        subprocess.check_call(set_ip_cmd)

        BridgeTools.create_internal_iface(
            cls.UPLINK_BRIDGE,
            cls.UPLINK_DHCP, None,
        )
        BridgeTools.create_internal_iface(
            cls.UPLINK_BRIDGE,
            cls.UPLINK_PATCH, None,
        )
        BridgeTools.create_internal_iface(
            cls.UPLINK_BRIDGE,
            cls.UPLINK_ETH_PORT, None,
        )

        cls.thread = start_ryu_app_thread(test_setup)
        cls.uplink_br_controller = uplink_bridge_controller_reference.result()

        cls.testing_controller = testing_controller_reference.result()
Example #15
0
    def test_attach_multi_tunnel_flows(self):

        # Need to delete all default flows in table 0 before
        # install the specific flows test case.
        self.test_detach_default_tunnel_flows()

        ip_no = hex(socket.htonl(int(ipaddress.ip_address(self.EnodeB_IP))))
        buf = "g_{}".format(ip_no[2:])

        BridgeTools.create_veth_pair(buf, buf + "ns")
        BridgeTools.add_ovs_port(self.BRIDGE, buf, "40")

        seid1 = 5000
        ue_ip_addr = "192.168.128.30"
        ip_flow_dl = IPFlowDL(set_params=0)
        self.classifier_controller.add_tunnel_flows(
            65525,
            1,
            100000,
            IPAddress(version=IPAddress.IPV4,
                      address=ue_ip_addr.encode('utf-8')),
            self.EnodeB_IP,
            seid1,
            True,
            ip_flow_dl=ip_flow_dl)

        ip_no = hex(socket.htonl(int(ipaddress.ip_address(self.EnodeB2_IP))))
        buf = "g_{}".format(ip_no[2:])

        BridgeTools.create_veth_pair(buf, buf + "ns")
        BridgeTools.add_ovs_port(self.BRIDGE, buf, "41")

        seid2 = 5001
        ue_ip_addr = "192.168.128.31"
        self.classifier_controller.add_tunnel_flows(
            65525,
            2,
            100001,
            IPAddress(version=IPAddress.IPV4,
                      address=ue_ip_addr.encode('utf-8')),
            self.EnodeB2_IP,
            seid2,
            True,
            ip_flow_dl=ip_flow_dl)

        ue_ip_addr = "192.168.128.51"
        self.classifier_controller.add_tunnel_flows(
            65525,
            5,
            1001,
            IPAddress(version=IPAddress.IPV4,
                      address=ue_ip_addr.encode('utf-8')),
            self.EnodeB2_IP,
            seid2,
            True,
            ip_flow_dl=ip_flow_dl)

        snapshot_verifier = SnapshotVerifier(self, self.BRIDGE,
                                             self.service_manager)
        with snapshot_verifier:
            pass
Example #16
0
 def setUpClass(cls):
     BridgeTools.create_bridge(cls.BRIDGE, cls.BRIDGE)
     BridgeTools.create_internal_iface(cls.BRIDGE, cls.IFACE, None)
     TrafficClass.init_qdisc(cls.IFACE, True)
Example #17
0
 def __init__(self, *args, **kwargs):
     super(InOutController, self).__init__(*args, **kwargs)
     self.config = self._get_config(kwargs['config'])
     self._uplink_port = OFPP_LOCAL
     if (self.config.uplink_port_name):
         self._uplink_port = BridgeTools.get_ofport(self.config.uplink_port_name)
Example #18
0
 def tearDownClass(cls):
     BridgeTools.destroy_bridge(cls.BRIDGE)
     pass
Example #19
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 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()
        testing_controller_reference = Future()
        test_setup = TestSetup(apps=[
            PipelinedController.UEMac, PipelinedController.DPI,
            PipelinedController.Testing, PipelinedController.StartupFlows
        ],
                               references={
                                   PipelinedController.UEMac:
                                   ue_mac_controller_reference,
                                   PipelinedController.DPI:
                                   dpi_controller_reference,
                                   PipelinedController.Arp: Future(),
                                   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': False,
                                       'mon_port': 'mon1',
                                       'mon_port_number': 32769,
                                       'idle_timeout': 42,
                                   },
                               },
                               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.ue_mac_controller = ue_mac_controller_reference.result()
        cls.dpi_controller = dpi_controller_reference.result()
        cls.testing_controller = testing_controller_reference.result()

        cls.dpi_controller._policy_dict = cls._static_rule_dict
Example #20
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(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
Example #21
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(
            EnforcementStatsController.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.Testing,
            PipelinedController.Enforcement_stats
        ],
                               references={
                                   PipelinedController.Enforcement:
                                   enforcement_controller_reference,
                                   PipelinedController.Testing:
                                   testing_controller_reference,
                                   PipelinedController.Enforcement_stats:
                                   enf_stat_ref
                               },
                               config={
                                   'bridge_name': self.BRIDGE,
                                   'bridge_ip_address': '192.168.128.1',
                                   'enforcement': {
                                       'poll_interval': 5
                                   },
                                   'nat_iface': 'eth2',
                                   'enodeb_iface': 'eth1',
                                   'enable_queue_pgm': False,
                               },
                               mconfig=PipelineD(relay_enabled=True, ),
                               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()
Example #22
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(LIMirrorTest, cls).setUpClass()
        warnings.simplefilter('ignore')
        cls.service_manager = create_service_manager([], ['li_mirror'])

        inout_controller_reference = Future()
        li_mirror_reference = Future()
        testing_controller_reference = Future()
        test_setup = TestSetup(
            apps=[
                PipelinedController.InOut,
                PipelinedController.LIMirror,
                PipelinedController.Testing,
                PipelinedController.StartupFlows,
            ],
            references={
                PipelinedController.InOut: inout_controller_reference,
                PipelinedController.LIMirror: li_mirror_reference,
                PipelinedController.Testing: testing_controller_reference,
                PipelinedController.StartupFlows: Future(),
            },
            config={
                'setup_type': 'CWF',
                'bridge_name': cls.BRIDGE,
                'bridge_ip_address': cls.BRIDGE_IP,
                'internal_ip_subnet': '192.168.0.0/16',
                'ovs_gtp_port_number': 32768,
                'clean_restart': True,
                'li_mirror_all': True,
                'li_local_iface': cls.LI_LOCAL_IFACE,
                'li_dst_iface': cls.LI_DST_IFACE,
                'uplink_port': OFPP_LOCAL,
            },
            mconfig=None,
            loop=None,
            service_manager=cls.service_manager,
            integ_test=False,
        )

        BridgeTools.create_bridge(cls.BRIDGE, cls.IFACE)
        BridgeTools.create_internal_iface(
            cls.BRIDGE,
            cls.LI_LOCAL_IFACE,
            cls.LI_LOCAL_IP,
        )
        BridgeTools.create_internal_iface(
            cls.BRIDGE,
            cls.LI_DST_IFACE,
            cls.LI_DST_IP,
        )

        cls.thread = start_ryu_app_thread(test_setup)
        cls.inout_controller = inout_controller_reference.result()
        cls.li_controller = li_mirror_reference.result()
        cls.testing_controller = testing_controller_reference.result()
Example #23
0
def main():
    """
    Loads the Ryu apps we want to run from the config file.
    This should exit on keyboard interrupt.
    """

    # Run asyncio loop in a greenthread so we can evaluate other eventlets
    # TODO: Remove once Ryu migrates to asyncio
    asyncio.set_event_loop_policy(aioeventlet.EventLoopPolicy())

    service = MagmaService('pipelined', mconfigs_pb2.PipelineD())

    # Optionally pipe errors to Sentry
    sentry_init(service_name=service.name,
                sentry_mconfig=service.shared_mconfig.sentry_config)

    service_config = service.config

    if environment.is_dev_mode():
        of_rest_server.configure(service_config)

    # Set Ryu config params
    cfg.CONF.ofp_listen_host = "127.0.0.1"

    # override mconfig using local config.
    # TODO: move config compilation to separate module.
    enable_nat = service.config.get('enable_nat', service.mconfig.nat_enabled)
    service.config['enable_nat'] = enable_nat
    logging.info("Nat: %s", enable_nat)
    enable5g_features = service.config.get(
        'enable5g_features',
        service.mconfig.enable5g_features,
    )
    service.config['enable5g_features'] = enable5g_features
    logging.info("enable5g_features: %s", enable5g_features)
    vlan_tag = service.config.get(
        'sgi_management_iface_vlan',
        service.mconfig.sgi_management_iface_vlan,
    )
    service.config['sgi_management_iface_vlan'] = vlan_tag

    sgi_ip = service.config.get(
        'sgi_management_iface_ip_addr',
        service.mconfig.sgi_management_iface_ip_addr,
    )
    service.config['sgi_management_iface_ip_addr'] = sgi_ip

    sgi_gateway_ip = service.config.get(
        'sgi_management_iface_gw',
        service.mconfig.sgi_management_iface_gw,
    )
    service.config['sgi_management_iface_gw'] = sgi_gateway_ip

    # SGi IPv6 address conf
    sgi_ipv6 = service.config.get(
        'sgi_management_iface_ipv6_addr',
        service.mconfig.sgi_management_iface_ipv6_addr,
    )
    service.config['sgi_management_iface_ipv6_addr'] = sgi_ipv6

    sgi_gateway_ipv6 = service.config.get(
        'sgi_management_iface_ipv6_gw',
        service.mconfig.sgi_management_iface_ipv6_gw,
    )
    service.config['sgi_management_iface_ipv6_gw'] = sgi_gateway_ipv6

    # Keep router mode off for smooth upgrade path
    service.config['dp_router_enabled'] = service.config.get(
        'dp_router_enabled',
        False,
    )
    if 'virtual_mac' not in service.config:
        if service.config['dp_router_enabled']:
            up_iface_name = service.config.get('nat_iface', None)
            mac_addr = get_if_hwaddr(up_iface_name)
        else:
            mac_addr = get_if_hwaddr(service.config.get('bridge_name'))

        service.config['virtual_mac'] = mac_addr

    # this is not read from yml file.
    service.config['uplink_port'] = OFPP_LOCAL
    uplink_port_name = service.config.get('ovs_uplink_port_name', None)
    if enable_nat is False and uplink_port_name is not None:
        service.config['uplink_port'] = BridgeTools.get_ofport(
            uplink_port_name, )

    # header enrichment related configuration.
    service.config['proxy_port_name'] = PROXY_PORT_NAME
    he_enabled_flag = False
    if service.mconfig.he_config:
        he_enabled_flag = service.mconfig.he_config.enable_header_enrichment
        if he_enabled_flag:
            bridge = service.config.get('bridge_name')
            BridgeTools.add_ovs_port(bridge, PROXY_PORT_NAME, PROXY_OF_PORT)

    he_enabled = service.config.get('he_enabled', he_enabled_flag)
    service.config['he_enabled'] = he_enabled

    # tune datapath according to config
    configure_tso(service.config)
    setup_sgi_tunnel(service.config, service.loop)
    tune_datapath(service.config)
    setup_masquerade_rule(service.config, service.loop)

    # monitoring related configuration
    mtr_interface = service.config.get('mtr_interface', None)
    if mtr_interface:
        try:
            service.config['mtr_ip'] = get_ip_from_if(mtr_interface)
        except ValueError:
            logging.warning("Unable to set up mtr interface", exc_info=True)

    # Load the ryu apps
    service_manager = ServiceManager(service)
    service_manager.load()

    service.loop.create_task(
        monitor_ifaces(service.config['monitored_ifaces'], ), )

    manager = AppManager.get_instance()
    # Add pipelined rpc servicer
    pipelined_srv = PipelinedRpcServicer(
        service.loop,
        manager.applications.get('GYController', None),
        manager.applications.get('EnforcementController', None),
        manager.applications.get('EnforcementStatsController', None),
        manager.applications.get('DPIController', None),
        manager.applications.get('UEMacAddressController', None),
        manager.applications.get('CheckQuotaController', None),
        manager.applications.get('IPFIXController', None),
        manager.applications.get('VlanLearnController', None),
        manager.applications.get('TunnelLearnController', None),
        manager.applications.get('Classifier', None),
        manager.applications.get('IngressController', None),
        manager.applications.get('MiddleController', None),
        manager.applications.get('EgressController', None),
        manager.applications.get('NGServiceController', None),
        service.config,
        service_manager,
    )
    pipelined_srv.add_to_server(service.rpc_server)

    if service.config['setup_type'] == 'CWF':
        bridge_ip = service.config['bridge_ip_address']
        has_quota_port = service.config['has_quota_port']
        no_quota_port = service.config['no_quota_port']

        def on_exit_server_thread():
            service.StopService(None, None)

        # For CWF start quota check servers
        start_check_quota_server(
            run_flask,
            bridge_ip,
            has_quota_port,
            True,
            on_exit_server_thread,
        )
        start_check_quota_server(
            run_flask,
            bridge_ip,
            no_quota_port,
            False,
            on_exit_server_thread,
        )

    if service.config['setup_type'] == 'LTE':
        polling_interval = service.config.get(
            'ovs_gtp_stats_polling_interval',
            MIN_OVSDB_DUMP_POLLING_INTERVAL,
        )
        collector = GTPStatsCollector(
            polling_interval,
            service.loop,
        )
        collector.start()

    # Run the service loop
    service.run()

    # Cleanup the service
    service.close()
Example #24
0
    def setUpNetworkAndController(
        self, vlan: str = "",
        non_nat_arp_egress_port: str = None,
        gw_mac_addr="ff:ff:ff:ff:ff:ff",
    ):
        """
        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 = self.__class__
        super(InOutNonNatTest, cls).setUpClass()
        inout.get_mobilityd_gw_info = mocked_get_mobilityd_gw_info
        inout.set_mobilityd_gw_info = mocked_set_mobilityd_gw_info

        warnings.simplefilter('ignore')
        cls.setup_uplink_br()

        if vlan != "":
            cls._setup_vlan_network(vlan)

        cls.service_manager = create_service_manager([])

        inout_controller_reference = Future()
        testing_controller_reference = Future()

        if non_nat_arp_egress_port is None:
            non_nat_arp_egress_port = cls.DHCP_PORT

        patch_up_port_no = BridgeTools.get_ofport('patch-up')
        test_setup = TestSetup(
            apps=[
                PipelinedController.InOut,
                PipelinedController.Testing,
                PipelinedController.StartupFlows,
            ],
            references={
                PipelinedController.InOut:
                    inout_controller_reference,
                PipelinedController.Testing:
                    testing_controller_reference,
                PipelinedController.StartupFlows:
                    Future(),
            },
            config={
                'setup_type': 'LTE',
                'bridge_name': cls.BRIDGE,
                'bridge_ip_address': cls.BRIDGE_IP,
                'ovs_gtp_port_number': 32768,
                'clean_restart': True,
                'enable_nat': False,
                'non_nat_gw_probe_frequency': 0.5,
                'non_nat_arp_egress_port': non_nat_arp_egress_port,
                'uplink_port': patch_up_port_no,
                'uplink_gw_mac': gw_mac_addr,
            },
            mconfig=None,
            loop=None,
            service_manager=cls.service_manager,
            integ_test=False,
        )

        BridgeTools.create_bridge(cls.BRIDGE, cls.IFACE)
        subprocess.Popen(["ifconfig", cls.UPLINK_BR, "192.168.128.41"]).wait()
        cls.thread = start_ryu_app_thread(test_setup)
        cls.inout_controller = inout_controller_reference.result()

        cls.testing_controller = testing_controller_reference.result()
Example #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.
        """
        super(UEMacAddressTest, cls).setUpClass()
        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)

        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,
                PipelinedController.StartupFlows
            ],
            references={
                PipelinedController.InOut: inout_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.inout_controller = inout_controller_reference.result()
        cls.testing_controller = testing_controller_reference.result()
Example #26
0
 def tearDownClass(cls):
     cls.inout_controller._stop_gw_mac_monitor()
     stop_ryu_app_thread(cls.thread)
     BridgeTools.destroy_bridge(cls.BRIDGE)
     time.sleep(1)
     clear_gw_info_map()
Example #27
0
 def tearDown(self):
     self._dhcp_client.stop()
     BridgeTools.destroy_bridge(self._br)
Example #28
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.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,
                'setup_type': 'LTE',
            },
            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()
Example #29
0
 def tearDownClass(cls):
     stop_ryu_app_thread(cls.thread)
     BridgeTools.destroy_bridge(cls.BRIDGE)
Example #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()