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 SetNwSrcActionSerializer method buildAction.
@Override
protected SetFieldCase buildAction(Action input) {
final Address address = SetNwSrcActionCase.class.cast(input).getSetNwSrcAction().getAddress();
final SetFieldBuilder builder = new SetFieldBuilder();
if (Ipv4.class.isInstance(address)) {
builder.setLayer3Match(new Ipv4MatchBuilder().setIpv4Source(Ipv4.class.cast(address).getIpv4Address()).build());
} else if (Ipv6.class.isInstance(address)) {
builder.setLayer3Match(new Ipv6MatchBuilder().setIpv6Source(Ipv6.class.cast(address).getIpv6Address()).build());
}
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 SetTpDstActionSerializer method buildAction.
@Override
protected SetFieldCase buildAction(Action input) {
final SetTpDstAction setTpDstAction = SetTpDstActionCase.class.cast(input).getSetTpDstAction();
final PortNumber port = setTpDstAction.getPort();
final SetFieldBuilder builder = new SetFieldBuilder();
Optional.ofNullable(IPProtocols.fromProtocolNum(setTpDstAction.getIpProtocol())).ifPresent(proto -> {
switch(proto) {
case ICMP:
{
builder.setIcmpv4Match(new Icmpv4MatchBuilder().setIcmpv4Code((short) (0xFF & port.getValue())).build());
break;
}
case ICMPV6:
{
builder.setIcmpv6Match(new Icmpv6MatchBuilder().setIcmpv6Code((short) (0xFF & port.getValue())).build());
break;
}
case TCP:
{
builder.setLayer4Match(new TcpMatchBuilder().setTcpDestinationPort(port).build());
break;
}
case UDP:
{
builder.setLayer4Match(new UdpMatchBuilder().setUdpDestinationPort(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 SetFieldActionSerializer method serialize.
@Override
public void serialize(SetFieldCase action, ByteBuf outBuffer) {
// Serialize field type and save position
final int startIndex = outBuffer.writerIndex();
outBuffer.writeShort(getType());
final int lengthIndex = outBuffer.writerIndex();
outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
// Serialize match (using small workaround with serializeHeader method to serialize only match entries)
final SetField setField = action.getSetField();
final HeaderSerializer<Match> serializer = Preconditions.checkNotNull(registry).getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Match.class));
serializer.serializeHeader(setField, outBuffer);
// Serialize padding based on match length
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 SetNwDstActionSerializer method buildAction.
@Override
protected SetFieldCase buildAction(Action input) {
final Address address = SetNwDstActionCase.class.cast(input).getSetNwDstAction().getAddress();
final SetFieldBuilder builder = new SetFieldBuilder();
if (Ipv4.class.isInstance(address)) {
builder.setLayer3Match(new Ipv4MatchBuilder().setIpv4Destination(Ipv4.class.cast(address).getIpv4Address()).build());
} else if (Ipv6.class.isInstance(address)) {
builder.setLayer3Match(new Ipv6MatchBuilder().setIpv6Destination(Ipv6.class.cast(address).getIpv6Address()).build());
}
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 ActionsDeserializerTest method test.
/**
* Testing actions deserialization.
*/
@Test
public void test() {
ByteBuf message = BufferHelper.buildBuffer("00 00 00 10 00 00 00 01 00 02 00 00 00 00 00 00 " + "00 0B 00 08 00 00 00 00 " + "00 0C 00 08 00 00 00 00 " + "00 0F 00 08 03 00 00 00 " + "00 10 00 08 00 00 00 00 " + "00 11 00 08 00 04 00 00 " + "00 12 00 08 00 00 00 00 " + "00 13 00 08 00 05 00 00 " + "00 14 00 08 00 06 00 00 " + "00 15 00 08 00 00 00 07 " + "00 16 00 08 00 00 00 08 " + "00 17 00 08 09 00 00 00 " + "00 18 00 08 00 00 00 00 " + "00 19 00 10 80 00 02 04 00 00 00 0B 00 00 00 00 " + "00 1A 00 08 00 0A 00 00 " + "00 1B 00 08 00 00 00 00");
// skip XID
message.skipBytes(4);
LOG.info("bytes: {}", message.readableBytes());
CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, message.readableBytes(), message, keyMaker, registry);
Assert.assertTrue("Wrong action type", actions.get(0).getActionChoice() instanceof OutputActionCase);
Assert.assertEquals("Wrong action port", 1, ((OutputActionCase) actions.get(0).getActionChoice()).getOutputAction().getPort().getValue().intValue());
Assert.assertEquals("Wrong action max-length", 2, ((OutputActionCase) actions.get(0).getActionChoice()).getOutputAction().getMaxLength().intValue());
Assert.assertTrue("Wrong action type", actions.get(1).getActionChoice() instanceof CopyTtlOutCase);
Assert.assertTrue("Wrong action type", actions.get(2).getActionChoice() instanceof CopyTtlInCase);
Assert.assertTrue("Wrong action type", actions.get(3).getActionChoice() instanceof SetMplsTtlCase);
Assert.assertEquals("Wrong action value", 3, ((SetMplsTtlCase) actions.get(3).getActionChoice()).getSetMplsTtlAction().getMplsTtl().shortValue());
Assert.assertTrue("Wrong action type", actions.get(4).getActionChoice() instanceof DecMplsTtlCase);
Assert.assertTrue("Wrong action type", actions.get(5).getActionChoice() instanceof PushVlanCase);
Assert.assertEquals("Wrong action value", 4, ((PushVlanCase) actions.get(5).getActionChoice()).getPushVlanAction().getEthertype().getValue().intValue());
Assert.assertTrue("Wrong action type", actions.get(6).getActionChoice() instanceof PopVlanCase);
Assert.assertTrue("Wrong action type", actions.get(7).getActionChoice() instanceof PushMplsCase);
Assert.assertEquals("Wrong action value", 5, ((PushMplsCase) actions.get(7).getActionChoice()).getPushMplsAction().getEthertype().getValue().intValue());
Assert.assertTrue("Wrong action type", actions.get(8).getActionChoice() instanceof PopMplsCase);
Assert.assertEquals("Wrong action value", 6, ((PopMplsCase) actions.get(8).getActionChoice()).getPopMplsAction().getEthertype().getValue().intValue());
Assert.assertTrue("Wrong action type", actions.get(9).getActionChoice() instanceof SetQueueCase);
Assert.assertEquals("Wrong action value", 7, ((SetQueueCase) actions.get(9).getActionChoice()).getSetQueueAction().getQueueId().intValue());
Assert.assertTrue("Wrong action type", actions.get(10).getActionChoice() instanceof GroupCase);
Assert.assertEquals("Wrong action value", 8, ((GroupCase) actions.get(10).getActionChoice()).getGroupAction().getGroupId().intValue());
Assert.assertTrue("Wrong action type", actions.get(11).getActionChoice() instanceof SetNwTtlCase);
Assert.assertEquals("Wrong action value", 9, ((SetNwTtlCase) actions.get(11).getActionChoice()).getSetNwTtlAction().getNwTtl().intValue());
Assert.assertTrue("Wrong action type", actions.get(12).getActionChoice() instanceof DecNwTtlCase);
Assert.assertTrue("Wrong action type", actions.get(13).getActionChoice() instanceof SetFieldCase);
List<MatchEntry> entries = ((SetFieldCase) actions.get(13).getActionChoice()).getSetFieldAction().getMatchEntry();
Assert.assertEquals("Wrong number of fields", 1, entries.size());
Assert.assertEquals("Wrong match entry class", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow." + "oxm.rev150225.OpenflowBasicClass", entries.get(0).getOxmClass().getName());
Assert.assertEquals("Wrong match entry field", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow." + "oxm.rev150225.InPhyPort", entries.get(0).getOxmMatchField().getName());
Assert.assertEquals("Wrong match entry mask", false, entries.get(0).isHasMask());
Assert.assertEquals("Wrong match entry value", 11, ((InPhyPortCase) entries.get(0).getMatchEntryValue()).getInPhyPort().getPortNumber().getValue().intValue());
Assert.assertTrue("Wrong action type", actions.get(14).getActionChoice() instanceof PushPbbCase);
Assert.assertEquals("Wrong action value", 10, ((PushPbbCase) actions.get(14).getActionChoice()).getPushPbbAction().getEthertype().getValue().intValue());
Assert.assertTrue("Wrong action type", actions.get(15).getActionChoice() instanceof PopPbbCase);
Assert.assertTrue("Unread data in message", message.readableBytes() == 0);
}
Aggregations