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;
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.unimgr.api.IUnimgrConsoleProvider;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentationBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.uni.SpeedBuilder;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 @Command(name = "uni-add",
25 description = "Adds an uni to the controller.")
26 public class UniAddShellCommand extends OsgiCommandSupport {
28 private static final Logger LOG = LoggerFactory.getLogger(UniAddShellCommand.class);
29 protected IUnimgrConsoleProvider provider;
32 aliases = { "--physical-medium" },
33 description = "The physical medium.\n-pm / --physical-medium <physical-medium>",
36 private String physicalMedium = "UNI TypeFull Duplex 2 Physical Interface";
39 aliases = { "--mac-address" },
40 description = "The mac address.\n-ma / --mac-address <mac-address>",
43 private String macAddress = "any";
46 aliases = { "--mode" },
47 description = "The mode.\n-m / --mode <mode>",
50 private String mode = "Full Duplex";
53 aliases = { "--mac-layer" },
54 description = "The mac layer.\n-ml / --mac-layer <mac-layer",
57 private String macLayer = "IEEE 802.3-2005";
60 aliases = { "--type" },
61 description = "The type.\n-t / --type <type>",
64 private String type = "";
67 aliases = { "--mtu-size" },
68 description = "The mtu size.\n-ms / --mtu-size <mtu-size>",
71 private String mtuSize = "0";
74 aliases = { "--speed" },
75 description = "Spped.\n-s / --speed 10M/100M/1G/10G",
78 private String speed = "1G";
81 aliases = { "--ipAddress" },
82 description = "IpAddress of the Uni",
85 private String ipAddress = "any";
87 public UniAddShellCommand(IUnimgrConsoleProvider provider) {
88 this.provider = provider;
92 protected Object doExecute() throws Exception {
93 UniAugmentation uni = new UniAugmentationBuilder()
94 .setMacAddress(new MacAddress(macAddress))
95 .setMacLayer(macLayer)
97 .setMtuSize(BigInteger.valueOf(Long.valueOf(mtuSize)))
98 .setPhysicalMedium(physicalMedium)
99 .setSpeed(new SpeedBuilder().setSpeed(Utils.getSpeed(speed)).build())
101 .setIpAddress(new IpAddress(ipAddress.toCharArray()))
103 if (provider.addUni(uni)) {
104 return new String("Uni with ip " +ipAddress+" created");
106 return new String("Error creating new Uni");