blob: 686ea45faff00cbcbb2a0e811074e6797597174c [file] [log] [blame]
Satish Kba1c9122017-04-05 15:27:23 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Satish Kba1c9122017-04-05 15:27:23 +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.Argument;
21import org.apache.karaf.shell.api.action.Command;
Satish Kba1c9122017-04-05 15:27:23 +053022
Ray Milkey7a2dee52018-09-28 10:58:28 -070023import org.apache.karaf.shell.api.action.lifecycle.Service;
Satish Kba1c9122017-04-05 15:27:23 +053024import org.onosproject.cli.AbstractShellCommand;
25import org.onosproject.incubator.net.tunnel.Tunnel;
26import org.onosproject.incubator.net.tunnel.TunnelId;
27import org.onosproject.net.AnnotationKeys;
28import org.onosproject.pce.pceservice.api.PceService;
29
30import org.slf4j.Logger;
31
32import java.util.List;
33
34/**
35 * Supports quering PCE load balanced path.
36 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070037@Service
Satish Kba1c9122017-04-05 15:27:23 +053038@Command(scope = "onos", name = "pce-query-load-balancing-path",
39 description = "Supports querying PCE path.")
40public 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 Milkey86ad7bb2018-09-27 12:32:28 -070049 protected void doExecute() {
Satish Kba1c9122017-04-05 15:27:23 +053050 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}