use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCase 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.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCase 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.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCase 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.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCase in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactory method setPortStats.
private static MultipartReplyPortStatsCase setPortStats(final ByteBuf input) {
MultipartReplyPortStatsCaseBuilder caseBuilder = new MultipartReplyPortStatsCaseBuilder();
MultipartReplyPortStatsBuilder builder = new MultipartReplyPortStatsBuilder();
List<PortStats> portStatsList = new ArrayList<>();
while (input.readableBytes() > 0) {
PortStatsBuilder portStatsBuilder = new PortStatsBuilder();
portStatsBuilder.setPortNo(input.readUnsignedInt());
input.skipBytes(PADDING_IN_PORT_STATS_HEADER);
byte[] rxPackets = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(rxPackets);
portStatsBuilder.setRxPackets(new BigInteger(1, rxPackets));
byte[] txPackets = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(txPackets);
portStatsBuilder.setTxPackets(new BigInteger(1, txPackets));
byte[] rxBytes = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(rxBytes);
portStatsBuilder.setRxBytes(new BigInteger(1, rxBytes));
byte[] txBytes = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(txBytes);
portStatsBuilder.setTxBytes(new BigInteger(1, txBytes));
byte[] rxDropped = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(rxDropped);
portStatsBuilder.setRxDropped(new BigInteger(1, rxDropped));
byte[] txDropped = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(txDropped);
portStatsBuilder.setTxDropped(new BigInteger(1, txDropped));
byte[] rxErrors = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(rxErrors);
portStatsBuilder.setRxErrors(new BigInteger(1, rxErrors));
byte[] txErrors = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(txErrors);
portStatsBuilder.setTxErrors(new BigInteger(1, txErrors));
byte[] rxFrameErr = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(rxFrameErr);
portStatsBuilder.setRxFrameErr(new BigInteger(1, rxFrameErr));
byte[] rxOverErr = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(rxOverErr);
portStatsBuilder.setRxOverErr(new BigInteger(1, rxOverErr));
byte[] rxCrcErr = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(rxCrcErr);
portStatsBuilder.setRxCrcErr(new BigInteger(1, rxCrcErr));
byte[] collisions = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(collisions);
portStatsBuilder.setCollisions(new BigInteger(1, collisions));
portStatsBuilder.setDurationSec(input.readUnsignedInt());
portStatsBuilder.setDurationNsec(input.readUnsignedInt());
portStatsList.add(portStatsBuilder.build());
}
builder.setPortStats(portStatsList);
caseBuilder.setMultipartReplyPortStats(builder.build());
return caseBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCase in project openflowplugin by opendaylight.
the class OF10StatsReplyMessageFactory method setPortStats.
private static MultipartReplyPortStatsCase setPortStats(ByteBuf input) {
MultipartReplyPortStatsCaseBuilder caseBuilder = new MultipartReplyPortStatsCaseBuilder();
MultipartReplyPortStatsBuilder builder = new MultipartReplyPortStatsBuilder();
List<PortStats> portStatsList = new ArrayList<>();
while (input.readableBytes() > 0) {
PortStatsBuilder portStatsBuilder = new PortStatsBuilder();
portStatsBuilder.setPortNo((long) input.readUnsignedShort());
input.skipBytes(PADDING_IN_PORT_STATS_HEADER);
byte[] rxPackets = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(rxPackets);
portStatsBuilder.setRxPackets(new BigInteger(1, rxPackets));
byte[] txPackets = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(txPackets);
portStatsBuilder.setTxPackets(new BigInteger(1, txPackets));
byte[] rxBytes = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(rxBytes);
portStatsBuilder.setRxBytes(new BigInteger(1, rxBytes));
byte[] txBytes = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(txBytes);
portStatsBuilder.setTxBytes(new BigInteger(1, txBytes));
byte[] rxDropped = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(rxDropped);
portStatsBuilder.setRxDropped(new BigInteger(1, rxDropped));
byte[] txDropped = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(txDropped);
portStatsBuilder.setTxDropped(new BigInteger(1, txDropped));
byte[] rxErrors = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(rxErrors);
portStatsBuilder.setRxErrors(new BigInteger(1, rxErrors));
byte[] txErrors = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(txErrors);
portStatsBuilder.setTxErrors(new BigInteger(1, txErrors));
byte[] rxFrameErr = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(rxFrameErr);
portStatsBuilder.setRxFrameErr(new BigInteger(1, rxFrameErr));
byte[] rxOverErr = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(rxOverErr);
portStatsBuilder.setRxOverErr(new BigInteger(1, rxOverErr));
byte[] rxCrcErr = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(rxCrcErr);
portStatsBuilder.setRxCrcErr(new BigInteger(1, rxCrcErr));
byte[] collisions = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(collisions);
portStatsBuilder.setCollisions(new BigInteger(1, collisions));
portStatsList.add(portStatsBuilder.build());
}
builder.setPortStats(portStatsList);
caseBuilder.setMultipartReplyPortStats(builder.build());
return caseBuilder.build();
}
Aggregations