blob: 0ef7e389dac19f2fbc83ebf689389e27aa063927 [file] [log] [blame]
alshabibeff00542015-09-23 13:22:33 -07001/*
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 */
16package org.onosproject.pim.cli;
17
18import com.fasterxml.jackson.databind.JsonNode;
19import org.apache.karaf.shell.commands.Command;
20import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.net.ConnectPoint;
22import org.onosproject.pim.impl.PIMNeighbors;
23import org.onosproject.pim.impl.PIMNeighborsCodec;
24
25import java.util.HashMap;
26
Rusty Eddy7ca3ed92015-10-06 01:32:03 +000027@Command(scope = "onos", name = "pim-neighbors", description = "Displays the pim neighbors")
alshabibeff00542015-09-23 13:22:33 -070028public 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}