blob: f5f02991d8e59ea167b3973ad12fb21d5ed61ee3 [file] [log] [blame]
sangho316d4382015-06-24 09:37:40 -07001/*
Brian O'Connor0947d7e2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
sangho316d4382015-06-24 09:37:40 -07003 *
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 com.google.common.collect.Lists;
Ray Milkeydb38bc82018-09-27 12:32:28 -070020import org.apache.karaf.shell.api.action.Argument;
21import org.apache.karaf.shell.api.action.Command;
Ray Milkey52ca4e92018-09-28 10:58:28 -070022import org.apache.karaf.shell.api.action.lifecycle.Service;
sangho316d4382015-06-24 09:37:40 -070023import org.onosproject.cli.AbstractShellCommand;
24import org.onosproject.segmentrouting.DefaultTunnel;
25import org.onosproject.segmentrouting.SegmentRoutingService;
26import org.onosproject.segmentrouting.Tunnel;
sanghobd812f82015-06-29 14:58:47 -070027import org.onosproject.segmentrouting.TunnelHandler;
sangho316d4382015-06-24 09:37:40 -070028
29/**
30 * Command to remove a tunnel.
31 */
Ray Milkey52ca4e92018-09-28 10:58:28 -070032@Service
Saurav Das07c74602016-04-27 18:35:50 -070033@Command(scope = "onos", name = "sr-tunnel-remove",
sangho316d4382015-06-24 09:37:40 -070034 description = "Remove a tunnel")
35public class TunnelRemoveCommand extends AbstractShellCommand {
36
37 @Argument(index = 0, name = "tunnel ID",
38 description = "tunnel ID",
39 required = true, multiValued = false)
40 String tunnelId;
41
42 @Override
Ray Milkeydb38bc82018-09-27 12:32:28 -070043 protected void doExecute() {
sangho316d4382015-06-24 09:37:40 -070044 SegmentRoutingService srService =
45 AbstractShellCommand.get(SegmentRoutingService.class);
46
47 Tunnel tunnel = new DefaultTunnel(tunnelId, Lists.newArrayList());
sanghobd812f82015-06-29 14:58:47 -070048 TunnelHandler.Result result = srService.removeTunnel(tunnel);
49 switch (result) {
50 case TUNNEL_IN_USE:
51 print("ERROR: the tunnel is still in use");
52 break;
53 case TUNNEL_NOT_FOUND:
54 print("ERROR: the tunnel is not found");
55 break;
56 default:
57 break;
58 }
sangho316d4382015-06-24 09:37:40 -070059 }
60}