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.rev151012.Uni;
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.service.speed.speed.Speed100MBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10GBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10MBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed1GBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.uni.Speed;
25 @Command(name = "add",
27 description = "Adds an uni to the controller.")
28 public class UniAddShellCommand extends OsgiCommandSupport {
30 protected IUnimgrConsoleProvider provider;
33 aliases = { "--uni-id" },
34 description = "The id.\n-id / --id <id>",
37 private String uniId = "any";
40 aliases = { "--physical-medium" },
41 description = "The physical medium.\n-pm / --physical-medium <physical-medium>",
44 private String physicalMedium = "any";
47 aliases = { "--mac-address" },
48 description = "The mac address.\n-ma / --mac-address <mac-address>",
51 private String macAddress = "any";
54 aliases = { "--mode" },
55 description = "The mode.\n-m / --mode <mode>",
58 private String mode = "any";
61 aliases = { "--mac-layer" },
62 description = "The mac layer.\n-ml / --mac-layer <mac-layer",
65 private String macLayer = "any";
68 aliases = { "--type" },
69 description = "The type.\n-t / --type <type>",
72 private String type = "any";
75 aliases = { "--mtu-size" },
76 description = "The mtu size.\n-ms / --mtu-size <mtu-size>",
79 private String mtuSize;
82 aliases = { "--speed" },
83 description = "Spped.\n-s / --speed 10M/100M/1G/10G",
86 private String speed = "any";
88 public UniAddShellCommand(IUnimgrConsoleProvider provider) {
89 this.provider = provider;
92 private Object getSpeed() {
94 System.out.println(speed);
96 Object speedObject = null;
97 if (speed.equals("10M")) {
98 speedObject = new Speed10MBuilder().build();
100 if (speed.equals("100M")) {
101 speedObject = new Speed100MBuilder().build();
103 if (speed.equals("1G")) {
104 speedObject = new Speed1GBuilder().build();
106 if (speed.equals("10G")) {
107 speedObject = new Speed10GBuilder().build();
109 System.out.println(speedObject);
114 protected Object doExecute() throws Exception {
115 Uni 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())
125 if (provider.addUni(uni)) {
126 return String.format("Uni created {}", uni.getIpAddress().getIpv4Address());
128 return new String("Error creating new uni");