use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow 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.multipart.reply.flow._case.MultipartReplyFlow 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.multipart.reply.flow._case.MultipartReplyFlow 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);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow in project openflowplugin by opendaylight.
the class FlowStatisticsToNotificationTransformer method transformToNotification.
/**
* Transform to notification.
*
* @param mpResult raw multipart response from device
* @param deviceInfo device state
* @param ofVersion device version
* @param emulatedTxId emulated transaction Id
* @param convertorExecutor convertor executor
* @return notification containing flow stats
*/
public static FlowsStatisticsUpdate transformToNotification(final List<MultipartReply> mpResult, final DeviceInfo deviceInfo, final OpenflowVersion ofVersion, final TransactionId emulatedTxId, final ConvertorExecutor convertorExecutor) {
final FlowStatsResponseConvertorData data = new FlowStatsResponseConvertorData(ofVersion.getVersion());
data.setDatapathId(deviceInfo.getDatapathId());
data.setMatchPath(MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
final FlowsStatisticsUpdateBuilder notification = new FlowsStatisticsUpdateBuilder();
final List<FlowAndStatisticsMapList> statsList = new ArrayList<>();
notification.setId(deviceInfo.getNodeId());
notification.setFlowAndStatisticsMapList(statsList);
notification.setMoreReplies(Boolean.FALSE);
notification.setTransactionId(emulatedTxId);
for (MultipartReply mpRawReply : mpResult) {
Preconditions.checkArgument(MultipartType.OFPMPFLOW.equals(mpRawReply.getType()));
MultipartReplyFlowCase caseBody = (MultipartReplyFlowCase) mpRawReply.getMultipartReplyBody();
MultipartReplyFlow replyBody = caseBody.getMultipartReplyFlow();
final Optional<List<FlowAndStatisticsMapList>> outStatsItem = convertorExecutor.convert(replyBody.getFlowStats(), data);
outStatsItem.ifPresent(statsList::addAll);
}
return notification.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow in project openflowplugin by opendaylight.
the class FlowDirectStatisticsService method buildReply.
@Override
protected GetFlowStatisticsOutput buildReply(List<MultipartReply> input, boolean success) {
final List<FlowAndStatisticsMapList> statsList = new ArrayList<>();
if (success) {
for (final MultipartReply mpReply : input) {
final MultipartReplyFlowCase caseBody = (MultipartReplyFlowCase) mpReply.getMultipartReplyBody();
final MultipartReplyFlow replyBody = caseBody.getMultipartReplyFlow();
final Optional<List<FlowAndStatisticsMapList>> statsListPart = getConvertorExecutor().convert(replyBody.getFlowStats(), data);
statsListPart.ifPresent(flowAndStatisticsMapLists -> {
for (final FlowAndStatisticsMapList part : flowAndStatisticsMapLists) {
final FlowId flowId = new FlowId(generateFlowId(part).getValue());
statsList.add(new FlowAndStatisticsMapListBuilder(part).setKey(new FlowAndStatisticsMapListKey(flowId)).setFlowId(flowId).build());
}
});
}
}
return new GetFlowStatisticsOutputBuilder().setFlowAndStatisticsMapList(statsList).build();
}
Aggregations