blob: 659b399ab722c9260142632735b27b5829d0550a [file] [log] [blame]
Jonathan Hart54119bb2016-02-06 18:48:27 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
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
Ray Milkey86ad7bb2018-09-27 12:32:28 -070019import org.apache.karaf.shell.api.action.Command;
Ray Milkey7a2dee52018-09-28 10:58:28 -070020import org.apache.karaf.shell.api.action.lifecycle.Service;
Jonathan Hart54119bb2016-02-06 18:48:27 -080021import org.onlab.util.Tools;
22import org.onosproject.cli.AbstractShellCommand;
Jonathan Hartfbfe2a82016-03-29 11:36:33 -070023import org.onosproject.pim.impl.PimInterface;
24import org.onosproject.pim.impl.PimInterfaceService;
25import org.onosproject.pim.impl.PimNeighbor;
Jonathan Hart54119bb2016-02-06 18:48:27 -080026
27import java.util.Set;
28
29/**
30 * Lists PIM neighbors.
31 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070032@Service
Jonathan Hart54119bb2016-02-06 18:48:27 -080033@Command(scope = "onos", name = "pim-neighbors",
34 description = "Lists the PIM neighbors")
35public class PimNeighborsListCommand extends AbstractShellCommand {
36
37 private static final String INTF_FORMAT = "interface=%s, address=%s";
38 private static final String NEIGHBOR_FORMAT = " neighbor=%s, uptime=%s, holdtime=%s, drPriority=%s, genId=%s";
39
40 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070041 protected void doExecute() {
Jonathan Hartfbfe2a82016-03-29 11:36:33 -070042 PimInterfaceService interfaceService = get(PimInterfaceService.class);
Jonathan Hart54119bb2016-02-06 18:48:27 -080043
Jonathan Hartfbfe2a82016-03-29 11:36:33 -070044 Set<PimInterface> interfaces = interfaceService.getPimInterfaces();
Jonathan Hart54119bb2016-02-06 18:48:27 -080045
Jonathan Hartfbfe2a82016-03-29 11:36:33 -070046 for (PimInterface intf : interfaces) {
Jonathan Hart54119bb2016-02-06 18:48:27 -080047 print(INTF_FORMAT, intf.getInterface().name(), intf.getIpAddress());
Jonathan Hartfbfe2a82016-03-29 11:36:33 -070048 for (PimNeighbor neighbor : intf.getNeighbors()) {
Jonathan Hart54119bb2016-02-06 18:48:27 -080049 // Filter out the PIM neighbor representing 'us'
50 if (!neighbor.ipAddress().equals(intf.getIpAddress())) {
51 print(NEIGHBOR_FORMAT, neighbor.ipAddress(),
52 Tools.timeAgo(neighbor.upTime()), neighbor.holdtime(),
53 neighbor.priority(), neighbor.generationId());
54 }
55 }
56 }
57 }
58
59}