blob: de3b0c2a9f572afd4b00975cfe5cbe00ebf915d4 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.onlab.onos.cli.net;
import org.apache.karaf.shell.commands.Option;
import org.onlab.onos.cli.AbstractShellCommand;
import org.onlab.onos.net.flow.DefaultTrafficSelector;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.packet.Ethernet;
import org.onlab.packet.MacAddress;
import com.google.common.base.Strings;
/**
* Base class for command line operations for connectivity based intents.
*/
public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
@Option(name = "-s", aliases = "--ethSrc", description = "Source MAC Address",
required = false, multiValued = false)
private String srcMacString = null;
@Option(name = "-d", aliases = "--ethDst", description = "Destination MAC Address",
required = false, multiValued = false)
private String dstMacString = null;
@Option(name = "-t", aliases = "--ethType", description = "Ethernet Type",
required = false, multiValued = false)
private String ethTypeString = "";
/**
* Constructs a traffic selector based on the command line arguments
* presented to the command.
*/
protected TrafficSelector buildTrafficSelector() {
TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
Short ethType = Ethernet.TYPE_IPV4;
if (!Strings.isNullOrEmpty(ethTypeString)) {
EthType ethTypeParameter = EthType.valueOf(ethTypeString);
ethType = ethTypeParameter.value();
}
selectorBuilder.matchEthType(ethType);
if (!Strings.isNullOrEmpty(srcMacString)) {
selectorBuilder.matchEthSrc(MacAddress.valueOf(srcMacString));
}
if (!Strings.isNullOrEmpty(dstMacString)) {
selectorBuilder.matchEthDst(MacAddress.valueOf(dstMacString));
}
return selectorBuilder.build();
}
}