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 | |
breezestars | df95f9f | 2016-09-16 15:35:25 -0700 | [diff] [blame] | 19 | import org.apache.karaf.shell.commands.Argument; |
| 20 | import org.apache.karaf.shell.commands.Command; |
| 21 | import org.onosproject.cli.AbstractShellCommand; |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 22 | import org.onosproject.net.EncapsulationType; |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 23 | import org.onosproject.vpls.config.VplsConfigService; |
breezestars | df95f9f | 2016-09-16 15:35:25 -0700 | [diff] [blame] | 24 | |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 25 | import java.util.Map; |
breezestars | df95f9f | 2016-09-16 15:35:25 -0700 | [diff] [blame] | 26 | import java.util.Set; |
| 27 | |
| 28 | import 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") |
| 35 | public class VplsShowCommand extends AbstractShellCommand { |
| 36 | |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 37 | private VplsConfigService vplsConfigService = |
| 38 | get(VplsConfigService.class); |
breezestars | df95f9f | 2016-09-16 15:35:25 -0700 | [diff] [blame] | 39 | |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 40 | @Argument(index = 0, name = "vplsName", description = "Name of the VPLS", |
breezestars | df95f9f | 2016-09-16 15:35:25 -0700 | [diff] [blame] | 41 | required = false, multiValued = false) |
| 42 | private String vplsName = null; |
| 43 | |
| 44 | @Override |
| 45 | protected void execute() { |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 46 | Set<String> vplsNames = vplsConfigService.vplsNames(); |
| 47 | Map<String, EncapsulationType> encapByVplsName = |
| 48 | vplsConfigService.encapByVplsName(); |
breezestars | df95f9f | 2016-09-16 15:35:25 -0700 | [diff] [blame] | 49 | |
| 50 | if (!isNullOrEmpty(vplsName)) { |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 51 | // 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()); |
breezestars | df95f9f | 2016-09-16 15:35:25 -0700 | [diff] [blame] | 57 | } else { |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 58 | print(VplsCommandUtils.VPLS_NOT_FOUND, vplsName); |
breezestars | df95f9f | 2016-09-16 15:35:25 -0700 | [diff] [blame] | 59 | } |
| 60 | } else { |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 61 | // No VPLS names are provided. Display all VPLSs configured |
breezestars | df95f9f | 2016-09-16 15:35:25 -0700 | [diff] [blame] | 62 | vplsNames.forEach(vplsName -> { |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 63 | print(VplsCommandUtils.VPLS_DISPLAY, |
| 64 | vplsName, |
| 65 | VplsCommandUtils.ifacesFromVplsName(vplsName).toString(), |
| 66 | encapByVplsName.get(vplsName).toString()); |
breezestars | df95f9f | 2016-09-16 15:35:25 -0700 | [diff] [blame] | 67 | }); |
| 68 | } |
| 69 | } |
| 70 | } |