blob: d8ec3c7573c8b3572c64ceb7a4a95f760277f3dc [file] [log] [blame]
Thomas Vachuska7d693f52014-10-21 19:17:57 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska7d693f52014-10-21 19:17:57 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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 Vachuska7d693f52014-10-21 19:17:57 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska7d693f52014-10-21 19:17:57 -070015 */
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070016package org.onlab.onos.cli.net;
17
18import org.apache.karaf.shell.commands.Option;
19import org.onlab.onos.cli.AbstractShellCommand;
20import org.onlab.onos.net.flow.DefaultTrafficSelector;
21import org.onlab.onos.net.flow.TrafficSelector;
22import org.onlab.packet.Ethernet;
23import org.onlab.packet.MacAddress;
24
25import com.google.common.base.Strings;
26
27/**
28 * Base class for command line operations for connectivity based intents.
29 */
30public 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 HIGUCHI5c947272014-11-03 21:39:21 -080047 * @return traffic selector
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070048 */
49 protected TrafficSelector buildTrafficSelector() {
50 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070051 Short ethType = Ethernet.TYPE_IPV4;
Ray Milkeycaa450b2014-10-29 15:54:24 -070052
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070053 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}