Jonathan Hart | 6601899 | 2015-07-31 11:19:27 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.routing.cli; |
| 18 | |
| 19 | import org.apache.karaf.shell.commands.Command; |
| 20 | import org.onosproject.cli.AbstractShellCommand; |
| 21 | import org.onosproject.core.ApplicationId; |
| 22 | import org.onosproject.core.CoreService; |
Ray Milkey | a412236 | 2015-08-18 15:19:08 -0700 | [diff] [blame^] | 23 | import org.onosproject.net.config.NetworkConfigService; |
Jonathan Hart | 6601899 | 2015-07-31 11:19:27 -0700 | [diff] [blame] | 24 | import org.onosproject.routing.RoutingService; |
| 25 | import org.onosproject.routing.config.impl.BgpConfig; |
| 26 | |
| 27 | /** |
| 28 | * Lists the BGP speakers configured in the system. |
| 29 | */ |
| 30 | @Command(scope = "onos", name = "bgp-speakers", |
| 31 | description = "Lists all BGP speakers") |
| 32 | public 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( |
| 50 | s -> print(FORMAT, s.connectPoint(), s.listenAddresses())); |
| 51 | } |
| 52 | } |
| 53 | } |