blob: bb0ae549498c63f5ec332acf5a767d8440b55086 [file] [log] [blame]
sangho6703da22015-06-11 14:49:59 -07001
2/*
3 * Copyright 2015 Open Networking Laboratory
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17package org.onosproject.segmentrouting.cli;
18
19import org.apache.karaf.shell.commands.Argument;
20import org.apache.karaf.shell.commands.Command;
21import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.segmentrouting.DefaultTunnel;
23import org.onosproject.segmentrouting.SegmentRoutingService;
24import org.onosproject.segmentrouting.Tunnel;
sangho71abe1b2015-06-29 14:58:47 -070025import org.onosproject.segmentrouting.TunnelHandler;
sangho6703da22015-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 */
34@Command(scope = "onos", name = "srtunnel-add",
35 description = "Create a new tunnel")
36public class TunnelAddCommand extends AbstractShellCommand {
37
38 @Argument(index = 0, name = "tunnel ID",
39 description = "tunnel ID",
40 required = true, multiValued = false)
41 String tunnelId;
42
43 @Argument(index = 1, name = "label path",
44 description = "label path",
45 required = true, multiValued = false)
46 String labels;
47
48
49 @Override
50 protected void execute() {
51
52 SegmentRoutingService srService =
53 AbstractShellCommand.get(SegmentRoutingService.class);
54
55 List<Integer> labelIds = new ArrayList<>();
56 StringTokenizer strToken = new StringTokenizer(labels, ",");
57 while (strToken.hasMoreTokens()) {
58 labelIds.add(Integer.valueOf(strToken.nextToken()));
59 }
60 Tunnel tunnel = new DefaultTunnel(tunnelId, labelIds);
61
sangho71abe1b2015-06-29 14:58:47 -070062 TunnelHandler.Result result = srService.createTunnel(tunnel);
63 switch (result) {
64 case ID_EXISTS:
65 print("ERROR: the same tunnel ID exists");
66 break;
67 case TUNNEL_EXISTS:
68 print("ERROR: the same tunnel exists");
69 break;
70 case INTERNAL_ERROR:
71 print("ERROR: internal tunnel creation error");
72 break;
73 case WRONG_PATH:
74 print("ERROR: the tunnel path is wrong");
75 break;
76 default:
77 break;
78 }
sangho6703da22015-06-11 14:49:59 -070079 }
80}