use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase in project openflowplugin by opendaylight.
the class SetTpSrcActionSerializer method buildAction.
@Override
protected SetFieldCase buildAction(Action input) {
final SetTpSrcAction setTpSrcAction = SetTpSrcActionCase.class.cast(input).getSetTpSrcAction();
final PortNumber port = setTpSrcAction.getPort();
final SetFieldBuilder builder = new SetFieldBuilder();
Optional.ofNullable(IPProtocols.fromProtocolNum(setTpSrcAction.getIpProtocol())).ifPresent(proto -> {
switch(proto) {
case ICMP:
{
builder.setIcmpv4Match(new Icmpv4MatchBuilder().setIcmpv4Type((short) (0xFF & port.getValue())).build());
break;
}
case ICMPV6:
{
builder.setIcmpv6Match(new Icmpv6MatchBuilder().setIcmpv6Type((short) (0xFF & port.getValue())).build());
break;
}
case TCP:
{
builder.setLayer4Match(new TcpMatchBuilder().setTcpSourcePort(port).build());
break;
}
case UDP:
{
builder.setLayer4Match(new UdpMatchBuilder().setUdpSourcePort(port).build());
break;
}
default:
}
});
return new SetFieldCaseBuilder().setSetField(builder.build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase in project openflowplugin by opendaylight.
the class OfToSalSetFieldCase method process.
@Override
public Optional<Action> process(@Nonnull final SetFieldCase source, final ActionResponseConvertorData data, ConvertorExecutor convertorExecutor) {
final VersionDatapathIdConvertorData datapathIdConvertorData = new VersionDatapathIdConvertorData(data.getVersion());
final SetFieldAction setFieldAction = source.getSetFieldAction();
final SetFieldBuilder setField = new SetFieldBuilder();
final Optional<MatchBuilder> matchOptional = convertorExecutor.convert(setFieldAction, datapathIdConvertorData);
setField.fieldsFrom(matchOptional.orElse(new MatchBuilder()).build());
return Optional.of(new SetFieldCaseBuilder().setSetField(setField.build()).build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase in project openflowplugin by opendaylight.
the class OF13SetFieldActionSerializer method serialize.
@Override
// FB doesn't recognize Objects.requireNonNull
@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
public void serialize(Action action, ByteBuf outBuffer) {
Objects.requireNonNull(registry);
final int startIndex = outBuffer.writerIndex();
outBuffer.writeShort(ActionConstants.SET_FIELD_CODE);
final int lengthIndex = outBuffer.writerIndex();
outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
MatchEntry entry = ((SetFieldCase) action.getActionChoice()).getSetFieldAction().getMatchEntry().get(0);
MatchEntrySerializerKey<?, ?> key = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, entry.getOxmClass(), entry.getOxmMatchField());
if (entry.getOxmClass().equals(ExperimenterClass.class)) {
ExperimenterIdCase experimenterIdCase = (ExperimenterIdCase) entry.getMatchEntryValue();
key.setExperimenterId(experimenterIdCase.getExperimenter().getExperimenter().getValue());
} else {
key.setExperimenterId(null);
}
OFSerializer<MatchEntry> serializer = registry.getSerializer(key);
serializer.serialize(entry, outBuffer);
int paddingRemainder = (outBuffer.writerIndex() - startIndex) % EncodeConstants.PADDING;
if (paddingRemainder != 0) {
outBuffer.writeZero(EncodeConstants.PADDING - paddingRemainder);
}
outBuffer.setShort(lengthIndex, outBuffer.writerIndex() - startIndex);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactoryTest method testMultipartReplyGroupDescBody04.
/**
* Testing {@link MultipartReplyMessageFactory} for correct translation into POJO.
* Test covers bodies of actions NW TTL, Experimenter.
*/
@Test
public void testMultipartReplyGroupDescBody04() {
ByteBuf bb = BufferHelper.buildBuffer("00 07 00 01 00 00 00 00 " + // len
"00 30 " + // type
"01 " + // pad
"00 " + // groupId
"00 00 00 08 " + // bucketLen
"00 28 " + // bucketWeight
"00 06 " + // bucketWatchPort
"00 00 00 05 " + // bucketWatchGroup
"00 00 00 04 " + // bucketPad
"00 00 00 00 " + // nwTTlType
"00 17 " + // nwTTlLen
"00 08 " + // nwTTlnwTTL
"0E " + // nwTTlPad
"00 00 00 " + // setFieldType
"00 19 " + // setFieldLen
"00 10 " + // setFieldOXMClass
"80 00 " + // setFieldOXMField
"00 " + // setFieldOXMLength
"04 " + // setFieldPort
"00 00 00 FF " + "00 00 00 00");
MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
BufferHelper.checkHeaderV13(builtByFactory);
Assert.assertEquals("Wrong type", 7, builtByFactory.getType().getIntValue());
Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
MultipartReplyGroupDescCase messageCase = (MultipartReplyGroupDescCase) builtByFactory.getMultipartReplyBody();
MultipartReplyGroupDesc message = messageCase.getMultipartReplyGroupDesc();
Assert.assertEquals("Wrong type", 1, message.getGroupDesc().get(0).getType().getIntValue());
Assert.assertEquals("Wrong groupId", 8, message.getGroupDesc().get(0).getGroupId().getValue().intValue());
Assert.assertEquals("Wrong bucketWeight", 6, message.getGroupDesc().get(0).getBucketsList().get(0).getWeight().intValue());
Assert.assertEquals("Wrong bucketWatchPort", 5, message.getGroupDesc().get(0).getBucketsList().get(0).getWatchPort().getValue().intValue());
Assert.assertEquals("Wrong bucketWatchGroup", 4, message.getGroupDesc().get(0).getBucketsList().get(0).getWatchGroup().intValue());
Assert.assertTrue("Wrong nwTTlType", message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(0).getActionChoice() instanceof SetNwTtlCase);
Assert.assertEquals("Wrong nwTTlnwTTL", 14, ((SetNwTtlCase) message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(0).getActionChoice()).getSetNwTtlAction().getNwTtl().intValue());
Assert.assertTrue("Wrong setFieldType", message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(1).getActionChoice() instanceof SetFieldCase);
Assert.assertEquals("Wrong setFieldOXMClass", OpenflowBasicClass.class, ((SetFieldCase) message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(1).getActionChoice()).getSetFieldAction().getMatchEntry().get(0).getOxmClass());
Assert.assertEquals("Wrong setFieldOXMField", InPort.class, ((SetFieldCase) message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(1).getActionChoice()).getSetFieldAction().getMatchEntry().get(0).getOxmMatchField());
MatchEntry entry = ((SetFieldCase) message.getGroupDesc().get(0).getBucketsList().get(0).getAction().get(1).getActionChoice()).getSetFieldAction().getMatchEntry().get(0);
Assert.assertEquals("Wrong setFieldOXMValue", 255, ((InPortCase) entry.getMatchEntryValue()).getInPort().getPortNumber().getValue().intValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase in project openflowplugin by opendaylight.
the class ActionsDeserializerTest method testDeserializeHeader.
/**
* Tests {@link AbstractActionDeserializer#deserializeHeader(ByteBuf)}.
*/
@Test
public void testDeserializeHeader() {
ByteBuf message = BufferHelper.buildBuffer("00 00 00 04 00 19 00 04");
// skip XID
message.skipBytes(4);
CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
List<Action> actions = ListDeserializer.deserializeHeaders(EncodeConstants.OF13_VERSION_ID, message.readableBytes(), message, keyMaker, registry);
Assert.assertTrue("Wrong action type", actions.get(0).getActionChoice() instanceof OutputActionCase);
Assert.assertNull("Wrong action port", ((OutputActionCase) actions.get(0).getActionChoice()).getOutputAction());
Assert.assertNull("Wrong action max-length", ((OutputActionCase) actions.get(0).getActionChoice()).getOutputAction());
Assert.assertTrue("Wrong action type", actions.get(1).getActionChoice() instanceof SetFieldCase);
Assert.assertNull("Wrong action oxm field", ((SetFieldCase) actions.get(1).getActionChoice()).getSetFieldAction());
}
Aggregations