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.service.speed.speed.Speed100MBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10GBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10MBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed1GBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.uni.Speed;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 @Command(name = "uni-add",
30 description = "Adds an uni to the controller.")
31 public class UniAddShellCommand extends OsgiCommandSupport {
33 private static final Logger LOG = LoggerFactory.getLogger(UniAddShellCommand.class);
34 protected IUnimgrConsoleProvider provider;
37 aliases = { "--physical-medium" },
38 description = "The physical medium.\n-pm / --physical-medium <physical-medium>",
41 private String physicalMedium = "UNI TypeFull Duplex 2 Physical Interface";
44 aliases = { "--mac-address" },
45 description = "The mac address.\n-ma / --mac-address <mac-address>",
48 private String macAddress = "any";
51 aliases = { "--mode" },
52 description = "The mode.\n-m / --mode <mode>",
55 private String mode = "Full Duplex";
58 aliases = { "--mac-layer" },
59 description = "The mac layer.\n-ml / --mac-layer <mac-layer",
62 private String macLayer = "IEEE 802.3-2005";
65 aliases = { "--type" },
66 description = "The type.\n-t / --type <type>",
69 private String type = "";
72 aliases = { "--mtu-size" },
73 description = "The mtu size.\n-ms / --mtu-size <mtu-size>",
76 private String mtuSize = "0";
79 aliases = { "--speed" },
80 description = "Spped.\n-s / --speed 10M/100M/1G/10G",
83 private String speed = "";
86 aliases = { "--ipAddress" },
87 description = "IpAddress of the Uni",
90 private String ipAddress = "any";
92 public UniAddShellCommand(IUnimgrConsoleProvider provider) {
93 this.provider = provider;
96 private Object getSpeed() {
97 Object speedObject = null;
98 if (speed.equals("10M")) {
99 speedObject = new Speed10MBuilder().build();
101 else if (speed.equals("100M")) {
102 speedObject = new Speed100MBuilder().build();
104 else if (speed.equals("1G")) {
105 speedObject = new Speed1GBuilder().build();
107 else if (speed.equals("10G")) {
108 speedObject = new Speed10GBuilder().build();
114 protected Object doExecute() throws Exception {
115 UniAugmentation uni = new UniAugmentationBuilder()
116 .setMacAddress(new MacAddress(macAddress))
117 .setMacLayer(macLayer)
119 .setMtuSize(BigInteger.valueOf(Long.valueOf(mtuSize)))
120 .setPhysicalMedium(physicalMedium)
121 .setSpeed((Speed) getSpeed())
123 .setIpAddress(new IpAddress(ipAddress.toCharArray()))
126 if (provider.addUni(uni)) {
127 return new String("Uni with ip " +ipAddress+" created");
129 return new String("Error creating new Uni");