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