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;
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;
21 @Command(name = "uni-update",
23 description = "Updates an uni to the controller.")
24 public class UniUpdateShellCommand extends OsgiCommandSupport{
26 aliases = { "--ipAddress" },
27 description = "IpAddress of the Uni",
30 private String ipAddress = "any";
33 aliases = { "--mac-address" },
34 description = "The mac address.\n-ma / --mac-address <mac-address>",
37 private String macAddress = "any";
40 aliases = { "--mac-layer" },
41 description = "The mac layer.\n-ml / --mac-layer <mac-layer",
44 private String macLayer = "IEEE 802.3-2005";
47 aliases = { "--mode" },
48 description = "The mode.\n-m / --mode <mode>",
51 private String mode = "Full Duplex";
54 aliases = { "--mtu-size" },
55 description = "The mtu size.\n-ms / --mtu-size <mtu-size>",
58 private String mtuSize = "0";
61 aliases = { "--physical-medium" },
62 description = "The physical medium.\n-pm / --physical-medium <physical-medium>",
65 private String physicalMedium = "UNI TypeFull Duplex 2 Physical Interface";
67 protected IUnimgrConsoleProvider provider;
70 aliases = { "--speed" },
71 description = "Spped.\n-s / --speed 10M/100M/1G/10G",
74 private String speed = "";
77 aliases = { "--type" },
78 description = "The type.\n-t / --type <type>",
81 private String type = "";
83 public UniUpdateShellCommand(IUnimgrConsoleProvider provider) {
84 this.provider = provider;
88 protected Object doExecute() throws Exception {
89 final UniAugmentation uniAug = new UniAugmentationBuilder()
90 .setMacAddress(new MacAddress(macAddress))
91 .setMacLayer(macLayer)
93 .setMtuSize(BigInteger.valueOf(Long.valueOf(mtuSize)))
94 .setPhysicalMedium(physicalMedium)
95 .setSpeed(new SpeedBuilder().setSpeed(Utils.getSpeed(speed)).build())
97 .setIpAddress(new IpAddress(ipAddress.toCharArray()))
99 if (provider.updateUni(uniAug)) {
100 return new String("Uni with ip " +ipAddress+" updated");
102 return new String("Error updating new Uni");