Beispiel #1
0
 def _process_logical_switch(self, uuid, uuid_dict, data_dict):
     """Processes Logical_Switch record from the OVSDB event."""
     new_row = uuid_dict.get('new', None)
     old_row = uuid_dict.get('old', None)
     if new_row:
         l_switch = ovsdb_schema.LogicalSwitch(uuid,
                                               new_row.get('name'),
                                               new_row.get('tunnel_key'),
                                               new_row.get('description'))
         if old_row:
             modified_logical_switches = data_dict.get(
                 'modified_logical_switches')
             modified_logical_switches.append(l_switch)
         else:
             new_logical_switches = data_dict.get(
                 'new_logical_switches')
             new_logical_switches.append(l_switch)
     elif old_row:
         l_switch = ovsdb_schema.LogicalSwitch(uuid,
                                               old_row.get('name'),
                                               old_row.get('tunnel_key'),
                                               old_row.get('description'))
         deleted_logical_switches = data_dict.get(
             'deleted_logical_switches')
         deleted_logical_switches.append(l_switch)
Beispiel #2
0
 def _form_logical_switch_schema(self, context, network, ls_dict):
     logical_switch_uuid = None
     logical_switch = db.get_logical_switch_by_name(
         context, ls_dict)
     if logical_switch:
         logical_switch_uuid = logical_switch.get('uuid')
     logical_switch = self._get_dict(ovsdb_schema.LogicalSwitch(
         uuid=logical_switch_uuid,
         name=network['id'],
         key=network['provider:segmentation_id'],
         description=network['name']))
     return logical_switch
Beispiel #3
0
    def notify_ovsdb_states(self, context, ovsdb_states):
        """RPC to notify the OVSDB servers connection state."""
        for ovsdb_identifier, state in ovsdb_states.items():
            if state == 'connected':
                pending_recs = db.get_all_pending_remote_macs_in_asc_order(
                    context, ovsdb_identifier)
                if pending_recs:
                    for pending_mac in pending_recs:
                        logical_switch_uuid = pending_mac[
                            'logical_switch_uuid']
                        mac = pending_mac['mac']
                        operation = pending_mac['operation']
                        try:
                            if operation == 'insert' or operation == 'update':
                                l_switch = ovsdb_schema.LogicalSwitch(
                                    logical_switch_uuid, None, None, None)
                                locator_uuid = pending_mac.get(
                                    'locator_uuid', None)
                                dst_ip = pending_mac.get('dst_ip', None)
                                locator = ovsdb_schema.PhysicalLocator(
                                    locator_uuid, dst_ip)
                                mac_remote = ovsdb_schema.UcastMacsRemote(
                                    pending_mac.get('uuid', None), mac,
                                    logical_switch_uuid, locator_uuid,
                                    pending_mac['vm_ip'])
                                if operation == 'insert':
                                    self.agent_rpc.add_vif_to_gateway(
                                        context, ovsdb_identifier,
                                        l_switch.__dict__, locator.__dict__,
                                        mac_remote.__dict__)
                                else:
                                    # update operation
                                    self.agent_rpc.update_vif_to_gateway(
                                        context, ovsdb_identifier,
                                        locator.__dict__, mac_remote.__dict__)
                            else:
                                self.agent_rpc.delete_vif_from_gateway(
                                    context, ovsdb_identifier,
                                    logical_switch_uuid, [mac])

                            # As the pending operation is over, delete the
                            # record from the pending_ucast_mac_remote table
                            db.delete_pending_ucast_mac_remote(
                                context, operation, ovsdb_identifier,
                                logical_switch_uuid, mac)
                        except Exception as ex:
                            LOG.exception(_LE("Exception occurred = %s"),
                                          str(ex))
Beispiel #4
0
    def insert_ucast_macs_remote(self, l_switch_dict, locator_dict,
                                 mac_dict, ovsdb_identifier,
                                 rcv_required=True):
        """Insert an entry in Ucast_Macs_Remote OVSDB table."""
        # To insert an entry in Ucast_Macs_Remote table, it requires
        # corresponding entry in Physical_Locator (Compute node VTEP IP)
        # and Logical_Switch (Neutron network) tables.
        logical_switch = ovsdb_schema.LogicalSwitch(l_switch_dict['uuid'],
                                                    l_switch_dict['name'],
                                                    l_switch_dict['key'],
                                                    l_switch_dict['description'
                                                                  ])
        locator = ovsdb_schema.PhysicalLocator(locator_dict['uuid'],
                                               locator_dict['dst_ip'])
        macObject = ovsdb_schema.UcastMacsRemote(mac_dict['uuid'],
                                                 mac_dict['mac'],
                                                 mac_dict['logical_switch_id'],
                                                 mac_dict['physical_locator_id'
                                                          ],
                                                 mac_dict['ip_address'])
        # Form the insert query now.
        commit_dict = {"op": "commit", "durable": True}
        op_id = str(random.getrandbits(128))
        params = [n_const.OVSDB_SCHEMA_NAME]

        if locator.uuid:
            locator_list = ['uuid', locator.uuid]
        else:
            locator.uuid = ''.join(['a', str(random.getrandbits(128))])
            locator_list = ["named-uuid", locator.uuid]
            params.append(self._get_physical_locator_dict(locator))

        if logical_switch.uuid:
            l_switches = ['uuid', logical_switch.uuid]
        else:
            logical_switch.uuid = ''.join(['a', str(random.getrandbits(128))])
            l_switches = ["named-uuid", logical_switch.uuid]
            params.append(self._get_logical_switch_dict(logical_switch))

        params.append(self._get_ucast_macs_remote_dict(
            macObject, locator_list, l_switches))
        params.append(commit_dict)
        query = {"method": "transact",
                 "params": params,
                 "id": op_id}
        LOG.debug("insert_ucast_macs_remote: query: %s", query)
        self._send_and_receive(query, op_id, ovsdb_identifier, rcv_required)
    def test_get_bindings_to_update1(self):
        """Test case to test _get_bindings_to_update."""
        fake_op_method = 'CREATE'
        with mock.patch.object(
                ovsdb_writer.OVSDBWriter,
                '_form_logical_switch') as form_ls, \
                mock.patch.object(
                    ovsdb_writer.OVSDBWriter,
                    '_form_physical_locators') as form_pl, \
                mock.patch.object(
                    ovsdb_writer.OVSDBWriter, '_form_ports') as form_pp, \
                mock.patch.object(
                    ovsdb_schema, 'LogicalSwitch') as mock_ls, \
                mock.patch.object(
                    ovsdb_schema, 'PhysicalLocator') as mock_pl, \
                mock.patch.object(
                    ovsdb_schema, 'UcastMacsRemote') as mock_ucmr, \
                mock.patch.object(ovsdb_schema, 'PhysicalPort') as mock_pp:
            ls = mock_ls.return_value = ovsdb_schema.LogicalSwitch(
                'ls_uuid', 'ls_name', 'ls_key', 'ls_desc')
            pl = mock_pl.return_value = ovsdb_schema.PhysicalLocator(
                'pl_uuid', 'pl_dst_ip')
            mock_ucmr.return_value = ovsdb_schema.UcastMacsRemote(
                'ucmr_uuid', 'ucmr_mac', 'ucmr_ls_id', 'ucmr_pl_id', 'ucmr_ip')
            pp = mock_pp.return_value = ovsdb_schema.PhysicalPort(
                'pp_uuid', 'pp_name', 'pp_ps_id', 'pp_vlan_bindings')
            form_ls.return_value = ['uuid', ls.uuid]
            self.l2gw_ovsdb._get_bindings_to_update(
                mock.MagicMock(), [{
                    'uuid': 'uuid',
                    'dst_ip': 'dst_ip'
                }], mock.MagicMock(), [{
                    'uuid': 'uuid',
                    'name': 'name',
                    'physical_switch_id': 'physical_switch_id',
                    'vlan_bindings': 'vlan_bindings',
                    'port_fault_status': 'port_fault_status'
                }], fake_op_method)

            form_ls.assert_called_with(ls, mock.ANY)
            form_pl.assert_called_with(['uuid', ls.uuid], [pl], mock.ANY,
                                       mock.ANY)
            form_pp.assert_called_with(['uuid', ls.uuid], [pp], mock.ANY,
                                       fake_op_method)
Beispiel #6
0
    def _get_bindings_to_update(self, l_switch_dict, locator_dicts, mac_dicts,
                                port_dicts):
        # For connection-create, there are two cases to be handled
        # Case 1: VMs exist in a network on compute nodes.
        #         Connection request will contain locators, ports, MACs and
        #         network.
        # Case 2: VMs do not exist in a network on compute nodes.
        #         Connection request will contain only ports and network
        #
        # For connection-delete, we do not need logical_switch and locators
        # information, we just need ports.
        locator_list = []
        port_list = []
        ls_list = []
        logical_switch = None
        # Convert logical switch dict to a class object
        if l_switch_dict:
            logical_switch = ovsdb_schema.LogicalSwitch(
                l_switch_dict['uuid'], l_switch_dict['name'],
                l_switch_dict['key'], l_switch_dict['description'])

        # Convert locator dicts into class objects
        for locator in locator_dicts:
            locator_list.append(
                ovsdb_schema.PhysicalLocator(locator['uuid'],
                                             locator['dst_ip']))

        # Convert MAC dicts into class objects. mac_dicts is a dictionary with
        # locator VTEP IP as the key and list of MACs as the value.
        locator_macs = {}
        for locator_ip, mac_list in mac_dicts.items():
            mac_object_list = []
            for mac_dict in mac_list:
                mac_object = ovsdb_schema.UcastMacsRemote(
                    mac_dict['uuid'], mac_dict['mac'],
                    mac_dict['logical_switch_id'],
                    mac_dict['physical_locator_id'], mac_dict['ip_address'])
                mac_object_list.append(mac_object)
            locator_macs[locator_ip] = mac_object_list

        # Convert port dicts into class objects
        for port in port_dicts:
            phys_port = ovsdb_schema.PhysicalPort(port['uuid'], port['name'],
                                                  port['physical_switch_id'],
                                                  port['vlan_bindings'],
                                                  port['port_fault_status'])
            port_list.append(phys_port)

        bindings = []
        bindings.append(n_const.OVSDB_SCHEMA_NAME)

        # Form the query.
        commit_dict = {"op": "commit", "durable": True}
        params = [n_const.OVSDB_SCHEMA_NAME]

        # Use logical switch
        if logical_switch:
            ls_list = self._form_logical_switch(logical_switch, params)

        # Use physical locators
        if locator_list:
            self._form_physical_locators(ls_list, locator_list, locator_macs,
                                         params)

        # Use ports
        self._form_ports(ls_list, port_list, params)
        params.append(commit_dict)
        return params