Moved CLI options for rewrite actions up to ConnectivityIntentCommand so they
can be used by all connectivity intent commands. Change-Id: I6cd6b05423479d53313c92491ab636ebd58def43
Showing
3 changed files
with
44 additions
and
45 deletions
... | @@ -15,12 +15,18 @@ | ... | @@ -15,12 +15,18 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.onos.cli.net; | 16 | package org.onlab.onos.cli.net; |
17 | 17 | ||
18 | +import static org.onlab.onos.net.DeviceId.deviceId; | ||
19 | +import static org.onlab.onos.net.PortNumber.portNumber; | ||
20 | + | ||
21 | +import java.util.HashSet; | ||
22 | +import java.util.List; | ||
23 | +import java.util.Set; | ||
24 | + | ||
18 | import org.apache.karaf.shell.commands.Argument; | 25 | import org.apache.karaf.shell.commands.Argument; |
19 | import org.apache.karaf.shell.commands.Command; | 26 | import org.apache.karaf.shell.commands.Command; |
20 | import org.onlab.onos.net.ConnectPoint; | 27 | import org.onlab.onos.net.ConnectPoint; |
21 | import org.onlab.onos.net.DeviceId; | 28 | import org.onlab.onos.net.DeviceId; |
22 | import org.onlab.onos.net.PortNumber; | 29 | import org.onlab.onos.net.PortNumber; |
23 | -import org.onlab.onos.net.flow.DefaultTrafficTreatment; | ||
24 | import org.onlab.onos.net.flow.TrafficSelector; | 30 | import org.onlab.onos.net.flow.TrafficSelector; |
25 | import org.onlab.onos.net.flow.TrafficTreatment; | 31 | import org.onlab.onos.net.flow.TrafficTreatment; |
26 | import org.onlab.onos.net.intent.Constraint; | 32 | import org.onlab.onos.net.intent.Constraint; |
... | @@ -28,13 +34,6 @@ import org.onlab.onos.net.intent.Intent; | ... | @@ -28,13 +34,6 @@ import org.onlab.onos.net.intent.Intent; |
28 | import org.onlab.onos.net.intent.IntentService; | 34 | import org.onlab.onos.net.intent.IntentService; |
29 | import org.onlab.onos.net.intent.MultiPointToSinglePointIntent; | 35 | import org.onlab.onos.net.intent.MultiPointToSinglePointIntent; |
30 | 36 | ||
31 | -import java.util.HashSet; | ||
32 | -import java.util.List; | ||
33 | -import java.util.Set; | ||
34 | - | ||
35 | -import static org.onlab.onos.net.DeviceId.deviceId; | ||
36 | -import static org.onlab.onos.net.PortNumber.portNumber; | ||
37 | - | ||
38 | /** | 37 | /** |
39 | * Installs point-to-point connectivity intents. | 38 | * Installs point-to-point connectivity intents. |
40 | */ | 39 | */ |
... | @@ -70,7 +69,7 @@ public class AddMultiPointToSinglePointIntentCommand extends ConnectivityIntentC | ... | @@ -70,7 +69,7 @@ public class AddMultiPointToSinglePointIntentCommand extends ConnectivityIntentC |
70 | } | 69 | } |
71 | 70 | ||
72 | TrafficSelector selector = buildTrafficSelector(); | 71 | TrafficSelector selector = buildTrafficSelector(); |
73 | - TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); | 72 | + TrafficTreatment treatment = buildTrafficTreatment(); |
74 | List<Constraint> constraints = buildConstraints(); | 73 | List<Constraint> constraints = buildConstraints(); |
75 | 74 | ||
76 | Intent intent = new MultiPointToSinglePointIntent(appId(), selector, treatment, | 75 | Intent intent = new MultiPointToSinglePointIntent(appId(), selector, treatment, | ... | ... |
... | @@ -15,11 +15,13 @@ | ... | @@ -15,11 +15,13 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.onos.cli.net; | 16 | package org.onlab.onos.cli.net; |
17 | 17 | ||
18 | +import static org.onlab.onos.net.DeviceId.deviceId; | ||
19 | +import static org.onlab.onos.net.PortNumber.portNumber; | ||
20 | + | ||
18 | import java.util.List; | 21 | import java.util.List; |
19 | 22 | ||
20 | import org.apache.karaf.shell.commands.Argument; | 23 | import org.apache.karaf.shell.commands.Argument; |
21 | import org.apache.karaf.shell.commands.Command; | 24 | import org.apache.karaf.shell.commands.Command; |
22 | -import org.apache.karaf.shell.commands.Option; | ||
23 | import org.onlab.onos.net.ConnectPoint; | 25 | import org.onlab.onos.net.ConnectPoint; |
24 | import org.onlab.onos.net.DeviceId; | 26 | import org.onlab.onos.net.DeviceId; |
25 | import org.onlab.onos.net.PortNumber; | 27 | import org.onlab.onos.net.PortNumber; |
... | @@ -29,12 +31,6 @@ import org.onlab.onos.net.intent.Constraint; | ... | @@ -29,12 +31,6 @@ import org.onlab.onos.net.intent.Constraint; |
29 | import org.onlab.onos.net.intent.Intent; | 31 | import org.onlab.onos.net.intent.Intent; |
30 | import org.onlab.onos.net.intent.IntentService; | 32 | import org.onlab.onos.net.intent.IntentService; |
31 | import org.onlab.onos.net.intent.PointToPointIntent; | 33 | import org.onlab.onos.net.intent.PointToPointIntent; |
32 | -import org.onlab.packet.MacAddress; | ||
33 | - | ||
34 | -import static com.google.common.base.Strings.isNullOrEmpty; | ||
35 | -import static org.onlab.onos.net.DeviceId.deviceId; | ||
36 | -import static org.onlab.onos.net.PortNumber.portNumber; | ||
37 | -import static org.onlab.onos.net.flow.DefaultTrafficTreatment.builder; | ||
38 | 34 | ||
39 | /** | 35 | /** |
40 | * Installs point-to-point connectivity intents. | 36 | * Installs point-to-point connectivity intents. |
... | @@ -53,35 +49,6 @@ public class AddPointToPointIntentCommand extends ConnectivityIntentCommand { | ... | @@ -53,35 +49,6 @@ public class AddPointToPointIntentCommand extends ConnectivityIntentCommand { |
53 | required = true, multiValued = false) | 49 | required = true, multiValued = false) |
54 | String egressDeviceString = null; | 50 | String egressDeviceString = null; |
55 | 51 | ||
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 | 52 | ||
86 | @Override | 53 | @Override |
87 | protected void execute() { | 54 | protected void execute() { | ... | ... |
... | @@ -23,6 +23,7 @@ import org.onlab.onos.cli.AbstractShellCommand; | ... | @@ -23,6 +23,7 @@ import org.onlab.onos.cli.AbstractShellCommand; |
23 | import org.onlab.onos.net.Link; | 23 | import org.onlab.onos.net.Link; |
24 | import org.onlab.onos.net.flow.DefaultTrafficSelector; | 24 | import org.onlab.onos.net.flow.DefaultTrafficSelector; |
25 | import org.onlab.onos.net.flow.TrafficSelector; | 25 | import org.onlab.onos.net.flow.TrafficSelector; |
26 | +import org.onlab.onos.net.flow.TrafficTreatment; | ||
26 | import org.onlab.onos.net.intent.Constraint; | 27 | import org.onlab.onos.net.intent.Constraint; |
27 | import org.onlab.onos.net.intent.constraint.BandwidthConstraint; | 28 | import org.onlab.onos.net.intent.constraint.BandwidthConstraint; |
28 | import org.onlab.onos.net.intent.constraint.LambdaConstraint; | 29 | import org.onlab.onos.net.intent.constraint.LambdaConstraint; |
... | @@ -33,12 +34,14 @@ import org.onlab.packet.IpPrefix; | ... | @@ -33,12 +34,14 @@ import org.onlab.packet.IpPrefix; |
33 | import org.onlab.packet.MacAddress; | 34 | import org.onlab.packet.MacAddress; |
34 | 35 | ||
35 | import static com.google.common.base.Strings.isNullOrEmpty; | 36 | import static com.google.common.base.Strings.isNullOrEmpty; |
37 | +import static org.onlab.onos.net.flow.DefaultTrafficTreatment.builder; | ||
36 | 38 | ||
37 | /** | 39 | /** |
38 | * Base class for command line operations for connectivity based intents. | 40 | * Base class for command line operations for connectivity based intents. |
39 | */ | 41 | */ |
40 | public abstract class ConnectivityIntentCommand extends AbstractShellCommand { | 42 | public abstract class ConnectivityIntentCommand extends AbstractShellCommand { |
41 | 43 | ||
44 | + // Selectors | ||
42 | @Option(name = "-s", aliases = "--ethSrc", description = "Source MAC Address", | 45 | @Option(name = "-s", aliases = "--ethSrc", description = "Source MAC Address", |
43 | required = false, multiValued = false) | 46 | required = false, multiValued = false) |
44 | private String srcMacString = null; | 47 | private String srcMacString = null; |
... | @@ -79,6 +82,16 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { | ... | @@ -79,6 +82,16 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { |
79 | required = false, multiValued = false) | 82 | required = false, multiValued = false) |
80 | private boolean lambda = false; | 83 | private boolean lambda = false; |
81 | 84 | ||
85 | + | ||
86 | + // Treatments | ||
87 | + @Option(name = "--setEthSrc", description = "Rewrite Source MAC Address", | ||
88 | + required = false, multiValued = false) | ||
89 | + private String setEthSrcString = null; | ||
90 | + | ||
91 | + @Option(name = "--setEthDst", description = "Rewrite Destination MAC Address", | ||
92 | + required = false, multiValued = false) | ||
93 | + private String setEthDstString = null; | ||
94 | + | ||
82 | /** | 95 | /** |
83 | * Constructs a traffic selector based on the command line arguments | 96 | * Constructs a traffic selector based on the command line arguments |
84 | * presented to the command. | 97 | * presented to the command. |
... | @@ -126,6 +139,26 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { | ... | @@ -126,6 +139,26 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { |
126 | } | 139 | } |
127 | 140 | ||
128 | /** | 141 | /** |
142 | + * Generates a traffic treatment for this intent based on command line | ||
143 | + * arguments presented to the command. | ||
144 | + * | ||
145 | + * @return traffic treatment | ||
146 | + */ | ||
147 | + protected TrafficTreatment buildTrafficTreatment() { | ||
148 | + final TrafficTreatment.Builder builder = builder(); | ||
149 | + | ||
150 | + if (!isNullOrEmpty(setEthSrcString)) { | ||
151 | + final MacAddress setEthSrc = MacAddress.valueOf(setEthSrcString); | ||
152 | + builder.setEthSrc(setEthSrc); | ||
153 | + } | ||
154 | + if (!isNullOrEmpty(setEthDstString)) { | ||
155 | + final MacAddress setEthDst = MacAddress.valueOf(setEthDstString); | ||
156 | + builder.setEthDst(setEthDst); | ||
157 | + } | ||
158 | + return builder.build(); | ||
159 | + } | ||
160 | + | ||
161 | + /** | ||
129 | * Builds the constraint list for this command based on the command line | 162 | * Builds the constraint list for this command based on the command line |
130 | * parameters. | 163 | * parameters. |
131 | * | 164 | * | ... | ... |
-
Please register or login to post a comment