import static org.opendaylight.ovsdb.lib.operations.Operations.op;
+import java.util.Collection;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
-import org.opendaylight.ovsdb.lib.notation.Condition;
-import org.opendaylight.ovsdb.lib.notation.Mutator;
import org.opendaylight.ovsdb.lib.notation.UUID;
-import org.opendaylight.ovsdb.lib.operations.Mutate;
import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
-import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
-import org.opendaylight.ovsdb.schema.openvswitch.Port;
import org.opendaylight.ovsdb.schema.openvswitch.Qos;
+import org.opendaylight.ovsdb.southbound.InstanceIdentifierCodec;
import org.opendaylight.ovsdb.southbound.SouthboundConstants;
import org.opendaylight.ovsdb.southbound.SouthboundMapper;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
+import org.opendaylight.ovsdb.utils.yang.YangUtils;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbQueueRef;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QosEntries;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QosEntriesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.Queues;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QueuesKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.qos.entries.QosExternalIds;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.qos.entries.QosOtherConfig;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.qos.entries.QueueList;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.collect.ImmutableMap;
-
-public class QosUpdateCommand extends AbstractTransactCommand {
+public class QosUpdateCommand implements TransactCommand {
private static final Logger LOG = LoggerFactory.getLogger(QosUpdateCommand.class);
-
- public QosUpdateCommand(BridgeOperationalState state, AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes) {
- super(state, changes);
+ @Override
+ public void execute(TransactionBuilder transaction, BridgeOperationalState state,
+ AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> events,
+ InstanceIdentifierCodec instanceIdentifierCodec) {
+ execute(transaction, state, TransactUtils.extractCreatedOrUpdated(events, QosEntries.class),
+ instanceIdentifierCodec);
}
@Override
- public void execute(TransactionBuilder transaction) {
- Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> created =
- TransactUtils.extractCreated(getChanges(),OvsdbNodeAugmentation.class);
- for (Entry<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> ovsdbNodeEntry:
- created.entrySet()) {
- updateQos(transaction, ovsdbNodeEntry.getKey(), ovsdbNodeEntry.getValue());
- }
- Map<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> updated =
- TransactUtils.extractUpdated(getChanges(),OvsdbNodeAugmentation.class);
- for (Entry<InstanceIdentifier<OvsdbNodeAugmentation>, OvsdbNodeAugmentation> ovsdbNodeEntry:
- updated.entrySet()) {
- updateQos(transaction, ovsdbNodeEntry.getKey(), ovsdbNodeEntry.getValue());
- }
+ public void execute(TransactionBuilder transaction, BridgeOperationalState state,
+ Collection<DataTreeModification<Node>> modifications, InstanceIdentifierCodec instanceIdentifierCodec) {
+ execute(transaction, state, TransactUtils.extractCreatedOrUpdated(modifications, QosEntries.class),
+ instanceIdentifierCodec);
}
- private void updateQos(
- TransactionBuilder transaction,
- InstanceIdentifier<OvsdbNodeAugmentation> iid, OvsdbNodeAugmentation ovsdbNode) {
-
- List<QosEntries> qosEntries = ovsdbNode.getQosEntries();
-
- if (!getOperationalState().getBridgeNode(iid).isPresent()) {
- return;
- }
- OvsdbNodeAugmentation operNode = getOperationalState().getBridgeNode(iid).get().getAugmentation(OvsdbNodeAugmentation.class);
- List<QosEntries> operQosEntries = operNode.getQosEntries();
-
- if (qosEntries != null) {
- for (QosEntries qosEntry : qosEntries) {
- Qos qos = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Qos.class);
+ private void execute(TransactionBuilder transaction, BridgeOperationalState state,
+ Map<InstanceIdentifier<QosEntries>, QosEntries> createdOrUpdated,
+ InstanceIdentifierCodec instanceIdentifierCodec) {
+ for (Entry<InstanceIdentifier<QosEntries>, QosEntries> qosMapEntry: createdOrUpdated.entrySet()) {
+ InstanceIdentifier<OvsdbNodeAugmentation> iid =
+ qosMapEntry.getKey().firstIdentifierOf(OvsdbNodeAugmentation.class);
+ if (!state.getBridgeNode(iid).isPresent()) {
+ return;
+ }
+ OvsdbNodeAugmentation operNode =
+ state.getBridgeNode(iid).get().getAugmentation(OvsdbNodeAugmentation.class);
- if (qosEntry.getQosType() != null) {
- qos.setType(SouthboundMapper.createQosType(qosEntry.getQosType()));
- }
+ QosEntries qosEntry = qosMapEntry.getValue();
+ Qos qos = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Qos.class);
- Uuid qosUuid = getQosEntryUuid(operQosEntries, qosEntry.getQosId());
- UUID uuid = null;
- if (qosUuid != null) {
- uuid = new UUID(qosUuid.getValue());
- }
+ if (qosEntry.getQosType() != null) {
+ qos.setType(SouthboundMapper.createQosType(qosEntry.getQosType()));
+ }
- List<QueueList> queueList = qosEntry.getQueueList();
- Map<Long, UUID>newQueueList = new HashMap<>();
- if (queueList != null && !queueList.isEmpty()) {
- for (QueueList queue : queueList) {
- newQueueList.put(queue.getQueueNumber(), new UUID(queue.getQueueUuid().getValue()));
+ List<QueueList> queueList = qosEntry.getQueueList();
+ Map<Long, UUID> newQueueList = new HashMap<>();
+ if (queueList != null && !queueList.isEmpty()) {
+ for (QueueList queue : queueList) {
+ if (queue.getQueueRef() != null) {
+ newQueueList.put(queue.getQueueNumber(),
+ new UUID(getQueueUuid(queue.getQueueRef(), operNode)));
}
}
- qos.setQueues(newQueueList);
+ }
+ qos.setQueues(newQueueList);
+
+ Map<String, String> externalIdsMap = new HashMap<>();
+ try {
+ YangUtils.copyYangKeyValueListToMap(externalIdsMap, qosEntry.getQosExternalIds(),
+ QosExternalIds::getQosExternalIdKey, QosExternalIds::getQosExternalIdValue);
+ } catch (NullPointerException e) {
+ LOG.warn("Incomplete Qos external IDs", e);
+ }
+ externalIdsMap.put(SouthboundConstants.IID_EXTERNAL_ID_KEY,
+
+ instanceIdentifierCodec.serialize(
+ SouthboundMapper.createInstanceIdentifier(iid.firstKeyOf(Node.class).getNodeId())
+ .augmentation(OvsdbNodeAugmentation.class)
+ .child(QosEntries.class, new QosEntriesKey(qosEntry.getQosId()))));
+ qos.setExternalIds(externalIdsMap);
+
+ try {
+ qos.setOtherConfig(YangUtils.convertYangKeyValueListToMap(qosEntry.getQosOtherConfig(),
+ QosOtherConfig::getOtherConfigKey, QosOtherConfig::getOtherConfigValue));
+ } catch (NullPointerException e) {
+ LOG.warn("Incomplete Qos other_config", e);
+ }
- List<QosExternalIds> externalIds = qosEntry.getQosExternalIds();
- Map<String, String> externalIdsMap = new HashMap<>();
- if (externalIds != null) {
- for (QosExternalIds externalId : externalIds) {
- externalIdsMap.put(externalId.getQosExternalIdKey(), externalId.getQosExternalIdValue());
- }
- }
- externalIdsMap.put(SouthboundConstants.QOS_ID_EXTERNAL_ID_KEY, qosEntry.getQosId().getValue());
- try {
- qos.setExternalIds(ImmutableMap.copyOf(externalIdsMap));
- } catch (NullPointerException e) {
- LOG.warn("Incomplete Qos external IDs", e);
- }
+ Uuid operQosUuid = getQosEntryUuid(operNode.getQosEntries(), qosEntry.getQosId());
+ if (operQosUuid == null) {
+ UUID namedUuid = new UUID(SouthboundConstants.QOS_NAMED_UUID_PREFIX
+ + TransactUtils.bytesToHexString(qosEntry.getQosId().getValue().getBytes()));
+ transaction.add(op.insert(qos).withId(namedUuid.toString())).build();
+ LOG.info("Added QoS Uuid: {} for node : {} ", namedUuid, operNode.getConnectionInfo());
+ } else {
+ UUID uuid = new UUID(operQosUuid.getValue());
+ Qos extraQos = TyperUtils.getTypedRowWrapper(
+ transaction.getDatabaseSchema(), Qos.class, null);
+ extraQos.getUuidColumn().setData(uuid);
+ transaction.add(op.update(qos)
+ .where(extraQos.getUuidColumn().getSchema().opEqual(uuid)).build());
+ LOG.info("Updated QoS Uuid : {} for node : {} ", operQosUuid, operNode.getConnectionInfo());
+ }
+ transaction.build();
+ }
+ }
- List<QosOtherConfig> otherConfigs = qosEntry.getQosOtherConfig();
- if (otherConfigs != null) {
- Map<String, String> otherConfigsMap = new HashMap<>();
- for (QosOtherConfig otherConfig : otherConfigs) {
- otherConfigsMap.put(otherConfig.getOtherConfigKey(), otherConfig.getOtherConfigValue());
- }
- try {
- qos.setOtherConfig(ImmutableMap.copyOf(otherConfigsMap));
- } catch (NullPointerException e) {
- LOG.warn("Incomplete Qos other_config", e);
- }
- }
- if (uuid == null) {
- transaction.add(op.insert(qos)).build();
- } else {
- Qos extraQos = TyperUtils.getTypedRowWrapper(
- transaction.getDatabaseSchema(), Qos.class, null);
- extraQos.getUuidColumn().setData(uuid);
- transaction.add(op.update(qos)
- .where(extraQos.getUuidColumn().getSchema().opEqual(uuid)).build());
+ private String getQueueUuid(OvsdbQueueRef queueRef, OvsdbNodeAugmentation operNode) {
+ QueuesKey queueKey = queueRef.getValue().firstKeyOf(Queues.class);
+ if (operNode.getQueues() != null && !operNode.getQueues().isEmpty()) {
+ for (Queues queue : operNode.getQueues()) {
+ if (queue.getQueueId().equals(queueKey.getQueueId())) {
+ return queue.getQueueUuid().getValue();
}
- transaction.build();
}
}
+ return SouthboundConstants.QUEUE_NAMED_UUID_PREFIX
+ + TransactUtils.bytesToHexString(queueKey.getQueueId().getValue().getBytes());
}
private Uuid getQosEntryUuid(List<QosEntries> operQosEntries, Uri qosId) {