Committed by
Gerrit Code Review
API for core-based unicast route service.
Change-Id: I5d20c02f90b74ef8013898da2520bfb19a54b5c0
Showing
6 changed files
with
390 additions
and
0 deletions
| 1 | +/* | ||
| 2 | + * Copyright 2016 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 | + | ||
| 17 | +package org.onosproject.incubator.net.routing; | ||
| 18 | + | ||
| 19 | +import org.onlab.packet.IpAddress; | ||
| 20 | +import org.onlab.packet.IpPrefix; | ||
| 21 | +import org.onlab.packet.MacAddress; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * Represents a route with the next hop MAC address resolved. | ||
| 25 | + */ | ||
| 26 | +public class ResolvedRoute { | ||
| 27 | + | ||
| 28 | + private final IpPrefix prefix; | ||
| 29 | + private final IpAddress nextHop; | ||
| 30 | + private final MacAddress nextHopMac; | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * Creates a new resolved route. | ||
| 34 | + * | ||
| 35 | + * @param route input route | ||
| 36 | + * @param nextHopMac next hop MAC address | ||
| 37 | + */ | ||
| 38 | + public ResolvedRoute(Route route, MacAddress nextHopMac) { | ||
| 39 | + this.prefix = route.prefix(); | ||
| 40 | + this.nextHop = route.nextHop(); | ||
| 41 | + this.nextHopMac = nextHopMac; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * Creates a new resolved route. | ||
| 46 | + * | ||
| 47 | + * @param prefix route prefix | ||
| 48 | + * @param nextHop route next hop IP address | ||
| 49 | + * @param nextHopMac next hop MAC address | ||
| 50 | + */ | ||
| 51 | + public ResolvedRoute(IpPrefix prefix, IpAddress nextHop, MacAddress nextHopMac) { | ||
| 52 | + this.prefix = prefix; | ||
| 53 | + this.nextHop = nextHop; | ||
| 54 | + this.nextHopMac = nextHopMac; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * Returns the IP prefix. | ||
| 59 | + * | ||
| 60 | + * @return IP prefix | ||
| 61 | + */ | ||
| 62 | + public IpPrefix prefix() { | ||
| 63 | + return prefix; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + /** | ||
| 67 | + * Returns the next hop IP address. | ||
| 68 | + * | ||
| 69 | + * @return IP address | ||
| 70 | + */ | ||
| 71 | + public IpAddress nextHop() { | ||
| 72 | + return nextHop; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + /** | ||
| 76 | + * Returns the next hop MAC address. | ||
| 77 | + * | ||
| 78 | + * @return MAC address | ||
| 79 | + */ | ||
| 80 | + public MacAddress nextHopMac() { | ||
| 81 | + return nextHopMac; | ||
| 82 | + } | ||
| 83 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2016 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 | + | ||
| 17 | +package org.onosproject.incubator.net.routing; | ||
| 18 | + | ||
| 19 | +import org.onlab.packet.IpAddress; | ||
| 20 | +import org.onlab.packet.IpPrefix; | ||
| 21 | + | ||
| 22 | +import java.util.Objects; | ||
| 23 | + | ||
| 24 | +import static com.google.common.base.Preconditions.checkArgument; | ||
| 25 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 26 | + | ||
| 27 | +/** | ||
| 28 | + * Represents a route. | ||
| 29 | + */ | ||
| 30 | +public class Route { | ||
| 31 | + | ||
| 32 | + private static final String VERSION_MISMATCH = | ||
| 33 | + "Prefix and next hop must be in the same address family"; | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * Source of the route. | ||
| 37 | + */ | ||
| 38 | + public enum Source { | ||
| 39 | + /** | ||
| 40 | + * Route came from the iBGP route source. | ||
| 41 | + */ | ||
| 42 | + BGP, | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * Route came from the FPM route source. | ||
| 46 | + */ | ||
| 47 | + FPM, | ||
| 48 | + | ||
| 49 | + /** | ||
| 50 | + * Route can from the static route source. | ||
| 51 | + */ | ||
| 52 | + STATIC, | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * Route source was not defined. | ||
| 56 | + */ | ||
| 57 | + UNDEFINED | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + private final Source source; | ||
| 61 | + private final IpPrefix prefix; | ||
| 62 | + private final IpAddress nextHop; | ||
| 63 | + | ||
| 64 | + /** | ||
| 65 | + * Creates a route. | ||
| 66 | + * | ||
| 67 | + * @param source route source | ||
| 68 | + * @param prefix IP prefix | ||
| 69 | + * @param nextHop | ||
| 70 | + */ | ||
| 71 | + public Route(Source source, IpPrefix prefix, IpAddress nextHop) { | ||
| 72 | + checkNotNull(prefix); | ||
| 73 | + checkNotNull(nextHop); | ||
| 74 | + checkArgument(prefix.version().equals(nextHop.version()), VERSION_MISMATCH); | ||
| 75 | + | ||
| 76 | + this.source = checkNotNull(source); | ||
| 77 | + this.prefix = prefix; | ||
| 78 | + this.nextHop = nextHop; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + /** | ||
| 82 | + * Returns the route source. | ||
| 83 | + * | ||
| 84 | + * @return route source | ||
| 85 | + */ | ||
| 86 | + public Source source() { | ||
| 87 | + return source; | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + /** | ||
| 91 | + * Returns the IP prefix of the route. | ||
| 92 | + * | ||
| 93 | + * @return IP prefix | ||
| 94 | + */ | ||
| 95 | + public IpPrefix prefix() { | ||
| 96 | + return prefix; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + /** | ||
| 100 | + * Returns the next hop IP address. | ||
| 101 | + * | ||
| 102 | + * @return next hop | ||
| 103 | + */ | ||
| 104 | + public IpAddress nextHop() { | ||
| 105 | + return nextHop; | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + @Override | ||
| 109 | + public int hashCode() { | ||
| 110 | + return Objects.hash(prefix, nextHop); | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + @Override | ||
| 114 | + public boolean equals(Object other) { | ||
| 115 | + if (this == other) { | ||
| 116 | + return true; | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + if (!(other instanceof Route)) { | ||
| 120 | + return false; | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + Route that = (Route) other; | ||
| 124 | + | ||
| 125 | + return Objects.equals(this.prefix, that.prefix) && | ||
| 126 | + Objects.equals(this.nextHop, that.nextHop); | ||
| 127 | + } | ||
| 128 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2016 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 | + | ||
| 17 | +package org.onosproject.incubator.net.routing; | ||
| 18 | + | ||
| 19 | +import org.onosproject.event.AbstractEvent; | ||
| 20 | + | ||
| 21 | +/** | ||
| 22 | + * Describes an event about a route. | ||
| 23 | + */ | ||
| 24 | +public class RouteEvent extends AbstractEvent<RouteEvent.Type, ResolvedRoute> { | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * Route event type. | ||
| 28 | + */ | ||
| 29 | + public enum Type { | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * Route is new. | ||
| 33 | + */ | ||
| 34 | + ROUTE_ADDED, | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * Route has updated information. | ||
| 38 | + */ | ||
| 39 | + ROUTE_UPDATED, | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * Route was removed. | ||
| 43 | + */ | ||
| 44 | + ROUTE_REMOVED | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * Creates a new route event. | ||
| 49 | + * | ||
| 50 | + * @param type event type | ||
| 51 | + * @param subject event subject | ||
| 52 | + */ | ||
| 53 | + public RouteEvent(Type type, ResolvedRoute subject) { | ||
| 54 | + super(type, subject); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * Creates a new route event. | ||
| 59 | + * | ||
| 60 | + * @param type event type | ||
| 61 | + * @param subject event subject | ||
| 62 | + * @param time event time | ||
| 63 | + */ | ||
| 64 | + protected RouteEvent(Type type, ResolvedRoute subject, long time) { | ||
| 65 | + super(type, subject, time); | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2016 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 | + | ||
| 17 | +package org.onosproject.incubator.net.routing; | ||
| 18 | + | ||
| 19 | +import org.onosproject.event.EventListener; | ||
| 20 | + | ||
| 21 | +/** | ||
| 22 | + * Listener for route events. | ||
| 23 | + */ | ||
| 24 | +public interface RouteListener extends EventListener<RouteEvent> { | ||
| 25 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2016 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 | + | ||
| 17 | +package org.onosproject.incubator.net.routing; | ||
| 18 | + | ||
| 19 | +import org.onlab.packet.IpAddress; | ||
| 20 | +import org.onosproject.event.ListenerService; | ||
| 21 | + | ||
| 22 | +import java.util.Collection; | ||
| 23 | + | ||
| 24 | +/** | ||
| 25 | + * IP unicast routing service. | ||
| 26 | + */ | ||
| 27 | +public interface RouteService extends ListenerService<RouteEvent, RouteListener> { | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * Gets all routes. | ||
| 31 | + * | ||
| 32 | + * @return collection of all routes | ||
| 33 | + */ | ||
| 34 | + Collection<Route> getRoutes(); | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * Gets routes learnt from a particular source. | ||
| 38 | + * | ||
| 39 | + * @param source route source | ||
| 40 | + * @return collection of routes | ||
| 41 | + */ | ||
| 42 | + Collection<Route> getRoutesFromSource(Route.Source source); | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * Gets the longest prefix route that matches the given IP address. | ||
| 46 | + * | ||
| 47 | + * @param ip IP addres | ||
| 48 | + * @return longest prefix matched route | ||
| 49 | + */ | ||
| 50 | + Route longestPrefixMatch(IpAddress ip); | ||
| 51 | + | ||
| 52 | + //TODO should mutation methods be pushed to a different interface? | ||
| 53 | + /** | ||
| 54 | + * Updates the given routes in the route service. | ||
| 55 | + * | ||
| 56 | + * @param routes collection of routes to update | ||
| 57 | + */ | ||
| 58 | + void update(Collection<Route> routes); | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * Withdraws the given routes from the route service. | ||
| 62 | + * | ||
| 63 | + * @param routes collection of routes to withdraw | ||
| 64 | + */ | ||
| 65 | + void withdraw(Collection<Route> routes); | ||
| 66 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2016 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 | + | ||
| 17 | +/** | ||
| 18 | + * Unicast routing service. | ||
| 19 | + */ | ||
| 20 | +package org.onosproject.incubator.net.routing; |
-
Please register or login to post a comment