Moving PortStatistcs port number to Long to aling with Port class

Change-Id: I43ab8760dc3bf192cd2f47511819076fbf1070b6
This commit is contained in:
Andrea Campanella 2017-09-01 11:28:59 +02:00 committed by Carmelo Cascone
parent b045ddce4a
commit c86154a8a1
2 changed files with 40 additions and 9 deletions

View File

@ -16,6 +16,7 @@
package org.onosproject.net.device; package org.onosproject.net.device;
import org.onosproject.net.DeviceId; import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
/** /**
* Default implementation of immutable port statistics. * Default implementation of immutable port statistics.
@ -23,7 +24,7 @@ import org.onosproject.net.DeviceId;
public final class DefaultPortStatistics implements PortStatistics { public final class DefaultPortStatistics implements PortStatistics {
private final DeviceId deviceId; private final DeviceId deviceId;
private final int port; private final PortNumber portNumber;
private final long packetsReceived; private final long packetsReceived;
private final long packetsSent; private final long packetsSent;
private final long bytesReceived; private final long bytesReceived;
@ -36,7 +37,7 @@ public final class DefaultPortStatistics implements PortStatistics {
private final long durationNano; private final long durationNano;
private DefaultPortStatistics(DeviceId deviceId, private DefaultPortStatistics(DeviceId deviceId,
int port, PortNumber portNumber,
long packetsReceived, long packetsReceived,
long packetsSent, long packetsSent,
long bytesReceived, long bytesReceived,
@ -48,7 +49,7 @@ public final class DefaultPortStatistics implements PortStatistics {
long durationSec, long durationSec,
long durationNano) { long durationNano) {
this.deviceId = deviceId; this.deviceId = deviceId;
this.port = port; this.portNumber = portNumber;
this.packetsReceived = packetsReceived; this.packetsReceived = packetsReceived;
this.packetsSent = packetsSent; this.packetsSent = packetsSent;
this.bytesReceived = bytesReceived; this.bytesReceived = bytesReceived;
@ -64,7 +65,7 @@ public final class DefaultPortStatistics implements PortStatistics {
// Constructor for serializer // Constructor for serializer
private DefaultPortStatistics() { private DefaultPortStatistics() {
this.deviceId = null; this.deviceId = null;
this.port = 0; this.portNumber = null;
this.packetsReceived = 0; this.packetsReceived = 0;
this.packetsSent = 0; this.packetsSent = 0;
this.bytesReceived = 0; this.bytesReceived = 0;
@ -88,7 +89,12 @@ public final class DefaultPortStatistics implements PortStatistics {
@Override @Override
public int port() { public int port() {
return this.port; return (int) this.portNumber.toLong();
}
@Override
public PortNumber portNumber() {
return this.portNumber;
} }
@Override @Override
@ -154,7 +160,7 @@ public final class DefaultPortStatistics implements PortStatistics {
@Override @Override
public String toString() { public String toString() {
return "device: " + deviceId + ", " + return "device: " + deviceId + ", " +
"port: " + this.port + ", " + "port: " + this.portNumber + ", " +
"pktRx: " + this.packetsReceived + ", " + "pktRx: " + this.packetsReceived + ", " +
"pktTx: " + this.packetsSent + ", " + "pktTx: " + this.packetsSent + ", " +
"byteRx: " + this.bytesReceived + ", " + "byteRx: " + this.bytesReceived + ", " +
@ -168,7 +174,7 @@ public final class DefaultPortStatistics implements PortStatistics {
public static final class Builder { public static final class Builder {
DeviceId deviceId; DeviceId deviceId;
int port; PortNumber portNumber;
long packetsReceived; long packetsReceived;
long packetsSent; long packetsSent;
long bytesReceived; long bytesReceived;
@ -189,9 +195,23 @@ public final class DefaultPortStatistics implements PortStatistics {
* *
* @param port port number * @param port port number
* @return builder object * @return builder object
* @deprecated ONOS 1.12 Magpie
*/ */
@Deprecated
public Builder setPort(int port) { public Builder setPort(int port) {
this.port = port; this.portNumber = PortNumber.portNumber(port);
return this;
}
/**
* Sets port number.
*
* @param portNumber port number
* @return builder object
*/
public Builder setPort(PortNumber portNumber) {
this.portNumber = portNumber;
return this; return this;
} }
@ -336,7 +356,7 @@ public final class DefaultPortStatistics implements PortStatistics {
public DefaultPortStatistics build() { public DefaultPortStatistics build() {
return new DefaultPortStatistics( return new DefaultPortStatistics(
deviceId, deviceId,
port, portNumber,
packetsReceived, packetsReceived,
packetsSent, packetsSent,
bytesReceived, bytesReceived,

View File

@ -15,6 +15,8 @@
*/ */
package org.onosproject.net.device; package org.onosproject.net.device;
import org.onosproject.net.PortNumber;
/** /**
* Statistics of a port. * Statistics of a port.
*/ */
@ -24,9 +26,18 @@ public interface PortStatistics {
* Returns the port number. * Returns the port number.
* *
* @return port number * @return port number
* @deprecated ONOS 1.12 Magpie please use portNumber()
*/ */
@Deprecated
int port(); int port();
/**
* Returns the port number.
*
* @return port number
*/
PortNumber portNumber();
/** /**
* Returns the number of packets received. * Returns the number of packets received.
* *