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.Collections;
13 import java.util.List;
15 import org.opendaylight.controller.sal.core.Node;
16 import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
17 import org.opendaylight.controller.sal.utils.NodeCreator;
18 import org.openflow.protocol.statistics.OFPortStatisticsReply;
19 import org.openflow.protocol.statistics.OFStatistics;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * Converts an openflow list of port statistics in a SAL list of
25 * NodeConnectorStatistics objects
30 public class PortStatisticsConverter {
31 private static final Logger log = LoggerFactory
32 .getLogger(PortStatisticsConverter.class);
33 private long switchId;
34 private List<OFStatistics> ofStatsList;
35 private List<NodeConnectorStatistics> ncStatsList;
37 public PortStatisticsConverter(long switchId, List<OFStatistics> statsList) {
38 this.switchId = switchId;
39 if (statsList == null || statsList.isEmpty()) {
40 this.ofStatsList = Collections.emptyList();
42 this.ofStatsList = new ArrayList<OFStatistics>(statsList);
44 this.ncStatsList = null;
47 public List<NodeConnectorStatistics> getNodeConnectorStatsList() {
48 if (this.ofStatsList != null && this.ncStatsList == null) {
49 this.ncStatsList = new ArrayList<NodeConnectorStatistics>();
50 OFPortStatisticsReply ofPortStat;
51 Node node = NodeCreator.createOFNode(switchId);
52 for (OFStatistics ofStat : this.ofStatsList) {
53 ofPortStat = (OFPortStatisticsReply) ofStat;
54 NodeConnectorStatistics NCStat = new NodeConnectorStatistics();
55 NCStat.setNodeConnector(PortConverter.toNodeConnector(
56 ofPortStat.getPortNumber(), node));
57 NCStat.setReceivePacketCount(ofPortStat.getreceivePackets());
58 NCStat.setTransmitPacketCount(ofPortStat.getTransmitPackets());
59 NCStat.setReceiveByteCount(ofPortStat.getReceiveBytes());
60 NCStat.setTransmitByteCount(ofPortStat.getTransmitBytes());
61 NCStat.setReceiveDropCount(ofPortStat.getReceiveDropped());
62 NCStat.setTransmitDropCount(ofPortStat.getTransmitDropped());
63 NCStat.setReceiveErrorCount(ofPortStat.getreceiveErrors());
64 NCStat.setTransmitErrorCount(ofPortStat.getTransmitErrors());
65 NCStat.setReceiveFrameErrorCount(ofPortStat
66 .getReceiveFrameErrors());
67 NCStat.setReceiveOverRunErrorCount(ofPortStat
68 .getReceiveOverrunErrors());
69 NCStat.setReceiveCRCErrorCount(ofPortStat.getReceiveCRCErrors());
70 NCStat.setCollisionCount(ofPortStat.getCollisions());
71 this.ncStatsList.add(NCStat);
74 log.trace("OFStatistics: {} NodeConnectorStatistics: {}", ofStatsList,
76 return this.ncStatsList;