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
Showing
1 changed file
with
35 additions
and
3 deletions
... | @@ -19,6 +19,7 @@ import java.util.List; | ... | @@ -19,6 +19,7 @@ import java.util.List; |
19 | 19 | ||
20 | import org.apache.karaf.shell.commands.Argument; | 20 | import org.apache.karaf.shell.commands.Argument; |
21 | import org.apache.karaf.shell.commands.Command; | 21 | import org.apache.karaf.shell.commands.Command; |
22 | +import org.apache.karaf.shell.commands.Option; | ||
22 | import org.onlab.onos.net.ConnectPoint; | 23 | import org.onlab.onos.net.ConnectPoint; |
23 | import org.onlab.onos.net.DeviceId; | 24 | import org.onlab.onos.net.DeviceId; |
24 | import org.onlab.onos.net.PortNumber; | 25 | import org.onlab.onos.net.PortNumber; |
... | @@ -28,11 +29,12 @@ import org.onlab.onos.net.intent.Constraint; | ... | @@ -28,11 +29,12 @@ import org.onlab.onos.net.intent.Constraint; |
28 | import org.onlab.onos.net.intent.Intent; | 29 | import org.onlab.onos.net.intent.Intent; |
29 | import org.onlab.onos.net.intent.IntentService; | 30 | import org.onlab.onos.net.intent.IntentService; |
30 | import org.onlab.onos.net.intent.PointToPointIntent; | 31 | import org.onlab.onos.net.intent.PointToPointIntent; |
32 | +import org.onlab.packet.MacAddress; | ||
31 | 33 | ||
32 | -import static org.onlab.onos.net.flow.DefaultTrafficTreatment.builder; | 34 | +import static com.google.common.base.Strings.isNullOrEmpty; |
33 | - | ||
34 | import static org.onlab.onos.net.DeviceId.deviceId; | 35 | import static org.onlab.onos.net.DeviceId.deviceId; |
35 | import static org.onlab.onos.net.PortNumber.portNumber; | 36 | import static org.onlab.onos.net.PortNumber.portNumber; |
37 | +import static org.onlab.onos.net.flow.DefaultTrafficTreatment.builder; | ||
36 | 38 | ||
37 | /** | 39 | /** |
38 | * Installs point-to-point connectivity intents. | 40 | * Installs point-to-point connectivity intents. |
... | @@ -51,6 +53,36 @@ public class AddPointToPointIntentCommand extends ConnectivityIntentCommand { | ... | @@ -51,6 +53,36 @@ public class AddPointToPointIntentCommand extends ConnectivityIntentCommand { |
51 | required = true, multiValued = false) | 53 | required = true, multiValued = false) |
52 | String egressDeviceString = null; | 54 | String egressDeviceString = null; |
53 | 55 | ||
56 | + @Option(name = "--srcMacRewrite", description = "Source MAC address to rewrite", | ||
57 | + required = false, multiValued = false) | ||
58 | + private String rewriteSrcMacAddressString = null; | ||
59 | + | ||
60 | + @Option(name = "--dstMacRewrite", description = "Destination MAC address to rewrite", | ||
61 | + required = false, multiValued = false) | ||
62 | + private String rewriteDstMacAddressString = null; | ||
63 | + | ||
64 | + | ||
65 | + /** | ||
66 | + * Generates a traffic treatment for this intent. If the mac address rewrite | ||
67 | + * argument is specified the treatment is updated | ||
68 | + * to implement the rewrite rule if necessary. | ||
69 | + */ | ||
70 | + private TrafficTreatment buildTrafficTreatment() { | ||
71 | + final TrafficTreatment.Builder builder = builder(); | ||
72 | + | ||
73 | + if (!isNullOrEmpty(rewriteSrcMacAddressString)) { | ||
74 | + final MacAddress rewriteSrcMacAddress = | ||
75 | + MacAddress.valueOf(rewriteSrcMacAddressString); | ||
76 | + builder.setEthSrc(rewriteSrcMacAddress); | ||
77 | + } | ||
78 | + if (!isNullOrEmpty(rewriteDstMacAddressString)) { | ||
79 | + final MacAddress rewriteDstMacAddress = | ||
80 | + MacAddress.valueOf(rewriteDstMacAddressString); | ||
81 | + builder.setEthDst(rewriteDstMacAddress); | ||
82 | + } | ||
83 | + return builder.build(); | ||
84 | + } | ||
85 | + | ||
54 | @Override | 86 | @Override |
55 | protected void execute() { | 87 | protected void execute() { |
56 | IntentService service = get(IntentService.class); | 88 | IntentService service = get(IntentService.class); |
... | @@ -64,7 +96,7 @@ public class AddPointToPointIntentCommand extends ConnectivityIntentCommand { | ... | @@ -64,7 +96,7 @@ public class AddPointToPointIntentCommand extends ConnectivityIntentCommand { |
64 | ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber); | 96 | ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber); |
65 | 97 | ||
66 | TrafficSelector selector = buildTrafficSelector(); | 98 | TrafficSelector selector = buildTrafficSelector(); |
67 | - TrafficTreatment treatment = builder().build(); | 99 | + TrafficTreatment treatment = buildTrafficTreatment(); |
68 | 100 | ||
69 | List<Constraint> constraints = buildConstraints(); | 101 | List<Constraint> constraints = buildConstraints(); |
70 | 102 | ... | ... |
-
Please register or login to post a comment