use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface in project netvirt by opendaylight.
the class NeutronvpnManager method removeExternalVpnInterfaces.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void removeExternalVpnInterfaces(Uuid extNetId) {
Collection<String> extElanInterfaces = elanService.getExternalElanInterfaces(extNetId.getValue());
if (extElanInterfaces == null || extElanInterfaces.isEmpty()) {
LOG.error("No external ports attached for external network {}", extNetId.getValue());
return;
}
try {
WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
for (String elanInterface : extElanInterfaces) {
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(elanInterface);
LOG.info("Removing vpn interface {}", elanInterface);
wrtConfigTxn.delete(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
}
wrtConfigTxn.submit();
} catch (Exception ex) {
LOG.error("Removal of vpninterfaces {} failed", extElanInterfaces, ex);
}
}
use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface in project netvirt by opendaylight.
the class NeutronvpnManager method deleteVpnInterface.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected boolean deleteVpnInterface(String infName, @Nullable String vpnId, WriteTransaction wrtConfigTxn) {
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
Optional<VpnInterface> optionalVpnInterface = null;
try {
optionalVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
} catch (ReadFailedException ex) {
LOG.error("Error during deletion of vpninterface {}", infName, ex);
return false;
}
if (!optionalVpnInterface.isPresent()) {
LOG.warn("Deletion of vpninterface {}, optionalVpnInterface is not present()", infName);
return false;
}
boolean wrtConfigTxnPresent = true;
if (wrtConfigTxn == null) {
wrtConfigTxnPresent = false;
wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
}
if (vpnId != null) {
VpnInterface vpnInterface = optionalVpnInterface.get();
List<VpnInstanceNames> vpnList = vpnInterface.getVpnInstanceNames();
if (vpnList != null && VpnHelper.doesVpnInterfaceBelongToVpnInstance(vpnId, vpnList)) {
VpnHelper.removeVpnInterfaceVpnInstanceNamesFromList(vpnId, vpnList);
if (!vpnList.isEmpty()) {
if (!wrtConfigTxnPresent) {
wrtConfigTxn.submit();
}
LOG.debug("Deleting vpn interface {} not immediately since vpnInstanceName " + "List not empty", infName);
return false;
}
VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get()).setVpnInstanceNames(vpnList);
wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIfBuilder.build());
}
}
LOG.debug("Deleting vpn interface {}", infName);
wrtConfigTxn.delete(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
if (!wrtConfigTxnPresent) {
wrtConfigTxn.submit();
}
return true;
}
use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface in project netvirt by opendaylight.
the class VpnFootprintService method createOrUpdateVpnToDpnListForInterfaceName.
private void createOrUpdateVpnToDpnListForInterfaceName(long vpnId, String primaryRd, BigInteger dpnId, String intfName, String vpnName) {
Boolean newDpnOnVpn = Boolean.FALSE;
synchronized (vpnName.intern()) {
WriteTransaction writeTxn = dataBroker.newWriteOnlyTransaction();
InstanceIdentifier<VpnToDpnList> id = VpnUtil.getVpnToDpnListIdentifier(primaryRd, dpnId);
Optional<VpnToDpnList> dpnInVpn = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
VpnInterfaces vpnInterface = new VpnInterfacesBuilder().setInterfaceName(intfName).build();
if (dpnInVpn.isPresent()) {
VpnToDpnList vpnToDpnList = dpnInVpn.get();
List<VpnInterfaces> vpnInterfaces = vpnToDpnList.getVpnInterfaces();
if (vpnInterfaces == null) {
vpnInterfaces = new ArrayList<>();
}
vpnInterfaces.add(vpnInterface);
VpnToDpnListBuilder vpnToDpnListBuilder = new VpnToDpnListBuilder(vpnToDpnList);
vpnToDpnListBuilder.setDpnState(VpnToDpnList.DpnState.Active).setVpnInterfaces(vpnInterfaces);
writeTxn.put(LogicalDatastoreType.OPERATIONAL, id, vpnToDpnListBuilder.build(), WriteTransaction.CREATE_MISSING_PARENTS);
/*
* If earlier state was inactive, it is considered new DPN coming back to the
* same VPN
*/
if (vpnToDpnList.getDpnState() == VpnToDpnList.DpnState.Inactive) {
newDpnOnVpn = Boolean.TRUE;
}
LOG.debug("createOrUpdateVpnToDpnList: Updating vpn footprint for vpn {} vpnId {} interface {}" + " on dpn {}", vpnName, vpnId, intfName, dpnId);
} else {
List<VpnInterfaces> vpnInterfaces = new ArrayList<>();
vpnInterfaces.add(vpnInterface);
VpnToDpnListBuilder vpnToDpnListBuilder = new VpnToDpnListBuilder().setDpnId(dpnId);
vpnToDpnListBuilder.setDpnState(VpnToDpnList.DpnState.Active).setVpnInterfaces(vpnInterfaces);
writeTxn.put(LogicalDatastoreType.OPERATIONAL, id, vpnToDpnListBuilder.build(), WriteTransaction.CREATE_MISSING_PARENTS);
newDpnOnVpn = Boolean.TRUE;
LOG.debug("createOrUpdateVpnToDpnList: Creating vpn footprint for vpn {} vpnId {} interface {}" + " on dpn {}", vpnName, vpnId, intfName, dpnId);
}
try {
writeTxn.submit().get();
} catch (InterruptedException | ExecutionException e) {
LOG.error("createOrUpdateVpnToDpnList: Error adding to dpnToVpnList for vpn {} vpnId {} interface {}" + " dpn {}", vpnName, vpnId, intfName, dpnId, e);
throw new RuntimeException(e.getMessage(), e);
}
}
LOG.info("createOrUpdateVpnToDpnList: Created/Updated vpn footprint for vpn {} vpnId {} interfacName{}" + " on dpn {}", vpnName, vpnId, intfName, dpnId);
/*
* Informing the FIB only after writeTxn is submitted successfully.
*/
if (newDpnOnVpn) {
if (VpnUtil.isVlan(dataBroker, intfName)) {
if (!VpnUtil.shouldPopulateFibForVlan(dataBroker, vpnName, null, dpnId, interfaceManager)) {
return;
}
}
fibManager.populateFibOnNewDpn(dpnId, vpnId, primaryRd, new DpnEnterExitVpnWorker(dpnId, vpnName, primaryRd, true));
LOG.info("createOrUpdateVpnToDpnList: Sent populateFib event for new dpn {} in VPN {} for interface {}", dpnId, vpnName, intfName);
}
}
use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface in project netvirt by opendaylight.
the class VpnInterfaceManager method processVpnInterfaceAdjacencies.
@SuppressWarnings("checkstyle:IllegalCatch")
protected void processVpnInterfaceAdjacencies(BigInteger dpnId, final int lportTag, String vpnName, String primaryRd, String interfaceName, final long vpnId, WriteTransaction writeConfigTxn, WriteTransaction writeOperTxn, final WriteTransaction writeInvTxn, Interface interfaceState) {
InstanceIdentifier<VpnInterface> identifier = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
// Read NextHops
InstanceIdentifier<Adjacencies> path = identifier.augmentation(Adjacencies.class);
Optional<Adjacencies> adjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, path);
if (!adjacencies.isPresent()) {
addVpnInterfaceToOperational(vpnName, interfaceName, dpnId, null, /*adjacencies*/
lportTag, null, /*gwMac*/
writeOperTxn);
return;
}
// Get the rd of the vpn instance
String nextHopIp = null;
try {
nextHopIp = InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, dpnId);
} catch (Exception e) {
LOG.error("processVpnInterfaceAdjacencies: Unable to retrieve endpoint ip address for " + "dpnId {} for vpnInterface {} vpnName {}", dpnId, interfaceName, vpnName);
}
List<String> nhList = new ArrayList<>();
if (nextHopIp != null) {
nhList.add(nextHopIp);
LOG.debug("processVpnInterfaceAdjacencies: NextHop for interface {} on dpn {} in vpn {} is {}", interfaceName, dpnId, vpnName, nhList);
}
Optional<String> gwMac = Optional.absent();
String vpnInterfaceSubnetGwMacAddress = null;
VpnInstanceOpDataEntry vpnInstanceOpData = VpnUtil.getVpnInstanceOpData(dataBroker, primaryRd);
Long l3vni = vpnInstanceOpData.getL3vni();
boolean isL3VpnOverVxLan = VpnUtil.isL3VpnOverVxLan(l3vni);
VrfEntry.EncapType encapType = isL3VpnOverVxLan ? VrfEntry.EncapType.Vxlan : VrfEntry.EncapType.Mplsgre;
VpnPopulator registeredPopulator = L3vpnRegistry.getRegisteredPopulator(encapType);
List<Adjacency> nextHops = adjacencies.get().getAdjacency();
List<Adjacency> value = new ArrayList<>();
for (Adjacency nextHop : nextHops) {
String rd = primaryRd;
String nexthopIpValue = nextHop.getIpAddress().split("/")[0];
if (vpnInstanceOpData.getBgpvpnType() == VpnInstanceOpDataEntry.BgpvpnType.BGPVPNInternet && NWUtil.isIpv4Address(nexthopIpValue)) {
String prefix = nextHop.getIpAddress() == null ? "null" : VpnUtil.getIpPrefix(nextHop.getIpAddress());
LOG.debug("processVpnInterfaceAdjacencies: UnsupportedOperation : Not Adding prefix {} to interface {}" + " as InternetVpn has an IPV4 address {}", prefix, interfaceName, vpnName);
continue;
}
if (nextHop.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
String prefix = VpnUtil.getIpPrefix(nextHop.getIpAddress());
Prefixes.PrefixCue prefixCue = nextHop.isPhysNetworkFunc() ? Prefixes.PrefixCue.PhysNetFunc : Prefixes.PrefixCue.None;
LOG.debug("processVpnInterfaceAdjacencies: Adding prefix {} to interface {} with nextHops {} on dpn {}" + " for vpn {}", prefix, interfaceName, nhList, dpnId, vpnName);
writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(VpnUtil.getVpnId(dataBroker, vpnName), prefix), VpnUtil.getPrefixToInterface(dpnId, interfaceName, prefix, nextHop.getSubnetId(), prefixCue), true);
final Uuid subnetId = nextHop.getSubnetId();
String gatewayIp = nextHop.getSubnetGatewayIp();
if (gatewayIp == null) {
Optional<String> gatewayIpOptional = VpnUtil.getVpnSubnetGatewayIp(dataBroker, subnetId);
if (gatewayIpOptional.isPresent()) {
gatewayIp = gatewayIpOptional.get();
}
}
if (gatewayIp != null) {
gwMac = getMacAddressForSubnetIp(vpnName, interfaceName, gatewayIp);
if (gwMac.isPresent()) {
// A valid mac-address is available for this subnet-gateway-ip
// Use this for programming ARP_RESPONDER table here. And save this
// info into vpnInterface operational, so it can used in VrfEntryProcessor
// to populate L3_GW_MAC_TABLE there.
arpResponderHandler.addArpResponderFlow(dpnId, lportTag, interfaceName, gatewayIp, gwMac.get());
vpnInterfaceSubnetGwMacAddress = gwMac.get();
} else {
// A valid mac-address is not available for this subnet-gateway-ip
// Use the connected-mac-address to configure ARP_RESPONDER Table.
// Save this connected-mac-address as gateway-mac-address for the
// VrfEntryProcessor to use this later to populate the L3_GW_MAC_TABLE.
gwMac = InterfaceUtils.getMacAddressFromInterfaceState(interfaceState);
if (gwMac.isPresent()) {
VpnUtil.setupGwMacIfExternalVpn(dataBroker, mdsalManager, dpnId, interfaceName, vpnId, writeInvTxn, NwConstants.ADD_FLOW, gwMac.get());
arpResponderHandler.addArpResponderFlow(dpnId, lportTag, interfaceName, gatewayIp, gwMac.get());
} else {
LOG.error("processVpnInterfaceAdjacencies: Gateway MAC for subnet ID {} could not be " + "obtained, cannot create ARP responder flow for interface name {}, vpnName {}, " + "gwIp {}", subnetId, interfaceName, vpnName, gatewayIp);
}
}
} else {
LOG.warn("processVpnInterfaceAdjacencies: Gateway IP for subnet ID {} could not be obtained, " + "cannot create ARP responder flow for interface name {}, vpnName {}", subnetId, interfaceName, vpnName);
gwMac = InterfaceUtils.getMacAddressFromInterfaceState(interfaceState);
}
LOG.info("processVpnInterfaceAdjacencies: Added prefix {} to interface {} with nextHops {} on dpn {}" + " for vpn {}", prefix, interfaceName, nhList, dpnId, vpnName);
} else {
// Extra route adjacency
String prefix = VpnUtil.getIpPrefix(nextHop.getIpAddress());
String vpnPrefixKey = VpnUtil.getVpnNamePrefixKey(vpnName, prefix);
synchronized (vpnPrefixKey.intern()) {
java.util.Optional<String> rdToAllocate = VpnUtil.allocateRdForExtraRouteAndUpdateUsedRdsMap(dataBroker, vpnId, null, prefix, vpnName, nextHop.getNextHopIpList().get(0), dpnId);
if (rdToAllocate.isPresent()) {
rd = rdToAllocate.get();
LOG.info("processVpnInterfaceAdjacencies: The rd {} is allocated for the extraroute {}", rd, prefix);
} else {
LOG.error("processVpnInterfaceAdjacencies: No rds to allocate extraroute {}", prefix);
continue;
}
}
LOG.info("processVpnInterfaceAdjacencies: Added prefix {} and nextHopList {} as extra-route for vpn{}" + " interface {} on dpn {}", nextHop.getIpAddress(), nextHop.getNextHopIpList(), vpnName, interfaceName, dpnId);
}
// Please note that primary adjacency will use a subnet-gateway-mac-address that
// can be different from the gateway-mac-address within the VRFEntry as the
// gateway-mac-address is a superset.
RouteOrigin origin = nextHop.getAdjacencyType() == AdjacencyType.PrimaryAdjacency ? RouteOrigin.LOCAL : RouteOrigin.STATIC;
L3vpnInput input = new L3vpnInput().setNextHop(nextHop).setRd(rd).setVpnName(vpnName).setInterfaceName(interfaceName).setNextHopIp(nextHopIp).setPrimaryRd(primaryRd).setSubnetGatewayMacAddress(vpnInterfaceSubnetGwMacAddress).setRouteOrigin(origin);
Adjacency operationalAdjacency = null;
try {
operationalAdjacency = registeredPopulator.createOperationalAdjacency(input);
} catch (NullPointerException e) {
LOG.error("processVpnInterfaceAdjacencies: failed to create operational adjacency: input: {}, {}", input, e.getMessage());
return;
}
if (nextHop.getAdjacencyType() != AdjacencyType.PrimaryAdjacency) {
vpnManager.addExtraRoute(vpnName, nextHop.getIpAddress(), nextHop.getNextHopIpList().get(0), rd, vpnName, l3vni, origin, interfaceName, operationalAdjacency, encapType, writeConfigTxn);
}
value.add(operationalAdjacency);
}
AdjacenciesOp aug = VpnUtil.getVpnInterfaceOpDataEntryAugmentation(value);
addVpnInterfaceToOperational(vpnName, interfaceName, dpnId, aug, lportTag, gwMac.isPresent() ? gwMac.get() : null, writeOperTxn);
L3vpnInput input = new L3vpnInput().setNextHopIp(nextHopIp).setL3vni(l3vni).setPrimaryRd(primaryRd).setGatewayMac(gwMac.orNull()).setInterfaceName(interfaceName).setVpnName(vpnName).setDpnId(dpnId).setEncapType(encapType);
for (Adjacency nextHop : aug.getAdjacency()) {
// Adjacencies other than primary Adjacencies are handled in the addExtraRoute call above.
if (nextHop.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
RouteOrigin origin = nextHop.getAdjacencyType() == AdjacencyType.PrimaryAdjacency ? RouteOrigin.LOCAL : RouteOrigin.STATIC;
input.setNextHop(nextHop).setRd(nextHop.getVrfId()).setRouteOrigin(origin);
registeredPopulator.populateFib(input, writeConfigTxn);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface in project netvirt by opendaylight.
the class VpnInterfaceManager method removeVpnInterfaceCall.
private void removeVpnInterfaceCall(final InstanceIdentifier<VpnInterface> identifier, final VpnInterface vpnInterface, final String vpnName, final String interfaceName) {
if (Boolean.TRUE.equals(vpnInterface.isRouterInterface())) {
jobCoordinator.enqueueJob("VPNINTERFACE-" + vpnInterface.getName(), () -> {
WriteTransaction writeConfigTxn = dataBroker.newWriteOnlyTransaction();
deleteFibEntryForRouterInterface(vpnInterface, writeConfigTxn, vpnName);
LOG.info("remove: Router interface {} for vpn {}", interfaceName, vpnName);
ListenableFuture<Void> futures = writeConfigTxn.submit();
String errorText = "removeVpnInterfaceCall: Exception encountered while submitting writeConfigTxn" + " for interface " + vpnInterface.getName() + " on vpn " + vpnName;
ListenableFutures.addErrorLogging(futures, LOG, errorText);
return Collections.singletonList(futures);
}, DJC_MAX_RETRIES);
} else {
Interface interfaceState = InterfaceUtils.getInterfaceStateFromOperDS(dataBroker, interfaceName);
removeVpnInterfaceFromVpn(identifier, vpnInterface, vpnName, interfaceName, interfaceState);
}
}
Aggregations