use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.multipart.reply.port.stats.PortStats in project openflowplugin by opendaylight.
the class OF10StatsReplyMessageFactoryTest method createPortStats.
private static List<PortStats> createPortStats() {
PortStatsBuilder builder = new PortStatsBuilder();
builder.setPortNo(1L);
builder.setRxPackets(BigInteger.valueOf(1L));
builder.setTxPackets(BigInteger.valueOf(1L));
builder.setRxBytes(BigInteger.valueOf(1L));
builder.setTxBytes(BigInteger.valueOf(1L));
builder.setRxDropped(BigInteger.valueOf(1L));
builder.setTxDropped(BigInteger.valueOf(1L));
builder.setRxErrors(BigInteger.valueOf(1L));
builder.setTxErrors(BigInteger.valueOf(1L));
builder.setRxFrameErr(BigInteger.valueOf(1L));
builder.setRxOverErr(BigInteger.valueOf(1L));
builder.setRxCrcErr(BigInteger.valueOf(1L));
builder.setCollisions(BigInteger.valueOf(1L));
List<PortStats> list = new ArrayList<>();
list.add(builder.build());
return list;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.multipart.reply.port.stats.PortStats 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.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.multipart.reply.port.stats.PortStats 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.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.multipart.reply.port.stats.PortStats 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.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.multipart.reply.port.stats.PortStats in project openflowplugin by opendaylight.
the class OpenflowpluginStatsTestCommandProvider method _portStats.
public void _portStats(CommandInterpreter ci) {
int nodeConnectorCount = 0;
int nodeConnectorStatsCount = 0;
List<Node> nodes = getNodes();
for (Node node2 : nodes) {
NodeKey nodeKey = node2.getKey();
InstanceIdentifier<Node> nodeRef = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey);
ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
Node node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
if (node != null) {
if (node.getNodeConnector() != null) {
List<NodeConnector> ports = node.getNodeConnector();
for (NodeConnector nodeConnector2 : ports) {
nodeConnectorCount++;
NodeConnectorKey nodeConnectorKey = nodeConnector2.getKey();
InstanceIdentifier<NodeConnector> connectorRef = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey).child(NodeConnector.class, nodeConnectorKey);
NodeConnector nodeConnector = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, connectorRef);
if (nodeConnector != null) {
FlowCapableNodeConnectorStatisticsData data = nodeConnector.getAugmentation(FlowCapableNodeConnectorStatisticsData.class);
if (null != data) {
nodeConnectorStatsCount++;
}
}
}
}
}
}
if (nodeConnectorCount == nodeConnectorStatsCount) {
LOG.debug("portStats - Success");
} else {
LOG.debug("portStats - Failed");
LOG.debug("System fetchs stats data in 50 seconds interval, so pls wait and try again.");
}
}
Aggregations