blob: dca30cae5beb742e1f9ba41cf935c4ab67bb70dc [file] [log] [blame]
Ray Milkey9fdf1ea2014-10-21 09:48:02 -07001package org.onlab.onos.cli.net;
2
3import org.apache.karaf.shell.commands.Option;
4import org.onlab.onos.cli.AbstractShellCommand;
5import org.onlab.onos.net.flow.DefaultTrafficSelector;
6import org.onlab.onos.net.flow.TrafficSelector;
7import org.onlab.packet.Ethernet;
8import org.onlab.packet.MacAddress;
9
10import com.google.common.base.Strings;
11
12/**
13 * Base class for command line operations for connectivity based intents.
14 */
15public 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}