use of org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.multipart.reply.multipart.reply.body.MultipartReplyPortStats in project openflowplugin by opendaylight.
the class OF10StatsReplyMessageFactoryTest method testPortStatsBodySerialize.
@Test
public void testPortStatsBodySerialize() throws Exception {
MultipartReplyMessageBuilder builder;
builder = new MultipartReplyMessageBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
builder.setFlags(new MultipartRequestFlags(true));
builder.setType(MultipartType.forValue(4));
MultipartReplyPortStatsCaseBuilder portStatsCase = new MultipartReplyPortStatsCaseBuilder();
MultipartReplyPortStatsBuilder portStats = new MultipartReplyPortStatsBuilder();
portStats.setPortStats(createPortStats());
portStatsCase.setMultipartReplyPortStats(portStats.build());
builder.setMultipartReplyBody(portStatsCase.build());
MultipartReplyMessage message = builder.build();
ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
factory.serialize(message, serializedBuffer);
BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 118);
Assert.assertEquals("Wrong type", MultipartType.OFPMPPORTSTATS.getIntValue(), serializedBuffer.readShort());
Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort()));
MultipartReplyPortStatsCase body = (MultipartReplyPortStatsCase) message.getMultipartReplyBody();
MultipartReplyPortStats messageOutput = body.getMultipartReplyPortStats();
PortStats portStatsOutput = messageOutput.getPortStats().get(0);
Assert.assertEquals("Wrong port no", portStatsOutput.getPortNo().intValue(), serializedBuffer.readInt());
serializedBuffer.skipBytes(6);
Assert.assertEquals("Wrong rx packets", portStatsOutput.getRxPackets().longValue(), serializedBuffer.readLong());
Assert.assertEquals("Wrong tx packets", portStatsOutput.getTxPackets().longValue(), serializedBuffer.readLong());
Assert.assertEquals("Wrong rx bytes", portStatsOutput.getRxBytes().longValue(), serializedBuffer.readLong());
Assert.assertEquals("Wrong tx bytes", portStatsOutput.getTxBytes().longValue(), serializedBuffer.readLong());
Assert.assertEquals("Wrong rx dropped", portStatsOutput.getRxDropped().longValue(), serializedBuffer.readLong());
Assert.assertEquals("Wrong tx dropped", portStatsOutput.getTxDropped().longValue(), serializedBuffer.readLong());
Assert.assertEquals("Wrong rx errors", portStatsOutput.getRxErrors().longValue(), serializedBuffer.readLong());
Assert.assertEquals("Wrong tx errors", portStatsOutput.getTxErrors().longValue(), serializedBuffer.readLong());
Assert.assertEquals("Wrong rx frame err", portStatsOutput.getRxFrameErr().longValue(), serializedBuffer.readLong());
Assert.assertEquals("Wrong rx over err", portStatsOutput.getRxOverErr().longValue(), serializedBuffer.readLong());
Assert.assertEquals("Wrong rx crc err", portStatsOutput.getRxCrcErr().longValue(), serializedBuffer.readLong());
Assert.assertEquals("Wrong collisions", portStatsOutput.getCollisions().longValue(), serializedBuffer.readLong());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.multipart.reply.multipart.reply.body.MultipartReplyPortStats in project openflowplugin by opendaylight.
the class OF10StatsReplyMessageFactoryTest method testPort.
/**
* Testing OF10StatsReplyMessageFactory (Port) for correct deserialization.
*/
@Test
public void testPort() {
ByteBuf bb = BufferHelper.buildBuffer("00 04 00 01 " + "00 FF 00 00 00 00 00 00 " + "FF 01 01 01 01 01 01 01 FF 02 02 02 02 02 02 02 " + "FF 02 03 02 03 02 03 02 FF 02 03 02 03 02 03 02 " + "FF 02 03 02 03 02 03 02 FF 02 03 02 03 02 03 02 " + "FF 02 03 02 03 02 03 02 FF 02 03 02 03 02 03 02 " + "FF 02 03 02 03 02 03 02 FF 02 03 02 03 02 03 02 FF 02 03 02 03 02 03 02 " + "FF 02 03 02 03 02 03 02");
MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb);
BufferHelper.checkHeaderV10(builtByFactory);
Assert.assertEquals("Wrong type", 0x04, builtByFactory.getType().getIntValue());
Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
MultipartReplyPortStatsCase messageCase = (MultipartReplyPortStatsCase) builtByFactory.getMultipartReplyBody();
MultipartReplyPortStats message = messageCase.getMultipartReplyPortStats();
Assert.assertEquals("Wrong portNo", 255, message.getPortStats().get(0).getPortNo().intValue());
Assert.assertEquals("Wrong rxPackets", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getPortStats().get(0).getRxPackets());
Assert.assertEquals("Wrong txPackets", new BigInteger(1, new byte[] { (byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 }), message.getPortStats().get(0).getTxPackets());
Assert.assertEquals("Wrong rxBytes", new BigInteger(1, new byte[] { (byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02 }), message.getPortStats().get(0).getRxBytes());
Assert.assertEquals("Wrong txBytes", new BigInteger(1, new byte[] { (byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02 }), message.getPortStats().get(0).getTxBytes());
Assert.assertEquals("Wrong rxDropped", new BigInteger(1, new byte[] { (byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02 }), message.getPortStats().get(0).getRxDropped());
Assert.assertEquals("Wrong txDropped", new BigInteger(1, new byte[] { (byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02 }), message.getPortStats().get(0).getTxDropped());
Assert.assertEquals("Wrong rxErrors", new BigInteger(1, new byte[] { (byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02 }), message.getPortStats().get(0).getRxErrors());
Assert.assertEquals("Wrong txErrors", new BigInteger(1, new byte[] { (byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02 }), message.getPortStats().get(0).getTxErrors());
Assert.assertEquals("Wrong rxFrameErr", new BigInteger(1, new byte[] { (byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02 }), message.getPortStats().get(0).getRxFrameErr());
Assert.assertEquals("Wrong rxOverErr", new BigInteger(1, new byte[] { (byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02 }), message.getPortStats().get(0).getRxOverErr());
Assert.assertEquals("Wrong rxCrcErr", new BigInteger(1, new byte[] { (byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02 }), message.getPortStats().get(0).getRxCrcErr());
Assert.assertEquals("Wrong collisions", new BigInteger(1, new byte[] { (byte) 0xFF, 0x02, 0x03, 0x02, 0x03, 0x02, 0x03, 0x02 }), message.getPortStats().get(0).getCollisions());
Assert.assertTrue("Unread data", bb.readableBytes() == 0);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.multipart.reply.multipart.reply.body.MultipartReplyPortStats 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.port.statistics.rev131214.multipart.reply.multipart.reply.body.MultipartReplyPortStats in project openflowplugin by opendaylight.
the class NodeConnectorDirectStatisticsServiceTest method testBuildReply.
@Override
public void testBuildReply() throws Exception {
final MultipartReply reply = mock(MultipartReply.class);
final MultipartReplyPortStatsCase nodeConnectorCase = mock(MultipartReplyPortStatsCase.class);
final MultipartReplyPortStats nodeConnector = mock(MultipartReplyPortStats.class);
final PortStats nodeConnectorStat = mock(PortStats.class);
final List<PortStats> nodeConnectorStats = Collections.singletonList(nodeConnectorStat);
final List<MultipartReply> input = Collections.singletonList(reply);
when(nodeConnector.getPortStats()).thenReturn(nodeConnectorStats);
when(nodeConnectorCase.getMultipartReplyPortStats()).thenReturn(nodeConnector);
when(reply.getMultipartReplyBody()).thenReturn(nodeConnectorCase);
when(nodeConnectorStat.getPortNo()).thenReturn(PORT_NO);
when(nodeConnectorStat.getTxBytes()).thenReturn(BigInteger.ONE);
when(nodeConnectorStat.getCollisions()).thenReturn(BigInteger.ONE);
when(nodeConnectorStat.getRxBytes()).thenReturn(BigInteger.ONE);
when(nodeConnectorStat.getRxCrcErr()).thenReturn(BigInteger.ONE);
when(nodeConnectorStat.getRxDropped()).thenReturn(BigInteger.ONE);
when(nodeConnectorStat.getRxErrors()).thenReturn(BigInteger.ONE);
when(nodeConnectorStat.getRxFrameErr()).thenReturn(BigInteger.ONE);
when(nodeConnectorStat.getRxOverErr()).thenReturn(BigInteger.ONE);
when(nodeConnectorStat.getRxPackets()).thenReturn(BigInteger.ONE);
when(nodeConnectorStat.getTxDropped()).thenReturn(BigInteger.ONE);
when(nodeConnectorStat.getTxErrors()).thenReturn(BigInteger.ONE);
final GetNodeConnectorStatisticsOutput output = service.buildReply(input, true);
assertTrue(output.getNodeConnectorStatisticsAndPortNumberMap().size() > 0);
final NodeConnectorStatisticsAndPortNumberMap stats = output.getNodeConnectorStatisticsAndPortNumberMap().get(0);
assertEquals(stats.getNodeConnectorId(), nodeConnectorId);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.multipart.reply.multipart.reply.body.MultipartReplyPortStats in project openflowplugin by opendaylight.
the class OF10StatsReplyMessageFactory method serializePortStatsBody.
private void serializePortStatsBody(MultipartReplyBody body, ByteBuf outBuffer) {
MultipartReplyPortStatsCase portStatsCase = (MultipartReplyPortStatsCase) body;
MultipartReplyPortStats portStats = portStatsCase.getMultipartReplyPortStats();
for (PortStats portStat : portStats.getPortStats()) {
outBuffer.writeInt(portStat.getPortNo().intValue());
outBuffer.writeZero(PORT_STATS_PADDING);
outBuffer.writeLong(portStat.getRxPackets().longValue());
outBuffer.writeLong(portStat.getTxPackets().longValue());
outBuffer.writeLong(portStat.getRxBytes().longValue());
outBuffer.writeLong(portStat.getTxBytes().longValue());
outBuffer.writeLong(portStat.getRxDropped().longValue());
outBuffer.writeLong(portStat.getTxDropped().longValue());
outBuffer.writeLong(portStat.getRxErrors().longValue());
outBuffer.writeLong(portStat.getTxErrors().longValue());
outBuffer.writeLong(portStat.getRxFrameErr().longValue());
outBuffer.writeLong(portStat.getRxOverErr().longValue());
outBuffer.writeLong(portStat.getRxCrcErr().longValue());
outBuffer.writeLong(portStat.getCollisions().longValue());
}
}
Aggregations