Search in sources :

Example 1 with FlowModFlags

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags in project openflowplugin by opendaylight.

the class FlowStatsResponseConvertor method convert.

@Override
public List<FlowAndStatisticsMapList> convert(List<FlowStats> source, FlowStatsResponseConvertorData data) {
    final List<FlowAndStatisticsMapList> result = new ArrayList<>();
    for (FlowStats flowStats : source) {
        // Convert Openflow switch specific flow statistics to the MD-SAL format flow statistics
        FlowAndStatisticsMapListBuilder salFlowStatsBuilder = new FlowAndStatisticsMapListBuilder();
        salFlowStatsBuilder.setByteCount(new Counter64(flowStats.getByteCount()));
        if (flowStats.getCookie() != null) {
            salFlowStatsBuilder.setCookie(new FlowCookie(flowStats.getCookie()));
        }
        DurationBuilder time = new DurationBuilder();
        time.setSecond(new Counter32(flowStats.getDurationSec()));
        time.setNanosecond(new Counter32(flowStats.getDurationNsec()));
        salFlowStatsBuilder.setDuration(time.build());
        salFlowStatsBuilder.setHardTimeout(flowStats.getHardTimeout());
        salFlowStatsBuilder.setIdleTimeout(flowStats.getIdleTimeout());
        salFlowStatsBuilder.setPacketCount(new Counter64(flowStats.getPacketCount()));
        salFlowStatsBuilder.setPriority(flowStats.getPriority());
        salFlowStatsBuilder.setTableId(flowStats.getTableId());
        Short ipProtocol = null;
        if (flowStats.getMatchV10() != null) {
            final Optional<MatchBuilder> matchBuilderOptional = getConvertorExecutor().convert(flowStats.getMatchV10(), data);
            if (matchBuilderOptional.isPresent()) {
                if (Objects.nonNull(matchBuilderOptional.get().getIpMatch())) {
                    ipProtocol = matchBuilderOptional.get().getIpMatch().getIpProtocol();
                }
                salFlowStatsBuilder.setMatch(matchBuilderOptional.get().build());
            }
            if (flowStats.getAction() != null && flowStats.getAction().size() != 0) {
                salFlowStatsBuilder.setInstructions(wrapOF10ActionsToInstruction(flowStats.getAction(), data.getVersion(), ipProtocol));
            }
        }
        if (flowStats.getMatch() != null) {
            final Optional<MatchBuilder> matchBuilderOptional = getConvertorExecutor().convert(flowStats.getMatch(), data);
            if (matchBuilderOptional.isPresent()) {
                final MatchBuilder matchBuilder = matchBuilderOptional.get();
                final AugmentTuple<Match> matchExtensionWrap = MatchExtensionHelper.processAllExtensions(flowStats.getMatch().getMatchEntry(), OpenflowVersion.get(data.getVersion()), data.getMatchPath());
                if (matchExtensionWrap != null) {
                    matchBuilder.addAugmentation(matchExtensionWrap.getAugmentationClass(), matchExtensionWrap.getAugmentationObject());
                }
                salFlowStatsBuilder.setMatch(matchBuilder.build());
            }
            salFlowStatsBuilder.setFlags(new FlowModFlags(flowStats.getFlags().isOFPFFCHECKOVERLAP(), flowStats.getFlags().isOFPFFRESETCOUNTS(), flowStats.getFlags().isOFPFFNOPKTCOUNTS(), flowStats.getFlags().isOFPFFNOBYTCOUNTS(), flowStats.getFlags().isOFPFFSENDFLOWREM()));
        }
        if (flowStats.getInstruction() != null) {
            final VersionConvertorData simpleConvertorData = new VersionConvertorData(data.getVersion());
            final Optional<Instructions> instructions = getConvertorExecutor().convert(flowStats.getInstruction(), simpleConvertorData);
            salFlowStatsBuilder.setInstructions(instructions.orElse(new InstructionsBuilder().setInstruction(Collections.emptyList()).build()));
        }
        result.add(salFlowStatsBuilder.build());
    }
    return result;
}
Also used : FlowModFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags) ArrayList(java.util.ArrayList) Instructions(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions) FlowAndStatisticsMapList(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match) InstructionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder) FlowStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats) FlowAndStatisticsMapListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder) Counter32(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32) Counter64(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64) VersionConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData) FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) DurationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.duration.DurationBuilder)

Example 2 with FlowModFlags

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags in project openflowplugin by opendaylight.

the class LLDPPacketPuntEnforcer method createFlow.

static Flow createFlow() {
    FlowBuilder flowBuilder = new FlowBuilder();
    flowBuilder.setMatch(new MatchBuilder().build());
    flowBuilder.setInstructions(createSendToControllerInstructions().build());
    flowBuilder.setPriority(0);
    FlowKey key = new FlowKey(new FlowId(DEFAULT_FLOW_ID));
    flowBuilder.setBarrier(Boolean.FALSE);
    flowBuilder.setBufferId(OFConstants.OFP_NO_BUFFER);
    BigInteger value = BigInteger.valueOf(10L);
    flowBuilder.setCookie(new FlowCookie(value));
    flowBuilder.setCookieMask(new FlowCookie(value));
    flowBuilder.setHardTimeout(0);
    flowBuilder.setIdleTimeout(0);
    flowBuilder.setInstallHw(false);
    flowBuilder.setStrict(false);
    flowBuilder.setContainerName(null);
    flowBuilder.setFlags(new FlowModFlags(false, false, false, false, true));
    flowBuilder.setId(new FlowId("12"));
    flowBuilder.setTableId(TABLE_ID);
    flowBuilder.setKey(key);
    flowBuilder.setFlowName(LLDP_PUNT_WHOLE_PACKET_FLOW);
    return flowBuilder.build();
}
Also used : FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) FlowModFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags) BigInteger(java.math.BigInteger) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)

Example 3 with FlowModFlags

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags in project openflowplugin by opendaylight.

the class OpenflowpluginTestCommandProvider method createTestFlowPerfTest.

private FlowBuilder createTestFlowPerfTest(final String flowTypeArg, final String tableId, final int id) {
    final FlowBuilder flow = new FlowBuilder();
    String flowType = flowTypeArg;
    int flowId = id;
    if (flowType == null) {
        flowType = "f1";
    }
    flow.setPriority(flowId);
    switch(flowType) {
        case "f1":
            flowId += 1;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createDecNwTtlInstructions().build());
            break;
        default:
            LOG.warn("flow type not understood: {}", flowType);
    }
    final FlowKey key = new FlowKey(new FlowId(Long.toString(flowId)));
    if (null == flow.isBarrier()) {
        flow.setBarrier(Boolean.FALSE);
    }
    final BigInteger value = BigInteger.valueOf(10);
    flow.setCookie(new FlowCookie(value));
    flow.setCookieMask(new FlowCookie(value));
    flow.setHardTimeout(0);
    flow.setIdleTimeout(0);
    flow.setInstallHw(false);
    flow.setStrict(false);
    flow.setContainerName(null);
    flow.setFlags(new FlowModFlags(false, false, false, false, true));
    flow.setId(new FlowId("12"));
    flow.setTableId(getTableId(tableId));
    flow.setKey(key);
    flow.setFlowName(ORIGINAL_FLOW_NAME + "X" + flowType);
    return flow;
}
Also used : FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) FlowModFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags) BigInteger(java.math.BigInteger)

Example 4 with FlowModFlags

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags in project openflowplugin by opendaylight.

the class OpenflowPluginBulkGroupTransactionProvider method createTestFlow.

private FlowBuilder createTestFlow(NodeBuilder nodeBuilder, String flowTypeArg, String tableId) {
    FlowBuilder flow = new FlowBuilder();
    long id = 123;
    String flowType = flowTypeArg;
    if (flowType == null) {
        flowType = "f1";
    }
    switch(flowType) {
        case "f1":
            id += 1;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createDecNwTtlInstructions().build());
            break;
        case "f2":
            id += 2;
            flow.setMatch(createMatch2().build());
            flow.setInstructions(createDropInstructions().build());
            break;
        case "f3":
            id += 3;
            flow.setMatch(createMatch3().build());
            flow.setInstructions(createDropInstructions().build());
            break;
        case "f4":
            id += 4;
            flow.setMatch(createEthernetMatch().build());
            flow.setInstructions(createDropInstructions().build());
            break;
        case "f82":
            id += 1;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createDropInstructions().build());
            break;
        case "f5":
            id += 5;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction().build());
            break;
        case "f6":
            id += 6;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createGotoTableInstructions().build());
            break;
        case "f7":
            id += 7;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createMeterInstructions().build());
            break;
        case "f8":
            id += 8;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction7().build());
            break;
        case "f9":
            id += 9;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction2().build());
            break;
        case "f10":
            id += 10;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction3().build());
            break;
        case "f14":
            id += 14;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction7().build());
            break;
        case "f29":
            id += 29;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction21().build());
            break;
        default:
            LOG.warn("flow type not understood: {}", flowType);
    }
    final FlowKey key = new FlowKey(new FlowId(Long.toString(id)));
    if (null == flow.isBarrier()) {
        flow.setBarrier(Boolean.FALSE);
    }
    // flow.setBufferId(12L);
    BigInteger value = BigInteger.valueOf(10);
    BigInteger outputPort = BigInteger.valueOf(4294967295L);
    flow.setCookie(new FlowCookie(value));
    flow.setCookieMask(new FlowCookie(value));
    flow.setHardTimeout(0);
    flow.setIdleTimeout(0);
    flow.setInstallHw(false);
    flow.setStrict(false);
    flow.setContainerName(null);
    flow.setFlags(new FlowModFlags(false, false, false, false, true));
    flow.setId(new FlowId("12"));
    flow.setTableId(getTableId(tableId));
    flow.setOutGroup(4294967295L);
    // set outport to OFPP_NONE (65535) to disable remove restriction for
    // flow
    flow.setOutPort(outputPort);
    flow.setKey(key);
    flow.setPriority(2);
    flow.setFlowName(originalFlowName + "X" + flowType);
    return flow;
}
Also used : FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) FlowModFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags) BigInteger(java.math.BigInteger)

Example 5 with FlowModFlags

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags in project openflowplugin by opendaylight.

the class FlowConvertorTest method test.

/**
 * Tests {@link FlowConvertor#convert(Flow, VersionDatapathIdConvertorData)} }.
 */
@Test
public void test() {
    RemoveFlowInputBuilder flowBuilder = new RemoveFlowInputBuilder();
    flowBuilder.setBarrier(false);
    flowBuilder.setCookie(new FlowCookie(new BigInteger("4")));
    flowBuilder.setCookieMask(new FlowCookie(new BigInteger("5")));
    flowBuilder.setTableId((short) 6);
    flowBuilder.setStrict(true);
    flowBuilder.setIdleTimeout(50);
    flowBuilder.setHardTimeout(500);
    flowBuilder.setPriority(40);
    flowBuilder.setBufferId(18L);
    flowBuilder.setOutPort(new BigInteger("65535"));
    flowBuilder.setOutGroup(5000L);
    flowBuilder.setFlags(null);
    flowBuilder.setMatch(null);
    RemoveFlowInput flow = flowBuilder.build();
    VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_3);
    data.setDatapathId(new BigInteger("42"));
    List<FlowModInputBuilder> flowMod = convert(flow, data);
    Assert.assertEquals("Wrong version", 4, flowMod.get(0).getVersion().intValue());
    Assert.assertEquals("Wrong cookie", 4, flowMod.get(0).getCookie().intValue());
    Assert.assertEquals("Wrong cookie mask", 5, flowMod.get(0).getCookieMask().intValue());
    Assert.assertEquals("Wrong table id", 6, flowMod.get(0).getTableId().getValue().intValue());
    Assert.assertEquals("Wrong command", FlowModCommand.OFPFCDELETESTRICT, flowMod.get(0).getCommand());
    Assert.assertEquals("Wrong idle timeout", 50, flowMod.get(0).getIdleTimeout().intValue());
    Assert.assertEquals("Wrong hard timeout", 500, flowMod.get(0).getHardTimeout().intValue());
    Assert.assertEquals("Wrong priority", 40, flowMod.get(0).getPriority().intValue());
    Assert.assertEquals("Wrong buffer id", 18, flowMod.get(0).getBufferId().intValue());
    Assert.assertEquals("Wrong out port", 65535, flowMod.get(0).getOutPort().getValue().intValue());
    Assert.assertEquals("Wrong out group", 5000, flowMod.get(0).getOutGroup().intValue());
    Assert.assertEquals("Wrong flags", new FlowModFlags(false, false, false, false, false), flowMod.get(0).getFlags());
    Assert.assertEquals("Wrong match", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmMatchType", flowMod.get(0).getMatch().getType().getName());
    Assert.assertEquals("Wrong match entries size", 0, flowMod.get(0).getMatch().getMatchEntry().size());
}
Also used : FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) VersionDatapathIdConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData) FlowModFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags) RemoveFlowInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput) RemoveFlowInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder) BigInteger(java.math.BigInteger) FlowModInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder) Test(org.junit.Test)

Aggregations

FlowModFlags (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags)16 BigInteger (java.math.BigInteger)12 FlowCookie (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie)12 FlowBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder)11 FlowKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey)10 FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)9 Test (org.junit.Test)8 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)7 FlowModFlags (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags)7 ByteBuf (io.netty.buffer.ByteBuf)3 ArrayList (java.util.ArrayList)3 InstructionsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder)3 FlowModInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder)3 Optional (com.google.common.base.Optional)2 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)2 Uri (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri)2 Counter32 (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32)2 Counter64 (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64)2 OutputActionCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder)2 OutputActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder)2