Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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 | package org.onosproject.cfm.cli; |
| 17 | |
| 18 | import org.apache.karaf.shell.commands.Argument; |
| 19 | import org.apache.karaf.shell.commands.Command; |
| 20 | import org.onosproject.cli.AbstractShellCommand; |
| 21 | import org.onosproject.incubator.net.l2monitoring.cfm.Mep; |
| 22 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException; |
| 23 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService; |
| 24 | import org.onosproject.net.DeviceId; |
| 25 | import org.slf4j.Logger; |
| 26 | |
| 27 | import static org.slf4j.LoggerFactory.getLogger; |
| 28 | |
| 29 | /** |
| 30 | * Lists all the MEPs on a particular device. |
| 31 | */ |
| 32 | @Command(scope = "onos", name = "cfm-mep-device-list", |
| 33 | description = "Lists a set of MEPs filtered by device.") |
| 34 | public class CfmMepListDeviceCommand extends AbstractShellCommand { |
| 35 | private final Logger log = getLogger(getClass()); |
| 36 | @Argument(index = 0, name = "device", |
| 37 | description = "Device Id", |
| 38 | required = true, multiValued = false) |
| 39 | String deviceStr = null; |
| 40 | |
| 41 | @Override |
| 42 | protected void execute() { |
| 43 | CfmMepService mepService = get(CfmMepService.class); |
| 44 | if (deviceStr != null) { |
| 45 | DeviceId deviceId = DeviceId.deviceId(deviceStr); |
| 46 | try { |
| 47 | mepService.getAllMepsByDevice(deviceId).forEach(mep -> { |
| 48 | print(printMep(mep)); |
| 49 | }); |
| 50 | } catch (CfmConfigException e) { |
| 51 | log.error("Error retrieving Meps for Device {}", |
| 52 | deviceId, e); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Print only the config part of the MEP. |
| 59 | * @param mep The MEP to print |
| 60 | * @return A string with MD name, MA name and Mep details |
| 61 | */ |
| 62 | public static String printMep(Mep mep) { |
| 63 | StringBuffer sb = new StringBuffer("MEP: "); |
| 64 | sb.append(mep.mdId().mdName() + "/"); |
| 65 | sb.append(mep.maId().maName() + "/"); |
| 66 | sb.append(mep.mepId()); |
| 67 | sb.append(" Device:" + mep.deviceId()); |
| 68 | sb.append(", Port: " + mep.port()); |
| 69 | sb.append(", Vlan: " + mep.primaryVid()); |
| 70 | sb.append(", AdminSt: " + mep.administrativeState()); |
| 71 | sb.append(", CciEnabled: " + mep.cciEnabled()); |
| 72 | sb.append(", Priority: " + mep.ccmLtmPriority()); |
| 73 | |
| 74 | return sb.toString(); |
| 75 | } |
| 76 | |
| 77 | } |