Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 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 | } |