コード例 #1
0
    def setUp(self, enable_selective_topo_dist=False):
        extra_apps = ['portbinding']
        cfg.CONF.set_override(
            'apps_list',
            self.apps_list + extra_apps,
            group='df',
        )
        cfg.CONF.set_override('host', fake_chassis1.id)
        super(DFAppTestBase, self).setUp()
        self.useFixture(log_fixture.SetLogLevel([None], logging.DEBUG))
        mock_app = mock.patch(
            'ryu.base.app_manager.AppManager.get_instance').start()
        self.addCleanup(mock_app.stop)
        mock_nb = mock.patch('dragonflow.db.api_nb.NbApi.get_instance')
        mock_nb.start()
        self.addCleanup(mock_nb.stop)
        mod_flow = mock.patch(
            'dragonflow.controller.df_base_app.DFlowApp.mod_flow')
        mod_flow_mock = mod_flow.start()
        self.addCleanup(mod_flow.stop)
        add_flow_go_to_table_mock_patch = mock.patch(
            'dragonflow.controller.df_base_app.DFlowApp.add_flow_go_to_table')
        add_flow_go_to_table = add_flow_go_to_table_mock_patch
        add_flow_go_to_table_mock = add_flow_go_to_table.start()
        self.addCleanup(add_flow_go_to_table_mock_patch.stop)
        execute = mock.patch('neutron.agent.common.utils.execute')
        execute_mock = execute.start()
        self.addCleanup(execute.stop)

        # CLear old objects from cache
        db_store.get_instance().clear()

        self.nb_api = api_nb.NbApi.get_instance(False)
        self.controller = df_local_controller.DfLocalController(
            fake_chassis1.id, self.nb_api)
        self.vswitch_api = self.controller.vswitch_api = mock.MagicMock()
        kwargs = dict(
            nb_api=self.controller.nb_api,
            vswitch_api=self.controller.vswitch_api,
        )
        self.controller.open_flow_app = ryu_base_app.RyuDFAdapter(**kwargs)
        self.open_flow_app = self.controller.open_flow_app
        self.datapath = self.open_flow_app._datapath = mock.Mock()
        self.open_flow_app.load(self.controller.open_flow_app, **kwargs)
        self.topology = self.controller.topology = topology.Topology(
            self.controller, enable_selective_topo_dist)

        # Add basic network topology
        self.controller.update(fake_logic_switch1)
        self.controller.update(fake_lswitch_default_subnets[0])
        self.controller.update(fake_external_switch1)
        self.controller.update(fake_logic_router1)
        self.controller.db_store.update(fake_chassis1)
        self.controller.db_store.update(fake_chassis2)

        mod_flow_mock.reset_mock()
        add_flow_go_to_table_mock.reset_mock()
        execute_mock.reset_mock()
コード例 #2
0
    def __init__(self, *args, **kwargs):
        super(SimpleSwitch13, self).__init__(*args, **kwargs)
        # self.mac_to_port = {}
        db_store._instance = None
        self.fake_lswitch_default_subnets = [
            l2.Subnet(dhcp_ip="192.168.123.0",
                      name="private-subnet",
                      enable_dhcp=True,
                      topic="fake_tenant1",
                      gateway_ip="192.168.123.1",
                      cidr="192.168.123.0/24",
                      id="fake_subnet1")
        ]
        #print (self.fake_lswitch_default_subnets[0].dhcp_ip)

        #common_config.init(sys.argv[1:3])
        #common_config.setup_logging()
        self.nb_api = api_nb.NbApi.get_instance(False)

        self.controller = controller_concept.DfStandaloneController(
            'df_standalone', self.nb_api)
        self.db_store = db_store.get_instance()
        self.controller.on_datapath_set()

        self.nb_api.on_db_change.append(self.db_change_callback)

        if self.USE_CACHE:
            self.sync_with_database()
コード例 #3
0
    def __init__(self, chassis_name, nb_api):
        chassis_name = cfg.CONF.host

        self.db_store = db_store.get_instance()
        self.chassis_name = chassis_name
        self.nb_api = nb_api
        self.ip = cfg.CONF.df.local_ip

        app_mgr = app_manager.AppManager.get_instance()
        self.open_flow_app = app_mgr.instantiate(
            ryu_base_app.RyuDFAdapter,
            nb_api=self.nb_api,
            vswitch_api=None,
            neutron_server_notifier=None,
        )
        # The OfctlService is needed to support the 'get_flows' method
        self.open_flow_service = app_mgr.instantiate(of_service.OfctlService)
        self.ryu_switches = app_mgr.instantiate(switches.Switches)
        self.simples_switch = app_mgr.instantiate(concept_app.SimpleSwitch13)
        self.enable_selective_topo_dist = \
            cfg.CONF.df.enable_selective_topology_distribution
        self._sync = sync.Sync(
            nb_api=self.nb_api,
            update_cb=self.update,
            delete_cb=self.delete,
            selective=self.enable_selective_topo_dist,
        )
        self._sync_pulse = loopingcall.FixedIntervalLoopingCall(
            self._submit_sync_event)

        self.sync_rate_limiter = df_utils.RateLimiter(
            max_rate=1, time_unit=db_common.DB_SYNC_MINIMUM_INTERVAL)
コード例 #4
0
    def __init__(self, chassis_name, nb_api):
        self.db_store = db_store.get_instance()

        self.chassis_name = chassis_name
        self.nb_api = nb_api
        self.ip = cfg.CONF.df.local_ip
        # Virtual tunnel port support multiple tunnel types together
        self.tunnel_types = cfg.CONF.df.tunnel_types
        self.sync_finished = False
        self.vswitch_api = vswitch_impl.OvsApi(cfg.CONF.df.management_ip)
        self.neutron_notifier = None
        if cfg.CONF.df.enable_neutron_notifier:
            self.neutron_notifier = df_utils.load_driver(
                cfg.CONF.df.neutron_notifier,
                df_utils.DF_NEUTRON_NOTIFIER_DRIVER_NAMESPACE)

        app_mgr = app_manager.AppManager.get_instance()
        self.open_flow_app = app_mgr.instantiate(
            ryu_base_app.RyuDFAdapter,
            nb_api=self.nb_api,
            vswitch_api=self.vswitch_api,
            neutron_server_notifier=self.neutron_notifier,
        )
        self.topology = None
        self.db_consistency_manager = None
        self.enable_db_consistency = cfg.CONF.df.enable_df_db_consistency
        self.enable_selective_topo_dist = \
            cfg.CONF.df.enable_selective_topology_distribution
コード例 #5
0
ファイル: test_trunk_app.py プロジェクト: QiuMike/dragonflow
 def setUp(self):
     super(TestTrunkApp, self).setUp()
     self.app = self.open_flow_app.dispatcher.apps[0]
     self.mock_mod_flow = self.app.mod_flow
     self.db_store = db_store.get_instance()
     self.app.ofproto.OFPVID_PRESENT = 0x1000
     self.db_store.update(test_app_base.fake_local_port2)
コード例 #6
0
ファイル: sync.py プロジェクト: snapiri/dragonflow
 def __init__(self, nb_api, update_cb, delete_cb, selective=True):
     self._nb_api = nb_api
     self._update_cb = update_cb
     self._delete_cb = delete_cb
     self._db_store = db_store.get_instance()
     self._topics = set()
     self._selective = selective
     self._models = []
コード例 #7
0
ファイル: df_bgp_service.py プロジェクト: QiuMike/dragonflow
    def __init__(self, nb_api):
        super(BGPService, self).__init__()
        self.initialize_driver()
        self.db_store = db_store.get_instance()

        self.nb_api = nb_api

        self.bgp_pulse = loopingcall.FixedIntervalLoopingCall(
            self.sync_data_from_nb_db)
コード例 #8
0
 def wrapper(*args, **kwargs):
     db_store_inst = db_store.get_instance()
     for obj in objs:
         db_store_inst.update(obj)
     try:
         return func(*args, **kwargs)
     finally:
         for obj in objs:
             db_store_inst.delete(obj)
コード例 #9
0
    def __init__(self, chassis_name, nb_api):
        chassis_name = cfg.CONF.host

        self.db_store = db_store.get_instance()
        self.chassis_name = chassis_name
        self.nb_api = nb_api
        self.ip = cfg.CONF.df.local_ip
        self._sync = sync.Sync(
            nb_api=self.nb_api,
            update_cb=self.update,
            delete_cb=self.delete,
            selective=False,
        )
コード例 #10
0
ファイル: df_base_app.py プロジェクト: QiuMike/dragonflow
 def __init__(self,
              api,
              vswitch_api=None,
              nb_api=None,
              neutron_server_notifier=None):
     self.api = api
     self.db_store = db_store.get_instance()
     self.vswitch_api = vswitch_api
     self.nb_api = nb_api
     self.neutron_server_notifier = neutron_server_notifier
     # Though there is nothing to initialize in super class, call it
     # will make the multi-inheritence work.
     super(DFlowApp, self).__init__()
     self._register_events()
コード例 #11
0
    def __init__(self, chassis_name, nb_api):
        #用于缓存obj
        self.db_store = db_store.get_instance()
        self._queue = queue.PriorityQueue()
        # pending_id -> (model, pender_id)
        #       'pending_id' is the ID of the object for which we are waiting.
        #       'model' and 'pender_id' are the model and the ID of the object
        #       which is waiting for the object described by 'pending_id'
        self._pending_objects = collections.defaultdict(set)

        self.chassis_name = chassis_name
        #北向api
        self.nb_api = nb_api
        #指定database change event的处理函数
        self.nb_api.set_db_change_callback(self.db_change_callback)
        #指明本主机ip地址
        self.ip = cfg.CONF.df.local_ip
        # Virtual tunnel port support multiple tunnel types together
        self.tunnel_types = cfg.CONF.df.tunnel_types
        self.neutron_notifier = None
        if cfg.CONF.df.enable_neutron_notifier:
            self.neutron_notifier = df_utils.load_driver(
                cfg.CONF.df.neutron_notifier,
                df_utils.DF_NEUTRON_NOTIFIER_DRIVER_NAMESPACE)
        #加载switch_backend
        self.switch_backend = df_utils.load_driver(
            cfg.CONF.df.switch_backend,
            df_utils.DF_SWITCH_BACKEND_DRIVER_NAMESPACE, nb_api,
            cfg.CONF.df.management_ip)

        #switch_backend初始化
        self.switch_backend.initialize(self.db_change_callback,
                                       self.neutron_notifier)
        self.topology = None
        self.enable_selective_topo_dist = \
            cfg.CONF.df.enable_selective_topology_distribution
        self._sync = sync.Sync(
            nb_api=self.nb_api,
            #指明同步对应的update,delete回调
            update_cb=self.update,
            delete_cb=self.delete,
            selective=self.enable_selective_topo_dist,
        )
        #周期性产生controller_sync事件
        self._sync_pulse = loopingcall.FixedIntervalLoopingCall(
            self._submit_sync_event)

        self.sync_rate_limiter = df_utils.RateLimiter(
            max_rate=1, time_unit=db_common.DB_SYNC_MINIMUM_INTERVAL)
コード例 #12
0
    def __init__(self, nb_api):
        super(BGPService, self).__init__()
        self.initialize_driver()
        self.db_store = db_store.get_instance()

        self.nb_api = nb_api

        self.sync = sync.Sync(
            nb_api=self.nb_api,
            update_cb=self.update_model_object,
            delete_cb=self.delete_model_object,
            selective=False,
        )
        self.bgp_pulse = loopingcall.FixedIntervalLoopingCall(
            self.sync_data_from_nb_db)
コード例 #13
0
ファイル: api_nb.py プロジェクト: Benny93/dragonflow
 def __init__(self, db_driver, use_pubsub=False, is_neutron_server=False):
     super(NbApi, self).__init__()
     self.driver = db_driver
     self.controller = None
     self._queue = queue.PriorityQueue()
     self.use_pubsub = use_pubsub
     self.publisher = None
     self.subscriber = None
     self.is_neutron_server = is_neutron_server
     self.enable_selective_topo_dist = \
         cfg.CONF.df.enable_selective_topology_distribution
     self.pub_sub_use_multiproc = False
     if self.is_neutron_server:
         # multiproc pub/sub is only supported in neutron server
         self.pub_sub_use_multiproc = cfg.CONF.df.pub_sub_use_multiproc
     self.db_store = db_store.get_instance()
コード例 #14
0
ファイル: topology.py プロジェクト: snapiri/dragonflow
    def __init__(self, controller, enable_selective_topology_distribution):
        # Stores topics(tenants) subscribed by lports in the current local
        # controller. I,e, {tenant1:{lport1, lport2}, tenant2:{lport3}}
        self.topic_subscribed = {}
        self.enable_selective_topo_dist = \
            enable_selective_topology_distribution
        self.ovs_to_lport_mapping = {}

        self.controller = controller
        self.nb_api = controller.get_nb_api()
        self.chassis_name = controller.get_chassis_name()
        self.db_store = db_store.get_instance()

        ovs.OvsPort.register_created(self.ovs_port_updated)
        ovs.OvsPort.register_updated(self.ovs_port_updated)
        ovs.OvsPort.register_deleted(self.ovs_port_deleted)
コード例 #15
0
    def __init__(self, chassis_name, nb_api):
        self.db_store = db_store.get_instance()
        self._queue = queue.PriorityQueue()
        # pending_id -> (model, pender_id)
        #       'pending_id' is the ID of the object for which we are waiting.
        #       'model' and 'pender_id' are the model and the ID of the object
        #       which is waiting for the object described by 'pending_id'
        self._pending_objects = collections.defaultdict(set)

        self.chassis_name = chassis_name
        self.nb_api = nb_api
        self.nb_api.set_db_change_callback(self.db_change_callback)
        self.ip = cfg.CONF.df.local_ip
        # Virtual tunnel port support multiple tunnel types together
        self.tunnel_types = cfg.CONF.df.tunnel_types
        self.sync_finished = False
        self.vswitch_api = vswitch_impl.OvsApi(cfg.CONF.df.management_ip)
        self.neutron_notifier = None
        if cfg.CONF.df.enable_neutron_notifier:
            self.neutron_notifier = df_utils.load_driver(
                     cfg.CONF.df.neutron_notifier,
                     df_utils.DF_NEUTRON_NOTIFIER_DRIVER_NAMESPACE)

        app_mgr = app_manager.AppManager.get_instance()
        self.open_flow_app = app_mgr.instantiate(
            ryu_base_app.RyuDFAdapter,
            nb_api=self.nb_api,
            vswitch_api=self.vswitch_api,
            neutron_server_notifier=self.neutron_notifier,
            db_change_callback=self.db_change_callback
        )
        # The OfctlService is needed to support the 'get_flows' method
        self.open_flow_service = app_mgr.instantiate(of_service.OfctlService)
        self.topology = None
        self.enable_selective_topo_dist = \
            cfg.CONF.df.enable_selective_topology_distribution
        self._sync = sync.Sync(
            nb_api=self.nb_api,
            update_cb=self.update,
            delete_cb=self.delete,
            selective=self.enable_selective_topo_dist,
        )
        self._sync_pulse = loopingcall.FixedIntervalLoopingCall(
            self._submit_sync_event)

        self.sync_rate_limiter = df_utils.RateLimiter(
                max_rate=1, time_unit=db_common.DB_SYNC_MINIMUM_INTERVAL)
コード例 #16
0
ファイル: test_sync.py プロジェクト: rubiruchi/dragonflow
    def setUp(self):
        super(TestSync, self).setUp()
        self._db_store = db_store.get_instance()
        self._db_store.clear()

        self.nb_api = api_nb.NbApi(db_driver=mock.Mock())
        self.nb_api.publisher = mock.Mock()
        self.nb_api.enable_selective_topo_dist = True
        self._update = mock.Mock(side_effect=self._db_store.update)
        self._delete = mock.Mock(side_effect=self._db_store.delete)
        self.sync = sync.Sync(
            self.nb_api,
            self._update,
            self._delete,
        )
        self.sync.add_model(TopiclessModel)
        self.sync.add_model(TopicModel1)
        self.sync.add_model(TopicModel2)
コード例 #17
0
ファイル: topology.py プロジェクト: Benny93/dragonflow
    def __init__(self, controller, enable_selective_topology_distribution):
        self.ovs_port_type = (constants.OVS_VM_INTERFACE,
                              constants.OVS_BRIDGE_INTERFACE,
                              constants.OVS_TUNNEL_INTERFACE,
                              constants.OVS_PATCH_INTERFACE)

        # Stores topics(tenants) subscribed by lports in the current local
        # controller. I,e, {tenant1:{lport1, lport2}, tenant2:{lport3}}
        self.topic_subscribed = {}
        self.enable_selective_topo_dist = \
            enable_selective_topology_distribution
        self.ovs_ports = {}
        self.ovs_to_lport_mapping = {}

        self.controller = controller
        self.nb_api = controller.get_nb_api()
        self.chassis_name = controller.get_chassis_name()
        self.db_store = db_store.get_instance()
コード例 #18
0
    def __init__(self, chassis_name, nb_api):
        self.db_store = db_store.get_instance()
        self._queue = queue.PriorityQueue()

        self.chassis_name = chassis_name
        self.nb_api = nb_api
        self.nb_api.set_db_change_callback(self.db_change_callback)
        self.ip = cfg.CONF.df.local_ip
        # Virtual tunnel port support multiple tunnel types together
        self.tunnel_types = cfg.CONF.df.tunnel_types
        # self.sync_finished = False
        # self.vswitch_api = vswitch_impl.OvsApi(cfg.CONF.df.management_ip)
        # self.neutron_notifier = None
        # if cfg.CONF.df.enable_neutron_notifier:
        #     self.neutron_notifier = df_utils.load_driver(
        #              cfg.CONF.df.neutron_notifier,
        #              df_utils.DF_NEUTRON_NOTIFIER_DRIVER_NAMESPACE)

        # app_mgr = app_manager.AppManager.get_instance()
        # self.open_flow_app = app_mgr.instantiate(
        #     ryu_base_app.RyuDFAdapter,
        #     nb_api=self.nb_api,
        #     vswitch_api=self.vswitch_api,
        #     neutron_server_notifier=self.neutron_notifier,
        #     db_change_callback=self.db_change_callback
        # )
        # The OfctlService is needed to support the 'get_flows' method
        # self.open_flow_service = app_mgr.instantiate(of_service.OfctlService)
        # self.topology = None
        # self.enable_selective_topo_dist = \
        #     cfg.CONF.df.enable_selective_topology_distribution
        # self._sync = sync.Sync(
        #     nb_api=self.nb_api,
        #     update_cb=self.update,
        #     delete_cb=self.delete,
        #     selective=self.enable_selective_topo_dist,
        # )
        # self._sync_pulse = loopingcall.FixedIntervalLoopingCall(
        #     self._submit_sync_event)

        self.sync_rate_limiter = df_utils.RateLimiter(
            max_rate=1, time_unit=db_common.DB_SYNC_MINIMUM_INTERVAL)
コード例 #19
0
 def wrapper(*args, **kwargs):
     db_store_inst = db_store.get_instance()
     for obj in objs:
         db_store_inst.update(obj)
     return func(*args, **kwargs)
コード例 #20
0
ファイル: api_nb.py プロジェクト: Benny93/dragonflow
 def get_all_weak(self, model, topic=None):
     if not self.db_store:
         self.db_store = db_store.get_instance()
     return self.db_store.get_all(model)
コード例 #21
0
ファイル: model_proxy.py プロジェクト: snapiri/dragonflow
 def _fetch_obj(self):
     # _model attribute is provided by the deriving class
     obj = db_store.get_instance().get_one(self._model(id=self._id))
     # FIXME fetch from NbApi
     return obj