blob: 8516ed2c9f54c95b44e24790a49b0f7fce9ba2e2 [file] [log] [blame]
Jonathan Hart6b045582016-02-03 10:00:08 -08001/*
Jonathan Hartf4bd0482017-01-27 15:11:18 -08002 * Copyright 2017-present Open Networking Laboratory
Jonathan Hart6b045582016-02-03 10:00:08 -08003 *
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.fpm.cli;
18
19import org.apache.karaf.shell.commands.Command;
Jonathan Hartdc7e76c2017-03-27 11:35:34 -070020import org.onlab.packet.IpAddress;
Jonathan Hart6b045582016-02-03 10:00:08 -080021import org.onlab.util.Tools;
22import org.onosproject.cli.AbstractShellCommand;
Jonathan Hartdc7e76c2017-03-27 11:35:34 -070023import org.onosproject.cluster.ClusterService;
24import org.onosproject.routing.fpm.FpmConnectionInfo;
Jonathan Hart6b045582016-02-03 10:00:08 -080025import org.onosproject.routing.fpm.FpmInfoService;
26
Jonathan Hartdc7e76c2017-03-27 11:35:34 -070027import java.util.Comparator;
28
Jonathan Hart6b045582016-02-03 10:00:08 -080029/**
30 * Displays the current FPM connections.
31 */
32@Command(scope = "onos", name = "fpm-connections",
33 description = "Displays the current FPM connections")
34public class FpmConnectionsList extends AbstractShellCommand {
35
Jonathan Hartdc7e76c2017-03-27 11:35:34 -070036 private static final String FORMAT = "peer %s:%s connected to %s since %s %s";
Jonathan Hart6b045582016-02-03 10:00:08 -080037
38 @Override
39 protected void execute() {
Jonathan Hartdc7e76c2017-03-27 11:35:34 -070040 FpmInfoService fpmInfo = get(FpmInfoService.class);
41 ClusterService clusterService = get(ClusterService.class);
Jonathan Hart6b045582016-02-03 10:00:08 -080042
Jonathan Hartdc7e76c2017-03-27 11:35:34 -070043 fpmInfo.peers().values().stream()
44 .flatMap(v -> v.stream())
45 .sorted(Comparator.<FpmConnectionInfo, IpAddress>comparing(i -> i.peer().address())
46 .thenComparing(i -> i.peer().port()))
47 .forEach(info -> print(FORMAT, info.peer().address(), info.peer().port(),
48 info.connectedTo(), Tools.timeAgo(info.connectTime()),
49 info.connectedTo().equals(clusterService.getLocalNode().id()) ? "*" : ""));
Jonathan Hart6b045582016-02-03 10:00:08 -080050 }
51}