use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase in project openflowplugin by opendaylight.
the class OF10StatsReplyMessageFactory method setFlow.
private MultipartReplyFlowCase setFlow(ByteBuf input) {
MultipartReplyFlowCaseBuilder caseBuilder = new MultipartReplyFlowCaseBuilder();
MultipartReplyFlowBuilder flowBuilder = new MultipartReplyFlowBuilder();
List<FlowStats> flowStatsList = new ArrayList<>();
while (input.readableBytes() > 0) {
FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder();
final int length = input.readUnsignedShort();
flowStatsBuilder.setTableId(input.readUnsignedByte());
input.skipBytes(PADDING_IN_FLOW_STATS_HEADER);
OFDeserializer<MatchV10> matchDeserializer = registry.getDeserializer(new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class));
flowStatsBuilder.setMatchV10(matchDeserializer.deserialize(input));
flowStatsBuilder.setDurationSec(input.readUnsignedInt());
flowStatsBuilder.setDurationNsec(input.readUnsignedInt());
flowStatsBuilder.setPriority(input.readUnsignedShort());
flowStatsBuilder.setIdleTimeout(input.readUnsignedShort());
flowStatsBuilder.setHardTimeout(input.readUnsignedShort());
input.skipBytes(PADDING_IN_FLOW_STATS_HEADER_02);
byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(cookie);
flowStatsBuilder.setCookie(new BigInteger(1, cookie));
byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(packetCount);
flowStatsBuilder.setPacketCount(new BigInteger(1, packetCount));
byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(byteCount);
flowStatsBuilder.setByteCount(new BigInteger(1, byteCount));
CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF10_VERSION_ID);
List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF10_VERSION_ID, length - LENGTH_OF_FLOW_STATS, input, keyMaker, registry);
flowStatsBuilder.setAction(actions);
flowStatsList.add(flowStatsBuilder.build());
}
flowBuilder.setFlowStats(flowStatsList);
caseBuilder.setMultipartReplyFlow(flowBuilder.build());
return caseBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase in project openflowplugin by opendaylight.
the class OF10StatsReplyMessageFactoryTest method testFlow.
/**
* Testing OF10StatsReplyMessageFactory (Flow) for correct deserialization.
*/
@Test
public void testFlow() {
ByteBuf bb = BufferHelper.buildBuffer("00 01 00 01 00 68 01 00 " + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 " + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 " + "00 00 00 02 00 00 00 03 00 04 00 05 00 06 00 00 00 00 00 00 " + "FF 01 02 03 04 05 06 07 FF 01 02 03 04 05 06 07 FF 00 00 00 00 00 00 20 " + "00 00 00 08 00 01 00 02 00 01 00 08 00 03 00 00");
MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb);
BufferHelper.checkHeaderV10(builtByFactory);
Assert.assertEquals("Wrong type", 0x01, builtByFactory.getType().getIntValue());
Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE().booleanValue());
MultipartReplyFlowCase messageCase = (MultipartReplyFlowCase) builtByFactory.getMultipartReplyBody();
MultipartReplyFlow message = messageCase.getMultipartReplyFlow();
Assert.assertEquals("Wrong tableId", 1, message.getFlowStats().get(0).getTableId().intValue());
Assert.assertEquals("Wrong durationSec", 2, message.getFlowStats().get(0).getDurationSec().intValue());
Assert.assertEquals("Wrong durationNsec", 3, message.getFlowStats().get(0).getDurationNsec().intValue());
Assert.assertEquals("Wrong priority", 4, message.getFlowStats().get(0).getPriority().intValue());
Assert.assertEquals("Wrong idleTimeOut", 5, message.getFlowStats().get(0).getIdleTimeout().intValue());
Assert.assertEquals("Wrong hardTimeOut", 6, message.getFlowStats().get(0).getHardTimeout().intValue());
Assert.assertEquals("Wrong cookie", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }), message.getFlowStats().get(0).getCookie());
Assert.assertEquals("Wrong packetCount", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }), message.getFlowStats().get(0).getPacketCount());
Assert.assertEquals("Wrong byteCount", new BigInteger(1, new byte[] { (byte) 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20 }), message.getFlowStats().get(0).getByteCount());
Action action1 = message.getFlowStats().get(0).getAction().get(0);
Assert.assertTrue("Wrong action type", action1.getActionChoice() instanceof OutputActionCase);
Assert.assertEquals("Wrong action port", 1, ((OutputActionCase) action1.getActionChoice()).getOutputAction().getPort().getValue().intValue());
Assert.assertEquals("Wrong action port", 2, ((OutputActionCase) action1.getActionChoice()).getOutputAction().getMaxLength().intValue());
Action action2 = message.getFlowStats().get(0).getAction().get(1);
Assert.assertTrue("Wrong action type", action2.getActionChoice() instanceof SetVlanVidCase);
Assert.assertEquals("Wrong action port", 3, ((SetVlanVidCase) action2.getActionChoice()).getSetVlanVidAction().getVlanVid().intValue());
Assert.assertTrue("Unread data", bb.readableBytes() == 0);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase in project openflowplugin by opendaylight.
the class MultipartReplyFlowTest method testEmptyMultipartReplyFlowBody.
/**
* Testing {@link MultipartReplyMessageFactory} for correct translation into POJO.
*/
@Test
public void testEmptyMultipartReplyFlowBody() {
ByteBuf bb = BufferHelper.buildBuffer("00 01 00 01 00 00 00 00");
MultipartReplyMessage builtByFactory = BufferHelper.deserialize(factory, bb);
BufferHelper.checkHeaderV13(builtByFactory);
Assert.assertEquals("Wrong type", 0x01, builtByFactory.getType().getIntValue());
Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
MultipartReplyFlowCase messageCase = (MultipartReplyFlowCase) builtByFactory.getMultipartReplyBody();
MultipartReplyFlow message = messageCase.getMultipartReplyFlow();
Assert.assertEquals("Wrong flow stats size", 0, message.getFlowStats().size());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase in project openflowplugin by opendaylight.
the class MultipartReplyFlowTest method testMultipartReplyFlowBody.
/**
* Testing {@link MultipartReplyMessageFactory} for correct translation into POJO.
*/
@Test
public void testMultipartReplyFlowBody() {
ByteBuf bb = BufferHelper.buildBuffer(//
"00 01 00 01 00 00 00 00 " + // first flow stat
"00 48 08 00 " + // length, tableId, padding
"00 00 00 09 " + // durationSec
"00 00 00 07 " + // durationNsec
"00 0C 00 0E 00 0F 00 1F " + // priority, idleTimeout, hardTimeout, flags
"00 00 00 00 " + // pad_02
"FF 01 01 01 01 01 01 01 " + // cookie
"EF 01 01 01 01 01 01 01 " + // packetCount
"7F 01 01 01 01 01 01 01 " + // byteCount
"00 01 00 04 00 00 00 00 " + // empty match
"00 01 00 08 06 00 00 00 " + //
"00 01 00 08 06 00 00 00 " + // second flow stat
"00 48 08 00 " + // length, tableId, padding
"00 00 00 09 " + // durationSec
"00 00 00 07 " + // durationNsec
"00 0C 00 0E 00 0F 00 00 " + // priority, idleTimeout, hardTimeout, flags
"00 00 00 00 " + // pad_02
"FF 01 01 01 01 01 01 01 " + // cookie
"EF 01 01 01 01 01 01 01 " + // packetCount
"7F 01 01 01 01 01 01 01 " + // byteCount
"00 01 00 04 00 00 00 00 " + // empty match
"00 01 00 08 06 00 00 00 " + //
"00 01 00 08 06 00 00 00");
MultipartReplyMessage builtByFactory = BufferHelper.deserialize(factory, bb);
BufferHelper.checkHeaderV13(builtByFactory);
Assert.assertEquals("Wrong type", 0x01, builtByFactory.getType().getIntValue());
Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
MultipartReplyFlowCase messageCase = (MultipartReplyFlowCase) builtByFactory.getMultipartReplyBody();
MultipartReplyFlow message = messageCase.getMultipartReplyFlow();
Assert.assertEquals("Wrong flow stats size", 2, message.getFlowStats().size());
FlowStats flowStats1 = message.getFlowStats().get(0);
Assert.assertEquals("Wrong tableId", 8, flowStats1.getTableId().intValue());
Assert.assertEquals("Wrong durationSec", 9, flowStats1.getDurationSec().intValue());
Assert.assertEquals("Wrong durationNsec", 7, flowStats1.getDurationNsec().intValue());
Assert.assertEquals("Wrong priority", 12, flowStats1.getPriority().intValue());
Assert.assertEquals("Wrong idleTimeOut", 14, flowStats1.getIdleTimeout().intValue());
Assert.assertEquals("Wrong hardTimeOut", 15, flowStats1.getHardTimeout().intValue());
Assert.assertEquals("Wrong flags", new FlowModFlags(true, true, true, true, true), flowStats1.getFlags());
Assert.assertEquals("Wrong cookie", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), flowStats1.getCookie());
Assert.assertEquals("Wrong packetCount", new BigInteger(1, new byte[] { (byte) 0xEF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), flowStats1.getPacketCount());
Assert.assertEquals("Wrong byteCount", new BigInteger(1, new byte[] { (byte) 0x7F, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), flowStats1.getByteCount());
Assert.assertEquals("Wrong match type", OxmMatchType.class, flowStats1.getMatch().getType());
flowStats1 = message.getFlowStats().get(1);
Assert.assertEquals("Wrong tableId", 8, flowStats1.getTableId().intValue());
Assert.assertEquals("Wrong durationSec", 9, flowStats1.getDurationSec().intValue());
Assert.assertEquals("Wrong durationNsec", 7, flowStats1.getDurationNsec().intValue());
Assert.assertEquals("Wrong priority", 12, flowStats1.getPriority().intValue());
Assert.assertEquals("Wrong idleTimeOut", 14, flowStats1.getIdleTimeout().intValue());
Assert.assertEquals("Wrong hardTimeOut", 15, flowStats1.getHardTimeout().intValue());
Assert.assertEquals("Wrong flags", new FlowModFlags(false, false, false, false, false), flowStats1.getFlags());
Assert.assertEquals("Wrong cookie", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), flowStats1.getCookie());
Assert.assertEquals("Wrong packetCount", new BigInteger(1, new byte[] { (byte) 0xEF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), flowStats1.getPacketCount());
Assert.assertEquals("Wrong byteCount", new BigInteger(1, new byte[] { (byte) 0x7F, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), flowStats1.getByteCount());
Assert.assertEquals("Wrong match type", OxmMatchType.class, flowStats1.getMatch().getType());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase in project openflowplugin by opendaylight.
the class OF10StatsReplyMessageFactory method serializeFlowBody.
private void serializeFlowBody(MultipartReplyBody body, ByteBuf outBuffer, MultipartReplyMessage message) {
MultipartReplyFlowCase flowCase = (MultipartReplyFlowCase) body;
MultipartReplyFlow flow = flowCase.getMultipartReplyFlow();
for (FlowStats flowStats : flow.getFlowStats()) {
ByteBuf flowStatsBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
flowStatsBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
flowStatsBuff.writeByte((byte) flowStats.getTableId().longValue());
flowStatsBuff.writeZero(FLOW_STATS_PADDING_1);
OFSerializer<MatchV10> matchSerializer = registry.getSerializer(new MessageTypeKey<>(message.getVersion(), MatchV10.class));
matchSerializer.serialize(flowStats.getMatchV10(), flowStatsBuff);
flowStatsBuff.writeInt(flowStats.getDurationSec().intValue());
flowStatsBuff.writeInt(flowStats.getDurationNsec().intValue());
flowStatsBuff.writeShort(flowStats.getPriority());
flowStatsBuff.writeShort(flowStats.getIdleTimeout());
flowStatsBuff.writeShort(flowStats.getHardTimeout());
flowStatsBuff.writeZero(FLOW_STATS_PADDING_2);
flowStatsBuff.writeLong(flowStats.getCookie().longValue());
flowStatsBuff.writeLong(flowStats.getPacketCount().longValue());
flowStatsBuff.writeLong(flowStats.getByteCount().longValue());
ListSerializer.serializeList(flowStats.getAction(), ACTION_KEY_MAKER, registry, flowStatsBuff);
flowStatsBuff.setShort(FLOW_STATS_LENGTH_INDEX, flowStatsBuff.readableBytes());
outBuffer.writeBytes(flowStatsBuff);
}
}
Aggregations