Ray Milkey
Committed by Gerrit Code Review

ONOS-196 Add --macSrcRewrite and --macDstRewrite options to add-point-intent command

Add the option for specifying a mac address rewrite.

Generate instructions for the rewrite and include them in the
treatment for the intent.

Change-Id: Ib2fa5ad5a6eb1d9617159c34d832fd89f7245db9
......@@ -19,6 +19,7 @@ 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;
......@@ -28,11 +29,12 @@ 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 org.onlab.onos.net.flow.DefaultTrafficTreatment.builder;
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.
......@@ -51,6 +53,36 @@ 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() {
IntentService service = get(IntentService.class);
......@@ -64,7 +96,7 @@ public class AddPointToPointIntentCommand extends ConnectivityIntentCommand {
ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber);
TrafficSelector selector = buildTrafficSelector();
TrafficTreatment treatment = builder().build();
TrafficTreatment treatment = buildTrafficTreatment();
List<Constraint> constraints = buildConstraints();
......