Jonathan Hart | c4f681c | 2016-09-09 07:14:25 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Jonathan Hart | c4f681c | 2016-09-09 07:14:25 -0700 | [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.cli.net; |
| 18 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 19 | import org.apache.karaf.shell.api.action.Command; |
| 20 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Jonathan Hart | c4f681c | 2016-09-09 07:14:25 -0700 | [diff] [blame] | 21 | import org.onosproject.cli.AbstractShellCommand; |
Ray Milkey | facf286 | 2017-08-03 11:58:29 -0700 | [diff] [blame] | 22 | import org.onosproject.net.intf.Interface; |
Ray Milkey | b65d784 | 2017-08-03 16:28:24 -0700 | [diff] [blame] | 23 | import org.onosproject.net.neighbour.NeighbourResolutionService; |
Jonathan Hart | c4f681c | 2016-09-09 07:14:25 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * Lists neighbour message handlers. |
| 27 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 28 | @Service |
Jonathan Hart | c4f681c | 2016-09-09 07:14:25 -0700 | [diff] [blame] | 29 | @Command(scope = "onos", name = "neighbour-handlers", |
| 30 | description = "Lists neighbour message handlers") |
| 31 | public class NeighbourHandlersListCommand extends AbstractShellCommand { |
| 32 | |
| 33 | private static final String FORMAT = "%20s: interface=%s, class=%s"; |
| 34 | |
| 35 | @Override |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 36 | protected void doExecute() { |
Jonathan Hart | c4f681c | 2016-09-09 07:14:25 -0700 | [diff] [blame] | 37 | NeighbourResolutionService service = get(NeighbourResolutionService.class); |
| 38 | |
| 39 | service.getHandlerRegistrations().forEach((cp, list) -> { |
| 40 | list.forEach(hr -> print(FORMAT, cp, intfToName(hr.intf()), |
| 41 | hr.handler().getClass().getCanonicalName())); |
| 42 | }); |
| 43 | } |
| 44 | |
| 45 | private String intfToName(Interface intf) { |
| 46 | return (intf == null) ? "(None)" : intf.name(); |
| 47 | } |
| 48 | } |