blob: 32323fa947a49c8c97d4a52875b4b0a5567aff03 [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());
38
39 @Option(name = "-i", aliases = "--id", description = "path-id", required = false,
40 multiValued = false)
41 String id = null;
42
43 @Override
44 protected void execute() {
45 log.info("executing pce-query-path");
46
47 PceService service = get(PceService.class);
48 if (null == id) {
Mahesh Poojary S8e1670e2016-05-19 22:15:34 +053049 Iterable<Tunnel> tunnels = service.queryAllPath();
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053050 if (tunnels != null) {
51 for (final Tunnel tunnel : tunnels) {
52 display(tunnel);
53 }
54 } else {
55 print("No path is found.");
56 return;
57 }
58 } else {
Mahesh Poojary S8e1670e2016-05-19 22:15:34 +053059 Tunnel tunnel = service.queryPath(TunnelId.valueOf(id));
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053060 if (tunnel == null) {
61 print("Path doesnot exists.");
62 return;
63 }
64 display(tunnel);
65 }
66 }
67
68 /**
69 * Display tunnel information on the terminal.
70 *
71 * @param tunnel pce tunnel
72 */
73 void display(Tunnel tunnel) {
74 print("\npath-id : %d \n" +
75 "source : %s \n" +
76 "destination : %s \n" +
77 "path-type : %d \n" +
78 "symbolic-path-name : %s \n" +
79 "constraints: \n" +
80 " cost : %d \n" +
81 " bandwidth : %.2f",
82 tunnel.tunnelId().id(), tunnel.src().toString(), tunnel.dst().toString(),
83 tunnel.type(), tunnel.tunnelName(), tunnel.path().cost(),
84 tunnel.annotations().value(AnnotationKeys.BANDWIDTH));
85 }
86}