sangho | 2eae4c6 | 2015-06-11 14:49:59 -0700 | [diff] [blame] | 1 | |
| 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 | */ |
| 17 | package org.onosproject.segmentrouting.cli; |
| 18 | |
| 19 | import org.apache.karaf.shell.commands.Argument; |
| 20 | import org.apache.karaf.shell.commands.Command; |
| 21 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | import org.onosproject.segmentrouting.DefaultTunnel; |
| 23 | import org.onosproject.segmentrouting.SegmentRoutingService; |
| 24 | import org.onosproject.segmentrouting.Tunnel; |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 25 | import org.onosproject.segmentrouting.TunnelHandler; |
sangho | 2eae4c6 | 2015-06-11 14:49:59 -0700 | [diff] [blame] | 26 | |
| 27 | import java.util.ArrayList; |
| 28 | import java.util.List; |
| 29 | import 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") |
| 36 | public 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 | |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 62 | 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 | } |
sangho | 2eae4c6 | 2015-06-11 14:49:59 -0700 | [diff] [blame] | 79 | } |
| 80 | } |