2 * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netvirt.fibmanager.shell;
10 import java.util.Locale;
11 import javax.annotation.Nullable;
12 import org.apache.karaf.shell.commands.Command;
13 import org.apache.karaf.shell.commands.Option;
14 import org.apache.karaf.shell.console.OsgiCommandSupport;
15 import org.opendaylight.netvirt.fibmanager.api.IFibManager;
16 import org.opendaylight.netvirt.fibmanager.api.L3VPNTransportTypes;
18 @Command(scope = "vpnservice", name = "configureTransportType",
19 description = "Configure Preferred Transport Type for L3VPN service")
20 public class ConfTransportL3VPNCommand extends OsgiCommandSupport {
21 private final IFibManager fibManager;
23 @Option(name = "-s", aliases = {"--service"}, description = "Service", required = false, multiValued = false)
26 @Option(name = "-t", aliases = {"--type"}, description = "Configure Transport Type",
27 required = false, multiValued = false)
30 public ConfTransportL3VPNCommand(IFibManager fibManager) {
31 this.fibManager = fibManager;
36 protected Object doExecute() {
38 if (service == null || service.isEmpty() || !"L3VPN".equalsIgnoreCase(service)) {
39 session.getConsole().println("Please provide valid input for service ");
40 session.getConsole().println(
41 "exec configure-transport-type (-s | --service) <L3VPN> (-t | --type) <VxLAN/GRE>");
44 if (transportType == null || transportType.isEmpty()
45 || L3VPNTransportTypes.validateTransportType(transportType.toUpperCase(Locale.getDefault()))
46 == L3VPNTransportTypes.Invalid) {
47 session.getConsole().println("Please provide valid input for Transport type");
51 String cachedTransType = fibManager.getConfTransType();
52 if (cachedTransType.equalsIgnoreCase(transportType)) {
53 session.getConsole().println("Transport type already configured as " + cachedTransType);
57 if (cachedTransType.equals(L3VPNTransportTypes.Invalid.getTransportType())
58 || !fibManager.isVPNConfigured()) {
59 fibManager.setConfTransType(service, transportType.toUpperCase(Locale.getDefault()));
60 fibManager.writeConfTransTypeConfigDS();
62 session.getConsole().println("VPN service already configured with " + cachedTransType
63 + " as the transport type. Please remove vpn service and configure"
64 + " again. Changes were discarded.");