Add L2 selector options to connectivity intents
Added --etherType, --etherSrc, and --etherDst to PointToPointIntent and MultiPontToSinglePointIntent creation in the ONOS CLI. Change-Id: Ibccd3c0b331e7f89be6903f264a6889ac1ad5f17
Showing
6 changed files
with
136 additions
and
16 deletions
| ... | @@ -2,18 +2,15 @@ package org.onlab.onos.cli.net; | ... | @@ -2,18 +2,15 @@ package org.onlab.onos.cli.net; |
| 2 | 2 | ||
| 3 | import org.apache.karaf.shell.commands.Argument; | 3 | import org.apache.karaf.shell.commands.Argument; |
| 4 | import org.apache.karaf.shell.commands.Command; | 4 | import org.apache.karaf.shell.commands.Command; |
| 5 | -import org.onlab.onos.cli.AbstractShellCommand; | ||
| 6 | import org.onlab.onos.net.ConnectPoint; | 5 | import org.onlab.onos.net.ConnectPoint; |
| 7 | import org.onlab.onos.net.DeviceId; | 6 | import org.onlab.onos.net.DeviceId; |
| 8 | import org.onlab.onos.net.PortNumber; | 7 | import org.onlab.onos.net.PortNumber; |
| 9 | -import org.onlab.onos.net.flow.DefaultTrafficSelector; | ||
| 10 | import org.onlab.onos.net.flow.DefaultTrafficTreatment; | 8 | import org.onlab.onos.net.flow.DefaultTrafficTreatment; |
| 11 | import org.onlab.onos.net.flow.TrafficSelector; | 9 | import org.onlab.onos.net.flow.TrafficSelector; |
| 12 | import org.onlab.onos.net.flow.TrafficTreatment; | 10 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 13 | import org.onlab.onos.net.intent.Intent; | 11 | import org.onlab.onos.net.intent.Intent; |
| 14 | import org.onlab.onos.net.intent.IntentService; | 12 | import org.onlab.onos.net.intent.IntentService; |
| 15 | import org.onlab.onos.net.intent.MultiPointToSinglePointIntent; | 13 | import org.onlab.onos.net.intent.MultiPointToSinglePointIntent; |
| 16 | -import org.onlab.packet.Ethernet; | ||
| 17 | 14 | ||
| 18 | import java.util.HashSet; | 15 | import java.util.HashSet; |
| 19 | import java.util.Set; | 16 | import java.util.Set; |
| ... | @@ -26,7 +23,7 @@ import static org.onlab.onos.net.PortNumber.portNumber; | ... | @@ -26,7 +23,7 @@ import static org.onlab.onos.net.PortNumber.portNumber; |
| 26 | */ | 23 | */ |
| 27 | @Command(scope = "onos", name = "add-multi-to-single-intent", | 24 | @Command(scope = "onos", name = "add-multi-to-single-intent", |
| 28 | description = "Installs point-to-point connectivity intent") | 25 | description = "Installs point-to-point connectivity intent") |
| 29 | -public class AddMultiPointToSinglePointIntentCommand extends AbstractShellCommand { | 26 | +public class AddMultiPointToSinglePointIntentCommand extends ConnectivityIntentCommand { |
| 30 | 27 | ||
| 31 | @Argument(index = 0, name = "ingressDevices", | 28 | @Argument(index = 0, name = "ingressDevices", |
| 32 | description = "Ingress Device/Port Description", | 29 | description = "Ingress Device/Port Description", |
| ... | @@ -55,9 +52,7 @@ public class AddMultiPointToSinglePointIntentCommand extends AbstractShellComman | ... | @@ -55,9 +52,7 @@ public class AddMultiPointToSinglePointIntentCommand extends AbstractShellComman |
| 55 | ingressPoints.add(ingress); | 52 | ingressPoints.add(ingress); |
| 56 | } | 53 | } |
| 57 | 54 | ||
| 58 | - TrafficSelector selector = DefaultTrafficSelector.builder() | 55 | + TrafficSelector selector = buildTrafficSelector(); |
| 59 | - .matchEthType(Ethernet.TYPE_IPV4) | ||
| 60 | - .build(); | ||
| 61 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); | 56 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); |
| 62 | 57 | ||
| 63 | Intent intent = new MultiPointToSinglePointIntent(appId(), selector, treatment, | 58 | Intent intent = new MultiPointToSinglePointIntent(appId(), selector, treatment, | ... | ... |
| ... | @@ -2,18 +2,16 @@ package org.onlab.onos.cli.net; | ... | @@ -2,18 +2,16 @@ package org.onlab.onos.cli.net; |
| 2 | 2 | ||
| 3 | import org.apache.karaf.shell.commands.Argument; | 3 | import org.apache.karaf.shell.commands.Argument; |
| 4 | import org.apache.karaf.shell.commands.Command; | 4 | import org.apache.karaf.shell.commands.Command; |
| 5 | -import org.onlab.onos.cli.AbstractShellCommand; | ||
| 6 | import org.onlab.onos.net.ConnectPoint; | 5 | import org.onlab.onos.net.ConnectPoint; |
| 7 | import org.onlab.onos.net.DeviceId; | 6 | import org.onlab.onos.net.DeviceId; |
| 8 | import org.onlab.onos.net.PortNumber; | 7 | import org.onlab.onos.net.PortNumber; |
| 9 | -import org.onlab.onos.net.flow.DefaultTrafficSelector; | ||
| 10 | -import org.onlab.onos.net.flow.DefaultTrafficTreatment; | ||
| 11 | import org.onlab.onos.net.flow.TrafficSelector; | 8 | import org.onlab.onos.net.flow.TrafficSelector; |
| 12 | import org.onlab.onos.net.flow.TrafficTreatment; | 9 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 13 | import org.onlab.onos.net.intent.Intent; | 10 | import org.onlab.onos.net.intent.Intent; |
| 14 | import org.onlab.onos.net.intent.IntentService; | 11 | import org.onlab.onos.net.intent.IntentService; |
| 15 | import org.onlab.onos.net.intent.PointToPointIntent; | 12 | import org.onlab.onos.net.intent.PointToPointIntent; |
| 16 | -import org.onlab.packet.Ethernet; | 13 | + |
| 14 | +import static org.onlab.onos.net.flow.DefaultTrafficTreatment.builder; | ||
| 17 | 15 | ||
| 18 | import static org.onlab.onos.net.DeviceId.deviceId; | 16 | import static org.onlab.onos.net.DeviceId.deviceId; |
| 19 | import static org.onlab.onos.net.PortNumber.portNumber; | 17 | import static org.onlab.onos.net.PortNumber.portNumber; |
| ... | @@ -23,7 +21,7 @@ import static org.onlab.onos.net.PortNumber.portNumber; | ... | @@ -23,7 +21,7 @@ import static org.onlab.onos.net.PortNumber.portNumber; |
| 23 | */ | 21 | */ |
| 24 | @Command(scope = "onos", name = "add-point-intent", | 22 | @Command(scope = "onos", name = "add-point-intent", |
| 25 | description = "Installs point-to-point connectivity intent") | 23 | description = "Installs point-to-point connectivity intent") |
| 26 | -public class AddPointToPointIntentCommand extends AbstractShellCommand { | 24 | +public class AddPointToPointIntentCommand extends ConnectivityIntentCommand { |
| 27 | 25 | ||
| 28 | @Argument(index = 0, name = "ingressDevice", | 26 | @Argument(index = 0, name = "ingressDevice", |
| 29 | description = "Ingress Device/Port Description", | 27 | description = "Ingress Device/Port Description", |
| ... | @@ -47,10 +45,8 @@ public class AddPointToPointIntentCommand extends AbstractShellCommand { | ... | @@ -47,10 +45,8 @@ public class AddPointToPointIntentCommand extends AbstractShellCommand { |
| 47 | PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString)); | 45 | PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString)); |
| 48 | ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber); | 46 | ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber); |
| 49 | 47 | ||
| 50 | - TrafficSelector selector = DefaultTrafficSelector.builder() | 48 | + TrafficSelector selector = buildTrafficSelector(); |
| 51 | - .matchEthType(Ethernet.TYPE_IPV4) | 49 | + TrafficTreatment treatment = builder().build(); |
| 52 | - .build(); | ||
| 53 | - TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); | ||
| 54 | 50 | ||
| 55 | Intent intent = new PointToPointIntent(appId(), selector, treatment, | 51 | Intent intent = new PointToPointIntent(appId(), selector, treatment, |
| 56 | ingress, egress); | 52 | ingress, egress); | ... | ... |
| 1 | +package org.onlab.onos.cli.net; | ||
| 2 | + | ||
| 3 | +import org.apache.karaf.shell.commands.Option; | ||
| 4 | +import org.onlab.onos.cli.AbstractShellCommand; | ||
| 5 | +import org.onlab.onos.net.flow.DefaultTrafficSelector; | ||
| 6 | +import org.onlab.onos.net.flow.TrafficSelector; | ||
| 7 | +import org.onlab.packet.Ethernet; | ||
| 8 | +import org.onlab.packet.MacAddress; | ||
| 9 | + | ||
| 10 | +import com.google.common.base.Strings; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * Base class for command line operations for connectivity based intents. | ||
| 14 | + */ | ||
| 15 | +public abstract class ConnectivityIntentCommand extends AbstractShellCommand { | ||
| 16 | + | ||
| 17 | + @Option(name = "-s", aliases = "--ethSrc", description = "Source MAC Address", | ||
| 18 | + required = false, multiValued = false) | ||
| 19 | + private String srcMacString = null; | ||
| 20 | + | ||
| 21 | + @Option(name = "-d", aliases = "--ethDst", description = "Destination MAC Address", | ||
| 22 | + required = false, multiValued = false) | ||
| 23 | + private String dstMacString = null; | ||
| 24 | + | ||
| 25 | + @Option(name = "-t", aliases = "--ethType", description = "Ethernet Type", | ||
| 26 | + required = false, multiValued = false) | ||
| 27 | + private String ethTypeString = ""; | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * Constructs a traffic selector based on the command line arguments | ||
| 31 | + * presented to the command. | ||
| 32 | + */ | ||
| 33 | + protected TrafficSelector buildTrafficSelector() { | ||
| 34 | + TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); | ||
| 35 | + | ||
| 36 | + Short ethType = Ethernet.TYPE_IPV4; | ||
| 37 | + if (!Strings.isNullOrEmpty(ethTypeString)) { | ||
| 38 | + EthType ethTypeParameter = EthType.valueOf(ethTypeString); | ||
| 39 | + ethType = ethTypeParameter.value(); | ||
| 40 | + } | ||
| 41 | + selectorBuilder.matchEthType(ethType); | ||
| 42 | + | ||
| 43 | + if (!Strings.isNullOrEmpty(srcMacString)) { | ||
| 44 | + selectorBuilder.matchEthSrc(MacAddress.valueOf(srcMacString)); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + if (!Strings.isNullOrEmpty(dstMacString)) { | ||
| 48 | + selectorBuilder.matchEthDst(MacAddress.valueOf(dstMacString)); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + return selectorBuilder.build(); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | +} |
| 1 | +package org.onlab.onos.cli.net; | ||
| 2 | + | ||
| 3 | +import org.onlab.packet.Ethernet; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * Allowed values for Ethernet types. Used by the CLI completer for | ||
| 7 | + * connectivity based intent L2 parameters. | ||
| 8 | + */ | ||
| 9 | +public enum EthType { | ||
| 10 | + /** ARP. */ | ||
| 11 | + ARP(Ethernet.TYPE_ARP), | ||
| 12 | + /** RARP. */ | ||
| 13 | + RARP(Ethernet.TYPE_RARP), | ||
| 14 | + /** IPV4. */ | ||
| 15 | + IPV4(Ethernet.TYPE_IPV4), | ||
| 16 | + /** LLDP. */ | ||
| 17 | + LLDP(Ethernet.TYPE_LLDP), | ||
| 18 | + /** BSN. */ | ||
| 19 | + BSN(Ethernet.TYPE_BSN); | ||
| 20 | + | ||
| 21 | + private short value; | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * Constructs an EthType with the given value. | ||
| 25 | + * | ||
| 26 | + * @param value value to use when this EthType is seen. | ||
| 27 | + */ | ||
| 28 | + private EthType(short value) { | ||
| 29 | + this.value = value; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * Gets the value to use for this EthType. | ||
| 34 | + * | ||
| 35 | + * @return short value to use for this EthType | ||
| 36 | + */ | ||
| 37 | + public short value() { | ||
| 38 | + return this.value; | ||
| 39 | + } | ||
| 40 | +} |
| 1 | +package org.onlab.onos.cli.net; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | +import java.util.SortedSet; | ||
| 5 | + | ||
| 6 | +import org.apache.karaf.shell.console.Completer; | ||
| 7 | +import org.apache.karaf.shell.console.completer.StringsCompleter; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * Ethernet type completer. | ||
| 11 | + */ | ||
| 12 | +public class EthTypeCompleter implements Completer { | ||
| 13 | + @Override | ||
| 14 | + public int complete(String buffer, int cursor, List<String> candidates) { | ||
| 15 | + // Delegate string completer | ||
| 16 | + StringsCompleter delegate = new StringsCompleter(); | ||
| 17 | + SortedSet<String> strings = delegate.getStrings(); | ||
| 18 | + strings.add(EthType.ARP.toString()); | ||
| 19 | + strings.add(EthType.BSN.toString()); | ||
| 20 | + strings.add(EthType.IPV4.toString()); | ||
| 21 | + strings.add(EthType.LLDP.toString()); | ||
| 22 | + strings.add(EthType.RARP.toString()); | ||
| 23 | + | ||
| 24 | + // Now let the completer do the work for figuring out what to offer. | ||
| 25 | + return delegate.complete(buffer, cursor, candidates); | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | +} |
| ... | @@ -96,12 +96,18 @@ | ... | @@ -96,12 +96,18 @@ |
| 96 | <ref component-id="connectPointCompleter"/> | 96 | <ref component-id="connectPointCompleter"/> |
| 97 | <null/> | 97 | <null/> |
| 98 | </completers> | 98 | </completers> |
| 99 | + <optional-completers> | ||
| 100 | + <entry key="-t" value-ref="ethTypeCompleter"/> | ||
| 101 | + </optional-completers> | ||
| 99 | </command> | 102 | </command> |
| 100 | <command> | 103 | <command> |
| 101 | <action class="org.onlab.onos.cli.net.AddMultiPointToSinglePointIntentCommand"/> | 104 | <action class="org.onlab.onos.cli.net.AddMultiPointToSinglePointIntentCommand"/> |
| 102 | <completers> | 105 | <completers> |
| 103 | <ref component-id="connectPointCompleter"/> | 106 | <ref component-id="connectPointCompleter"/> |
| 104 | </completers> | 107 | </completers> |
| 108 | + <optional-completers> | ||
| 109 | + <entry key="-t" value-ref="ethTypeCompleter"/> | ||
| 110 | + </optional-completers> | ||
| 105 | </command> | 111 | </command> |
| 106 | <command> | 112 | <command> |
| 107 | <action class="org.onlab.onos.cli.net.IntentPushTestCommand"/> | 113 | <action class="org.onlab.onos.cli.net.IntentPushTestCommand"/> |
| ... | @@ -158,5 +164,6 @@ | ... | @@ -158,5 +164,6 @@ |
| 158 | <bean id="flowRuleStatusCompleter" class="org.onlab.onos.cli.net.FlowRuleStatusCompleter"/> | 164 | <bean id="flowRuleStatusCompleter" class="org.onlab.onos.cli.net.FlowRuleStatusCompleter"/> |
| 159 | <bean id="connectPointCompleter" class="org.onlab.onos.cli.net.ConnectPointCompleter"/> | 165 | <bean id="connectPointCompleter" class="org.onlab.onos.cli.net.ConnectPointCompleter"/> |
| 160 | <bean id="nullCompleter" class="org.apache.karaf.shell.console.completer.NullCompleter"/> | 166 | <bean id="nullCompleter" class="org.apache.karaf.shell.console.completer.NullCompleter"/> |
| 167 | + <bean id="ethTypeCompleter" class="org.onlab.onos.cli.net.EthTypeCompleter"/> | ||
| 161 | 168 | ||
| 162 | </blueprint> | 169 | </blueprint> | ... | ... |
-
Please register or login to post a comment