blob: 362ebbbadafc8036428da5b8c46fc22e96c4bdc6 [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
19import org.apache.karaf.shell.commands.Argument;
20import org.apache.karaf.shell.commands.Command;
21import 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
42 protected void execute() {
43
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);
52 } catch (Exception e) {
53 print("Exception while parsing pseudowire id : {}", e);
54 return;
55 }
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070056
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -080057 L2TunnelHandler.Result res = mngr.removePseudowire(pwIntId);
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070058 switch (res) {
Andreas Pantelopoulos96851252018-03-20 13:58:49 -070059 case WRONG_PARAMETERS:
60 error("Pseudowire could not be removed , wrong parameters: \n\t %s\n",
61 res.getSpecificError());
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070062 break;
Andreas Pantelopoulos96851252018-03-20 13:58:49 -070063 case INTERNAL_ERROR:
64 error("Pseudowire could not be removed, internal error : \n\t %s\n",
65 res.getSpecificError());
66 break;
67 case SUCCESS:
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070068 break;
69 default:
Andreas Pantelopoulosafc637f2017-12-20 18:04:27 -080070 break;
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070071 }
72 }
73}