X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fprotocol_plugins%2Fopenflow%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fprotocol_plugin%2Fopenflow%2Finternal%2FPortStatisticsConverter.java;fp=opendaylight%2Fprotocol_plugins%2Fopenflow%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fprotocol_plugin%2Fopenflow%2Finternal%2FPortStatisticsConverter.java;h=2b4df3f0c10ce7b3dddf463a29dfc37b7fb978a7;hb=29f7cfb54b580928c7feac63abce028a7014b0d5;hp=0000000000000000000000000000000000000000;hpb=42210c03b0a4c54706320ba9f55794c0abd4d201;p=controller.git diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/PortStatisticsConverter.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/PortStatisticsConverter.java new file mode 100644 index 0000000000..2b4df3f0c1 --- /dev/null +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/PortStatisticsConverter.java @@ -0,0 +1,76 @@ + +/* + * 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.openflow.protocol.statistics.OFPortStatisticsReply; +import org.openflow.protocol.statistics.OFStatistics; + +import org.opendaylight.controller.sal.core.Node; +import org.opendaylight.controller.sal.reader.NodeConnectorStatistics; +import org.opendaylight.controller.sal.utils.NodeCreator; + +/** + * Converts an openflow list of port statistics in a SAL list of + * NodeConnectorStatistics objects + * + * + * + */ +public class PortStatisticsConverter { + 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); + } + } + return this.ncStatsList; + } + +}