BUG 2302 : odl-clustering-test-app should not be part of the odl-restconf-all feature set
[controller.git] / opendaylight / adsal / protocol_plugins / openflow / src / main / java / org / opendaylight / controller / protocol_plugin / openflow / internal / TableStatisticsConverter.java
1 /*
2  * Copyright (c) 2013 Big Switch Networks, Inc.  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.protocol_plugin.openflow.internal;
9
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
13
14 import org.opendaylight.controller.sal.core.Node;
15 import org.opendaylight.controller.sal.reader.NodeTableStatistics;
16 import org.opendaylight.controller.sal.utils.NodeCreator;
17 import org.openflow.protocol.statistics.OFStatistics;
18 import org.openflow.protocol.statistics.OFTableStatistics;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 /**
23  * Converts an openflow list of table statistics in a SAL list of
24  * NodeTableStatistics objects
25  */
26 public class TableStatisticsConverter {
27     private static final Logger log = LoggerFactory
28             .getLogger(TableStatisticsConverter.class);
29
30     private final long switchId;
31     private List<OFStatistics> ofStatsList;
32     private List<NodeTableStatistics> ntStatsList;
33
34     public TableStatisticsConverter(long switchId, List<OFStatistics> statsList) {
35         this.switchId = switchId;
36         if (statsList == null || statsList.isEmpty()) {
37             this.ofStatsList = Collections.emptyList();
38         } else {
39             this.ofStatsList = new ArrayList<OFStatistics>(statsList);
40         }
41         this.ntStatsList = null;
42     }
43
44     public List<NodeTableStatistics> getNodeTableStatsList() {
45         if (this.ofStatsList != null && this.ntStatsList == null) {
46             this.ntStatsList = new ArrayList<NodeTableStatistics>();
47             OFTableStatistics ofTableStat;
48             Node node = NodeCreator.createOFNode(switchId);
49             for (OFStatistics ofStat : this.ofStatsList) {
50                 ofTableStat = (OFTableStatistics) ofStat;
51                 NodeTableStatistics ntStat = new NodeTableStatistics();
52                 ntStat.setNodeTable(TableConverter.toNodeTable(
53                         ofTableStat.getTableId(), node));
54                 ntStat.setActiveCount(ofTableStat.getActiveCount());
55                 ntStat.setLookupCount(ofTableStat.getLookupCount());
56                 ntStat.setMatchedCount(ofTableStat.getMatchedCount());
57                 ntStat.setMaximumEntries(ofTableStat.getMaximumEntries());
58                 this.ntStatsList.add(ntStat);
59             }
60         }
61         log.trace("OFStatistics: {} NodeTableStatistics: {}", ofStatsList,
62                 ntStatsList);
63         return this.ntStatsList;
64     }
65 }