use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class TunnelInterfaceStateListener method handleTunnelEventForDPNVpn.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void handleTunnelEventForDPNVpn(StateTunnelList stateTunnelList, Map<Uint32, String> vpnIdRdMap, TunnelAction tunnelAction, boolean isTepDeletedOnDpn, List<Uuid> subnetList, TunnelEventProcessingMethod method, VpnInterface cfgVpnInterface) {
String rd;
String intfName = cfgVpnInterface.getName();
final Uint64 srcDpnId = Uint64.valueOf(stateTunnelList.getSrcInfo() != null ? stateTunnelList.getSrcInfo().getTepDeviceId() : "0").intern();
String destTepIp = stateTunnelList.getDstInfo() != null ? stateTunnelList.getDstInfo().getTepIp().stringValue() : null;
String srcTepIp = stateTunnelList.getSrcInfo() != null ? stateTunnelList.getSrcInfo().getTepIp().stringValue() : null;
int tunTypeVal = getTunnelType(stateTunnelList);
Uint64 remoteDpnId = null;
if (tunTypeVal == VpnConstants.ITMTunnelLocType.Internal.getValue()) {
remoteDpnId = Uint64.valueOf(stateTunnelList.getDstInfo() != null ? stateTunnelList.getDstInfo().getTepDeviceId() : "0").intern();
}
if (cfgVpnInterface.getVpnInstanceNames() == null) {
LOG.warn("handleTunnelEventForDpn: no vpnName found for interface {}", intfName);
return;
}
try {
for (VpnInstanceNames vpnInstance : cfgVpnInterface.getVpnInstanceNames().values()) {
String vpnName = vpnInstance.getVpnName();
if (method == TunnelEventProcessingMethod.POPULATESUBNETS) {
Optional<VpnInterfaceOpDataEntry> opVpnInterface = vpnUtil.getVpnInterfaceOpDataEntry(intfName, vpnName);
if (opVpnInterface.isPresent()) {
VpnInterfaceOpDataEntry vpnInterface = opVpnInterface.get();
jobCoordinator.enqueueJob("VPNINTERFACE-" + intfName, new UpdateVpnInterfaceOnTunnelEvent(tunnelAction, vpnInterface, stateTunnelList, isTepDeletedOnDpn));
// Populate the List of subnets
InstanceIdentifier<PortOpDataEntry> portOpIdentifier = InstanceIdentifier.builder(PortOpData.class).child(PortOpDataEntry.class, new PortOpDataEntryKey(intfName)).build();
Optional<PortOpDataEntry> optionalPortOp = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier);
if (optionalPortOp.isPresent()) {
List<Uuid> subnetIdList = optionalPortOp.get().getSubnetIds();
if (subnetIdList != null) {
for (Uuid subnetId : subnetIdList) {
if (!subnetList.contains(subnetId)) {
subnetList.add(subnetId);
}
}
}
}
// Populate the map for VpnId-to-Rd
Uint32 vpnId = vpnUtil.getVpnId(vpnName);
rd = vpnUtil.getVpnRd(vpnName);
vpnIdRdMap.put(vpnId, rd);
}
} else if (method == TunnelEventProcessingMethod.MANAGEREMOTEROUTES) {
Optional<VpnInterfaceOpDataEntry> opVpnInterface = vpnUtil.getVpnInterfaceOpDataEntry(intfName, vpnName);
if (opVpnInterface.isPresent()) {
VpnInterfaceOpDataEntry vpnInterface = opVpnInterface.get();
AdjacenciesOp adjacencies = vpnInterface.augmentation(AdjacenciesOp.class);
Map<AdjacencyKey, Adjacency> adjacencyKeyAdjacencyMap = adjacencies != null && adjacencies.getAdjacency() != null ? adjacencies.getAdjacency() : Collections.<AdjacencyKey, Adjacency>emptyMap();
String prefix = null;
Uint32 vpnId = vpnUtil.getVpnId(vpnInterface.getVpnInstanceName());
if (vpnIdRdMap.containsKey(vpnId)) {
rd = vpnIdRdMap.get(vpnId);
LOG.info("handleTunnelEventForDPN: Remote DpnId {} VpnId {} rd {} VpnInterface {}" + " srcTepIp {} destTepIp {}", remoteDpnId, vpnId, rd, vpnInterface, srcTepIp, destTepIp);
for (Adjacency adj : adjacencyKeyAdjacencyMap.values()) {
prefix = adj.getIpAddress();
Uint32 label = adj.getLabel();
if (tunnelAction == TunnelAction.TUNNEL_EP_ADD && tunTypeVal == VpnConstants.ITMTunnelLocType.Internal.getValue()) {
fibManager.manageRemoteRouteOnDPN(true, srcDpnId, vpnId, rd, prefix, destTepIp, label);
}
if (tunnelAction == TunnelAction.TUNNEL_EP_DELETE && tunTypeVal == VpnConstants.ITMTunnelLocType.Internal.getValue()) {
fibManager.manageRemoteRouteOnDPN(false, srcDpnId, vpnId, rd, prefix, destTepIp, label);
}
}
}
}
}
}
} catch (InterruptedException | ExecutionException e) {
LOG.error("handleTunnelEventForDPN: Failed to read data store for interface {} srcDpn {} srcTep {} " + "dstTep {}", intfName, srcDpnId, srcTepIp, destTepIp);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class NatUtil method getVpnId.
/*
getVpnId() returns the VPN ID from the VPN name
*/
public static Uint32 getVpnId(DataBroker broker, @Nullable String vpnName) {
if (vpnName == null) {
return NatConstants.INVALID_ID;
}
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance> id = getVpnInstanceToVpnIdIdentifier(vpnName);
Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance> vpnInstance = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.CONFIGURATION, id);
Uint32 vpnId = NatConstants.INVALID_ID;
if (vpnInstance.isPresent()) {
Uint32 vpnIdAsLong = vpnInstance.get().getVpnId();
if (vpnIdAsLong != null) {
vpnId = vpnIdAsLong;
}
}
return vpnId;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class NeutronBgpvpnNetworkAssociationChangeListener method remove.
@Override
public void remove(InstanceIdentifier<BgpvpnNetworkAssociation> identifier, BgpvpnNetworkAssociation input) {
LOG.trace("Removing Bgpvpn network association : key: {}, value={}", identifier, input);
Uuid vpnId = input.getBgpvpnId();
String vpnName = vpnId.getValue();
Uuid networkId = input.getNetworkId();
List<Uuid> networks = new ArrayList<>();
networks.add(networkId);
NamedLocks<String> vpnLock = neutronBgpvpnUtils.getVpnLock();
try (AcquireResult lock = vpnLock.tryAcquire(vpnName, NeutronConstants.LOCK_WAIT_TIME, TimeUnit.SECONDS)) {
if (!lock.wasAcquired()) {
LOG.error("Remove network association: remove association failed for vpn : {} and networkId: {} due " + "to failure in acquiring lock", vpnName, networkId.getValue());
return;
}
neutronBgpvpnUtils.removeUnProcessedNetwork(vpnId, networkId);
VpnInstance vpnInstance = neutronvpnUtils.getVpnInstance(vpnId);
if (vpnInstance != null) {
List<String> errorMessages = nvpnManager.dissociateNetworksFromVpn(vpnId, networks);
if (!errorMessages.isEmpty()) {
LOG.error("BgpvpnNetworkAssociation remove: dissociate network id {} to vpn {} failed due to {}", networkId.getValue(), vpnName, errorMessages);
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class VPNServiceChainHandler method programScfToVpnPipeline.
/**
* L3VPN Service chaining: It moves traffic from a ServiceChain to a L3VPN.
*
* @param vpnName Vpn Instance Name. Typicall the UUID
* @param scfTag ServiceChainForwarding Tag
* @param servChainTag ServiceChain Tag
* @param dpnId DpnId in which the egress pseudo logical port belongs
* @param vpnPseudoLportTag VpnPseudo Logical port tag
* @param isLastServiceChain Flag stating if there is no other ServiceChain
* using this VpnPseudoPort
* @param addOrRemove States if pipeline must be installed or removed
*/
public void programScfToVpnPipeline(String vpnName, long scfTag, int servChainTag, long dpnId, int vpnPseudoLportTag, boolean isLastServiceChain, int addOrRemove) {
// These Flows must be installed in the DPN where the last SF in the ServiceChain is located
// + ScForwardingTable (75): (This one is created and maintained by ScHopManager)
// - Match: scfTag + servChainId + lportTagOfvVSF Instr: VpnPseudoPortTag + SI=L3VPN + GOTO LPortDisp
// And these 2 flows must be installed in all Dpns where the Vpn is present:
// + LPortDisp (17):
// - Match: VpnPseudoPortTag + SI==L3VPN Instr: setVpnTag + GOTO FIB
// + FIB (21): (one entry per VrfEntry, and it is maintained by FibManager)
// - Match: vrfTag==vpnTag + eth_type=IPv4 + dst_ip Instr: Output DC-GW
//
LOG.info("L3VPN: Service Chaining programScfToVpnPipeline [Started]: Parameters Vpn Name: {} ", vpnName);
String rd = VpnServiceChainUtils.getVpnRd(dataBroker, vpnName);
if (rd == null || rd.isEmpty()) {
LOG.warn("programScfToVpnPipeline: Could not find Router-distinguisher for VPN {}. No further actions", vpnName);
return;
}
VpnInstanceOpDataEntry vpnInstance = getVpnInstance(rd);
LOG.debug("programScfToVpnPipeline: rd={}, lportTag={} ", rd, vpnPseudoLportTag);
// Find out the set of DPNs for the given VPN ID
if (vpnInstance != null) {
if (addOrRemove == NwConstants.ADD_FLOW || addOrRemove == NwConstants.DEL_FLOW && isLastServiceChain) {
Long vpnId = vpnInstance.getVpnId();
List<VpnToDpnList> vpnToDpnList = vpnInstance.getVpnToDpnList();
if (vpnToDpnList != null) {
List<BigInteger> dpns = new ArrayList<>();
for (VpnToDpnList dpnInVpn : vpnToDpnList) {
dpns.add(dpnInVpn.getDpnId());
}
if (!dpns.contains(BigInteger.valueOf(dpnId))) {
LOG.debug("Dpn {} is not included in the current VPN Footprint", dpnId);
dpns.add(BigInteger.valueOf(dpnId));
}
for (BigInteger dpn : dpns) {
VpnServiceChainUtils.programLPortDispatcherFlowForScfToVpn(mdsalManager, vpnId, dpn, vpnPseudoLportTag, addOrRemove);
}
} else {
LOG.debug("Could not find VpnToDpn list for VPN {} with rd {}", vpnName, rd);
}
}
// We need to keep a fake VpnInterface in the DPN where the last vSF (before the VpnPseudoPort) is
// located, because in case the last real VpnInterface is removed from that DPN, we still need
// the Fib table programmed there
String intfName = VpnServiceChainUtils.buildVpnPseudoPortIfName(dpnId, scfTag, servChainTag, vpnPseudoLportTag);
vpnFootprintService.updateVpnToDpnMapping(BigInteger.valueOf(dpnId), vpnName, rd, intfName, null, /*ipAddressSourceValuePair*/
addOrRemove == NwConstants.ADD_FLOW);
}
LOG.info("L3VPN: Service Chaining programScfToVpnPipeline [End]");
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class VrfEntryListener method cleanUpExternalRoutesOnDpn.
public void cleanUpExternalRoutesOnDpn(final Uint64 dpnId, final Uint32 vpnId, final String rd, final String localNextHopIp, final String remoteNextHopIp) {
LOG.trace("cleanUpExternalRoutesOnDpn : cleanup remote routes on dpn {} for vpn {}, rd {}, " + " localNexthopIp {} , remoteNexhtHopIp {}", dpnId, vpnId, rd, localNextHopIp, remoteNextHopIp);
InstanceIdentifier<VrfTables> id = buildVrfId(rd);
final VpnInstanceOpDataEntry vpnInstance = fibUtil.getVpnInstance(rd);
List<SubTransaction> txnObjects = new ArrayList<>();
final Optional<VrfTables> vrfTable;
try {
vrfTable = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
} catch (ExecutionException | InterruptedException e) {
LOG.error("getVrfEntry: Exception while reading VrfTable for the rd {} vpnId {}", rd, vpnId, e);
return;
}
if (vrfTable.isPresent()) {
jobCoordinator.enqueueJob(FibUtil.getJobKeyForVpnIdDpnId(vpnId, dpnId), () -> {
final ReentrantLock lock = lockFor(vpnInstance);
lock.lock();
try {
return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> vrfTable.get().nonnullVrfEntry().values().stream().filter(vrfEntry -> RouteOrigin.value(vrfEntry.getOrigin()) == RouteOrigin.BGP).forEach(bgpRouteVrfEntryHandler.getConsumerForDeletingRemoteFib(dpnId, vpnId, remoteNextHopIp, vrfTable, TransactionAdapter.toWriteTransaction(tx), txnObjects))));
} finally {
lock.unlock();
}
});
}
}
Aggregations