Search in sources :

Example 36 with ActionInfo

use of org.opendaylight.genius.mdsalutil.ActionInfo in project netvirt by opendaylight.

the class NexthopManager method createLocalNextHop.

public long createLocalNextHop(long vpnId, BigInteger dpnId, String ifName, String ipNextHopAddress, String ipPrefixAddress, String gwMacAddress, String jobKey) {
    String vpnName = fibUtil.getVpnNameFromId(vpnId);
    if (vpnName == null) {
        return 0;
    }
    String macAddress = fibUtil.getMacAddressFromPrefix(ifName, vpnName, ipPrefixAddress);
    String ipAddress = macAddress != null ? ipPrefixAddress : ipNextHopAddress;
    long groupId = createNextHopPointer(getNextHopKey(vpnId, ipAddress));
    if (groupId == 0) {
        LOG.error("Unable to allocate groupId for vpnId {} , prefix {}  IntfName {}, nextHopAddr {}", vpnId, ipAddress, ifName, ipNextHopAddress);
        return groupId;
    }
    String nextHopLockStr = vpnId + ipAddress;
    jobCoordinator.enqueueJob(jobKey, () -> {
        synchronized (nextHopLockStr.intern()) {
            VpnNexthop nexthop = getVpnNexthop(vpnId, ipAddress);
            LOG.trace("nexthop: {} retrieved for vpnId {}, prefix {}, ifName {} on dpn {}", nexthop, vpnId, ipAddress, ifName, dpnId);
            if (nexthop == null) {
                String encMacAddress = macAddress == null ? fibUtil.getMacAddressFromPrefix(ifName, vpnName, ipAddress) : macAddress;
                List<BucketInfo> listBucketInfo = new ArrayList<>();
                List<ActionInfo> listActionInfo = new ArrayList<>();
                int actionKey = 0;
                // MAC re-write
                if (encMacAddress != null) {
                    if (gwMacAddress != null) {
                        LOG.trace("The Local NextHop Group Source Mac {} for VpnInterface {} on VPN {}", gwMacAddress, ifName, vpnId);
                        listActionInfo.add(new ActionSetFieldEthernetSource(actionKey++, new MacAddress(gwMacAddress)));
                    }
                    listActionInfo.add(new ActionSetFieldEthernetDestination(actionKey++, new MacAddress(encMacAddress)));
                // listActionInfo.add(0, new ActionPopMpls());
                } else {
                    // FIXME: Log message here.
                    LOG.debug("mac address for new local nexthop is null");
                }
                listActionInfo.addAll(getEgressActionsForInterface(ifName, actionKey));
                BucketInfo bucket = new BucketInfo(listActionInfo);
                listBucketInfo.add(bucket);
                GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, ipAddress, GroupTypes.GroupAll, listBucketInfo);
                LOG.trace("Install LNH Group: id {}, mac address {}, interface {} for prefix {}", groupId, encMacAddress, ifName, ipAddress);
                // Try to install group directly on the DPN bypassing the FRM, in order to avoid waiting for the
                // group to get installed before programming the flows
                installGroupOnDpn(groupId, dpnId, ipAddress, listBucketInfo, getNextHopKey(vpnId, ipAddress), GroupTypes.GroupAll);
                // install Group
                mdsalApiManager.syncInstallGroup(groupEntity);
                // update MD-SAL DS
                addVpnNexthopToDS(dpnId, vpnId, ipAddress, groupId);
            } else {
                // nexthop exists already; a new flow is going to point to
                // it, increment the flowrefCount by 1
                int flowrefCnt = nexthop.getFlowrefCount() + 1;
                VpnNexthop nh = new VpnNexthopBuilder().setKey(new VpnNexthopKey(ipAddress)).setFlowrefCount(flowrefCnt).build();
                LOG.trace("Updating vpnnextHop {} for refCount {} to Operational DS", nh, flowrefCnt);
                MDSALUtil.syncUpdate(dataBroker, LogicalDatastoreType.OPERATIONAL, getVpnNextHopIdentifier(vpnId, ipAddress), nh);
            }
        }
        return Collections.emptyList();
    });
    return groupId;
}
Also used : CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) VpnNexthop(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthop) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) VpnNexthopBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthopBuilder) ActionSetFieldEthernetDestination(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetDestination) ActionSetFieldEthernetSource(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetSource) VpnNexthopKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthopKey) GroupEntity(org.opendaylight.genius.mdsalutil.GroupEntity) BucketInfo(org.opendaylight.genius.mdsalutil.BucketInfo)

Example 37 with ActionInfo

use of org.opendaylight.genius.mdsalutil.ActionInfo in project netvirt by opendaylight.

the class VrfEntryListener method installSubnetBroadcastAddrDropRule.

private void installSubnetBroadcastAddrDropRule(final BigInteger dpnId, final String rd, final long vpnId, final VrfEntry vrfEntry, int addOrRemove, WriteTransaction tx) {
    List<MatchInfo> matches = new ArrayList<>();
    LOG.debug("SUBNETROUTE: installSubnetBroadcastAddrDropRule: destPrefix {} rd {} vpnId {} dpnId {}", vrfEntry.getDestPrefix(), rd, vpnId, dpnId);
    String[] ipAddress = vrfEntry.getDestPrefix().split("/");
    String subnetBroadcastAddr = FibUtil.getBroadcastAddressFromCidr(vrfEntry.getDestPrefix());
    final int prefixLength = ipAddress.length == 1 ? 0 : Integer.parseInt(ipAddress[1]);
    InetAddress destPrefix;
    try {
        destPrefix = InetAddress.getByName(subnetBroadcastAddr);
    } catch (UnknownHostException e) {
        LOG.error("Failed to get destPrefix for prefix {} rd {} VpnId {} DPN {}", vrfEntry.getDestPrefix(), rd, vpnId, dpnId, e);
        return;
    }
    // Match on VpnId and SubnetBroadCast IP address
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
    matches.add(MatchEthernetType.IPV4);
    if (prefixLength != 0) {
        matches.add(new MatchIpv4Destination(subnetBroadcastAddr, Integer.toString(IPV4_ADDR_PREFIX_LENGTH)));
    }
    // Action is to drop the packet
    List<InstructionInfo> dropInstructions = new ArrayList<>();
    List<ActionInfo> actionsInfos = new ArrayList<>();
    actionsInfos.add(new ActionDrop());
    dropInstructions.add(new InstructionApplyActions(actionsInfos));
    int priority = DEFAULT_FIB_FLOW_PRIORITY + IPV4_ADDR_PREFIX_LENGTH;
    String flowRef = FibUtil.getFlowRef(dpnId, NwConstants.L3_SUBNET_ROUTE_TABLE, rd, priority, destPrefix);
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpnId, NwConstants.L3_SUBNET_ROUTE_TABLE, flowRef, priority, flowRef, 0, 0, COOKIE_TABLE_MISS, matches, dropInstructions);
    Flow flow = flowEntity.getFlowBuilder().build();
    String flowId = flowEntity.getFlowId();
    FlowKey flowKey = new FlowKey(new FlowId(flowId));
    Node nodeDpn = FibUtil.buildDpnNode(dpnId);
    InstanceIdentifier<Flow> flowInstanceId = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class).child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flowKey).build();
    if (addOrRemove == NwConstants.ADD_FLOW) {
        tx.put(LogicalDatastoreType.CONFIGURATION, flowInstanceId, flow, true);
    } else {
        tx.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId);
    }
}
Also used : FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) ActionDrop(org.opendaylight.genius.mdsalutil.actions.ActionDrop) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) UnknownHostException(java.net.UnknownHostException) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) InetAddress(java.net.InetAddress)

Example 38 with ActionInfo

use of org.opendaylight.genius.mdsalutil.ActionInfo in project netvirt by opendaylight.

the class VrfEntryListener method createRemoteFibEntry.

private void createRemoteFibEntry(final BigInteger remoteDpnId, final long vpnId, String rd, final VrfEntry vrfEntry, WriteTransaction tx) {
    Boolean wrTxPresent = true;
    if (tx == null) {
        wrTxPresent = false;
        tx = dataBroker.newWriteOnlyTransaction();
    }
    String vpnName = fibUtil.getVpnNameFromId(vpnId);
    LOG.debug("createremotefibentry: adding route {} for rd {} on remoteDpnId {}", vrfEntry.getDestPrefix(), rd, remoteDpnId);
    List<AdjacencyResult> adjacencyResults = baseVrfEntryHandler.resolveAdjacency(remoteDpnId, vpnId, vrfEntry, rd);
    if (adjacencyResults.isEmpty()) {
        LOG.error("Could not get interface for route-paths: {} in vpn {} on DPN {}", vrfEntry.getRoutePaths(), rd, remoteDpnId);
        LOG.error("Failed to add Route: {} in vpn: {}", vrfEntry.getDestPrefix(), rd);
        return;
    }
    List<String> usedRds = VpnExtraRouteHelper.getUsedRds(dataBroker, vpnId, vrfEntry.getDestPrefix());
    List<Routes> vpnExtraRoutes = VpnExtraRouteHelper.getAllVpnExtraRoutes(dataBroker, vpnName, usedRds, vrfEntry.getDestPrefix());
    // multiple VMs
    if (!vpnExtraRoutes.isEmpty() && (vpnExtraRoutes.size() > 1 || vpnExtraRoutes.get(0).getNexthopIpList().size() > 1)) {
        List<InstructionInfo> instructions = new ArrayList<>();
        // Obtain the local routes for this particular dpn.
        java.util.Optional<Routes> routes = vpnExtraRoutes.stream().filter(route -> {
            Prefixes prefixToInterface = fibUtil.getPrefixToInterface(vpnId, fibUtil.getIpPrefix(route.getNexthopIpList().get(0)));
            if (prefixToInterface == null) {
                return false;
            }
            return remoteDpnId.equals(prefixToInterface.getDpnId());
        }).findFirst();
        long groupId = nextHopManager.createNextHopGroups(vpnId, rd, remoteDpnId, vrfEntry, routes.isPresent() ? routes.get() : null, vpnExtraRoutes);
        if (groupId == FibConstants.INVALID_GROUP_ID) {
            LOG.error("Unable to create Group for local prefix {} on rd {} on Node {}", vrfEntry.getDestPrefix(), rd, remoteDpnId.toString());
            return;
        }
        List<ActionInfo> actionInfos = Collections.singletonList(new ActionGroup(groupId));
        instructions.add(new InstructionApplyActions(actionInfos));
        baseVrfEntryHandler.makeConnectedRoute(remoteDpnId, vpnId, vrfEntry, rd, instructions, NwConstants.ADD_FLOW, tx, null);
    } else {
        baseVrfEntryHandler.programRemoteFib(remoteDpnId, vpnId, vrfEntry, tx, rd, adjacencyResults, null);
    }
    if (!wrTxPresent) {
        tx.submit();
    }
    LOG.debug("Successfully added FIB entry for prefix {} in vpnId {}", vrfEntry.getDestPrefix(), vpnId);
}
Also used : Arrays(java.util.Arrays) Table(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table) AdjacencyResult(org.opendaylight.netvirt.fibmanager.NexthopManager.AdjacencyResult) FibEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.FibEntries) ActionDrop(org.opendaylight.genius.mdsalutil.actions.ActionDrop) LoggerFactory(org.slf4j.LoggerFactory) CheckedFuture(com.google.common.util.concurrent.CheckedFuture) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry) InetAddress(java.net.InetAddress) ServiceIndex(org.opendaylight.genius.utils.ServiceIndex) InterVpnLinkCache(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkCache) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) Optional(com.google.common.base.Optional) BigInteger(java.math.BigInteger) LabelRouteInfoBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.label.route.map.LabelRouteInfoBuilder) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) LabelRouteInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.label.route.map.LabelRouteInfo) Collection(java.util.Collection) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) PrefixesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.PrefixesBuilder) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) SubTransaction(org.opendaylight.genius.utils.batching.SubTransaction) List(java.util.List) RoutePaths(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePaths) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) State(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkState.State) PostConstruct(javax.annotation.PostConstruct) SubnetRoute(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.SubnetRoute) AdjacenciesOp(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp) NWUtil.isIpv4Address(org.opendaylight.genius.mdsalutil.NWUtil.isIpv4Address) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) LabelRouteMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.LabelRouteMap) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Callable(java.util.concurrent.Callable) IElanService(org.opendaylight.netvirt.elanmanager.api.IElanService) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) Singleton(javax.inject.Singleton) InstructionWriteMetadata(org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) InstanceIdentifierBuilder(org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder) MatchTunnelId(org.opendaylight.genius.mdsalutil.matches.MatchTunnelId) LabelRouteInfoKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.label.route.map.LabelRouteInfoKey) InterVpnLinkDataComposite(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite) ManagedNewTransactionRunnerImpl(org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) MatchEthernetType(org.opendaylight.genius.mdsalutil.matches.MatchEthernetType) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) ActionPopMpls(org.opendaylight.genius.mdsalutil.actions.ActionPopMpls) VpnExtraRouteHelper(org.opendaylight.netvirt.vpnmanager.api.VpnExtraRouteHelper) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) RouterInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.RouterInterface) ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) Logger(org.slf4j.Logger) VrfTablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey) RouteOrigin(org.opendaylight.netvirt.fibmanager.api.RouteOrigin) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) VrfTables(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables) AsyncDataTreeChangeListenerBase(org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase) RetryingManagedNewTransactionRunner(org.opendaylight.genius.infra.RetryingManagedNewTransactionRunner) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) UnknownHostException(java.net.UnknownHostException) FutureCallback(com.google.common.util.concurrent.FutureCallback) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) Prefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes) VpnToDpnList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) IMdsalApiManager(org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager) MatchMplsLabel(org.opendaylight.genius.mdsalutil.matches.MatchMplsLabel) Preconditions(com.google.common.base.Preconditions) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) VrfEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntryKey) Collections(java.util.Collections) MetaDataUtil(org.opendaylight.genius.mdsalutil.MetaDataUtil) FibHelper(org.opendaylight.netvirt.fibmanager.api.FibHelper) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) Prefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes) AdjacencyResult(org.opendaylight.netvirt.fibmanager.NexthopManager.AdjacencyResult) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)

Example 39 with ActionInfo

use of org.opendaylight.genius.mdsalutil.ActionInfo in project netvirt by opendaylight.

the class BaseVrfEntryHandler method installPingResponderFlowEntry.

public void installPingResponderFlowEntry(BigInteger dpnId, long vpnId, String routerInternalIp, MacAddress routerMac, long label, int addOrRemove) {
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(MatchIpProtocol.ICMP);
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
    matches.add(new MatchIcmpv4((short) 8, (short) 0));
    matches.add(MatchEthernetType.IPV4);
    matches.add(new MatchIpv4Destination(routerInternalIp, "32"));
    List<ActionInfo> actionsInfos = new ArrayList<>();
    // Set Eth Src and Eth Dst
    actionsInfos.add(new ActionMoveSourceDestinationEth());
    actionsInfos.add(new ActionSetFieldEthernetSource(routerMac));
    // Move Ip Src to Ip Dst
    actionsInfos.add(new ActionMoveSourceDestinationIp());
    actionsInfos.add(new ActionSetSourceIp(routerInternalIp, "32"));
    // Set the ICMP type to 0 (echo reply)
    actionsInfos.add(new ActionSetIcmpType((short) 0));
    actionsInfos.add(new ActionNxLoadInPort(BigInteger.ZERO));
    actionsInfos.add(new ActionNxResubmit(NwConstants.L3_FIB_TABLE));
    List<InstructionInfo> instructions = new ArrayList<>();
    instructions.add(new InstructionApplyActions(actionsInfos));
    int priority = FibConstants.DEFAULT_FIB_FLOW_PRIORITY + FibConstants.DEFAULT_PREFIX_LENGTH;
    String flowRef = FibUtil.getFlowRef(dpnId, NwConstants.L3_FIB_TABLE, label, priority);
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpnId, NwConstants.L3_FIB_TABLE, flowRef, priority, flowRef, 0, 0, NwConstants.COOKIE_VM_FIB_TABLE, matches, instructions);
    if (addOrRemove == NwConstants.ADD_FLOW) {
        mdsalManager.syncInstallFlow(flowEntity);
    } else {
        mdsalManager.syncRemoveFlow(flowEntity);
    }
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) ActionMoveSourceDestinationIp(org.opendaylight.genius.mdsalutil.actions.ActionMoveSourceDestinationIp) ActionSetIcmpType(org.opendaylight.genius.mdsalutil.actions.ActionSetIcmpType) ArrayList(java.util.ArrayList) ActionSetSourceIp(org.opendaylight.genius.mdsalutil.actions.ActionSetSourceIp) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) ActionNxLoadInPort(org.opendaylight.genius.mdsalutil.actions.ActionNxLoadInPort) ActionSetFieldEthernetSource(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetSource) MatchIcmpv4(org.opendaylight.genius.mdsalutil.matches.MatchIcmpv4) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) ActionMoveSourceDestinationEth(org.opendaylight.genius.mdsalutil.actions.ActionMoveSourceDestinationEth) ActionNxResubmit(org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)

Example 40 with ActionInfo

use of org.opendaylight.genius.mdsalutil.ActionInfo in project netvirt by opendaylight.

the class BgpRouteVrfEntryHandler method programRemoteFibForBgpRoutes.

public void programRemoteFibForBgpRoutes(final BigInteger remoteDpnId, final long vpnId, final VrfEntry vrfEntry, WriteTransaction tx, String rd, List<NexthopManager.AdjacencyResult> adjacencyResults, List<SubTransaction> subTxns) {
    Preconditions.checkArgument(vrfEntry.getRoutePaths().size() <= 2);
    if (adjacencyResults.size() == 1) {
        programRemoteFib(remoteDpnId, vpnId, vrfEntry, tx, rd, adjacencyResults, subTxns);
        return;
    }
    // ECMP Use case, point to LB group. Move the mpls label accordingly.
    List<String> tunnelList = adjacencyResults.stream().map(adjacencyResult -> adjacencyResult.getNextHopIp()).sorted().collect(toList());
    String lbGroupKey = FibUtil.getGreLbGroupKey(tunnelList);
    long groupId = nexthopManager.createNextHopPointer(lbGroupKey);
    int index = 0;
    List<ActionInfo> actionInfos = new ArrayList<>();
    for (NexthopManager.AdjacencyResult adjResult : adjacencyResults) {
        String nextHopIp = adjResult.getNextHopIp();
        java.util.Optional<Long> optionalLabel = FibUtil.getLabelForNextHop(vrfEntry, nextHopIp);
        if (!optionalLabel.isPresent()) {
            LOG.warn("NextHopIp {} not found in vrfEntry {}", nextHopIp, vrfEntry);
            continue;
        }
        long label = optionalLabel.get();
        actionInfos.add(new ActionRegLoad(index, FibConstants.NXM_REG_MAPPING.get(index++), 0, 31, label));
    }
    List<InstructionInfo> instructions = new ArrayList<>();
    actionInfos.add(new ActionGroup(index, groupId));
    instructions.add(new InstructionApplyActions(actionInfos));
    makeConnectedRoute(remoteDpnId, vpnId, vrfEntry, rd, instructions, NwConstants.ADD_FLOW, tx, subTxns);
}
Also used : ArrayList(java.util.ArrayList) ActionRegLoad(org.opendaylight.genius.mdsalutil.actions.ActionRegLoad) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)

Aggregations

ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)133 ArrayList (java.util.ArrayList)97 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)74 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)73 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)52 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)39 MatchMetadata (org.opendaylight.genius.mdsalutil.matches.MatchMetadata)33 Test (org.junit.Test)32 ActionNxResubmit (org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit)32 BigInteger (java.math.BigInteger)26 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)20 MatchInfoBase (org.opendaylight.genius.mdsalutil.MatchInfoBase)17 ActionGroup (org.opendaylight.genius.mdsalutil.actions.ActionGroup)16 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)15 BucketInfo (org.opendaylight.genius.mdsalutil.BucketInfo)14 ActionNxConntrack (org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack)12 ActionPuntToController (org.opendaylight.genius.mdsalutil.actions.ActionPuntToController)12 ActionSetFieldTunnelId (org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId)12 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)11 ActionDrop (org.opendaylight.genius.mdsalutil.actions.ActionDrop)9