sangho | 6703da2 | 2015-06-11 14:49:59 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
sangho | 6703da2 | 2015-06-11 14:49:59 -0700 | [diff] [blame] | 3 | * |
| 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 | */ |
| 16 | package org.onosproject.segmentrouting.cli; |
| 17 | |
| 18 | import org.apache.karaf.shell.commands.Argument; |
| 19 | import org.apache.karaf.shell.commands.Command; |
| 20 | import org.onosproject.cli.AbstractShellCommand; |
| 21 | import org.onosproject.segmentrouting.DefaultTunnel; |
| 22 | import org.onosproject.segmentrouting.SegmentRoutingService; |
| 23 | import org.onosproject.segmentrouting.Tunnel; |
sangho | 71abe1b | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 24 | import org.onosproject.segmentrouting.TunnelHandler; |
sangho | 6703da2 | 2015-06-11 14:49:59 -0700 | [diff] [blame] | 25 | |
| 26 | import java.util.ArrayList; |
| 27 | import java.util.List; |
| 28 | import java.util.StringTokenizer; |
| 29 | |
| 30 | /** |
| 31 | * Command to add a new tunnel. |
| 32 | */ |
Saurav Das | 59232cf | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 33 | @Command(scope = "onos", name = "sr-tunnel-add", |
sangho | 6703da2 | 2015-06-11 14:49:59 -0700 | [diff] [blame] | 34 | description = "Create a new tunnel") |
| 35 | public 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 | |
sangho | 71abe1b | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 61 | 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 | } |
sangho | 6703da2 | 2015-06-11 14:49:59 -0700 | [diff] [blame] | 78 | } |
Ray Milkey | 8526700 | 2016-11-16 11:06:35 -0800 | [diff] [blame] | 79 | } |