ELAN: skip remote unicast MACs
[netvirt.git] / fibmanager / shell / src / main / java / org / opendaylight / netvirt / fibmanager / shell / ConfTransportL3VPNCommand.java
1 /*
2  * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netvirt.fibmanager.shell;
9
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;
16
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;
21
22     @Option(name = "-s", aliases = {"--service"}, description = "Service", required = false, multiValued = false)
23     String service;
24
25     @Option(name = "-t", aliases = {"--type"}, description = "Configure Transport Type",
26         required = false, multiValued = false)
27     String transportType;
28
29     public ConfTransportL3VPNCommand(IFibManager fibManager) {
30         this.fibManager = fibManager;
31     }
32
33     @Override
34     protected Object doExecute() throws Exception {
35
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>");
40             return null;
41         }
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");
46             return null;
47         }
48
49         String cachedTransType = fibManager.getConfTransType();
50         if (cachedTransType.equalsIgnoreCase(transportType)) {
51             session.getConsole().println("Transport type already configured as " + cachedTransType);
52             return null;
53         }
54
55         if (cachedTransType.equals(L3VPNTransportTypes.Invalid.getTransportType())
56             || !fibManager.isVPNConfigured()) {
57             fibManager.setConfTransType(service, transportType.toUpperCase(Locale.getDefault()));
58             fibManager.writeConfTransTypeConfigDS();
59         } else {
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.");
63         }
64         return null;
65     }
66 }