blob: 0e487d0d5f59bf3c293b74d98815b5e6f76cbf34 [file] [log] [blame]
sangho2eae4c62015-06-11 14:49:59 -07001/*
Brian O'Connor0947d7e2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
sangho2eae4c62015-06-11 14:49:59 -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
Ray Milkeydb38bc82018-09-27 12:32:28 -070018import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
Ray Milkey52ca4e92018-09-28 10:58:28 -070020import org.apache.karaf.shell.api.action.lifecycle.Service;
sangho2eae4c62015-06-11 14:49:59 -070021import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.segmentrouting.DefaultTunnel;
23import org.onosproject.segmentrouting.SegmentRoutingService;
24import org.onosproject.segmentrouting.Tunnel;
sanghobd812f82015-06-29 14:58:47 -070025import org.onosproject.segmentrouting.TunnelHandler;
sangho2eae4c62015-06-11 14:49:59 -070026
27import java.util.ArrayList;
28import java.util.List;
29import java.util.StringTokenizer;
30
31/**
32 * Command to add a new tunnel.
33 */
Ray Milkey52ca4e92018-09-28 10:58:28 -070034@Service
Saurav Das07c74602016-04-27 18:35:50 -070035@Command(scope = "onos", name = "sr-tunnel-add",
sangho2eae4c62015-06-11 14:49:59 -070036 description = "Create a new tunnel")
37public class TunnelAddCommand extends AbstractShellCommand {
38
39 @Argument(index = 0, name = "tunnel ID",
40 description = "tunnel ID",
41 required = true, multiValued = false)
42 String tunnelId;
43
44 @Argument(index = 1, name = "label path",
45 description = "label path",
46 required = true, multiValued = false)
47 String labels;
48
49
50 @Override
Ray Milkeydb38bc82018-09-27 12:32:28 -070051 protected void doExecute() {
sangho2eae4c62015-06-11 14:49:59 -070052
53 SegmentRoutingService srService =
54 AbstractShellCommand.get(SegmentRoutingService.class);
55
56 List<Integer> labelIds = new ArrayList<>();
57 StringTokenizer strToken = new StringTokenizer(labels, ",");
58 while (strToken.hasMoreTokens()) {
59 labelIds.add(Integer.valueOf(strToken.nextToken()));
60 }
61 Tunnel tunnel = new DefaultTunnel(tunnelId, labelIds);
62
sanghobd812f82015-06-29 14:58:47 -070063 TunnelHandler.Result result = srService.createTunnel(tunnel);
64 switch (result) {
65 case ID_EXISTS:
66 print("ERROR: the same tunnel ID exists");
67 break;
68 case TUNNEL_EXISTS:
69 print("ERROR: the same tunnel exists");
70 break;
71 case INTERNAL_ERROR:
72 print("ERROR: internal tunnel creation error");
73 break;
74 case WRONG_PATH:
75 print("ERROR: the tunnel path is wrong");
76 break;
77 default:
78 break;
79 }
sangho2eae4c62015-06-11 14:49:59 -070080 }
Ray Milkey91197ae2016-11-16 11:06:35 -080081}