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
9 package org.opendaylight.unimgr.cli;
12 import java.util.ArrayList;
13 import java.util.Iterator;
14 import java.util.List;
15 import java.util.ListIterator;
17 import org.apache.karaf.shell.commands.Command;
18 import org.apache.karaf.shell.commands.Option;
19 import org.apache.karaf.shell.console.OsgiCommandSupport;
20 import org.opendaylight.unimgr.api.IUnimgrConsoleProvider;
21 import org.opendaylight.unimgr.impl.UnimgrConstants;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentation;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentationBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.EgressBw;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.IngressBw;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDest;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDestBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDestKey;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSource;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSourceBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSourceKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed100MBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10GBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10MBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed1GBuilder;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
41 @Command(name = "evc-add",
43 description = "Add evc to the controller.")
45 public class EvcAddShellCommand extends OsgiCommandSupport {
47 private static final Logger LOG = LoggerFactory.getLogger(EvcAddShellCommand.class);
48 protected IUnimgrConsoleProvider provider;
50 @Option(name = "-IPs",
51 aliases = { "--IP-Address-source-uni" },
52 description = "The IP address of the source UNI.\n-IPs / --IP Address source uni",
55 private String IPs = "";
57 @Option(name = "-IPd",
58 aliases = { "--IP-Address-destenation-uni" },
59 description = "The IP address of the destenation UNI.\n-IPs / --IP Address destenation uni",
62 private String IPd = "";
64 @Option(name = "-egress",
65 aliases = { "--egress-speed" },
66 description = "egress speed.\n-s / --speed 10M/100M/1G/10G",
69 private String egress = "";
71 @Option(name = "-ingress",
72 aliases = { "--ingress-speed" },
73 description = "ingress speed.\n-s / --speed 10M/100M/1G/10G",
76 private String ingress = "";
78 private Object getSpeed(String speed) {
79 Object speedObject = null;
80 if (speed.equals("10M")) {
81 speedObject = new Speed10MBuilder().build();
83 else if (speed.equals("100M")) {
84 speedObject = new Speed100MBuilder().build();
86 else if (speed.equals("1G")) {
87 speedObject = new Speed1GBuilder().build();
89 else if (speed.equals("10G")) {
90 speedObject = new Speed10GBuilder().build();
95 public EvcAddShellCommand(IUnimgrConsoleProvider provider) {
96 this.provider = provider;
100 protected Object doExecute() throws Exception {
101 Short order = new Short("0");
102 IpAddress ipAddreSource = new IpAddress(IPs.toCharArray());
103 UniSource uniSource = new UniSourceBuilder()
104 .setIpAddress(ipAddreSource)
105 .setKey(new UniSourceKey(order))
108 List<UniSource> uniSourceList = new ArrayList<UniSource>();
109 uniSourceList.add(uniSource);
110 IpAddress ipAddreDest = new IpAddress(IPd.toCharArray());
111 UniDest uniDest = new UniDestBuilder()
113 .setKey(new UniDestKey(order))
114 .setIpAddress(ipAddreDest)
116 List<UniDest> uniDestList = new ArrayList<UniDest>();
117 uniDestList.add(uniDest);
118 EvcAugmentation evcAug = new EvcAugmentationBuilder()
119 .setCosId(UnimgrConstants.EVC_PREFIX + 1)
120 .setEgressBw((EgressBw) getSpeed(egress))
121 .setIngressBw((IngressBw) getSpeed(ingress))
122 .setUniDest(uniDestList)
123 .setUniSource(uniSourceList)
125 if (provider.addEvc(evcAug)) {
126 return new String("Evc with Source Uni " +IPs+" and destenation Uni " +IPd+" created");
128 return new String("Error creating new Evc");