Distribute FPM connection state amongst the cluster
Change-Id: I7b02a630e33107c124d9445f2fefbf4fd31ffc45
diff --git a/apps/routing/fpm/src/main/java/org/onosproject/routing/fpm/cli/FpmConnectionsList.java b/apps/routing/fpm/src/main/java/org/onosproject/routing/fpm/cli/FpmConnectionsList.java
index 5a398b8..8516ed2 100644
--- a/apps/routing/fpm/src/main/java/org/onosproject/routing/fpm/cli/FpmConnectionsList.java
+++ b/apps/routing/fpm/src/main/java/org/onosproject/routing/fpm/cli/FpmConnectionsList.java
@@ -17,10 +17,15 @@
package org.onosproject.routing.fpm.cli;
import org.apache.karaf.shell.commands.Command;
+import org.onlab.packet.IpAddress;
import org.onlab.util.Tools;
import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.cluster.ClusterService;
+import org.onosproject.routing.fpm.FpmConnectionInfo;
import org.onosproject.routing.fpm.FpmInfoService;
+import java.util.Comparator;
+
/**
* Displays the current FPM connections.
*/
@@ -28,14 +33,19 @@
description = "Displays the current FPM connections")
public class FpmConnectionsList extends AbstractShellCommand {
- private static final String FORMAT = "%s:%s connected since %s";
+ private static final String FORMAT = "peer %s:%s connected to %s since %s %s";
@Override
protected void execute() {
- FpmInfoService fpmInfo = AbstractShellCommand.get(FpmInfoService.class);
+ FpmInfoService fpmInfo = get(FpmInfoService.class);
+ ClusterService clusterService = get(ClusterService.class);
- fpmInfo.peers().forEach((peer, timestamp) -> {
- print(FORMAT, peer.address(), peer.port(), Tools.timeAgo(timestamp));
- });
+ fpmInfo.peers().values().stream()
+ .flatMap(v -> v.stream())
+ .sorted(Comparator.<FpmConnectionInfo, IpAddress>comparing(i -> i.peer().address())
+ .thenComparing(i -> i.peer().port()))
+ .forEach(info -> print(FORMAT, info.peer().address(), info.peer().port(),
+ info.connectedTo(), Tools.timeAgo(info.connectTime()),
+ info.connectedTo().equals(clusterService.getLocalNode().id()) ? "*" : ""));
}
}