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