Move PIM and Reactive routing to new route service.
Also remove old static router, fix CLI commands Change-Id: Ice1ded45b272ff93d9cdbf0f8def7b6bff9a681c
Showing
12 changed files
with
41 additions
and
413 deletions
... | @@ -28,10 +28,10 @@ import org.onosproject.incubator.net.intf.Interface; | ... | @@ -28,10 +28,10 @@ import org.onosproject.incubator.net.intf.Interface; |
28 | import org.onosproject.incubator.net.intf.InterfaceEvent; | 28 | import org.onosproject.incubator.net.intf.InterfaceEvent; |
29 | import org.onosproject.incubator.net.intf.InterfaceListener; | 29 | import org.onosproject.incubator.net.intf.InterfaceListener; |
30 | import org.onosproject.incubator.net.intf.InterfaceService; | 30 | import org.onosproject.incubator.net.intf.InterfaceService; |
31 | +import org.onosproject.incubator.net.routing.Route; | ||
32 | +import org.onosproject.incubator.net.routing.RouteService; | ||
31 | import org.onosproject.net.ConnectPoint; | 33 | import org.onosproject.net.ConnectPoint; |
32 | - | ||
33 | import org.onosproject.net.Host; | 34 | import org.onosproject.net.Host; |
34 | - | ||
35 | import org.onosproject.net.config.ConfigFactory; | 35 | import org.onosproject.net.config.ConfigFactory; |
36 | import org.onosproject.net.config.NetworkConfigEvent; | 36 | import org.onosproject.net.config.NetworkConfigEvent; |
37 | import org.onosproject.net.config.NetworkConfigListener; | 37 | import org.onosproject.net.config.NetworkConfigListener; |
... | @@ -43,8 +43,6 @@ import org.onosproject.net.mcast.McastListener; | ... | @@ -43,8 +43,6 @@ import org.onosproject.net.mcast.McastListener; |
43 | import org.onosproject.net.mcast.McastRoute; | 43 | import org.onosproject.net.mcast.McastRoute; |
44 | import org.onosproject.net.mcast.MulticastRouteService; | 44 | import org.onosproject.net.mcast.MulticastRouteService; |
45 | import org.onosproject.net.packet.PacketService; | 45 | import org.onosproject.net.packet.PacketService; |
46 | -import org.onosproject.routing.RouteEntry; | ||
47 | -import org.onosproject.routing.RoutingService; | ||
48 | import org.slf4j.Logger; | 46 | import org.slf4j.Logger; |
49 | 47 | ||
50 | import java.util.Map; | 48 | import java.util.Map; |
... | @@ -101,7 +99,7 @@ public class PimInterfaceManager implements PimInterfaceService { | ... | @@ -101,7 +99,7 @@ public class PimInterfaceManager implements PimInterfaceService { |
101 | protected MulticastRouteService multicastRouteService; | 99 | protected MulticastRouteService multicastRouteService; |
102 | 100 | ||
103 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 101 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
104 | - protected RoutingService unicastRoutingService; | 102 | + protected RouteService unicastRouteService; |
105 | 103 | ||
106 | // Store PIM Interfaces in a map key'd by ConnectPoint | 104 | // Store PIM Interfaces in a map key'd by ConnectPoint |
107 | private final Map<ConnectPoint, PimInterface> pimInterfaces = Maps.newConcurrentMap(); | 105 | private final Map<ConnectPoint, PimInterface> pimInterfaces = Maps.newConcurrentMap(); |
... | @@ -251,17 +249,17 @@ public class PimInterfaceManager implements PimInterfaceService { | ... | @@ -251,17 +249,17 @@ public class PimInterfaceManager implements PimInterfaceService { |
251 | } | 249 | } |
252 | 250 | ||
253 | private PimInterface getSourceInterface(McastRoute route) { | 251 | private PimInterface getSourceInterface(McastRoute route) { |
254 | - RouteEntry routeEntry = unicastRoutingService.getLongestMatchableRouteEntry(route.source()); | 252 | + Route unicastRoute = unicastRouteService.longestPrefixMatch(route.source()); |
255 | 253 | ||
256 | - if (routeEntry == null) { | 254 | + if (unicastRoute == null) { |
257 | log.warn("No route to source {}", route.source()); | 255 | log.warn("No route to source {}", route.source()); |
258 | return null; | 256 | return null; |
259 | } | 257 | } |
260 | 258 | ||
261 | - Interface intf = interfaceService.getMatchingInterface(routeEntry.nextHop()); | 259 | + Interface intf = interfaceService.getMatchingInterface(unicastRoute.nextHop()); |
262 | 260 | ||
263 | if (intf == null) { | 261 | if (intf == null) { |
264 | - log.warn("No interface with route to next hop {}", routeEntry.nextHop()); | 262 | + log.warn("No interface with route to next hop {}", unicastRoute.nextHop()); |
265 | return null; | 263 | return null; |
266 | } | 264 | } |
267 | 265 | ||
... | @@ -272,7 +270,7 @@ public class PimInterfaceManager implements PimInterfaceService { | ... | @@ -272,7 +270,7 @@ public class PimInterfaceManager implements PimInterfaceService { |
272 | return null; | 270 | return null; |
273 | } | 271 | } |
274 | 272 | ||
275 | - Set<Host> hosts = hostService.getHostsByIp(routeEntry.nextHop()); | 273 | + Set<Host> hosts = hostService.getHostsByIp(unicastRoute.nextHop()); |
276 | Host host = null; | 274 | Host host = null; |
277 | for (Host h : hosts) { | 275 | for (Host h : hosts) { |
278 | if (h.vlan().equals(intf.vlan())) { | 276 | if (h.vlan().equals(intf.vlan())) { |
... | @@ -280,11 +278,11 @@ public class PimInterfaceManager implements PimInterfaceService { | ... | @@ -280,11 +278,11 @@ public class PimInterfaceManager implements PimInterfaceService { |
280 | } | 278 | } |
281 | } | 279 | } |
282 | if (host == null) { | 280 | if (host == null) { |
283 | - log.warn("Next hop host entry not found: {}", routeEntry.nextHop()); | 281 | + log.warn("Next hop host entry not found: {}", unicastRoute.nextHop()); |
284 | return null; | 282 | return null; |
285 | } | 283 | } |
286 | 284 | ||
287 | - pimInterface.addRoute(route, routeEntry.nextHop(), host.mac()); | 285 | + pimInterface.addRoute(route, unicastRoute.nextHop(), host.mac()); |
288 | 286 | ||
289 | return pimInterface; | 287 | return pimInterface; |
290 | } | 288 | } | ... | ... |
... | @@ -15,16 +15,6 @@ | ... | @@ -15,16 +15,6 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.reactive.routing; | 16 | package org.onosproject.reactive.routing; |
17 | 17 | ||
18 | -import static com.google.common.base.Preconditions.checkNotNull; | ||
19 | -import static org.onlab.packet.Ethernet.TYPE_ARP; | ||
20 | -import static org.onlab.packet.Ethernet.TYPE_IPV4; | ||
21 | -import static org.onosproject.net.packet.PacketPriority.REACTIVE; | ||
22 | -import static org.slf4j.LoggerFactory.getLogger; | ||
23 | - | ||
24 | -import java.nio.ByteBuffer; | ||
25 | -import java.util.Optional; | ||
26 | -import java.util.Set; | ||
27 | - | ||
28 | import org.apache.felix.scr.annotations.Activate; | 18 | import org.apache.felix.scr.annotations.Activate; |
29 | import org.apache.felix.scr.annotations.Component; | 19 | import org.apache.felix.scr.annotations.Component; |
30 | import org.apache.felix.scr.annotations.Deactivate; | 20 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -43,6 +33,8 @@ import org.onosproject.core.ApplicationId; | ... | @@ -43,6 +33,8 @@ import org.onosproject.core.ApplicationId; |
43 | import org.onosproject.core.CoreService; | 33 | import org.onosproject.core.CoreService; |
44 | import org.onosproject.incubator.net.intf.Interface; | 34 | import org.onosproject.incubator.net.intf.Interface; |
45 | import org.onosproject.incubator.net.intf.InterfaceService; | 35 | import org.onosproject.incubator.net.intf.InterfaceService; |
36 | +import org.onosproject.incubator.net.routing.Route; | ||
37 | +import org.onosproject.incubator.net.routing.RouteService; | ||
46 | import org.onosproject.net.ConnectPoint; | 38 | import org.onosproject.net.ConnectPoint; |
47 | import org.onosproject.net.Host; | 39 | import org.onosproject.net.Host; |
48 | import org.onosproject.net.flow.DefaultTrafficSelector; | 40 | import org.onosproject.net.flow.DefaultTrafficSelector; |
... | @@ -58,11 +50,19 @@ import org.onosproject.net.packet.PacketProcessor; | ... | @@ -58,11 +50,19 @@ import org.onosproject.net.packet.PacketProcessor; |
58 | import org.onosproject.net.packet.PacketService; | 50 | import org.onosproject.net.packet.PacketService; |
59 | import org.onosproject.routing.IntentRequestListener; | 51 | import org.onosproject.routing.IntentRequestListener; |
60 | import org.onosproject.routing.IntentSynchronizationService; | 52 | import org.onosproject.routing.IntentSynchronizationService; |
61 | -import org.onosproject.routing.RouteEntry; | ||
62 | -import org.onosproject.routing.RoutingService; | ||
63 | import org.onosproject.routing.config.RoutingConfigurationService; | 53 | import org.onosproject.routing.config.RoutingConfigurationService; |
64 | import org.slf4j.Logger; | 54 | import org.slf4j.Logger; |
65 | 55 | ||
56 | +import java.nio.ByteBuffer; | ||
57 | +import java.util.Optional; | ||
58 | +import java.util.Set; | ||
59 | + | ||
60 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
61 | +import static org.onlab.packet.Ethernet.TYPE_ARP; | ||
62 | +import static org.onlab.packet.Ethernet.TYPE_IPV4; | ||
63 | +import static org.onosproject.net.packet.PacketPriority.REACTIVE; | ||
64 | +import static org.slf4j.LoggerFactory.getLogger; | ||
65 | + | ||
66 | /** | 66 | /** |
67 | * This is reactive routing to handle 3 cases: | 67 | * This is reactive routing to handle 3 cases: |
68 | * (1) one host wants to talk to another host, both two hosts are in | 68 | * (1) one host wants to talk to another host, both two hosts are in |
... | @@ -83,7 +83,7 @@ public class SdnIpReactiveRouting { | ... | @@ -83,7 +83,7 @@ public class SdnIpReactiveRouting { |
83 | protected PacketService packetService; | 83 | protected PacketService packetService; |
84 | 84 | ||
85 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 85 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
86 | - protected RoutingService routingService; | 86 | + protected RouteService routeService; |
87 | 87 | ||
88 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 88 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
89 | protected IntentSynchronizationService intentSynchronizer; | 89 | protected IntentSynchronizationService intentSynchronizer; |
... | @@ -230,7 +230,7 @@ public class SdnIpReactiveRouting { | ... | @@ -230,7 +230,7 @@ public class SdnIpReactiveRouting { |
230 | // Step1: Try to update the existing intent first if it exists. | 230 | // Step1: Try to update the existing intent first if it exists. |
231 | // | 231 | // |
232 | IpPrefix ipPrefix = null; | 232 | IpPrefix ipPrefix = null; |
233 | - RouteEntry routeEntry = null; | 233 | + Route route = null; |
234 | if (config.isIpAddressLocal(dstIpAddress)) { | 234 | if (config.isIpAddressLocal(dstIpAddress)) { |
235 | if (dstIpAddress.isIp4()) { | 235 | if (dstIpAddress.isIp4()) { |
236 | ipPrefix = IpPrefix.valueOf(dstIpAddress, | 236 | ipPrefix = IpPrefix.valueOf(dstIpAddress, |
... | @@ -241,9 +241,9 @@ public class SdnIpReactiveRouting { | ... | @@ -241,9 +241,9 @@ public class SdnIpReactiveRouting { |
241 | } | 241 | } |
242 | } else { | 242 | } else { |
243 | // Get IP prefix from BGP route table | 243 | // Get IP prefix from BGP route table |
244 | - routeEntry = routingService.getLongestMatchableRouteEntry(dstIpAddress); | 244 | + route = routeService.longestPrefixMatch(dstIpAddress); |
245 | - if (routeEntry != null) { | 245 | + if (route != null) { |
246 | - ipPrefix = routeEntry.prefix(); | 246 | + ipPrefix = route.prefix(); |
247 | } | 247 | } |
248 | } | 248 | } |
249 | if (ipPrefix != null | 249 | if (ipPrefix != null |
... | @@ -266,7 +266,7 @@ public class SdnIpReactiveRouting { | ... | @@ -266,7 +266,7 @@ public class SdnIpReactiveRouting { |
266 | // If the destination IP address is outside the local SDN network. | 266 | // If the destination IP address is outside the local SDN network. |
267 | // The Step 1 has already handled it. We do not need to do anything here. | 267 | // The Step 1 has already handled it. We do not need to do anything here. |
268 | intentRequestListener.setUpConnectivityHostToInternet(srcIpAddress, | 268 | intentRequestListener.setUpConnectivityHostToInternet(srcIpAddress, |
269 | - ipPrefix, routeEntry.nextHop()); | 269 | + ipPrefix, route.nextHop()); |
270 | break; | 270 | break; |
271 | case INTERNET_TO_HOST: | 271 | case INTERNET_TO_HOST: |
272 | intentRequestListener.setUpConnectivityInternetToHost(dstIpAddress); | 272 | intentRequestListener.setUpConnectivityInternetToHost(dstIpAddress); |
... | @@ -343,7 +343,7 @@ public class SdnIpReactiveRouting { | ... | @@ -343,7 +343,7 @@ public class SdnIpReactiveRouting { |
343 | private LocationType getLocationType(IpAddress ipAddress) { | 343 | private LocationType getLocationType(IpAddress ipAddress) { |
344 | if (config.isIpAddressLocal(ipAddress)) { | 344 | if (config.isIpAddressLocal(ipAddress)) { |
345 | return LocationType.LOCAL; | 345 | return LocationType.LOCAL; |
346 | - } else if (routingService.getLongestMatchableRouteEntry(ipAddress) != null) { | 346 | + } else if (routeService.longestPrefixMatch(ipAddress) != null) { |
347 | return LocationType.INTERNET; | 347 | return LocationType.INTERNET; |
348 | } else { | 348 | } else { |
349 | return LocationType.NO_ROUTE; | 349 | return LocationType.NO_ROUTE; |
... | @@ -362,9 +362,9 @@ public class SdnIpReactiveRouting { | ... | @@ -362,9 +362,9 @@ public class SdnIpReactiveRouting { |
362 | } | 362 | } |
363 | } else if (type == LocationType.INTERNET) { | 363 | } else if (type == LocationType.INTERNET) { |
364 | IpAddress nextHopIpAddress = null; | 364 | IpAddress nextHopIpAddress = null; |
365 | - RouteEntry routeEntry = routingService.getLongestMatchableRouteEntry(dstIpAddress); | 365 | + Route route = routeService.longestPrefixMatch(dstIpAddress); |
366 | - if (routeEntry != null) { | 366 | + if (route != null) { |
367 | - nextHopIpAddress = routeEntry.nextHop(); | 367 | + nextHopIpAddress = route.nextHop(); |
368 | Interface it = interfaceService.getMatchingInterface(nextHopIpAddress); | 368 | Interface it = interfaceService.getMatchingInterface(nextHopIpAddress); |
369 | if (it != null) { | 369 | if (it != null) { |
370 | return it.connectPoint(); | 370 | return it.connectPoint(); | ... | ... |
... | @@ -19,7 +19,10 @@ import java.util.Collection; | ... | @@ -19,7 +19,10 @@ import java.util.Collection; |
19 | 19 | ||
20 | /** | 20 | /** |
21 | * An interface to receive route updates from route providers. | 21 | * An interface to receive route updates from route providers. |
22 | + * | ||
23 | + * @deprecated in Goldeneye. Use RouteService instead. | ||
22 | */ | 24 | */ |
25 | +@Deprecated | ||
23 | public interface RouteListener { | 26 | public interface RouteListener { |
24 | /** | 27 | /** |
25 | * Receives a route update from a route provider. | 28 | * Receives a route update from a route provider. | ... | ... |
... | @@ -17,6 +17,8 @@ package org.onosproject.routing; | ... | @@ -17,6 +17,8 @@ package org.onosproject.routing; |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * A source of route updates. | 19 | * A source of route updates. |
20 | + * | ||
21 | + * @deprecated in Goldeneye. Use RouteService instead. | ||
20 | */ | 22 | */ |
21 | @Deprecated | 23 | @Deprecated |
22 | public interface RouteSourceService { | 24 | public interface RouteSourceService { | ... | ... |
... | @@ -23,7 +23,10 @@ import java.util.Collection; | ... | @@ -23,7 +23,10 @@ import java.util.Collection; |
23 | 23 | ||
24 | /** | 24 | /** |
25 | * Provides a way of interacting with the RIB management component. | 25 | * Provides a way of interacting with the RIB management component. |
26 | + * | ||
27 | + * @deprecated in Goldeneye. Use RouteService instead. | ||
26 | */ | 28 | */ |
29 | +@Deprecated | ||
27 | public interface RoutingService { | 30 | public interface RoutingService { |
28 | 31 | ||
29 | String ROUTER_APP_ID = "org.onosproject.router"; | 32 | String ROUTER_APP_ID = "org.onosproject.router"; | ... | ... |
1 | -/* | ||
2 | - * Copyright 2015-present 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.routing; | ||
17 | - | ||
18 | -/** | ||
19 | - * Convenience interface to obtain the FIB listener. | ||
20 | - */ | ||
21 | -public interface StaticRoutingService { | ||
22 | - | ||
23 | - FibListener getFibListener(); | ||
24 | -} |
1 | -/* | ||
2 | - * Copyright 2015-present 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.routing.cli; | ||
17 | - | ||
18 | -import org.apache.karaf.shell.commands.Argument; | ||
19 | -import org.apache.karaf.shell.commands.Command; | ||
20 | -import org.onlab.packet.IpAddress; | ||
21 | -import org.onlab.packet.IpPrefix; | ||
22 | -import org.onlab.packet.MacAddress; | ||
23 | -import org.onosproject.cli.AbstractShellCommand; | ||
24 | -import org.onosproject.routing.FibEntry; | ||
25 | -import org.onosproject.routing.FibListener; | ||
26 | -import org.onosproject.routing.FibUpdate; | ||
27 | -import org.onosproject.routing.StaticRoutingService; | ||
28 | - | ||
29 | -import java.util.Arrays; | ||
30 | -import java.util.Collections; | ||
31 | - | ||
32 | -@Command(scope = "onos", name = "add-route", description = "Installs static route") | ||
33 | -public class AddRouteCommand extends AbstractShellCommand { | ||
34 | - | ||
35 | - @Argument(index = 0, name = "prefix IP MAC", | ||
36 | - description = "prefix nexthopIP nexthopMAC", | ||
37 | - required = true, multiValued = true) | ||
38 | - String[] fibEntryString = null; | ||
39 | - | ||
40 | - @Override | ||
41 | - protected void execute() { | ||
42 | - StaticRoutingService routingService = get(StaticRoutingService.class); | ||
43 | - | ||
44 | - if (fibEntryString.length < 3) { | ||
45 | - return; | ||
46 | - } | ||
47 | - | ||
48 | - IpPrefix prefix = IpPrefix.valueOf(fibEntryString[0]); | ||
49 | - IpAddress nextHopIp = IpAddress.valueOf(fibEntryString[1]); | ||
50 | - MacAddress nextHopMac = MacAddress.valueOf(fibEntryString[2]); | ||
51 | - FibEntry fibEntry = new FibEntry(prefix, nextHopIp, nextHopMac); | ||
52 | - FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, fibEntry); | ||
53 | - | ||
54 | - FibListener fibListener = routingService.getFibListener(); | ||
55 | - fibListener.update(Arrays.asList(fibUpdate), Collections.emptyList()); | ||
56 | - } | ||
57 | -} |
1 | -/* | ||
2 | - * Copyright 2015-present 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.routing.cli; | ||
17 | - | ||
18 | -import org.apache.karaf.shell.commands.Argument; | ||
19 | -import org.apache.karaf.shell.commands.Command; | ||
20 | -import org.onlab.packet.IpAddress; | ||
21 | -import org.onlab.packet.IpPrefix; | ||
22 | -import org.onlab.packet.MacAddress; | ||
23 | -import org.onosproject.cli.AbstractShellCommand; | ||
24 | -import org.onosproject.routing.FibEntry; | ||
25 | -import org.onosproject.routing.FibListener; | ||
26 | -import org.onosproject.routing.FibUpdate; | ||
27 | -import org.onosproject.routing.StaticRoutingService; | ||
28 | - | ||
29 | -import java.util.Arrays; | ||
30 | -import java.util.Collections; | ||
31 | - | ||
32 | -@Command(scope = "onos", name = "remove-route", description = "Removes static route") | ||
33 | -public class RemoveRouteCommand extends AbstractShellCommand { | ||
34 | - @Argument(index = 0, name = "prefix IP MAC", | ||
35 | - description = "prefix nexthopIP nexthopMAC", | ||
36 | - required = true, multiValued = true) | ||
37 | - String[] fibEntryString = null; | ||
38 | - | ||
39 | - @Override | ||
40 | - protected void execute() { | ||
41 | - StaticRoutingService routingService = get(StaticRoutingService.class); | ||
42 | - | ||
43 | - if (fibEntryString.length < 3) { | ||
44 | - return; | ||
45 | - } | ||
46 | - | ||
47 | - IpPrefix prefix = IpPrefix.valueOf(fibEntryString[0]); | ||
48 | - IpAddress nextHopIp = IpAddress.valueOf(fibEntryString[1]); | ||
49 | - MacAddress nextHopMac = MacAddress.valueOf(fibEntryString[2]); | ||
50 | - FibEntry fibEntry = new FibEntry(prefix, nextHopIp, nextHopMac); | ||
51 | - FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.DELETE, fibEntry); | ||
52 | - | ||
53 | - FibListener fibListener = routingService.getFibListener(); | ||
54 | - fibListener.update(Collections.emptyList(), Arrays.asList(fibUpdate)); | ||
55 | - } | ||
56 | -} |
1 | -/* | ||
2 | - * Copyright 2015-present 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.routing.cli; | ||
17 | - | ||
18 | -import com.fasterxml.jackson.databind.JsonNode; | ||
19 | -import com.fasterxml.jackson.databind.ObjectMapper; | ||
20 | -import com.fasterxml.jackson.databind.node.ArrayNode; | ||
21 | -import com.fasterxml.jackson.databind.node.ObjectNode; | ||
22 | -import org.apache.karaf.shell.commands.Command; | ||
23 | -import org.apache.karaf.shell.commands.Option; | ||
24 | -import org.onosproject.cli.AbstractShellCommand; | ||
25 | -import org.onosproject.routing.RouteEntry; | ||
26 | -import org.onosproject.routing.RoutingService; | ||
27 | - | ||
28 | -import java.util.Collection; | ||
29 | - | ||
30 | -/** | ||
31 | - * Command to show the routes in the routing table. | ||
32 | - */ | ||
33 | -@Command(scope = "onos", name = "routes", | ||
34 | - description = "Lists all routes in the RIB") | ||
35 | -public class RoutesListCommand extends AbstractShellCommand { | ||
36 | - | ||
37 | - @Option(name = "-s", aliases = "--summary", | ||
38 | - description = "Show summary of routes", | ||
39 | - required = false, multiValued = false) | ||
40 | - private boolean routesSummary = false; | ||
41 | - | ||
42 | - private static final String FORMAT_SUMMARY_V4 = | ||
43 | - "Total IPv4 routes = %d"; | ||
44 | - private static final String FORMAT_SUMMARY_V6 = | ||
45 | - "Total IPv6 routes = %d"; | ||
46 | - private static final String FORMAT_HEADER = | ||
47 | - " Network Next Hop"; | ||
48 | - private static final String FORMAT_ROUTE = | ||
49 | - " %-18s %-15s"; | ||
50 | - | ||
51 | - @Override | ||
52 | - protected void execute() { | ||
53 | - RoutingService service = AbstractShellCommand.get(RoutingService.class); | ||
54 | - | ||
55 | - // Print summary of the routes | ||
56 | - if (routesSummary) { | ||
57 | - printSummary(service.getRoutes4(), service.getRoutes6()); | ||
58 | - return; | ||
59 | - } | ||
60 | - | ||
61 | - // Print all routes | ||
62 | - printRoutes(service.getRoutes4(), service.getRoutes6()); | ||
63 | - } | ||
64 | - | ||
65 | - /** | ||
66 | - * Prints summary of the routes. | ||
67 | - * | ||
68 | - * @param routes4 the IPv4 routes | ||
69 | - * @param routes6 the IPv6 routes | ||
70 | - */ | ||
71 | - private void printSummary(Collection<RouteEntry> routes4, | ||
72 | - Collection<RouteEntry> routes6) { | ||
73 | - if (outputJson()) { | ||
74 | - ObjectMapper mapper = new ObjectMapper(); | ||
75 | - ObjectNode result = mapper.createObjectNode(); | ||
76 | - result.put("totalRoutes4", routes4.size()); | ||
77 | - result.put("totalRoutes6", routes6.size()); | ||
78 | - print("%s", result); | ||
79 | - } else { | ||
80 | - print(FORMAT_SUMMARY_V4, routes4.size()); | ||
81 | - print(FORMAT_SUMMARY_V6, routes6.size()); | ||
82 | - } | ||
83 | - } | ||
84 | - | ||
85 | - /** | ||
86 | - * Prints all routes. | ||
87 | - * | ||
88 | - * @param routes4 the IPv4 routes to print | ||
89 | - * @param routes6 the IPv6 routes to print | ||
90 | - */ | ||
91 | - private void printRoutes(Collection<RouteEntry> routes4, | ||
92 | - Collection<RouteEntry> routes6) { | ||
93 | - if (outputJson()) { | ||
94 | - ObjectMapper mapper = new ObjectMapper(); | ||
95 | - ObjectNode result = mapper.createObjectNode(); | ||
96 | - result.set("routes4", json(routes4)); | ||
97 | - result.set("routes6", json(routes6)); | ||
98 | - print("%s", result); | ||
99 | - } else { | ||
100 | - // The IPv4 routes | ||
101 | - print(FORMAT_HEADER); | ||
102 | - for (RouteEntry route : routes4) { | ||
103 | - printRoute(route); | ||
104 | - } | ||
105 | - print(FORMAT_SUMMARY_V4, routes4.size()); | ||
106 | - print(""); // Empty separator line | ||
107 | - // The IPv6 routes | ||
108 | - print(FORMAT_HEADER); | ||
109 | - for (RouteEntry route : routes6) { | ||
110 | - printRoute(route); | ||
111 | - } | ||
112 | - print(FORMAT_SUMMARY_V6, routes6.size()); | ||
113 | - } | ||
114 | - } | ||
115 | - | ||
116 | - /** | ||
117 | - * Prints a route. | ||
118 | - * | ||
119 | - * @param route the route to print | ||
120 | - */ | ||
121 | - private void printRoute(RouteEntry route) { | ||
122 | - if (route != null) { | ||
123 | - print(FORMAT_ROUTE, route.prefix(), route.nextHop()); | ||
124 | - } | ||
125 | - } | ||
126 | - | ||
127 | - /** | ||
128 | - * Produces a JSON array of routes. | ||
129 | - * | ||
130 | - * @param routes the routes with the data | ||
131 | - * @return JSON array with the routes | ||
132 | - */ | ||
133 | - private JsonNode json(Collection<RouteEntry> routes) { | ||
134 | - ObjectMapper mapper = new ObjectMapper(); | ||
135 | - ArrayNode result = mapper.createArrayNode(); | ||
136 | - | ||
137 | - for (RouteEntry route : routes) { | ||
138 | - result.add(json(mapper, route)); | ||
139 | - } | ||
140 | - return result; | ||
141 | - } | ||
142 | - | ||
143 | - /** | ||
144 | - * Produces JSON object for a route. | ||
145 | - * | ||
146 | - * @param mapper the JSON object mapper to use | ||
147 | - * @param route the route with the data | ||
148 | - * @return JSON object for the route | ||
149 | - */ | ||
150 | - private ObjectNode json(ObjectMapper mapper, RouteEntry route) { | ||
151 | - ObjectNode result = mapper.createObjectNode(); | ||
152 | - | ||
153 | - result.put("prefix", route.prefix().toString()); | ||
154 | - result.put("nextHop", route.nextHop().toString()); | ||
155 | - | ||
156 | - return result; | ||
157 | - } | ||
158 | -} |
1 | -/* | ||
2 | - * Copyright 2015-present 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.routing.impl; | ||
17 | - | ||
18 | -import org.apache.felix.scr.annotations.Component; | ||
19 | -import org.apache.felix.scr.annotations.Service; | ||
20 | -import org.onlab.packet.IpAddress; | ||
21 | -import org.onosproject.routing.FibListener; | ||
22 | -import org.onosproject.routing.RouteEntry; | ||
23 | -import org.onosproject.routing.RoutingService; | ||
24 | -import org.onosproject.routing.StaticRoutingService; | ||
25 | - | ||
26 | -import java.util.Collection; | ||
27 | - | ||
28 | -/** | ||
29 | - * Static router maintains handle to FIB listener. | ||
30 | - * | ||
31 | - * TODO: implement getRoutes methods | ||
32 | - */ | ||
33 | -@Component(immediate = true, enabled = false) | ||
34 | -@Service | ||
35 | -public class StaticRouter implements RoutingService, StaticRoutingService { | ||
36 | - private FibListener fibListener; | ||
37 | - | ||
38 | - @Override | ||
39 | - public void start() { | ||
40 | - | ||
41 | - } | ||
42 | - | ||
43 | - @Override | ||
44 | - public void addFibListener(FibListener fibListener) { | ||
45 | - this.fibListener = fibListener; | ||
46 | - } | ||
47 | - | ||
48 | - @Override | ||
49 | - public void stop() { | ||
50 | - | ||
51 | - } | ||
52 | - | ||
53 | - @Override | ||
54 | - public Collection<RouteEntry> getRoutes4() { | ||
55 | - return null; | ||
56 | - } | ||
57 | - | ||
58 | - @Override | ||
59 | - public Collection<RouteEntry> getRoutes6() { | ||
60 | - return null; | ||
61 | - } | ||
62 | - | ||
63 | - @Override | ||
64 | - public RouteEntry getLongestMatchableRouteEntry(IpAddress ipAddress) { | ||
65 | - return null; | ||
66 | - } | ||
67 | - | ||
68 | - @Override | ||
69 | - public FibListener getFibListener() { | ||
70 | - return fibListener; | ||
71 | - } | ||
72 | - | ||
73 | -} |
... | @@ -23,15 +23,6 @@ | ... | @@ -23,15 +23,6 @@ |
23 | <action class="org.onosproject.routing.cli.BgpRoutesListCommand"/> | 23 | <action class="org.onosproject.routing.cli.BgpRoutesListCommand"/> |
24 | </command> | 24 | </command> |
25 | <command> | 25 | <command> |
26 | - <action class="org.onosproject.routing.cli.RoutesListCommand"/> | ||
27 | - </command> | ||
28 | - <command> | ||
29 | - <action class="org.onosproject.routing.cli.AddRouteCommand"/> | ||
30 | - </command> | ||
31 | - <command> | ||
32 | - <action class="org.onosproject.routing.cli.RemoveRouteCommand"/> | ||
33 | - </command> | ||
34 | - <command> | ||
35 | <action class="org.onosproject.routing.cli.BgpSpeakersListCommand"/> | 26 | <action class="org.onosproject.routing.cli.BgpSpeakersListCommand"/> |
36 | </command> | 27 | </command> |
37 | <command> | 28 | <command> | ... | ... |
... | @@ -27,8 +27,7 @@ import java.util.Map; | ... | @@ -27,8 +27,7 @@ import java.util.Map; |
27 | /** | 27 | /** |
28 | * Command to show the routes in the routing tables. | 28 | * Command to show the routes in the routing tables. |
29 | */ | 29 | */ |
30 | -// TODO update command name when we switch over to new rib | 30 | +@Command(scope = "onos", name = "routes", |
31 | -@Command(scope = "onos", name = "routes2", | ||
32 | description = "Lists all routes in the route store") | 31 | description = "Lists all routes in the route store") |
33 | public class RoutesListCommand extends AbstractShellCommand { | 32 | public class RoutesListCommand extends AbstractShellCommand { |
34 | 33 | ... | ... |
-
Please register or login to post a comment