82d375f689b65face852dd855d2b8cd18cb2334a
[unimgr.git] / cli / src / main / java / org / opendaylight / unimgr / cli / UniAddShellCommand.java
1 /*
2  * Copyright (c) 2015 CableLabs 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.unimgr.cli;
9
10 import java.math.BigInteger;
11
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.unimgr.api.IUnimgrConsoleProvider;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentationBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.uni.SpeedBuilder;
21
22 @Command(name = "uni-add",
23          scope = "uni",
24          description = "Adds an uni to the controller.")
25 public class UniAddShellCommand extends OsgiCommandSupport {
26
27     protected IUnimgrConsoleProvider provider;
28
29     @Option(name = "-pm",
30             aliases = { "--physical-medium" },
31             description = "The physical medium.\n-pm / --physical-medium <physical-medium>",
32             required = false,
33             multiValued = false)
34     private String physicalMedium = "UNI TypeFull Duplex 2 Physical Interface";
35
36     @Option(name = "-ma",
37             aliases = { "--mac-address" },
38             description = "The mac address.\n-ma / --mac-address <mac-address>",
39             required = true,
40             multiValued = false)
41     private String macAddress = "any";
42
43     @Option(name = "-m",
44             aliases = { "--mode" },
45             description = "The mode.\n-m / --mode <mode>",
46             required = false,
47             multiValued = false)
48     private String mode = "Full Duplex";
49
50     @Option(name = "-ml",
51             aliases = { "--mac-layer" },
52             description = "The mac layer.\n-ml / --mac-layer <mac-layer",
53             required = false,
54             multiValued = false)
55     private String macLayer = "IEEE 802.3-2005";
56
57     @Option(name = "-t",
58             aliases = { "--type" },
59             description = "The type.\n-t / --type <type>",
60             required = false,
61             multiValued = false)
62     private String type = "";
63
64     @Option(name = "-ms",
65             aliases = { "--mtu-size" },
66             description = "The mtu size.\n-ms / --mtu-size <mtu-size>",
67             required = false,
68             multiValued = false)
69     private String mtuSize = "0";
70
71     @Option(name = "-s",
72             aliases = { "--speed" },
73             description = "Spped.\n-s / --speed 10M/100M/1G/10G",
74             required = false,
75             multiValued = false)
76     private String speed = "1G";
77
78     @Option(name = "-ip",
79             aliases = { "--ipAddress" },
80             description = "IpAddress of the Uni",
81             required = true,
82             multiValued = false)
83     private String ipAddress = "any";
84
85     public UniAddShellCommand(IUnimgrConsoleProvider provider) {
86         this.provider = provider;
87     }
88
89     @Override
90     protected Object doExecute() throws Exception {
91         UniAugmentation uni = new UniAugmentationBuilder()
92                         .setMacAddress(new MacAddress(macAddress))
93                         .setMacLayer(macLayer)
94                         .setMode(mode)
95                         .setMtuSize(BigInteger.valueOf(Long.valueOf(mtuSize)))
96                         .setPhysicalMedium(physicalMedium)
97                         .setSpeed(new SpeedBuilder().setSpeed(Utils.getSpeed(speed)).build())
98                         .setType(type)
99                         .setIpAddress(new IpAddress(ipAddress.toCharArray()))
100                         .build();
101         if (provider.addUni(uni)) {
102             return new String("Uni with ip " + ipAddress + " created");
103         } else {
104             return new String("Error creating new Uni");
105         }
106     }
107 }