Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 15 | */ |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 16 | package org.onlab.onos.cli.net; |
| 17 | |
| 18 | import org.apache.karaf.shell.commands.Option; |
| 19 | import org.onlab.onos.cli.AbstractShellCommand; |
| 20 | import org.onlab.onos.net.flow.DefaultTrafficSelector; |
| 21 | import org.onlab.onos.net.flow.TrafficSelector; |
| 22 | import org.onlab.packet.Ethernet; |
| 23 | import org.onlab.packet.MacAddress; |
| 24 | |
| 25 | import com.google.common.base.Strings; |
| 26 | |
| 27 | /** |
| 28 | * Base class for command line operations for connectivity based intents. |
| 29 | */ |
| 30 | public abstract class ConnectivityIntentCommand extends AbstractShellCommand { |
| 31 | |
| 32 | @Option(name = "-s", aliases = "--ethSrc", description = "Source MAC Address", |
| 33 | required = false, multiValued = false) |
| 34 | private String srcMacString = null; |
| 35 | |
| 36 | @Option(name = "-d", aliases = "--ethDst", description = "Destination MAC Address", |
| 37 | required = false, multiValued = false) |
| 38 | private String dstMacString = null; |
| 39 | |
| 40 | @Option(name = "-t", aliases = "--ethType", description = "Ethernet Type", |
| 41 | required = false, multiValued = false) |
| 42 | private String ethTypeString = ""; |
| 43 | |
| 44 | /** |
| 45 | * Constructs a traffic selector based on the command line arguments |
| 46 | * presented to the command. |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 47 | * @return traffic selector |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 48 | */ |
| 49 | protected TrafficSelector buildTrafficSelector() { |
| 50 | TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 51 | Short ethType = Ethernet.TYPE_IPV4; |
Ray Milkey | caa450b | 2014-10-29 15:54:24 -0700 | [diff] [blame] | 52 | |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 53 | if (!Strings.isNullOrEmpty(ethTypeString)) { |
| 54 | EthType ethTypeParameter = EthType.valueOf(ethTypeString); |
| 55 | ethType = ethTypeParameter.value(); |
| 56 | } |
| 57 | selectorBuilder.matchEthType(ethType); |
| 58 | |
| 59 | if (!Strings.isNullOrEmpty(srcMacString)) { |
| 60 | selectorBuilder.matchEthSrc(MacAddress.valueOf(srcMacString)); |
| 61 | } |
| 62 | |
| 63 | if (!Strings.isNullOrEmpty(dstMacString)) { |
| 64 | selectorBuilder.matchEthDst(MacAddress.valueOf(dstMacString)); |
| 65 | } |
| 66 | |
| 67 | return selectorBuilder.build(); |
| 68 | } |
| 69 | |
| 70 | } |