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.HashSet;
14 import java.util.List;
16 import java.util.Map.Entry;
19 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
20 import org.opendaylight.ovsdb.lib.notation.UUID;
21 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
22 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
23 import org.opendaylight.ovsdb.schema.openvswitch.Queue;
24 import org.opendaylight.ovsdb.southbound.SouthboundConstants;
25 import org.opendaylight.ovsdb.utils.yang.YangUtils;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.Queues;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.queues.QueuesExternalIds;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.queues.QueuesOtherConfig;
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 QueueUpdateCommand extends AbstractTransactCommand {
38 private static final Logger LOG = LoggerFactory.getLogger(QueueUpdateCommand.class);
41 public QueueUpdateCommand(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 updateQueue(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 updateQueue(transaction, ovsdbNodeEntry.getKey(), ovsdbNodeEntry.getValue());
61 private void updateQueue(
62 TransactionBuilder transaction,
63 InstanceIdentifier<OvsdbNodeAugmentation> iid, OvsdbNodeAugmentation ovsdbNode) {
65 List<Queues> queueList = ovsdbNode.getQueues();
67 if (!getOperationalState().getBridgeNode(iid).isPresent()) {
70 OvsdbNodeAugmentation operNode = getOperationalState().getBridgeNode(iid).get().getAugmentation(OvsdbNodeAugmentation.class);
71 List<Queues> operQueues = operNode.getQueues();
73 if (queueList != null) {
74 for (Queues queueEntry : queueList) {
75 Queue queue = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Queue.class);
77 if (queueEntry.getDscp() != null) {
79 Set<Long> dscpSet = new HashSet<>();
80 if (dscpSet.add(new Long(queueEntry.getDscp().toString()))) {
81 queue.setDscp(dscpSet);
83 } catch (NumberFormatException e) {
84 LOG.warn("Invalid DSCP {} setting for Queue {}", queueEntry.getDscp(), queueEntry, e);
88 Uuid queueUuid = getQueueEntryUuid(operQueues, queueEntry.getQueueId());
90 if (queueUuid != null) {
91 uuid = new UUID(queueUuid.getValue());
94 Map<String, String> externalIdsMap = new HashMap<>();
96 YangUtils.copyYangKeyValueListToMap(externalIdsMap, queueEntry.getQueuesExternalIds(),
97 QueuesExternalIds::getQueuesExternalIdKey, QueuesExternalIds::getQueuesExternalIdValue);
98 } catch (NullPointerException e) {
99 LOG.warn("Incomplete Queue external IDs", e);
101 externalIdsMap.put(SouthboundConstants.QUEUE_ID_EXTERNAL_ID_KEY, queueEntry.getQueueId().getValue());
102 queue.setExternalIds(externalIdsMap);
105 queue.setOtherConfig(YangUtils.convertYangKeyValueListToMap(queueEntry.getQueuesOtherConfig(),
106 QueuesOtherConfig::getQueueOtherConfigKey, QueuesOtherConfig::getQueueOtherConfigValue));
107 } catch (NullPointerException e) {
108 LOG.warn("Incomplete Queue other_config", e);
111 transaction.add(op.insert(queue)).build();
113 transaction.add(op.update(queue)).build();
114 Queue extraQueue = TyperUtils.getTypedRowWrapper(
115 transaction.getDatabaseSchema(), Queue.class, null);
116 extraQueue.getUuidColumn().setData(uuid);
117 transaction.add(op.update(queue.getSchema())
118 .where(extraQueue.getUuidColumn().getSchema().opEqual(uuid)).build());
125 private Uuid getQueueEntryUuid(List<Queues> operQueues, Uri queueId) {
126 if (operQueues != null && !operQueues.isEmpty()) {
127 for (Queues queueEntry : operQueues) {
128 if (queueEntry.getQueueId().equals(queueId)) {
129 return queueEntry.getQueueUuid();