use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.statement.Actions in project netvirt by opendaylight.
the class ElanDmacUtils method buildDmacFlowForExternalRemoteMac.
/**
* Builds a Flow to be programmed in a DPN's DMAC table. This method must be
* used when the MAC is located in an External Device (TOR). The flow
* matches on the specified MAC and 1) sends the packet over the CSS-TOR
* tunnel if SHFlag is not set, or 2) drops it if SHFlag is set (what means
* the packet came from an external tunnel)
*
* @param dpId
* DPN whose DMAC table is going to be modified
* @param extDeviceNodeId
* Hwvtep node where the mac is attached to
* @param elanTag
* ElanId to which the MAC is being added to
* @param vni
* the vni
* @param dstMacAddress
* The mac address to be programmed
* @param displayName
* the display name
* @return the flow
*/
@SuppressWarnings("checkstyle:IllegalCatch")
public Flow buildDmacFlowForExternalRemoteMac(Uint64 dpId, String extDeviceNodeId, long elanTag, Long vni, String dstMacAddress, String displayName) {
List<MatchInfo> mkMatches = ElanUtils.buildMatchesForElanTagShFlagAndDstMac(elanTag, /* shFlag */
false, dstMacAddress);
Map<InstructionKey, Instruction> mkInstructionsMap = new HashMap<>();
try {
List<Action> actions = elanItmUtils.getExternalTunnelItmEgressAction(dpId, new NodeId(extDeviceNodeId), vni);
mkInstructionsMap.put(new InstructionKey(0), MDSALUtil.buildApplyActionsInstruction(actions));
} catch (Exception e) {
LOG.error("Could not get Egress Actions for DpId {} externalNode {}", dpId, extDeviceNodeId, e);
}
return MDSALUtil.buildFlowNew(NwConstants.ELAN_DMAC_TABLE, ElanUtils.getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpId, extDeviceNodeId, dstMacAddress, elanTag, false), 20, /* prio */
displayName, 0, /* idleTimeout */
0, /* hardTimeout */
Uint64.valueOf(ElanConstants.COOKIE_ELAN_KNOWN_DMAC.toJava().add(BigInteger.valueOf(elanTag))), mkMatches, mkInstructionsMap);
}
use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.statement.Actions in project netvirt by opendaylight.
the class VpnInterfaceManager method addVpnInterfaceToVpn.
private void addVpnInterfaceToVpn(final InstanceIdentifier<VpnInterfaceOpDataEntry> vpnInterfaceOpIdentifier, final VpnInterface vpnInterface, @Nullable final List<Adjacency> oldAdjs, @Nullable final List<Adjacency> newAdjs, final InstanceIdentifier<VpnInterface> identifier, String vpnName) {
final VpnInterfaceKey key = identifier.firstKeyOf(VpnInterface.class);
final String interfaceName = key.getName();
String primaryRd = vpnUtil.getPrimaryRd(vpnName);
if (!vpnUtil.isVpnPendingDelete(primaryRd)) {
Interface interfaceState = InterfaceUtils.getInterfaceStateFromOperDS(dataBroker, interfaceName);
boolean isBgpVpnInternetVpn = vpnUtil.isBgpVpnInternet(vpnName);
if (interfaceState != null) {
try {
final Uint64 dpnId = InterfaceUtils.getDpIdFromInterface(interfaceState);
final int ifIndex = interfaceState.getIfIndex();
jobCoordinator.enqueueJob("VPNINTERFACE-" + interfaceName, () -> {
// TODO Deal with sequencing — the config tx must only submitted if the oper tx goes in
// (the inventory tx goes in last)
List<ListenableFuture<?>> futures = new ArrayList<>();
// set of prefix used, as entry in prefix-to-interface datastore
// is prerequisite for refresh Fib to avoid race condition leading to
// missing remote next hop in bucket actions on bgp-vpn delete
Set<String> prefixListForRefreshFib = new HashSet<>();
ListenableFuture<?> confFuture = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, confTx -> futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, operTx -> futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, invTx -> {
LOG.info("addVpnInterface: VPN Interface add event - intfName {} vpnName {}" + " on dpn {}", vpnInterface.getName(), vpnName, vpnInterface.getDpnId());
processVpnInterfaceUp(dpnId, vpnInterface, primaryRd, ifIndex, false, confTx, operTx, invTx, interfaceState, vpnName, prefixListForRefreshFib);
if (oldAdjs != null && !oldAdjs.equals(newAdjs)) {
LOG.info("addVpnInterface: Adjacency changed upon VPNInterface {}" + " Update for swapping VPN {} case.", interfaceName, vpnName);
if (newAdjs != null) {
for (Adjacency adj : newAdjs) {
if (oldAdjs.contains(adj)) {
oldAdjs.remove(adj);
} else {
if (!isBgpVpnInternetVpn || vpnUtil.isAdjacencyEligibleToVpnInternet(adj)) {
addNewAdjToVpnInterface(vpnInterfaceOpIdentifier, primaryRd, adj, dpnId, operTx, confTx, invTx, prefixListForRefreshFib);
}
}
}
}
for (Adjacency adj : oldAdjs) {
if (!isBgpVpnInternetVpn || vpnUtil.isAdjacencyEligibleToVpnInternet(adj)) {
delAdjFromVpnInterface(vpnInterfaceOpIdentifier, adj, dpnId, operTx, confTx);
}
}
}
})))));
Futures.addCallback(confFuture, new VpnInterfaceCallBackHandler(primaryRd, prefixListForRefreshFib), MoreExecutors.directExecutor());
futures.add(confFuture);
Futures.addCallback(confFuture, new PostVpnInterfaceWorker(interfaceName, true, "Config"), MoreExecutors.directExecutor());
LOG.info("addVpnInterface: Addition of interface {} in VPN {} on dpn {}" + " processed successfully", interfaceName, vpnName, dpnId);
return futures;
});
} catch (NumberFormatException | IllegalStateException e) {
LOG.error("addVpnInterface: Unable to retrieve dpnId from interface operational data store for " + "interface {}. Interface addition on vpn {} failed", interfaceName, vpnName, e);
return;
}
} else if (Boolean.TRUE.equals(vpnInterface.isRouterInterface())) {
jobCoordinator.enqueueJob("VPNINTERFACE-" + vpnInterface.getName(), () -> {
ListenableFuture<?> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, confTx -> {
createFibEntryForRouterInterface(primaryRd, vpnInterface, interfaceName, confTx, vpnName);
LOG.info("addVpnInterface: Router interface {} for vpn {} on dpn {}", interfaceName, vpnName, vpnInterface.getDpnId());
});
LoggingFutures.addErrorLogging(future, LOG, "Error creating FIB entry for interface {} on VPN {}", vpnInterface.getName(), vpnName);
return Collections.singletonList(future);
});
} else {
LOG.info("addVpnInterface: Handling addition of VPN interface {} on vpn {} skipped as interfaceState" + " is not available", interfaceName, vpnName);
}
} else {
LOG.error("addVpnInterface: Handling addition of VPN interface {} on vpn {} dpn {} skipped" + " as vpn is pending delete", interfaceName, vpnName, vpnInterface.getDpnId());
}
}
use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.statement.Actions in project netvirt by opendaylight.
the class VpnInterfaceManager method updateVpnInstanceAdjChange.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private List<ListenableFuture<?>> updateVpnInstanceAdjChange(VpnInterface original, VpnInterface update, String vpnInterfaceName, List<ListenableFuture<?>> futures) {
final Adjacencies origAdjs = original.augmentation(Adjacencies.class);
final List<Adjacency> oldAdjs = origAdjs != null && origAdjs.getAdjacency() != null ? new ArrayList<>(origAdjs.getAdjacency().values()) : new ArrayList<>();
final Adjacencies updateAdjs = update.augmentation(Adjacencies.class);
final List<Adjacency> newAdjs = updateAdjs != null && updateAdjs.getAdjacency() != null ? new ArrayList<>(updateAdjs.getAdjacency().values()) : new ArrayList<>();
final Uint64 dpnId = InterfaceUtils.getDpnForInterface(ifaceMgrRpcService, vpnInterfaceName);
for (VpnInstanceNames vpnInterfaceVpnInstance : update.nonnullVpnInstanceNames().values()) {
String newVpnName = vpnInterfaceVpnInstance.getVpnName();
List<Adjacency> copyNewAdjs = new ArrayList<>(newAdjs);
List<Adjacency> copyOldAdjs = new ArrayList<>(oldAdjs);
String primaryRd = vpnUtil.getPrimaryRd(newVpnName);
if (!vpnUtil.isVpnPendingDelete(primaryRd)) {
// TODO Deal with sequencing — the config tx must only submitted if the oper tx goes in
// set of prefix used as entry in prefix-to-interface datastore
// is prerequisite for refresh Fib to avoid race condition leading to missing remote next hop
// in bucket actions on bgp-vpn delete
Set<String> prefixListForRefreshFib = new HashSet<>();
ListenableFuture<?> configTxFuture = txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, operTx -> {
InstanceIdentifier<VpnInterfaceOpDataEntry> vpnInterfaceOpIdentifier = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(vpnInterfaceName, newVpnName);
LOG.info("VPN Interface update event-intfName {} onto vpnName {} running config-driven", update.getName(), newVpnName);
// handle both addition and removal of adjacencies
// currently, new adjacency may be an extra route
boolean isBgpVpnInternetVpn = vpnUtil.isBgpVpnInternet(newVpnName);
if (!oldAdjs.equals(newAdjs)) {
for (Adjacency adj : copyNewAdjs) {
if (copyOldAdjs.contains(adj)) {
copyOldAdjs.remove(adj);
} else {
// add new adjacency
if (!isBgpVpnInternetVpn || vpnUtil.isAdjacencyEligibleToVpnInternet(adj)) {
try {
addNewAdjToVpnInterface(vpnInterfaceOpIdentifier, primaryRd, adj, dpnId, operTx, confTx, confTx, prefixListForRefreshFib);
} catch (RuntimeException e) {
LOG.error("Failed to add adjacency {} to vpn interface {} with" + " dpnId {}", adj, vpnInterfaceName, dpnId, e);
}
}
LOG.info("update: new Adjacency {} with nextHop {} label {} subnet {} " + " added to vpn interface {} on vpn {} dpnId {}", adj.getIpAddress(), adj.getNextHopIpList(), adj.getLabel(), adj.getSubnetId(), update.getName(), newVpnName, dpnId);
}
}
for (Adjacency adj : copyOldAdjs) {
if (!isBgpVpnInternetVpn || vpnUtil.isAdjacencyEligibleToVpnInternet(adj)) {
if (adj.getAdjacencyType() == AdjacencyType.PrimaryAdjacency && !adj.isPhysNetworkFunc()) {
delAdjFromVpnInterface(vpnInterfaceOpIdentifier, adj, dpnId, operTx, confTx);
// remove FIB entry
String vpnRd = vpnUtil.getVpnRd(newVpnName);
LOG.debug("update: remove prefix {} from the FIB and BGP entry " + "for the Vpn-Rd {} ", adj.getIpAddress(), vpnRd);
// remove BGP entry
fibManager.removeFibEntry(vpnRd, adj.getIpAddress(), null, confTx);
if (vpnRd != null && !vpnRd.equalsIgnoreCase(newVpnName)) {
bgpManager.withdrawPrefix(vpnRd, adj.getIpAddress());
}
} else {
delAdjFromVpnInterface(vpnInterfaceOpIdentifier, adj, dpnId, operTx, confTx);
}
}
LOG.info("update: Adjacency {} with nextHop {} label {} subnet {} removed from" + " vpn interface {} on vpn {}", adj.getIpAddress(), adj.getNextHopIpList(), adj.getLabel(), adj.getSubnetId(), update.getName(), newVpnName);
}
}
})));
Futures.addCallback(configTxFuture, new VpnInterfaceCallBackHandler(primaryRd, prefixListForRefreshFib), MoreExecutors.directExecutor());
futures.add(configTxFuture);
for (ListenableFuture<?> future : futures) {
LoggingFutures.addErrorLogging(future, LOG, "update: failed for interface {} on vpn {}", update.getName(), update.getVpnInstanceNames());
}
} else {
LOG.error("update: Ignoring update of vpnInterface {}, as newVpnInstance {} with primaryRd {}" + " is already marked for deletion", vpnInterfaceName, newVpnName, primaryRd);
}
}
return futures;
}
use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.statement.Actions in project netvirt by opendaylight.
the class InterfaceStateChangeListener method update.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public void update(InstanceIdentifier<Interface> identifier, Interface original, Interface update) {
final String ifName = update.getName();
try {
if (update.getIfIndex() == null) {
return;
}
if (L2vlan.class.equals(update.getType())) {
LOG.info("VPN Interface update event - intfName {} from InterfaceStateChangeListener", update.getName());
jobCoordinator.enqueueJob("VPNINTERFACE-" + ifName, () -> {
List<ListenableFuture<?>> futures = new ArrayList<>(3);
futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, writeOperTxn -> {
// map of prefix and vpn name used, as entry in prefix-to-interface datastore
// is prerequisite for refresh Fib to avoid race condition leading to missing remote
// next hop in bucket actions on bgp-vpn delete
Map<String, Set<String>> mapOfRdAndPrefixesForRefreshFib = new HashMap<>();
ListenableFuture<?> configTxFuture = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, writeConfigTxn -> futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, writeInvTxn -> {
final VpnInterface vpnIf = vpnUtil.getConfiguredVpnInterface(ifName);
if (vpnIf != null) {
final int ifIndex = update.getIfIndex();
Uint64 dpnId;
try {
dpnId = InterfaceUtils.getDpIdFromInterface(update);
} catch (Exception e) {
LOG.error("remove: Unable to retrieve dpnId for interface {}", ifName, e);
return;
}
IntfTransitionState state = getTransitionState(original.getOperStatus(), update.getOperStatus());
if (state.equals(IntfTransitionState.STATE_IGNORE)) {
LOG.info("InterfaceStateChangeListener: Interface {} state " + "original {}" + "updated {} not handled", ifName, original.getOperStatus(), update.getOperStatus());
return;
}
LOG.error("InterfaceStateChangeListener- Processing ifState {} " + "update event " + "with dpnId {} operstate {}", ifName, dpnId, update.getOperStatus());
if (state.equals(IntfTransitionState.STATE_UP) && vpnIf.getVpnInstanceNames() != null) {
for (VpnInstanceNames vpnInterfaceVpnInstance : vpnIf.getVpnInstanceNames().values()) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
String primaryRd = vpnUtil.getPrimaryRd(vpnName);
Set<String> prefixes = new HashSet<>();
if (!vpnInterfaceManager.isVpnInstanceReady(vpnName)) {
LOG.error("VPN Interface update event - intfName {} " + "onto vpnName {} running oper-driven UP, " + "VpnInstance not ready, holding on", vpnIf.getName(), vpnName);
} else if (vpnUtil.isVpnPendingDelete(primaryRd)) {
LOG.error("update: Ignoring UP event for vpnInterface " + "{}, as vpnInstance {} with primaryRd {} is " + "already marked for deletion ", vpnIf.getName(), vpnName, primaryRd);
} else {
vpnInterfaceManager.processVpnInterfaceUp(dpnId, vpnIf, primaryRd, ifIndex, true, writeConfigTxn, writeOperTxn, writeInvTxn, update, vpnName, prefixes);
mapOfRdAndPrefixesForRefreshFib.put(primaryRd, prefixes);
}
}
} else if (state.equals(IntfTransitionState.STATE_DOWN) && vpnIf.getVpnInstanceNames() != null) {
for (VpnInstanceNames vpnInterfaceVpnInstance : vpnIf.getVpnInstanceNames().values()) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
LOG.info("VPN Interface update event - intfName {} " + " onto vpnName {} running oper-driven DOWN", vpnIf.getName(), vpnName);
Optional<VpnInterfaceOpDataEntry> optVpnInterface = vpnUtil.getVpnInterfaceOpDataEntry(vpnIf.getName(), vpnName);
if (optVpnInterface.isPresent()) {
VpnInterfaceOpDataEntry vpnOpInterface = optVpnInterface.get();
vpnInterfaceManager.processVpnInterfaceDown(dpnId, vpnIf.getName(), ifIndex, update.getPhysAddress().getValue(), vpnOpInterface, true, writeConfigTxn, writeOperTxn, writeInvTxn);
} else {
LOG.error("InterfaceStateChangeListener Update DOWN - " + " vpnInterface {}not available, ignoring event", vpnIf.getName());
continue;
}
}
}
} else {
LOG.debug("Interface {} is not a vpninterface, ignoring.", ifName);
}
})));
Futures.addCallback(configTxFuture, new VpnInterfaceCallBackHandler(mapOfRdAndPrefixesForRefreshFib), MoreExecutors.directExecutor());
futures.add(configTxFuture);
}));
return futures;
});
}
} catch (Exception e) {
LOG.error("Exception observed in handling updation of VPN Interface {}. ", update.getName(), e);
}
}
use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.statement.Actions in project netvirt by opendaylight.
the class VPNServiceChainHandler method programVpnToScfPipeline.
/**
* Programs the necessary flows in LFIB and LPortDispatcher table so that
* the packets coming from a given VPN are delivered to a given
* ServiceChain Pipeline.
*
* @param vpnName Name of the VPN. Typically the UUID
* @param tableId Table to which the LPortDispatcher table sends the packet
* to (Uplink or Downlink Subsc table)
* @param scfTag Scf tag to the SCF to which the Vpn is linked to.
* @param lportTag VpnPseudo Port lportTag
* @param addOrRemove States if the VPN2SCF Pipeline must be installed or
* removed
*/
public void programVpnToScfPipeline(String vpnName, short tableId, long scfTag, int lportTag, int addOrRemove) {
// This entries must be created in the DPN where the CGNAT is installed. Since it is not possible
// to know where CGNAT is located, this entries are installed in all the VPN footprint.
// LFIB:
// - Match: cgnatLabel Instr: lportTag=vpnPseudoPortTag + SI=SCF + GOTO 17
// LportDisp:
// - Match: vpnPseudoPortTag + SI==SCF Instr: scfTag + GOTO 70
LOG.info("programVpnToScfPipeline ({}) : Parameters VpnName:{} tableId:{} scftag:{} lportTag:{}", addOrRemove == NwConstants.ADD_FLOW ? "Creation" : "Removal", vpnName, tableId, scfTag, lportTag);
String rd = VpnServiceChainUtils.getVpnRd(dataBroker, vpnName);
LOG.debug("Router distinguisher (rd):{}", rd);
if (rd == null || rd.isEmpty()) {
LOG.warn("programVpnToScfPipeline: Could not find Router-distinguisher for VPN {}. No further actions", vpnName);
return;
}
VpnInstanceOpDataEntry vpnInstance = getVpnInstance(rd);
if (vpnInstance == null) {
LOG.warn("Could not find a suitable VpnInstance for Route-Distinguisher={}", rd);
return;
}
// Find out the set of DPNs for the given VPN ID
Collection<VpnToDpnList> vpnToDpnList = vpnInstance.getVpnToDpnList();
List<VrfEntry> vrfEntries = VpnServiceChainUtils.getAllVrfEntries(dataBroker, rd);
if (vrfEntries != null) {
if (addOrRemove == NwConstants.ADD_FLOW) {
AddVpnPseudoPortDataJob updateVpnToPseudoPortTask = new AddVpnPseudoPortDataJob(dataBroker, rd, lportTag, tableId, (int) scfTag);
jobCoordinator.enqueueJob(updateVpnToPseudoPortTask.getDsJobCoordinatorKey(), updateVpnToPseudoPortTask);
} else {
RemoveVpnPseudoPortDataJob removeVpnPseudoPortDataTask = new RemoveVpnPseudoPortDataJob(dataBroker, rd);
jobCoordinator.enqueueJob(removeVpnPseudoPortDataTask.getDsJobCoordinatorKey(), removeVpnPseudoPortDataTask);
}
for (VpnToDpnList dpnInVpn : vpnToDpnList) {
BigInteger dpnId = dpnInVpn.getDpnId();
programVpnToScfPipelineOnDpn(dpnId, vrfEntries, tableId, (int) scfTag, lportTag, addOrRemove);
if (dpnInVpn.getVpnInterfaces() != null) {
long vpnId = vpnInstance.getVpnId();
Flow flow = VpnServiceChainUtils.buildLPortDispFromScfToL3VpnFlow(vpnId, dpnId, lportTag, NwConstants.ADD_FLOW);
if (addOrRemove == NwConstants.ADD_FLOW) {
mdsalManager.installFlow(dpnId, flow);
} else {
mdsalManager.removeFlow(dpnId, flow);
}
dpnInVpn.getVpnInterfaces().forEach(vpnIf -> {
if (addOrRemove == NwConstants.ADD_FLOW) {
bindScfOnVpnInterface(vpnIf.getInterfaceName(), (int) scfTag);
} else {
unbindScfOnVpnInterface(vpnIf.getInterfaceName());
}
});
}
}
}
}
Aggregations