blob: 09a396ea346fc65a48c924b5d5dbe029efa7ca6b [file] [log] [blame]
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +05301/*
Mahesh Poojary S8e1670e2016-05-19 22:15:34 +05302 * Copyright 2016-present Open Networking Laboratory
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +05303 *
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 */
16package org.onosproject.pce.cli;
17
18import static org.slf4j.LoggerFactory.getLogger;
19
20import org.apache.karaf.shell.commands.Command;
21import org.apache.karaf.shell.commands.Option;
22
23import org.onosproject.cli.AbstractShellCommand;
24import org.onosproject.incubator.net.tunnel.Tunnel;
Mahesh Poojary S8e1670e2016-05-19 22:15:34 +053025import org.onosproject.incubator.net.tunnel.TunnelId;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053026import org.onosproject.net.AnnotationKeys;
27import org.onosproject.pce.pceservice.api.PceService;
28
29import 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.")
36public class PceQueryPathCommand extends AbstractShellCommand {
37 private final Logger log = getLogger(getClass());
Priyanka B7938b722016-06-08 20:43:49 +053038 public static final String COST_TYPE = "costType";
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053039
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 S8e1670e2016-05-19 22:15:34 +053050 Iterable<Tunnel> tunnels = service.queryAllPath();
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053051 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 S8e1670e2016-05-19 22:15:34 +053060 Tunnel tunnel = service.queryPath(TunnelId.valueOf(id));
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053061 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 B7938b722016-06-08 20:43:49 +053075 print("\npath-id : %s \n" +
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053076 "source : %s \n" +
77 "destination : %s \n" +
Priyanka B7938b722016-06-08 20:43:49 +053078 "path-type : %s \n" +
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053079 "symbolic-path-name : %s \n" +
80 "constraints: \n" +
Priyanka B7938b722016-06-08 20:43:49 +053081 " cost : %s \n" +
82 " bandwidth : %s",
Priyanka B3fdb9dd2016-08-08 10:47:24 +053083 tunnel.tunnelId().id(), tunnel.path().src().deviceId().toString(),
84 tunnel.path().dst().deviceId().toString(),
Priyanka B7938b722016-06-08 20:43:49 +053085 tunnel.type().name(), tunnel.tunnelName(), tunnel.annotations().value(COST_TYPE),
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053086 tunnel.annotations().value(AnnotationKeys.BANDWIDTH));
87 }
88}