blob: a166a39339f2c6f1810cdb76736b5e4b39456481 [file] [log] [blame]
Sean Condon0e89bda2017-03-21 14:23:19 +00001/*
2 * Copyright 2017-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.Command;
19import org.apache.karaf.shell.api.action.Argument;
Sean Condon0e89bda2017-03-21 14:23:19 +000020import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceDomain;
22import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain;
23import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId;
Sean Condon0e89bda2017-03-21 14:23:19 +000024import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
25import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService;
26
Sean Condon0e89bda2017-03-21 14:23:19 +000027/**
28 * Adds a Maintenance Domain to the existing list.
29 */
30@Command(scope = "onos", name = "cfm-md-add",
31 description = "Add a CFM Maintenance Domain.")
32public class CfmMdAddCommand extends AbstractShellCommand {
33
Sean Condon3a1efef2018-02-24 13:16:03 +000034 @Argument(name = "name-type",
Sean Condon0e89bda2017-03-21 14:23:19 +000035 description = "Maintenance Domain name type",
Sean Condon3a1efef2018-02-24 13:16:03 +000036 required = true)
37 private String nameType = null;
Sean Condon0e89bda2017-03-21 14:23:19 +000038
39 @Argument(index = 1, name = "name",
40 description = "Maintenance Domain name. Restrictions apply depending " +
41 "on name-type. Leave empty if name type is none",
Sean Condon3a1efef2018-02-24 13:16:03 +000042 required = true)
43 private String name = null;
Sean Condon0e89bda2017-03-21 14:23:19 +000044
45 @Argument(index = 2, name = "level",
46 description = "Maintenance Domain level LEVEL0-LEVEL7",
Sean Condon3a1efef2018-02-24 13:16:03 +000047 required = true)
48 private String level = null;
Sean Condon0e89bda2017-03-21 14:23:19 +000049
50 @Argument(index = 3, name = "numeric-id",
Sean Condon3a1efef2018-02-24 13:16:03 +000051 description = "An optional numeric id for Maintenance Domain [1-65535]")
52 private Short numericId = null;
Sean Condon0e89bda2017-03-21 14:23:19 +000053
54 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070055 protected void doExecute() {
Sean Condon0e89bda2017-03-21 14:23:19 +000056 CfmMdService service = get(CfmMdService.class);
Sean Condon3a1efef2018-02-24 13:16:03 +000057 MdId mdId = CfmMdListMdCommand.parseMdName(name + "(" + nameType + ")");
58
Sean Condon0e89bda2017-03-21 14:23:19 +000059 MaintenanceDomain.MdLevel levelEnum =
60 MaintenanceDomain.MdLevel.valueOf(level);
Sean Condon0e89bda2017-03-21 14:23:19 +000061
Sean Condon0e89bda2017-03-21 14:23:19 +000062 try {
Sean Condon3a1efef2018-02-24 13:16:03 +000063 MaintenanceDomain.MdBuilder builder = DefaultMaintenanceDomain
64 .builder(mdId).mdLevel(levelEnum);
65 if (numericId != null) {
66 builder = builder.mdNumericId(numericId);
Sean Condon0e89bda2017-03-21 14:23:19 +000067 }
68 boolean created = service.createMaintenanceDomain(builder.build());
69 print("Maintenance Domain with id %s is successfully %s.",
70 mdId, created ? "updated" : "created");
71 } catch (CfmConfigException e) {
72 throw new IllegalArgumentException(e);
73 }
74 }
75}