use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.peer.Stats in project openflowplugin by opendaylight.
the class GroupDescStatsResponseConvertorTest method testGroupDescStats.
/**
* Test single GroupDescStats conversion.
*/
@Test
public void testGroupDescStats() {
// **********************************************
// First group desc
// **********************************************
GroupDescBuilder builder = new GroupDescBuilder();
builder.setType(GroupType.OFPGTFF);
builder.setGroupId(new GroupId(42L));
// Buckets for first group desc
BucketsListBuilder bucketsBuilder = new BucketsListBuilder();
bucketsBuilder.setWeight(16);
bucketsBuilder.setWatchPort(new PortNumber(84L));
bucketsBuilder.setWatchGroup(168L);
// Actions for buckets for first group desc
List<Action> actions = new ArrayList<>();
ActionBuilder actionBuilder = new ActionBuilder();
actionBuilder.setActionChoice(new CopyTtlInCaseBuilder().build());
actions.add(actionBuilder.build());
// Build bucket with actions
bucketsBuilder.setAction(actions);
List<BucketsList> bucketsList = new ArrayList<>();
bucketsList.add(bucketsBuilder.build());
// Build first group desc
builder.setBucketsList(bucketsList);
List<GroupDesc> groupDescStats = new ArrayList<>();
groupDescStats.add(builder.build());
// **********************************************
// Second group desc
// **********************************************
builder = new GroupDescBuilder();
builder.setType(GroupType.OFPGTINDIRECT);
builder.setGroupId(new GroupId(50L));
// First buckets for second group desc
bucketsList = new ArrayList<>();
bucketsBuilder = new BucketsListBuilder();
bucketsBuilder.setWeight(100);
bucketsBuilder.setWatchPort(new PortNumber(200L));
bucketsBuilder.setWatchGroup(400L);
// Actions for first buckets for second group desc
actions = new ArrayList<>();
actionBuilder = new ActionBuilder();
actionBuilder.setActionChoice(new CopyTtlOutCaseBuilder().build());
actions.add(actionBuilder.build());
actionBuilder = new ActionBuilder();
actionBuilder.setActionChoice(new DecNwTtlCaseBuilder().build());
actions.add(actionBuilder.build());
actionBuilder = new ActionBuilder();
actionBuilder.setActionChoice(new PopPbbCaseBuilder().build());
actions.add(actionBuilder.build());
// Build first bucket with actions
bucketsBuilder.setAction(actions);
bucketsList.add(bucketsBuilder.build());
// Second buckets for second group desc
bucketsBuilder = new BucketsListBuilder();
bucketsBuilder.setWeight(5);
bucketsBuilder.setWatchPort(new PortNumber(10L));
bucketsBuilder.setWatchGroup(15L);
// Actions for second buckets for second group desc
actions = new ArrayList<>();
// Build second bucket with actions
bucketsBuilder.setAction(actions);
bucketsList.add(bucketsBuilder.build());
// Build second group desc
builder.setBucketsList(bucketsList);
groupDescStats.add(builder.build());
VersionConvertorData data = new VersionConvertorData(OFConstants.OFP_VERSION_1_3);
List<GroupDescStats> statsList = convert(groupDescStats, data);
Assert.assertEquals("Wrong groupDesc stats size", 2, statsList.size());
// **********************************************
// Test first group desc
// **********************************************
GroupDescStats stat = statsList.get(0);
Assert.assertEquals("Wrong type", GroupTypes.GroupFf, stat.getGroupType());
Assert.assertEquals("Wrong group-id", 42, stat.getGroupId().getValue().intValue());
Assert.assertEquals("Wrong key", 42, stat.getKey().getGroupId().getValue().intValue());
Assert.assertEquals("Wrong buckets size", 1, stat.getBuckets().getBucket().size());
// Test first bucket for first group desc
Bucket bucket = stat.getBuckets().getBucket().get(0);
Assert.assertEquals("Wrong type", 0, bucket.getKey().getBucketId().getValue().intValue());
Assert.assertEquals("Wrong type", 0, bucket.getBucketId().getValue().intValue());
Assert.assertEquals("Wrong type", 16, bucket.getWeight().intValue());
Assert.assertEquals("Wrong type", 168, bucket.getWatchGroup().intValue());
Assert.assertEquals("Wrong type", 84, bucket.getWatchPort().intValue());
Assert.assertEquals("Wrong type", 1, bucket.getAction().size());
// Test first action for first bucket for first group desc
org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action action = bucket.getAction().get(0);
Assert.assertEquals("Wrong type", 0, action.getOrder().intValue());
Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112" + ".action.action.CopyTtlInCase", action.getAction().getImplementedInterface().getName());
// **********************************************
// Test second group desc
// **********************************************
stat = statsList.get(1);
Assert.assertEquals("Wrong type", GroupTypes.GroupIndirect, stat.getGroupType());
Assert.assertEquals("Wrong group-id", 50, stat.getGroupId().getValue().intValue());
Assert.assertEquals("Wrong key", 50, stat.getKey().getGroupId().getValue().intValue());
Assert.assertEquals("Wrong buckets size", 2, stat.getBuckets().getBucket().size());
// Test first bucket for second group desc
bucket = stat.getBuckets().getBucket().get(0);
Assert.assertEquals("Wrong type", 0, bucket.getKey().getBucketId().getValue().intValue());
Assert.assertEquals("Wrong type", 0, bucket.getBucketId().getValue().intValue());
Assert.assertEquals("Wrong type", 100, bucket.getWeight().intValue());
Assert.assertEquals("Wrong type", 400, bucket.getWatchGroup().intValue());
Assert.assertEquals("Wrong type", 200, bucket.getWatchPort().intValue());
Assert.assertEquals("Wrong type", 3, bucket.getAction().size());
// Test first action for first bucket of second group desc
action = bucket.getAction().get(0);
Assert.assertEquals("Wrong type", 0, action.getOrder().intValue());
Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112" + ".action.action.CopyTtlOutCase", action.getAction().getImplementedInterface().getName());
// Test second action for first bucket of second group desc
action = bucket.getAction().get(1);
Assert.assertEquals("Wrong type", 1, action.getOrder().intValue());
Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112" + ".action.action.DecNwTtlCase", action.getAction().getImplementedInterface().getName());
// Test third action for first bucket of second group desc
action = bucket.getAction().get(2);
Assert.assertEquals("Wrong type", 2, action.getOrder().intValue());
Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112" + ".action.action.PopPbbActionCase", action.getAction().getImplementedInterface().getName());
// Test second bucket for second group desc
bucket = stat.getBuckets().getBucket().get(1);
Assert.assertEquals("Wrong type", 1, bucket.getKey().getBucketId().getValue().intValue());
Assert.assertEquals("Wrong type", 1, bucket.getBucketId().getValue().intValue());
Assert.assertEquals("Wrong type", 5, bucket.getWeight().intValue());
Assert.assertEquals("Wrong type", 15, bucket.getWatchGroup().intValue());
Assert.assertEquals("Wrong type", 10, bucket.getWatchPort().intValue());
Assert.assertEquals("Wrong type", 0, bucket.getAction().size());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.peer.Stats in project openflowplugin by opendaylight.
the class GroupDescStatsResponseConvertorTest method testSingleGroupDescStat.
/**
* Test single GroupDescStat conversion without buckets.
*/
@Test
public void testSingleGroupDescStat() {
GroupDescBuilder builder = new GroupDescBuilder();
builder.setType(GroupType.OFPGTALL);
builder.setGroupId(new GroupId(42L));
builder.setBucketsList(new ArrayList<>());
List<GroupDesc> groupDescStats = new ArrayList<>();
groupDescStats.add(builder.build());
VersionConvertorData data = new VersionConvertorData(OFConstants.OFP_VERSION_1_3);
List<GroupDescStats> statsList = convert(groupDescStats, data);
Assert.assertEquals("Wrong groupDesc stats size", 1, statsList.size());
GroupDescStats stat = statsList.get(0);
Assert.assertEquals("Wrong type", GroupTypes.GroupAll, stat.getGroupType());
Assert.assertEquals("Wrong group-id", 42, stat.getGroupId().getValue().intValue());
Assert.assertEquals("Wrong key", 42, stat.getKey().getGroupId().getValue().intValue());
Assert.assertEquals("Wrong buckets size", 0, stat.getBuckets().getBucket().size());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.peer.Stats in project openflowplugin by opendaylight.
the class NodeConnectorDirectStatisticsServiceTest method testStoreStatistics.
@Override
public void testStoreStatistics() throws Exception {
final NodeConnectorStatisticsAndPortNumberMap stat = mock(NodeConnectorStatisticsAndPortNumberMap.class);
when(stat.getNodeConnectorId()).thenReturn(nodeConnectorId);
final List<NodeConnectorStatisticsAndPortNumberMap> stats = Collections.singletonList(stat);
final GetNodeConnectorStatisticsOutput output = mock(GetNodeConnectorStatisticsOutput.class);
when(output.getNodeConnectorStatisticsAndPortNumberMap()).thenReturn(stats);
multipartWriterProvider.lookup(MultipartType.OFPMPPORTSTATS).get().write(output, true);
verify(deviceContext).writeToTransactionWithParentsSlow(eq(LogicalDatastoreType.OPERATIONAL), any(), any());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.peer.Stats in project openflowplugin by opendaylight.
the class FlowDirectStatisticsServiceTest method testBuildReply.
@Override
public void testBuildReply() throws Exception {
final FlowAndStatisticsMapList flowStat = new FlowAndStatisticsMapListBuilder().setDuration(new DurationBuilder().setSecond(new Counter32(1L)).setNanosecond(new Counter32(1L)).build()).setTableId(TABLE_NO).setByteCount(new Counter64(BigInteger.ONE)).setPacketCount(new Counter64(BigInteger.ONE)).setFlags(new FlowModFlags(true, false, false, false, false)).setMatch(new MatchBuilder().build()).build();
final MultipartReply reply = new MultipartReplyBuilder().setMultipartReplyBody(new MultipartReplyFlowStatsBuilder().setFlowAndStatisticsMapList(Collections.singletonList(flowStat)).build()).build();
final List<MultipartReply> input = Collections.singletonList(reply);
final GetFlowStatisticsOutput output = service.buildReply(input, true);
assertTrue(output.getFlowAndStatisticsMapList().size() > 0);
final FlowAndStatisticsMap stats = output.getFlowAndStatisticsMapList().get(0);
assertEquals(stats.getTableId(), TABLE_NO);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.peer.Stats 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();
}
Aggregations