- /*
- * For a given route, it installs a flow in LFIB that sets the lportTag of the other endpoint and sends to
- * LportDispatcher table (via table 80)
- */
- private void installInterVpnRouteInLFib(final InterVpnLinkDataComposite interVpnLink, final String vpnName,
- final VrfEntry vrfEntry) {
- // INTERVPN routes are routes in a Vpn1 that have been leaked to Vpn2. In DC-GW, this Vpn2 route is pointing
- // to a list of DPNs where Vpn2's VpnLink was instantiated. In these DPNs LFIB must be programmed so that the
- // packet is commuted from Vpn2 to Vpn1.
- String interVpnLinkName = interVpnLink.getInterVpnLinkName();
- if (!interVpnLink.isActive()) {
- LOG.warn("InterVpnLink {} is NOT ACTIVE. InterVpnLink flows for prefix={} wont be installed in LFIB",
- interVpnLinkName, vrfEntry.getDestPrefix());
- return;
- }
-
- List<BigInteger> targetDpns = interVpnLink.getEndpointDpnsByVpnName(vpnName);
- Optional<Long> optLportTag = interVpnLink.getEndpointLportTagByVpnName(vpnName);
- if (!optLportTag.isPresent()) {
- LOG.warn("Could not retrieve lportTag for VPN {} endpoint in InterVpnLink {}", vpnName, interVpnLinkName);
- return;
- }
-
- Long lportTag = optLportTag.get();
- Long label = FibUtil.getLabelFromRoutePaths(vrfEntry).orElse(null);
- if (label == null) {
- LOG.error("Could not find label in vrfEntry=[prefix={} routePaths={}]. LFIB entry for InterVpnLink skipped",
- vrfEntry.getDestPrefix(), vrfEntry.getRoutePaths());
- return;
- }
- List<ActionInfo> actionsInfos = Collections.singletonList(new ActionPopMpls());
- List<InstructionInfo> instructions = Arrays.asList(
- new InstructionApplyActions(actionsInfos),
- new InstructionWriteMetadata(MetaDataUtil.getMetaDataForLPortDispatcher(lportTag.intValue(),
- ServiceIndex.getIndex(NwConstants.L3VPN_SERVICE_NAME,
- NwConstants.L3VPN_SERVICE_INDEX)),
- MetaDataUtil.getMetaDataMaskForLPortDispatcher()),
- new InstructionGotoTable(NwConstants.L3_INTERFACE_TABLE));
- List<String> interVpnNextHopList = FibHelper.getNextHopListFromRoutePaths(vrfEntry);
-
- for (BigInteger dpId : targetDpns) {
- LOG.debug("Installing flow: VrfEntry=[prefix={} label={} nexthop={}] dpn {} for InterVpnLink {} in LFIB",
- vrfEntry.getDestPrefix(), label, interVpnNextHopList, dpId, interVpnLink.getInterVpnLinkName());
-
- makeLFibTableEntry(dpId, label, instructions, LFIB_INTERVPN_PRIORITY, NwConstants.ADD_FLOW,
- /*writeTx*/null);
- }
- }
-
-
- /*
- * Installs the flows in FIB table that, for a given route, do the switching from one VPN to the other.
- */
- private void installIVpnLinkSwitchingFlows(final InterVpnLinkDataComposite interVpnLink, final String vpnUuid,
- final VrfEntry vrfEntry, long vpnTag) {
- Preconditions.checkNotNull(interVpnLink, "InterVpnLink cannot be null");
- Preconditions.checkArgument(vrfEntry.getRoutePaths() != null
- && vrfEntry.getRoutePaths().size() == 1);
- String destination = vrfEntry.getDestPrefix();
- String nextHop = vrfEntry.getRoutePaths().get(0).getNexthopAddress();
- String interVpnLinkName = interVpnLink.getInterVpnLinkName();
-
- // After having received a static route, we should check if the vpn is part of an inter-vpn-link.
- // In that case, we should populate the FIB table of the VPN pointing to LPortDisptacher table
- // using as metadata the LPortTag associated to that vpn in the inter-vpn-link.
- if (interVpnLink.getState().or(State.Error) != State.Active) {
- LOG.warn("Route to {} with nexthop={} cannot be installed because the interVpnLink {} is not active",
- destination, nextHop, interVpnLinkName);
- return;
- }
-
- Optional<Long> optOtherEndpointLportTag = interVpnLink.getOtherEndpointLportTagByVpnName(vpnUuid);
- if (!optOtherEndpointLportTag.isPresent()) {
- LOG.warn("Could not find suitable LportTag for the endpoint opposite to vpn {} in interVpnLink {}",
- vpnUuid, interVpnLinkName);
- return;
- }
-
- List<BigInteger> targetDpns = interVpnLink.getEndpointDpnsByVpnName(vpnUuid);
- if (targetDpns.isEmpty()) {
- LOG.warn("Could not find DPNs for endpoint opposite to vpn {} in interVpnLink {}",
- vpnUuid, interVpnLinkName);
- return;
- }
-
- String[] values = destination.split("/");
- String destPrefixIpAddress = values[0];
- int prefixLength = values.length == 1 ? 0 : Integer.parseInt(values[1]);
-
- List<MatchInfo> matches = new ArrayList<>();
- matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnTag), MetaDataUtil.METADATA_MASK_VRFID));
- matches.add(MatchEthernetType.IPV4);
-
- if (prefixLength != 0) {
- matches.add(new MatchIpv4Destination(destPrefixIpAddress, Integer.toString(prefixLength)));
- }
-
- List<Instruction> instructions =
- Arrays.asList(new InstructionWriteMetadata(
- MetaDataUtil.getMetaDataForLPortDispatcher(optOtherEndpointLportTag.get().intValue(),
- ServiceIndex.getIndex(NwConstants.L3VPN_SERVICE_NAME, NwConstants
- .L3VPN_SERVICE_INDEX)),
- MetaDataUtil.getMetaDataMaskForLPortDispatcher()).buildInstruction(0),
- new InstructionGotoTable(NwConstants.L3_INTERFACE_TABLE).buildInstruction(1));
-
- int priority = DEFAULT_FIB_FLOW_PRIORITY + prefixLength;
- String flowRef = getInterVpnFibFlowRef(interVpnLinkName, destination, nextHop);
- Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_FIB_TABLE, flowRef, priority, flowRef, 0, 0,
- COOKIE_VM_FIB_TABLE, matches, instructions);
-
- LOG.trace("Installing flow in FIB table for vpn {} interVpnLink {} nextHop {} key {}",
- vpnUuid, interVpnLink.getInterVpnLinkName(), nextHop, flowRef);
-
- for (BigInteger dpId : targetDpns) {
-
- LOG.debug("Installing flow: VrfEntry=[prefix={} route-paths={}] dpn {} for InterVpnLink {} in FIB",
- vrfEntry.getDestPrefix(), vrfEntry.getRoutePaths(),
- dpId, interVpnLink.getInterVpnLinkName());
-
- mdsalManager.installFlow(dpId, flowEntity);
- }
- }
-
- private List<BigInteger> createLocalFibEntry(Long vpnId, String rd, VrfEntry vrfEntry) {
- List<BigInteger> returnLocalDpnId = new ArrayList<>();