Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 1 | /* |
Mahesh Poojary S | 8e1670e | 2016-05-19 22:15:34 +0530 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [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.pce.cli; |
| 17 | |
| 18 | import static org.slf4j.LoggerFactory.getLogger; |
| 19 | |
| 20 | import org.apache.karaf.shell.commands.Command; |
| 21 | import org.apache.karaf.shell.commands.Option; |
| 22 | |
| 23 | import org.onosproject.cli.AbstractShellCommand; |
| 24 | import org.onosproject.incubator.net.tunnel.Tunnel; |
Mahesh Poojary S | 8e1670e | 2016-05-19 22:15:34 +0530 | [diff] [blame] | 25 | import org.onosproject.incubator.net.tunnel.TunnelId; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 26 | import org.onosproject.net.AnnotationKeys; |
| 27 | import org.onosproject.pce.pceservice.api.PceService; |
| 28 | |
| 29 | import org.slf4j.Logger; |
| 30 | |
| 31 | /** |
| 32 | * Supports quering PCE path. |
| 33 | */ |
| 34 | @Command(scope = "onos", name = "pce-query-path", |
| 35 | description = "Supports querying PCE path.") |
| 36 | public class PceQueryPathCommand extends AbstractShellCommand { |
| 37 | private final Logger log = getLogger(getClass()); |
Priyanka B | 7938b72 | 2016-06-08 20:43:49 +0530 | [diff] [blame] | 38 | public static final String COST_TYPE = "costType"; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 39 | |
| 40 | @Option(name = "-i", aliases = "--id", description = "path-id", required = false, |
| 41 | multiValued = false) |
| 42 | String id = null; |
| 43 | |
| 44 | @Override |
| 45 | protected void execute() { |
| 46 | log.info("executing pce-query-path"); |
| 47 | |
| 48 | PceService service = get(PceService.class); |
| 49 | if (null == id) { |
Mahesh Poojary S | 8e1670e | 2016-05-19 22:15:34 +0530 | [diff] [blame] | 50 | Iterable<Tunnel> tunnels = service.queryAllPath(); |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 51 | if (tunnels != null) { |
| 52 | for (final Tunnel tunnel : tunnels) { |
| 53 | display(tunnel); |
| 54 | } |
| 55 | } else { |
| 56 | print("No path is found."); |
| 57 | return; |
| 58 | } |
| 59 | } else { |
Mahesh Poojary S | 8e1670e | 2016-05-19 22:15:34 +0530 | [diff] [blame] | 60 | Tunnel tunnel = service.queryPath(TunnelId.valueOf(id)); |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 61 | if (tunnel == null) { |
| 62 | print("Path doesnot exists."); |
| 63 | return; |
| 64 | } |
| 65 | display(tunnel); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Display tunnel information on the terminal. |
| 71 | * |
| 72 | * @param tunnel pce tunnel |
| 73 | */ |
| 74 | void display(Tunnel tunnel) { |
Priyanka B | 7938b72 | 2016-06-08 20:43:49 +0530 | [diff] [blame] | 75 | print("\npath-id : %s \n" + |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 76 | "source : %s \n" + |
| 77 | "destination : %s \n" + |
Priyanka B | 7938b72 | 2016-06-08 20:43:49 +0530 | [diff] [blame] | 78 | "path-type : %s \n" + |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 79 | "symbolic-path-name : %s \n" + |
| 80 | "constraints: \n" + |
Priyanka B | 7938b72 | 2016-06-08 20:43:49 +0530 | [diff] [blame] | 81 | " cost : %s \n" + |
| 82 | " bandwidth : %s", |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 83 | tunnel.tunnelId().id(), tunnel.src().toString(), tunnel.dst().toString(), |
Priyanka B | 7938b72 | 2016-06-08 20:43:49 +0530 | [diff] [blame] | 84 | tunnel.type().name(), tunnel.tunnelName(), tunnel.annotations().value(COST_TYPE), |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 85 | tunnel.annotations().value(AnnotationKeys.BANDWIDTH)); |
| 86 | } |
| 87 | } |