Search in sources :

Example 51 with Matches

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Matches in project openflowplugin by opendaylight.

the class FlowCreatorUtilTest method testCanModifyFlow.

/**
 * Test method for
 * {@link FlowCreatorUtil#canModifyFlow(OriginalFlow, UpdatedFlow, Short)}.
 */
@Test
public void testCanModifyFlow() {
    final Short of10 = Short.valueOf(OFConstants.OFP_VERSION_1_0);
    final Short of13 = Short.valueOf(OFConstants.OFP_VERSION_1_3);
    final Short[] versions = { null, of10, of13 };
    final Boolean[] bools = { null, Boolean.TRUE, Boolean.FALSE };
    final Integer defPri = Integer.valueOf(0x8000);
    final Integer defIdle = Integer.valueOf(0);
    final Integer defHard = Integer.valueOf(0);
    final FlowModFlags defFlags = FlowModFlags.getDefaultInstance("sENDFLOWREM");
    final FlowModFlags flags = new FlowModFlags(false, true, false, true, false);
    final FlowCookie defCookie = new FlowCookie(BigInteger.ZERO);
    final FlowCookie cookie = new FlowCookie(BigInteger.valueOf(0x12345L));
    final FlowCookie cookie1 = new FlowCookie(BigInteger.valueOf(0x67890L));
    final FlowCookie cookieMask = new FlowCookie(BigInteger.valueOf(0xffff00L));
    for (final Short ver : versions) {
        final OriginalFlowBuilder originalBuilder = new OriginalFlowBuilder();
        final UpdatedFlowBuilder updatedBuilder = new UpdatedFlowBuilder();
        canModifyFlowTest(true, originalBuilder, updatedBuilder, ver);
        // Default value tests.
        canModifyFlowTest(true, new OriginalFlowBuilder().setPriority(defPri), updatedBuilder, ver);
        canModifyFlowTest(true, originalBuilder, new UpdatedFlowBuilder().setPriority(defPri), ver);
        canModifyFlowTest(true, new OriginalFlowBuilder().setIdleTimeout(defIdle), updatedBuilder, ver);
        canModifyFlowTest(true, originalBuilder, new UpdatedFlowBuilder().setIdleTimeout(defIdle), ver);
        canModifyFlowTest(true, new OriginalFlowBuilder().setHardTimeout(defHard), updatedBuilder, ver);
        canModifyFlowTest(true, originalBuilder, new UpdatedFlowBuilder().setHardTimeout(defHard), ver);
        canModifyFlowTest(false, new OriginalFlowBuilder().setFlags(defFlags), updatedBuilder, ver);
        canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder().setFlags(defFlags), ver);
        canModifyFlowTest(true, new OriginalFlowBuilder().setCookie(defCookie), updatedBuilder, ver);
        canModifyFlowTest(true, originalBuilder, new UpdatedFlowBuilder().setCookie(defCookie), ver);
        // Set non-default values.
        canModifyFlowTest(true, originalBuilder.setMatch(createMatch(0x800L)), updatedBuilder.setMatch(createMatch(0x800L)), ver);
        canModifyFlowTest(true, originalBuilder.setIdleTimeout(600), updatedBuilder.setIdleTimeout(600), ver);
        canModifyFlowTest(true, originalBuilder.setHardTimeout(1200), updatedBuilder.setHardTimeout(1200), ver);
        canModifyFlowTest(true, originalBuilder.setPriority(100), updatedBuilder.setPriority(100), ver);
        canModifyFlowTest(true, originalBuilder.setFlags(flags), updatedBuilder.setFlags(flags), ver);
        canModifyFlowTest(true, originalBuilder.setCookie(cookie), updatedBuilder.setCookie(cookie), ver);
        final OriginalFlow org = originalBuilder.build();
        final UpdatedFlow upd = updatedBuilder.build();
        // Set different match.
        final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match[] matches = { null, createMatch(0x86ddL) };
        for (final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match m : matches) {
            canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setMatch(m), ver);
            canModifyFlowTest(false, new OriginalFlowBuilder(org).setMatch(m), updatedBuilder, ver);
        }
        // Set different idle-timeout, hard-timeout, priority.
        final Integer[] integers = { null, Integer.valueOf(3600) };
        for (final Integer i : integers) {
            canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setIdleTimeout(i), ver);
            canModifyFlowTest(false, new OriginalFlowBuilder(org).setIdleTimeout(i), updatedBuilder, ver);
            canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setHardTimeout(i), ver);
            canModifyFlowTest(false, new OriginalFlowBuilder(org).setHardTimeout(i), updatedBuilder, ver);
            canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setPriority(i), ver);
            canModifyFlowTest(false, new OriginalFlowBuilder(org).setPriority(i), updatedBuilder, ver);
        }
        // Set different FLOW_MOD flags.
        final FlowModFlags[] flowModFlags = { null, defFlags, new FlowModFlags(true, true, true, true, true) };
        for (final FlowModFlags f : flowModFlags) {
            canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setFlags(f), ver);
            canModifyFlowTest(false, new OriginalFlowBuilder(org).setFlags(f), updatedBuilder, ver);
        }
        // Set different cookie.
        final FlowCookie[] cookies = { null, defCookie, new FlowCookie(BigInteger.valueOf(0x123456L)) };
        for (final FlowCookie c : cookies) {
            canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setCookie(c), ver);
            canModifyFlowTest(false, new OriginalFlowBuilder(org).setCookie(c), updatedBuilder, ver);
        }
        // Cookie mask test.
        // Cookie mask is used by OF13 non-strict MODIFY command.
        updatedBuilder.setCookie(cookie1);
        for (final Boolean strict : bools) {
            updatedBuilder.setCookieMask(null).setStrict(strict);
            canModifyFlowTest(false, originalBuilder, updatedBuilder, ver);
            updatedBuilder.setCookieMask(defCookie);
            canModifyFlowTest(false, originalBuilder, updatedBuilder, ver);
            updatedBuilder.setCookieMask(cookieMask);
            final boolean expected = (of13.equals(ver) && !Boolean.TRUE.equals(strict));
            canModifyFlowTest(expected, originalBuilder, updatedBuilder, ver);
        }
    }
}
Also used : UpdatedFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow) OriginalFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlow) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match) FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) FlowModFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags) BigInteger(java.math.BigInteger) OriginalFlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlowBuilder) UpdatedFlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlowBuilder) Test(org.junit.Test)

Example 52 with Matches

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Matches in project genius by opendaylight.

the class FlowBasedServicesUtils method installLPortDispatcherFlow.

public static void installLPortDispatcherFlow(BigInteger dpId, BoundServices boundService, String interfaceName, WriteTransaction writeTransaction, int interfaceTag, short currentServiceIndex, short nextServiceIndex) {
    String serviceRef = boundService.getServiceName();
    List<MatchInfo> matches = FlowBasedServicesUtils.getMatchInfoForDispatcherTable(interfaceTag, currentServiceIndex);
    // Get the metadata and mask from the service's write metadata
    // instruction
    StypeOpenflow stypeOpenFlow = boundService.getAugmentation(StypeOpenflow.class);
    List<Instruction> serviceInstructions = stypeOpenFlow.getInstruction();
    int instructionSize = serviceInstructions != null ? serviceInstructions.size() : 0;
    BigInteger[] metadataValues = IfmUtil.mergeOpenflowMetadataWriteInstructions(serviceInstructions);
    BigInteger metadata = MetaDataUtil.getMetaDataForLPortDispatcher(interfaceTag, nextServiceIndex, metadataValues[0]);
    BigInteger metadataMask = MetaDataUtil.getWriteMetaDataMaskForDispatcherTable();
    // build the final instruction for LPort Dispatcher table flow entry
    List<Instruction> instructions = new ArrayList<>();
    instructions.add(MDSALUtil.buildAndGetWriteMetadaInstruction(metadata, metadataMask, ++instructionSize));
    if (serviceInstructions != null && !serviceInstructions.isEmpty()) {
        for (Instruction info : serviceInstructions) {
            // Skip meta data write as that is handled already
            if (info.getInstruction() instanceof WriteMetadataCase) {
                continue;
            } else if (info.getInstruction() instanceof WriteActionsCase) {
                info = MDSALUtil.buildWriteActionsInstruction(ActionConverterUtil.convertServiceActionToFlowAction(((WriteActionsCase) info.getInstruction()).getWriteActions().getAction()));
            } else if (info.getInstruction() instanceof ApplyActionsCase) {
                info = MDSALUtil.buildApplyActionsInstruction(ActionConverterUtil.convertServiceActionToFlowAction(((ApplyActionsCase) info.getInstruction()).getApplyActions().getAction()));
            }
            instructions.add(info);
        }
    }
    // build the flow and install it
    String flowRef = getFlowRef(dpId, NwConstants.LPORT_DISPATCHER_TABLE, interfaceName, currentServiceIndex);
    Flow ingressFlow = MDSALUtil.buildFlowNew(NwConstants.LPORT_DISPATCHER_TABLE, flowRef, DEFAULT_DISPATCHER_PRIORITY, serviceRef, 0, 0, stypeOpenFlow.getFlowCookie(), matches, instructions);
    LOG.debug("Installing LPort Dispatcher Flow on DPN {}, for interface {}, with flowRef {}", dpId, interfaceName, flowRef);
    installFlow(dpId, ingressFlow, writeTransaction);
}
Also used : WriteMetadataCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase) StypeOpenflow(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.StypeOpenflow) ArrayList(java.util.ArrayList) WriteActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase) 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) ApplyActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase)

Example 53 with Matches

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Matches in project genius by opendaylight.

the class FlowBasedServicesUtils method getMatchInfoForEgressDispatcherTable.

public static List<MatchInfoBase> getMatchInfoForEgressDispatcherTable(int interfaceTag, short serviceIndex) {
    List<MatchInfoBase> matches = new ArrayList<>();
    matches.add(new NxMatchRegister(NxmNxReg6.class, MetaDataUtil.getReg6ValueForLPortDispatcher(interfaceTag, serviceIndex)));
    return matches;
}
Also used : NxmNxReg6(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6) ArrayList(java.util.ArrayList) NxMatchRegister(org.opendaylight.genius.mdsalutil.nxmatches.NxMatchRegister) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase)

Example 54 with Matches

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Matches in project genius by opendaylight.

the class FlowBasedServicesUtils method getMatchInfoForVlanPortAtIngressTable.

public static List<MatchInfo> getMatchInfoForVlanPortAtIngressTable(BigInteger dpId, long portNo, Interface iface) {
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(new MatchInPort(dpId, portNo));
    int vlanId = 0;
    IfL2vlan l2vlan = iface.getAugmentation(IfL2vlan.class);
    if (l2vlan != null) {
        vlanId = l2vlan.getVlanId() == null ? 0 : l2vlan.getVlanId().getValue();
    }
    if (vlanId >= 0 && l2vlan.getL2vlanMode() != IfL2vlan.L2vlanMode.Transparent) {
        matches.add(new MatchVlanVid(vlanId));
    }
    return matches;
}
Also used : MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) MatchVlanVid(org.opendaylight.genius.mdsalutil.matches.MatchVlanVid) ArrayList(java.util.ArrayList) MatchInPort(org.opendaylight.genius.mdsalutil.matches.MatchInPort) IfL2vlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan)

Example 55 with Matches

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Matches in project genius by opendaylight.

the class InterfaceManagerCommonUtils method addTunnelIngressFlow.

public void addTunnelIngressFlow(IfTunnel tunnel, BigInteger dpnId, long portNo, String interfaceName, int ifIndex) {
    if (isTunnelWithoutIngressFlow(tunnel)) {
        return;
    }
    LOG.debug("add tunnel ingress flow for {}", interfaceName);
    List<MatchInfoBase> matches = new ArrayList<>();
    matches.add(new MatchInPort(dpnId, portNo));
    if (BooleanUtils.isTrue(tunnel.isTunnelRemoteIpFlow())) {
        matches.add(new NxMatchTunnelSourceIp(tunnel.getTunnelDestination().getIpv4Address()));
    }
    if (BooleanUtils.isTrue(tunnel.isTunnelSourceIpFlow())) {
        matches.add(new NxMatchTunnelDestinationIp(tunnel.getTunnelSource().getIpv4Address()));
    }
    List<InstructionInfo> mkInstructions = new ArrayList<>();
    mkInstructions.add(new InstructionWriteMetadata(MetaDataUtil.getLportTagMetaData(ifIndex).or(BigInteger.ONE), MetaDataUtil.METADATA_MASK_LPORT_TAG_SH_FLAG));
    short tableId = tunnel.getTunnelInterfaceType().isAssignableFrom(TunnelTypeMplsOverGre.class) ? NwConstants.L3_LFIB_TABLE : tunnel.isInternal() ? NwConstants.INTERNAL_TUNNEL_TABLE : NwConstants.DHCP_TABLE_EXTERNAL_TUNNEL;
    mkInstructions.add(new InstructionGotoTable(tableId));
    mdsalApiManager.batchedAddFlow(dpnId, buildTunnelIngressFlowEntity(dpnId, interfaceName, matches, mkInstructions));
}
Also used : NxMatchTunnelDestinationIp(org.opendaylight.genius.mdsalutil.nxmatches.NxMatchTunnelDestinationIp) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) ArrayList(java.util.ArrayList) NxMatchTunnelSourceIp(org.opendaylight.genius.mdsalutil.nxmatches.NxMatchTunnelSourceIp) MatchInPort(org.opendaylight.genius.mdsalutil.matches.MatchInPort) InstructionWriteMetadata(org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase) TunnelTypeMplsOverGre(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeMplsOverGre)

Aggregations

ArrayList (java.util.ArrayList)66 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)31 MatchInfoBase (org.opendaylight.genius.mdsalutil.MatchInfoBase)30 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)28 Matches (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Matches)22 BigInteger (java.math.BigInteger)21 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)21 MatchMetadata (org.opendaylight.genius.mdsalutil.matches.MatchMetadata)20 Test (org.junit.Test)18 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)17 List (java.util.List)16 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)16 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)15 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)15 IpPrefixOrAddress (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.IpPrefixOrAddress)13 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)12 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)10 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)10 FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)8 NodeId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId)8