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 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 18 | import org.apache.karaf.shell.api.action.Argument; |
| 19 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | c2b7b96 | 2018-10-02 15:00:02 -0700 | [diff] [blame^] | 20 | import org.apache.karaf.shell.api.action.Completion; |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 21 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Ray Milkey | c2b7b96 | 2018-10-02 15:00:02 -0700 | [diff] [blame^] | 22 | import org.onosproject.cfm.cli.completer.CfmDeviceIdCompleter; |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 23 | import org.onosproject.cli.AbstractShellCommand; |
| 24 | import org.onosproject.incubator.net.l2monitoring.cfm.Mep; |
| 25 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException; |
| 26 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService; |
| 27 | import org.onosproject.net.DeviceId; |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Lists all the MEPs on a particular device. |
| 31 | */ |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 32 | @Service |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 33 | @Command(scope = "onos", name = "cfm-mep-device-list", |
| 34 | description = "Lists a set of MEPs filtered by device.") |
| 35 | public class CfmMepListDeviceCommand extends AbstractShellCommand { |
Sean Condon | 3a1efef | 2018-02-24 13:16:03 +0000 | [diff] [blame] | 36 | @Argument(name = "device", |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 37 | description = "Device Id", |
Sean Condon | 3a1efef | 2018-02-24 13:16:03 +0000 | [diff] [blame] | 38 | required = true) |
Ray Milkey | c2b7b96 | 2018-10-02 15:00:02 -0700 | [diff] [blame^] | 39 | @Completion(CfmDeviceIdCompleter.class) |
Sean Condon | 3a1efef | 2018-02-24 13:16:03 +0000 | [diff] [blame] | 40 | private String deviceStr = null; |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 41 | |
| 42 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 43 | protected void doExecute() { |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 44 | CfmMepService mepService = get(CfmMepService.class); |
| 45 | if (deviceStr != null) { |
| 46 | DeviceId deviceId = DeviceId.deviceId(deviceStr); |
| 47 | try { |
Sean Condon | 3a1efef | 2018-02-24 13:16:03 +0000 | [diff] [blame] | 48 | mepService.getAllMepsByDevice(deviceId) |
| 49 | .forEach(mep -> print(printMep(mep))); |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 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 | */ |
Sean Condon | 3a1efef | 2018-02-24 13:16:03 +0000 | [diff] [blame] | 62 | private static String printMep(Mep mep) { |
| 63 | return "MEP: " + mep.mdId().mdName() + "/" + mep.maId().maName() + "/" + |
| 64 | mep.mepId() + " Device:" + mep.deviceId() + ", Port: " + |
| 65 | mep.port() + ", Vlan: " + mep.primaryVid() + ", AdminSt: " + |
| 66 | mep.administrativeState() + ", CciEnabled: " + mep.cciEnabled() + |
| 67 | ", Priority: " + mep.ccmLtmPriority(); |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | } |