blob: b503f078b59d68ce9e436387ac3929ca75cd8402 [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
20import org.apache.karaf.shell.commands.Argument;
21import org.apache.karaf.shell.commands.Command;
22
23import org.onosproject.cli.AbstractShellCommand;
24import org.onosproject.incubator.net.tunnel.Tunnel;
25import org.onosproject.incubator.net.tunnel.TunnelId;
26import org.onosproject.net.AnnotationKeys;
27import org.onosproject.pce.pceservice.api.PceService;
28
29import org.slf4j.Logger;
30
31import java.util.List;
32
33/**
34 * Supports quering PCE load balanced path.
35 */
36@Command(scope = "onos", name = "pce-query-load-balancing-path",
37 description = "Supports querying PCE path.")
38public class PceQueryLoadBalancingPathCommand extends AbstractShellCommand {
39 private final Logger log = getLogger(getClass());
40 public static final String COST_TYPE = "costType";
41
42 @Argument(index = 0, name = "pathName", description = "load balencing path name", required = true,
43 multiValued = false)
44 String name = null;
45
46 @Override
47 protected void execute() {
48 log.info("executing pce-query-load-balancing-path");
49
50 PceService service = get(PceService.class);
51
52 if (name == null) {
53 print("Path name is mandatory");
54 return;
55 }
56
57 List<TunnelId> tunnelIds = service.queryLoadBalancingPath(name);
58 if (tunnelIds == null || tunnelIds.isEmpty()) {
59 print("Release path failed");
60 return;
61 }
62
63 for (TunnelId id : tunnelIds) {
64 Tunnel tunnel = service.queryPath(id);
65 if (tunnel == null) {
66 print("Path doesnot exists");
67 return;
68 }
69 display(tunnel);
70 }
71 }
72
73 /**
74 * Display tunnel information on the terminal.
75 *
76 * @param tunnel pce tunnel
77 */
78 void display(Tunnel tunnel) {
79
80 print("\npath-id : %s \n" +
81 "source : %s \n" +
82 "destination : %s \n" +
83 "path-type : %s \n" +
84 "symbolic-path-name : %s \n" +
85 "constraints: \n" +
86 " cost : %s \n" +
87 " bandwidth : %s",
88 tunnel.tunnelId().id(), tunnel.path().src().deviceId().toString(),
89 tunnel.path().dst().deviceId().toString(),
90 tunnel.type().name(), tunnel.tunnelName(), tunnel.annotations().value(COST_TYPE),
91 tunnel.annotations().value(AnnotationKeys.BANDWIDTH));
92 print("Path : %s", tunnel.path().toString());
93 }
94}