use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyKey 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.adjacency.list.AdjacencyKey in project netvirt by opendaylight.
the class NeutronvpnManager method getAdjacencyMap.
private Map<AdjacencyKey, Adjacency> getAdjacencyMap(List<Adjacency> adjList) {
// convert to set to remove duplicates.
Set<Adjacency> adjset = adjList.stream().collect(Collectors.toSet());
Map<AdjacencyKey, Adjacency> adjacencyMap = new HashMap<>();
for (Adjacency adj : adjset) {
adjacencyMap.put(new AdjacencyKey(adj.getIpAddress()), adj);
}
return adjacencyMap;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyKey in project netvirt by opendaylight.
the class NeutronvpnManager method updateVpnInterfaceWithExtraRouteAdjacency.
protected void updateVpnInterfaceWithExtraRouteAdjacency(Uuid vpnId, List<Routes> routeList) {
checkAlarmExtraRoutes(vpnId, routeList);
for (Routes route : routeList) {
if (route == null || route.getNexthop() == null || route.getDestination() == null) {
LOG.error("Incorrect input received for extra route. {}", route);
} else {
String nextHop = route.getNexthop().stringValue();
String destination = route.getDestination().stringValue();
String infName = neutronvpnUtils.getNeutronPortNameFromVpnPortFixedIp(vpnId.getValue(), nextHop);
if (infName != null) {
LOG.trace("Updating extra route for destination {} onto vpn {} with nexthop {} and infName {}", destination, vpnId.getValue(), nextHop, infName);
boolean isLockAcquired = false;
try {
InstanceIdentifier<VpnInterface> identifier = InstanceIdentifier.builder(VpnInterfaces.class).child(VpnInterface.class, new VpnInterfaceKey(infName)).build();
InstanceIdentifier<Adjacency> path = identifier.augmentation(Adjacencies.class).child(Adjacency.class, new AdjacencyKey(destination));
Optional<Adjacency> existingAdjacency = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, path);
if (existingAdjacency.isPresent() && existingAdjacency.get().getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
LOG.error("The route with destination {} nextHop {} is already present as" + " a primary adjacency for interface {}. Skipping adjacency addition.", destination, nextHop, infName);
continue;
}
Adjacency erAdj = new AdjacencyBuilder().setIpAddress(destination).setNextHopIpList(Collections.singletonList(nextHop)).withKey(new AdjacencyKey(destination)).setAdjacencyType(AdjacencyType.ExtraRoute).build();
try (AcquireResult lock = tryInterfaceLock(infName)) {
if (!lock.wasAcquired()) {
// FIXME: why do we even bother with locking if we do not honor it?!
logTryLockFailure(infName);
}
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, path, erAdj);
}
} catch (TransactionCommitFailedException e) {
LOG.error("exception in adding extra route with destination: {}, next hop: {}", destination, nextHop, e);
} catch (ExecutionException | InterruptedException e) {
LOG.error("Exception on reading data-store ", e);
}
} else {
LOG.error("Unable to find VPN NextHop interface to apply extra-route destination {} on VPN {} " + "with nexthop {}", destination, vpnId.getValue(), nextHop);
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyKey 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);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyKey in project netvirt by opendaylight.
the class NeutronvpnManager method removeAdjacencyforExtraRoute.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void removeAdjacencyforExtraRoute(Uuid vpnId, List<Routes> routeList) {
for (Routes route : routeList) {
if (route != null && route.getNexthop() != null && route.getDestination() != null) {
String nextHop = route.getNexthop().stringValue();
String destination = route.getDestination().stringValue();
String infName = neutronvpnUtils.getNeutronPortNameFromVpnPortFixedIp(vpnId.getValue(), nextHop);
if (infName == null) {
LOG.error("Unable to find VPN NextHop interface to remove extra-route destination {} on VPN {} " + "with nexthop {}", destination, vpnId.getValue(), nextHop);
// Proceed to remove the next extra-route
continue;
}
LOG.trace("Removing extra route for destination {} on vpn {} with nexthop {} and infName {}", destination, vpnId.getValue(), nextHop, infName);
InstanceIdentifier<Adjacency> adjacencyIdentifier = InstanceIdentifier.builder(VpnInterfaces.class).child(VpnInterface.class, new VpnInterfaceKey(infName)).augmentation(Adjacencies.class).child(Adjacency.class, new AdjacencyKey(destination)).build();
try {
// Looking for existing prefix in MDSAL database
Optional<Adjacency> adjacency = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, adjacencyIdentifier);
boolean updateNextHops = false;
List<String> nextHopList = new ArrayList<>();
if (adjacency.isPresent()) {
List<String> nhListRead = adjacency.get().getNextHopIpList();
if (nhListRead.size() > 1) {
// ECMP case
for (String nextHopRead : nhListRead) {
if (nextHopRead.equals(nextHop)) {
updateNextHops = true;
} else {
nextHopList.add(nextHopRead);
}
}
}
}
try (AcquireResult lock = tryInterfaceLock(infName)) {
if (!lock.wasAcquired()) {
// FIXME: why do we even bother with locking if we do not honor it?!
logTryLockFailure(infName);
}
if (updateNextHops) {
// An update must be done, not including the current next hop
InstanceIdentifier<VpnInterface> vpnIfIdentifier = InstanceIdentifier.builder(VpnInterfaces.class).child(VpnInterface.class, new VpnInterfaceKey(infName)).build();
Adjacency newAdj = new AdjacencyBuilder(adjacency.get()).setIpAddress(destination).setNextHopIpList(nextHopList).withKey(new AdjacencyKey(destination)).build();
List<Adjacency> newAdjList = Collections.singletonList(newAdj);
Adjacencies erAdjs = new AdjacenciesBuilder().setAdjacency(getAdjacencyMap(newAdjList)).build();
VpnInterface vpnIf = new VpnInterfaceBuilder().withKey(new VpnInterfaceKey(infName)).addAugmentation(erAdjs).build();
SingleTransactionDataBroker.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIf);
} else {
// Remove the whole route
SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, adjacencyIdentifier);
LOG.trace("extra route {} deleted successfully", route);
}
}
} catch (TransactionCommitFailedException | ExecutionException | InterruptedException e) {
LOG.error("exception in deleting extra route with destination {} for interface {}", destination, infName, e);
}
} else {
LOG.error("Incorrect input received for extra route: {}", route);
}
}
}
Aggregations