Andreas Pantelopoulos | 5e7be3d | 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 | |
| 19 | import org.apache.karaf.shell.commands.Argument; |
| 20 | import org.apache.karaf.shell.commands.Command; |
| 21 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | import org.onosproject.segmentrouting.SegmentRoutingManager; |
| 23 | import org.onosproject.segmentrouting.SegmentRoutingService; |
| 24 | import org.onosproject.segmentrouting.pwaas.L2TunnelHandler; |
| 25 | |
Andreas Pantelopoulos | cdbb22c | 2018-02-23 14:18:00 -0800 | [diff] [blame] | 26 | import static org.onosproject.segmentrouting.pwaas.PwaasUtil.parsePwId; |
| 27 | |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Command to remove a pseudowire. |
| 31 | */ |
Andreas Pantelopoulos | fc4bc2a | 2018-03-12 16:30:20 -0700 | [diff] [blame] | 32 | @Command(scope = "onos", name = "sr-pw-remove", |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 33 | description = "Remove a pseudowire") |
| 34 | public 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 Pantelopoulos | cdbb22c | 2018-02-23 14:18:00 -0800 | [diff] [blame] | 49 | int pwIntId; |
| 50 | try { |
| 51 | pwIntId = parsePwId(pwId); |
Andreas Pantelopoulos | f172ef8 | 2018-04-10 19:34:47 -0700 | [diff] [blame] | 52 | } 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 Pantelopoulos | cdbb22c | 2018-02-23 14:18:00 -0800 | [diff] [blame] | 55 | return; |
| 56 | } |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 57 | |
Andreas Pantelopoulos | f172ef8 | 2018-04-10 19:34:47 -0700 | [diff] [blame] | 58 | log.info("Removing pseudowire {} from the command line.", pwIntId); |
Andreas Pantelopoulos | cdbb22c | 2018-02-23 14:18:00 -0800 | [diff] [blame] | 59 | L2TunnelHandler.Result res = mngr.removePseudowire(pwIntId); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 60 | switch (res) { |
Andreas Pantelopoulos | 9685125 | 2018-03-20 13:58:49 -0700 | [diff] [blame] | 61 | case WRONG_PARAMETERS: |
| 62 | error("Pseudowire could not be removed , wrong parameters: \n\t %s\n", |
| 63 | res.getSpecificError()); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 64 | break; |
Andreas Pantelopoulos | 9685125 | 2018-03-20 13:58:49 -0700 | [diff] [blame] | 65 | 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 Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 70 | break; |
| 71 | default: |
Andreas Pantelopoulos | afc637f | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 72 | break; |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | } |