Renamed artifacts to reflect the project's name.
[unimgr.git] / cli / src / main / java / org / opendaylight / unimgr / cli / UniAddShellCommand.java
1 /*
2  * Copyright (c) 2015 CableLabs and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.unimgr.cli;
9
10 import java.math.BigInteger;
11
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;
25
26 @Command(name = "add",
27          scope = "uni",
28          description = "Adds an uni to the controller.")
29 public class UniAddShellCommand extends OsgiCommandSupport {
30
31     protected IUnimgrConsoleProvider provider;
32
33     @Option(name = "-id",
34             aliases = { "--uni-id" },
35             description = "The id.\n-id / --id <id>",
36             required = true,
37             multiValued = false)
38     private String uniId = "any";
39
40     @Option(name = "-pm",
41             aliases = { "--physical-medium" },
42             description = "The physical medium.\n-pm / --physical-medium <physical-medium>",
43             required = false,
44             multiValued = false)
45     private String physicalMedium = "any";
46
47     @Option(name = "-ma",
48             aliases = { "--mac-address" },
49             description = "The mac address.\n-ma / --mac-address <mac-address>",
50             required = false,
51             multiValued = false)
52     private String macAddress = "any";
53
54     @Option(name = "-m",
55             aliases = { "--mode" },
56             description = "The mode.\n-m / --mode <mode>",
57             required = false,
58             multiValued = false)
59     private String mode = "any";
60
61     @Option(name = "-ml",
62             aliases = { "--mac-layer" },
63             description = "The mac layer.\n-ml / --mac-layer <mac-layer",
64             required = false,
65             multiValued = false)
66     private String macLayer = "any";
67
68     @Option(name = "-t",
69             aliases = { "--type" },
70             description = "The type.\n-t / --type <type>",
71             required = false,
72             multiValued = false)
73     private String type = "any";
74
75     @Option(name = "-ms",
76             aliases = { "--mtu-size" },
77             description = "The mtu size.\n-ms / --mtu-size <mtu-size>",
78             required = false,
79             multiValued = false)
80     private String mtuSize;
81
82     @Option(name = "-s",
83             aliases = { "--speed" },
84             description = "Spped.\n-s / --speed 10M/100M/1G/10G",
85             required = true,
86             multiValued = true)
87     private String speed = "any";
88
89     public UniAddShellCommand(IUnimgrConsoleProvider provider) {
90         this.provider = provider;
91     }
92
93     private Object getSpeed() {
94
95         System.out.println(speed);
96
97         Object speedObject = null;
98         if (speed.equals("10M")) {
99             System.out.println("there");
100             speedObject = new Speed10MBuilder().build();
101         }
102         if (speed.equals("100M")) {
103             speedObject = new Speed100MBuilder().build();
104         }
105         if (speed.equals("1G")) {
106             speedObject = new Speed1GBuilder().build();
107         }
108         if (speed.equals("10G")) {
109             speedObject = new Speed10GBuilder().build();
110         }
111         System.out.println(speedObject);
112         return speedObject;
113     }
114
115     @Override
116     protected Object doExecute() throws Exception {
117         Uni uni = new UniBuilder()
118                         .setMacAddress(new MacAddress(macAddress))
119                         .setMacLayer(macLayer)
120                         .setMode(mode)
121                         .setMtuSize(BigInteger.valueOf(Long.valueOf(mtuSize)))
122                         .setPhysicalMedium(physicalMedium)
123                         .setSpeed((Speed) getSpeed())
124                         .setType(type)
125                         .setId(new NodeId(uniId))
126                         .build();
127
128         if (provider.addUni(uni)) {
129             return String.format("Uni created (id: %s)", uni.getId());
130         } else {
131             return new String("Error creating new uni");
132         }
133     }
134 }