blob: bdff1e8258c6e0299d7397a6a3a52a54ac3b649c [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 Milkeyc2b7b962018-10-02 15:00:02 -070020import org.apache.karaf.shell.api.action.Completion;
Ray Milkey7a2dee52018-09-28 10:58:28 -070021import org.apache.karaf.shell.api.action.lifecycle.Service;
Ray Milkeyc2b7b962018-10-02 15:00:02 -070022import org.onosproject.cfm.cli.completer.CfmDeviceIdCompleter;
Sean Condon96b896d2017-12-11 12:44:29 -080023import org.onosproject.cli.AbstractShellCommand;
24import org.onosproject.incubator.net.l2monitoring.cfm.Mep;
25import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
26import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService;
27import org.onosproject.net.DeviceId;
Sean Condon96b896d2017-12-11 12:44:29 -080028
29/**
30 * Lists all the MEPs on a particular device.
31 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070032@Service
Sean Condon96b896d2017-12-11 12:44:29 -080033@Command(scope = "onos", name = "cfm-mep-device-list",
34 description = "Lists a set of MEPs filtered by device.")
35public class CfmMepListDeviceCommand extends AbstractShellCommand {
Sean Condon3a1efef2018-02-24 13:16:03 +000036 @Argument(name = "device",
Sean Condon96b896d2017-12-11 12:44:29 -080037 description = "Device Id",
Sean Condon3a1efef2018-02-24 13:16:03 +000038 required = true)
Ray Milkeyc2b7b962018-10-02 15:00:02 -070039 @Completion(CfmDeviceIdCompleter.class)
Sean Condon3a1efef2018-02-24 13:16:03 +000040 private String deviceStr = null;
Sean Condon96b896d2017-12-11 12:44:29 -080041
42 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070043 protected void doExecute() {
Sean Condon96b896d2017-12-11 12:44:29 -080044 CfmMepService mepService = get(CfmMepService.class);
45 if (deviceStr != null) {
46 DeviceId deviceId = DeviceId.deviceId(deviceStr);
47 try {
Sean Condon3a1efef2018-02-24 13:16:03 +000048 mepService.getAllMepsByDevice(deviceId)
49 .forEach(mep -> print(printMep(mep)));
Sean Condon96b896d2017-12-11 12:44:29 -080050 } 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 Condon3a1efef2018-02-24 13:16:03 +000062 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 Condon96b896d2017-12-11 12:44:29 -080068 }
69
70}