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 MultipartReplyTranslatorUtil method translatePortStats.
private static org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.multipart.reply.multipart.reply.body.MultipartReplyPortStats translatePortStats(final MultipartReply msg, final OpenflowVersion ofVersion, final BigInteger datapathId) {
MultipartReplyPortStatsBuilder message = new MultipartReplyPortStatsBuilder();
MultipartReplyPortStatsCase caseBody = (MultipartReplyPortStatsCase) msg.getMultipartReplyBody();
MultipartReplyPortStats replyBody = caseBody.getMultipartReplyPortStats();
List<NodeConnectorStatisticsAndPortNumberMap> statsMap = new ArrayList<>();
for (PortStats portStats : replyBody.getPortStats()) {
NodeConnectorStatisticsAndPortNumberMapBuilder statsBuilder = new NodeConnectorStatisticsAndPortNumberMapBuilder();
statsBuilder.setNodeConnectorId(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathId, portStats.getPortNo(), ofVersion));
BytesBuilder bytesBuilder = new BytesBuilder();
bytesBuilder.setReceived(portStats.getRxBytes());
bytesBuilder.setTransmitted(portStats.getTxBytes());
statsBuilder.setBytes(bytesBuilder.build());
PacketsBuilder packetsBuilder = new PacketsBuilder();
packetsBuilder.setReceived(portStats.getRxPackets());
packetsBuilder.setTransmitted(portStats.getTxPackets());
statsBuilder.setPackets(packetsBuilder.build());
DurationBuilder durationBuilder = new DurationBuilder();
if (portStats.getDurationSec() != null) {
durationBuilder.setSecond(new Counter32(portStats.getDurationSec()));
}
if (portStats.getDurationNsec() != null) {
durationBuilder.setNanosecond(new Counter32(portStats.getDurationNsec()));
}
statsBuilder.setDuration(durationBuilder.build());
statsBuilder.setCollisionCount(portStats.getCollisions());
statsBuilder.setKey(new NodeConnectorStatisticsAndPortNumberMapKey(statsBuilder.getNodeConnectorId()));
statsBuilder.setReceiveCrcError(portStats.getRxCrcErr());
statsBuilder.setReceiveDrops(portStats.getRxDropped());
statsBuilder.setReceiveErrors(portStats.getRxErrors());
statsBuilder.setReceiveFrameError(portStats.getRxFrameErr());
statsBuilder.setReceiveOverRunError(portStats.getRxOverErr());
statsBuilder.setTransmitDrops(portStats.getTxDropped());
statsBuilder.setTransmitErrors(portStats.getTxErrors());
statsMap.add(statsBuilder.build());
}
message.setNodeConnectorStatisticsAndPortNumberMap(statsMap);
return message.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 MultipartReplyMessageFactory method serializePortStatsBody.
private void serializePortStatsBody(final MultipartReplyBody body, final 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());
outBuffer.writeInt(portStat.getDurationSec().intValue());
outBuffer.writeInt(portStat.getDurationNsec().intValue());
}
}
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 MultipartReplyMessageFactoryTest method testMultipartReplyPortStatsBody.
/**
* Testing {@link MultipartReplyMessageFactory} for correct translation into POJO.
*/
@Test
public void testMultipartReplyPortStatsBody() {
ByteBuf bb = BufferHelper.buildBuffer("00 04 00 01 00 00 00 00 " + // portNo
"00 00 00 FF " + // pad
"00 00 00 00 " + // rxPackets
"FF 01 01 01 01 01 01 01 " + // txPackets
"FF 02 02 02 02 02 02 02 " + // rxBytes
"FF 02 03 02 03 02 03 02 " + // txBytes
"FF 02 03 02 03 02 03 02 " + // rxDropped
"FF 02 03 02 03 02 03 02 " + // txDropped
"FF 02 03 02 03 02 03 02 " + // rxErrors
"FF 02 03 02 03 02 03 02 " + // txErrors
"FF 02 03 02 03 02 03 02 " + // rxFrameErr
"FF 02 03 02 03 02 03 02 " + // rxOverErr
"FF 02 03 02 03 02 03 02 " + // rxCrcErr
"FF 02 03 02 03 02 03 02 " + // collisions
"FF 02 03 02 03 02 03 02 " + // durationSec
"00 00 00 02 " + // durationNsec
"00 00 00 04");
MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
BufferHelper.checkHeaderV13(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.assertEquals("Wrong durationSec", 2, message.getPortStats().get(0).getDurationSec().intValue());
Assert.assertEquals("Wrong durationNsec", 4, message.getPortStats().get(0).getDurationNsec().intValue());
}
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 PortDirectStatisticsService method buildReply.
@Override
protected GetNodeConnectorStatisticsOutput buildReply(List<MultipartReply> input, boolean success) {
final List<NodeConnectorStatisticsAndPortNumberMap> nodeConnectorStatisticsAndPortNumberMap = new ArrayList<>();
if (success) {
for (final MultipartReply mpReply : input) {
final MultipartReplyPortStatsCase caseBody = (MultipartReplyPortStatsCase) mpReply.getMultipartReplyBody();
final MultipartReplyPortStats replyBody = caseBody.getMultipartReplyPortStats();
for (final PortStats portStats : replyBody.getPortStats()) {
final NodeConnectorId nodeConnectorId = InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(getDatapathId(), portStats.getPortNo(), getOfVersion());
final BytesBuilder bytesBuilder = new BytesBuilder().setReceived(portStats.getRxBytes()).setTransmitted(portStats.getTxBytes());
final PacketsBuilder packetsBuilder = new PacketsBuilder().setReceived(portStats.getRxPackets()).setTransmitted(portStats.getTxPackets());
final DurationBuilder durationBuilder = new DurationBuilder();
if (portStats.getDurationSec() != null) {
durationBuilder.setSecond(new Counter32(portStats.getDurationSec()));
}
if (portStats.getDurationNsec() != null) {
durationBuilder.setNanosecond(new Counter32(portStats.getDurationNsec()));
}
final NodeConnectorStatisticsAndPortNumberMap stats = new NodeConnectorStatisticsAndPortNumberMapBuilder().setBytes(bytesBuilder.build()).setPackets(packetsBuilder.build()).setNodeConnectorId(nodeConnectorId).setDuration(durationBuilder.build()).setCollisionCount(portStats.getCollisions()).setKey(new NodeConnectorStatisticsAndPortNumberMapKey(nodeConnectorId)).setReceiveCrcError(portStats.getRxCrcErr()).setReceiveDrops(portStats.getRxDropped()).setReceiveErrors(portStats.getRxErrors()).setReceiveFrameError(portStats.getRxFrameErr()).setReceiveOverRunError(portStats.getRxOverErr()).setTransmitDrops(portStats.getTxDropped()).setTransmitErrors(portStats.getTxErrors()).build();
nodeConnectorStatisticsAndPortNumberMap.add(stats);
}
}
}
return new GetNodeConnectorStatisticsOutputBuilder().setNodeConnectorStatisticsAndPortNumberMap(nodeConnectorStatisticsAndPortNumberMap).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 MultipartReplyMessageFactoryTest method testPortStatsSerialize.
@Test
public void testPortStatsSerialize() throws Exception {
MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF13_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.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 128);
Assert.assertEquals("Wrong type", MultipartType.OFPMPPORTSTATS.getIntValue(), serializedBuffer.readShort());
Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort()));
serializedBuffer.skipBytes(PADDING);
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(4);
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());
Assert.assertEquals("Wrong duration sec", portStatsOutput.getDurationSec().intValue(), serializedBuffer.readInt());
Assert.assertEquals("Wrong duration nsec", portStatsOutput.getDurationNsec().intValue(), serializedBuffer.readInt());
}
Aggregations