use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueueCase 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.MultipartReplyQueueCase 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.MultipartReplyQueueCase 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.MultipartReplyQueueCase 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());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueueCase in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactory method setQueue.
private static MultipartReplyQueueCase setQueue(final ByteBuf input) {
MultipartReplyQueueCaseBuilder caseBuilder = new MultipartReplyQueueCaseBuilder();
MultipartReplyQueueBuilder builder = new MultipartReplyQueueBuilder();
List<QueueStats> queueStatsList = new ArrayList<>();
while (input.readableBytes() > 0) {
QueueStatsBuilder queueStatsBuilder = new QueueStatsBuilder();
queueStatsBuilder.setPortNo(input.readUnsignedInt());
queueStatsBuilder.setQueueId(input.readUnsignedInt());
byte[] txBytes = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(txBytes);
queueStatsBuilder.setTxBytes(new BigInteger(1, txBytes));
byte[] txPackets = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(txPackets);
queueStatsBuilder.setTxPackets(new BigInteger(1, txPackets));
byte[] txErrors = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(txErrors);
queueStatsBuilder.setTxErrors(new BigInteger(1, txErrors));
queueStatsBuilder.setDurationSec(input.readUnsignedInt());
queueStatsBuilder.setDurationNsec(input.readUnsignedInt());
queueStatsList.add(queueStatsBuilder.build());
}
builder.setQueueStats(queueStatsList);
caseBuilder.setMultipartReplyQueue(builder.build());
return caseBuilder.build();
}
Aggregations