2 * Copyright (c) 2016 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;
26 @Command(name = "uni-update",
28 description = "Updates an uni to the controller.")
29 public class UniUpdateShellCommand extends OsgiCommandSupport{
30 protected IUnimgrConsoleProvider provider;
33 aliases = { "--physical-medium" },
34 description = "The physical medium.\n-pm / --physical-medium <physical-medium>",
37 private final String physicalMedium = "UNI TypeFull Duplex 2 Physical Interface";
40 aliases = { "--mac-address" },
41 description = "The mac address.\n-ma / --mac-address <mac-address>",
44 private final String macAddress = "any";
47 aliases = { "--mode" },
48 description = "The mode.\n-m / --mode <mode>",
51 private final String mode = "Full Duplex";
54 aliases = { "--mac-layer" },
55 description = "The mac layer.\n-ml / --mac-layer <mac-layer",
58 private final String macLayer = "IEEE 802.3-2005";
61 aliases = { "--type" },
62 description = "The type.\n-t / --type <type>",
65 private final String type = "";
68 aliases = { "--mtu-size" },
69 description = "The mtu size.\n-ms / --mtu-size <mtu-size>",
72 private final String mtuSize = "0";
75 aliases = { "--speed" },
76 description = "Spped.\n-s / --speed 10M/100M/1G/10G",
79 private final String speed = "";
82 aliases = { "--ipAddress" },
83 description = "IpAddress of the Uni",
86 private final String ipAddress = "any";
88 public UniUpdateShellCommand(IUnimgrConsoleProvider provider) {
89 this.provider = provider;
92 private Object getSpeed() {
93 Object speedObject = null;
94 if (speed.equals("10M")) {
95 speedObject = new Speed10MBuilder().build();
97 else if (speed.equals("100M")) {
98 speedObject = new Speed100MBuilder().build();
100 else if (speed.equals("1G")) {
101 speedObject = new Speed1GBuilder().build();
103 else if (speed.equals("10G")) {
104 speedObject = new Speed10GBuilder().build();
110 protected Object doExecute() throws Exception {
111 final UniAugmentation uniAug = new UniAugmentationBuilder()
112 .setMacAddress(new MacAddress(macAddress))
113 .setMacLayer(macLayer)
115 .setMtuSize(BigInteger.valueOf(Long.valueOf(mtuSize)))
116 .setPhysicalMedium(physicalMedium)
117 .setSpeed((Speed) getSpeed())
119 .setIpAddress(new IpAddress(ipAddress.toCharArray()))
121 if (provider.updateUni(uniAug)) {
122 return new String("Uni with ip " +ipAddress+" updated");
124 return new String("Error updating new Uni");