blob: ca60a1c02c9487d14c9e7170f66485d4d6e2fbc5 [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;
Ray Milkey7a2dee52018-09-28 10:58:28 -070020import org.apache.karaf.shell.api.action.lifecycle.Service;
Sean Condon96b896d2017-12-11 12:44:29 -080021import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.incubator.net.l2monitoring.cfm.Mep;
23import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
24import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService;
25import org.onosproject.net.DeviceId;
Sean Condon96b896d2017-12-11 12:44:29 -080026
27/**
28 * Lists all the MEPs on a particular device.
29 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070030@Service
Sean Condon96b896d2017-12-11 12:44:29 -080031@Command(scope = "onos", name = "cfm-mep-device-list",
32 description = "Lists a set of MEPs filtered by device.")
33public class CfmMepListDeviceCommand extends AbstractShellCommand {
Sean Condon3a1efef2018-02-24 13:16:03 +000034 @Argument(name = "device",
Sean Condon96b896d2017-12-11 12:44:29 -080035 description = "Device Id",
Sean Condon3a1efef2018-02-24 13:16:03 +000036 required = true)
37 private String deviceStr = null;
Sean Condon96b896d2017-12-11 12:44:29 -080038
39 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070040 protected void doExecute() {
Sean Condon96b896d2017-12-11 12:44:29 -080041 CfmMepService mepService = get(CfmMepService.class);
42 if (deviceStr != null) {
43 DeviceId deviceId = DeviceId.deviceId(deviceStr);
44 try {
Sean Condon3a1efef2018-02-24 13:16:03 +000045 mepService.getAllMepsByDevice(deviceId)
46 .forEach(mep -> print(printMep(mep)));
Sean Condon96b896d2017-12-11 12:44:29 -080047 } catch (CfmConfigException e) {
48 log.error("Error retrieving Meps for Device {}",
49 deviceId, e);
50 }
51 }
52 }
53
54 /**
55 * Print only the config part of the MEP.
56 * @param mep The MEP to print
57 * @return A string with MD name, MA name and Mep details
58 */
Sean Condon3a1efef2018-02-24 13:16:03 +000059 private static String printMep(Mep mep) {
60 return "MEP: " + mep.mdId().mdName() + "/" + mep.maId().maName() + "/" +
61 mep.mepId() + " Device:" + mep.deviceId() + ", Port: " +
62 mep.port() + ", Vlan: " + mep.primaryVid() + ", AdminSt: " +
63 mep.administrativeState() + ", CciEnabled: " + mep.cciEnabled() +
64 ", Priority: " + mep.ccmLtmPriority();
Sean Condon96b896d2017-12-11 12:44:29 -080065 }
66
67}