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 org.apache.karaf.shell.commands.Command;
12 import org.apache.karaf.shell.commands.Option;
13 import org.apache.karaf.shell.console.OsgiCommandSupport;
14 import org.opendaylight.netvirt.fibmanager.api.IFibManager;
15 import org.opendaylight.netvirt.fibmanager.api.L3VPNTransportTypes;
17 @Command(scope = "vpnservice", name = "configureTransportType",
18 description = "Configure Preferred Transport Type for L3VPN service")
19 public class ConfTransportL3VPNCommand extends OsgiCommandSupport {
20 private final IFibManager fibManager;
22 @Option(name = "-s", aliases = {"--service"}, description = "Service", required = false, multiValued = false)
25 @Option(name = "-t", aliases = {"--type"}, description = "Configure Transport Type",
26 required = false, multiValued = false)
29 public ConfTransportL3VPNCommand(IFibManager fibManager) {
30 this.fibManager = fibManager;
34 protected Object doExecute() throws Exception {
36 if (service == null || service.isEmpty() || !"L3VPN".equalsIgnoreCase(service)) {
37 session.getConsole().println("Please provide valid input for service ");
38 session.getConsole().println(
39 "exec configure-transport-type (-s | --service) <L3VPN> (-t | --type) <VxLAN/GRE>");
42 if (transportType == null || transportType.isEmpty()
43 || L3VPNTransportTypes.validateTransportType(transportType.toUpperCase(Locale.getDefault()))
44 == L3VPNTransportTypes.Invalid) {
45 session.getConsole().println("Please provide valid input for Transport type");
49 String cachedTransType = fibManager.getConfTransType();
50 if (cachedTransType.equalsIgnoreCase(transportType)) {
51 session.getConsole().println("Transport type already configured as " + cachedTransType);
55 if (cachedTransType.equals(L3VPNTransportTypes.Invalid.getTransportType())
56 || !fibManager.isVPNConfigured()) {
57 fibManager.setConfTransType(service, transportType.toUpperCase(Locale.getDefault()));
58 fibManager.writeConfTransTypeConfigDS();
60 session.getConsole().println("VPN service already configured with " + cachedTransType
61 + " as the transport type. Please remove vpn service and configure"
62 + " again. Changes were discarded.");