use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.Adjacencies in project netvirt by opendaylight.
the class VpnInterfaceManager method delAdjFromVpnInterface.
protected void delAdjFromVpnInterface(InstanceIdentifier<VpnInterfaceOpDataEntry> identifier, Adjacency adj, Uint64 dpnId, TypedWriteTransaction<Operational> writeOperTxn, TypedWriteTransaction<Configuration> writeConfigTxn) {
String interfaceName = identifier.firstKeyOf(VpnInterfaceOpDataEntry.class).getName();
String vpnName = identifier.firstKeyOf(VpnInterfaceOpDataEntry.class).getVpnInstanceName();
try {
Optional<VpnInterfaceOpDataEntry> optVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier);
if (optVpnInterface.isPresent()) {
VpnInterfaceOpDataEntry currVpnIntf = optVpnInterface.get();
InstanceIdentifier<AdjacenciesOp> path = identifier.augmentation(AdjacenciesOp.class);
Optional<AdjacenciesOp> optAdjacencies = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, path);
if (optAdjacencies.isPresent()) {
Map<AdjacencyKey, Adjacency> keyAdjacencyMap = optAdjacencies.get().getAdjacency();
if (keyAdjacencyMap != null && !keyAdjacencyMap.isEmpty()) {
LOG.trace("delAdjFromVpnInterface: Adjacencies are {}", keyAdjacencyMap);
for (Adjacency adjacency : keyAdjacencyMap.values()) {
if (Objects.equals(adjacency.getIpAddress(), adj.getIpAddress())) {
String rd = adjacency.getVrfId();
if (adj.getNextHopIpList() != null) {
for (String nh : adj.getNextHopIpList()) {
deleteExtraRouteFromCurrentAndImportingVpns(currVpnIntf.getVpnInstanceName(), adj.getIpAddress(), nh, rd, currVpnIntf.getName(), writeConfigTxn, writeOperTxn);
}
} else if (adj.isPhysNetworkFunc()) {
LOG.info("delAdjFromVpnInterface: deleting PNF adjacency prefix {} subnet {}", adj.getIpAddress(), adj.getSubnetId());
fibManager.removeFibEntry(adj.getSubnetId().getValue(), adj.getIpAddress(), null, writeConfigTxn);
}
break;
}
}
}
LOG.info("delAdjFromVpnInterface: Removed adj {} on dpn {} rd {}", adj.getIpAddress(), dpnId, adj.getVrfId());
} else {
LOG.error("delAdjFromVpnInterface: Cannnot DEL adjacency, since operational interface is " + "unavailable dpnId {} adjIP {} rd {}", dpnId, adj.getIpAddress(), adj.getVrfId());
}
}
} catch (InterruptedException | ExecutionException e) {
LOG.error("delAdjFromVpnInterface: Failed to read data store for ip {} interface {} dpn {} vpn {}", adj.getIpAddress(), interfaceName, dpnId, vpnName);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.Adjacencies in project netvirt by opendaylight.
the class VpnInterfaceManager method withdrawAdjacenciesForVpnFromBgp.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void withdrawAdjacenciesForVpnFromBgp(final InstanceIdentifier<VpnInterfaceOpDataEntry> identifier, String vpnName, String interfaceName, TypedWriteTransaction<Configuration> writeConfigTxn, TypedWriteTransaction<Operational> writeOperTx) {
// Read NextHops
InstanceIdentifier<AdjacenciesOp> path = identifier.augmentation(AdjacenciesOp.class);
String rd = vpnUtil.getVpnRd(interfaceName);
if (rd == null) {
LOG.error("withdrawAdjacenciesForVpnFromBgp: Unable to recover rd for interface {} in vpn {}", interfaceName, vpnName);
return;
} else {
if (rd.equals(vpnName)) {
LOG.info("withdrawAdjacenciesForVpnFromBgp: Ignoring BGP withdrawal for interface {} as it is in " + "internal vpn{} with rd {}", interfaceName, vpnName, rd);
return;
}
}
LOG.info("withdrawAdjacenciesForVpnFromBgp: For interface {} in vpn {} with rd {}", interfaceName, vpnName, rd);
Optional<AdjacenciesOp> adjacencies = Optional.empty();
try {
adjacencies = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, path);
} catch (InterruptedException | ExecutionException e) {
LOG.error("withdrawAdjacenciesForVpnFromBgp: Failed to read data store for interface {} vpn {}", interfaceName, vpnName);
}
if (adjacencies.isPresent()) {
Map<AdjacencyKey, Adjacency> nextHopsMap = adjacencies.get().getAdjacency();
if (nextHopsMap != null && !nextHopsMap.isEmpty()) {
LOG.trace("withdrawAdjacenciesForVpnFromBgp: NextHops are {} for interface {} in vpn {} rd {}", nextHopsMap, interfaceName, vpnName, rd);
for (Adjacency nextHop : nextHopsMap.values()) {
try {
if (nextHop.getAdjacencyType() != AdjacencyType.ExtraRoute) {
LOG.info("VPN WITHDRAW: withdrawAdjacenciesForVpnFromBgp: Removing Fib Entry rd {}" + " prefix {} for interface {} in vpn {}", rd, nextHop.getIpAddress(), interfaceName, vpnName);
bgpManager.withdrawPrefix(rd, nextHop.getIpAddress());
LOG.info("VPN WITHDRAW: withdrawAdjacenciesForVpnFromBgp: Removed Fib Entry rd {}" + " prefix {} for interface {} in vpn {}", rd, nextHop.getIpAddress(), interfaceName, vpnName);
} else if (nextHop.getNextHopIpList() != null) {
// Perform similar operation as interface delete event for extraroutes.
String allocatedRd = nextHop.getVrfId();
for (String nh : nextHop.getNextHopIpList()) {
deleteExtraRouteFromCurrentAndImportingVpns(vpnName, nextHop.getIpAddress(), nh, allocatedRd, interfaceName, writeConfigTxn, writeOperTx);
}
}
} catch (Exception e) {
LOG.error("withdrawAdjacenciesForVpnFromBgp: Failed to withdraw prefix {} in vpn {} with rd {}" + " for interface {} ", nextHop.getIpAddress(), vpnName, rd, interfaceName, e);
}
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.Adjacencies in project netvirt by opendaylight.
the class NeutronvpnManager method writeVpnInterfaceToDs.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void writeVpnInterfaceToDs(@NonNull Collection<Uuid> vpnIdList, String infName, @Nullable Adjacencies adjacencies, Uuid networkUuid, Boolean isRouterInterface, TypedWriteTransaction<Configuration> wrtConfigTxn) {
if (vpnIdList.isEmpty() || infName == null) {
LOG.error("vpnid is empty or interface({}) is null", infName);
return;
}
if (wrtConfigTxn == null) {
LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> writeVpnInterfaceToDs(vpnIdList, infName, adjacencies, networkUuid, isRouterInterface, tx)), LOG, "Error writing VPN interface");
return;
}
List<VpnInstanceNames> vpnIdListStruct = new ArrayList<>();
for (Uuid vpnId : vpnIdList) {
VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
vpnIdListStruct.add(vpnInstance);
}
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
VpnInterfaceBuilder vpnb = new VpnInterfaceBuilder().withKey(new VpnInterfaceKey(infName)).setName(infName).setVpnInstanceNames(vpnIdListStruct).setRouterInterface(isRouterInterface);
LOG.info("Network Id is {}", networkUuid);
if (networkUuid != null) {
Network portNetwork = neutronvpnUtils.getNeutronNetwork(networkUuid);
ProviderTypes providerType = NeutronvpnUtils.getProviderNetworkType(portNetwork);
NetworkAttributes.NetworkType networkType = providerType != null ? NetworkAttributes.NetworkType.valueOf(providerType.getName()) : null;
String segmentationId = NeutronvpnUtils.getSegmentationIdFromNeutronNetwork(portNetwork);
vpnb.setNetworkId(networkUuid).setNetworkType(networkType).setSegmentationId(segmentationId != null ? Long.parseLong(segmentationId) : 0L);
}
if (adjacencies != null) {
vpnb.addAugmentation(adjacencies);
}
VpnInterface vpnIf = vpnb.build();
try {
LOG.info("Creating vpn interface {}", vpnIf);
wrtConfigTxn.put(vpnIfIdentifier, vpnIf);
} catch (Exception ex) {
LOG.error("Creation of vpninterface {} failed", infName, ex);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.Adjacencies in project netvirt by opendaylight.
the class NeutronvpnManager method updateVpnInterfaceWithAdjacencies.
private void updateVpnInterfaceWithAdjacencies(Uuid vpnId, String infName, Adjacencies adjacencies, TypedWriteTransaction<Configuration> wrtConfigTxn) {
if (vpnId == null || infName == null) {
LOG.error("vpn id or interface is null");
return;
}
if (wrtConfigTxn == null) {
LOG.error("updateVpnInterfaceWithAdjancies called with wrtConfigTxn as null");
LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
updateVpnInterfaceWithAdjacencies(vpnId, infName, adjacencies, tx);
}), LOG, "Error updating VPN interface with adjacencies");
return;
}
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
try (AcquireResult lock = tryInterfaceLock(infName)) {
if (!lock.wasAcquired()) {
// FIXME: why do we even bother with locking if we do not honor it?!
logTryLockFailure(infName);
}
try {
Optional<VpnInterface> optionalVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
if (optionalVpnInterface.isPresent()) {
VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get());
LOG.debug("Updating vpn interface {} with new adjacencies", infName);
if (adjacencies == null) {
return;
}
vpnIfBuilder.addAugmentation(adjacencies);
if (optionalVpnInterface.get().getVpnInstanceNames() != null) {
List<VpnInstanceNames> listVpnInstances = new ArrayList<>(optionalVpnInterface.get().getVpnInstanceNames().values());
if (listVpnInstances.isEmpty() || !VpnHelper.doesVpnInterfaceBelongToVpnInstance(vpnId.getValue(), listVpnInstances)) {
VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
listVpnInstances.add(vpnInstance);
vpnIfBuilder.setVpnInstanceNames(listVpnInstances);
}
} else {
VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
List<VpnInstanceNames> listVpnInstances = new ArrayList<>();
listVpnInstances.add(vpnInstance);
vpnIfBuilder.setVpnInstanceNames(listVpnInstances);
}
LOG.info("Updating vpn interface {} with new adjacencies", infName);
wrtConfigTxn.put(vpnIfIdentifier, vpnIfBuilder.build());
}
} catch (IllegalStateException | ExecutionException | InterruptedException ex) {
// FIXME: why are we catching IllegalStateException here?
LOG.error("Update of vpninterface {} failed", infName, ex);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.Adjacencies in project netvirt by opendaylight.
the class NeutronvpnManager method removeInternetVpnFromVpnInterface.
protected void removeInternetVpnFromVpnInterface(Uuid vpnId, Port port, TypedWriteTransaction<Configuration> writeConfigTxn, Subnetmap sm) {
if (vpnId == null || port == null) {
return;
}
String infName = port.getUuid().getValue();
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
try {
Optional<VpnInterface> optionalVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
if (optionalVpnInterface.isPresent()) {
Map<VpnInstanceNamesKey, VpnInstanceNames> keyVpnInstanceNamesMap = optionalVpnInterface.get().getVpnInstanceNames();
if (keyVpnInstanceNamesMap != null && VpnHelper.doesVpnInterfaceBelongToVpnInstance(vpnId.getValue(), new ArrayList<>(keyVpnInstanceNamesMap.values()))) {
VpnHelper.removeVpnInterfaceVpnInstanceNamesFromList(vpnId.getValue(), new ArrayList<>(keyVpnInstanceNamesMap.values()));
}
VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get()).setVpnInstanceNames(keyVpnInstanceNamesMap);
Adjacencies adjs = vpnIfBuilder.augmentation(Adjacencies.class);
LOG.debug("Updating vpn interface {}", infName);
Map<AdjacencyKey, Adjacency> keyAdjacencyMap = adjs != null ? adjs.getAdjacency() : new HashMap<>();
Iterator<Adjacency> adjacencyIter = keyAdjacencyMap.values().iterator();
while (adjacencyIter.hasNext()) {
Adjacency adjacency = adjacencyIter.next();
if (adjacency.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
continue;
}
String mipToQuery = adjacency.getIpAddress().split("/")[0];
InstanceIdentifier<LearntVpnVipToPort> id = NeutronvpnUtils.buildLearntVpnVipToPortIdentifier(vpnId.getValue(), mipToQuery);
Optional<LearntVpnVipToPort> optionalVpnVipToPort = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (optionalVpnVipToPort.isPresent()) {
LOG.trace("Removing adjacencies from vpninterface {} upon dissociation of router {}", infName, vpnId);
if (keyVpnInstanceNamesMap == null || keyVpnInstanceNamesMap.isEmpty()) {
adjacencyIter.remove();
}
neutronvpnUtils.removeLearntVpnVipToPort(vpnId.getValue(), mipToQuery);
LOG.trace("Entry for fixedIP {} for port {} on VPN {} removed from VpnPortFixedIPToPortData", mipToQuery, infName, vpnId.getValue());
}
}
for (FixedIps ip : port.nonnullFixedIps().values()) {
String ipValue = ip.getIpAddress().stringValue();
// skip IPv4 address
if (!NeutronvpnUtils.getIpVersionFromString(ipValue).isIpVersionChosen(IpVersionChoice.IPV6)) {
continue;
}
neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), ipValue, writeConfigTxn);
}
if (keyVpnInstanceNamesMap == null || keyVpnInstanceNamesMap.isEmpty()) {
if (sm != null && sm.getRouterId() != null) {
removeFromNeutronRouterInterfacesMap(sm.getRouterId(), port.getUuid().getValue());
}
deleteVpnInterface(port.getUuid().getValue(), null, /* vpn-id */
writeConfigTxn);
} else {
writeConfigTxn.put(vpnIfIdentifier, vpnIfBuilder.build());
}
} else {
LOG.info("removeVpnFromVpnInterface: VPN Interface {} not found", infName);
}
} catch (ExecutionException | InterruptedException ex) {
LOG.error("Update of vpninterface {} failed", infName, ex);
}
}
Aggregations