2 * Copyright (c) 2013 Cisco Systems, Inc. and others. 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
9 package org.opendaylight.controller.protocol_plugin.openflow.internal;
11 import java.util.ArrayList;
12 import java.util.List;
14 import org.opendaylight.controller.sal.core.Node;
15 import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
16 import org.opendaylight.controller.sal.utils.NodeCreator;
17 import org.openflow.protocol.statistics.OFPortStatisticsReply;
18 import org.openflow.protocol.statistics.OFStatistics;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * Converts an openflow list of port statistics in a SAL list of
24 * NodeConnectorStatistics objects
29 public class PortStatisticsConverter {
30 private static final Logger log = LoggerFactory
31 .getLogger(PortStatisticsConverter.class);
32 private long switchId;
33 private List<OFStatistics> ofStatsList;
34 private List<NodeConnectorStatistics> ncStatsList;
36 public PortStatisticsConverter(long switchId, List<OFStatistics> statsList) {
37 this.switchId = switchId;
38 if (statsList == null || statsList.isEmpty()) {
39 this.ofStatsList = new ArrayList<OFStatistics>(1); // dummy list
41 this.ofStatsList = new ArrayList<OFStatistics>(statsList);
43 this.ncStatsList = null;
46 public List<NodeConnectorStatistics> getNodeConnectorStatsList() {
47 if (this.ofStatsList != null && this.ncStatsList == null) {
48 this.ncStatsList = new ArrayList<NodeConnectorStatistics>();
49 OFPortStatisticsReply ofPortStat;
50 Node node = NodeCreator.createOFNode(switchId);
51 for (OFStatistics ofStat : this.ofStatsList) {
52 ofPortStat = (OFPortStatisticsReply) ofStat;
53 NodeConnectorStatistics NCStat = new NodeConnectorStatistics();
54 NCStat.setNodeConnector(PortConverter.toNodeConnector(
55 ofPortStat.getPortNumber(), node));
56 NCStat.setReceivePacketCount(ofPortStat.getreceivePackets());
57 NCStat.setTransmitPacketCount(ofPortStat.getTransmitPackets());
58 NCStat.setReceiveByteCount(ofPortStat.getReceiveBytes());
59 NCStat.setTransmitByteCount(ofPortStat.getTransmitBytes());
60 NCStat.setReceiveDropCount(ofPortStat.getReceiveDropped());
61 NCStat.setTransmitDropCount(ofPortStat.getTransmitDropped());
62 NCStat.setReceiveErrorCount(ofPortStat.getreceiveErrors());
63 NCStat.setTransmitErrorCount(ofPortStat.getTransmitErrors());
64 NCStat.setReceiveFrameErrorCount(ofPortStat
65 .getReceiveFrameErrors());
66 NCStat.setReceiveOverRunErrorCount(ofPortStat
67 .getReceiveOverrunErrors());
68 NCStat.setReceiveCRCErrorCount(ofPortStat.getReceiveCRCErrors());
69 NCStat.setCollisionCount(ofPortStat.getCollisions());
70 this.ncStatsList.add(NCStat);
73 log.trace("OFStatistics: {} NodeConnectorStatistics: {}", ofStatsList,
75 return this.ncStatsList;