Split out statistics tracking into separate classes
[controller.git] / opendaylight / md-sal / statistics-manager / src / main / java / org / opendaylight / controller / md / statistics / manager / FlowTableStatsTracker.java
1 /*
2  * Copyright IBM Corporation, 2013.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.md.statistics.manager;
9
10 import java.util.Collections;
11 import java.util.Set;
12 import java.util.concurrent.ConcurrentSkipListSet;
13
14 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
15 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsData;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsDataBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatistics;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatisticsBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27
28 final class FlowTableStatsTracker extends AbstractStatsTracker<FlowTableAndStatisticsMap, FlowTableAndStatisticsMap> {
29     private final Set<TableKey> privateTables = new ConcurrentSkipListSet<>();
30     private final Set<TableKey> tables = Collections.unmodifiableSet(privateTables);
31
32     FlowTableStatsTracker(InstanceIdentifier<Node> nodeIdentifier, DataProviderService dps, long lifetimeNanos) {
33         super(nodeIdentifier, dps, lifetimeNanos);
34     }
35
36     Set<TableKey> getTables() {
37         return tables;
38     }
39
40     @Override
41     protected void cleanupSingleStat(DataModificationTransaction trans, FlowTableAndStatisticsMap item) {
42         // TODO: do we want to do this?
43     }
44
45     @Override
46     protected FlowTableAndStatisticsMap updateSingleStat(DataModificationTransaction trans, FlowTableAndStatisticsMap item) {
47
48         InstanceIdentifier<Table> tableRef = getNodeIdentifierBuilder()
49                 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(item.getTableId().getValue())).build();
50
51         FlowTableStatisticsDataBuilder statisticsDataBuilder = new FlowTableStatisticsDataBuilder();
52         final FlowTableStatistics stats = new FlowTableStatisticsBuilder(item).build();
53         statisticsDataBuilder.setFlowTableStatistics(stats);
54
55         TableBuilder tableBuilder = new TableBuilder();
56         tableBuilder.setKey(new TableKey(item.getTableId().getValue()));
57         tableBuilder.addAugmentation(FlowTableStatisticsData.class, statisticsDataBuilder.build());
58         trans.putOperationalData(tableRef, tableBuilder.build());
59         return item;
60     }
61 }