Search in sources :

Example 11 with FlowModInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder in project openflowplugin by opendaylight.

the class OF10FlowModInputMessageFactoryTest method testFlowModInputMessageFactory.

/**
 * Testing of {@link OF10FlowModInputMessageFactory} for correct translation from POJO.
 */
@Test
public void testFlowModInputMessageFactory() throws Exception {
    FlowModInputBuilder builder = new FlowModInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
    MatchV10Builder matchBuilder = new MatchV10Builder();
    matchBuilder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true));
    matchBuilder.setNwSrcMask((short) 0);
    matchBuilder.setNwDstMask((short) 0);
    matchBuilder.setInPort(58);
    matchBuilder.setDlSrc(new MacAddress("01:01:01:01:01:01"));
    matchBuilder.setDlDst(new MacAddress("ff:ff:ff:ff:ff:ff"));
    matchBuilder.setDlVlan(18);
    matchBuilder.setDlVlanPcp((short) 5);
    matchBuilder.setDlType(42);
    matchBuilder.setNwTos((short) 4);
    matchBuilder.setNwProto((short) 7);
    matchBuilder.setNwSrc(new Ipv4Address("8.8.8.8"));
    matchBuilder.setNwDst(new Ipv4Address("16.16.16.16"));
    matchBuilder.setTpSrc(6653);
    matchBuilder.setTpDst(6633);
    builder.setMatchV10(matchBuilder.build());
    byte[] cookie = new byte[] { (byte) 0xFF, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01 };
    builder.setCookie(new BigInteger(1, cookie));
    builder.setCommand(FlowModCommand.forValue(0));
    builder.setIdleTimeout(12);
    builder.setHardTimeout(16);
    builder.setPriority(1);
    builder.setBufferId(2L);
    builder.setOutPort(new PortNumber(4422L));
    builder.setFlagsV10(new FlowModFlagsV10(true, false, true));
    final List<Action> actions = new ArrayList<>();
    ActionBuilder actionBuilder = new ActionBuilder();
    SetNwDstCaseBuilder nwDstCaseBuilder = new SetNwDstCaseBuilder();
    SetNwDstActionBuilder nwDstBuilder = new SetNwDstActionBuilder();
    nwDstBuilder.setIpAddress(new Ipv4Address("2.2.2.2"));
    nwDstCaseBuilder.setSetNwDstAction(nwDstBuilder.build());
    actionBuilder.setActionChoice(nwDstCaseBuilder.build());
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    SetTpSrcCaseBuilder tpSrcCaseBuilder = new SetTpSrcCaseBuilder();
    SetTpSrcActionBuilder tpSrcBuilder = new SetTpSrcActionBuilder();
    tpSrcBuilder.setPort(new PortNumber(42L));
    tpSrcCaseBuilder.setSetTpSrcAction(tpSrcBuilder.build());
    actionBuilder.setActionChoice(tpSrcCaseBuilder.build());
    actions.add(actionBuilder.build());
    builder.setAction(actions);
    FlowModInput message = builder.build();
    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    flowModFactory.serialize(message, out);
    BufferHelper.checkHeaderV10(out, (byte) 14, 88);
    Assert.assertEquals("Wrong wildcards", 3678463, out.readUnsignedInt());
    Assert.assertEquals("Wrong inPort", 58, out.readUnsignedShort());
    byte[] dlSrc = new byte[6];
    out.readBytes(dlSrc);
    Assert.assertEquals("Wrong dlSrc", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc));
    byte[] dlDst = new byte[6];
    out.readBytes(dlDst);
    Assert.assertEquals("Wrong dlDst", "FF:FF:FF:FF:FF:FF", ByteBufUtils.macAddressToString(dlDst));
    Assert.assertEquals("Wrong dlVlan", 18, out.readUnsignedShort());
    Assert.assertEquals("Wrong dlVlanPcp", 5, out.readUnsignedByte());
    out.skipBytes(1);
    Assert.assertEquals("Wrong dlType", 42, out.readUnsignedShort());
    Assert.assertEquals("Wrong nwTos", 4, out.readUnsignedByte());
    Assert.assertEquals("Wrong nwProto", 7, out.readUnsignedByte());
    out.skipBytes(2);
    Assert.assertEquals("Wrong nwSrc", 134744072, out.readUnsignedInt());
    Assert.assertEquals("Wrong nwDst", 269488144, out.readUnsignedInt());
    Assert.assertEquals("Wrong tpSrc", 6653, out.readUnsignedShort());
    Assert.assertEquals("Wrong tpDst", 6633, out.readUnsignedShort());
    byte[] cookieRead = new byte[8];
    out.readBytes(cookieRead);
    Assert.assertArrayEquals("Wrong cookie", cookie, cookieRead);
    Assert.assertEquals("Wrong command", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong idleTimeOut", 12, out.readUnsignedShort());
    Assert.assertEquals("Wrong hardTimeOut", 16, out.readUnsignedShort());
    Assert.assertEquals("Wrong priority", 1, out.readUnsignedShort());
    Assert.assertEquals("Wrong bufferId", 2, out.readUnsignedInt());
    Assert.assertEquals("Wrong outPort", 4422, out.readUnsignedShort());
    Assert.assertEquals("Wrong flags", 3, out.readUnsignedShort());
    Assert.assertEquals("Wrong action - type", 7, out.readUnsignedShort());
    Assert.assertEquals("Wrong action - length", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong flags", 33686018, out.readUnsignedInt());
    Assert.assertEquals("Wrong action - type", 9, out.readUnsignedShort());
    Assert.assertEquals("Wrong action - length", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong flags", 42, out.readUnsignedShort());
    out.skipBytes(2);
}
Also used : Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) SetTpSrcActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.tp.src._case.SetTpSrcActionBuilder) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder) SetNwDstActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.dst._case.SetNwDstActionBuilder) SetTpSrcActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.tp.src._case.SetTpSrcActionBuilder) ArrayList(java.util.ArrayList) FlowModFlagsV10(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlagsV10) SetNwDstCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwDstCaseBuilder) FlowModInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) ByteBuf(io.netty.buffer.ByteBuf) FlowWildcardsV10(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10) SetNwDstActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.dst._case.SetNwDstActionBuilder) MatchV10Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10Builder) SetTpSrcCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetTpSrcCaseBuilder) FlowModInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput) BigInteger(java.math.BigInteger) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Test(org.junit.Test)

Example 12 with FlowModInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder in project openflowplugin by opendaylight.

the class FlowConvertor method handleSetVlanIdForOF13.

/**
 * A) If user provided flow's match includes vlan match  and action has set_vlan_field
 * Install following rules.
 *    1) match on (OFPVID_PRESENT |value) without mask + action [set_field]
 * <p/>
 * B) if user provided flow's match doesn't include vlan match but action has set_vlan field
 *     1) Match on (OFPVID_NONE ) without mask + action [push vlan tag + set_field]
 *     2) Match on (OFPVID_PRESENT) with mask (OFPVID_PRESENT ) + action [ set_field]
 */
private List<FlowModInputBuilder> handleSetVlanIdForOF13(Flow srcFlow, VersionDatapathIdConvertorData versionDatapathIdConverterData) {
    List<FlowModInputBuilder> list = new ArrayList<>(2);
    final Match srcMatch = Preconditions.checkNotNull(srcFlow.getMatch());
    final VlanMatch srcVlanMatch = srcMatch.getVlanMatch();
    if (srcVlanMatch != null) {
        // create flow with setfield and match
        // match on vlan tag or vlanid with no mask
        VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder(srcVlanMatch);
        VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
        vlanIdBuilder.setVlanIdPresent(srcVlanMatch.getVlanId().isVlanIdPresent());
        vlanIdBuilder.setVlanId(srcVlanMatch.getVlanId().getVlanId());
        vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
        Match match = new MatchBuilder(srcMatch).setVlanMatch(vlanMatchBuilder.build()).build();
        Optional<? extends Flow> optional = injectMatchToFlow(srcFlow, match);
        if (optional.isPresent()) {
            list.add(toFlowModInput(optional.get(), versionDatapathIdConverterData));
        }
    } else {
        // create 2 flows
        // flow 1
        // match on no vlan tag with no mask
        Match match1 = new MatchBuilder(srcMatch).setVlanMatch(VLAN_MATCH_FALSE).build();
        Optional<? extends Flow> optional1 = injectMatchAndAction(srcFlow, match1);
        if (optional1.isPresent()) {
            list.add(toFlowModInput(optional1.get(), versionDatapathIdConverterData));
        }
        // flow2
        // match on vlan tag with mask
        Match match2 = new MatchBuilder(srcMatch).setVlanMatch(VLAN_MATCH_TRUE).build();
        Optional<? extends Flow> optional2 = injectMatchToFlow(srcFlow, match2);
        if (optional2.isPresent()) {
            list.add(toFlowModInput(optional2.get(), versionDatapathIdConverterData));
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) VlanMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch) VlanMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder) FlowModInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder) VlanIdBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder) VlanMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match) VlanMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch)

Example 13 with FlowModInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder in project openflowplugin by opendaylight.

the class FlowModInputMessageFactory method deserialize.

@Override
// FB doesn't recognize Objects.requireNonNull
@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
public FlowModInput deserialize(ByteBuf rawMessage) {
    Objects.requireNonNull(registry);
    FlowModInputBuilder builder = new FlowModInputBuilder();
    builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
    builder.setXid(rawMessage.readUnsignedInt());
    byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    rawMessage.readBytes(cookie);
    builder.setCookie(new BigInteger(1, cookie));
    final byte[] cookieMask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    rawMessage.readBytes(cookieMask);
    builder.setCookieMask(new BigInteger(1, cookieMask));
    builder.setTableId(new TableId((long) rawMessage.readUnsignedByte()));
    builder.setCommand(FlowModCommand.forValue(rawMessage.readUnsignedByte()));
    builder.setIdleTimeout(rawMessage.readUnsignedShort());
    builder.setHardTimeout(rawMessage.readUnsignedShort());
    builder.setPriority(rawMessage.readUnsignedShort());
    builder.setBufferId(rawMessage.readUnsignedInt());
    builder.setOutPort(new PortNumber(rawMessage.readUnsignedInt()));
    builder.setOutGroup(rawMessage.readUnsignedInt());
    builder.setFlags(createFlowModFlagsFromBitmap(rawMessage.readUnsignedShort()));
    rawMessage.skipBytes(PADDING);
    OFDeserializer<Match> matchDeserializer = registry.getDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class));
    builder.setMatch(matchDeserializer.deserialize(rawMessage));
    CodeKeyMaker keyMaker = CodeKeyMakerFactory.createInstructionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
    List<Instruction> instructions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, rawMessage.readableBytes(), rawMessage, keyMaker, registry);
    builder.setInstruction(instructions);
    return builder.build();
}
Also used : TableId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId) MessageCodeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey) CodeKeyMaker(org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker) BigInteger(java.math.BigInteger) FlowModInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 14 with FlowModInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder in project openflowplugin by opendaylight.

the class FlowConvertorTest method testCloneAndAugmentFlowWithSetVlanId.

@Test
public void testCloneAndAugmentFlowWithSetVlanId() {
    MockFlow mockFlow = new MockFlow();
    Action action1 = createAction(new SetVlanIdActionCaseBuilder().setSetVlanIdAction(new SetVlanIdActionBuilder().setVlanId(new VlanId(10)).build()).build(), 0);
    mockFlow.setMatch(new MatchBuilder().setEthernetMatch(createEthernetMatch()).build());
    mockFlow.setInstructions(toApplyInstruction(Collections.singletonList(action1)));
    VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_3);
    data.setDatapathId(BigInteger.ONE);
    List<FlowModInputBuilder> flowModInputBuilders = convert(mockFlow, data);
    Assert.assertEquals(2, flowModInputBuilders.size());
}
Also used : Action(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action) SetVlanIdActionCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder) VersionDatapathIdConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData) SetVlanIdActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder) FlowModInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder) EthernetMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) VlanId(org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId) Test(org.junit.Test)

Example 15 with FlowModInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder in project openflowplugin by opendaylight.

the class FlowConvertorTest method testOnlyModifyStrictCommand.

/**
 * Tests {@link FlowConvertor#convert(Flow, VersionDatapathIdConvertorData)} }.
 */
@Test
public void testOnlyModifyStrictCommand() {
    UpdatedFlowBuilder flowBuilder = new UpdatedFlowBuilder();
    flowBuilder.setStrict(true);
    UpdatedFlow flow = flowBuilder.build();
    VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_0);
    data.setDatapathId(new BigInteger("42"));
    List<FlowModInputBuilder> flowMod = convert(flow, data);
    Assert.assertEquals("Wrong version", 1, flowMod.get(0).getVersion().intValue());
    Assert.assertEquals("Wrong command", FlowModCommand.OFPFCADD, flowMod.get(0).getCommand());
}
Also used : UpdatedFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow) VersionDatapathIdConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData) BigInteger(java.math.BigInteger) FlowModInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder) UpdatedFlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlowBuilder) Test(org.junit.Test)

Aggregations

FlowModInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder)14 BigInteger (java.math.BigInteger)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 List (java.util.List)4 VersionDatapathIdConvertorData (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)4 PortNumber (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber)4 AddFlowInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder)3 RemoveFlowInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder)3 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action)3 FlowModFlags (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 ByteBuf (io.netty.buffer.ByteBuf)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Optional (java.util.Optional)2 MessageCodeKey (org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey)2 EncodeConstants (org.opendaylight.openflowjava.protocol.api.util.EncodeConstants)2 CodeKeyMaker (org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker)2 OFConstants (org.opendaylight.openflowplugin.api.OFConstants)2