コード例 #1
0
    def test_attach_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"
        self.classifier_controller.add_tunnel_flows(65525, 1, 100000,
                                                    IPAddress(version=IPAddress.IPV4,address=ue_ip_addr.encode('utf-8')),
                                                    self.EnodeB_IP, seid1)

        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.EnodeB_IP, seid2)

        snapshot_verifier = SnapshotVerifier(self, self.BRIDGE,
                                             self.service_manager)
        with snapshot_verifier:
            pass
コード例 #2
0
ファイル: test_classifier.py プロジェクト: ssanadhya/magma
    def test_attach_s8_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")

        ue_ip_addr = "192.168.128.15"
        ip_flow_dl = IPFlowDL(set_params=0)
        self.classifier_controller.add_s8_tunnel_flows(
            65525,
            10,
            5000,
            IPAddress(version=IPAddress.IPV4,
                      address=ue_ip_addr.encode('utf-8')),
            self.EnodeB_IP,
            5678,
            "192.168.60.112",
            3000,
            True,
            ip_flow_dl=ip_flow_dl,
        )

        snapshot_verifier = SnapshotVerifier(
            self,
            self.BRIDGE,
            self.service_manager,
        )
        with snapshot_verifier:
            pass
コード例 #3
0
ファイル: test_he.py プロジェクト: katojunya/magma
    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()
コード例 #4
0
 def _setup_vlan_pop_dev(self):
     if self.config.ovs_vlan_workaround:
         # Create device
         BridgeTools.create_veth_pair(self.config.dev_vlan_in,
                                      self.config.dev_vlan_out)
         # Add to OVS,
         # OFP requested port (70 and 71) no are for test validation,
         # its not used anywhere else.
         BridgeTools.add_ovs_port(self.config.uplink_bridge,
                                  self.config.dev_vlan_in, "70")
         BridgeTools.add_ovs_port(self.config.uplink_bridge,
                                  self.config.dev_vlan_out, "71")
コード例 #5
0
    def _get_config(self, config_dict, mconfig) -> namedtuple:
        he_enabled = config_dict.get('he_enabled', True)
        uplink_port = config_dict.get('uplink_port', None)
        proxy_port_name = config_dict.get('proxy_port_name')

        bridge = config_dict.get('bridge_name')
        BridgeTools.add_ovs_port(bridge, proxy_port_name, PROXY_OF_PORT)

        try:
            he_proxy_port = BridgeTools.get_ofport(proxy_port_name)
        except DatapathLookupError:
            he_enabled = False
            uplink_port = 0
            he_proxy_port = 0

        encryption_algorithm = None
        hash_function = None
        encoding_type = None
        encryption_enabled = False
        encryption_key = None
        if mconfig.he_config and mconfig.he_config.enable_encryption:
            encryption_enabled = True
            encryption_key = mconfig.he_config.encryption_key
            encryption_algorithm = mconfig.he_config.encryptionAlgorithm
            hash_function = mconfig.he_config.hashFunction
            encoding_type = mconfig.he_config.encodingType

        return self.UplinkConfig(
            gtp_port=config_dict['ovs_gtp_port_number'],
            he_proxy_port=he_proxy_port,
            he_enabled=he_enabled,
            encryption_enabled=encryption_enabled,
            encryption_algorithm=encryption_algorithm,
            hash_function=hash_function,
            encoding_type=encoding_type,
            encryption_key=encryption_key,
            uplink_port=uplink_port,
        )
コード例 #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, 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()
コード例 #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.
        """
        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',
            },
            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()
コード例 #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.
        """
        super(UplinkBridgeWithNonNatUplinkConnect_Test, cls).setUpClass()
        warnings.simplefilter('ignore')
        cls.service_manager = create_service_manager([])

        cls._setup_vlan_network("0")

        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,
        )

        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",
            },
            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()
コード例 #9
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('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()