Beispiel #1
0
def cli():
    """CLI Entry

    TODO: Add support for sub-command
    """
    logger = logging.getLogger(__name__)
    desc = 'SFC-OSTACK Framework'
    parser = argparse.ArgumentParser(description=desc)

    parser.add_argument('conf_path',
                        help='Path of configuration file(YAML format).',
                        type=str)
    parser.add_argument('operation',
                        help='Operation for SFC',
                        choices=['create', 'delete'])

    if len(sys.argv) < 2:
        parser.print_help()
        sys.exit(0)
    args = parser.parse_args()

    conf_hd = conf.ConfigHolder('yaml', args.conf_path)
    auth_args = conf_hd.get_cloud_auth()
    flow_conf = conf_hd.get_sfc_flow()
    net_conf = conf_hd.get_sfc_net()
    srv_queue = conf_hd.get_sfc_server()
    fc_conf = conf_hd.get_sfc_fc()

    if args.operation == 'create':
        logger.info('Create the SFC, config file path: %s' % args.conf_path)
        srv_chain = resource.ServerChain(auth_args, fc_conf['name'],
                                         fc_conf['description'], net_conf,
                                         srv_queue, False, 'pt_in')
        srv_chain.create()
        port_chain = resource.PortChain(auth_args, fc_conf['name'],
                                        fc_conf['description'], srv_chain,
                                        flow_conf)
        port_chain.create()

    elif args.operation == 'delete':
        logger.info('Delete the SFC, config file: %s' % args.conf_path)
        srv_chain = resource.ServerChain(auth_args, fc_conf['name'],
                                         fc_conf['description'], net_conf,
                                         srv_queue, False)
        port_chain = resource.PortChain(auth_args, fc_conf['name'],
                                        fc_conf['description'], srv_chain,
                                        flow_conf)
        port_chain.delete()
        srv_chain.delete()
Beispiel #2
0
def dev_test():
    """Run tests during developing"""
    conf_hd = conf.ConfigHolder('yaml', './test/conf_test.yaml')
    logger = logging.getLogger(__name__)
    logger.info('Run tests for developing...')
    auth_args = conf_hd.get_cloud_auth()
    flow_conf = conf_hd.get_sfc_flow()
    net_conf = conf_hd.get_sfc_net()
    srv_queue = conf_hd.get_sfc_server()

    # --- Test sfc.resource ---
    srv_chain = resource.ServerChain(auth_args, 'test-server-chain', 'BlaBla',
                                     net_conf, srv_queue, True)

    # srv_chain.create(True)
    srv_chain.delete(True)

    port_chain = resource.PortChain(auth_args, 'test-port-chain', 'BlaBla',
                                    srv_chain, flow_conf)
Beispiel #3
0
    def create_sc(self,
                  sf_num,
                  sep_port=True,
                  fip_port='pt',
                  sf_wait_time=None,
                  timeout=3600):
        print('[TEST] Create ServerChain with %d SFs' % sf_num)
        srv_queue = list()
        for idx in range(1, sf_num + 1):
            self.server['name'] = 'chn%s' % idx
            srv_queue.append([self.server.copy()])
        srv_chain = resource.ServerChain(self.auth_args, self.fc_conf['name'],
                                         self.fc_conf['description'],
                                         self.net_conf, srv_queue, sep_port,
                                         fip_port)
        srv_chain.create(timeout=timeout)

        if sf_wait_time:
            wait_time = sf_wait_time * sf_num
            print('[TEST] Waiting %f seconds for SFs to be ready.' % wait_time)
            time.sleep(wait_time)

        return srv_chain
Beispiel #4
0
    def create_sfc(self, sfc_conf,
                   alloc_method, chain_method,
                   wait_sf_ready=True, wait_method='udp_packet'):
        """Create a SFC using given allocation and chaining method

        :param sfc_conf ():
        :param alloc_method (str): Method for instance allocation
        :param chain_method (str): Method for chaining instances
        :param wait_sf_ready (Bool): If True, the manager blocks until all SF
                                     programs are ready.
        :param wait_method (str): Method for waiting SF programs
        """

        if alloc_method not in ('nova_default', 'fill_one'):
            raise SFCManagerError('Unknown allocation method for SF servers.')

        if chain_method not in ('default', 'min_lat'):
            raise SFCManagerError('Unknown chaining method for SF servers')

        sfc_name = sfc_conf.function_chain.name
        sfc_desc = sfc_conf.function_chain.description
        time_info = list()
        logger.info(
            'Create SFC: %s, description: %s. Allocation method: %s, chaining method :%s'
            % (sfc_name, sfc_desc, alloc_method, chain_method))

        start_ts = time.time()
        self._alloc_srv_chn(
            alloc_method,
            sfc_conf.server_chain,
            sfc_conf.function_chain.availability_zone,
            sfc_conf.function_chain.destination_hypervisor,
            sfc_conf.function_chain.available_hypervisors
        )

        srv_chn = resource.ServerChain(
            sfc_conf.auth,
            sfc_name + '_srv_chn',
            sfc_desc,
            sfc_conf.network,
            sfc_conf.server_chain,
            self.ssh_access, 'pt'
        )

        logger.info('Create server chain: %s', srv_chn.name)
        # MARK: Create networking and instance resources separately

        srv_chn.create_network()

        if wait_sf_ready:
            logger.info('Wait all SF(s) to be ready with method: %s.',
                        wait_method)
            wait_sf_thread = threading.Thread(
                target=self._wait_sf_ready,
                args=(srv_chn, wait_method)
            )
            wait_sf_thread.start()
        else:
            logger.warn(
                (
                    'Do not wait for SF(s) to be ready. '
                    'Instances creation are not completed. '
                    'This is not recommeded!'
                )
            )

        srv_chn.create_instance(wait_complete=True)
        # Server chain launching time
        time_info.append(time.time() - start_ts)
        # Block main thread until all SFs are ready
        logger.info(
            'All server instances are launched, waiting for SF programs')
        if wait_sf_ready:
            start_ts = time.time()
            wait_sf_thread.join()
            # Waiting time for SF program
            time_info.append(time.time() - start_ts)
        else:
            time_info.append(0)

        # Log server chain allocation mapping
        alloc_map = self._get_srv_chn_alloc(
            sfc_conf.server_chain,
            self.all_hypers
        )
        logger.info(
            'Allocation mapping: %s', self._get_alloc_map_str(alloc_map)
        )

        if chain_method == 'min_lat':
            start_ts = time.time()
            if alloc_method != 'nova_default':
                raise SFCManagerError(
                    'Chaining method min_lat only support allocation method nova_default'
                )
            logger.info('Reorder server chain with simple min_lat method')
            logger.debug(
                'Before reorder: %s', ','.join(
                    (srv_grp[0]['name'] for srv_grp in sfc_conf.server_chain)
                )
            )
            reorder_srv_chn_conf = self._reorder_srv_chn(
                chain_method,
                sfc_conf.server_chain,
                sfc_conf.function_chain.available_hypervisors
            )

            logger.debug(
                'After reorder: %s', ','.join(
                    (srv_grp[0]['name'] for srv_grp in reorder_srv_chn_conf)
                )
            )

            srv_chn = resource.ServerChain(
                sfc_conf.auth,
                sfc_name + '_srv_chn',
                sfc_desc,
                sfc_conf.network,
                reorder_srv_chn_conf,
                self.ssh_access, 'pt'
            )
            # Time for reorder the chain
            time_info.append(time.time() - start_ts)
        else:
            time_info.append(0)

        port_chn = resource.PortChain(
            sfc_conf.auth,
            sfc_name + '_port_chn',
            sfc_desc,
            srv_chn,
            sfc_conf.flow_classifier
        )
        logger.info('Create port chain: %s', port_chn.name)
        start_ts = time.time()
        port_chn.create()
        # Time for creating port chain
        time_info.append(time.time() - start_ts)

        if self.log_ts:
            logger.info('Time info: %s',
                        ','.join(map(str, time_info)))

        if self.return_ts:
            return (
                resource.SFC(sfc_name, sfc_desc, srv_chn, port_chn),
                time_info
            )

        else:
            return resource.SFC(sfc_name, sfc_desc, srv_chn, port_chn)
Beispiel #5
0
    net_conf = conf_hd.get_sfc_net()
    EVA_SERVER['init_script'] = args.init_script

    srv_queue = []
    fc_conf = conf_hd.get_sfc_fc()

    opt = args.operation
    sf_num = args.sf_num
    if opt == 'c' or opt == 'create':
        print('[TEST] Create SFC with %s chain nodes' % sf_num)
        for idx in range(1, sf_num + 1):
            EVA_SERVER['name'] = 'chn%s' % idx
            srv_queue.append([EVA_SERVER.copy()])

        srv_chain = resource.ServerChain(auth_args, fc_conf['name'],
                                         fc_conf['description'], net_conf,
                                         srv_queue, True, 'pt')
        srv_chain.create(timeout=3600)
        """
        MARK: This is only a work around for tests. Just wait for all SF
        programs running properly.
        Checking status of the SF SHOULD be implmented in the resource or
        manager module.
        """
        wait_time = args.sf_wait_time * sf_num
        print('[TEST] Waiting %f seconds for SFs to be ready.' % wait_time)
        time.sleep((args.sf_wait_time * sf_num))

        port_chain = resource.PortChain(auth_args, fc_conf['name'],
                                        fc_conf['description'], srv_chain,
                                        flow_conf)