public void markKeyAsInTransit(Class<? extends Identifiable> cls, InstanceIdentifier key) {
LOG.debug("Marking device data as intransit {}", key);
+ DeviceData deviceData = getDeviceOpData(cls, key);
+ UUID uuid = null;
+ Object data = null;
+ if (deviceData != null) {
+ uuid = deviceData.getUuid();
+ data = deviceData.getData();
+ }
HwvtepSouthboundUtil.updateData(opKeyVsData, cls, key,
- new DeviceData(key, null, null, DeviceDataStatus.IN_TRANSIT));
+ new DeviceData(key, uuid, data, DeviceDataStatus.IN_TRANSIT));
}
public void updateDeviceOpData(Class<? extends Identifiable> cls, InstanceIdentifier key, UUID uuid, Object data) {
Pair<Map<Class<? extends Identifiable>, List<Identifiable>>,
Map<Class<? extends Identifiable>, List<Identifiable>>>> modifiedData = new HashMap<>();
private boolean inReconciliation = false;
+ private final DataBroker db;
+ private final Collection<DataTreeModification<Node>> changes;
public HwvtepOperationalState(DataBroker db, HwvtepConnectionInstance connectionInstance,
Collection<DataTreeModification<Node>> changes) {
this.connectionInstance = connectionInstance;
this.deviceInfo = connectionInstance.getDeviceInfo();
+ this.db = db;
+ this.changes = changes;
+ this.transaction = db.newReadWriteTransaction();
+ }
+
+ public HwvtepOperationalState(HwvtepConnectionInstance connectionInstance) {
+ this.connectionInstance = connectionInstance;
+ this.deviceInfo = connectionInstance.getDeviceInfo();
+ this.db = connectionInstance.getDataBroker();
+ this.changes = null;
+ transaction = connectionInstance.getDataBroker().newReadWriteTransaction();
+ Optional<Node> readNode = HwvtepSouthboundUtil.readNode(transaction,
+ connectionInstance.getInstanceIdentifier());
+ if (readNode.isPresent()) {
+ operationalNodes.put(connectionInstance.getInstanceIdentifier(), readNode.get());
+ }
+ }
+
+ public void readOperationalNodes() {
+ if (inReconciliation) {
+ return;
+ }
+ if (changes == null) {
+ LOG.warn("Could not read operational nodes for {} as changes is",
+ connectionInstance.getNodeId().getValue());
+ return;
+ }
Map<InstanceIdentifier<Node>, Node> nodeCreateOrUpdate =
- TransactUtils.extractCreatedOrUpdatedOrRemoved(changes, Node.class);
+ TransactUtils.extractCreatedOrUpdatedOrRemoved(changes, Node.class);
if (nodeCreateOrUpdate != null) {
transaction = db.newReadWriteTransaction();
for (Entry<InstanceIdentifier<Node>, Node> entry: nodeCreateOrUpdate.entrySet()) {
}
}
- public HwvtepOperationalState(HwvtepConnectionInstance connectionInstance) {
- this.connectionInstance = connectionInstance;
- this.deviceInfo = connectionInstance.getDeviceInfo();
- transaction = connectionInstance.getDataBroker().newReadWriteTransaction();
- Optional<Node> readNode = HwvtepSouthboundUtil.readNode(transaction, connectionInstance.getInstanceIdentifier());
- if (readNode.isPresent()) {
- operationalNodes.put(connectionInstance.getInstanceIdentifier(), readNode.get());
- }
- }
-
public Optional<Node> getGlobalNode(InstanceIdentifier<?> iid) {
InstanceIdentifier<Node> nodeIid = iid.firstIdentifierOf(Node.class);
return Optional.fromNullable(operationalNodes.get(nodeIid));
import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacs;
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.Identifiable;
}
private void onDataTreeChanged(final Collection<DataTreeModification<Node>> changes) {
+ boolean readOperationalNodes = false;
for (DataTreeModification<Node> change : changes) {
final InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
final DataObjectModification<Node> mod = change.getRootNode();
extractDataChanged(key, mod, updatedData, deletedData);
modifiedData.put(key, Pair.of(updatedData, deletedData));
operationalState.setModifiedData(modifiedData);
+ if (!isMacOnlyUpdate(updatedData, deletedData)) {
+ readOperationalNodes = true;
+ }
+ }
+ if (readOperationalNodes) {
+ operationalState.readOperationalNodes();
}
}
+ private boolean isMacOnlyUpdate(final Map<Class<? extends Identifiable>, List<Identifiable>> updatedData,
+ final Map<Class<? extends Identifiable>, List<Identifiable>> deletedData) {
+ return (updatedData.containsKey(RemoteUcastMacs.class) && updatedData.size() == 1)
+ || (deletedData.containsKey(RemoteUcastMacs.class) && deletedData.size() == 1);
+ }
+
private void extractDataChanged(final InstanceIdentifier<Node> key,
final DataObjectModification<Node> mod,
final Map<Class<? extends Identifiable>, List<Identifiable>> updatedData,
/*
- * Copyright (c) 2015, 2016 China Telecom Beijing Research Institute and others. All rights reserved.
+ * Copyright (c) 2015, 2017 China Telecom Beijing Research Institute and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import java.util.Map.Entry;
import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepDeviceInfo;
import org.opendaylight.ovsdb.lib.notation.UUID;
import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
InstanceIdentifier<Node> instanceIdentifier, List<RemoteUcastMacs> macList) {
for (RemoteUcastMacs mac: macList) {
LOG.debug("Removing remoteUcastMacs, mac address: {}", mac.getMacEntryKey().getValue());
- Optional<RemoteUcastMacs> operationalMacOptional =
- getOperationalState().getRemoteUcastMacs(instanceIdentifier, mac.getKey());
+ InstanceIdentifier<RemoteUcastMacs> macIid = instanceIdentifier.augmentation(HwvtepGlobalAugmentation.class).
+ child(RemoteUcastMacs.class, mac.getKey());
+ HwvtepDeviceInfo.DeviceData deviceData =
+ getOperationalState().getDeviceInfo().getDeviceOpData(RemoteUcastMacs.class, macIid);
UcastMacsRemote ucastMacsRemote = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(),
UcastMacsRemote.class, null);
- if (operationalMacOptional.isPresent() && operationalMacOptional.get().getMacEntryUuid() != null) {
+ if (deviceData != null && deviceData.getUuid() != null) {
//when mac entry is deleted, its referenced locators are deleted automatically.
//locators in config DS is not deleted and need to be removed explicitly by user.
- UUID macEntryUUID = new UUID(operationalMacOptional.get().getMacEntryUuid().getValue());
+ UUID macEntryUUID = deviceData.getUuid();
ucastMacsRemote.getUuidColumn().setData(macEntryUUID);
transaction.add(op.delete(ucastMacsRemote.getSchema()).
where(ucastMacsRemote.getUuidColumn().getSchema().opEqual(macEntryUUID)).build());
LOG.warn("Unable to delete remoteUcastMacs {} because it was not found in the operational store",
mac.getMacEntryKey().getValue());
}
- InstanceIdentifier<RemoteUcastMacs> macIid = instanceIdentifier.augmentation(HwvtepGlobalAugmentation.class).
- child(RemoteUcastMacs.class, mac.getKey());
updateCurrentTxDeleteData(RemoteUcastMacs.class, macIid, mac);
}
}
/*
- * Copyright (c) 2015, 2016 China Telecom Beijing Research Institute and others. All rights reserved.
+ * Copyright (c) 2015, 2017 China Telecom Beijing Research Institute and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import static org.opendaylight.ovsdb.lib.operations.Operations.op;
import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepDeviceInfo;
import org.opendaylight.ovsdb.lib.notation.UUID;
import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
InstanceIdentifier macKey,
Object... extraData) {
LOG.debug("Creating remoteUcastMacs, mac address: {}", remoteUcastMac.getMacEntryKey().getValue());
- Optional<RemoteUcastMacs> operationalMacOptional =
- getOperationalState().getRemoteUcastMacs(instanceIdentifier, remoteUcastMac.getKey());
+ HwvtepDeviceInfo.DeviceData deviceData =
+ getOperationalState().getDeviceInfo().getDeviceOpData(RemoteUcastMacs.class, macKey);
+
UcastMacsRemote ucastMacsRemote = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), UcastMacsRemote.class);
setIpAddress(ucastMacsRemote, remoteUcastMac);
setLocator(transaction, ucastMacsRemote, remoteUcastMac);
setLogicalSwitch(ucastMacsRemote, remoteUcastMac);
- if (!operationalMacOptional.isPresent()) {
- setMac(ucastMacsRemote, remoteUcastMac, operationalMacOptional);
+ if (deviceData == null) {
+ setMac(ucastMacsRemote, remoteUcastMac);
LOG.trace("doDeviceTransaction: creating RemotUcastMac entry: {}", ucastMacsRemote);
transaction.add(op.insert(ucastMacsRemote));
transaction.add(op.comment("UcastMacRemote: Creating " + remoteUcastMac.getMacEntryKey().getValue()));
- } else if (operationalMacOptional.get().getMacEntryUuid() != null) {
- UUID macEntryUUID = new UUID(operationalMacOptional.get().getMacEntryUuid().getValue());
+ } else if (deviceData.getUuid() != null) {
+ UUID macEntryUUID = deviceData.getUuid();
UcastMacsRemote extraMac = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(),
UcastMacsRemote.class, null);
extraMac.getUuidColumn().setData(macEntryUUID);
private void setLogicalSwitch(UcastMacsRemote ucastMacsRemote, RemoteUcastMacs inputMac) {
if (inputMac.getLogicalSwitchRef() != null) {
@SuppressWarnings("unchecked")
- InstanceIdentifier<LogicalSwitches> lswitchIid = (InstanceIdentifier<LogicalSwitches>) inputMac.getLogicalSwitchRef().getValue();
- Optional<LogicalSwitches> operationalSwitchOptional =
- getOperationalState().getLogicalSwitches(lswitchIid);
- if (operationalSwitchOptional.isPresent()) {
- Uuid logicalSwitchUuid = operationalSwitchOptional.get().getLogicalSwitchUuid();
- UUID logicalSwitchUUID = new UUID(logicalSwitchUuid.getValue());
- ucastMacsRemote.setLogicalSwitch(logicalSwitchUUID);
+ InstanceIdentifier<LogicalSwitches> lswitchIid =
+ (InstanceIdentifier<LogicalSwitches>) inputMac.getLogicalSwitchRef().getValue();
+ HwvtepDeviceInfo.DeviceData deviceData = getOperationalState().getDeviceInfo().getDeviceOpData(
+ LogicalSwitches.class, lswitchIid);
+ if (deviceData != null && deviceData.getUuid() != null) {
+ ucastMacsRemote.setLogicalSwitch(deviceData.getUuid());
} else {
ucastMacsRemote.setLogicalSwitch(TransactUtils.getLogicalSwitchUUID(lswitchIid));
}
@SuppressWarnings("unchecked")
InstanceIdentifier<TerminationPoint> iid = (InstanceIdentifier<TerminationPoint>) inputMac.getLocatorRef().getValue();
//try to find locator in operational DS
- Optional<HwvtepPhysicalLocatorAugmentation> operationalLocatorOptional =
- getOperationalState().getPhysicalLocatorAugmentation(iid);
- if (operationalLocatorOptional.isPresent()) {
+ HwvtepDeviceInfo.DeviceData deviceData = getOperationalState().getDeviceInfo().getDeviceOpData(TerminationPoint.class, iid);
+ if (deviceData != null) {
//if exist, get uuid
- HwvtepPhysicalLocatorAugmentation locatorAugmentation = operationalLocatorOptional.get();
- locatorUuid = new UUID(locatorAugmentation.getPhysicalLocatorUuid().getValue());
+ locatorUuid = deviceData.getUuid();
} else {
locatorUuid = getOperationalState().getUUIDFromCurrentTx(TerminationPoint.class, iid);
if (locatorUuid == null) {
}
}
- private void setMac(UcastMacsRemote ucastMacsRemote, RemoteUcastMacs inputMac,
- Optional<RemoteUcastMacs> inputSwitchOptional) {
+ private void setMac(UcastMacsRemote ucastMacsRemote, RemoteUcastMacs inputMac) {
if (inputMac.getMacEntryKey() != null) {
ucastMacsRemote.setMac(inputMac.getMacEntryKey().getValue());
- } else if (inputSwitchOptional.isPresent() && inputSwitchOptional.get().getMacEntryKey() != null) {
- ucastMacsRemote.setMac(inputSwitchOptional.get().getMacEntryKey().getValue());
}
}
/*
- * Copyright (c) 2015, 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2015, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
new RemoteUcastMacsKey(getLogicalSwitchRef(rum.getLogicalSwitchColumn().getData()),
getMacAddress(rum.getMac())));
transaction.delete(LogicalDatastoreType.OPERATIONAL, rumId);
- getOvsdbConnectionInstance().getDeviceInfo().clearDeviceOpData(RemoteMcastMacs.class, rumId);
+ getOvsdbConnectionInstance().getDeviceInfo().clearDeviceOpData(RemoteUcastMacs.class, rumId);
} else {
LOG.debug("Failed to delete UcastMacRemote entry {}", rum.getUuid());
}