/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016, 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,
this.mdsalUtils = new MdsalUtils(db);
}
- private void transactChangesToDevice(Collection<DataTreeModification<Node>> changes) {
- HwvtepOperationalState hwvtepOperationalState = new HwvtepOperationalState(db, connectionInstance, changes);
+ private void transactChangesToDevice(final Collection<DataTreeModification<Node>> changes,
+ final Node globalOperNode,
+ final Node psNode) {
+ HwvtepOperationalState hwvtepOperationalState = new HwvtepOperationalState(db, connectionInstance, changes,
+ globalOperNode, psNode);
hwvtepOperationalState.setInReconciliation(true);
connectionInstance.transact(new TransactCommandAggregator(hwvtepOperationalState,changes));
}
}
}
}
- transactChangesToDevice(changes);
+ transactChangesToDevice(changes, globalOpNode, psNode);
return true;
}
}
}
+ public HwvtepOperationalState(final DataBroker db,
+ final HwvtepConnectionInstance connectionInstance,
+ final Collection<DataTreeModification<Node>> changes,
+ final Node globalOperNode,
+ final Node psNode) {
+ this(db, connectionInstance, changes);
+ operationalNodes.put(connectionInstance.getInstanceIdentifier(), globalOperNode);
+ HwvtepGlobalAugmentation globalAugmentation = globalOperNode.getAugmentation(HwvtepGlobalAugmentation.class);
+ if (globalAugmentation != null) {
+ if (!HwvtepSouthboundUtil.isEmpty(globalAugmentation.getSwitches())) {
+ operationalNodes.put((InstanceIdentifier<Node>)
+ globalAugmentation.getSwitches().get(0).getSwitchRef().getValue(), psNode);
+ }
+ }
+ }
+
public void readOperationalNodes() {
if (inReconciliation) {
return;
/*
- * Copyright (c) 2015 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.Objects;
import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepDeviceInfo;
import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundUtil;
import org.opendaylight.ovsdb.lib.notation.UUID;
import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
import org.opendaylight.ovsdb.schema.hardwarevtep.LogicalSwitch;
+import org.opendaylight.ovsdb.schema.hardwarevtep.McastMacsLocal;
+import org.opendaylight.ovsdb.schema.hardwarevtep.McastMacsRemote;
+import org.opendaylight.ovsdb.schema.hardwarevtep.UcastMacsLocal;
+import org.opendaylight.ovsdb.schema.hardwarevtep.UcastMacsRemote;
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.hwvtep.global.attributes.LogicalSwitches;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacs;
final LogicalSwitches lswitch,
final InstanceIdentifier lsKey,
final Object... extraData) {
- LOG.debug("Removing logcial switch named: {}", lswitch.getHwvtepNodeName().getValue());
- Optional<LogicalSwitches> operationalSwitchOptional =
- getOperationalState().getLogicalSwitches(instanceIdentifier, lswitch.getKey());
+ LOG.debug("Removing logical switch named: {}", lswitch.getHwvtepNodeName().getValue());
+ HwvtepDeviceInfo.DeviceData deviceData = getOperationalState().getDeviceInfo().getDeviceOperData(
+ LogicalSwitches.class, lsKey);
LogicalSwitch logicalSwitch = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), LogicalSwitch.class, null);
- if (operationalSwitchOptional.isPresent() &&
- operationalSwitchOptional.get().getLogicalSwitchUuid() != null) {
- UUID logicalSwitchUuid = new UUID(operationalSwitchOptional.get().getLogicalSwitchUuid().getValue());
+ if (deviceData != null && deviceData.getUuid() != null) {
+ UUID logicalSwitchUuid = deviceData.getUuid();
transaction.add(op.delete(logicalSwitch.getSchema())
.where(logicalSwitch.getUuidColumn().getSchema().opEqual(logicalSwitchUuid)).build());
- transaction.add(op.comment("Logical Switch: Deleting " + lswitch.getHwvtepNodeName().getValue()));
+
+ UcastMacsRemote ucastMacsRemote = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(),
+ UcastMacsRemote.class, null);
+ transaction.add(op.delete(ucastMacsRemote.getSchema())
+ .where(ucastMacsRemote.getLogicalSwitchColumn().getSchema().opEqual(logicalSwitchUuid)).build());
+
+ UcastMacsLocal ucastMacsLocal = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(),
+ UcastMacsLocal.class, null);
+ transaction.add(op.delete(ucastMacsLocal.getSchema())
+ .where(ucastMacsLocal.getLogicalSwitchColumn().getSchema().opEqual(logicalSwitchUuid)).build());
+
+ McastMacsRemote mcastMacsRemote = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(),
+ McastMacsRemote.class, null);
+ transaction.add(op.delete(mcastMacsRemote.getSchema())
+ .where(mcastMacsRemote.getLogicalSwitchColumn().getSchema().opEqual(logicalSwitchUuid)).build());
+
+ McastMacsLocal mcastMacsLocal = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(),
+ McastMacsLocal.class, null);
+ transaction.add(op.delete(mcastMacsLocal.getSchema())
+ .where(mcastMacsLocal.getLogicalSwitchColumn().getSchema().opEqual(logicalSwitchUuid)).build());
getOperationalState().getDeviceInfo().markKeyAsInTransit(RemoteMcastMacs.class, lsKey);
} else {
LOG.warn("Unable to delete logical switch {} because it was not found in the operational store",
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
-import org.opendaylight.ovsdb.lib.notation.Mutator;
-import org.opendaylight.ovsdb.lib.notation.UUID;
import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalPort;
-import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalSwitch;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalPortAugmentation;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
if (!removeds.isEmpty()) {
for (Entry<InstanceIdentifier<Node>, List<HwvtepPhysicalPortAugmentation>> removed:
removeds.entrySet()) {
- removePhysicalPort(transaction, removed.getKey(), removed.getValue());
+ updatePhysicalPort(transaction, removed.getKey(), removed.getValue());
}
}
}
- private void removePhysicalPort(TransactionBuilder transaction,
- InstanceIdentifier<Node> psNodeiid,
- List<HwvtepPhysicalPortAugmentation> listPort) {
+ private void updatePhysicalPort(final TransactionBuilder transaction,
+ final InstanceIdentifier<Node> psNodeiid,
+ final List<HwvtepPhysicalPortAugmentation> listPort) {
for (HwvtepPhysicalPortAugmentation port : listPort) {
- LOG.debug("Removing a physical port named: {}", port.getHwvtepNodeName().getValue());
+ LOG.debug("Updating a physical port named: {}", port.getHwvtepNodeName().getValue());
Optional<HwvtepPhysicalPortAugmentation> operationalPhysicalPortOptional =
getOperationalState().getPhysicalPortAugmentation(psNodeiid, port.getHwvtepNodeName());
- PhysicalPort physicalPort = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), PhysicalPort.class, null);
- //get managing global node of physicalSwitchBelong
- //InstanceIdentifier<?> globalNodeIid = physicalSwitchBelong.getManagedBy().getValue();
if (operationalPhysicalPortOptional.isPresent()) {
- UUID physicalPortUuid = new UUID(operationalPhysicalPortOptional.get().getPhysicalPortUuid().getValue());
- PhysicalSwitch physicalSwitch = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(),
- PhysicalSwitch.class, null);
- transaction.add(op.delete(physicalPort.getSchema())
- .where(physicalPort.getUuidColumn().getSchema().opEqual(physicalPortUuid)).build());
- transaction.add(op.comment("Physical Port: Deleting " + port.getHwvtepNodeName().getValue()));
- transaction.add(op.mutate(physicalSwitch.getSchema())
- .addMutation(physicalSwitch.getPortsColumn().getSchema(), Mutator.DELETE,
- Collections.singleton(physicalPortUuid)));
- transaction.add(op.comment("Physical Switch: Mutating " + port.getHwvtepNodeName().getValue() + " " + physicalPortUuid));
+ PhysicalPort physicalPort = TyperUtils.getTypedRowWrapper(
+ transaction.getDatabaseSchema(),PhysicalPort.class);
+ physicalPort.setVlanBindings(new HashMap<>());
+ HwvtepPhysicalPortAugmentation updatedPhysicalPort = operationalPhysicalPortOptional.get();
+ String existingPhysicalPortName = updatedPhysicalPort.getHwvtepNodeName().getValue();
+ PhysicalPort extraPhyscialPort =
+ TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), PhysicalPort.class);
+ extraPhyscialPort.setName("");
+ LOG.trace("execute: updating physical port: {}", physicalPort);
+ transaction.add(op.update(physicalPort)
+ .where(extraPhyscialPort.getNameColumn().getSchema().opEqual(existingPhysicalPortName))
+ .build());
} else {
- LOG.warn("Unable to delete logical switch {} because it was not found in the operational store, "
+ LOG.warn("Unable to update physical port {} because it was not found in the operational store, "
+ "and thus we cannot retrieve its UUID", port.getHwvtepNodeName().getValue());
}
}
import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepDeviceInfo;
import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundConstants;
import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundMapper;
import org.opendaylight.ovsdb.lib.notation.UUID;
}
public static UUID createPhysicalLocatorSet(HwvtepOperationalState hwvtepOperationalState, TransactionBuilder transaction, List<LocatorSet> locatorList) {
- Set<UUID> locators = new HashSet<>();
+ Set<UUID> locators = new HashSet<UUID>();
for (LocatorSet locator: locatorList) {
- UUID locatorUuid = null;
@SuppressWarnings("unchecked")
InstanceIdentifier<TerminationPoint> iid =(InstanceIdentifier<TerminationPoint>) locator.getLocatorRef().getValue();
- //try to find locator in operational DS
- Optional<HwvtepPhysicalLocatorAugmentation> operationalLocatorOptional =
- hwvtepOperationalState.getPhysicalLocatorAugmentation(iid);
- if (operationalLocatorOptional.isPresent()) {
- //if exist, get uuid
- HwvtepPhysicalLocatorAugmentation locatorAugmentation = operationalLocatorOptional.get();
- locatorUuid = new UUID(locatorAugmentation.getPhysicalLocatorUuid().getValue());
- } else {
- locatorUuid = hwvtepOperationalState.getUUIDFromCurrentTx(TerminationPoint.class, iid);
- if (locatorUuid == null) {
- locatorUuid = createPhysicalLocator(transaction, hwvtepOperationalState, iid);
- }
- }
+ UUID locatorUuid = createPhysicalLocator(transaction, hwvtepOperationalState, iid);
if (locatorUuid != null) {
locators.add(locatorUuid);
}
public static UUID createPhysicalLocator(TransactionBuilder transaction, HwvtepOperationalState operationalState,
InstanceIdentifier<TerminationPoint> iid) {
- Optional<TerminationPoint> configLocatorOptional = TransactUtils.readNodeFromConfig(
- operationalState.getReadWriteTransaction(), iid);
+ UUID locatorUuid = null;
+ HwvtepDeviceInfo.DeviceData deviceData = operationalState.getDeviceInfo().getDeviceOperData(
+ TerminationPoint.class, iid);
+ if (deviceData != null && deviceData.getUuid() != null) {
+ locatorUuid = deviceData.getUuid();
+ return locatorUuid;
+ }
+ locatorUuid = operationalState.getUUIDFromCurrentTx(TerminationPoint.class, iid);
+ if (locatorUuid != null) {
+ return locatorUuid;
+ }
HwvtepPhysicalLocatorAugmentationBuilder builder = new HwvtepPhysicalLocatorAugmentationBuilder();
HwvtepPhysicalLocatorAugmentation locatorAugmentation = null;
- if (configLocatorOptional.isPresent()) {
- locatorAugmentation = configLocatorOptional.get().getAugmentation(HwvtepPhysicalLocatorAugmentation.class);
- } else {
- builder.setEncapsulationType(EncapsulationTypeVxlanOverIpv4.class);
- String tepKey = iid.firstKeyOf(TerminationPoint.class).getTpId().getValue();
- String ip = tepKey.substring(tepKey.indexOf(":")+1);
- builder.setDstIp(new IpAddress(ip.toCharArray()));
- locatorAugmentation = builder.build();
- }
- UUID locatorUuid = TransactUtils.createPhysicalLocator(transaction, locatorAugmentation);
+ builder.setEncapsulationType(EncapsulationTypeVxlanOverIpv4.class);
+ String tepKey = iid.firstKeyOf(TerminationPoint.class).getTpId().getValue();
+ String ip = tepKey.substring(tepKey.indexOf(":")+1);
+ builder.setDstIp(new IpAddress(ip.toCharArray()));
+ locatorAugmentation = builder.build();
+ locatorUuid = TransactUtils.createPhysicalLocator(transaction, locatorAugmentation);
operationalState.updateCurrentTxData(TerminationPoint.class, iid, locatorUuid);
operationalState.getDeviceInfo().markKeyAsInTransit(TerminationPoint.class, iid);
return locatorUuid;
private void setLocator(TransactionBuilder transaction, UcastMacsRemote ucastMacsRemote, RemoteUcastMacs inputMac) {
//get UUID by locatorRef
if (inputMac.getLocatorRef() != null) {
- UUID locatorUuid = null;
@SuppressWarnings("unchecked")
- InstanceIdentifier<TerminationPoint> iid = (InstanceIdentifier<TerminationPoint>) inputMac.getLocatorRef().getValue();
- //try to find locator in operational DS
- HwvtepDeviceInfo.DeviceData deviceData = getOperationalState().getDeviceInfo().getDeviceOperData(TerminationPoint.class, iid);
- if (deviceData != null) {
- //if exist, get uuid
- locatorUuid = deviceData.getUuid();
- } else {
- locatorUuid = getOperationalState().getUUIDFromCurrentTx(TerminationPoint.class, iid);
- if (locatorUuid == null) {
- locatorUuid = TransactUtils.createPhysicalLocator(transaction, getOperationalState(),
- (InstanceIdentifier<TerminationPoint>) inputMac.getLocatorRef().getValue());
- updateCurrentTxData(TerminationPoint.class, iid, locatorUuid, null);
- }
- }
+ InstanceIdentifier<TerminationPoint> iid = (InstanceIdentifier<TerminationPoint>)
+ inputMac.getLocatorRef().getValue();
+ UUID locatorUuid = TransactUtils.createPhysicalLocator(transaction, getOperationalState(), iid);
if (locatorUuid != null) {
ucastMacsRemote.setLocator(locatorUuid);
}
addData(OPERATIONAL, LogicalSwitches.class, logicalSwitches);
resetOperations();
deleteData(CONFIGURATION, LogicalSwitches.class, logicalSwitches);
- verify(Operations.op, times(2)).delete(any());
+ verify(Operations.op, times(10)).delete(any());
}
@Test