All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opendaylight.snmp4sdn.internal.TableStatisticsConverter Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2013 Industrial Technology Research Institute of Taiwan and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

/*
This code reused the code base of OpenFlow plugin contributed by Cisco Systems, Inc. Their efforts are appreciated.
*/

package org.opendaylight.snmp4sdn.internal;

import java.util.ArrayList;
import java.util.List;

import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.reader.NodeTableStatistics;
import org.opendaylight.controller.sal.utils.NodeCreator;
import org.openflow.protocol.statistics.OFStatistics;
import org.openflow.protocol.statistics.OFTableStatistics;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Converts an openflow list of table statistics in a SAL list of
 * NodeTableStatistics objects
 */
public class TableStatisticsConverter {
    private static final Logger log = LoggerFactory
            .getLogger(TableStatisticsConverter.class);

    private final long switchId;
    private List ofStatsList;
    private List ntStatsList;

    public TableStatisticsConverter(long switchId, List statsList) {
        this.switchId = switchId;
        if (statsList == null || statsList.isEmpty()) {
            this.ofStatsList = new ArrayList(1); // dummy list
        } else {
            this.ofStatsList = new ArrayList(statsList);
        }
        this.ntStatsList = null;
    }

    public List getNodeTableStatsList() {
        if (this.ofStatsList != null && this.ntStatsList == null) {
            this.ntStatsList = new ArrayList();
            OFTableStatistics ofTableStat;
            Node node = NodeCreator.createOFNode(switchId);
            for (OFStatistics ofStat : this.ofStatsList) {
                ofTableStat = (OFTableStatistics) ofStat;
                NodeTableStatistics ntStat = new NodeTableStatistics();
                ntStat.setNodeTable(TableConverter.toNodeTable(
                        ofTableStat.getTableId(), node));
                ntStat.setActiveCount(ofTableStat.getActiveCount());
                ntStat.setLookupCount(ofTableStat.getLookupCount());
                ntStat.setMatchedCount(ofTableStat.getMatchedCount());
                this.ntStatsList.add(ntStat);
            }
        }
        log.trace("OFStatistics: {} NodeTableStatistics: {}", ofStatsList,
                ntStatsList);
        return this.ntStatsList;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy