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();
}
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());
}
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);
});
}
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 });
});
}
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();
}
Aggregations