blob: e716949620467762e14296b1e3b95c27922cca63 [file] [log] [blame]
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
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;
Priyanka Bbae0eeb12016-11-30 11:59:48 +053027import org.onosproject.pce.pceservice.ExplicitPathInfo;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053028import org.onosproject.pce.pceservice.api.PceService;
29
30import org.slf4j.Logger;
31
Priyanka Bbae0eeb12016-11-30 11:59:48 +053032import java.util.List;
33
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053034/**
35 * Supports quering PCE path.
36 */
37@Command(scope = "onos", name = "pce-query-path",
38 description = "Supports querying PCE path.")
39public class PceQueryPathCommand extends AbstractShellCommand {
40 private final Logger log = getLogger(getClass());
Priyanka B7938b722016-06-08 20:43:49 +053041 public static final String COST_TYPE = "costType";
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053042
43 @Option(name = "-i", aliases = "--id", description = "path-id", required = false,
44 multiValued = false)
45 String id = null;
46
47 @Override
48 protected void execute() {
49 log.info("executing pce-query-path");
50
51 PceService service = get(PceService.class);
52 if (null == id) {
Mahesh Poojary S8e1670e2016-05-19 22:15:34 +053053 Iterable<Tunnel> tunnels = service.queryAllPath();
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053054 if (tunnels != null) {
55 for (final Tunnel tunnel : tunnels) {
56 display(tunnel);
57 }
58 } else {
59 print("No path is found.");
60 return;
61 }
62 } else {
Mahesh Poojary S8e1670e2016-05-19 22:15:34 +053063 Tunnel tunnel = service.queryPath(TunnelId.valueOf(id));
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053064 if (tunnel == null) {
65 print("Path doesnot exists.");
66 return;
67 }
68 display(tunnel);
69 }
70 }
71
72 /**
73 * Display tunnel information on the terminal.
74 *
75 * @param tunnel pce tunnel
76 */
77 void display(Tunnel tunnel) {
Priyanka Bbae0eeb12016-11-30 11:59:48 +053078 List<ExplicitPathInfo> explicitPathInfoList = AbstractShellCommand.get(PceService.class)
79 .explicitPathInfoList(tunnel.tunnelName().value());
80
81 print("\npath-id : %s \n" +
82 "source : %s \n" +
83 "destination : %s \n" +
84 "path-type : %s \n" +
85 "symbolic-path-name : %s \n" +
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053086 "constraints: \n" +
Priyanka Bbae0eeb12016-11-30 11:59:48 +053087 " cost : %s \n" +
88 " bandwidth : %s",
Priyanka B3fdb9dd2016-08-08 10:47:24 +053089 tunnel.tunnelId().id(), tunnel.path().src().deviceId().toString(),
90 tunnel.path().dst().deviceId().toString(),
Priyanka B7938b722016-06-08 20:43:49 +053091 tunnel.type().name(), tunnel.tunnelName(), tunnel.annotations().value(COST_TYPE),
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053092 tunnel.annotations().value(AnnotationKeys.BANDWIDTH));
Priyanka Bbae0eeb12016-11-30 11:59:48 +053093 if (explicitPathInfoList != null) {
94 for (ExplicitPathInfo e : explicitPathInfoList) {
95 print("explicitPathObjects : \n" +
96 " type : %s \n" +
97 " value : %s ",
98 String.valueOf(e.type().type()), e.value().toString());
99 }
100 }
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +0530101 }
102}