Jonathan Hart
Committed by Gerrit Code Review

Improvements to flows list command.

 * Added -s option which gives more succinct output.
 * Display each flow on one line for easy grepping.
 * Added ability to filter output by table ID.
 * Flows are now sorted by descending priority within a table.
 * Removed the use of toStringHelper in instructions and criterion to produce
   less verbose output.

Change-Id: I1c874c776491386488ea5a4d23627b20f1e5728b
Showing 46 changed files with 202 additions and 270 deletions
......@@ -71,10 +71,16 @@ public final class Comparators {
public static final Comparator<FlowRule> FLOW_RULE_COMPARATOR = new Comparator<FlowRule>() {
@Override
public int compare(FlowRule f1, FlowRule f2) {
int tableCompare = Integer.valueOf(f1.tableId()).compareTo(f2.tableId());
return (tableCompare == 0)
// Compare table IDs in ascending order
int tableCompare = f1.tableId() - f2.tableId();
if (tableCompare != 0) {
return tableCompare;
}
// Compare priorities in descending order
int priorityCompare = f2.priority() - f1.priority();
return (priorityCompare == 0)
? Long.valueOf(f1.id().value()).compareTo(f2.id().value())
: tableCompare;
: priorityCompare;
}
};
......
......@@ -15,16 +15,13 @@
*/
package org.onosproject.cli.net;
import static com.google.common.collect.Lists.newArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.commands.Option;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.cli.Comparators;
import org.onosproject.core.ApplicationId;
......@@ -35,11 +32,16 @@ import org.onosproject.net.device.DeviceService;
import org.onosproject.net.flow.FlowEntry;
import org.onosproject.net.flow.FlowEntry.FlowEntryState;
import org.onosproject.net.flow.FlowRuleService;
import org.onosproject.net.flow.TrafficTreatment;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.function.Predicate;
import static com.google.common.collect.Lists.newArrayList;
/**
* Lists all currently-known flows.
......@@ -48,26 +50,44 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
description = "Lists all currently-known flows.")
public class FlowsListCommand extends AbstractShellCommand {
private static final Predicate<FlowEntry> TRUE_PREDICATE = f -> true;
public static final String ANY = "any";
private static final String FMT =
" id=%s, state=%s, bytes=%s, packets=%s, duration=%s, priority=%s, tableId=%s appId=%s, payLoad=%s";
private static final String TFMT = " treatment=%s";
private static final String SFMT = " selector=%s";
private static final String LONG_FORMAT = " id=%s, state=%s, bytes=%s, "
+ "packets=%s, duration=%s, priority=%s, tableId=%s, appId=%s, "
+ "payLoad=%s, selector=%s, treatment=%s";
private static final String SHORT_FORMAT = " %s, bytes=%s, packets=%s, "
+ "table=%s, priority=%s, selector=%s, treatment=%s";
@Argument(index = 0, name = "state", description = "Flow Rule state",
required = false, multiValued = false)
String state = null;
@Argument(index = 1, name = "uri", description = "Device ID",
required = false, multiValued = false)
String uri = null;
@Argument(index = 0, name = "state", description = "Flow Rule state",
required = false, multiValued = false)
String state = null;
@Argument(index = 2, name = "table", description = "Table ID",
required = false, multiValued = false)
String table = null;
@Option(name = "-s", aliases = "--short",
description = "Print more succinct output for each flow",
required = false, multiValued = false)
private boolean shortOutput = false;
private Predicate<FlowEntry> predicate = TRUE_PREDICATE;
@Override
protected void execute() {
CoreService coreService = get(CoreService.class);
DeviceService deviceService = get(DeviceService.class);
FlowRuleService service = get(FlowRuleService.class);
compilePredicate();
SortedMap<Device, List<FlowEntry>> flows = getSortedFlows(deviceService, service);
if (outputJson()) {
......@@ -94,6 +114,22 @@ public class FlowsListCommand extends AbstractShellCommand {
return result;
}
/**
* Compiles a predicate to find matching flows based on the command
* arguments.
*/
private void compilePredicate() {
if (state != null && !state.equals(ANY)) {
final FlowEntryState feState = FlowEntryState.valueOf(state.toUpperCase());
predicate = predicate.and(f -> f.state().equals(feState));
}
if (table != null) {
final int tableId = Integer.parseInt(table);
predicate = predicate.and(f -> f.tableId() == tableId);
}
}
// Produces JSON object with the flows of the given device.
private ObjectNode json(ObjectMapper mapper,
Device device, List<FlowEntry> flows) {
......@@ -119,10 +155,7 @@ public class FlowsListCommand extends AbstractShellCommand {
FlowRuleService service) {
SortedMap<Device, List<FlowEntry>> flows = new TreeMap<>(Comparators.ELEMENT_COMPARATOR);
List<FlowEntry> rules;
FlowEntryState s = null;
if (state != null && !state.equals("any")) {
s = FlowEntryState.valueOf(state.toUpperCase());
}
Iterable<Device> devices = null;
if (uri == null) {
devices = deviceService.getDevices();
......@@ -131,13 +164,14 @@ public class FlowsListCommand extends AbstractShellCommand {
devices = (dev == null) ? deviceService.getDevices()
: Collections.singletonList(dev);
}
for (Device d : devices) {
if (s == null) {
if (predicate.equals(TRUE_PREDICATE)) {
rules = newArrayList(service.getFlowEntries(d.id()));
} else {
rules = newArrayList();
for (FlowEntry f : service.getFlowEntries(d.id())) {
if (f.state().equals(s)) {
if (predicate.test(f)) {
rules.add(f);
}
}
......@@ -159,17 +193,51 @@ public class FlowsListCommand extends AbstractShellCommand {
CoreService coreService) {
boolean empty = flows == null || flows.isEmpty();
print("deviceId=%s, flowRuleCount=%d", d.id(), empty ? 0 : flows.size());
if (!empty) {
for (FlowEntry f : flows) {
if (empty) {
return;
}
for (FlowEntry f : flows) {
if (shortOutput) {
print(SHORT_FORMAT, f.state(), f.bytes(), f.packets(),
f.tableId(), f.priority(), f.selector().criteria(),
printTreatment(f.treatment()));
} else {
ApplicationId appId = coreService.getAppId(f.appId());
print(FMT, Long.toHexString(f.id().value()), f.state(),
f.bytes(), f.packets(), f.life(), f.priority(), f.tableId(),
appId != null ? appId.name() : "<none>",
f.payLoad() == null ? null : f.payLoad().payLoad().toString());
print(SFMT, f.selector().criteria());
print(TFMT, f.treatment());
print(LONG_FORMAT, Long.toHexString(f.id().value()), f.state(),
f.bytes(), f.packets(), f.life(), f.priority(), f.tableId(),
appId != null ? appId.name() : "<none>",
f.payLoad() == null ? null : f.payLoad().payLoad().toString(),
f.selector().criteria(), f.treatment());
}
}
}
private String printTreatment(TrafficTreatment treatment) {
final String delimiter = ", ";
StringBuilder builder = new StringBuilder("[");
if (!treatment.immediate().isEmpty()) {
builder.append("immediate=" + treatment.immediate() + delimiter);
}
if (!treatment.deferred().isEmpty()) {
builder.append("deferred=" + treatment.deferred() + delimiter);
}
if (treatment.clearedDeferred()) {
builder.append("clearDeferred" + delimiter);
}
if (treatment.tableTransition() != null) {
builder.append("transition=" + treatment.tableTransition() + delimiter);
}
if (treatment.metered() != null) {
builder.append("meter=" + treatment.metered() + delimiter);
}
if (treatment.writeMetadata() != null) {
builder.append("metadata=" + treatment.writeMetadata() + delimiter);
}
// Chop off last delimiter
builder.replace(builder.length() - delimiter.length(), builder.length(), "");
builder.append("]");
return builder.toString();
}
}
......
......@@ -427,6 +427,8 @@
<completers>
<ref component-id="flowRuleStatusCompleter"/>
<ref component-id="deviceIdCompleter"/>
<ref component-id="placeholderCompleter"/>
<null/>
</completers>
</command>
......
......@@ -15,12 +15,11 @@
*/
package org.onosproject.net.flow.criteria;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
import org.onlab.packet.MacAddress;
import java.util.Objects;
import org.onlab.packet.MacAddress;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Implementation of arp_eth_src address or arp_eth_dst address criterion.
......@@ -59,8 +58,7 @@ public final class ArpHaCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("mac", mac).toString();
return type().toString() + SEPARATOR + mac;
}
@Override
......@@ -80,4 +78,4 @@ public final class ArpHaCriterion implements Criterion {
}
return false;
}
}
\ No newline at end of file
}
......
......@@ -15,8 +15,6 @@
*/
package org.onosproject.net.flow.criteria;
import static com.google.common.base.MoreObjects.toStringHelper;
import java.util.Objects;
/**
......@@ -54,8 +52,7 @@ public final class ArpOpCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("arpOp", arpOp).toString();
return type().toString() + SEPARATOR + arpOp;
}
@Override
......@@ -75,4 +72,4 @@ public final class ArpOpCriterion implements Criterion {
}
return false;
}
}
\ No newline at end of file
}
......
......@@ -15,12 +15,10 @@
*/
package org.onosproject.net.flow.criteria;
import static com.google.common.base.MoreObjects.toStringHelper;
import org.onlab.packet.Ip4Address;
import java.util.Objects;
import org.onlab.packet.Ip4Address;
/**
* Implementation of arp spa or tpa address criterion.
*/
......@@ -56,8 +54,7 @@ public final class ArpPaCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("ip", ip).toString();
return type().toString() + SEPARATOR + ip;
}
@Override
......@@ -77,4 +74,4 @@ public final class ArpPaCriterion implements Criterion {
}
return false;
}
}
\ No newline at end of file
}
......
......@@ -21,6 +21,8 @@ package org.onosproject.net.flow.criteria;
*/
public interface Criterion {
static final String SEPARATOR = ":";
/**
* Types of fields to which the selection criterion may apply.
*/
......
......@@ -19,8 +19,6 @@ import org.onlab.packet.MacAddress;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of MAC address criterion.
*/
......@@ -56,8 +54,7 @@ public final class EthCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("mac", mac).toString();
return type().toString() + SEPARATOR + mac;
}
@Override
......
......@@ -19,8 +19,6 @@ import org.onlab.packet.EthType;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of Ethernet type criterion (16 bits unsigned integer).
*/
......@@ -64,9 +62,7 @@ public final class EthTypeCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("ethType", ethType.toString())
.toString();
return type().toString() + SEPARATOR + ethType;
}
@Override
......
......@@ -20,8 +20,6 @@ import org.onosproject.net.DeviceId;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Criterion for implementing selector extensions.
*/
......@@ -66,10 +64,7 @@ public class ExtensionCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("extensionSelector", extensionSelector.toString())
.add("deviceId", deviceId)
.toString();
return type().toString() + SEPARATOR + deviceId + "/" + extensionSelector;
}
@Override
......
......@@ -19,8 +19,6 @@ import org.onlab.packet.IpPrefix;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of IP address criterion.
*/
......@@ -56,8 +54,7 @@ public final class IPCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("ip", ip).toString();
return type().toString() + SEPARATOR + ip;
}
@Override
......
......@@ -17,8 +17,6 @@ package org.onosproject.net.flow.criteria;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of IP DSCP (Differentiated Services Code Point)
* criterion (6 bits).
......@@ -52,8 +50,7 @@ public final class IPDscpCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("ipDscp", Long.toHexString(ipDscp)).toString();
return type().toString() + SEPARATOR + Long.toHexString(ipDscp);
}
@Override
......
......@@ -17,8 +17,6 @@ package org.onosproject.net.flow.criteria;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of IP ECN (Explicit Congestion Notification) criterion
* (2 bits).
......@@ -52,8 +50,7 @@ public final class IPEcnCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("ipEcn", Long.toHexString(ipEcn)).toString();
return type().toString() + SEPARATOR + Long.toHexString(ipEcn);
}
@Override
......
......@@ -17,8 +17,6 @@ package org.onosproject.net.flow.criteria;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of Internet Protocol Number criterion (8 bits unsigned)
* integer.
......@@ -53,8 +51,7 @@ public final class IPProtocolCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("protocol", proto).toString();
return type().toString() + SEPARATOR + proto;
}
@Override
......
......@@ -17,8 +17,6 @@ package org.onosproject.net.flow.criteria;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of IPv6 Extension Header pseudo-field criterion
* (16 bits). Those are defined in Criterion.IPv6ExthdrFlags.
......@@ -54,8 +52,7 @@ public final class IPv6ExthdrFlagsCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("exthdrFlags", Long.toHexString(exthdrFlags)).toString();
return type().toString() + SEPARATOR + Long.toHexString(exthdrFlags);
}
@Override
......
......@@ -17,8 +17,6 @@ package org.onosproject.net.flow.criteria;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of IPv6 Flow Label (RFC 6437) criterion (20 bits unsigned
* integer).
......@@ -52,8 +50,7 @@ public final class IPv6FlowLabelCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("flowLabel", Long.toHexString(flowLabel)).toString();
return type().toString() + SEPARATOR + Long.toHexString(flowLabel);
}
@Override
......
......@@ -19,8 +19,6 @@ import org.onlab.packet.MacAddress;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of IPv6 Neighbor Discovery link-layer address criterion.
*/
......@@ -56,8 +54,7 @@ public final class IPv6NDLinkLayerAddressCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("mac", mac).toString();
return type().toString() + SEPARATOR + mac;
}
@Override
......
......@@ -19,8 +19,6 @@ import org.onlab.packet.Ip6Address;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of IPv6 Neighbor Discovery target address criterion.
*/
......@@ -52,8 +50,7 @@ public final class IPv6NDTargetAddressCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("targetAddress", targetAddress).toString();
return type().toString() + SEPARATOR + targetAddress;
}
@Override
......
......@@ -17,8 +17,6 @@ package org.onosproject.net.flow.criteria;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of ICMP code criterion (8 bits unsigned integer).
*/
......@@ -51,8 +49,7 @@ public final class IcmpCodeCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("icmpCode", icmpCode).toString();
return type().toString() + SEPARATOR + icmpCode;
}
@Override
......
......@@ -17,8 +17,6 @@ package org.onosproject.net.flow.criteria;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of ICMP type criterion (8 bits unsigned integer).
*/
......@@ -51,8 +49,7 @@ public final class IcmpTypeCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("icmpType", icmpType).toString();
return type().toString() + SEPARATOR + icmpType;
}
@Override
......
......@@ -17,8 +17,6 @@ package org.onosproject.net.flow.criteria;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of ICMPv6 code criterion (8 bits unsigned integer).
*/
......@@ -51,8 +49,7 @@ public final class Icmpv6CodeCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("icmpv6Code", icmpv6Code).toString();
return type().toString() + SEPARATOR + icmpv6Code;
}
@Override
......
......@@ -17,8 +17,6 @@ package org.onosproject.net.flow.criteria;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of ICMPv6 type criterion (8 bits unsigned integer).
*/
......@@ -51,8 +49,7 @@ public final class Icmpv6TypeCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("icmpv6Type", icmpv6Type).toString();
return type().toString() + SEPARATOR + icmpv6Type;
}
@Override
......
......@@ -15,7 +15,6 @@
*/
package org.onosproject.net.flow.criteria;
import com.google.common.base.MoreObjects;
import org.onosproject.net.IndexedLambda;
import java.util.Objects;
......@@ -76,8 +75,6 @@ public class IndexedLambdaCriterion implements Criterion {
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("lambda", lambda)
.toString();
return type().toString() + SEPARATOR + lambda;
}
}
......
......@@ -17,8 +17,6 @@ package org.onosproject.net.flow.criteria;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of lambda (wavelength) criterion (16 bits unsigned
* integer).
......@@ -56,8 +54,7 @@ public final class LambdaCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("lambda", lambda).toString();
return type().toString() + SEPARATOR + lambda;
}
@Override
......
......@@ -17,8 +17,6 @@ package org.onosproject.net.flow.criteria;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of Metadata criterion.
*/
......@@ -50,9 +48,7 @@ public final class MetadataCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("metadata", Long.toHexString(metadata))
.toString();
return type().toString() + SEPARATOR + Long.toHexString(metadata);
}
@Override
......
......@@ -15,7 +15,6 @@
*/
package org.onosproject.net.flow.criteria;
import static com.google.common.base.MoreObjects.toStringHelper;
import java.util.Objects;
/**
......@@ -39,8 +38,7 @@ public class MplsBosCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("bos", mplsBos).toString();
return type().toString() + SEPARATOR + mplsBos;
}
@Override
......
......@@ -19,8 +19,6 @@ import org.onlab.packet.MplsLabel;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of MPLS tag criterion (20 bits).
*/
......@@ -43,8 +41,7 @@ public final class MplsCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("mpls", mplsLabel).toString();
return type().toString() + SEPARATOR + mplsLabel;
}
@Override
......
......@@ -17,8 +17,6 @@ package org.onosproject.net.flow.criteria;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of MPLS TC criterion (3 bits).
*/
......@@ -51,8 +49,7 @@ public final class MplsTcCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("tc", Long.toHexString(mplsTc)).toString();
return type().toString() + SEPARATOR + Long.toHexString(mplsTc);
}
@Override
......
......@@ -15,7 +15,6 @@
*/
package org.onosproject.net.flow.criteria;
import com.google.common.base.MoreObjects;
import org.onosproject.net.OchSignal;
import java.util.Objects;
......@@ -74,8 +73,6 @@ public final class OchSignalCriterion implements Criterion {
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("lambda", lambda)
.toString();
return type().toString() + SEPARATOR + lambda;
}
}
......
......@@ -15,7 +15,6 @@
*/
package org.onosproject.net.flow.criteria;
import com.google.common.base.MoreObjects;
import org.onosproject.net.OchSignalType;
import java.util.Objects;
......@@ -71,8 +70,6 @@ public class OchSignalTypeCriterion implements Criterion {
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("signalType", signalType)
.toString();
return type().toString() + SEPARATOR + signalType;
}
}
......
......@@ -15,12 +15,11 @@
*/
package org.onosproject.net.flow.criteria;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
import org.onosproject.net.OduSignalId;
import java.util.Objects;
import org.onosproject.net.OduSignalId;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Implementation of ODU (Optical channel Data Unit) signal ID signal criterion.
......@@ -74,9 +73,7 @@ public final class OduSignalIdCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(this)
.add("oduSignalId", oduSignalId)
.toString();
return type().toString() + SEPARATOR + oduSignalId;
}
}
......
......@@ -15,12 +15,11 @@
*/
package org.onosproject.net.flow.criteria;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
import org.onosproject.net.OduSignalType;
import java.util.Objects;
import org.onosproject.net.OduSignalType;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Implementation of ODU (Optical channel Data Unit) signal Type criterion.
......@@ -74,8 +73,6 @@ public final class OduSignalTypeCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(this)
.add("signalType", signalType)
.toString();
return type().toString() + SEPARATOR + signalType;
}
}
......
......@@ -17,8 +17,6 @@ package org.onosproject.net.flow.criteria;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of PBB I-SID criterion (24 bits unsigned integer).
*/
......@@ -51,8 +49,7 @@ public final class PbbIsidCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("pbbIsid", Long.toHexString(pbbIsid)).toString();
return type().toString() + SEPARATOR + Long.toHexString(pbbIsid);
}
@Override
......
......@@ -19,8 +19,6 @@ import org.onosproject.net.PortNumber;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of input port criterion.
*/
......@@ -56,8 +54,7 @@ public final class PortCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("port", port).toString();
return type().toString() + SEPARATOR + port;
}
@Override
......
......@@ -19,8 +19,6 @@ import org.onlab.packet.TpPort;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of SCTP port criterion (16 bits unsigned integer).
*/
......@@ -56,8 +54,7 @@ public final class SctpPortCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("sctpPort", sctpPort).toString();
return type().toString() + SEPARATOR + sctpPort;
}
@Override
......
......@@ -17,8 +17,6 @@ package org.onosproject.net.flow.criteria;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of TCP flags criterion (12 bits unsigned integer).
*/
......@@ -51,8 +49,7 @@ public final class TcpFlagsCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("flags", Long.toHexString(flags)).toString();
return type().toString() + SEPARATOR + Long.toHexString(flags);
}
@Override
......
......@@ -19,8 +19,6 @@ import org.onlab.packet.TpPort;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of TCP port criterion (16 bits unsigned integer).
*/
......@@ -56,8 +54,7 @@ public final class TcpPortCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("tcpPort", tcpPort).toString();
return type().toString() + SEPARATOR + tcpPort;
}
@Override
......
......@@ -16,8 +16,6 @@
package org.onosproject.net.flow.criteria;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of Tunnel ID criterion.
*/
......@@ -49,9 +47,7 @@ public class TunnelIdCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("tunnelId", Long.toHexString(tunnelId))
.toString();
return type().toString() + SEPARATOR + Long.toHexString(tunnelId);
}
@Override
......
......@@ -19,8 +19,6 @@ import org.onlab.packet.TpPort;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of UDP port criterion (16 bits unsigned integer).
*/
......@@ -56,8 +54,7 @@ public final class UdpPortCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("udpPort", udpPort).toString();
return type().toString() + SEPARATOR + udpPort;
}
@Override
......
......@@ -19,7 +19,6 @@ import org.onlab.packet.VlanId;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkArgument;
/**
......@@ -69,8 +68,7 @@ public final class VlanIdCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("vlanId", vlanId).toString();
return type().toString() + SEPARATOR + vlanId;
}
@Override
......
......@@ -17,7 +17,6 @@ package org.onosproject.net.flow.criteria;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkArgument;
/**
......@@ -68,8 +67,7 @@ public final class VlanPcpCriterion implements Criterion {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("priority", Long.toHexString(vlanPcp)).toString();
return type().toString() + SEPARATOR + Long.toHexString(vlanPcp);
}
@Override
......
......@@ -54,6 +54,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
*/
public final class Instructions {
private static final String SEPARATOR = ":";
// Ban construction
private Instructions() {}
......@@ -547,7 +549,7 @@ public final class Instructions {
@Override
public String toString() {
return toStringHelper(type().toString()).toString();
return type().toString();
}
@Override
......@@ -581,7 +583,7 @@ public final class Instructions {
@Override
public String toString() {
return toStringHelper(type().toString()).toString();
return type().toString();
}
@Override
......@@ -619,10 +621,10 @@ public final class Instructions {
public Type type() {
return Type.OUTPUT;
}
@Override
public String toString() {
return toStringHelper(type().toString())
.add("port", port).toString();
return type().toString() + SEPARATOR + port.toString();
}
@Override
......@@ -665,9 +667,7 @@ public final class Instructions {
@Override
public String toString() {
return toStringHelper(type().toString())
.addValue("group ID=0x" + Integer.toHexString(groupId.id()))
.toString();
return type().toString() + SEPARATOR + Integer.toHexString(groupId.id());
}
@Override
......@@ -770,8 +770,7 @@ public final class Instructions {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("meter ID", meterId.id()).toString();
return type().toString() + SEPARATOR + meterId.id();
}
@Override
......@@ -814,8 +813,7 @@ public final class Instructions {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("tableId", this.tableId).toString();
return type().toString() + SEPARATOR + this.tableId;
}
@Override
......@@ -864,10 +862,9 @@ public final class Instructions {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("metadata", Long.toHexString(this.metadata))
.add("metadata mask", Long.toHexString(this.metadataMask))
.toString();
return type().toString() + SEPARATOR +
Long.toHexString(this.metadata) + "/" +
Long.toHexString(this.metadataMask);
}
@Override
......@@ -917,10 +914,7 @@ public final class Instructions {
@Override
public String toString() {
return toStringHelper(type().toString())
.add("extension", extensionTreatment)
.add("deviceId", deviceId)
.toString();
return type().toString() + SEPARATOR + deviceId + "/" + extensionTreatment;
}
@Override
......
......@@ -15,15 +15,14 @@
*/
package org.onosproject.net.flow.instructions;
import com.google.common.base.MoreObjects;
import org.onosproject.net.OchSignal;
import static com.google.common.base.MoreObjects.toStringHelper;
import java.util.Objects;
public abstract class L0ModificationInstruction implements Instruction {
public static final String SEPARATOR = ":";
/**
* Represents the type of traffic treatment.
*/
......@@ -69,8 +68,7 @@ public abstract class L0ModificationInstruction implements Instruction {
@Override
public String toString() {
return toStringHelper(subtype().toString())
.add("lambda", lambda).toString();
return subtype().toString() + SEPARATOR + lambda;
}
@Override
......@@ -131,9 +129,7 @@ public abstract class L0ModificationInstruction implements Instruction {
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("lambda", lambda)
.toString();
return subtype().toString() + SEPARATOR + lambda;
}
}
}
......
......@@ -17,12 +17,12 @@ package org.onosproject.net.flow.instructions;
import org.onosproject.net.OduSignalId;
import static com.google.common.base.MoreObjects.toStringHelper;
import java.util.Objects;
public abstract class L1ModificationInstruction implements Instruction {
public static final String SEPARATOR = ":";
/**
* Represents the type of traffic treatment.
*/
......@@ -79,9 +79,7 @@ public abstract class L1ModificationInstruction implements Instruction {
@Override
public String toString() {
return toStringHelper(this)
.add("oduSignalId", oduSignalId)
.toString();
return subtype().toString() + SEPARATOR + oduSignalId;
}
}
......
......@@ -22,13 +22,13 @@ import org.onlab.packet.VlanId;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Abstraction of a single traffic treatment step.
*/
public abstract class L2ModificationInstruction implements Instruction {
private static final String SEPARATOR = ":";
/**
* Represents the type of traffic treatment.
*/
......@@ -94,9 +94,6 @@ public abstract class L2ModificationInstruction implements Instruction {
MPLS_BOS
}
// TODO: Create factory class 'Instructions' that will have various factory
// to create specific instructions.
public abstract L2SubType subtype();
@Override
......@@ -129,8 +126,7 @@ public abstract class L2ModificationInstruction implements Instruction {
@Override
public String toString() {
return toStringHelper(subtype().toString())
.add("mac", mac).toString();
return subtype().toString() + SEPARATOR + mac;
}
@Override
......@@ -176,9 +172,7 @@ public abstract class L2ModificationInstruction implements Instruction {
@Override
public String toString() {
return toStringHelper(subtype().toString())
.add("ethernetType", ethernetType())
.toString();
return subtype().toString() + SEPARATOR + ethernetType;
}
@Override
......@@ -224,8 +218,7 @@ public abstract class L2ModificationInstruction implements Instruction {
@Override
public String toString() {
return toStringHelper(subtype().toString())
.add("id", vlanId).toString();
return subtype().toString() + SEPARATOR + vlanId;
}
@Override
......@@ -269,8 +262,7 @@ public abstract class L2ModificationInstruction implements Instruction {
@Override
public String toString() {
return toStringHelper(subtype().toString())
.add("pcp", Long.toHexString(vlanPcp)).toString();
return subtype().toString() + SEPARATOR + Long.toHexString(vlanPcp);
}
@Override
......@@ -308,8 +300,7 @@ public abstract class L2ModificationInstruction implements Instruction {
@Override
public String toString() {
return toStringHelper(subtype().toString())
.toString();
return subtype().toString();
}
@Override
......@@ -365,8 +356,7 @@ public abstract class L2ModificationInstruction implements Instruction {
@Override
public String toString() {
return toStringHelper(subtype().toString())
.add("mpls", mplsLabel).toString();
return subtype().toString() + SEPARATOR + mplsLabel;
}
@Override
......@@ -410,8 +400,7 @@ public abstract class L2ModificationInstruction implements Instruction {
@Override
public String toString() {
return toStringHelper(subtype().toString()).add("bos", mplsBos)
.toString();
return subtype().toString() + SEPARATOR + mplsBos;
}
@Override
......@@ -448,8 +437,7 @@ public abstract class L2ModificationInstruction implements Instruction {
@Override
public String toString() {
return toStringHelper(subtype().toString())
.toString();
return subtype().toString();
}
@Override
......@@ -492,9 +480,7 @@ public abstract class L2ModificationInstruction implements Instruction {
@Override
public String toString() {
return toStringHelper(subtype().toString())
.add("id", Long.toHexString(tunnelId))
.toString();
return subtype().toString() + SEPARATOR + Long.toHexString(tunnelId);
}
@Override
......
......@@ -15,18 +15,18 @@
*/
package org.onosproject.net.flow.instructions;
import static com.google.common.base.MoreObjects.toStringHelper;
import java.util.Objects;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import java.util.Objects;
/**
* Abstraction of a single traffic treatment step.
*/
public abstract class L3ModificationInstruction implements Instruction {
private static final String SEPARATOR = ":";
/**
* Represents the type of traffic treatment.
*/
......@@ -85,8 +85,6 @@ public abstract class L3ModificationInstruction implements Instruction {
* Arp operation modification.
*/
ARP_OP
//TODO: remaining types
}
/**
......@@ -125,8 +123,7 @@ public abstract class L3ModificationInstruction implements Instruction {
@Override
public String toString() {
return toStringHelper(subtype().toString())
.add("ip", ip).toString();
return subtype().toString() + SEPARATOR + ip;
}
@Override
......@@ -173,8 +170,7 @@ public abstract class L3ModificationInstruction implements Instruction {
@Override
public String toString() {
return toStringHelper(subtype().toString())
.add("ip", ip).toString();
return subtype().toString() + SEPARATOR + ip;
}
@Override
......@@ -221,8 +217,7 @@ public abstract class L3ModificationInstruction implements Instruction {
@Override
public String toString() {
return toStringHelper(subtype().toString())
.add("mac", mac).toString();
return subtype().toString() + SEPARATOR + mac;
}
@Override
......@@ -269,8 +264,7 @@ public abstract class L3ModificationInstruction implements Instruction {
@Override
public String toString() {
return toStringHelper(subtype().toString())
.add("op", op).toString();
return subtype().toString() + SEPARATOR + op;
}
@Override
......@@ -326,8 +320,7 @@ public abstract class L3ModificationInstruction implements Instruction {
@Override
public String toString() {
return toStringHelper(subtype().toString())
.add("flowLabel", Long.toHexString(flowLabel)).toString();
return subtype().toString() + SEPARATOR + Long.toHexString(flowLabel);
}
@Override
......@@ -367,8 +360,7 @@ public abstract class L3ModificationInstruction implements Instruction {
@Override
public String toString() {
return toStringHelper(subtype().toString())
.toString();
return subtype().toString();
}
@Override
......