blob: b9b071fbba09f5bd1ffa0232c8bfa9b0fa3bd9e7 [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.
47 */
48 protected TrafficSelector buildTrafficSelector() {
49 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
50
51 Short ethType = Ethernet.TYPE_IPV4;
52 if (!Strings.isNullOrEmpty(ethTypeString)) {
53 EthType ethTypeParameter = EthType.valueOf(ethTypeString);
54 ethType = ethTypeParameter.value();
55 }
56 selectorBuilder.matchEthType(ethType);
57
58 if (!Strings.isNullOrEmpty(srcMacString)) {
59 selectorBuilder.matchEthSrc(MacAddress.valueOf(srcMacString));
60 }
61
62 if (!Strings.isNullOrEmpty(dstMacString)) {
63 selectorBuilder.matchEthDst(MacAddress.valueOf(dstMacString));
64 }
65
66 return selectorBuilder.build();
67 }
68
69}