Search in sources :

Example 1 with SetNwSrcActionBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.src._case.SetNwSrcActionBuilder in project openflowplugin by opendaylight.

the class TableFeaturesResponseConvertorTest method createSetNwSrcAction.

private static SetNwSrcCase createSetNwSrcAction() {
    final SetNwSrcCaseBuilder setNwSrcCaseBuilder;
    final SetNwSrcActionBuilder setNwSrcActionBuilder;
    setNwSrcCaseBuilder = new SetNwSrcCaseBuilder();
    setNwSrcActionBuilder = new SetNwSrcActionBuilder();
    setNwSrcActionBuilder.setIpAddress(new Ipv4Address("1.2.3.4"));
    setNwSrcCaseBuilder.setSetNwSrcAction(setNwSrcActionBuilder.build());
    return setNwSrcCaseBuilder.build();
}
Also used : SetNwSrcActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.src._case.SetNwSrcActionBuilder) SetNwSrcCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwSrcCaseBuilder) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)

Example 2 with SetNwSrcActionBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.src._case.SetNwSrcActionBuilder in project openflowplugin by opendaylight.

the class SalToOfSetNwSrcActionV10Case method process.

@Nonnull
@Override
public Optional<Action> process(@Nonnull final SetNwSrcActionCase source, final ActionConvertorData data, ConvertorExecutor convertorExecutor) {
    final ActionBuilder builder = new ActionBuilder();
    final Address address = source.getSetNwSrcAction().getAddress();
    if (address instanceof Ipv4) {
        // FIXME use of substring should be removed and OF models should distinguish where
        // FIXME to use Ipv4Prefix (with mask) and where to use Ipv4Address (without mask)
        String ipAddress = ((Ipv4) address).getIpv4Address().getValue();
        ipAddress = ipAddress.substring(0, ipAddress.indexOf("/"));
        Ipv4Address result = new Ipv4Address(ipAddress);
        SetNwSrcCaseBuilder nwSrcCaseBuilder = new SetNwSrcCaseBuilder();
        SetNwSrcActionBuilder nwSrcBuilder = new SetNwSrcActionBuilder();
        nwSrcBuilder.setIpAddress(new Ipv4Address(result));
        nwSrcCaseBuilder.setSetNwSrcAction(nwSrcBuilder.build());
        builder.setActionChoice(nwSrcCaseBuilder.build());
    } else {
        throw new IllegalArgumentException("Address is not supported by OF-1.0: " + address.getClass().getName());
    }
    return Optional.of(builder.build());
}
Also used : SetNwSrcActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.src._case.SetNwSrcActionBuilder) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder) Address(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Ipv4(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4) SetNwSrcActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.src._case.SetNwSrcActionBuilder) SetNwSrcCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwSrcCaseBuilder) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Nonnull(javax.annotation.Nonnull)

Example 3 with SetNwSrcActionBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.src._case.SetNwSrcActionBuilder in project openflowplugin by opendaylight.

the class WriteActionsInstructionSerializerTest method testSerialize.

@Test
public void testSerialize() throws Exception {
    final int order = 0;
    final Ipv4Prefix prefix = new Ipv4Prefix("192.168.76.0/32");
    final Instruction instruction = new WriteActionsCaseBuilder().setWriteActions(new WriteActionsBuilder().setAction(Collections.singletonList(new ActionBuilder().setOrder(order).setKey(new ActionKey(order)).setAction(new SetNwSrcActionCaseBuilder().setSetNwSrcAction(new SetNwSrcActionBuilder().setAddress(new Ipv4Builder().setIpv4Address(prefix).build()).build()).build()).build())).build()).build();
    assertInstruction(instruction, out -> {
        out.skipBytes(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
        assertEquals(out.readUnsignedShort(), ActionConstants.SET_FIELD_CODE);
        // Skip length of set field action
        out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
        assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS);
        assertEquals(out.readUnsignedByte(), OxmMatchConstants.IPV4_SRC << 1);
        // Skip match entry length
        out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
        byte[] addressBytes = new byte[4];
        out.readBytes(addressBytes);
        assertArrayEquals(addressBytes, new byte[] { (byte) 192, (byte) 168, 76, 0 });
        // Padding at end
        out.skipBytes(4);
    });
}
Also used : SetNwSrcActionCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder) WriteActionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.actions._case.WriteActionsBuilder) WriteActionsCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCaseBuilder) SetNwSrcActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder) SetNwSrcActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder) ActionKey(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey) Ipv4Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) Test(org.junit.Test)

Example 4 with SetNwSrcActionBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.src._case.SetNwSrcActionBuilder in project openflowplugin by opendaylight.

the class SetNwSrcActionSerializerTest method testSerialize.

@Test
public void testSerialize() throws Exception {
    final Ipv4 address = new Ipv4Builder().setIpv4Address(new Ipv4Prefix("192.168.76.2/32")).build();
    final Action action = new SetNwSrcActionCaseBuilder().setSetNwSrcAction(new SetNwSrcActionBuilder().setAddress(address).build()).build();
    assertAction(action, out -> {
        byte[] addressBytes = new byte[4];
        out.readBytes(addressBytes);
        assertArrayEquals(addressBytes, new byte[] { (byte) 192, (byte) 168, 76, 2 });
    });
}
Also used : SetNwSrcActionCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action) Ipv4(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4) SetNwSrcActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder) Ipv4Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) Test(org.junit.Test)

Example 5 with SetNwSrcActionBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.src._case.SetNwSrcActionBuilder in project openflowplugin by opendaylight.

the class OF10SetNwSrcActionDeserializer method deserialize.

@Override
public Action deserialize(final ByteBuf input) {
    final ActionBuilder builder = new ActionBuilder();
    input.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    SetNwSrcCaseBuilder caseBuilder = new SetNwSrcCaseBuilder();
    SetNwSrcActionBuilder actionBuilder = new SetNwSrcActionBuilder();
    actionBuilder.setIpAddress(ByteBufUtils.readIetfIpv4Address(input));
    caseBuilder.setSetNwSrcAction(actionBuilder.build());
    builder.setActionChoice(caseBuilder.build());
    return builder.build();
}
Also used : SetNwSrcActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.src._case.SetNwSrcActionBuilder) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder) SetNwSrcActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.src._case.SetNwSrcActionBuilder) SetNwSrcCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwSrcCaseBuilder)

Aggregations

Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)7 SetNwSrcActionCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder)7 SetNwSrcActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder)7 Ipv4Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder)7 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 ActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder)5 SetDlSrcActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcActionBuilder)4 SetNwDstActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder)4 SetNwTosActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.tos.action._case.SetNwTosActionBuilder)4 SetVlanIdActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder)4 SetVlanPcpActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.pcp.action._case.SetVlanPcpActionBuilder)4 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)3 SetDlDstActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.dst.action._case.SetDlDstActionBuilder)3 SetTpDstActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.dst.action._case.SetTpDstActionBuilder)3 SetTpSrcActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.src.action._case.SetTpSrcActionBuilder)3 StripVlanActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.strip.vlan.action._case.StripVlanActionBuilder)3 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action)3 ApplyActionsCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder)3 ApplyActionsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder)3