blob: 5edb675673e1752f6d89b63cbdcf8a764fc26998 [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
Ray Milkey86ad7bb2018-09-27 12:32:28 -070020import org.apache.karaf.shell.api.action.Command;
21import org.apache.karaf.shell.api.action.Option;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053022
Ray Milkey7a2dee52018-09-28 10:58:28 -070023import org.apache.karaf.shell.api.action.lifecycle.Service;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053024import org.onosproject.cli.AbstractShellCommand;
25import org.onosproject.incubator.net.tunnel.Tunnel;
Mahesh Poojary S8e1670e2016-05-19 22:15:34 +053026import org.onosproject.incubator.net.tunnel.TunnelId;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053027import org.onosproject.net.AnnotationKeys;
Priyanka Bbae0eeb12016-11-30 11:59:48 +053028import org.onosproject.pce.pceservice.ExplicitPathInfo;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053029import org.onosproject.pce.pceservice.api.PceService;
30
31import org.slf4j.Logger;
32
Priyanka Bbae0eeb12016-11-30 11:59:48 +053033import java.util.List;
34
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053035/**
36 * Supports quering PCE path.
37 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070038@Service
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053039@Command(scope = "onos", name = "pce-query-path",
40 description = "Supports querying PCE path.")
41public class PceQueryPathCommand extends AbstractShellCommand {
42 private final Logger log = getLogger(getClass());
Priyanka B7938b722016-06-08 20:43:49 +053043 public static final String COST_TYPE = "costType";
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053044
45 @Option(name = "-i", aliases = "--id", description = "path-id", required = false,
46 multiValued = false)
47 String id = null;
48
49 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070050 protected void doExecute() {
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053051 log.info("executing pce-query-path");
52
53 PceService service = get(PceService.class);
54 if (null == id) {
Mahesh Poojary S8e1670e2016-05-19 22:15:34 +053055 Iterable<Tunnel> tunnels = service.queryAllPath();
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053056 if (tunnels != null) {
57 for (final Tunnel tunnel : tunnels) {
58 display(tunnel);
59 }
60 } else {
61 print("No path is found.");
62 return;
63 }
64 } else {
Mahesh Poojary S8e1670e2016-05-19 22:15:34 +053065 Tunnel tunnel = service.queryPath(TunnelId.valueOf(id));
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053066 if (tunnel == null) {
67 print("Path doesnot exists.");
68 return;
69 }
70 display(tunnel);
71 }
72 }
73
74 /**
75 * Display tunnel information on the terminal.
76 *
77 * @param tunnel pce tunnel
78 */
79 void display(Tunnel tunnel) {
Priyanka Bbae0eeb12016-11-30 11:59:48 +053080 List<ExplicitPathInfo> explicitPathInfoList = AbstractShellCommand.get(PceService.class)
81 .explicitPathInfoList(tunnel.tunnelName().value());
82
83 print("\npath-id : %s \n" +
84 "source : %s \n" +
85 "destination : %s \n" +
86 "path-type : %s \n" +
87 "symbolic-path-name : %s \n" +
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053088 "constraints: \n" +
Priyanka Bbae0eeb12016-11-30 11:59:48 +053089 " cost : %s \n" +
90 " bandwidth : %s",
Priyanka B3fdb9dd2016-08-08 10:47:24 +053091 tunnel.tunnelId().id(), tunnel.path().src().deviceId().toString(),
92 tunnel.path().dst().deviceId().toString(),
Priyanka B7938b722016-06-08 20:43:49 +053093 tunnel.type().name(), tunnel.tunnelName(), tunnel.annotations().value(COST_TYPE),
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053094 tunnel.annotations().value(AnnotationKeys.BANDWIDTH));
Priyanka Bbae0eeb12016-11-30 11:59:48 +053095 if (explicitPathInfoList != null) {
96 for (ExplicitPathInfo e : explicitPathInfoList) {
97 print("explicitPathObjects : \n" +
98 " type : %s \n" +
99 " value : %s ",
100 String.valueOf(e.type().type()), e.value().toString());
101 }
102 }
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +0530103 }
104}