blob: 8be0dad7e756678bd43f99e30950eb14b1a2b33e [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;
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070021import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.segmentrouting.SegmentRoutingManager;
23import org.onosproject.segmentrouting.SegmentRoutingService;
24import org.onosproject.segmentrouting.pwaas.L2TunnelHandler;
25
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -080026import static org.onosproject.segmentrouting.pwaas.PwaasUtil.parsePwId;
27
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070028
29/**
30 * Command to remove a pseudowire.
31 */
Andreas Pantelopoulosfc4bc2a2018-03-12 16:30:20 -070032@Command(scope = "onos", name = "sr-pw-remove",
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070033 description = "Remove a pseudowire")
34public class PseudowireRemoveCommand extends AbstractShellCommand {
35
36 @Argument(index = 0, name = "pwId",
37 description = "pseudowire ID",
38 required = true, multiValued = false)
39 String pwId;
40
41 @Override
Ray Milkeydb38bc82018-09-27 12:32:28 -070042 protected void doExecute() {
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070043
44 SegmentRoutingService srService =
45 AbstractShellCommand.get(SegmentRoutingService.class);
46
47 // remove the pseudowire
48 SegmentRoutingManager mngr = (SegmentRoutingManager) srService;
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -080049 int pwIntId;
50 try {
51 pwIntId = parsePwId(pwId);
Andreas Pantelopoulosf172ef82018-04-10 19:34:47 -070052 } catch (IllegalArgumentException e) {
53 log.error("Exception while parsing pseudowire id : \n\t %s", e.getMessage());
54 print("Exception while parsing pseudowire id : \n\t %s", e.getMessage());
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -080055 return;
56 }
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070057
Andreas Pantelopoulosf172ef82018-04-10 19:34:47 -070058 log.info("Removing pseudowire {} from the command line.", pwIntId);
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -080059 L2TunnelHandler.Result res = mngr.removePseudowire(pwIntId);
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070060 switch (res) {
Andreas Pantelopoulos96851252018-03-20 13:58:49 -070061 case WRONG_PARAMETERS:
62 error("Pseudowire could not be removed , wrong parameters: \n\t %s\n",
63 res.getSpecificError());
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070064 break;
Andreas Pantelopoulos96851252018-03-20 13:58:49 -070065 case INTERNAL_ERROR:
66 error("Pseudowire could not be removed, internal error : \n\t %s\n",
67 res.getSpecificError());
68 break;
69 case SUCCESS:
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070070 break;
71 default:
Andreas Pantelopoulosafc637f2017-12-20 18:04:27 -080072 break;
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070073 }
74 }
75}