2 * Copyright (c) 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
9 package org.opendaylight.vpnservice.itm.cli;
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.vpnservice.itm.api.IITMProvider;
15 import org.opendaylight.vpnservice.itm.globals.ITMConstants;
16 import org.opendaylight.vpnservice.itm.impl.ItmUtils;
17 import org.opendaylight.vpnservice.itm.cli.ItmCliUtils;
18 //import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.itm.config.rev151102.vtep.config.schemas.VtepConfigSchema;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.vtep.config.schemas.VtepConfigSchema;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * The Class which implements karaf command "vtep:schema-add".
26 @Command(scope = "vtep", name = "schema-add", description = "Adding a VTEP schema.")
27 public class VtepSchemaAdd extends OsgiCommandSupport {
29 private static final String SCHEMA_NAME = "--schema-name";
30 private static final String PORT_NAME = "--port-name";
31 private static final String VLAN_ID = "--vlan-id";
32 private static final String SUBNET_CIDR = "--subnet-cidr";
33 private static final String TRANSPORT_ZONE = "--transport-zone";
34 private static final String DPN_IDS = "--dpn-ids";
35 private static final String GATEWAY_IP = "--gateway-ip";
36 private static final String TUNNEL_TYPE = "--tunnel-type";
37 private static final String EXCLUDE_IP_FILTER = "--exclude-ip-filter";
39 /** The schema name. */
40 @Option(name = SCHEMA_NAME, aliases = { "-s" }, description = "Schema name", required = true, multiValued = false)
41 private String schemaName;
44 @Option(name = PORT_NAME, aliases = { "-p" }, description = "Port name", required = true, multiValued = false)
45 private String portName;
48 @Option(name = VLAN_ID, aliases = { "-v" }, description = "VLAN ID", required = true, multiValued = false)
49 private Integer vlanId;
51 /** The subnet mask. */
52 @Option(name = SUBNET_CIDR, aliases = {
53 "-sc" }, description = "Subnet Mask in CIDR-notation string, e.g. 10.0.0.0/24", required = true, multiValued = false)
54 private String subnetCIDR;
56 /** The transport zone. */
57 @Option(name = TRANSPORT_ZONE, aliases = {
58 "-tz" }, description = "Transport zone", required = true, multiValued = false)
59 private String transportZone;
62 @Option(name = DPN_IDS, aliases = {
63 "-d" }, description = "DPN ID's in comma separated values. e.g: 2,3,10", required = false, multiValued = false)
64 private String dpnIds;
66 /** The gateway ip. */
67 @Option(name = GATEWAY_IP, aliases = {
68 "-g" }, description = "Gateway IP address", required = false, multiValued = false)
69 private String gatewayIp;
71 /** The tunnel type. */
72 @Option(name = TUNNEL_TYPE, aliases = {
73 "-t" }, description = "Tunnel type. Value: VXLAN | GRE. Default: VXLAN", required = false, multiValued = false)
74 private String tunnelType;
76 /** The exclude ip filter. */
77 @Option(name = EXCLUDE_IP_FILTER, aliases = {
78 "-ex" }, description = "IP Addresses which needs to be excluded from the specified subnet. IP address range or comma separated IP addresses can to be specified. e.g: 10.0.0.1-10.0.0.20,10.0.0.30,10.0.0.35", required = false, multiValued = false)
79 private String excludeIpFilter;
81 /** The Constant logger. */
82 private static final Logger LOG = LoggerFactory.getLogger(VtepSchemaAdd.class);
84 /** The itm provider. */
85 private IITMProvider itmProvider;
88 * Sets the itm provider.
91 * the new itm provider
93 public void setItmProvider(IITMProvider itmProvider) {
94 this.itmProvider = itmProvider;
100 private void usage() {
101 System.out.println(String.format(
102 "usage: vtep:schema-add [%s schema-name] [%s port-name] [%s vlan-id] [%s subnet-cidr] [%s transport-zone] [%s dpn-ids] [%s gateway-ip] [%s tunnel-type] [%s exclude-ip-filter]",
103 SCHEMA_NAME, PORT_NAME, VLAN_ID, SUBNET_CIDR, TRANSPORT_ZONE, DPN_IDS, GATEWAY_IP, TUNNEL_TYPE,
110 * @see org.apache.karaf.shell.console.AbstractAction#doExecute()
113 protected Object doExecute() {
115 if (this.schemaName == null || this.portName == null || this.vlanId == null || this.subnetCIDR == null
116 || this.transportZone == null) {
120 LOG.debug("Executing vtep:schema-add command\t {} \t {} \t {} \t {} \t {} \t {} \t {} \t {} \t {}", schemaName,
121 portName, vlanId, subnetCIDR, gatewayIp, transportZone, tunnelType, dpnIds, excludeIpFilter);
123 if( null == tunnelType) {
124 tunnelType = ITMConstants.TUNNEL_TYPE_VXLAN ;
126 VtepConfigSchema schema = ItmUtils.constructVtepConfigSchema(schemaName, portName, vlanId, subnetCIDR,
127 gatewayIp, transportZone, tunnelType, ItmCliUtils.constructDpnIdList(dpnIds), excludeIpFilter);
128 this.itmProvider.addVtepConfigSchema(schema);
130 } catch (IllegalArgumentException e) {
131 System.out.println(e.getMessage());
132 } catch (Exception e) {
133 LOG.error("Exception occurred during execution of command \"vtep:schema-add\": ", e);