blob: 2bb28b06f8dffab87f85ea868a89101c2e3af394 [file] [log] [blame]
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -07001/*
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.segmentrouting.cli;
17
18
Ray Milkeydb38bc82018-09-27 12:32:28 -070019import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
Ray Milkey5105ec32018-10-05 10:17:34 -070021import org.apache.karaf.shell.api.action.Completion;
Ray Milkey52ca4e92018-09-28 10:58:28 -070022import org.apache.karaf.shell.api.action.lifecycle.Service;
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070023import org.onosproject.cli.AbstractShellCommand;
24import org.onosproject.segmentrouting.SegmentRoutingManager;
25import org.onosproject.segmentrouting.SegmentRoutingService;
26import org.onosproject.segmentrouting.pwaas.L2TunnelHandler;
27
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -080028import static org.onosproject.segmentrouting.pwaas.PwaasUtil.parsePwId;
29
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070030
31/**
32 * Command to remove a pseudowire.
33 */
Ray Milkey52ca4e92018-09-28 10:58:28 -070034@Service
Andreas Pantelopoulosfc4bc2a2018-03-12 16:30:20 -070035@Command(scope = "onos", name = "sr-pw-remove",
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070036 description = "Remove a pseudowire")
37public class PseudowireRemoveCommand extends AbstractShellCommand {
38
39 @Argument(index = 0, name = "pwId",
40 description = "pseudowire ID",
41 required = true, multiValued = false)
Ray Milkey5105ec32018-10-05 10:17:34 -070042 @Completion(PseudowireIdCompleter.class)
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070043 String pwId;
44
45 @Override
Ray Milkeydb38bc82018-09-27 12:32:28 -070046 protected void doExecute() {
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070047
48 SegmentRoutingService srService =
49 AbstractShellCommand.get(SegmentRoutingService.class);
50
51 // remove the pseudowire
52 SegmentRoutingManager mngr = (SegmentRoutingManager) srService;
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -080053 int pwIntId;
54 try {
55 pwIntId = parsePwId(pwId);
Andreas Pantelopoulosf172ef82018-04-10 19:34:47 -070056 } catch (IllegalArgumentException e) {
57 log.error("Exception while parsing pseudowire id : \n\t %s", e.getMessage());
58 print("Exception while parsing pseudowire id : \n\t %s", e.getMessage());
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -080059 return;
60 }
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070061
Andreas Pantelopoulosf172ef82018-04-10 19:34:47 -070062 log.info("Removing pseudowire {} from the command line.", pwIntId);
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -080063 L2TunnelHandler.Result res = mngr.removePseudowire(pwIntId);
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070064 switch (res) {
Andreas Pantelopoulos96851252018-03-20 13:58:49 -070065 case WRONG_PARAMETERS:
66 error("Pseudowire could not be removed , wrong parameters: \n\t %s\n",
67 res.getSpecificError());
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070068 break;
Andreas Pantelopoulos96851252018-03-20 13:58:49 -070069 case INTERNAL_ERROR:
70 error("Pseudowire could not be removed, internal error : \n\t %s\n",
71 res.getSpecificError());
72 break;
73 case SUCCESS:
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070074 break;
75 default:
Andreas Pantelopoulosafc637f2017-12-20 18:04:27 -080076 break;
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070077 }
78 }
79}