package org.opendaylight.netvirt.neutronvpn;
import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils.requireNonNullElse;
import com.google.common.base.Optional;
import com.google.common.base.Strings;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
+import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import javax.inject.Singleton;
import org.apache.commons.lang3.ObjectUtils;
import org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice;
import org.opendaylight.netvirt.neutronvpn.api.utils.NeutronConstants;
import org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev170119.L2vlan;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
@Override
protected void add(InstanceIdentifier<Port> identifier, Port input) {
+ LOG.trace("Received port add event: port={}", input);
String portName = input.getUuid().getValue();
LOG.trace("Adding Port : key: {}, value={}", identifier, input);
Network network = neutronvpnUtils.getNeutronNetwork(input.getNetworkId());
return;
}
if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(input.getDeviceOwner())) {
- handleRouterGatewayUpdated(input);
+ handleRouterGatewayUpdated(input, false);
portStatus = NeutronUtils.PORT_STATUS_ACTIVE;
} else if (NeutronConstants.DEVICE_OWNER_FLOATING_IP.equals(input.getDeviceOwner())) {
handleFloatingIpPortUpdated(null, input);
return;
} else if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(input.getDeviceOwner())
|| NeutronConstants.DEVICE_OWNER_FLOATING_IP.equals(input.getDeviceOwner())) {
+ handleRouterGatewayUpdated(input, true);
elanService.removeKnownL3DmacAddress(input.getMacAddress().getValue(), input.getNetworkId().getValue());
}
}
@Override
protected void update(InstanceIdentifier<Port> identifier, Port original, Port update) {
+ LOG.trace("Received port update event: original={}, update={}", original, update);
// Switchdev ports need to be bounded to a host before creation
// in order to validate the supported vnic types from the hostconfig
if (isPortTypeSwitchdev(original)
return;
}
if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(update.getDeviceOwner())) {
- handleRouterGatewayUpdated(update);
+ handleRouterGatewayUpdated(update, false);
} else if (NeutronConstants.DEVICE_OWNER_FLOATING_IP.equals(update.getDeviceOwner())) {
handleFloatingIpPortUpdated(original, update);
}
}
}
- private void handleFloatingIpPortUpdated(Port original, Port update) {
- if ((original == null || original.getDeviceId().equals(NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING))
- && !update.getDeviceId().equals(NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING)) {
+ private void handleFloatingIpPortUpdated(@Nullable Port original, Port update) {
+ if ((original == null || NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING.equals(original.getDeviceId()))
+ && !NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING.equals(update.getDeviceId())) {
// populate floating-ip uuid and floating-ip port attributes (uuid, mac and subnet id for the ONLY
// fixed IP) to be used by NAT, depopulated in NATService once mac is retrieved in the removal path
addToFloatingIpPortInfo(new Uuid(update.getDeviceId()), update.getUuid(), update.getFixedIps().get(0)
listVpnIds.add(vpnId);
Uuid internetVpnId = neutronvpnUtils.getInternetvpnUuidBoundToRouterId(routerId);
List<Subnetmap> subnetMapList = new ArrayList<>();
- List<FixedIps> portIps = routerPort.getFixedIps();
boolean portIsIpv6 = false;
- for (FixedIps portIP : portIps) {
+ for (FixedIps portIP : requireNonNullElse(routerPort.getFixedIps(),
+ Collections.<FixedIps>emptyList())) {
// NOTE: Please donot change the order of calls to updateSubnetNodeWithFixedIP
// and addSubnetToVpn here
if (internetVpnId != null
}
if (portIsIpv6) {
listVpnIds.add(internetVpnId);
- if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChangeToAdd(
- IpVersionChoice.IPV6, internetVpnId)) {
- neutronvpnUtils.updateVpnInstanceWithIpFamily(internetVpnId.getValue(),
- IpVersionChoice.IPV6, true);
- neutronvpnUtils.updateVpnInstanceWithFallback(internetVpnId.getValue(), true);
+ if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChange(
+ IpVersionChoice.IPV6, routerId, true)) {
+ neutronvpnUtils.updateVpnInstanceWithIpFamily(internetVpnId.getValue(), IpVersionChoice.IPV6,
+ true);
+ neutronvpnUtils.updateVpnInstanceWithFallback(routerId, internetVpnId, true);
}
}
if (! subnetMapList.isEmpty()) {
nvpnManager.createVpnInterface(listVpnIds, routerPort, null);
}
- for (FixedIps portIP : routerPort.getFixedIps()) {
+ IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
+ for (FixedIps portIP : requireNonNullElse(routerPort.getFixedIps(),
+ Collections.<FixedIps>emptyList())) {
String ipValue = portIP.getIpAddress().stringValue();
- IpVersionChoice version = NeutronvpnUtils.getIpVersionFromString(ipValue);
- if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChangeToAdd(version, vpnId)) {
- neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(),
- version, true);
- }
- if (version.isIpVersionChosen(IpVersionChoice.IPV4)) {
+ ipVersion = NeutronvpnUtils.getIpVersionFromString(ipValue);
+ if (ipVersion.isIpVersionChosen(IpVersionChoice.IPV4)) {
nvpnManager.addSubnetToVpn(vpnId, portIP.getSubnetId(),
null /* internet-vpn-id */);
} else {
ipValue, routerPort.getMacAddress(),
routerPort.getUuid().getValue(), vpnId.getValue());
}
+ if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChange(ipVersion, routerId, true)) {
+ LOG.debug("vpnInstanceOpDataEntry is getting update with ip address family {} for VPN {}",
+ ipVersion, vpnId.getValue());
+ neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, true);
+ }
nvpnManager.addToNeutronRouterInterfacesMap(routerId, routerPort.getUuid().getValue());
jobCoordinator.enqueueJob(routerId.toString(), () -> {
nvpnNatManager.handleSubnetsForExternalRouter(routerId);
Uuid routerId = new Uuid(routerPort.getDeviceId());
Uuid infNetworkId = routerPort.getNetworkId();
elanService.removeKnownL3DmacAddress(routerPort.getMacAddress().getValue(), infNetworkId.getValue());
- Uuid vpnId = ObjectUtils.defaultIfNull(neutronvpnUtils.getVpnForRouter(routerId, true), routerId);
- List<FixedIps> portIps = routerPort.getFixedIps();
+ Uuid vpnId = ObjectUtils.defaultIfNull(neutronvpnUtils.getVpnForRouter(routerId, true),
+ routerId);
+ List<FixedIps> portIps = requireNonNullElse(routerPort.getFixedIps(), Collections.emptyList());
boolean vpnInstanceInternetIpVersionRemoved = false;
Uuid vpnInstanceInternetUuid = null;
for (FixedIps portIP : portIps) {
* cleanup of router interface flows*/
nvpnManager.deleteVpnInterface(routerPort.getUuid().getValue(),
null /* vpn-id */, null /* wrtConfigTxn*/);
+ final Uuid internetVpnId = vpnInstanceInternetUuid;
// update RouterInterfaces map
ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
confTx -> {
- boolean vpnInstanceIpVersionRemoved = false;
- IpVersionChoice vpnInstanceIpVersionToRemove = IpVersionChoice.UNDEFINED;
+ IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
for (FixedIps portIP : portIps) {
Subnetmap sn = neutronvpnUtils.getSubnetmap(portIP.getSubnetId());
// router Port have either IPv4 or IPv6, never both
- if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sn, vpnId)) {
- vpnInstanceIpVersionRemoved = true;
- vpnInstanceIpVersionToRemove = NeutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
- }
+ ipVersion = neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
String ipValue = portIP.getIpAddress().stringValue();
neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), ipValue, confTx);
// NOTE: Please donot change the order of calls to removeSubnetFromVpn and
// and updateSubnetNodeWithFixedIP
- nvpnManager.removeSubnetFromVpn(vpnId, portIP.getSubnetId(),
- sn != null ? sn.getInternetVpnId() : null);
+ nvpnManager.removeSubnetFromVpn(vpnId, portIP.getSubnetId(), internetVpnId);
nvpnManager.updateSubnetNodeWithFixedIp(portIP.getSubnetId(), null, null,
null, null, null);
}
nvpnNatManager.handleSubnetsForExternalRouter(routerId);
return Collections.emptyList();
});
- if (vpnInstanceIpVersionRemoved) {
- neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), vpnInstanceIpVersionToRemove,
- false);
+ if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChange(ipVersion, routerId, false)) {
+ LOG.debug("vpnInstanceOpDataEntry is getting update with ip address family {} for VPN {}",
+ ipVersion, vpnId.getValue());
+ neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, false);
}
}), LOG, "Error handling interface removal");
if (vpnInstanceInternetIpVersionRemoved) {
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnInstanceInternetUuid.getValue(),
IpVersionChoice.IPV6, false);
- neutronvpnUtils.updateVpnInstanceWithFallback(vpnInstanceInternetUuid.getValue(), false);
+ neutronvpnUtils.updateVpnInstanceWithFallback(routerId, vpnInstanceInternetUuid, false);
}
}
}
- private void handleRouterGatewayUpdated(Port routerGwPort) {
+ private void handleRouterGatewayUpdated(Port routerGwPort, boolean isRtrGwRemoved) {
Uuid routerId = new Uuid(routerGwPort.getDeviceId());
Uuid networkId = routerGwPort.getNetworkId();
Network network = neutronvpnUtils.getNeutronNetwork(networkId);
if (isExternal) {
Uuid vpnInternetId = neutronvpnUtils.getVpnForNetwork(networkId);
if (vpnInternetId != null) {
+ if (!isRtrGwRemoved) {
+ nvpnManager.updateVpnMaps(vpnInternetId, null, routerId, null, null);
+ }
List<Subnetmap> snList = neutronvpnUtils.getNeutronRouterSubnetMaps(routerId);
for (Subnetmap sn : snList) {
if (sn.getNetworkId() == networkId) {
if (NeutronvpnUtils.getIpVersionFromString(sn.getSubnetIp()) != IpVersionChoice.IPV6) {
continue;
}
- nvpnManager.addSubnetToVpn(null, sn.getId(), vpnInternetId);
+ if (isRtrGwRemoved) {
+ nvpnManager.removeV6PrivateSubnetToExtNetwork(routerId, vpnInternetId, sn);
+ } else {
+ nvpnManager.addV6PrivateSubnetToExtNetwork(routerId, vpnInternetId, sn);
+ }
+ }
+ //Update Internet BGP-VPN
+ if (isRtrGwRemoved) {
+ nvpnManager.updateVpnMaps(vpnInternetId, null, null, null, null);
}
}
}
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersId, builder.build());
}
+ @Nullable
private String getPortHostId(final Port port) {
if (port != null) {
PortBindingExtension portBinding = port.augmentation(PortBindingExtension.class);
return null;
}
+ @Nullable
private Hostconfig getHostConfig(final Port port) {
String hostId = getPortHostId(port);
if (hostId == null) {
LOG.error("failed to read host config from host {}", hostId, e);
return null;
}
- return hostConfig.isPresent() ? hostConfig.get() : null;
+ return hostConfig.orNull();
}
private boolean isPortBound(final Port port) {
return false;
}
+ @Nullable
private Map<String, JsonElement> unmarshal(final String profile) {
if (null == profile) {
return null;
}
Gson gson = new Gson();
JsonObject jsonObject = gson.fromJson(profile, JsonObject.class);
- Map<String, JsonElement> map = new HashMap();
+ Map<String, JsonElement> map = new HashMap<>();
for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
map.put(entry.getKey(), entry.getValue());
}
private void handleNeutronPortCreated(final Port port) {
final String portName = port.getUuid().getValue();
final Uuid portId = port.getUuid();
- final List<FixedIps> portIpAddrsList = port.getFixedIps();
+ final List<FixedIps> portIpAddrsList = requireNonNullElse(port.getFixedIps(), Collections.emptyList());
if (NeutronConstants.IS_ODL_DHCP_PORT.test(port)) {
return;
}
private void handleNeutronPortDeleted(final Port port) {
final String portName = port.getUuid().getValue();
final Uuid portId = port.getUuid();
- final List<FixedIps> portIpsList = port.getFixedIps();
+ final List<FixedIps> portIpsList = requireNonNullElse(port.getFixedIps(), Collections.emptyList());
jobCoordinator.enqueueJob("PORT- " + portName,
() -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, confTx -> {
if (!(NeutronUtils.isPortVnicTypeNormal(port) || isPortTypeSwitchdev(port))) {
+ "during subnet deletion event.", portupdate.getUuid().getValue());
return;
}
+
+ if (NeutronConstants.IS_ODL_DHCP_PORT.test(portupdate)) {
+ return;
+ }
+
jobCoordinator.enqueueJob("PORT- " + portupdate.getUuid().getValue(),
() -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, confTx -> {
final List<Uuid> originalSnMapsIds = portoriginalIps.stream().map(FixedIps::getSubnetId)
})));
}
+ @Nullable
private InterfaceAclBuilder handlePortSecurityUpdated(Port portOriginal,
Port portUpdated, boolean origSecurityEnabled, boolean updatedSecurityEnabled,
InterfaceBuilder interfaceBuilder) {