ITM impl Organize Imports for Checkstyle compliance
[genius.git] / itm / itm-impl / src / main / java / org / opendaylight / genius / itm / cli / RemoveExternalEndpoint.java
1 /*
2  * Copyright (c) 2015 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.genius.itm.cli;
9
10 import org.apache.karaf.shell.commands.Argument;
11 import org.apache.karaf.shell.commands.Command;
12 import org.apache.karaf.shell.console.OsgiCommandSupport;
13 import org.opendaylight.genius.itm.api.IITMProvider;
14 import org.opendaylight.genius.itm.globals.ITMConstants;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeBase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeGre;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeMplsOverGre;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22 /**
23  * Created by echiapt on 7/5/2016.
24  */
25 @Command(scope = "tep", name = "rem-external-endpoint", description = "removing an external endpoint")
26 public class RemoveExternalEndpoint extends OsgiCommandSupport {
27     @Argument(index = 0, name = "destination-ip", description = "Destination-IP", required = true, multiValued = false)
28     private String destinationIp;
29     @Argument(index = 1, name = "TunnelType", description = "Tunnel-Type", required = true, multiValued = false)
30     private String tunnelType;
31
32     private static final Logger LOG = LoggerFactory.getLogger(RemoveExternalEndpoint.class);
33     private IITMProvider itmProvider;
34
35     public void setItmProvider(IITMProvider itmProvider) {
36         this.itmProvider = itmProvider;
37     }
38
39     @Override
40     protected Object doExecute() {
41         try {
42             LOG.debug("RemoveExternalEndpoint: destinationIP {} with tunnelType {}", destinationIp, tunnelType);
43             Class<? extends TunnelTypeBase> tunType = TunnelTypeVxlan.class;
44             if( tunnelType.toUpperCase().equals(ITMConstants.TUNNEL_TYPE_VXLAN))
45                 tunType = TunnelTypeVxlan.class ;
46             else if( tunnelType.toUpperCase().equals(ITMConstants.TUNNEL_TYPE_GRE) )
47                 tunType = TunnelTypeGre.class ;
48             else if (tunnelType.toUpperCase().equals(ITMConstants.TUNNEL_TYPE_MPLSoGRE)) {
49                 tunType = TunnelTypeMplsOverGre.class;
50             } else {
51                 System.out.println("Invalid tunnel-type " + tunnelType);
52                 return null;
53             }
54
55             if (!itmProvider.validateIP(destinationIp)) {
56                 System.out.println("Invalid IpAddress " + destinationIp);
57                 return null;
58             }
59
60             IpAddress dcgwIPAddr = new IpAddress(destinationIp.toCharArray());
61             itmProvider.remExternalEndpoint(tunType, dcgwIPAddr);
62         } catch (IllegalArgumentException e) {
63             System.out.println(e.getMessage());
64         } catch (Exception e) {
65             System.out.println(e.getMessage());
66             LOG.error("Exception occurred during execution of command \"tep:configure-tunnelType\": ", e);
67         }
68         return null;
69     }
70
71
72 }