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.mfwd.cli; |
| 17 | |
| 18 | import org.apache.karaf.shell.commands.Command; |
alshabib | eff0054 | 2015-09-23 13:22:33 -0700 | [diff] [blame] | 19 | |
Rusty Eddy | c0e3fea | 2015-09-28 21:20:41 +0000 | [diff] [blame^] | 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 21 | import com.fasterxml.jackson.databind.JsonNode; |
| 22 | |
| 23 | import org.onosproject.cli.AbstractShellCommand; |
| 24 | import org.onosproject.mfwd.impl.McastRouteTable; |
| 25 | import org.onosproject.mfwd.impl.MRibCodec; |
alshabib | eff0054 | 2015-09-23 13:22:33 -0700 | [diff] [blame] | 26 | |
| 27 | import org.slf4j.Logger; |
alshabib | eff0054 | 2015-09-23 13:22:33 -0700 | [diff] [blame] | 28 | import static org.slf4j.LoggerFactory.getLogger; |
| 29 | |
| 30 | /** |
| 31 | * Displays the source, multicast group flows entries. |
| 32 | */ |
| 33 | @Command(scope = "onos", name = "mcast-show", description = "Displays the source, multicast group flows") |
| 34 | public class McastShowCommand extends AbstractShellCommand { |
| 35 | |
| 36 | private final Logger log = getLogger(getClass()); |
Rusty Eddy | c0e3fea | 2015-09-28 21:20:41 +0000 | [diff] [blame^] | 37 | private static final String MCAST_GROUP = "mcastgroup"; |
alshabib | eff0054 | 2015-09-23 13:22:33 -0700 | [diff] [blame] | 38 | |
| 39 | @Override |
| 40 | protected void execute() { |
| 41 | McastRouteTable mrt = McastRouteTable.getInstance(); |
| 42 | if (outputJson()) { |
| 43 | print("%s", json(mrt)); |
| 44 | } else { |
| 45 | printMrib4(mrt); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | public JsonNode json(McastRouteTable mrt) { |
Rusty Eddy | c0e3fea | 2015-09-28 21:20:41 +0000 | [diff] [blame^] | 50 | ObjectNode pushContent = new MRibCodec().encode(mrt , this); |
| 51 | return pushContent; |
alshabib | eff0054 | 2015-09-23 13:22:33 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Displays multicast route table entries. |
| 56 | * |
Rusty Eddy | c0e3fea | 2015-09-28 21:20:41 +0000 | [diff] [blame^] | 57 | * @param mrt Mutlicast Route Table |
alshabib | eff0054 | 2015-09-23 13:22:33 -0700 | [diff] [blame] | 58 | */ |
| 59 | protected void printMrib4(McastRouteTable mrt) { |
| 60 | print(mrt.printMcastRouteTable()); |
| 61 | } |
| 62 | } |