blob: fbd54b56f1c29b7c23838b4bfd2b0742f63e7449 [file] [log] [blame]
breezestarsdf95f9f2016-09-16 15:35:25 -07001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.vpls.cli;
18
breezestarsdf95f9f2016-09-16 15:35:25 -070019import org.apache.karaf.shell.commands.Argument;
20import org.apache.karaf.shell.commands.Command;
21import org.onosproject.cli.AbstractShellCommand;
Luca Prete092e8952016-10-26 16:25:56 +020022import org.onosproject.net.EncapsulationType;
Carolina Fernandezb1cef5c2016-11-22 19:18:40 +010023import org.onosproject.vpls.config.VplsConfigService;
breezestarsdf95f9f2016-09-16 15:35:25 -070024
Luca Prete092e8952016-10-26 16:25:56 +020025import java.util.Map;
breezestarsdf95f9f2016-09-16 15:35:25 -070026import java.util.Set;
27
28import static com.google.common.base.Strings.isNullOrEmpty;
29
30/**
31 * CLI to show VPLS details.
32 */
33@Command(scope = "onos", name = "vpls-show",
34 description = "Shows the details of an existing VPLS")
35public class VplsShowCommand extends AbstractShellCommand {
36
Carolina Fernandezb1cef5c2016-11-22 19:18:40 +010037 private VplsConfigService vplsConfigService =
38 get(VplsConfigService.class);
breezestarsdf95f9f2016-09-16 15:35:25 -070039
Luca Prete092e8952016-10-26 16:25:56 +020040 @Argument(index = 0, name = "vplsName", description = "Name of the VPLS",
breezestarsdf95f9f2016-09-16 15:35:25 -070041 required = false, multiValued = false)
42 private String vplsName = null;
43
44 @Override
45 protected void execute() {
Luca Prete092e8952016-10-26 16:25:56 +020046 Set<String> vplsNames = vplsConfigService.vplsNames();
47 Map<String, EncapsulationType> encapByVplsName =
48 vplsConfigService.encapByVplsName();
breezestarsdf95f9f2016-09-16 15:35:25 -070049
50 if (!isNullOrEmpty(vplsName)) {
Luca Prete092e8952016-10-26 16:25:56 +020051 // A VPLS name is provided. Check first if the VPLS exists
52 if (VplsCommandUtils.vplsExists(vplsName)) {
53 print(VplsCommandUtils.VPLS_DISPLAY,
54 vplsName,
55 VplsCommandUtils.ifacesFromVplsName(vplsName).toString(),
56 encapByVplsName.get(vplsName).toString());
breezestarsdf95f9f2016-09-16 15:35:25 -070057 } else {
Luca Prete092e8952016-10-26 16:25:56 +020058 print(VplsCommandUtils.VPLS_NOT_FOUND, vplsName);
breezestarsdf95f9f2016-09-16 15:35:25 -070059 }
60 } else {
Luca Prete092e8952016-10-26 16:25:56 +020061 // No VPLS names are provided. Display all VPLSs configured
breezestarsdf95f9f2016-09-16 15:35:25 -070062 vplsNames.forEach(vplsName -> {
Luca Prete092e8952016-10-26 16:25:56 +020063 print(VplsCommandUtils.VPLS_DISPLAY,
64 vplsName,
65 VplsCommandUtils.ifacesFromVplsName(vplsName).toString(),
66 encapByVplsName.get(vplsName).toString());
breezestarsdf95f9f2016-09-16 15:35:25 -070067 });
68 }
69 }
70}