Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 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.sdnip; |
| 18 | |
| 19 | import com.google.common.collect.ImmutableList; |
Jonathan Hart | b14221c | 2016-03-07 09:55:50 -0800 | [diff] [blame] | 20 | import com.google.common.collect.Sets; |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 21 | import org.apache.felix.scr.annotations.Activate; |
| 22 | import org.apache.felix.scr.annotations.Component; |
| 23 | import org.apache.felix.scr.annotations.Deactivate; |
| 24 | import org.apache.felix.scr.annotations.Reference; |
| 25 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 26 | import org.onlab.packet.Ethernet; |
| 27 | import org.onlab.packet.IpAddress; |
| 28 | import org.onlab.packet.IpPrefix; |
| 29 | import org.onlab.packet.MacAddress; |
| 30 | import org.onlab.packet.VlanId; |
| 31 | import org.onosproject.core.ApplicationId; |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 32 | import org.onosproject.core.CoreService; |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 33 | import org.onosproject.incubator.net.intf.Interface; |
Jonathan Hart | b14221c | 2016-03-07 09:55:50 -0800 | [diff] [blame] | 34 | import org.onosproject.incubator.net.intf.InterfaceEvent; |
| 35 | import org.onosproject.incubator.net.intf.InterfaceListener; |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 36 | import org.onosproject.incubator.net.intf.InterfaceService; |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 37 | import org.onosproject.incubator.net.routing.ResolvedRoute; |
| 38 | import org.onosproject.incubator.net.routing.RouteEvent; |
| 39 | import org.onosproject.incubator.net.routing.RouteListener; |
| 40 | import org.onosproject.incubator.net.routing.RouteService; |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 41 | import org.onosproject.net.ConnectPoint; |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 42 | import org.onosproject.net.FilteredConnectPoint; |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 43 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 44 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 45 | import org.onosproject.net.flow.TrafficSelector; |
| 46 | import org.onosproject.net.flow.TrafficTreatment; |
| 47 | import org.onosproject.net.intent.Constraint; |
| 48 | import org.onosproject.net.intent.Key; |
| 49 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; |
| 50 | import org.onosproject.net.intent.constraint.PartialFailureConstraint; |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 51 | import org.onosproject.routing.IntentSynchronizationService; |
| 52 | import org.slf4j.Logger; |
| 53 | import org.slf4j.LoggerFactory; |
| 54 | |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 55 | import java.util.Map; |
| 56 | import java.util.Set; |
| 57 | import java.util.concurrent.ConcurrentHashMap; |
| 58 | |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 59 | /** |
| 60 | * FIB component of SDN-IP. |
| 61 | */ |
Jonathan Hart | c22e847 | 2015-11-17 18:25:45 -0800 | [diff] [blame] | 62 | @Component(immediate = true, enabled = false) |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 63 | public class SdnIpFib { |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 64 | private Logger log = LoggerFactory.getLogger(getClass()); |
| 65 | |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 66 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 67 | protected InterfaceService interfaceService; |
| 68 | |
| 69 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 70 | protected IntentSynchronizationService intentSynchronizer; |
| 71 | |
| 72 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 73 | protected CoreService coreService; |
| 74 | |
| 75 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 76 | protected RouteService routeService; |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 77 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 78 | private final InternalRouteListener routeListener = new InternalRouteListener(); |
Jonathan Hart | b14221c | 2016-03-07 09:55:50 -0800 | [diff] [blame] | 79 | private final InternalInterfaceListener interfaceListener = new InternalInterfaceListener(); |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 80 | |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 81 | private static final int PRIORITY_OFFSET = 100; |
| 82 | private static final int PRIORITY_MULTIPLIER = 5; |
| 83 | protected static final ImmutableList<Constraint> CONSTRAINTS |
| 84 | = ImmutableList.of(new PartialFailureConstraint()); |
| 85 | |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 86 | private final Map<IpPrefix, MultiPointToSinglePointIntent> routeIntents |
| 87 | = new ConcurrentHashMap<>(); |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 88 | |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 89 | private ApplicationId appId; |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 90 | |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 91 | @Activate |
| 92 | public void activate() { |
| 93 | appId = coreService.getAppId(SdnIp.SDN_IP_APP); |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 94 | |
Jonathan Hart | b14221c | 2016-03-07 09:55:50 -0800 | [diff] [blame] | 95 | interfaceService.addListener(interfaceListener); |
| 96 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 97 | routeService.addListener(routeListener); |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 98 | } |
| 99 | |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 100 | @Deactivate |
| 101 | public void deactivate() { |
Jonathan Hart | b14221c | 2016-03-07 09:55:50 -0800 | [diff] [blame] | 102 | interfaceService.removeListener(interfaceListener); |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 103 | routeService.removeListener(routeListener); |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 104 | } |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 105 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 106 | private void update(ResolvedRoute route) { |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 107 | synchronized (this) { |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 108 | IpPrefix prefix = route.prefix(); |
| 109 | MultiPointToSinglePointIntent intent = |
| 110 | generateRouteIntent(prefix, route.nextHop(), route.nextHopMac()); |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 111 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 112 | if (intent == null) { |
| 113 | log.debug("SDN-IP no interface found for route {}", route); |
| 114 | return; |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 115 | } |
| 116 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 117 | routeIntents.put(prefix, intent); |
| 118 | intentSynchronizer.submit(intent); |
| 119 | } |
| 120 | } |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 121 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 122 | private void withdraw(ResolvedRoute route) { |
| 123 | synchronized (this) { |
| 124 | IpPrefix prefix = route.prefix(); |
| 125 | MultiPointToSinglePointIntent intent = routeIntents.remove(prefix); |
| 126 | if (intent == null) { |
| 127 | log.trace("SDN-IP no intent in routeIntents to delete " + |
| 128 | "for prefix: {}", prefix); |
| 129 | return; |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 130 | } |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 131 | intentSynchronizer.withdraw(intent); |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 132 | } |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Generates a route intent for a prefix, the next hop IP address, and |
| 137 | * the next hop MAC address. |
| 138 | * <p/> |
| 139 | * This method will find the egress interface for the intent. |
| 140 | * Intent will match dst IP prefix and rewrite dst MAC address at all other |
| 141 | * border switches, then forward packets according to dst MAC address. |
| 142 | * |
| 143 | * @param prefix IP prefix of the route to add |
| 144 | * @param nextHopIpAddress IP address of the next hop |
| 145 | * @param nextHopMacAddress MAC address of the next hop |
| 146 | * @return the generated intent, or null if no intent should be submitted |
| 147 | */ |
| 148 | private MultiPointToSinglePointIntent generateRouteIntent( |
| 149 | IpPrefix prefix, |
| 150 | IpAddress nextHopIpAddress, |
| 151 | MacAddress nextHopMacAddress) { |
| 152 | |
| 153 | // Find the attachment point (egress interface) of the next hop |
Pingping Lin | 92ca491 | 2015-11-19 16:41:54 -0800 | [diff] [blame] | 154 | Interface egressInterface = |
| 155 | interfaceService.getMatchingInterface(nextHopIpAddress); |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 156 | if (egressInterface == null) { |
| 157 | log.warn("No outgoing interface found for {}", |
| 158 | nextHopIpAddress); |
| 159 | return null; |
| 160 | } |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 161 | ConnectPoint egressPort = egressInterface.connectPoint(); |
Luca Prete | e951151 | 2016-05-13 10:30:19 -0700 | [diff] [blame] | 162 | |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 163 | log.debug("Generating intent for prefix {}, next hop mac {}", |
| 164 | prefix, nextHopMacAddress); |
| 165 | |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 166 | Set<FilteredConnectPoint> ingressFilteredCPs = Sets.newHashSet(); |
Luca Prete | e951151 | 2016-05-13 10:30:19 -0700 | [diff] [blame] | 167 | |
Luca Prete | e951151 | 2016-05-13 10:30:19 -0700 | [diff] [blame] | 168 | // TODO this should be only peering interfaces |
Sho SHIMIZU | 8ebb04a | 2016-10-06 15:58:29 -0700 | [diff] [blame] | 169 | interfaceService.getInterfaces().forEach(intf -> { |
| 170 | // Get ony ingress interfaces with IPs configured |
| 171 | if (validIngressIntf(intf, egressInterface)) { |
| 172 | TrafficSelector.Builder selector = |
| 173 | buildIngressTrafficSelector(intf, prefix); |
| 174 | FilteredConnectPoint ingressFilteredCP = |
| 175 | new FilteredConnectPoint(intf.connectPoint(), selector.build()); |
| 176 | ingressFilteredCPs.add(ingressFilteredCP); |
| 177 | } |
| 178 | }); |
Luca Prete | e951151 | 2016-05-13 10:30:19 -0700 | [diff] [blame] | 179 | |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 180 | // Build treatment: rewrite the destination MAC address |
| 181 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder() |
| 182 | .setEthDst(nextHopMacAddress); |
Luca Prete | e951151 | 2016-05-13 10:30:19 -0700 | [diff] [blame] | 183 | |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 184 | // Build the egress selector for VLAN Id |
| 185 | TrafficSelector.Builder selector = |
| 186 | buildTrafficSelector(egressInterface); |
| 187 | FilteredConnectPoint egressFilteredCP = |
| 188 | new FilteredConnectPoint(egressPort, selector.build()); |
| 189 | |
| 190 | // Set priority |
| 191 | int priority = |
| 192 | prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET; |
| 193 | |
| 194 | // Set key |
| 195 | Key key = Key.of(prefix.toString(), appId); |
| 196 | |
| 197 | return MultiPointToSinglePointIntent.builder() |
| 198 | .appId(appId) |
| 199 | .key(key) |
| 200 | .filteredIngressPoints(ingressFilteredCPs) |
| 201 | .filteredEgressPoint(egressFilteredCP) |
| 202 | .treatment(treatment.build()) |
| 203 | .priority(priority) |
| 204 | .constraints(CONSTRAINTS) |
| 205 | .build(); |
| 206 | } |
| 207 | |
| 208 | private void addInterface(Interface intf) { |
| 209 | synchronized (this) { |
| 210 | for (Map.Entry<IpPrefix, MultiPointToSinglePointIntent> entry : routeIntents.entrySet()) { |
| 211 | // Retrieve the IP prefix and affected intent |
| 212 | IpPrefix prefix = entry.getKey(); |
| 213 | MultiPointToSinglePointIntent intent = entry.getValue(); |
| 214 | |
| 215 | // Add new ingress FilteredConnectPoint |
| 216 | Set<FilteredConnectPoint> ingressFilteredCPs = |
| 217 | Sets.newHashSet(intent.filteredIngressPoints()); |
| 218 | |
| 219 | // Create the new traffic selector |
| 220 | TrafficSelector.Builder selector = |
| 221 | buildIngressTrafficSelector(intf, prefix); |
| 222 | |
| 223 | // Create the Filtered ConnectPoint and add it to the existing set |
| 224 | FilteredConnectPoint newIngressFilteredCP = |
| 225 | new FilteredConnectPoint(intf.connectPoint(), selector.build()); |
| 226 | ingressFilteredCPs.add(newIngressFilteredCP); |
| 227 | |
| 228 | // Create new intent |
| 229 | MultiPointToSinglePointIntent newIntent = |
| 230 | MultiPointToSinglePointIntent.builder(intent) |
| 231 | .filteredIngressPoints(ingressFilteredCPs) |
| 232 | .build(); |
| 233 | |
| 234 | routeIntents.put(entry.getKey(), newIntent); |
| 235 | intentSynchronizer.submit(newIntent); |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 236 | } |
| 237 | } |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | /* |
| 241 | * Handles the case in which an existing interface gets removed. |
| 242 | */ |
| 243 | private void removeInterface(Interface intf) { |
| 244 | synchronized (this) { |
| 245 | for (Map.Entry<IpPrefix, MultiPointToSinglePointIntent> entry : routeIntents.entrySet()) { |
| 246 | // Retrieve the IP prefix and intent possibly affected |
| 247 | IpPrefix prefix = entry.getKey(); |
| 248 | MultiPointToSinglePointIntent intent = entry.getValue(); |
| 249 | |
| 250 | // The interface removed might be an ingress interface, so the |
| 251 | // selector needs to match on the interface tagging params and |
| 252 | // on the prefix |
| 253 | TrafficSelector.Builder ingressSelector = |
| 254 | buildIngressTrafficSelector(intf, prefix); |
| 255 | FilteredConnectPoint removedIngressFilteredCP = |
| 256 | new FilteredConnectPoint(intf.connectPoint(), |
| 257 | ingressSelector.build()); |
| 258 | |
| 259 | // The interface removed might be an egress interface, so the |
| 260 | // selector needs to match only on the interface tagging params |
| 261 | TrafficSelector.Builder selector = buildTrafficSelector(intf); |
| 262 | FilteredConnectPoint removedEgressFilteredCP = |
| 263 | new FilteredConnectPoint(intf.connectPoint(), selector.build()); |
| 264 | |
| 265 | if (intent.filteredEgressPoint().equals(removedEgressFilteredCP)) { |
| 266 | // The interface is an egress interface for the intent. |
| 267 | // This intent just lost its head. Remove it and let higher |
| 268 | // layer routing reroute |
| 269 | intentSynchronizer.withdraw(routeIntents.remove(entry.getKey())); |
| 270 | } else { |
| 271 | if (intent.filteredIngressPoints().contains(removedIngressFilteredCP)) { |
| 272 | // The FilteredConnectPoint is an ingress |
| 273 | // FilteredConnectPoint for the intent |
| 274 | Set<FilteredConnectPoint> ingressFilteredCPs = |
| 275 | Sets.newHashSet(intent.filteredIngressPoints()); |
| 276 | |
| 277 | // Remove FilteredConnectPoint from the existing set |
| 278 | ingressFilteredCPs.remove(removedIngressFilteredCP); |
| 279 | |
| 280 | if (!ingressFilteredCPs.isEmpty()) { |
| 281 | // There are still ingress points. Create a new |
| 282 | // intent and resubmit |
| 283 | MultiPointToSinglePointIntent newIntent = |
| 284 | MultiPointToSinglePointIntent.builder(intent) |
| 285 | .filteredIngressPoints(ingressFilteredCPs) |
| 286 | .build(); |
| 287 | |
| 288 | routeIntents.put(entry.getKey(), newIntent); |
| 289 | intentSynchronizer.submit(newIntent); |
| 290 | } else { |
| 291 | // No more ingress FilteredConnectPoint. Withdraw |
| 292 | //the intent |
| 293 | intentSynchronizer.withdraw(routeIntents.remove(entry.getKey())); |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | /* |
| 302 | * Builds an ingress traffic selector builder given an ingress interface and |
| 303 | * the IP prefix to be reached. |
| 304 | */ |
| 305 | private TrafficSelector.Builder buildIngressTrafficSelector(Interface intf, IpPrefix prefix) { |
| 306 | TrafficSelector.Builder selector = buildTrafficSelector(intf); |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 307 | |
| 308 | // Match the destination IP prefix at the first hop |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 309 | if (prefix.isIp4()) { |
| 310 | selector.matchEthType(Ethernet.TYPE_IPV4); |
Pingping Lin | 92ca491 | 2015-11-19 16:41:54 -0800 | [diff] [blame] | 311 | // if it is default route, then we do not need match destination |
| 312 | // IP address |
| 313 | if (prefix.prefixLength() != 0) { |
| 314 | selector.matchIPDst(prefix); |
| 315 | } |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 316 | } else { |
| 317 | selector.matchEthType(Ethernet.TYPE_IPV6); |
Pingping Lin | 92ca491 | 2015-11-19 16:41:54 -0800 | [diff] [blame] | 318 | // if it is default route, then we do not need match destination |
| 319 | // IP address |
| 320 | if (prefix.prefixLength() != 0) { |
| 321 | selector.matchIPv6Dst(prefix); |
| 322 | } |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 323 | } |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 324 | return selector; |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 325 | } |
| 326 | |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 327 | /* |
| 328 | * Builds a traffic selector builder based on interface tagging settings. |
| 329 | */ |
| 330 | private TrafficSelector.Builder buildTrafficSelector(Interface intf) { |
| 331 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
Jonathan Hart | b14221c | 2016-03-07 09:55:50 -0800 | [diff] [blame] | 332 | |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 333 | // TODO: Consider other tag types |
| 334 | // Match the VlanId if specified in the network interface configuration |
| 335 | VlanId vlanId = intf.vlan(); |
| 336 | if (!vlanId.equals(VlanId.NONE)) { |
| 337 | selector.matchVlanId(vlanId); |
Jonathan Hart | b14221c | 2016-03-07 09:55:50 -0800 | [diff] [blame] | 338 | } |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 339 | return selector; |
Jonathan Hart | b14221c | 2016-03-07 09:55:50 -0800 | [diff] [blame] | 340 | } |
| 341 | |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 342 | // Check if the interface is an ingress interface with IPs configured |
| 343 | private boolean validIngressIntf(Interface intf, Interface egressInterface) { |
| 344 | if (!intf.equals(egressInterface) && |
| 345 | !intf.ipAddressesList().isEmpty() && |
| 346 | // TODO: An egress point might have two routers connected on different interfaces |
| 347 | !intf.connectPoint().equals(egressInterface.connectPoint())) { |
| 348 | return true; |
Jonathan Hart | b14221c | 2016-03-07 09:55:50 -0800 | [diff] [blame] | 349 | } |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 350 | return false; |
Jonathan Hart | b14221c | 2016-03-07 09:55:50 -0800 | [diff] [blame] | 351 | } |
| 352 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 353 | private class InternalRouteListener implements RouteListener { |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 354 | @Override |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 355 | public void event(RouteEvent event) { |
| 356 | switch (event.type()) { |
| 357 | case ROUTE_ADDED: |
| 358 | case ROUTE_UPDATED: |
| 359 | update(event.subject()); |
| 360 | break; |
| 361 | case ROUTE_REMOVED: |
| 362 | withdraw(event.subject()); |
| 363 | break; |
| 364 | default: |
| 365 | break; |
| 366 | } |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | |
Jonathan Hart | b14221c | 2016-03-07 09:55:50 -0800 | [diff] [blame] | 370 | private class InternalInterfaceListener implements InterfaceListener { |
| 371 | |
| 372 | @Override |
| 373 | public void event(InterfaceEvent event) { |
| 374 | switch (event.type()) { |
| 375 | case INTERFACE_ADDED: |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 376 | addInterface(event.subject()); |
Jonathan Hart | b14221c | 2016-03-07 09:55:50 -0800 | [diff] [blame] | 377 | break; |
| 378 | case INTERFACE_UPDATED: |
Luca Prete | e4a5e1a | 2016-09-07 17:01:22 -0700 | [diff] [blame] | 379 | removeInterface(event.prevSubject()); |
| 380 | addInterface(event.subject()); |
Jonathan Hart | b14221c | 2016-03-07 09:55:50 -0800 | [diff] [blame] | 381 | break; |
| 382 | case INTERFACE_REMOVED: |
| 383 | removeInterface(event.subject()); |
| 384 | break; |
| 385 | default: |
| 386 | break; |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | |
Jonathan Hart | 9a426f8 | 2015-09-03 15:43:13 +0200 | [diff] [blame] | 391 | } |