2 * Copyright (c) 2015 CableLabs 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.unimgr.cli;
10 import java.math.BigInteger;
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;
22 @Command(name = "uni-add",
24 description = "Adds an uni to the controller.")
25 public class UniAddShellCommand extends OsgiCommandSupport {
27 protected IUnimgrConsoleProvider provider;
30 aliases = { "--physical-medium" },
31 description = "The physical medium.\n-pm / --physical-medium <physical-medium>",
34 private String physicalMedium = "UNI TypeFull Duplex 2 Physical Interface";
37 aliases = { "--mac-address" },
38 description = "The mac address.\n-ma / --mac-address <mac-address>",
41 private String macAddress = "any";
44 aliases = { "--mode" },
45 description = "The mode.\n-m / --mode <mode>",
48 private String mode = "Full Duplex";
51 aliases = { "--mac-layer" },
52 description = "The mac layer.\n-ml / --mac-layer <mac-layer",
55 private String macLayer = "IEEE 802.3-2005";
58 aliases = { "--type" },
59 description = "The type.\n-t / --type <type>",
62 private String type = "";
65 aliases = { "--mtu-size" },
66 description = "The mtu size.\n-ms / --mtu-size <mtu-size>",
69 private String mtuSize = "0";
72 aliases = { "--speed" },
73 description = "Spped.\n-s / --speed 10M/100M/1G/10G",
76 private String speed = "1G";
79 aliases = { "--ipAddress" },
80 description = "IpAddress of the Uni",
83 private String ipAddress = "any";
85 public UniAddShellCommand(IUnimgrConsoleProvider provider) {
86 this.provider = provider;
90 protected Object doExecute() throws Exception {
91 UniAugmentation uni = new UniAugmentationBuilder()
92 .setMacAddress(new MacAddress(macAddress))
93 .setMacLayer(macLayer)
95 .setMtuSize(BigInteger.valueOf(Long.valueOf(mtuSize)))
96 .setPhysicalMedium(physicalMedium)
97 .setSpeed(new SpeedBuilder().setSpeed(Utils.getSpeed(speed)).build())
99 .setIpAddress(new IpAddress(ipAddress.toCharArray()))
101 if (provider.addUni(uni)) {
102 return new String("Uni with ip " + ipAddress + " created");
104 return new String("Error creating new Uni");