alshabib | eff0054 | 2015-09-23 13:22:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014-2015 Open Networking Laboratory |
| 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.onosproject.pim.cli; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.JsonNode; |
| 19 | import org.apache.karaf.shell.commands.Command; |
| 20 | import org.onosproject.cli.AbstractShellCommand; |
| 21 | import org.onosproject.net.ConnectPoint; |
| 22 | import org.onosproject.pim.impl.PIMNeighbors; |
| 23 | import org.onosproject.pim.impl.PIMNeighborsCodec; |
| 24 | |
| 25 | import java.util.HashMap; |
| 26 | |
Rusty Eddy | 7ca3ed9 | 2015-10-06 01:32:03 +0000 | [diff] [blame^] | 27 | @Command(scope = "onos", name = "pim-neighbors", description = "Displays the pim neighbors") |
alshabib | eff0054 | 2015-09-23 13:22:33 -0700 | [diff] [blame] | 28 | public class PIMShowCommand extends AbstractShellCommand { |
| 29 | |
| 30 | // prints either the json or cli version of the hash map connect point |
| 31 | // neighbors from the PIMNeighbors class. |
| 32 | @Override |
| 33 | protected void execute() { |
| 34 | // grab connect point neighbors hash map to send in to json encoder. |
| 35 | HashMap<ConnectPoint, PIMNeighbors> pimNbrs = PIMNeighbors.getConnectPointNeighbors(); |
| 36 | if (outputJson()) { |
| 37 | print("%s", json(pimNbrs)); |
| 38 | } else { |
| 39 | print(PIMNeighbors.printPimNeighbors()); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | private JsonNode json(HashMap<ConnectPoint, PIMNeighbors> pimNbrs) { |
| 44 | return new PIMNeighborsCodec().encode(pimNbrs, this); |
| 45 | } |
| 46 | |
| 47 | } |