blob: f7c130fa8e36c926481f425db92b2d9d1c928c10 [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.MepEntry;
23import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort;
24import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId;
25import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
26import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepKeyId;
27import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
28import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService;
29import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService;
30import org.slf4j.Logger;
31
32import static org.onosproject.cfm.cli.CfmMdListMdCommand.parseMaName;
33import static org.onosproject.cfm.cli.CfmMdListMdCommand.parseMdName;
34import static org.slf4j.LoggerFactory.getLogger;
35
36/**
37 * Lists a particular Maintenance Domain.
38 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070039@Service
Sean Condon96b896d2017-12-11 12:44:29 -080040@Command(scope = "onos", name = "cfm-mep-list",
41 description = "Lists a filtered set of MEPs or all if no parameters specified.")
42public class CfmMepListCommand extends AbstractShellCommand {
43 private final Logger log = getLogger(getClass());
Sean Condon3a1efef2018-02-24 13:16:03 +000044 @Argument(name = "md",
45 description = "Maintenance Domain name and type (in brackets) - will use all MDs if not specified")
46 private String mdStr = null;
Sean Condon96b896d2017-12-11 12:44:29 -080047 @Argument(index = 1, name = "ma",
Sean Condon3a1efef2018-02-24 13:16:03 +000048 description = "Maintenance Association name and type (in brackets) - requires MD")
49 private String maStr = null;
Sean Condon96b896d2017-12-11 12:44:29 -080050 @Argument(index = 2, name = "mep",
Sean Condon3a1efef2018-02-24 13:16:03 +000051 description = "MEP identifier - requires MD and MA")
52 private String mepStr = null;
Sean Condon96b896d2017-12-11 12:44:29 -080053
54 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070055 protected void doExecute() {
Sean Condon96b896d2017-12-11 12:44:29 -080056 CfmMepService mepService = get(CfmMepService.class);
57 CfmMdService mdService = get(CfmMdService.class);
58
59 if (mdStr != null && !mdStr.isEmpty()) {
60
61
62 MdId mdId = parseMdName(mdStr);
63 print(printMdId(mdId));
64
65 if (maStr != null && !maStr.isEmpty()) {
66 MaIdShort maId = parseMaName(maStr);
67 print(printMaId(maId));
68
69 if (mepStr != null && !mepStr.isEmpty()) {
70 MepId mepId = MepId.valueOf(Short.parseShort(mepStr));
71 try {
72 MepEntry mep = mepService.getMep(mdId, maId, mepId);
73 if (mep != null) {
74 print(printMepEntry(mep));
75 }
76 } catch (CfmConfigException e) {
77 log.error("Error retrieving Mep details {}",
78 new MepKeyId(mdId, maId, mepId), e);
79 }
80
81 //MD, MA and MEP given
82 } else {
83 //MD and MA given but no MEP given
84 try {
Sean Condon3a1efef2018-02-24 13:16:03 +000085 mepService.getAllMeps(mdId, maId)
86 .forEach(mep -> print(printMepEntry(mep)));
Sean Condon96b896d2017-12-11 12:44:29 -080087 } catch (CfmConfigException e) {
88 log.error("Error retrieving Meps for {}/{}",
89 mdId.mdName(), maId.maName(), e);
90 }
91 }
92 } else {
93 //MD given but no MA given
94 mdService.getAllMaintenanceAssociation(mdId).forEach(ma -> {
95 print(printMaId(ma.maId()));
96 try {
Sean Condon3a1efef2018-02-24 13:16:03 +000097 mepService.getAllMeps(mdId, ma.maId())
98 .forEach(mep -> print(printMepEntry(mep)));
Sean Condon96b896d2017-12-11 12:44:29 -080099 } catch (CfmConfigException e) {
100 log.error("Error retrieving Meps for {}/{}",
101 mdId.mdName(), ma.maId().maName(), e);
102 }
103 });
104
105 }
106 } else {
107 mdService.getAllMaintenanceDomain().forEach(md -> {
108 print(printMdId(md.mdId()));
109
110 mdService.getAllMaintenanceAssociation(md.mdId()).forEach(ma -> {
111 print(printMaId(ma.maId()));
112 try {
Sean Condon3a1efef2018-02-24 13:16:03 +0000113 mepService.getAllMeps(md.mdId(), ma.maId())
114 .forEach(mep -> print(printMepEntry(mep)));
Sean Condon96b896d2017-12-11 12:44:29 -0800115 } catch (CfmConfigException e) {
116 log.error("Error retrieving Meps for {}/{}",
117 md.mdId().mdName(), ma.maId().maName(), e);
118 }
119 });
120 });
121 }
122 }
123
124 /**
125 * Print the whole MEP Entry (config and status).
126 * @param mep The MEPEntry to print
127 * @return A string with MepEntry details
128 */
Sean Condon3a1efef2018-02-24 13:16:03 +0000129 private static String printMepEntry(MepEntry mep) {
Sean Condon96b896d2017-12-11 12:44:29 -0800130 StringBuffer sb = new StringBuffer("MEP: ");
131 sb.append(mep.mepId());
Sean Condon3a1efef2018-02-24 13:16:03 +0000132 sb.append(" Device:");
133 sb.append(mep.deviceId());
134 sb.append(", Port: ");
135 sb.append(mep.port());
136 sb.append(", Vlan: ");
137 sb.append(mep.primaryVid());
138 sb.append(", AdminSt: ");
139 sb.append(mep.administrativeState());
140 sb.append(", CciEnabled: ");
141 sb.append(mep.cciEnabled());
142 sb.append(", Priority: ");
143 sb.append(mep.ccmLtmPriority());
Sean Condon96b896d2017-12-11 12:44:29 -0800144 sb.append("\n"); //The following are state
Sean Condon3a1efef2018-02-24 13:16:03 +0000145 sb.append(", Total CCMs: ");
146 sb.append(mep.totalCcmsTransmitted());
147 sb.append(", MAC: ");
148 sb.append(mep.macAddress());
149 sb.append(", Fault: ");
150 sb.append(mep.fngState());
Sean Condon96b896d2017-12-11 12:44:29 -0800151
152 mep.activeRemoteMepList().forEach(rmep -> {
Sean Condon3a1efef2018-02-24 13:16:03 +0000153 sb.append("\n\tRmep: ");
154 sb.append(rmep.remoteMepId());
155 sb.append(", Mac: ");
156 sb.append(rmep.macAddress());
157 sb.append(", State: ");
158 sb.append(rmep.state());
159 sb.append(", Failed Time: ");
160 sb.append(rmep.failedOrOkTime());
Sean Condon96b896d2017-12-11 12:44:29 -0800161
162 });
163
164
165 return sb.toString();
166 }
167
Sean Condon3a1efef2018-02-24 13:16:03 +0000168 private static String printMdId(MdId mdId) {
169 return "MD: " + mdId.mdName() + "(" + mdId.nameType() + ")";
Sean Condon96b896d2017-12-11 12:44:29 -0800170 }
171
Sean Condon3a1efef2018-02-24 13:16:03 +0000172 private static String printMaId(MaIdShort maId) {
173 return "MA: " + maId.maName() + "(" + maId.nameType() + ")";
Sean Condon96b896d2017-12-11 12:44:29 -0800174 }
175
176}