Jonathan Hart | 6b04558 | 2016-02-03 10:00:08 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Jonathan Hart | 6b04558 | 2016-02-03 10:00:08 -0800 | [diff] [blame] | 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.fpm.cli; |
| 18 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 19 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 20 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Jonathan Hart | dc7e76c | 2017-03-27 11:35:34 -0700 | [diff] [blame] | 21 | import org.onlab.packet.IpAddress; |
Jonathan Hart | 6b04558 | 2016-02-03 10:00:08 -0800 | [diff] [blame] | 22 | import org.onlab.util.Tools; |
| 23 | import org.onosproject.cli.AbstractShellCommand; |
Jonathan Hart | dc7e76c | 2017-03-27 11:35:34 -0700 | [diff] [blame] | 24 | import org.onosproject.cluster.ClusterService; |
Jonathan Hart | f4b2ca1 | 2017-05-17 16:10:16 -0700 | [diff] [blame] | 25 | import org.onosproject.routing.fpm.FpmPeerInfo; |
Jonathan Hart | 6b04558 | 2016-02-03 10:00:08 -0800 | [diff] [blame] | 26 | import org.onosproject.routing.fpm.FpmInfoService; |
Jonathan Hart | f4b2ca1 | 2017-05-17 16:10:16 -0700 | [diff] [blame] | 27 | import org.onosproject.routing.fpm.FpmPeer; |
Jonathan Hart | 6b04558 | 2016-02-03 10:00:08 -0800 | [diff] [blame] | 28 | |
Jonathan Hart | dc7e76c | 2017-03-27 11:35:34 -0700 | [diff] [blame] | 29 | import java.util.Comparator; |
Jonathan Hart | f4b2ca1 | 2017-05-17 16:10:16 -0700 | [diff] [blame] | 30 | import java.util.Map; |
Jonathan Hart | dc7e76c | 2017-03-27 11:35:34 -0700 | [diff] [blame] | 31 | |
Jonathan Hart | 6b04558 | 2016-02-03 10:00:08 -0800 | [diff] [blame] | 32 | /** |
| 33 | * Displays the current FPM connections. |
| 34 | */ |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 35 | @Service |
Jonathan Hart | 6b04558 | 2016-02-03 10:00:08 -0800 | [diff] [blame] | 36 | @Command(scope = "onos", name = "fpm-connections", |
| 37 | description = "Displays the current FPM connections") |
| 38 | public class FpmConnectionsList extends AbstractShellCommand { |
| 39 | |
Jonathan Hart | f4b2ca1 | 2017-05-17 16:10:16 -0700 | [diff] [blame] | 40 | private static final String FORMAT = "peer %s:%s connected to %s since %s %s (%d routes locally)"; |
Jonathan Hart | 6b04558 | 2016-02-03 10:00:08 -0800 | [diff] [blame] | 41 | |
| 42 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 43 | protected void doExecute() { |
Jonathan Hart | dc7e76c | 2017-03-27 11:35:34 -0700 | [diff] [blame] | 44 | FpmInfoService fpmInfo = get(FpmInfoService.class); |
Jonathan Hart | f4b2ca1 | 2017-05-17 16:10:16 -0700 | [diff] [blame] | 45 | |
Kalhee Kim | 40beb72 | 2018-01-16 20:32:04 +0000 | [diff] [blame] | 46 | print(String.format("PD Pushing is %s.", fpmInfo.isPdPushEnabled() ? "enabled" : "disabled")); |
| 47 | |
Jonathan Hart | f4b2ca1 | 2017-05-17 16:10:16 -0700 | [diff] [blame] | 48 | fpmInfo.peers().entrySet().stream() |
| 49 | .sorted(Comparator.<Map.Entry<FpmPeer, FpmPeerInfo>, IpAddress>comparing(e -> e.getKey().address()) |
| 50 | .thenComparing(e -> e.getKey().port())) |
| 51 | .map(Map.Entry::getValue) |
| 52 | .forEach(this::print); |
| 53 | } |
| 54 | |
| 55 | private void print(FpmPeerInfo info) { |
Jonathan Hart | dc7e76c | 2017-03-27 11:35:34 -0700 | [diff] [blame] | 56 | ClusterService clusterService = get(ClusterService.class); |
Jonathan Hart | 6b04558 | 2016-02-03 10:00:08 -0800 | [diff] [blame] | 57 | |
Jonathan Hart | f4b2ca1 | 2017-05-17 16:10:16 -0700 | [diff] [blame] | 58 | info.connections().forEach(cinfo -> |
| 59 | print(FORMAT, cinfo.peer().address(), cinfo.peer().port(), |
| 60 | cinfo.connectedTo(), Tools.timeAgo(cinfo.connectTime()), |
| 61 | cinfo.connectedTo().equals(clusterService.getLocalNode().id()) ? "*" : "", |
| 62 | info.routes()) |
| 63 | ); |
Jonathan Hart | 6b04558 | 2016-02-03 10:00:08 -0800 | [diff] [blame] | 64 | } |
| 65 | } |