blob: e26321474619483bb38d023e904ed7247a2d2a57 [file] [log] [blame]
Sean Condon96b896d2017-12-11 12:44:29 -08001/*
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 */
16package org.onosproject.cfm.cli;
17
Ray Milkey86ad7bb2018-09-27 12:32:28 -070018import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
Sean Condon96b896d2017-12-11 12:44:29 -080020import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.incubator.net.l2monitoring.cfm.Mep;
22import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
23import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService;
24import org.onosproject.net.DeviceId;
Sean Condon96b896d2017-12-11 12:44:29 -080025
26/**
27 * Lists all the MEPs on a particular device.
28 */
29@Command(scope = "onos", name = "cfm-mep-device-list",
30 description = "Lists a set of MEPs filtered by device.")
31public class CfmMepListDeviceCommand extends AbstractShellCommand {
Sean Condon3a1efef2018-02-24 13:16:03 +000032 @Argument(name = "device",
Sean Condon96b896d2017-12-11 12:44:29 -080033 description = "Device Id",
Sean Condon3a1efef2018-02-24 13:16:03 +000034 required = true)
35 private String deviceStr = null;
Sean Condon96b896d2017-12-11 12:44:29 -080036
37 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070038 protected void doExecute() {
Sean Condon96b896d2017-12-11 12:44:29 -080039 CfmMepService mepService = get(CfmMepService.class);
40 if (deviceStr != null) {
41 DeviceId deviceId = DeviceId.deviceId(deviceStr);
42 try {
Sean Condon3a1efef2018-02-24 13:16:03 +000043 mepService.getAllMepsByDevice(deviceId)
44 .forEach(mep -> print(printMep(mep)));
Sean Condon96b896d2017-12-11 12:44:29 -080045 } catch (CfmConfigException e) {
46 log.error("Error retrieving Meps for Device {}",
47 deviceId, e);
48 }
49 }
50 }
51
52 /**
53 * Print only the config part of the MEP.
54 * @param mep The MEP to print
55 * @return A string with MD name, MA name and Mep details
56 */
Sean Condon3a1efef2018-02-24 13:16:03 +000057 private static String printMep(Mep mep) {
58 return "MEP: " + mep.mdId().mdName() + "/" + mep.maId().maName() + "/" +
59 mep.mepId() + " Device:" + mep.deviceId() + ", Port: " +
60 mep.port() + ", Vlan: " + mep.primaryVid() + ", AdminSt: " +
61 mep.administrativeState() + ", CciEnabled: " + mep.cciEnabled() +
62 ", Priority: " + mep.ccmLtmPriority();
Sean Condon96b896d2017-12-11 12:44:29 -080063 }
64
65}