mirror of
https://github.com/opennetworkinglab/onos.git
synced 2026-05-04 19:56:49 +02:00
Fix few commands handling PortNumber as args.
- should now be able to handle named ports Change-Id: Ic913f2ac8e1cfd7a0fa2a7631bd5c207b9747eee
This commit is contained in:
parent
c584bd9278
commit
820f034f98
@ -37,7 +37,7 @@ public class DevicePortStateCommand extends AbstractShellCommand {
|
||||
|
||||
@Argument(index = 1, name = "portNumber", description = "Port Number",
|
||||
required = true, multiValued = false)
|
||||
Integer portNumber = null;
|
||||
String portNumber = null;
|
||||
|
||||
@Argument(index = 2, name = "portState",
|
||||
description = "Desired State. Either \"enable\" or \"disable\".",
|
||||
@ -53,7 +53,7 @@ public class DevicePortStateCommand extends AbstractShellCommand {
|
||||
print(" %s", "Device does not exist");
|
||||
return;
|
||||
}
|
||||
PortNumber pnum = PortNumber.portNumber(portNumber);
|
||||
PortNumber pnum = PortNumber.fromString(portNumber);
|
||||
Port p = deviceService.getPort(dev.id(), pnum);
|
||||
if (p == null) {
|
||||
print(" %s", "Port does not exist");
|
||||
|
||||
@ -18,6 +18,7 @@ package org.onosproject.cli.net;
|
||||
import static org.onosproject.cli.net.DevicesListCommand.getSortedDevices;
|
||||
import static org.onosproject.net.DeviceId.deviceId;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -28,6 +29,7 @@ import org.apache.karaf.shell.commands.Option;
|
||||
import org.onosproject.cli.AbstractShellCommand;
|
||||
import org.onosproject.net.Device;
|
||||
import org.onosproject.net.DeviceId;
|
||||
import org.onosproject.net.PortNumber;
|
||||
import org.onosproject.net.device.DeviceService;
|
||||
import org.onosproject.net.device.PortStatistics;
|
||||
|
||||
@ -60,7 +62,9 @@ public class DevicePortStatsCommand extends AbstractShellCommand {
|
||||
|
||||
@Argument(index = 1, name = "portNumber", description = "Port Number",
|
||||
required = false, multiValued = false)
|
||||
Integer portNumber = null;
|
||||
String portNumberStr = null;
|
||||
|
||||
PortNumber portNumber = null;
|
||||
|
||||
private static final String FORMAT =
|
||||
" port=%s, pktRx=%s, pktTx=%s, bytesRx=%s, bytesTx=%s, pktRxDrp=%s, pktTxDrp=%s, Dur=%s";
|
||||
@ -69,6 +73,10 @@ public class DevicePortStatsCommand extends AbstractShellCommand {
|
||||
protected void execute() {
|
||||
DeviceService deviceService = get(DeviceService.class);
|
||||
|
||||
if (portNumberStr != null) {
|
||||
portNumber = PortNumber.fromString(portNumberStr);
|
||||
}
|
||||
|
||||
if (uri == null) {
|
||||
for (Device d : getSortedDevices(deviceService)) {
|
||||
if (delta) {
|
||||
@ -106,17 +114,22 @@ public class DevicePortStatsCommand extends AbstractShellCommand {
|
||||
private void printPortStats(DeviceId deviceId, Iterable<PortStatistics> portStats) {
|
||||
print("deviceId=%s", deviceId);
|
||||
for (PortStatistics stat : sortByPort(portStats)) {
|
||||
if (portNumber != null && stat.port() != portNumber) {
|
||||
if (isIrrelevant(stat)) {
|
||||
continue;
|
||||
}
|
||||
if (nonzero && stat.isZero()) {
|
||||
continue;
|
||||
}
|
||||
print(FORMAT, stat.port(), stat.packetsReceived(), stat.packetsSent(), stat.bytesReceived(),
|
||||
print(FORMAT, stat.portNumber(), stat.packetsReceived(), stat.packetsSent(), stat.bytesReceived(),
|
||||
stat.bytesSent(), stat.packetsRxDropped(), stat.packetsTxDropped(), stat.durationSec());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isIrrelevant(PortStatistics stat) {
|
||||
// TODO revisit logical port (e.g., ALL) handling
|
||||
return portNumber != null && !portNumber.equals(stat.portNumber());
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints Port delta statistics.
|
||||
*
|
||||
@ -128,7 +141,7 @@ public class DevicePortStatsCommand extends AbstractShellCommand {
|
||||
+ " rateRx=%s, rateTx=%s, pktRxDrp=%s, pktTxDrp=%s, interval=%s";
|
||||
print("deviceId=%s", deviceId);
|
||||
for (PortStatistics stat : sortByPort(portStats)) {
|
||||
if (portNumber != null && stat.port() != portNumber) {
|
||||
if (isIrrelevant(stat)) {
|
||||
continue;
|
||||
}
|
||||
if (nonzero && stat.isZero()) {
|
||||
@ -138,7 +151,7 @@ public class DevicePortStatsCommand extends AbstractShellCommand {
|
||||
(((float) stat.durationNano()) / TimeUnit.SECONDS.toNanos(1));
|
||||
float rateRx = stat.bytesReceived() * 8 / duration;
|
||||
float rateTx = stat.bytesSent() * 8 / duration;
|
||||
print(formatDelta, stat.port(),
|
||||
print(formatDelta, stat.portNumber(),
|
||||
stat.packetsReceived(),
|
||||
stat.packetsSent(),
|
||||
stat.bytesReceived(),
|
||||
@ -167,7 +180,7 @@ public class DevicePortStatsCommand extends AbstractShellCommand {
|
||||
print("|---------------------------------------------------------------------------------------------------|");
|
||||
|
||||
for (PortStatistics stat : sortByPort(portStats)) {
|
||||
if (portNumber != null && stat.port() != portNumber) {
|
||||
if (isIrrelevant(stat)) {
|
||||
continue;
|
||||
}
|
||||
if (nonzero && stat.isZero()) {
|
||||
@ -177,7 +190,7 @@ public class DevicePortStatsCommand extends AbstractShellCommand {
|
||||
(((float) stat.durationNano()) / TimeUnit.SECONDS.toNanos(1));
|
||||
float rateRx = duration > 0 ? stat.bytesReceived() * 8 / duration : 0;
|
||||
float rateTx = duration > 0 ? stat.bytesSent() * 8 / duration : 0;
|
||||
print(formatDeltaTable, stat.port(),
|
||||
print(formatDeltaTable, stat.portNumber(),
|
||||
humanReadable(stat.packetsReceived()),
|
||||
humanReadable(stat.bytesReceived()),
|
||||
humanReadableBps(rateRx),
|
||||
@ -225,8 +238,8 @@ public class DevicePortStatsCommand extends AbstractShellCommand {
|
||||
|
||||
private static List<PortStatistics> sortByPort(Iterable<PortStatistics> portStats) {
|
||||
List<PortStatistics> portStatsList = Lists.newArrayList(portStats);
|
||||
portStatsList.sort((PortStatistics o1, PortStatistics o2) ->
|
||||
o1.port() - o2.port());
|
||||
|
||||
portStatsList.sort(Comparator.comparing(ps -> ps.portNumber().toLong()));
|
||||
return portStatsList;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user