blob: 3c0f58fa7cb1cd7c8e2c34211d295fe8e22c15da [file] [log] [blame]
Jonathan Hart54119bb2016-02-06 18:48:27 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Jonathan Hart54119bb2016-02-06 18:48:27 -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.pim.cli;
18
19import org.apache.karaf.shell.commands.Command;
20import org.onlab.util.Tools;
21import org.onosproject.cli.AbstractShellCommand;
Jonathan Hartfbfe2a82016-03-29 11:36:33 -070022import org.onosproject.pim.impl.PimInterface;
23import org.onosproject.pim.impl.PimInterfaceService;
24import org.onosproject.pim.impl.PimNeighbor;
Jonathan Hart54119bb2016-02-06 18:48:27 -080025
26import java.util.Set;
27
28/**
29 * Lists PIM neighbors.
30 */
31@Command(scope = "onos", name = "pim-neighbors",
32 description = "Lists the PIM neighbors")
33public class PimNeighborsListCommand extends AbstractShellCommand {
34
35 private static final String INTF_FORMAT = "interface=%s, address=%s";
36 private static final String NEIGHBOR_FORMAT = " neighbor=%s, uptime=%s, holdtime=%s, drPriority=%s, genId=%s";
37
38 @Override
39 protected void execute() {
Jonathan Hartfbfe2a82016-03-29 11:36:33 -070040 PimInterfaceService interfaceService = get(PimInterfaceService.class);
Jonathan Hart54119bb2016-02-06 18:48:27 -080041
Jonathan Hartfbfe2a82016-03-29 11:36:33 -070042 Set<PimInterface> interfaces = interfaceService.getPimInterfaces();
Jonathan Hart54119bb2016-02-06 18:48:27 -080043
Jonathan Hartfbfe2a82016-03-29 11:36:33 -070044 for (PimInterface intf : interfaces) {
Jonathan Hart54119bb2016-02-06 18:48:27 -080045 print(INTF_FORMAT, intf.getInterface().name(), intf.getIpAddress());
Jonathan Hartfbfe2a82016-03-29 11:36:33 -070046 for (PimNeighbor neighbor : intf.getNeighbors()) {
Jonathan Hart54119bb2016-02-06 18:48:27 -080047 // Filter out the PIM neighbor representing 'us'
48 if (!neighbor.ipAddress().equals(intf.getIpAddress())) {
49 print(NEIGHBOR_FORMAT, neighbor.ipAddress(),
50 Tools.timeAgo(neighbor.upTime()), neighbor.holdtime(),
51 neighbor.priority(), neighbor.generationId());
52 }
53 }
54 }
55 }
56
57}