use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterfaceKey in project netvirt by opendaylight.
the class VpnInterfaceManager method addVpnInterfaceCall.
private void addVpnInterfaceCall(final InstanceIdentifier<VpnInterface> identifier, final VpnInterface vpnInterface, final List<Adjacency> oldAdjs, final List<Adjacency> newAdjs, String vpnName) {
final VpnInterfaceKey key = identifier.firstKeyOf(VpnInterface.class);
final String interfaceName = key.getName();
if (!canHandleNewVpnInterface(identifier, vpnInterface, vpnName)) {
LOG.error("add: VpnInstance {} for vpnInterface {} not ready, holding on ", vpnName, vpnInterface.getName());
return;
}
InstanceIdentifier<VpnInterfaceOpDataEntry> vpnInterfaceOpIdentifier = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
List<Adjacency> copyOldAdjs = null;
if (oldAdjs != null) {
copyOldAdjs = new ArrayList<>();
copyOldAdjs.addAll(oldAdjs);
}
List<Adjacency> copyNewAdjs = null;
if (newAdjs != null) {
copyNewAdjs = new ArrayList<>();
copyNewAdjs.addAll(newAdjs);
}
addVpnInterfaceToVpn(vpnInterfaceOpIdentifier, vpnInterface, copyOldAdjs, copyNewAdjs, identifier, vpnName);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterfaceKey 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.vpn.interfaces.VpnInterfaceKey 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.vpn.interfaces.VpnInterfaceKey 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