use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.counterresult.groups.Counters in project openflowplugin by opendaylight.
the class SyncPlanPushStrategyIncrementalImplTest method testAddMissingMeters_withUpdate.
@Test
public void testAddMissingMeters_withUpdate() throws Exception {
Mockito.when(meterCommitter.add(Matchers.<InstanceIdentifier<Meter>>any(), meterCaptor.capture(), Matchers.same(NODE_IDENT))).thenReturn(RpcResultBuilder.success(new AddMeterOutputBuilder().build()).buildFuture());
Mockito.when(meterCommitter.update(Matchers.<InstanceIdentifier<Meter>>any(), meterUpdateCaptor.capture(), meterUpdateCaptor.capture(), Matchers.same(NODE_IDENT))).thenReturn(RpcResultBuilder.success(new UpdateMeterOutputBuilder().build()).buildFuture());
final ItemSyncBox<Meter> meterSyncBox = new ItemSyncBox<>();
meterSyncBox.getItemsToPush().add(DSInputFactory.createMeter(2L));
meterSyncBox.getItemsToPush().add(DSInputFactory.createMeter(4L));
meterSyncBox.getItemsToUpdate().add(new ItemSyncBox.ItemUpdateTuple<>(DSInputFactory.createMeter(1L), DSInputFactory.createMeterWithBody(1L)));
final ListenableFuture<RpcResult<Void>> result = syncPlanPushStrategy.addMissingMeters(NODE_ID, NODE_IDENT, meterSyncBox, counters);
Assert.assertTrue(result.isDone());
Assert.assertTrue(result.get().isSuccessful());
final List<Meter> meterCaptorAllValues = meterCaptor.getAllValues();
Assert.assertEquals(2, meterCaptorAllValues.size());
Assert.assertEquals(2L, meterCaptorAllValues.get(0).getMeterId().getValue().longValue());
Assert.assertEquals(4L, meterCaptorAllValues.get(1).getMeterId().getValue().longValue());
final List<Meter> meterUpdateCaptorAllValues = meterUpdateCaptor.getAllValues();
Assert.assertEquals(2, meterUpdateCaptorAllValues.size());
Assert.assertEquals(1L, meterUpdateCaptorAllValues.get(0).getMeterId().getValue().longValue());
Assert.assertEquals(1L, meterUpdateCaptorAllValues.get(1).getMeterId().getValue().longValue());
final InOrder inOrderMeters = Mockito.inOrder(flowCapableTxService, meterCommitter);
inOrderMeters.verify(meterCommitter, Mockito.times(2)).add(Matchers.<InstanceIdentifier<Meter>>any(), Matchers.<Meter>any(), Matchers.eq(NODE_IDENT));
inOrderMeters.verify(meterCommitter).update(Matchers.<InstanceIdentifier<Meter>>any(), Matchers.<Meter>any(), Matchers.<Meter>any(), Matchers.eq(NODE_IDENT));
// TODO: uncomment when enabled in impl
// inOrderMeters.verify(flowCapableTxService).sendBarrier(Matchers.<SendBarrierInput>any());
inOrderMeters.verifyNoMoreInteractions();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.counterresult.groups.Counters in project genius by opendaylight.
the class NodeConnectorStatsImpl method processFlowStatistics.
/**
* This method processes FlowStatistics RPC result.
* It performs:
* - fetches all flows of node
* - stores flows count per table in local map
* - creates/updates Flow table counters using Infrautils metrics API
* - set counter with values fetched from FlowStatistics
*/
private void processFlowStatistics(GetFlowStatisticsOutput flowStatsOutput, BigInteger dpid) {
Map<Short, AtomicInteger> flowTableMap = new HashMap<>();
// Get all flows for node from RPC result
List<FlowAndStatisticsMapList> flowTableAndStatisticsMapList = flowStatsOutput.getFlowAndStatisticsMapList();
for (FlowAndStatisticsMapList flowAndStatisticsMap : flowTableAndStatisticsMapList) {
short tableId = flowAndStatisticsMap.getTableId();
// populate map to maintain flow count per table
flowTableMap.computeIfAbsent(tableId, key -> new AtomicInteger(0)).incrementAndGet();
}
LOG.trace("FlowTableStatistics (tableId:counter): {} for node: {}", flowTableMap.entrySet(), dpid.toString());
for (Map.Entry<Short, AtomicInteger> flowTable : flowTableMap.entrySet()) {
Short tableId = flowTable.getKey();
AtomicInteger flowCount = flowTable.getValue();
Counter counter = getCounter(CounterConstants.IFM_FLOW_TBL_COUNTER_FLOWS_PER_TBL, dpid, null, null, tableId.toString());
// update counter value
updateCounter(counter, flowCount.longValue());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.counterresult.groups.Counters in project genius by opendaylight.
the class NodeConnectorStatsImpl method processNodeConnectorStatistics.
/**
* This method processes NodeConnectorStatistics RPC result.
* It performs:
* - fetches various OF Port counters values
* - creates/updates new OF Port counters using Infrautils metrics API
* - set counter with values fetched from NodeConnectorStatistics
*/
private void processNodeConnectorStatistics(GetNodeConnectorStatisticsOutput nodeConnectorStatisticsOutput, BigInteger dpid) {
String port = "";
String portUuid = "";
List<NodeConnectorStatisticsAndPortNumberMap> ncStatsAndPortMapList = nodeConnectorStatisticsOutput.getNodeConnectorStatisticsAndPortNumberMap();
// Parse NodeConnectorStatistics and create/update counters for them
for (NodeConnectorStatisticsAndPortNumberMap ncStatsAndPortMap : ncStatsAndPortMapList) {
NodeConnectorId nodeConnector = ncStatsAndPortMap.getNodeConnectorId();
LOG.trace("Create/update metric counter for NodeConnector: {} of node: {}", nodeConnector, dpid.toString());
port = nodeConnector.getValue();
// update port name as per port name maintained in portNameCache
String portNameInCache = "openflow" + ":" + dpid.toString() + ":" + port;
java.util.Optional<String> portName = portNameCache.get(portNameInCache);
if (portName.isPresent()) {
Optional<List<InterfaceChildEntry>> interfaceChildEntries = interfaceChildCache.getInterfaceChildEntries(portName.get());
if (interfaceChildEntries.isPresent()) {
if (!interfaceChildEntries.get().isEmpty()) {
portUuid = interfaceChildEntries.get().get(0).getChildInterface();
LOG.trace("Retrieved portUuid {} for portname {}", portUuid, portName.get());
} else {
LOG.trace("PortUuid is not found for portname {}. Skipping IFM counters publish for this port.", portName.get());
continue;
}
} else {
LOG.trace("PortUuid is not found for portname {}. Skipping IFM counters publish for this port.", portName.get());
continue;
}
}
Counter counter = getCounter(CounterConstants.IFM_PORT_COUNTER_OFPORT_DURATION, dpid, port, portUuid, null);
long ofPortDuration = ncStatsAndPortMap.getDuration().getSecond().getValue();
updateCounter(counter, ofPortDuration);
counter = getCounter(CounterConstants.IFM_PORT_COUNTER_OFPORT_PKT_RECVDROP, dpid, port, portUuid, null);
long packetsPerOFPortReceiveDrop = ncStatsAndPortMap.getReceiveDrops().longValue();
updateCounter(counter, packetsPerOFPortReceiveDrop);
counter = getCounter(CounterConstants.IFM_PORT_COUNTER_OFPORT_PKT_RECVERROR, dpid, port, portUuid, null);
long packetsPerOFPortReceiveError = ncStatsAndPortMap.getReceiveErrors().longValue();
updateCounter(counter, packetsPerOFPortReceiveError);
counter = getCounter(CounterConstants.IFM_PORT_COUNTER_OFPORT_PKT_SENT, dpid, port, portUuid, null);
long packetsPerOFPortSent = ncStatsAndPortMap.getPackets().getTransmitted().longValue();
updateCounter(counter, packetsPerOFPortSent);
counter = getCounter(CounterConstants.IFM_PORT_COUNTER_OFPORT_PKT_RECV, dpid, port, portUuid, null);
long packetsPerOFPortReceive = ncStatsAndPortMap.getPackets().getReceived().longValue();
updateCounter(counter, packetsPerOFPortReceive);
counter = getCounter(CounterConstants.IFM_PORT_COUNTER_OFPORT_BYTE_SENT, dpid, port, portUuid, null);
long bytesPerOFPortSent = ncStatsAndPortMap.getBytes().getTransmitted().longValue();
updateCounter(counter, bytesPerOFPortSent);
counter = getCounter(CounterConstants.IFM_PORT_COUNTER_OFPORT_BYTE_RECV, dpid, port, portUuid, null);
long bytesPerOFPortReceive = ncStatsAndPortMap.getBytes().getReceived().longValue();
updateCounter(counter, bytesPerOFPortReceive);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.counterresult.groups.Counters in project genius by opendaylight.
the class NodeConnectorStatsImpl method remove.
@Override
protected void remove(InstanceIdentifier<Node> identifier, Node node) {
NodeId nodeId = node.getId();
String nodeVal = nodeId.getValue().split(":")[1];
BigInteger dpId = new BigInteger(nodeVal);
if (nodes.contains(dpId)) {
nodes.remove(dpId);
// remove counters set from node
Set<Counter> nodeMetricCounterSet = metricsCountersPerNodeMap.remove(dpId);
if (nodeMetricCounterSet != null) {
// remove counters
nodeMetricCounterSet.forEach(UncheckedCloseable::close);
}
}
if (nodes.size() > 0) {
delayStatsQuery = ifmConfig.getIfmStatsDefPollInterval() / nodes.size();
} else {
stopPortStatRequestTask();
delayStatsQuery = 0;
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.counterresult.groups.Counters in project genius by opendaylight.
the class NodeConnectorStatsImpl method getCounter.
/*
* This method returns counter and also creates counter if does not exist.
*
* @param counterName name of the counter
* @param switchId datapath-id value
* @param port port-id value
* @param aliasId alias-id value
* @param tableId table-id value of switch
* @return counter object
*/
private Counter getCounter(String counterName, BigInteger switchId, String port, String aliasId, String tableId) {
/*
* Pattern to be followed for key generation:
*
* genius.interfacemanager.entitycounter{entitytype=port,switchid=value,portid=value,aliasid=value,
* name=counterName}
* genius.interfacemanager.entitycounter{entitytype=flowtable,switchid=value,flowtableid=value,name=counterName}
*/
Counter counter = null;
if (port != null) {
Labeled<Labeled<Labeled<Labeled<Labeled<Counter>>>>> labeledCounter = metricProvider.newCounter(MetricDescriptor.builder().anchor(this).project("genius").module("interfacemanager").id(CounterConstants.CNT_TYPE_ENTITY_CNT_ID).build(), CounterConstants.LBL_KEY_ENTITY_TYPE, CounterConstants.LBL_KEY_SWITCHID, CounterConstants.LBL_KEY_PORTID, CounterConstants.LBL_KEY_ALIASID, CounterConstants.LBL_KEY_COUNTER_NAME);
counter = labeledCounter.label(CounterConstants.LBL_VAL_ENTITY_TYPE_PORT).label(switchId.toString()).label(port).label(aliasId).label(counterName);
}
if (tableId != null) {
Labeled<Labeled<Labeled<Labeled<Counter>>>> labeledCounter = metricProvider.newCounter(MetricDescriptor.builder().anchor(this).project("genius").module("interfacemanager").id(CounterConstants.CNT_TYPE_ENTITY_CNT_ID).build(), CounterConstants.LBL_KEY_ENTITY_TYPE, CounterConstants.LBL_KEY_SWITCHID, CounterConstants.LBL_KEY_FLOWTBLID, CounterConstants.LBL_KEY_COUNTER_NAME);
counter = labeledCounter.label(CounterConstants.LBL_VAL_ENTITY_TYPE_FLOWTBL).label(switchId.toString()).label(tableId).label(counterName);
}
// create counters set for node if absent.
// and then populate counter set with counter object
// which will be needed to close counters when node is removed.
metricsCountersPerNodeMap.computeIfAbsent(switchId, counterSet -> ConcurrentHashMap.newKeySet()).add(counter);
return counter;
}
Aggregations