use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.multipart.reply.queue.QueueStats in project openflowplugin by opendaylight.
the class QueueStatisticsToNotificationTransformer method transformToNotification.
/**
* Transform statistics to notification.
*
* @param mpReplyList raw multipart response from device
* @param deviceInfo device state
* @param ofVersion device version
* @param emulatedTxId emulated transaction Id
* @return notification containing flow stats
*/
public static QueueStatisticsUpdate transformToNotification(final List<MultipartReply> mpReplyList, final DeviceInfo deviceInfo, final OpenflowVersion ofVersion, final TransactionId emulatedTxId) {
QueueStatisticsUpdateBuilder notification = new QueueStatisticsUpdateBuilder();
notification.setId(deviceInfo.getNodeId());
notification.setMoreReplies(Boolean.FALSE);
notification.setTransactionId(emulatedTxId);
notification.setQueueIdAndStatisticsMap(new ArrayList<>());
for (MultipartReply mpReply : mpReplyList) {
MultipartReplyQueueCase caseBody = (MultipartReplyQueueCase) mpReply.getMultipartReplyBody();
MultipartReplyQueue replyBody = caseBody.getMultipartReplyQueue();
for (QueueStats queueStats : replyBody.getQueueStats()) {
QueueIdAndStatisticsMapBuilder statsBuilder = new QueueIdAndStatisticsMapBuilder();
statsBuilder.setNodeConnectorId(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(deviceInfo.getDatapathId(), queueStats.getPortNo(), ofVersion));
statsBuilder.setTransmissionErrors(new Counter64(queueStats.getTxErrors()));
statsBuilder.setTransmittedBytes(new Counter64(queueStats.getTxBytes()));
statsBuilder.setTransmittedPackets(new Counter64(queueStats.getTxPackets()));
DurationBuilder durationBuilder = new DurationBuilder();
durationBuilder.setSecond(new Counter32(queueStats.getDurationSec()));
durationBuilder.setNanosecond(new Counter32(queueStats.getDurationNsec()));
statsBuilder.setDuration(durationBuilder.build());
statsBuilder.setQueueId(new QueueId(queueStats.getQueueId()));
notification.getQueueIdAndStatisticsMap().add(statsBuilder.build());
}
}
return notification.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.multipart.reply.queue.QueueStats in project openflowplugin by opendaylight.
the class MultipartReplyQueueStatsDeserializerTest method deserialize.
@Test
public void deserialize() throws Exception {
ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
buffer.writeInt(PORT);
buffer.writeInt(QUEUE_ID);
buffer.writeLong(TRANSMITTED_BYTES);
buffer.writeLong(TRANSMITTED_PACKETS);
buffer.writeLong(TRANSMISSON_ERRORS);
buffer.writeInt(SECOND);
buffer.writeInt(NANOSECOND);
final MultipartReplyQueueStats reply = (MultipartReplyQueueStats) deserializeMultipart(buffer);
final QueueIdAndStatisticsMap queueStats = reply.getQueueIdAndStatisticsMap().get(0);
assertEquals(QUEUE_ID, queueStats.getQueueId().getValue().intValue());
assertEquals(TRANSMITTED_BYTES, queueStats.getTransmittedBytes().getValue().longValue());
assertEquals(TRANSMITTED_PACKETS, queueStats.getTransmittedPackets().getValue().longValue());
assertEquals(TRANSMISSON_ERRORS, queueStats.getTransmissionErrors().getValue().longValue());
assertEquals(SECOND, queueStats.getDuration().getSecond().getValue().intValue());
assertEquals(NANOSECOND, queueStats.getDuration().getNanosecond().getValue().intValue());
assertEquals(0, buffer.readableBytes());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.multipart.reply.queue.QueueStats in project openflowplugin by opendaylight.
the class QueueDirectStatisticsServiceTest method testBuildReply.
@Override
public void testBuildReply() throws Exception {
final MultipartReply reply = mock(MultipartReply.class);
final MultipartReplyQueueCase queueCase = mock(MultipartReplyQueueCase.class);
final MultipartReplyQueue queue = mock(MultipartReplyQueue.class);
final QueueStats queueStat = mock(QueueStats.class);
final List<QueueStats> queueStats = Collections.singletonList(queueStat);
final List<MultipartReply> input = Collections.singletonList(reply);
when(queue.getQueueStats()).thenReturn(queueStats);
when(queueCase.getMultipartReplyQueue()).thenReturn(queue);
when(reply.getMultipartReplyBody()).thenReturn(queueCase);
when(queueStat.getPortNo()).thenReturn(PORT_NO);
when(queueStat.getQueueId()).thenReturn(QUEUE_NO);
when(queueStat.getTxBytes()).thenReturn(BigInteger.ONE);
when(queueStat.getTxErrors()).thenReturn(BigInteger.ONE);
when(queueStat.getTxPackets()).thenReturn(BigInteger.ONE);
final GetQueueStatisticsOutput output = service.buildReply(input, true);
assertTrue(output.getQueueIdAndStatisticsMap().size() > 0);
final QueueIdAndStatisticsMap map = output.getQueueIdAndStatisticsMap().get(0);
assertEquals(map.getQueueId().getValue(), QUEUE_NO);
assertEquals(map.getNodeConnectorId(), nodeConnectorId);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.multipart.reply.queue.QueueStats in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactory method serializeQueueBody.
private void serializeQueueBody(final MultipartReplyBody body, final ByteBuf outBuffer) {
MultipartReplyQueueCase queueCase = (MultipartReplyQueueCase) body;
MultipartReplyQueue queue = queueCase.getMultipartReplyQueue();
for (QueueStats queueStats : queue.getQueueStats()) {
outBuffer.writeInt(queueStats.getPortNo().intValue());
outBuffer.writeInt(queueStats.getQueueId().intValue());
outBuffer.writeLong(queueStats.getTxBytes().longValue());
outBuffer.writeLong(queueStats.getTxPackets().longValue());
outBuffer.writeLong(queueStats.getTxErrors().longValue());
outBuffer.writeInt(queueStats.getDurationSec().intValue());
outBuffer.writeInt(queueStats.getDurationNsec().intValue());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.multipart.reply.queue.QueueStats in project openflowplugin by opendaylight.
the class OF10StatsReplyMessageFactoryTest method testQueueBodySerialize.
@Test
public void testQueueBodySerialize() throws Exception {
MultipartReplyMessageBuilder builder;
builder = new MultipartReplyMessageBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
builder.setFlags(new MultipartRequestFlags(true));
builder.setType(MultipartType.forValue(5));
MultipartReplyQueueCaseBuilder queueCase = new MultipartReplyQueueCaseBuilder();
MultipartReplyQueueBuilder queue = new MultipartReplyQueueBuilder();
queue.setQueueStats(createQueueStats());
queueCase.setMultipartReplyQueue(queue.build());
builder.setMultipartReplyBody(queueCase.build());
MultipartReplyMessage message = builder.build();
ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
factory.serialize(message, serializedBuffer);
BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 44);
Assert.assertEquals("Wrong type", MultipartType.OFPMPQUEUE.getIntValue(), serializedBuffer.readShort());
Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort()));
MultipartReplyQueueCase body = (MultipartReplyQueueCase) message.getMultipartReplyBody();
MultipartReplyQueue messageOutput = body.getMultipartReplyQueue();
QueueStats queueStats = messageOutput.getQueueStats().get(0);
Assert.assertEquals("Wrong length", 32, serializedBuffer.readUnsignedShort());
serializedBuffer.skipBytes(2);
Assert.assertEquals("Wrong queue id", queueStats.getQueueId().intValue(), serializedBuffer.readUnsignedInt());
Assert.assertEquals("Wrong tx bytes", queueStats.getTxBytes().longValue(), serializedBuffer.readLong());
Assert.assertEquals("Wrong tx packets", queueStats.getTxPackets().longValue(), serializedBuffer.readLong());
Assert.assertEquals("Wrong tx errors", queueStats.getTxErrors().longValue(), serializedBuffer.readLong());
}
Aggregations