amit.ghosh | 6104cf5 | 2021-01-07 16:53:28 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 | package org.opencord.olttopology.cli; |
| 17 | |
| 18 | import org.apache.karaf.shell.api.action.Command; |
| 19 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
| 20 | import org.onosproject.cli.AbstractShellCommand; |
| 21 | import org.onosproject.net.ConnectPoint; |
| 22 | import org.opencord.olttopology.OltNeighborInfo; |
| 23 | import org.opencord.olttopology.OltTopologyInformationService; |
| 24 | |
| 25 | import java.util.Map; |
| 26 | |
| 27 | /** |
| 28 | * OLT Topology CLI Command. |
| 29 | * <p> |
| 30 | * Shows the current topology in the CLI. |
| 31 | */ |
| 32 | @Service |
| 33 | @Command(scope = "onos", name = "olt-topology", description = "OLT Topology CLI command") |
| 34 | public class OltTopologyGetCommand extends AbstractShellCommand { |
| 35 | |
| 36 | private static final String FORMAT = "%s"; |
| 37 | |
| 38 | private OltTopologyInformationService oltTopoSer = get(OltTopologyInformationService.class); |
| 39 | |
| 40 | @Override |
| 41 | protected void doExecute() { |
| 42 | oltTopoSer.getNeighbours().entrySet().forEach(this::display); |
| 43 | } |
| 44 | |
| 45 | private void display(Map.Entry<ConnectPoint, OltNeighborInfo> neighbor) { |
| 46 | print(FORMAT, neighbor.getValue()); |
| 47 | } |
| 48 | } |