blob: 605ec819d126702d3211cd2540c552622d2ff1e9 [file] [log] [blame]
Jonathan Hart54119bb2016-02-06 18:48:27 -08001/*
2 * Copyright 2016 Open Networking Laboratory
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
17package org.onosproject.pim.cli;
18
19import org.apache.karaf.shell.commands.Command;
20import org.onlab.util.Tools;
21import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.pim.impl.PIMInterface;
23import org.onosproject.pim.impl.PIMInterfaceService;
24import org.onosproject.pim.impl.PIMNeighbor;
25
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() {
40 PIMInterfaceService interfaceService = get(PIMInterfaceService.class);
41
42 Set<PIMInterface> interfaces = interfaceService.getPimInterfaces();
43
44 for (PIMInterface intf : interfaces) {
45 print(INTF_FORMAT, intf.getInterface().name(), intf.getIpAddress());
46 for (PIMNeighbor neighbor : intf.getNeighbors()) {
47 // 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}