use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.peers.peer.Stats in project openflowplugin by opendaylight.
the class GroupStatsResponseConvertorTest method testGroupStatsWithBuckets.
/**
* Test GroupStats with buckets conversion.
*/
@Test
public void testGroupStatsWithBuckets() {
GroupStatsBuilder statsBuilder = new GroupStatsBuilder();
statsBuilder.setByteCount(new BigInteger("12345"));
statsBuilder.setDurationNsec(1000000L);
statsBuilder.setDurationSec(5000L);
statsBuilder.setGroupId(new GroupId(42L));
statsBuilder.setPacketCount(new BigInteger("54321"));
statsBuilder.setRefCount(24L);
List<BucketStats> bucketStats = new ArrayList<>();
BucketStatsBuilder bucketStatsBuilder = new BucketStatsBuilder();
bucketStatsBuilder.setByteCount(new BigInteger("987"));
bucketStatsBuilder.setPacketCount(new BigInteger("654"));
bucketStats.add(bucketStatsBuilder.build());
bucketStatsBuilder = new BucketStatsBuilder();
bucketStatsBuilder.setByteCount(new BigInteger("123"));
bucketStatsBuilder.setPacketCount(new BigInteger("456"));
bucketStats.add(bucketStatsBuilder.build());
statsBuilder.setBucketStats(bucketStats);
List<GroupStats> groupStats = new ArrayList<>();
groupStats.add(statsBuilder.build());
Optional<List<org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats>> salGroupStatsOptional = convertorManager.convert(groupStats, new VersionConvertorData(OFConstants.OFP_VERSION_1_3));
Assert.assertTrue("Group stats response convertor not found", salGroupStatsOptional.isPresent());
List<org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats> salGroupStats = salGroupStatsOptional.get();
Assert.assertEquals("Wrong group stats size", 1, salGroupStats.size());
org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats stat = salGroupStats.get(0);
Assert.assertEquals("Wrong group-id", 42, stat.getGroupId().getValue().intValue());
Assert.assertEquals("Wrong ref-count", 24, stat.getRefCount().getValue().intValue());
Assert.assertEquals("Wrong packet count", 54321, stat.getPacketCount().getValue().intValue());
Assert.assertEquals("Wrong byte count", 12345, stat.getByteCount().getValue().intValue());
Assert.assertEquals("Wrong duration sec", 5000, stat.getDuration().getSecond().getValue().intValue());
Assert.assertEquals("Wrong duration n sec", 1000000, stat.getDuration().getNanosecond().getValue().intValue());
Assert.assertEquals("Wrong bucket stats", 2, stat.getBuckets().getBucketCounter().size());
List<BucketCounter> list = stat.getBuckets().getBucketCounter();
Assert.assertEquals("Wrong bucket-id", 0, list.get(0).getBucketId().getValue().intValue());
Assert.assertEquals("Wrong bucket packet count", 654, list.get(0).getPacketCount().getValue().intValue());
Assert.assertEquals("Wrong bucket byte count", 987, list.get(0).getByteCount().getValue().intValue());
Assert.assertEquals("Wrong bucket-id", 1, list.get(1).getBucketId().getValue().intValue());
Assert.assertEquals("Wrong bucket packet count", 456, list.get(1).getPacketCount().getValue().intValue());
Assert.assertEquals("Wrong bucket byte count", 123, list.get(1).getByteCount().getValue().intValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.peers.peer.Stats 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.params.xml.ns.yang.bmp.monitor.rev171207.peers.peer.Stats 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.params.xml.ns.yang.bmp.monitor.rev171207.peers.peer.Stats in project openflowplugin by opendaylight.
the class NodeConnectorStatisticsToNotificationTransformer method transformToNotification.
/**
* Transform statistics to notification.
*
* @param mpReplyList raw multipart response from device
* @param deviceInfo device basic info
* @param ofVersion device version
* @param emulatedTxId emulated transaction Id
* @return notification containing flow stats
*/
public static NodeConnectorStatisticsUpdate transformToNotification(final List<MultipartReply> mpReplyList, final DeviceInfo deviceInfo, final OpenflowVersion ofVersion, final TransactionId emulatedTxId) {
NodeConnectorStatisticsUpdateBuilder notification = new NodeConnectorStatisticsUpdateBuilder();
notification.setId(deviceInfo.getNodeId());
notification.setMoreReplies(Boolean.FALSE);
notification.setTransactionId(emulatedTxId);
notification.setNodeConnectorStatisticsAndPortNumberMap(new ArrayList<>());
for (MultipartReply mpReply : mpReplyList) {
MultipartReplyPortStatsCase caseBody = (MultipartReplyPortStatsCase) mpReply.getMultipartReplyBody();
MultipartReplyPortStats replyBody = caseBody.getMultipartReplyPortStats();
for (PortStats portStats : replyBody.getPortStats()) {
NodeConnectorStatisticsAndPortNumberMapBuilder statsBuilder = processSingleNodeConnectorStats(deviceInfo, ofVersion, portStats);
notification.getNodeConnectorStatisticsAndPortNumberMap().add(statsBuilder.build());
}
}
return notification.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.peers.peer.Stats in project openflowplugin by opendaylight.
the class GroupDirectStatisticsServiceTest method testBuildReply.
@Override
public void testBuildReply() throws Exception {
final MultipartReply reply = mock(MultipartReply.class);
final MultipartReplyGroupCase groupCase = mock(MultipartReplyGroupCase.class);
final MultipartReplyGroup group = mock(MultipartReplyGroup.class);
final GroupStats groupStat = new GroupStatsBuilder().setGroupId(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId(GROUP_NO)).setByteCount(BigInteger.ONE).setPacketCount(BigInteger.ONE).setBucketStats(Collections.emptyList()).setDurationSec(1L).setDurationNsec(1L).setRefCount(0L).build();
final List<GroupStats> groupStats = Collections.singletonList(groupStat);
final List<MultipartReply> input = Collections.singletonList(reply);
when(group.getGroupStats()).thenReturn(groupStats);
when(groupCase.getMultipartReplyGroup()).thenReturn(group);
when(reply.getMultipartReplyBody()).thenReturn(groupCase);
final GetGroupStatisticsOutput output = service.buildReply(input, true);
assertTrue(output.getGroupStats().size() > 0);
final org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats stats = output.getGroupStats().get(0);
assertEquals(stats.getGroupId().getValue(), GROUP_NO);
}
Aggregations