blob: fb1705c0188498b2bceab03e16c11f8264320788 [file] [log] [blame]
Andreas Pantelopoulos27532cd2017-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 Milkey86ad7bb2018-09-27 12:32:28 -070019import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
Ray Milkey7a2dee52018-09-28 10:58:28 -070021import org.apache.karaf.shell.api.action.lifecycle.Service;
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070022import org.onosproject.cli.AbstractShellCommand;
23import org.onosproject.segmentrouting.SegmentRoutingManager;
24import org.onosproject.segmentrouting.SegmentRoutingService;
25import org.onosproject.segmentrouting.pwaas.L2TunnelHandler;
26
Andreas Pantelopouloscd339592018-02-23 14:18:00 -080027import static org.onosproject.segmentrouting.pwaas.PwaasUtil.parsePwId;
28
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070029
30/**
31 * Command to remove a pseudowire.
32 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070033@Service
Andreas Pantelopoulosff691b72018-03-12 16:30:20 -070034@Command(scope = "onos", name = "sr-pw-remove",
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070035 description = "Remove a pseudowire")
36public class PseudowireRemoveCommand extends AbstractShellCommand {
37
38 @Argument(index = 0, name = "pwId",
39 description = "pseudowire ID",
40 required = true, multiValued = false)
41 String pwId;
42
43 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070044 protected void doExecute() {
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070045
46 SegmentRoutingService srService =
47 AbstractShellCommand.get(SegmentRoutingService.class);
48
49 // remove the pseudowire
50 SegmentRoutingManager mngr = (SegmentRoutingManager) srService;
Andreas Pantelopouloscd339592018-02-23 14:18:00 -080051 int pwIntId;
52 try {
53 pwIntId = parsePwId(pwId);
Andreas Pantelopoulos5bf13662018-04-10 19:34:47 -070054 } catch (IllegalArgumentException e) {
55 log.error("Exception while parsing pseudowire id : \n\t %s", e.getMessage());
56 print("Exception while parsing pseudowire id : \n\t %s", e.getMessage());
Andreas Pantelopouloscd339592018-02-23 14:18:00 -080057 return;
58 }
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070059
Andreas Pantelopoulos5bf13662018-04-10 19:34:47 -070060 log.info("Removing pseudowire {} from the command line.", pwIntId);
Andreas Pantelopouloscd339592018-02-23 14:18:00 -080061 L2TunnelHandler.Result res = mngr.removePseudowire(pwIntId);
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070062 switch (res) {
Andreas Pantelopoulosffe69742018-03-20 13:58:49 -070063 case WRONG_PARAMETERS:
64 error("Pseudowire could not be removed , wrong parameters: \n\t %s\n",
65 res.getSpecificError());
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070066 break;
Andreas Pantelopoulosffe69742018-03-20 13:58:49 -070067 case INTERNAL_ERROR:
68 error("Pseudowire could not be removed, internal error : \n\t %s\n",
69 res.getSpecificError());
70 break;
71 case SUCCESS:
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070072 break;
73 default:
Andreas Pantelopoulos20474e02017-12-20 18:04:27 -080074 break;
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070075 }
76 }
77}