sangho | 316d438 | 2015-06-24 09:37:40 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 43b5354 | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
sangho | 316d438 | 2015-06-24 09:37:40 -0700 | [diff] [blame] | 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 com.google.common.collect.Lists; |
| 20 | import org.apache.karaf.shell.commands.Argument; |
| 21 | import org.apache.karaf.shell.commands.Command; |
| 22 | import org.onosproject.cli.AbstractShellCommand; |
| 23 | import org.onosproject.segmentrouting.DefaultTunnel; |
| 24 | import org.onosproject.segmentrouting.SegmentRoutingService; |
| 25 | import org.onosproject.segmentrouting.Tunnel; |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 26 | import org.onosproject.segmentrouting.TunnelHandler; |
sangho | 316d438 | 2015-06-24 09:37:40 -0700 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Command to remove a tunnel. |
| 30 | */ |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 31 | @Command(scope = "onos", name = "sr-tunnel-remove", |
sangho | 316d438 | 2015-06-24 09:37:40 -0700 | [diff] [blame] | 32 | description = "Remove a tunnel") |
| 33 | public class TunnelRemoveCommand extends AbstractShellCommand { |
| 34 | |
| 35 | @Argument(index = 0, name = "tunnel ID", |
| 36 | description = "tunnel ID", |
| 37 | required = true, multiValued = false) |
| 38 | String tunnelId; |
| 39 | |
| 40 | @Override |
| 41 | protected void execute() { |
sangho | 316d438 | 2015-06-24 09:37:40 -0700 | [diff] [blame] | 42 | SegmentRoutingService srService = |
| 43 | AbstractShellCommand.get(SegmentRoutingService.class); |
| 44 | |
| 45 | Tunnel tunnel = new DefaultTunnel(tunnelId, Lists.newArrayList()); |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 46 | TunnelHandler.Result result = srService.removeTunnel(tunnel); |
| 47 | switch (result) { |
| 48 | case TUNNEL_IN_USE: |
| 49 | print("ERROR: the tunnel is still in use"); |
| 50 | break; |
| 51 | case TUNNEL_NOT_FOUND: |
| 52 | print("ERROR: the tunnel is not found"); |
| 53 | break; |
| 54 | default: |
| 55 | break; |
| 56 | } |
sangho | 316d438 | 2015-06-24 09:37:40 -0700 | [diff] [blame] | 57 | } |
| 58 | } |