blob: 8ba768b27f0d9617fadea7622215bae01c640525 [file] [log] [blame]
Jonathan Hartc4f681c2016-09-09 07:14:25 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Jonathan Hartc4f681c2016-09-09 07:14:25 -07003 *
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.cli.net;
18
19import org.apache.karaf.shell.commands.Command;
20import org.onosproject.cli.AbstractShellCommand;
Ray Milkeyfacf2862017-08-03 11:58:29 -070021import org.onosproject.net.intf.Interface;
Ray Milkeyb65d7842017-08-03 16:28:24 -070022import org.onosproject.net.neighbour.NeighbourResolutionService;
Jonathan Hartc4f681c2016-09-09 07:14:25 -070023
24/**
25 * Lists neighbour message handlers.
26 */
27@Command(scope = "onos", name = "neighbour-handlers",
28 description = "Lists neighbour message handlers")
29public class NeighbourHandlersListCommand extends AbstractShellCommand {
30
31 private static final String FORMAT = "%20s: interface=%s, class=%s";
32
33 @Override
34 protected void execute() {
35 NeighbourResolutionService service = get(NeighbourResolutionService.class);
36
37 service.getHandlerRegistrations().forEach((cp, list) -> {
38 list.forEach(hr -> print(FORMAT, cp, intfToName(hr.intf()),
39 hr.handler().getClass().getCanonicalName()));
40 });
41 }
42
43 private String intfToName(Interface intf) {
44 return (intf == null) ? "(None)" : intf.name();
45 }
46}