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.yang.types.rev130715.MacAddress;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev150622.service.speed.speed.Speed100MBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev150622.service.speed.speed.Speed10GBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev150622.service.speed.speed.Speed10MBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev150622.service.speed.speed.Speed1GBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev150622.uni.Speed;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev150622.unis.Uni;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev150622.unis.UniBuilder;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
26 @Command(name = "add",
28 description = "Adds an uni to the controller.")
29 public class UniAddShellCommand extends OsgiCommandSupport {
31 protected IUnimgrConsoleProvider provider;
34 aliases = { "--uni-id" },
35 description = "The id.\n-id / --id <id>",
38 private String uniId = "any";
41 aliases = { "--physical-medium" },
42 description = "The physical medium.\n-pm / --physical-medium <physical-medium>",
45 private String physicalMedium = "any";
48 aliases = { "--mac-address" },
49 description = "The mac address.\n-ma / --mac-address <mac-address>",
52 private String macAddress = "any";
55 aliases = { "--mode" },
56 description = "The mode.\n-m / --mode <mode>",
59 private String mode = "any";
62 aliases = { "--mac-layer" },
63 description = "The mac layer.\n-ml / --mac-layer <mac-layer",
66 private String macLayer = "any";
69 aliases = { "--type" },
70 description = "The type.\n-t / --type <type>",
73 private String type = "any";
76 aliases = { "--mtu-size" },
77 description = "The mtu size.\n-ms / --mtu-size <mtu-size>",
80 private String mtuSize;
83 aliases = { "--speed" },
84 description = "Spped.\n-s / --speed 10M/100M/1G/10G",
87 private String speed = "any";
89 public UniAddShellCommand(IUnimgrConsoleProvider provider) {
90 this.provider = provider;
93 private Object getSpeed() {
95 System.out.println(speed);
97 Object speedObject = null;
98 if (speed.equals("10M")) {
99 System.out.println("there");
100 speedObject = new Speed10MBuilder().build();
102 if (speed.equals("100M")) {
103 speedObject = new Speed100MBuilder().build();
105 if (speed.equals("1G")) {
106 speedObject = new Speed1GBuilder().build();
108 if (speed.equals("10G")) {
109 speedObject = new Speed10GBuilder().build();
111 System.out.println(speedObject);
116 protected Object doExecute() throws Exception {
117 Uni uni = new UniBuilder()
118 .setMacAddress(new MacAddress(macAddress))
119 .setMacLayer(macLayer)
121 .setMtuSize(BigInteger.valueOf(Long.valueOf(mtuSize)))
122 .setPhysicalMedium(physicalMedium)
123 .setSpeed((Speed) getSpeed())
125 .setId(new NodeId(uniId))
128 if (provider.addUni(uni)) {
129 return String.format("Uni created (id: %s)", uni.getId());
131 return new String("Error creating new uni");