blob: 2b5a2bff8ed63614bb417d351d3d92ce54763e00 [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;
Ray Milkey7a2dee52018-09-28 10:58:28 -070020import org.apache.karaf.shell.api.action.lifecycle.Service;
Sean Condon0e89bda2017-03-21 14:23:19 +000021import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceDomain;
23import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain;
24import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId;
Sean Condon0e89bda2017-03-21 14:23:19 +000025import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
26import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService;
27
Sean Condon0e89bda2017-03-21 14:23:19 +000028/**
29 * Adds a Maintenance Domain to the existing list.
30 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070031@Service
Sean Condon0e89bda2017-03-21 14:23:19 +000032@Command(scope = "onos", name = "cfm-md-add",
33 description = "Add a CFM Maintenance Domain.")
34public class CfmMdAddCommand extends AbstractShellCommand {
35
Sean Condon3a1efef2018-02-24 13:16:03 +000036 @Argument(name = "name-type",
Sean Condon0e89bda2017-03-21 14:23:19 +000037 description = "Maintenance Domain name type",
Sean Condon3a1efef2018-02-24 13:16:03 +000038 required = true)
39 private String nameType = null;
Sean Condon0e89bda2017-03-21 14:23:19 +000040
41 @Argument(index = 1, name = "name",
42 description = "Maintenance Domain name. Restrictions apply depending " +
43 "on name-type. Leave empty if name type is none",
Sean Condon3a1efef2018-02-24 13:16:03 +000044 required = true)
45 private String name = null;
Sean Condon0e89bda2017-03-21 14:23:19 +000046
47 @Argument(index = 2, name = "level",
48 description = "Maintenance Domain level LEVEL0-LEVEL7",
Sean Condon3a1efef2018-02-24 13:16:03 +000049 required = true)
50 private String level = null;
Sean Condon0e89bda2017-03-21 14:23:19 +000051
52 @Argument(index = 3, name = "numeric-id",
Sean Condon3a1efef2018-02-24 13:16:03 +000053 description = "An optional numeric id for Maintenance Domain [1-65535]")
54 private Short numericId = null;
Sean Condon0e89bda2017-03-21 14:23:19 +000055
56 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070057 protected void doExecute() {
Sean Condon0e89bda2017-03-21 14:23:19 +000058 CfmMdService service = get(CfmMdService.class);
Sean Condon3a1efef2018-02-24 13:16:03 +000059 MdId mdId = CfmMdListMdCommand.parseMdName(name + "(" + nameType + ")");
60
Sean Condon0e89bda2017-03-21 14:23:19 +000061 MaintenanceDomain.MdLevel levelEnum =
62 MaintenanceDomain.MdLevel.valueOf(level);
Sean Condon0e89bda2017-03-21 14:23:19 +000063
Sean Condon0e89bda2017-03-21 14:23:19 +000064 try {
Sean Condon3a1efef2018-02-24 13:16:03 +000065 MaintenanceDomain.MdBuilder builder = DefaultMaintenanceDomain
66 .builder(mdId).mdLevel(levelEnum);
67 if (numericId != null) {
68 builder = builder.mdNumericId(numericId);
Sean Condon0e89bda2017-03-21 14:23:19 +000069 }
70 boolean created = service.createMaintenanceDomain(builder.build());
71 print("Maintenance Domain with id %s is successfully %s.",
72 mdId, created ? "updated" : "created");
73 } catch (CfmConfigException e) {
74 throw new IllegalArgumentException(e);
75 }
76 }
77}