breezestars | df95f9f | 2016-09-16 15:35:25 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.vpls.cli; |
| 18 | |
| 19 | import com.google.common.collect.SetMultimap; |
| 20 | import com.google.common.collect.Sets; |
| 21 | import org.apache.karaf.shell.commands.Argument; |
| 22 | import org.apache.karaf.shell.commands.Command; |
| 23 | import org.onosproject.cli.AbstractShellCommand; |
| 24 | import org.onosproject.incubator.net.intf.Interface; |
| 25 | import org.onosproject.vpls.config.VplsConfigurationService; |
| 26 | |
| 27 | import java.util.Set; |
| 28 | |
| 29 | import 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") |
| 36 | public 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 | } |