blob: 86dd44c8bb621889051b5247bab77a4366c3adda [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;
20import org.onlab.util.Tools;
21import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.routing.fpm.FpmInfoService;
23
24import java.net.InetSocketAddress;
25
26/**
27 * Displays the current FPM connections.
28 */
29@Command(scope = "onos", name = "fpm-connections",
30 description = "Displays the current FPM connections")
31public class FpmConnectionsList extends AbstractShellCommand {
32
33 private static final String FORMAT = "%s:%s connected since %s";
34
35 @Override
36 protected void execute() {
Jonathan Hartf4bd0482017-01-27 15:11:18 -080037 FpmInfoService fpmInfo = AbstractShellCommand.get(FpmInfoService.class);
Jonathan Hart6b045582016-02-03 10:00:08 -080038
39 fpmInfo.peers().forEach((socketAddress, timestamp) -> {
40 if (socketAddress instanceof InetSocketAddress) {
41 InetSocketAddress inet = (InetSocketAddress) socketAddress;
42
43 print(FORMAT, inet.getHostString(), inet.getPort(), Tools.timeAgo(timestamp));
44 } else {
45 print("Unknown data format");
46 }
47 });
48 }
49}