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.Collections;
12 import java.util.List;
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;
23 * Converts an openflow list of table statistics in a SAL list of
24 * NodeTableStatistics objects
26 public class TableStatisticsConverter {
27 private static final Logger log = LoggerFactory
28 .getLogger(TableStatisticsConverter.class);
30 private final long switchId;
31 private List<OFStatistics> ofStatsList;
32 private List<NodeTableStatistics> ntStatsList;
34 public TableStatisticsConverter(long switchId, List<OFStatistics> statsList) {
35 this.switchId = switchId;
36 if (statsList == null || statsList.isEmpty()) {
37 this.ofStatsList = Collections.emptyList();
39 this.ofStatsList = new ArrayList<OFStatistics>(statsList);
41 this.ntStatsList = null;
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);
61 log.trace("OFStatistics: {} NodeTableStatistics: {}", ofStatsList,
63 return this.ntStatsList;