2 * Copyright (c) 2013 Big Switch Networks, Inc. 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.protocol_plugin.openflow.internal;
10 import java.util.ArrayList;
11 import java.util.List;
13 import org.opendaylight.controller.sal.core.Node;
14 import org.opendaylight.controller.sal.reader.NodeTableStatistics;
15 import org.opendaylight.controller.sal.utils.NodeCreator;
16 import org.openflow.protocol.statistics.OFStatistics;
17 import org.openflow.protocol.statistics.OFTableStatistics;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 * Converts an openflow list of table statistics in a SAL list of
23 * NodeTableStatistics objects
25 public class TableStatisticsConverter {
26 private static final Logger log = LoggerFactory
27 .getLogger(TableStatisticsConverter.class);
29 private final long switchId;
30 private List<OFStatistics> ofStatsList;
31 private List<NodeTableStatistics> ntStatsList;
33 public TableStatisticsConverter(long switchId, List<OFStatistics> statsList) {
34 this.switchId = switchId;
35 if (statsList == null || statsList.isEmpty()) {
36 this.ofStatsList = new ArrayList<OFStatistics>(1); // dummy list
38 this.ofStatsList = new ArrayList<OFStatistics>(statsList);
40 this.ntStatsList = null;
43 public List<NodeTableStatistics> getNodeTableStatsList() {
44 if (this.ofStatsList != null && this.ntStatsList == null) {
45 this.ntStatsList = new ArrayList<NodeTableStatistics>();
46 OFTableStatistics ofTableStat;
47 Node node = NodeCreator.createOFNode(switchId);
48 for (OFStatistics ofStat : this.ofStatsList) {
49 ofTableStat = (OFTableStatistics) ofStat;
50 NodeTableStatistics ntStat = new NodeTableStatistics();
51 ntStat.setNodeTable(TableConverter.toNodeTable(
52 ofTableStat.getTableId(), node));
53 ntStat.setActiveCount(ofTableStat.getActiveCount());
54 ntStat.setLookupCount(ofTableStat.getLookupCount());
55 ntStat.setMatchedCount(ofTableStat.getMatchedCount());
56 this.ntStatsList.add(ntStat);
59 log.trace("OFStatistics: {} NodeTableStatistics: {}", ofStatsList,
61 return this.ntStatsList;