blob: 0f027b25962472d41f42af68d53765b6338a0692 [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 */
32@Command(scope = "onos", name = "pseudowire-remove",
33 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) {
59 case REMOVAL_ERROR:
60 error("Error in deletion, pseudowire not found!");
61 break;
62 case CONFIG_NOT_FOUND:
63 error("Could not fetch pseudowire class configuration!");
64 break;
65 default:
Andreas Pantelopoulosafc637f2017-12-20 18:04:27 -080066 break;
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070067 }
68 }
69}