2 * Copyright (c) 2016 Intel Corporation and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.ovsdb.southbound.ovsdb.transact;
10 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
12 import java.util.HashMap;
13 import java.util.List;
15 import java.util.Map.Entry;
17 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
18 import org.opendaylight.ovsdb.lib.notation.UUID;
19 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
20 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
21 import org.opendaylight.ovsdb.schema.openvswitch.Qos;
22 import org.opendaylight.ovsdb.southbound.SouthboundConstants;
23 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
24 import org.opendaylight.ovsdb.utils.yang.YangUtils;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QosEntries;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.qos.entries.QosExternalIds;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.qos.entries.QosOtherConfig;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.qos.entries.QueueList;
32 import org.opendaylight.yangtools.yang.binding.DataObject;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 public class QosUpdateCommand extends AbstractTransactCommand {
38 private static final Logger LOG = LoggerFactory.getLogger(QosUpdateCommand.class);
41 public QosUpdateCommand(BridgeOperationalState state, AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes) {
42 super(state, changes);
46 public void execute(TransactionBuilder transaction) {
47 Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> created =
48 TransactUtils.extractCreated(getChanges(),OvsdbNodeAugmentation.class);
49 for (Entry<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> ovsdbNodeEntry:
51 updateQos(transaction, ovsdbNodeEntry.getKey(), ovsdbNodeEntry.getValue());
53 Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> updated =
54 TransactUtils.extractUpdated(getChanges(),OvsdbNodeAugmentation.class);
55 for (Entry<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> ovsdbNodeEntry:
57 updateQos(transaction, ovsdbNodeEntry.getKey(), ovsdbNodeEntry.getValue());
61 private void updateQos(
62 TransactionBuilder transaction,
63 InstanceIdentifier<OvsdbNodeAugmentation> iid, OvsdbNodeAugmentation ovsdbNode) {
65 List<QosEntries> qosEntries = ovsdbNode.getQosEntries();
67 if (!getOperationalState().getBridgeNode(iid).isPresent()) {
70 OvsdbNodeAugmentation operNode = getOperationalState().getBridgeNode(iid).get().getAugmentation(OvsdbNodeAugmentation.class);
71 List<QosEntries> operQosEntries = operNode.getQosEntries();
73 if (qosEntries != null) {
74 for (QosEntries qosEntry : qosEntries) {
75 Qos qos = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Qos.class);
77 if (qosEntry.getQosType() != null) {
78 qos.setType(SouthboundMapper.createQosType(qosEntry.getQosType()));
81 Uuid qosUuid = getQosEntryUuid(operQosEntries, qosEntry.getQosId());
83 if (qosUuid != null) {
84 uuid = new UUID(qosUuid.getValue());
87 List<QueueList> queueList = qosEntry.getQueueList();
88 Map<Long, UUID>newQueueList = new HashMap<>();
89 if (queueList != null && !queueList.isEmpty()) {
90 for (QueueList queue : queueList) {
91 newQueueList.put(queue.getQueueNumber(), new UUID(queue.getQueueUuid().getValue()));
94 qos.setQueues(newQueueList);
96 Map<String, String> externalIdsMap = new HashMap<>();
98 YangUtils.copyYangKeyValueListToMap(externalIdsMap, qosEntry.getQosExternalIds(),
99 QosExternalIds::getQosExternalIdKey, QosExternalIds::getQosExternalIdValue);
100 } catch (NullPointerException e) {
101 LOG.warn("Incomplete Qos external IDs", e);
103 externalIdsMap.put(SouthboundConstants.QOS_ID_EXTERNAL_ID_KEY, qosEntry.getQosId().getValue());
104 qos.setExternalIds(externalIdsMap);
107 qos.setOtherConfig(YangUtils.convertYangKeyValueListToMap(qosEntry.getQosOtherConfig(),
108 QosOtherConfig::getOtherConfigKey, QosOtherConfig::getOtherConfigValue));
109 } catch (NullPointerException e) {
110 LOG.warn("Incomplete Qos other_config", e);
113 transaction.add(op.insert(qos)).build();
115 Qos extraQos = TyperUtils.getTypedRowWrapper(
116 transaction.getDatabaseSchema(), Qos.class, null);
117 extraQos.getUuidColumn().setData(uuid);
118 transaction.add(op.update(qos)
119 .where(extraQos.getUuidColumn().getSchema().opEqual(uuid)).build());
126 private Uuid getQosEntryUuid(List<QosEntries> operQosEntries, Uri qosId) {
127 if (operQosEntries != null && !operQosEntries.isEmpty()) {
128 for (QosEntries qosEntry : operQosEntries) {
129 if (qosEntry.getQosId().equals(qosId)) {
130 return qosEntry.getQosUuid();