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.Mutator;
21 import org.opendaylight.ovsdb.lib.notation.UUID;
22 import org.opendaylight.ovsdb.lib.operations.Mutate;
23 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
24 import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
25 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
26 import org.opendaylight.ovsdb.schema.openvswitch.Qos;
27 import org.opendaylight.ovsdb.schema.openvswitch.Queue;
28 import org.opendaylight.ovsdb.southbound.SouthboundConstants;
29 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QosEntries;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.Queues;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.queues.QueuesExternalIds;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.queues.QueuesOtherConfig;
37 import org.opendaylight.yangtools.yang.binding.DataObject;
38 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
42 import com.google.common.collect.ImmutableMap;
44 public class QueueUpdateCommand extends AbstractTransactCommand {
45 private static final Logger LOG = LoggerFactory.getLogger(QueueUpdateCommand.class);
48 public QueueUpdateCommand(BridgeOperationalState state, AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes) {
49 super(state, changes);
53 public void execute(TransactionBuilder transaction) {
54 Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> created =
55 TransactUtils.extractCreated(getChanges(),OvsdbNodeAugmentation.class);
56 for (Entry<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> ovsdbNodeEntry:
58 updateQueue(transaction, ovsdbNodeEntry.getKey(), ovsdbNodeEntry.getValue());
60 Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> updated =
61 TransactUtils.extractUpdated(getChanges(),OvsdbNodeAugmentation.class);
62 for (Entry<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> ovsdbNodeEntry:
64 updateQueue(transaction, ovsdbNodeEntry.getKey(), ovsdbNodeEntry.getValue());
68 private void updateQueue(
69 TransactionBuilder transaction,
70 InstanceIdentifier<OvsdbNodeAugmentation> iid, OvsdbNodeAugmentation ovsdbNode) {
72 List<Queues> queueList = ovsdbNode.getQueues();
74 if (!getOperationalState().getBridgeNode(iid).isPresent()) {
77 OvsdbNodeAugmentation operNode = getOperationalState().getBridgeNode(iid).get().getAugmentation(OvsdbNodeAugmentation.class);
78 List<Queues> operQueues = operNode.getQueues();
80 if (queueList != null) {
81 for (Queues queueEntry : queueList) {
82 Queue queue = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Queue.class);
84 if (queueEntry.getDscp() != null) {
86 Set<Long> dscpSet = new HashSet<>();
87 if (dscpSet.add(new Long(queueEntry.getDscp().toString()))) {
88 queue.setDscp(dscpSet);
90 } catch (NumberFormatException e) {
91 LOG.warn("Invalid DSCP {} setting for Queue {}", queueEntry.getDscp(), queueEntry, e);
95 Uuid queueUuid = getQueueEntryUuid(operQueues, queueEntry.getQueueId());
97 if (queueUuid != null) {
98 uuid = new UUID(queueUuid.getValue());
101 List<QueuesExternalIds> externalIds = queueEntry.getQueuesExternalIds();
102 Map<String, String> externalIdsMap = new HashMap<>();
103 if (externalIds != null) {
104 for (QueuesExternalIds externalId : externalIds) {
105 externalIdsMap.put(externalId.getQueuesExternalIdKey(), externalId.getQueuesExternalIdValue());
108 externalIdsMap.put(SouthboundConstants.QUEUE_ID_EXTERNAL_ID_KEY, queueEntry.getQueueId().getValue());
110 queue.setExternalIds(ImmutableMap.copyOf(externalIdsMap));
111 } catch (NullPointerException e) {
112 LOG.warn("Incomplete Queue external IDs", e);
115 List<QueuesOtherConfig> otherConfigs = queueEntry.getQueuesOtherConfig();
116 if (otherConfigs != null) {
117 Map<String, String> otherConfigsMap = new HashMap<>();
118 for (QueuesOtherConfig otherConfig : otherConfigs) {
119 otherConfigsMap.put(otherConfig.getQueueOtherConfigKey(), otherConfig.getQueueOtherConfigValue());
122 queue.setOtherConfig(ImmutableMap.copyOf(otherConfigsMap));
123 } catch (NullPointerException e) {
124 LOG.warn("Incomplete Queue other_config", e);
128 transaction.add(op.insert(queue)).build();
130 transaction.add(op.update(queue)).build();
131 Queue extraQueue = TyperUtils.getTypedRowWrapper(
132 transaction.getDatabaseSchema(), Queue.class, null);
133 extraQueue.getUuidColumn().setData(uuid);
134 transaction.add(op.update(queue.getSchema())
135 .where(extraQueue.getUuidColumn().getSchema().opEqual(uuid)).build());
142 private Uuid getQueueEntryUuid(List<Queues> operQueues, Uri queueId) {
143 if (operQueues != null && !operQueues.isEmpty()) {
144 for (Queues queueEntry : operQueues) {
145 if (queueEntry.getQueueId().equals(queueId)) {
146 return queueEntry.getQueueUuid();