Jonathan Hart

Moved CLI options for rewrite actions up to ConnectivityIntentCommand so they

can be used by all connectivity intent commands.

Change-Id: I6cd6b05423479d53313c92491ab636ebd58def43
......@@ -15,12 +15,18 @@
*/
package org.onlab.onos.cli.net;
import static org.onlab.onos.net.DeviceId.deviceId;
import static org.onlab.onos.net.PortNumber.portNumber;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.flow.DefaultTrafficTreatment;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
import org.onlab.onos.net.intent.Constraint;
......@@ -28,13 +34,6 @@ import org.onlab.onos.net.intent.Intent;
import org.onlab.onos.net.intent.IntentService;
import org.onlab.onos.net.intent.MultiPointToSinglePointIntent;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static org.onlab.onos.net.DeviceId.deviceId;
import static org.onlab.onos.net.PortNumber.portNumber;
/**
* Installs point-to-point connectivity intents.
*/
......@@ -70,7 +69,7 @@ public class AddMultiPointToSinglePointIntentCommand extends ConnectivityIntentC
}
TrafficSelector selector = buildTrafficSelector();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
TrafficTreatment treatment = buildTrafficTreatment();
List<Constraint> constraints = buildConstraints();
Intent intent = new MultiPointToSinglePointIntent(appId(), selector, treatment,
......
......@@ -15,11 +15,13 @@
*/
package org.onlab.onos.cli.net;
import static org.onlab.onos.net.DeviceId.deviceId;
import static org.onlab.onos.net.PortNumber.portNumber;
import java.util.List;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.commands.Option;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.PortNumber;
......@@ -29,12 +31,6 @@ import org.onlab.onos.net.intent.Constraint;
import org.onlab.onos.net.intent.Intent;
import org.onlab.onos.net.intent.IntentService;
import org.onlab.onos.net.intent.PointToPointIntent;
import org.onlab.packet.MacAddress;
import static com.google.common.base.Strings.isNullOrEmpty;
import static org.onlab.onos.net.DeviceId.deviceId;
import static org.onlab.onos.net.PortNumber.portNumber;
import static org.onlab.onos.net.flow.DefaultTrafficTreatment.builder;
/**
* Installs point-to-point connectivity intents.
......@@ -53,35 +49,6 @@ public class AddPointToPointIntentCommand extends ConnectivityIntentCommand {
required = true, multiValued = false)
String egressDeviceString = null;
@Option(name = "--srcMacRewrite", description = "Source MAC address to rewrite",
required = false, multiValued = false)
private String rewriteSrcMacAddressString = null;
@Option(name = "--dstMacRewrite", description = "Destination MAC address to rewrite",
required = false, multiValued = false)
private String rewriteDstMacAddressString = null;
/**
* Generates a traffic treatment for this intent. If the mac address rewrite
* argument is specified the treatment is updated
* to implement the rewrite rule if necessary.
*/
private TrafficTreatment buildTrafficTreatment() {
final TrafficTreatment.Builder builder = builder();
if (!isNullOrEmpty(rewriteSrcMacAddressString)) {
final MacAddress rewriteSrcMacAddress =
MacAddress.valueOf(rewriteSrcMacAddressString);
builder.setEthSrc(rewriteSrcMacAddress);
}
if (!isNullOrEmpty(rewriteDstMacAddressString)) {
final MacAddress rewriteDstMacAddress =
MacAddress.valueOf(rewriteDstMacAddressString);
builder.setEthDst(rewriteDstMacAddress);
}
return builder.build();
}
@Override
protected void execute() {
......
......@@ -23,6 +23,7 @@ import org.onlab.onos.cli.AbstractShellCommand;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.flow.DefaultTrafficSelector;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
import org.onlab.onos.net.intent.Constraint;
import org.onlab.onos.net.intent.constraint.BandwidthConstraint;
import org.onlab.onos.net.intent.constraint.LambdaConstraint;
......@@ -33,12 +34,14 @@ import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import static com.google.common.base.Strings.isNullOrEmpty;
import static org.onlab.onos.net.flow.DefaultTrafficTreatment.builder;
/**
* Base class for command line operations for connectivity based intents.
*/
public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
// Selectors
@Option(name = "-s", aliases = "--ethSrc", description = "Source MAC Address",
required = false, multiValued = false)
private String srcMacString = null;
......@@ -79,6 +82,16 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
required = false, multiValued = false)
private boolean lambda = false;
// Treatments
@Option(name = "--setEthSrc", description = "Rewrite Source MAC Address",
required = false, multiValued = false)
private String setEthSrcString = null;
@Option(name = "--setEthDst", description = "Rewrite Destination MAC Address",
required = false, multiValued = false)
private String setEthDstString = null;
/**
* Constructs a traffic selector based on the command line arguments
* presented to the command.
......@@ -126,6 +139,26 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
}
/**
* Generates a traffic treatment for this intent based on command line
* arguments presented to the command.
*
* @return traffic treatment
*/
protected TrafficTreatment buildTrafficTreatment() {
final TrafficTreatment.Builder builder = builder();
if (!isNullOrEmpty(setEthSrcString)) {
final MacAddress setEthSrc = MacAddress.valueOf(setEthSrcString);
builder.setEthSrc(setEthSrc);
}
if (!isNullOrEmpty(setEthDstString)) {
final MacAddress setEthDst = MacAddress.valueOf(setEthDstString);
builder.setEthDst(setEthDst);
}
return builder.build();
}
/**
* Builds the constraint list for this command based on the command line
* parameters.
*
......