Jonathan Hart | 54119bb | 2016-02-06 18:48:27 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Laboratory |
Jonathan Hart | 54119bb | 2016-02-06 18:48:27 -0800 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.pim.cli; |
| 18 | |
| 19 | import org.apache.karaf.shell.commands.Command; |
| 20 | import org.onlab.util.Tools; |
| 21 | import org.onosproject.cli.AbstractShellCommand; |
Jonathan Hart | fbfe2a8 | 2016-03-29 11:36:33 -0700 | [diff] [blame] | 22 | import org.onosproject.pim.impl.PimInterface; |
| 23 | import org.onosproject.pim.impl.PimInterfaceService; |
| 24 | import org.onosproject.pim.impl.PimNeighbor; |
Jonathan Hart | 54119bb | 2016-02-06 18:48:27 -0800 | [diff] [blame] | 25 | |
| 26 | import java.util.Set; |
| 27 | |
| 28 | /** |
| 29 | * Lists PIM neighbors. |
| 30 | */ |
| 31 | @Command(scope = "onos", name = "pim-neighbors", |
| 32 | description = "Lists the PIM neighbors") |
| 33 | public 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 Hart | fbfe2a8 | 2016-03-29 11:36:33 -0700 | [diff] [blame] | 40 | PimInterfaceService interfaceService = get(PimInterfaceService.class); |
Jonathan Hart | 54119bb | 2016-02-06 18:48:27 -0800 | [diff] [blame] | 41 | |
Jonathan Hart | fbfe2a8 | 2016-03-29 11:36:33 -0700 | [diff] [blame] | 42 | Set<PimInterface> interfaces = interfaceService.getPimInterfaces(); |
Jonathan Hart | 54119bb | 2016-02-06 18:48:27 -0800 | [diff] [blame] | 43 | |
Jonathan Hart | fbfe2a8 | 2016-03-29 11:36:33 -0700 | [diff] [blame] | 44 | for (PimInterface intf : interfaces) { |
Jonathan Hart | 54119bb | 2016-02-06 18:48:27 -0800 | [diff] [blame] | 45 | print(INTF_FORMAT, intf.getInterface().name(), intf.getIpAddress()); |
Jonathan Hart | fbfe2a8 | 2016-03-29 11:36:33 -0700 | [diff] [blame] | 46 | for (PimNeighbor neighbor : intf.getNeighbors()) { |
Jonathan Hart | 54119bb | 2016-02-06 18:48:27 -0800 | [diff] [blame] | 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 | } |