blob: 550d122d18f8e6f1056d582ecf7353e20d44abbf [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
19import com.google.common.collect.SetMultimap;
20import com.google.common.collect.Sets;
21import org.apache.karaf.shell.commands.Argument;
22import org.apache.karaf.shell.commands.Command;
23import org.onosproject.cli.AbstractShellCommand;
24import org.onosproject.incubator.net.intf.Interface;
25import org.onosproject.vpls.config.VplsConfigurationService;
26
27import java.util.Set;
28
29import static com.google.common.base.Strings.isNullOrEmpty;
30
31/**
32 * CLI to show VPLS details.
33 */
34@Command(scope = "onos", name = "vpls-show",
35 description = "Shows the details of an existing VPLS")
36public class VplsShowCommand extends AbstractShellCommand {
37
38 private static final String NAME_FORMAT = "%10s: interface=%s";
39 private static final String NETWORK_NOT_FOUND =
40 "VPLS with name \'%s\' not found";
41 private VplsConfigurationService vplsConfigService =
42 get(VplsConfigurationService.class);
43
44 @Argument(index = 0, name = "NETWORK_NAME", description = "Name of the VPLS",
45 required = false, multiValued = false)
46 private String vplsName = null;
47
48 @Override
49 protected void execute() {
50 Set<String> vplsNames = vplsConfigService.getAllVpls();
51 SetMultimap<String, Interface> vplsNetowrks = vplsConfigService.getVplsNetworks();
52 Set<String> ifaceNames = Sets.newHashSet();
53
54
55 if (!isNullOrEmpty(vplsName)) {
56
57 if (vplsNames.contains(vplsName)) {
58 vplsNetowrks.get(vplsName).stream()
59 .map(Interface::name)
60 .forEach(ifaceNames::add);
61 print(NAME_FORMAT, vplsName, ifaceNames);
62 } else {
63 print(NETWORK_NOT_FOUND, vplsName);
64 }
65 } else {
66 vplsNames.forEach(vplsName -> {
67 ifaceNames.clear();
68 vplsNetowrks.get(vplsName).stream()
69 .map(Interface::name)
70 .forEach(ifaceNames::add);
71 print(NAME_FORMAT, vplsName, ifaceNames);
72 });
73 }
74 }
75}