Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.segmentrouting.cli; |
| 17 | |
| 18 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 19 | import org.apache.karaf.shell.api.action.Argument; |
| 20 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | b52acf3 | 2018-10-05 10:17:34 -0700 | [diff] [blame] | 21 | import org.apache.karaf.shell.api.action.Completion; |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 22 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 23 | import org.onosproject.cli.AbstractShellCommand; |
| 24 | import org.onosproject.segmentrouting.SegmentRoutingManager; |
| 25 | import org.onosproject.segmentrouting.SegmentRoutingService; |
| 26 | import org.onosproject.segmentrouting.pwaas.L2TunnelHandler; |
| 27 | |
Andreas Pantelopoulos | cd33959 | 2018-02-23 14:18:00 -0800 | [diff] [blame] | 28 | import static org.onosproject.segmentrouting.pwaas.PwaasUtil.parsePwId; |
| 29 | |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Command to remove a pseudowire. |
| 33 | */ |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 34 | @Service |
Andreas Pantelopoulos | ff691b7 | 2018-03-12 16:30:20 -0700 | [diff] [blame] | 35 | @Command(scope = "onos", name = "sr-pw-remove", |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 36 | description = "Remove a pseudowire") |
| 37 | public class PseudowireRemoveCommand extends AbstractShellCommand { |
| 38 | |
| 39 | @Argument(index = 0, name = "pwId", |
| 40 | description = "pseudowire ID", |
| 41 | required = true, multiValued = false) |
Ray Milkey | b52acf3 | 2018-10-05 10:17:34 -0700 | [diff] [blame] | 42 | @Completion(PseudowireIdCompleter.class) |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 43 | String pwId; |
| 44 | |
| 45 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 46 | protected void doExecute() { |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 47 | |
| 48 | SegmentRoutingService srService = |
| 49 | AbstractShellCommand.get(SegmentRoutingService.class); |
| 50 | |
| 51 | // remove the pseudowire |
| 52 | SegmentRoutingManager mngr = (SegmentRoutingManager) srService; |
Andreas Pantelopoulos | cd33959 | 2018-02-23 14:18:00 -0800 | [diff] [blame] | 53 | int pwIntId; |
| 54 | try { |
| 55 | pwIntId = parsePwId(pwId); |
Andreas Pantelopoulos | 5bf1366 | 2018-04-10 19:34:47 -0700 | [diff] [blame] | 56 | } 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 Pantelopoulos | cd33959 | 2018-02-23 14:18:00 -0800 | [diff] [blame] | 59 | return; |
| 60 | } |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 61 | |
Andreas Pantelopoulos | 5bf1366 | 2018-04-10 19:34:47 -0700 | [diff] [blame] | 62 | log.info("Removing pseudowire {} from the command line.", pwIntId); |
Andreas Pantelopoulos | cd33959 | 2018-02-23 14:18:00 -0800 | [diff] [blame] | 63 | L2TunnelHandler.Result res = mngr.removePseudowire(pwIntId); |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 64 | switch (res) { |
Andreas Pantelopoulos | ffe6974 | 2018-03-20 13:58:49 -0700 | [diff] [blame] | 65 | case WRONG_PARAMETERS: |
| 66 | error("Pseudowire could not be removed , wrong parameters: \n\t %s\n", |
| 67 | res.getSpecificError()); |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 68 | break; |
Andreas Pantelopoulos | ffe6974 | 2018-03-20 13:58:49 -0700 | [diff] [blame] | 69 | 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 Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 74 | break; |
| 75 | default: |
Andreas Pantelopoulos | 20474e0 | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 76 | break; |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | } |