Satish K | ba1c912 | 2017-04-05 15:27:23 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Satish K | ba1c912 | 2017-04-05 15:27:23 +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 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 20 | import org.apache.karaf.shell.api.action.Argument; |
| 21 | import org.apache.karaf.shell.api.action.Command; |
Satish K | ba1c912 | 2017-04-05 15:27:23 +0530 | [diff] [blame] | 22 | |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame^] | 23 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Satish K | ba1c912 | 2017-04-05 15:27:23 +0530 | [diff] [blame] | 24 | import org.onosproject.cli.AbstractShellCommand; |
| 25 | import org.onosproject.incubator.net.tunnel.Tunnel; |
| 26 | import org.onosproject.incubator.net.tunnel.TunnelId; |
| 27 | import org.onosproject.net.AnnotationKeys; |
| 28 | import org.onosproject.pce.pceservice.api.PceService; |
| 29 | |
| 30 | import org.slf4j.Logger; |
| 31 | |
| 32 | import java.util.List; |
| 33 | |
| 34 | /** |
| 35 | * Supports quering PCE load balanced path. |
| 36 | */ |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame^] | 37 | @Service |
Satish K | ba1c912 | 2017-04-05 15:27:23 +0530 | [diff] [blame] | 38 | @Command(scope = "onos", name = "pce-query-load-balancing-path", |
| 39 | description = "Supports querying PCE path.") |
| 40 | public class PceQueryLoadBalancingPathCommand extends AbstractShellCommand { |
| 41 | private final Logger log = getLogger(getClass()); |
| 42 | public static final String COST_TYPE = "costType"; |
| 43 | |
| 44 | @Argument(index = 0, name = "pathName", description = "load balencing path name", required = true, |
| 45 | multiValued = false) |
| 46 | String name = null; |
| 47 | |
| 48 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 49 | protected void doExecute() { |
Satish K | ba1c912 | 2017-04-05 15:27:23 +0530 | [diff] [blame] | 50 | log.info("executing pce-query-load-balancing-path"); |
| 51 | |
| 52 | PceService service = get(PceService.class); |
| 53 | |
| 54 | if (name == null) { |
| 55 | print("Path name is mandatory"); |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | List<TunnelId> tunnelIds = service.queryLoadBalancingPath(name); |
| 60 | if (tunnelIds == null || tunnelIds.isEmpty()) { |
| 61 | print("Release path failed"); |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | for (TunnelId id : tunnelIds) { |
| 66 | Tunnel tunnel = service.queryPath(id); |
| 67 | if (tunnel == null) { |
| 68 | print("Path doesnot exists"); |
| 69 | return; |
| 70 | } |
| 71 | display(tunnel); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Display tunnel information on the terminal. |
| 77 | * |
| 78 | * @param tunnel pce tunnel |
| 79 | */ |
| 80 | void display(Tunnel tunnel) { |
| 81 | |
| 82 | print("\npath-id : %s \n" + |
| 83 | "source : %s \n" + |
| 84 | "destination : %s \n" + |
| 85 | "path-type : %s \n" + |
| 86 | "symbolic-path-name : %s \n" + |
| 87 | "constraints: \n" + |
| 88 | " cost : %s \n" + |
| 89 | " bandwidth : %s", |
| 90 | tunnel.tunnelId().id(), tunnel.path().src().deviceId().toString(), |
| 91 | tunnel.path().dst().deviceId().toString(), |
| 92 | tunnel.type().name(), tunnel.tunnelName(), tunnel.annotations().value(COST_TYPE), |
| 93 | tunnel.annotations().value(AnnotationKeys.BANDWIDTH)); |
| 94 | print("Path : %s", tunnel.path().toString()); |
| 95 | } |
| 96 | } |