blob: d37c6d3f44a44c4169e50bc6f09456e60c0dd78f [file] [log] [blame]
Jonathan Hart66018992015-07-31 11:19:27 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
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 */
16
17package org.onosproject.routing.cli;
18
19import org.apache.karaf.shell.commands.Command;
20import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.core.ApplicationId;
22import org.onosproject.core.CoreService;
Ray Milkeya4122362015-08-18 15:19:08 -070023import org.onosproject.net.config.NetworkConfigService;
Jonathan Hart66018992015-07-31 11:19:27 -070024import org.onosproject.routing.RoutingService;
Jonathan Hart4cb39882015-08-12 23:50:55 -040025import org.onosproject.routing.config.BgpConfig;
Jonathan Hart66018992015-07-31 11:19:27 -070026
27/**
28 * Lists the BGP speakers configured in the system.
29 */
30@Command(scope = "onos", name = "bgp-speakers",
31 description = "Lists all BGP speakers")
32public class BgpSpeakersListCommand extends AbstractShellCommand {
33
34 private static final String FORMAT = "%s : %s";
35
36 @Override
37 protected void execute() {
38 NetworkConfigService configService = get(NetworkConfigService.class);
39 CoreService coreService = get(CoreService.class);
40 ApplicationId appId = coreService.getAppId(RoutingService.ROUTER_APP_ID);
41
42 print(appId.toString());
43
44 BgpConfig config = configService.getConfig(appId, BgpConfig.class);
45
46 if (config == null || config.bgpSpeakers().isEmpty()) {
47 print("No speakers configured");
48 } else {
49 config.bgpSpeakers().forEach(
Jonathan Hart4cb39882015-08-12 23:50:55 -040050 s -> print(FORMAT, s.connectPoint(), s.peers()));
Jonathan Hart66018992015-07-31 11:19:27 -070051 }
52 }
53}