2 * Copyright IBM Corporation, 2013. All rights reserved.
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
8 package org.opendaylight.controller.md.statistics.manager;
10 import java.util.Collections;
12 import java.util.concurrent.ConcurrentSkipListSet;
14 import org.opendaylight.controller.md.statistics.manager.MultipartMessageManager.StatsRequestType;
15 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
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.GetFlowTablesStatisticsInputBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatistics;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatisticsBuilder;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 final class FlowTableStatsTracker extends AbstractStatsTracker<FlowTableAndStatisticsMap, FlowTableAndStatisticsMap> {
30 private final Set<TableKey> privateTables = new ConcurrentSkipListSet<>();
31 private final Set<TableKey> tables = Collections.unmodifiableSet(privateTables);
32 private final OpendaylightFlowTableStatisticsService flowTableStatsService;
34 FlowTableStatsTracker(OpendaylightFlowTableStatisticsService flowTableStatsService, final FlowCapableContext context, long lifetimeNanos) {
35 super(context, lifetimeNanos);
36 this.flowTableStatsService = flowTableStatsService;
39 Set<TableKey> getTables() {
44 protected void cleanupSingleStat(DataModificationTransaction trans, FlowTableAndStatisticsMap item) {
45 // TODO: do we want to do this?
49 protected FlowTableAndStatisticsMap updateSingleStat(DataModificationTransaction trans, FlowTableAndStatisticsMap item) {
51 InstanceIdentifier<Table> tableRef = getNodeIdentifierBuilder()
52 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(item.getTableId().getValue())).build();
54 FlowTableStatisticsDataBuilder statisticsDataBuilder = new FlowTableStatisticsDataBuilder();
55 final FlowTableStatistics stats = new FlowTableStatisticsBuilder(item).build();
56 statisticsDataBuilder.setFlowTableStatistics(stats);
58 TableBuilder tableBuilder = new TableBuilder();
59 tableBuilder.setKey(new TableKey(item.getTableId().getValue()));
60 tableBuilder.addAugmentation(FlowTableStatisticsData.class, statisticsDataBuilder.build());
61 trans.putOperationalData(tableRef, tableBuilder.build());
65 public void request() {
66 if (flowTableStatsService != null) {
67 final GetFlowTablesStatisticsInputBuilder input = new GetFlowTablesStatisticsInputBuilder();
68 input.setNode(getNodeRef());
70 requestHelper(flowTableStatsService.getFlowTablesStatistics(input.build()), StatsRequestType.ALL_FLOW);