/* * Copyright (c) 2013 Cisco Systems, Inc. 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 */ package org.opendaylight.controller.protocol_plugin.openflow.internal; import java.util.ArrayList; import java.util.List; import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.reader.NodeConnectorStatistics; import org.opendaylight.controller.sal.utils.NodeCreator; import org.openflow.protocol.statistics.OFPortStatisticsReply; import org.openflow.protocol.statistics.OFStatistics; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Converts an openflow list of port statistics in a SAL list of * NodeConnectorStatistics objects * * * */ public class PortStatisticsConverter { private static final Logger log = LoggerFactory .getLogger(PortStatisticsConverter.class); private long switchId; private List ofStatsList; private List ncStatsList; public PortStatisticsConverter(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.ncStatsList = null; } public List getNodeConnectorStatsList() { if (this.ofStatsList != null && this.ncStatsList == null) { this.ncStatsList = new ArrayList(); OFPortStatisticsReply ofPortStat; Node node = NodeCreator.createOFNode(switchId); for (OFStatistics ofStat : this.ofStatsList) { ofPortStat = (OFPortStatisticsReply) ofStat; NodeConnectorStatistics NCStat = new NodeConnectorStatistics(); NCStat.setNodeConnector(PortConverter.toNodeConnector( ofPortStat.getPortNumber(), node)); NCStat.setReceivePacketCount(ofPortStat.getreceivePackets()); NCStat.setTransmitPacketCount(ofPortStat.getTransmitPackets()); NCStat.setReceiveByteCount(ofPortStat.getReceiveBytes()); NCStat.setTransmitByteCount(ofPortStat.getTransmitBytes()); NCStat.setReceiveDropCount(ofPortStat.getReceiveDropped()); NCStat.setTransmitDropCount(ofPortStat.getTransmitDropped()); NCStat.setReceiveErrorCount(ofPortStat.getreceiveErrors()); NCStat.setTransmitErrorCount(ofPortStat.getTransmitErrors()); NCStat.setReceiveFrameErrorCount(ofPortStat .getReceiveFrameErrors()); NCStat.setReceiveOverRunErrorCount(ofPortStat .getReceiveOverrunErrors()); NCStat.setReceiveCRCErrorCount(ofPortStat.getReceiveCRCErrors()); NCStat.setCollisionCount(ofPortStat.getCollisions()); this.ncStatsList.add(NCStat); } } log.trace("OFStatistics: {} NodeConnectorStatistics: {}", ofStatsList, ncStatsList); return this.ncStatsList; } }