}
public void addL2GatewayConnection(L2gatewayConnection input) {
- addL2GatewayConnection(input, null/*deviceName*/);
+ addL2GatewayConnection(input, null/*deviceName*/, null);
}
- public void addL2GatewayConnection(L2gatewayConnection input, String l2GwDeviceName) {
+ public void addL2GatewayConnection(final L2gatewayConnection input,
+ final String l2GwDeviceName) {
+ addL2GatewayConnection(input, l2GwDeviceName, null);
+ }
+
+ public void addL2GatewayConnection(final L2gatewayConnection input,
+ final String l2GwDeviceName ,
+ L2gateway l2Gateway) {
LOG.info("Adding L2gateway Connection with ID: {}", input.getKey().getUuid());
Uuid networkUuid = input.getNetworkId();
LOG.error("Neutron network with id {} is not VxlanNetwork", networkUuid.getValue());
} else {
Uuid l2GatewayId = input.getL2gatewayId();
- L2gateway l2Gateway = getNeutronL2gateway(broker, l2GatewayId);
+ if (l2Gateway == null) {
+ l2Gateway = getNeutronL2gateway(broker, l2GatewayId);
+ }
if (l2Gateway == null) {
LOG.error("L2Gateway with id {} is not present", l2GatewayId.getValue());
} else {
import java.util.Collections;
import java.util.List;
+import java.util.Set;
+
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
import org.opendaylight.infrautils.inject.AbstractLifecycle;
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.genius.itm.rpcs.rev160406.ItmRpcService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.l2gatewayconnections.L2gatewayConnection;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gateway;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
this.dataBroker, l2GatewayId);
}
+ @Override
+ public void addL2GatewayConnection(L2gatewayConnection input) {
+ this.elanUtils.getL2GatewayConnectionUtils().addL2GatewayConnection(input);
+ }
+
+ @Override
+ public void addL2GatewayConnection(L2gatewayConnection input,
+ String l2GwDeviceName,
+ L2gateway l2Gateway) {
+ this.elanUtils.getL2GatewayConnectionUtils().addL2GatewayConnection(input, l2GwDeviceName, l2Gateway);
+ }
+
+ @Override
+ public List<L2gatewayConnection> getAssociatedL2GwConnections(DataBroker broker, Set<Uuid> l2GatewayIds) {
+ return L2GatewayConnectionUtils.getAssociatedL2GwConnections(dataBroker, l2GatewayIds);
+ }
+
@Override
protected void start() throws Exception {
LOG.info("Starting L2gwServiceProvider");
*/
package org.opendaylight.netvirt.neutronvpn.l2gw;
+import com.google.common.collect.Sets;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
+
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase;
+import org.opendaylight.genius.datastoreutils.DataStoreJobCoordinator;
import org.opendaylight.genius.mdsalutil.MDSALUtil;
+import org.opendaylight.genius.utils.SystemPropertyReader;
import org.opendaylight.genius.utils.clustering.ClusteringUtils;
import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants;
import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
+import org.opendaylight.genius.utils.hwvtep.HwvtepUtils;
import org.opendaylight.netvirt.elanmanager.api.IL2gwService;
import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
import org.opendaylight.netvirt.neutronvpn.api.l2gw.utils.L2GatewayCacheUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.devices.Interfaces;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.L2gatewayConnections;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.l2gatewayconnections.L2gatewayConnection;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.L2gateways;
@Override
protected void update(InstanceIdentifier<L2gateway> identifier, L2gateway original, L2gateway update) {
LOG.trace("Updating L2gateway : key: {}, original value={}, update value={}", identifier, original, update);
+ List<L2gatewayConnection> connections = l2gwService.getAssociatedL2GwConnections(
+ dataBroker, Sets.newHashSet(update.getUuid()));
+ if (connections == null) {
+ LOG.warn("There are no connections associated with l2 gateway uuid {} name {}",
+ update.getUuid(), update.getName());
+ return;
+ }
+ if (original.getDevices() == null) {
+ connections.forEach(
+ (connection) -> l2gwService.addL2GatewayConnection(connection));
+ return;
+ }
+ DataStoreJobCoordinator.getInstance().enqueueJob("l2gw.update", () -> {
+ ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction();
+ DeviceInterfaces updatedDeviceInterfaces = new DeviceInterfaces(update);
+ List<ListenableFuture<Void>> fts = new ArrayList<ListenableFuture<Void>>();
+ original.getDevices()
+ .stream()
+ .filter((originalDevice) -> originalDevice.getInterfaces() != null)
+ .forEach((originalDevice) -> {
+ String deviceName = originalDevice.getDeviceName();
+ L2GatewayDevice l2GwDevice = L2GatewayCacheUtils.getL2DeviceFromCache(deviceName);
+ NodeId physicalSwitchNodeId = HwvtepSouthboundUtils.createManagedNodeId(
+ new NodeId(l2GwDevice.getHwvtepNodeId()), deviceName);
+ originalDevice.getInterfaces()
+ .stream()
+ .filter((intf) -> !updatedDeviceInterfaces.containsInterface(
+ deviceName, intf.getInterfaceName()))
+ .forEach((intf) -> {
+ connections.forEach((connection) -> {
+ Integer vlanId = connection.getSegmentId();
+ if (intf.getSegmentationIds() != null
+ && !intf.getSegmentationIds().isEmpty()) {
+ for (Integer vlan : intf.getSegmentationIds()) {
+ HwvtepUtils.deleteVlanBinding(transaction,
+ physicalSwitchNodeId, intf.getInterfaceName(), vlan);
+ }
+ } else {
+ LOG.debug("Deleting vlan binding {} {} {}",
+ physicalSwitchNodeId, intf.getInterfaceName(), vlanId);
+ HwvtepUtils.deleteVlanBinding(transaction, physicalSwitchNodeId,
+ intf.getInterfaceName(), vlanId);
+ }
+ });
+ });
+ });
+ fts.add(transaction.submit());
+ Futures.addCallback(fts.get(0), new FutureCallback<Void>() {
+ @Override
+ public void onSuccess(Void success) {
+ LOG.debug("Successfully deleted vlan bindings for l2gw update {}", update);
+ connections.forEach((l2GwConnection) ->
+ l2gwService.addL2GatewayConnection(l2GwConnection, null, update));
+ }
+
+ @Override
+ public void onFailure(Throwable throwable) {
+ LOG.error("Failed to delete vlan bindings as part of l2gw udpate {}", update);
+ }
+ });
+ return fts;
+ }, SystemPropertyReader.getDataStoreJobCoordinatorMaxRetries());
}
private synchronized void addL2Device(Devices l2Device, L2gateway input) {
protected L2GatewayListener getDataTreeChangeListener() {
return this;
}
+
+ static class DeviceInterfaces {
+ Map<String, Map<String, Interfaces>> deviceInterfacesMap = new HashMap<>();
+
+ DeviceInterfaces(L2gateway l2gateway) {
+ if (l2gateway.getDevices() != null) {
+ l2gateway.getDevices().forEach((device) -> {
+ deviceInterfacesMap.putIfAbsent(device.getDeviceName(), new HashMap<>());
+ if (device.getInterfaces() != null) {
+ device.getInterfaces().forEach((intf) ->
+ deviceInterfacesMap.get(device.getDeviceName()).put(intf.getInterfaceName(), intf));
+ }
+ });
+ }
+ }
+
+ boolean containsInterface(String deviceName, String interfaceName) {
+ if (deviceInterfacesMap.containsKey(deviceName)) {
+ return deviceInterfacesMap.get(deviceName).containsKey(interfaceName);
+ }
+ return false;
+ }
+ }
}