Search in sources :

Example 16 with InstructionWriteMetadata

use of org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata in project netvirt by opendaylight.

the class ExternalRoutersListener method buildOutboundFlowEntityWithBgpVpn.

protected FlowEntity buildOutboundFlowEntityWithBgpVpn(BigInteger dpId, long routerId, long changedVpnId) {
    LOG.debug("buildOutboundFlowEntityWithBgpVpn : called for dpId {} and routerId {}, BGP VPN ID {}", dpId, routerId, changedVpnId);
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(MatchEthernetType.IPV4);
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(changedVpnId), MetaDataUtil.METADATA_MASK_VRFID));
    List<InstructionInfo> instructions = new ArrayList<>();
    List<ActionInfo> actionsInfos = new ArrayList<>();
    actionsInfos.add(new ActionPuntToController());
    instructions.add(new InstructionApplyActions(actionsInfos));
    instructions.add(new InstructionWriteMetadata(MetaDataUtil.getVpnIdMetadata(changedVpnId), MetaDataUtil.METADATA_MASK_VRFID));
    String flowRef = getFlowRefOutbound(dpId, NwConstants.OUTBOUND_NAPT_TABLE, routerId);
    BigInteger cookie = getCookieOutboundFlow(routerId);
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.OUTBOUND_NAPT_TABLE, flowRef, 5, flowRef, 0, 0, cookie, matches, instructions);
    LOG.debug("createOutboundTblEntryWithBgpVpn : returning flowEntity {}", flowEntity);
    return flowEntity;
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) ActionPuntToController(org.opendaylight.genius.mdsalutil.actions.ActionPuntToController) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) InstructionWriteMetadata(org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata) BigInteger(java.math.BigInteger) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)

Example 17 with InstructionWriteMetadata

use of org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata in project netvirt by opendaylight.

the class VrfEntryListener method installIVpnLinkSwitchingFlows.

/*
     * 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();
    // 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);
    }
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) BigInteger(java.math.BigInteger) InstructionWriteMetadata(org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata)

Example 18 with InstructionWriteMetadata

use of org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata in project netvirt by opendaylight.

the class VrfEntryListener method installInterVpnRouteInLFib.

/*
     * 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);
    }
}
Also used : InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) ActionPopMpls(org.opendaylight.genius.mdsalutil.actions.ActionPopMpls) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) BigInteger(java.math.BigInteger) InstructionWriteMetadata(org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)

Example 19 with InstructionWriteMetadata

use of org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata in project netvirt by opendaylight.

the class VrfEntryListener method installSubnetRouteInFib.

void installSubnetRouteInFib(final BigInteger dpnId, final long elanTag, final String rd, final long vpnId, final VrfEntry vrfEntry, WriteTransaction tx) {
    Boolean wrTxPresent = true;
    if (tx == null) {
        wrTxPresent = false;
        tx = dataBroker.newWriteOnlyTransaction();
    }
    FibUtil.getLabelFromRoutePaths(vrfEntry).ifPresent(label -> {
        List<String> nextHopAddressList = FibHelper.getNextHopListFromRoutePaths(vrfEntry);
        synchronized (label.toString().intern()) {
            LabelRouteInfo lri = getLabelRouteInfo(label);
            if (isPrefixAndNextHopPresentInLri(vrfEntry.getDestPrefix(), nextHopAddressList, lri)) {
                if (RouteOrigin.value(vrfEntry.getOrigin()) == RouteOrigin.SELF_IMPORTED) {
                    Optional<VpnInstanceOpDataEntry> vpnInstanceOpDataEntryOptional = fibUtil.getVpnInstanceOpData(rd);
                    if (vpnInstanceOpDataEntryOptional.isPresent()) {
                        String vpnInstanceName = vpnInstanceOpDataEntryOptional.get().getVpnInstanceName();
                        if (!lri.getVpnInstanceList().contains(vpnInstanceName)) {
                            updateVpnReferencesInLri(lri, vpnInstanceName, false);
                        }
                    }
                }
                LOG.debug("SUBNETROUTE: installSubnetRouteInFib: Fetched labelRouteInfo for label {} interface {}" + " and got dpn {}", label, lri.getVpnInterfaceName(), lri.getDpnId());
            }
        }
    });
    final List<InstructionInfo> instructions = new ArrayList<>();
    BigInteger subnetRouteMeta = BigInteger.valueOf(elanTag).shiftLeft(24).or(BigInteger.valueOf(vpnId).shiftLeft(1));
    instructions.add(new InstructionWriteMetadata(subnetRouteMeta, MetaDataUtil.METADATA_MASK_SUBNET_ROUTE));
    instructions.add(new InstructionGotoTable(NwConstants.L3_SUBNET_ROUTE_TABLE));
    baseVrfEntryHandler.makeConnectedRoute(dpnId, vpnId, vrfEntry, rd, instructions, NwConstants.ADD_FLOW, tx, null);
    if (vrfEntry.getRoutePaths() != null) {
        for (RoutePaths routePath : vrfEntry.getRoutePaths()) {
            if (RouteOrigin.value(vrfEntry.getOrigin()) != RouteOrigin.SELF_IMPORTED) {
                List<ActionInfo> actionsInfos = new ArrayList<>();
                // reinitialize instructions list for LFIB Table
                final List<InstructionInfo> LFIBinstructions = new ArrayList<>();
                actionsInfos.add(new ActionPopMpls());
                LFIBinstructions.add(new InstructionApplyActions(actionsInfos));
                LFIBinstructions.add(new InstructionWriteMetadata(subnetRouteMeta, MetaDataUtil.METADATA_MASK_SUBNET_ROUTE));
                LFIBinstructions.add(new InstructionGotoTable(NwConstants.L3_SUBNET_ROUTE_TABLE));
                makeLFibTableEntry(dpnId, routePath.getLabel(), LFIBinstructions, DEFAULT_FIB_FLOW_PRIORITY, NwConstants.ADD_FLOW, tx);
            }
        }
    }
    if (!wrTxPresent) {
        tx.submit();
    }
}
Also used : LabelRouteInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.label.route.map.LabelRouteInfo) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) ActionPopMpls(org.opendaylight.genius.mdsalutil.actions.ActionPopMpls) RoutePaths(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePaths) BigInteger(java.math.BigInteger) InstructionWriteMetadata(org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)

Aggregations

InstructionWriteMetadata (org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata)19 ArrayList (java.util.ArrayList)18 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)16 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)15 BigInteger (java.math.BigInteger)9 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)9 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)8 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)8 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)6 MatchMetadata (org.opendaylight.genius.mdsalutil.matches.MatchMetadata)5 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)4 ActionPopMpls (org.opendaylight.genius.mdsalutil.actions.ActionPopMpls)3 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ActionPuntToController (org.opendaylight.genius.mdsalutil.actions.ActionPuntToController)2 ActionSetDestinationIp (org.opendaylight.genius.mdsalutil.actions.ActionSetDestinationIp)2 ActionSetSourceIp (org.opendaylight.genius.mdsalutil.actions.ActionSetSourceIp)2 MatchEthernetDestination (org.opendaylight.genius.mdsalutil.matches.MatchEthernetDestination)2 MatchIpv4Destination (org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination)2 MatchTunnelId (org.opendaylight.genius.mdsalutil.matches.MatchTunnelId)2