blob: 6b3e1fc882644f9b836783c48a5d29ec565b9a42 [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
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
20import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.segmentrouting.DefaultTunnel;
22import org.onosproject.segmentrouting.SegmentRoutingService;
23import org.onosproject.segmentrouting.Tunnel;
sanghobd812f82015-06-29 14:58:47 -070024import org.onosproject.segmentrouting.TunnelHandler;
sangho2eae4c62015-06-11 14:49:59 -070025
26import java.util.ArrayList;
27import java.util.List;
28import java.util.StringTokenizer;
29
30/**
31 * Command to add a new tunnel.
32 */
Saurav Das07c74602016-04-27 18:35:50 -070033@Command(scope = "onos", name = "sr-tunnel-add",
sangho2eae4c62015-06-11 14:49:59 -070034 description = "Create a new tunnel")
35public class TunnelAddCommand extends AbstractShellCommand {
36
37 @Argument(index = 0, name = "tunnel ID",
38 description = "tunnel ID",
39 required = true, multiValued = false)
40 String tunnelId;
41
42 @Argument(index = 1, name = "label path",
43 description = "label path",
44 required = true, multiValued = false)
45 String labels;
46
47
48 @Override
49 protected void execute() {
50
51 SegmentRoutingService srService =
52 AbstractShellCommand.get(SegmentRoutingService.class);
53
54 List<Integer> labelIds = new ArrayList<>();
55 StringTokenizer strToken = new StringTokenizer(labels, ",");
56 while (strToken.hasMoreTokens()) {
57 labelIds.add(Integer.valueOf(strToken.nextToken()));
58 }
59 Tunnel tunnel = new DefaultTunnel(tunnelId, labelIds);
60
sanghobd812f82015-06-29 14:58:47 -070061 TunnelHandler.Result result = srService.createTunnel(tunnel);
62 switch (result) {
63 case ID_EXISTS:
64 print("ERROR: the same tunnel ID exists");
65 break;
66 case TUNNEL_EXISTS:
67 print("ERROR: the same tunnel exists");
68 break;
69 case INTERNAL_ERROR:
70 print("ERROR: internal tunnel creation error");
71 break;
72 case WRONG_PATH:
73 print("ERROR: the tunnel path is wrong");
74 break;
75 default:
76 break;
77 }
sangho2eae4c62015-06-11 14:49:59 -070078 }
Ray Milkey91197ae2016-11-16 11:06:35 -080079}