Pier Luigi | b29144d | 2018-01-15 18:06:43 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-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.onosproject.cli.net; |
| 17 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 18 | import org.apache.karaf.shell.api.action.Command; |
| 19 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Pier Luigi | b29144d | 2018-01-15 18:06:43 +0100 | [diff] [blame] | 20 | import org.onosproject.cli.AbstractShellCommand; |
| 21 | import org.onosproject.net.ConnectPoint; |
| 22 | import org.onosproject.net.mcast.McastRoute; |
| 23 | import org.onosproject.net.mcast.MulticastRouteService; |
| 24 | |
| 25 | import java.util.Comparator; |
| 26 | import java.util.Set; |
| 27 | import java.util.stream.Collectors; |
| 28 | |
| 29 | /** |
| 30 | * Displays the source, multicast group flows entries. |
| 31 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 32 | @Service |
Pier Luigi | b29144d | 2018-01-15 18:06:43 +0100 | [diff] [blame] | 33 | @Command(scope = "onos", name = "mcast-routes", |
| 34 | description = "Lists routes in the mcast route store") |
| 35 | public class McastRoutesListCommand extends AbstractShellCommand { |
| 36 | |
| 37 | // Format for total |
| 38 | private static final String FORMAT_TOTAL = " Total: %d"; |
| 39 | |
| 40 | // Format for ipv4 |
| 41 | private static final String FORMAT_ROUTE = "%-1s %-18s %-15s %s %s"; |
| 42 | // Format for ipv6 |
| 43 | private static final String FORMAT_ROUTE6 = "%-1s %-40s %-36s %s %s"; |
| 44 | |
| 45 | // Table header |
| 46 | private static final String FORMAT_TABLE = "Table: %s"; |
| 47 | private static final String GROUP = "Group"; |
| 48 | private static final String SOURCE = "Source"; |
| 49 | private static final String ORIGIN = "Origin"; |
| 50 | private static final String SINKS = "Sinks"; |
| 51 | |
| 52 | @Override |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 53 | protected void doExecute() { |
Pier Luigi | b29144d | 2018-01-15 18:06:43 +0100 | [diff] [blame] | 54 | // Get the service |
| 55 | MulticastRouteService mcastService = get(MulticastRouteService.class); |
| 56 | // Get the routes |
| 57 | Set<McastRoute> routes = mcastService.getRoutes(); |
| 58 | // Filter ipv4 |
| 59 | Set<McastRoute> ipv4Routes = routes.stream() |
| 60 | .filter(mcastRoute -> mcastRoute.group().isIp4()) |
| 61 | .collect(Collectors.toSet()); |
| 62 | // Filter ipv6 |
| 63 | Set<McastRoute> ipv6Routes = routes.stream() |
| 64 | .filter(mcastRoute -> mcastRoute.group().isIp6()) |
| 65 | .collect(Collectors.toSet()); |
| 66 | // Print header |
| 67 | print(FORMAT_TABLE, "ipv4"); |
| 68 | print(FORMAT_ROUTE, "", GROUP, SOURCE, ORIGIN, SINKS); |
| 69 | // Print ipv4 mcast routing entries |
| 70 | ipv4Routes.stream() |
| 71 | .sorted(Comparator.comparing(McastRoute::group)) |
| 72 | .forEach(route -> { |
| 73 | // Get sinks |
| 74 | Set<ConnectPoint> sinks = mcastService.fetchSinks(route); |
| 75 | print(FORMAT_ROUTE, "", route.group(), route.source(), |
| 76 | route.type(), sinks.size()); |
| 77 | }); |
| 78 | print(FORMAT_TOTAL, ipv4Routes.size()); |
| 79 | print(""); |
| 80 | |
| 81 | // Print header |
| 82 | print(FORMAT_TABLE, "ipv6"); |
| 83 | print(FORMAT_ROUTE6, "", GROUP, SOURCE, ORIGIN, SINKS); |
| 84 | // Print ipv6 mcast routing entries |
| 85 | ipv6Routes.stream() |
| 86 | .sorted(Comparator.comparing(McastRoute::group)) |
| 87 | .forEach(route -> { |
| 88 | // Get sinks |
| 89 | Set<ConnectPoint> sinks = mcastService.fetchSinks(route); |
| 90 | print(FORMAT_ROUTE6, "", route.group(), route.source(), |
| 91 | route.type(), sinks.size()); |
| 92 | }); |
| 93 | print(FORMAT_TOTAL, ipv6Routes.size()); |
| 94 | print(""); |
| 95 | } |
| 96 | |
| 97 | |
| 98 | |
| 99 | } |