blob: 51dee4182b7597b61ff98b7a30e41b6b3c6983f6 [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;
25
26import java.util.ArrayList;
27import java.util.List;
28import java.util.StringTokenizer;
29
30/**
31 * Command to add a new tunnel.
32 */
33@Command(scope = "onos", name = "srtunnel-add",
34 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
61 srService.createTunnel(tunnel);
62 }
63}