Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.sdnip; |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 17 | |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 18 | import java.util.Collection; |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 19 | import java.util.HashSet; |
| 20 | import java.util.Iterator; |
| 21 | import java.util.LinkedList; |
| 22 | import java.util.List; |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 23 | import java.util.Map; |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 24 | import java.util.Set; |
| 25 | import java.util.concurrent.BlockingQueue; |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 26 | import java.util.concurrent.ConcurrentHashMap; |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 27 | import java.util.concurrent.ExecutorService; |
| 28 | import java.util.concurrent.Executors; |
| 29 | import java.util.concurrent.LinkedBlockingQueue; |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 30 | |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 31 | import org.apache.commons.lang3.tuple.Pair; |
Jonathan Hart | 7dd4a33 | 2014-12-04 17:37:05 -0800 | [diff] [blame] | 32 | import org.onlab.packet.Ethernet; |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 33 | import org.onlab.packet.Ip4Address; |
Jonathan Hart | 7dd4a33 | 2014-12-04 17:37:05 -0800 | [diff] [blame] | 34 | import org.onlab.packet.IpAddress; |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 35 | import org.onlab.packet.IpPrefix; |
Jonathan Hart | 7dd4a33 | 2014-12-04 17:37:05 -0800 | [diff] [blame] | 36 | import org.onlab.packet.MacAddress; |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 37 | import org.onlab.packet.VlanId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 38 | import org.onosproject.core.ApplicationId; |
| 39 | import org.onosproject.net.ConnectPoint; |
| 40 | import org.onosproject.net.Host; |
| 41 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 42 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 43 | import org.onosproject.net.flow.TrafficSelector; |
| 44 | import org.onosproject.net.flow.TrafficTreatment; |
| 45 | import org.onosproject.net.host.HostEvent; |
| 46 | import org.onosproject.net.host.HostListener; |
| 47 | import org.onosproject.net.host.HostService; |
| 48 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; |
| 49 | import org.onosproject.sdnip.config.BgpPeer; |
| 50 | import org.onosproject.sdnip.config.Interface; |
| 51 | import org.onosproject.sdnip.config.SdnIpConfigurationService; |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 52 | import org.slf4j.Logger; |
| 53 | import org.slf4j.LoggerFactory; |
| 54 | |
Pingping | 3855f31 | 2014-10-22 12:50:37 -0700 | [diff] [blame] | 55 | import com.google.common.collect.HashMultimap; |
| 56 | import com.google.common.collect.Multimaps; |
| 57 | import com.google.common.collect.SetMultimap; |
| 58 | import com.google.common.util.concurrent.ThreadFactoryBuilder; |
| 59 | import com.googlecode.concurrenttrees.common.KeyValuePair; |
| 60 | import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory; |
| 61 | import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree; |
| 62 | import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree; |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 63 | |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 64 | /** |
| 65 | * This class processes BGP route update, translates each update into a intent |
| 66 | * and submits the intent. |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 67 | */ |
| 68 | public class Router implements RouteListener { |
| 69 | |
| 70 | private static final Logger log = LoggerFactory.getLogger(Router.class); |
| 71 | |
Jonathan Hart | 0b04bed | 2014-10-16 16:39:19 -0700 | [diff] [blame] | 72 | // Store all route updates in a radix tree. |
| 73 | // The key in this tree is the binary string of prefix of the route. |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 74 | private InvertedRadixTree<RouteEntry> ribTable4; |
| 75 | private InvertedRadixTree<RouteEntry> ribTable6; |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 76 | |
| 77 | // Stores all incoming route updates in a queue. |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 78 | private final BlockingQueue<Collection<RouteUpdate>> routeUpdatesQueue; |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 79 | |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 80 | // The IpAddress is the next hop address of each route update. |
| 81 | private final SetMultimap<IpAddress, RouteEntry> routesWaitingOnArp; |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 82 | |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 83 | // The IPv4 address to MAC address mapping |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 84 | private final Map<IpAddress, MacAddress> ip2Mac; |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 85 | |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 86 | private final ApplicationId appId; |
Pavlin Radoslavov | a071b1e | 2014-11-17 13:37:57 -0800 | [diff] [blame] | 87 | private final IntentSynchronizer intentSynchronizer; |
| 88 | private final HostService hostService; |
Jonathan Hart | 9965d77 | 2014-12-02 10:28:34 -0800 | [diff] [blame] | 89 | private final SdnIpConfigurationService configService; |
Pavlin Radoslavov | a071b1e | 2014-11-17 13:37:57 -0800 | [diff] [blame] | 90 | private final InterfaceService interfaceService; |
| 91 | private final ExecutorService bgpUpdatesExecutor; |
| 92 | private final HostListener hostListener; |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * Class constructor. |
| 96 | * |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 97 | * @param appId the application ID |
Pavlin Radoslavov | a071b1e | 2014-11-17 13:37:57 -0800 | [diff] [blame] | 98 | * @param intentSynchronizer the intent synchronizer |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 99 | * @param configService the configuration service |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 100 | * @param interfaceService the interface service |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 101 | * @param hostService the host service |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 102 | */ |
Pavlin Radoslavov | a071b1e | 2014-11-17 13:37:57 -0800 | [diff] [blame] | 103 | public Router(ApplicationId appId, IntentSynchronizer intentSynchronizer, |
Jonathan Hart | 9965d77 | 2014-12-02 10:28:34 -0800 | [diff] [blame] | 104 | SdnIpConfigurationService configService, |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 105 | InterfaceService interfaceService, |
| 106 | HostService hostService) { |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 107 | this.appId = appId; |
Pavlin Radoslavov | a071b1e | 2014-11-17 13:37:57 -0800 | [diff] [blame] | 108 | this.intentSynchronizer = intentSynchronizer; |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 109 | this.configService = configService; |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 110 | this.interfaceService = interfaceService; |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 111 | this.hostService = hostService; |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 112 | |
Pavlin Radoslavov | a071b1e | 2014-11-17 13:37:57 -0800 | [diff] [blame] | 113 | this.hostListener = new InternalHostListener(); |
| 114 | |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 115 | ribTable4 = new ConcurrentInvertedRadixTree<>( |
| 116 | new DefaultByteArrayNodeFactory()); |
| 117 | ribTable6 = new ConcurrentInvertedRadixTree<>( |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 118 | new DefaultByteArrayNodeFactory()); |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 119 | routeUpdatesQueue = new LinkedBlockingQueue<>(); |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 120 | routesWaitingOnArp = Multimaps.synchronizedSetMultimap( |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 121 | HashMultimap.<IpAddress, RouteEntry>create()); |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 122 | ip2Mac = new ConcurrentHashMap<>(); |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 123 | |
| 124 | bgpUpdatesExecutor = Executors.newSingleThreadExecutor( |
Pavlin Radoslavov | 8b75244 | 2014-11-18 14:34:37 -0800 | [diff] [blame] | 125 | new ThreadFactoryBuilder() |
| 126 | .setNameFormat("sdnip-bgp-updates-%d").build()); |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | /** |
Jonathan Hart | 739c835 | 2014-10-29 17:49:26 -0700 | [diff] [blame] | 130 | * Starts the router. |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 131 | */ |
| 132 | public void start() { |
Pavlin Radoslavov | a071b1e | 2014-11-17 13:37:57 -0800 | [diff] [blame] | 133 | this.hostService.addListener(hostListener); |
| 134 | |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 135 | bgpUpdatesExecutor.execute(new Runnable() { |
| 136 | @Override |
| 137 | public void run() { |
| 138 | doUpdatesThread(); |
| 139 | } |
| 140 | }); |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Jonathan Hart | 739c835 | 2014-10-29 17:49:26 -0700 | [diff] [blame] | 143 | /** |
Pavlin Radoslavov | a071b1e | 2014-11-17 13:37:57 -0800 | [diff] [blame] | 144 | * Stops the router. |
Jonathan Hart | 739c835 | 2014-10-29 17:49:26 -0700 | [diff] [blame] | 145 | */ |
Pavlin Radoslavov | a071b1e | 2014-11-17 13:37:57 -0800 | [diff] [blame] | 146 | public void stop() { |
| 147 | this.hostService.removeListener(hostListener); |
| 148 | |
| 149 | // Stop the thread(s) |
Jonathan Hart | 739c835 | 2014-10-29 17:49:26 -0700 | [diff] [blame] | 150 | bgpUpdatesExecutor.shutdownNow(); |
Pavlin Radoslavov | 7e19094 | 2014-11-13 18:50:59 -0800 | [diff] [blame] | 151 | |
| 152 | synchronized (this) { |
| 153 | // Cleanup all local state |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 154 | ribTable4 = new ConcurrentInvertedRadixTree<>( |
| 155 | new DefaultByteArrayNodeFactory()); |
| 156 | ribTable6 = new ConcurrentInvertedRadixTree<>( |
Pavlin Radoslavov | 7e19094 | 2014-11-13 18:50:59 -0800 | [diff] [blame] | 157 | new DefaultByteArrayNodeFactory()); |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 158 | routeUpdatesQueue.clear(); |
Pavlin Radoslavov | 7e19094 | 2014-11-13 18:50:59 -0800 | [diff] [blame] | 159 | routesWaitingOnArp.clear(); |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 160 | ip2Mac.clear(); |
Pavlin Radoslavov | 7e19094 | 2014-11-13 18:50:59 -0800 | [diff] [blame] | 161 | } |
Jonathan Hart | 739c835 | 2014-10-29 17:49:26 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 164 | @Override |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 165 | public void update(Collection<RouteUpdate> routeUpdates) { |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 166 | try { |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 167 | routeUpdatesQueue.put(routeUpdates); |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 168 | } catch (InterruptedException e) { |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 169 | log.debug("Interrupted while putting on routeUpdatesQueue", e); |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 170 | Thread.currentThread().interrupt(); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | /** |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 175 | * Thread for handling route updates. |
| 176 | */ |
| 177 | private void doUpdatesThread() { |
| 178 | boolean interrupted = false; |
| 179 | try { |
| 180 | while (!interrupted) { |
| 181 | try { |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 182 | Collection<RouteUpdate> routeUpdates = |
| 183 | routeUpdatesQueue.take(); |
| 184 | processRouteUpdates(routeUpdates); |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 185 | } catch (InterruptedException e) { |
| 186 | log.debug("Interrupted while taking from updates queue", e); |
| 187 | interrupted = true; |
| 188 | } catch (Exception e) { |
| 189 | log.debug("exception", e); |
| 190 | } |
| 191 | } |
| 192 | } finally { |
| 193 | if (interrupted) { |
| 194 | Thread.currentThread().interrupt(); |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | /** |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 200 | * Gets all IPv4 routes from the RIB. |
| 201 | * |
| 202 | * @return all IPv4 routes from the RIB |
| 203 | */ |
| 204 | public Collection<RouteEntry> getRoutes4() { |
| 205 | Iterator<KeyValuePair<RouteEntry>> it = |
| 206 | ribTable4.getKeyValuePairsForKeysStartingWith("").iterator(); |
| 207 | |
| 208 | List<RouteEntry> routes = new LinkedList<>(); |
| 209 | |
| 210 | while (it.hasNext()) { |
| 211 | KeyValuePair<RouteEntry> entry = it.next(); |
| 212 | routes.add(entry.getValue()); |
| 213 | } |
| 214 | |
| 215 | return routes; |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * Gets all IPv6 routes from the RIB. |
| 220 | * |
| 221 | * @return all IPv6 routes from the RIB |
| 222 | */ |
| 223 | public Collection<RouteEntry> getRoutes6() { |
| 224 | Iterator<KeyValuePair<RouteEntry>> it = |
| 225 | ribTable6.getKeyValuePairsForKeysStartingWith("").iterator(); |
| 226 | |
| 227 | List<RouteEntry> routes = new LinkedList<>(); |
| 228 | |
| 229 | while (it.hasNext()) { |
| 230 | KeyValuePair<RouteEntry> entry = it.next(); |
| 231 | routes.add(entry.getValue()); |
| 232 | } |
| 233 | |
| 234 | return routes; |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Finds a route in the RIB for a prefix. The prefix can be either IPv4 or |
| 239 | * IPv6. |
| 240 | * |
| 241 | * @param prefix the prefix to use |
| 242 | * @return the route if found, otherwise null |
| 243 | */ |
| 244 | RouteEntry findRibRoute(IpPrefix prefix) { |
| 245 | String binaryString = RouteEntry.createBinaryString(prefix); |
| 246 | if (prefix.version() == Ip4Address.VERSION) { |
| 247 | // IPv4 |
| 248 | return ribTable4.getValueForExactKey(binaryString); |
| 249 | } |
| 250 | // IPv6 |
| 251 | return ribTable6.getValueForExactKey(binaryString); |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * Adds a route to the RIB. The route can be either IPv4 or IPv6. |
| 256 | * |
| 257 | * @param routeEntry the route entry to use |
| 258 | */ |
| 259 | void addRibRoute(RouteEntry routeEntry) { |
| 260 | if (routeEntry.prefix().version() == Ip4Address.VERSION) { |
| 261 | // IPv4 |
| 262 | ribTable4.put(RouteEntry.createBinaryString(routeEntry.prefix()), |
| 263 | routeEntry); |
| 264 | } else { |
| 265 | // IPv6 |
| 266 | ribTable6.put(RouteEntry.createBinaryString(routeEntry.prefix()), |
| 267 | routeEntry); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * Removes a route for a prefix from the RIB. The prefix can be either IPv4 |
| 273 | * or IPv6. |
| 274 | * |
| 275 | * @param prefix the prefix to use |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 276 | * @return true if the route was found and removed, otherwise false |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 277 | */ |
| 278 | boolean removeRibRoute(IpPrefix prefix) { |
| 279 | if (prefix.version() == Ip4Address.VERSION) { |
| 280 | // IPv4 |
| 281 | return ribTable4.remove(RouteEntry.createBinaryString(prefix)); |
| 282 | } |
| 283 | // IPv6 |
| 284 | return ribTable6.remove(RouteEntry.createBinaryString(prefix)); |
| 285 | } |
| 286 | |
| 287 | /** |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 288 | * Processes route updates. |
| 289 | * |
| 290 | * @param routeUpdates the route updates to process |
| 291 | */ |
| 292 | void processRouteUpdates(Collection<RouteUpdate> routeUpdates) { |
| 293 | synchronized (this) { |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 294 | Collection<Pair<IpPrefix, MultiPointToSinglePointIntent>> |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 295 | submitIntents = new LinkedList<>(); |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 296 | Collection<IpPrefix> withdrawPrefixes = new LinkedList<>(); |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 297 | MultiPointToSinglePointIntent intent; |
| 298 | |
| 299 | for (RouteUpdate update : routeUpdates) { |
| 300 | switch (update.type()) { |
| 301 | case UPDATE: |
| 302 | intent = processRouteAdd(update.routeEntry(), |
| 303 | withdrawPrefixes); |
| 304 | if (intent != null) { |
| 305 | submitIntents.add(Pair.of(update.routeEntry().prefix(), |
| 306 | intent)); |
| 307 | } |
| 308 | break; |
| 309 | case DELETE: |
| 310 | processRouteDelete(update.routeEntry(), withdrawPrefixes); |
| 311 | break; |
| 312 | default: |
| 313 | log.error("Unknown update Type: {}", update.type()); |
| 314 | break; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | intentSynchronizer.updateRouteIntents(submitIntents, |
| 319 | withdrawPrefixes); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | /** |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 324 | * Processes adding a route entry. |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 325 | * <p> |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 326 | * The route entry is added to the radix tree. If there was an existing |
| 327 | * next hop for this prefix, but the next hop was different, then the |
| 328 | * old route entry is deleted. |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 329 | * </p> |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 330 | * <p> |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 331 | * NOTE: Currently, we don't handle routes if the next hop is within the |
| 332 | * SDN domain. |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 333 | * </p> |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 334 | * |
| 335 | * @param routeEntry the route entry to add |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 336 | * @param withdrawPrefixes the collection of accumulated prefixes whose |
| 337 | * intents will be withdrawn |
| 338 | * @return the corresponding intent that should be submitted, or null |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 339 | */ |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 340 | private MultiPointToSinglePointIntent processRouteAdd( |
| 341 | RouteEntry routeEntry, |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 342 | Collection<IpPrefix> withdrawPrefixes) { |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 343 | log.debug("Processing route add: {}", routeEntry); |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 344 | |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 345 | // Find the old next-hop if we are updating an old route entry |
| 346 | IpAddress oldNextHop = null; |
| 347 | RouteEntry oldRouteEntry = findRibRoute(routeEntry.prefix()); |
| 348 | if (oldRouteEntry != null) { |
| 349 | oldNextHop = oldRouteEntry.nextHop(); |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 350 | } |
| 351 | |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 352 | // Add the new route to the RIB |
| 353 | addRibRoute(routeEntry); |
| 354 | |
| 355 | if (oldNextHop != null) { |
| 356 | if (oldNextHop.equals(routeEntry.nextHop())) { |
| 357 | return null; // No change |
| 358 | } |
| 359 | // |
| 360 | // Update an existing nexthop for the prefix. |
| 361 | // We need to remove the old flows for this prefix from the |
| 362 | // switches before the new flows are added. |
| 363 | // |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 364 | withdrawPrefixes.add(routeEntry.prefix()); |
| 365 | } |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 366 | |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 367 | if (routeEntry.nextHop().isZero()) { |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 368 | // Route originated by SDN domain |
| 369 | // We don't handle these at the moment |
| 370 | log.debug("Own route {} to {}", |
| 371 | routeEntry.prefix(), routeEntry.nextHop()); |
| 372 | return null; |
| 373 | } |
| 374 | |
| 375 | // |
| 376 | // Find the MAC address of next hop router for this route entry. |
| 377 | // If the MAC address can not be found in ARP cache, then this prefix |
| 378 | // will be put in routesWaitingOnArp queue. Otherwise, generate |
| 379 | // a new route intent. |
| 380 | // |
| 381 | |
| 382 | // Monitor the IP address for updates of the MAC address |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 383 | hostService.startMonitoringIp(routeEntry.nextHop()); |
| 384 | |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 385 | // Check if we know the MAC address of the next hop |
| 386 | MacAddress nextHopMacAddress = ip2Mac.get(routeEntry.nextHop()); |
| 387 | if (nextHopMacAddress == null) { |
| 388 | Set<Host> hosts = hostService.getHostsByIp(routeEntry.nextHop()); |
| 389 | if (!hosts.isEmpty()) { |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 390 | nextHopMacAddress = hosts.iterator().next().mac(); |
| 391 | } |
| 392 | if (nextHopMacAddress != null) { |
| 393 | ip2Mac.put(routeEntry.nextHop(), nextHopMacAddress); |
| 394 | } |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 395 | } |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 396 | if (nextHopMacAddress == null) { |
| 397 | routesWaitingOnArp.put(routeEntry.nextHop(), routeEntry); |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 398 | return null; |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 399 | } |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 400 | return generateRouteIntent(routeEntry.prefix(), routeEntry.nextHop(), |
| 401 | nextHopMacAddress); |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | /** |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 405 | * Generates a route intent for a prefix, the next hop IP address, and |
| 406 | * the next hop MAC address. |
| 407 | * <p/> |
| 408 | * This method will find the egress interface for the intent. |
| 409 | * Intent will match dst IP prefix and rewrite dst MAC address at all other |
| 410 | * border switches, then forward packets according to dst MAC address. |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 411 | * |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 412 | * @param prefix IP prefix of the route to add |
| 413 | * @param nextHopIpAddress IP address of the next hop |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 414 | * @param nextHopMacAddress MAC address of the next hop |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 415 | * @return the generated intent, or null if no intent should be submitted |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 416 | */ |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 417 | private MultiPointToSinglePointIntent generateRouteIntent( |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 418 | IpPrefix prefix, |
| 419 | IpAddress nextHopIpAddress, |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 420 | MacAddress nextHopMacAddress) { |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 421 | |
| 422 | // Find the attachment point (egress interface) of the next hop |
| 423 | Interface egressInterface; |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 424 | if (configService.getBgpPeers().containsKey(nextHopIpAddress)) { |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 425 | // Route to a peer |
| 426 | log.debug("Route to peer {}", nextHopIpAddress); |
| 427 | BgpPeer peer = |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 428 | configService.getBgpPeers().get(nextHopIpAddress); |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 429 | egressInterface = |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 430 | interfaceService.getInterface(peer.connectPoint()); |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 431 | } else { |
| 432 | // Route to non-peer |
| 433 | log.debug("Route to non-peer {}", nextHopIpAddress); |
| 434 | egressInterface = |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 435 | interfaceService.getMatchingInterface(nextHopIpAddress); |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 436 | if (egressInterface == null) { |
| 437 | log.warn("No outgoing interface found for {}", |
| 438 | nextHopIpAddress); |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 439 | return null; |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 443 | // |
| 444 | // Generate the intent itself |
| 445 | // |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 446 | Set<ConnectPoint> ingressPorts = new HashSet<>(); |
Pavlin Radoslavov | a071b1e | 2014-11-17 13:37:57 -0800 | [diff] [blame] | 447 | ConnectPoint egressPort = egressInterface.connectPoint(); |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 448 | log.debug("Generating intent for prefix {}, next hop mac {}", |
| 449 | prefix, nextHopMacAddress); |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 450 | |
| 451 | for (Interface intf : interfaceService.getInterfaces()) { |
Jonathan Hart | 2e3eef3 | 2014-11-12 11:05:40 -0800 | [diff] [blame] | 452 | if (!intf.connectPoint().equals(egressInterface.connectPoint())) { |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 453 | ConnectPoint srcPort = intf.connectPoint(); |
| 454 | ingressPorts.add(srcPort); |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | // Match the destination IP prefix at the first hop |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 459 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 460 | if (prefix.version() == Ip4Address.VERSION) { |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 461 | selector.matchEthType(Ethernet.TYPE_IPV4); |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 462 | } else { |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 463 | selector.matchEthType(Ethernet.TYPE_IPV6); |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 464 | } |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 465 | selector.matchIPDst(prefix); |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 466 | |
| 467 | // Rewrite the destination MAC address |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 468 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder() |
| 469 | .setEthDst(nextHopMacAddress); |
| 470 | if (!egressInterface.vlan().equals(VlanId.NONE)) { |
| 471 | treatment.setVlanId(egressInterface.vlan()); |
| 472 | // If we set VLAN ID, we have to make sure a VLAN tag exists. |
| 473 | // TODO support no VLAN -> VLAN routing |
| 474 | selector.matchVlanId(VlanId.ANY); |
| 475 | } |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 476 | |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 477 | return new MultiPointToSinglePointIntent(appId, selector.build(), |
| 478 | treatment.build(), |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 479 | ingressPorts, egressPort); |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | /** |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 483 | * Processes the deletion of a route entry. |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 484 | * <p> |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 485 | * The prefix for the routing entry is removed from radix tree. |
| 486 | * If the operation is successful, the prefix is added to the collection |
| 487 | * of prefixes whose intents that will be withdrawn. |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 488 | * </p> |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 489 | * |
| 490 | * @param routeEntry the route entry to delete |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 491 | * @param withdrawPrefixes the collection of accumulated prefixes whose |
| 492 | * intents will be withdrawn |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 493 | */ |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 494 | private void processRouteDelete(RouteEntry routeEntry, |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 495 | Collection<IpPrefix> withdrawPrefixes) { |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 496 | log.debug("Processing route delete: {}", routeEntry); |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 497 | boolean isRemoved = removeRibRoute(routeEntry.prefix()); |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 498 | |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 499 | if (isRemoved) { |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 500 | // |
| 501 | // Only withdraw intents if an entry was actually removed from the |
| 502 | // tree. If no entry was removed, the <prefix, nexthop> wasn't |
| 503 | // there so it's probably already been removed and we don't |
| 504 | // need to do anything. |
| 505 | // |
| 506 | withdrawPrefixes.add(routeEntry.prefix()); |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 507 | } |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 508 | |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 509 | routesWaitingOnArp.remove(routeEntry.nextHop(), routeEntry); |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | /** |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 513 | * Signals the Router that the MAC to IP mapping has potentially been |
| 514 | * updated. This has the effect of updating the MAC address for any |
| 515 | * installed prefixes if it has changed, as well as installing any pending |
| 516 | * prefixes that were waiting for MAC resolution. |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 517 | * |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 518 | * @param ipAddress the IP address that an event was received for |
| 519 | * @param macAddress the most recently known MAC address for the IP address |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 520 | */ |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 521 | private void updateMac(IpAddress ipAddress, MacAddress macAddress) { |
| 522 | log.debug("Received updated MAC info: {} => {}", ipAddress, |
| 523 | macAddress); |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 524 | |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 525 | // |
| 526 | // We synchronize on "this" to prevent changes to the Radix tree |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 527 | // while we're pushing intents. If the tree changes, the |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 528 | // tree and the intents could get out of sync. |
| 529 | // |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 530 | synchronized (this) { |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 531 | Collection<Pair<IpPrefix, MultiPointToSinglePointIntent>> |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 532 | submitIntents = new LinkedList<>(); |
| 533 | MultiPointToSinglePointIntent intent; |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 534 | |
| 535 | Set<RouteEntry> routesToPush = |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 536 | routesWaitingOnArp.removeAll(ipAddress); |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 537 | |
| 538 | for (RouteEntry routeEntry : routesToPush) { |
| 539 | // These will always be adds |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 540 | RouteEntry foundRouteEntry = findRibRoute(routeEntry.prefix()); |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 541 | if (foundRouteEntry != null && |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 542 | foundRouteEntry.nextHop().equals(routeEntry.nextHop())) { |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 543 | // We only push prefix flows if the prefix is still in the |
Jonathan Hart | 0b04bed | 2014-10-16 16:39:19 -0700 | [diff] [blame] | 544 | // radix tree and the next hop is the same as our |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 545 | // update. |
| 546 | // The prefix could have been removed while we were waiting |
| 547 | // for the ARP, or the next hop could have changed. |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 548 | intent = generateRouteIntent(routeEntry.prefix(), |
| 549 | ipAddress, macAddress); |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 550 | if (intent != null) { |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 551 | submitIntents.add(Pair.of(routeEntry.prefix(), |
| 552 | intent)); |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 553 | } |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 554 | } else { |
Jonathan Hart | 31582d1 | 2014-10-22 13:52:41 -0700 | [diff] [blame] | 555 | log.debug("{} has been revoked before the MAC was resolved", |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 556 | routeEntry); |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 557 | } |
| 558 | } |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 559 | |
| 560 | if (!submitIntents.isEmpty()) { |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 561 | Collection<IpPrefix> withdrawPrefixes = new LinkedList<>(); |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 562 | intentSynchronizer.updateRouteIntents(submitIntents, |
| 563 | withdrawPrefixes); |
| 564 | } |
| 565 | |
| 566 | ip2Mac.put(ipAddress, macAddress); |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 567 | } |
| 568 | } |
| 569 | |
| 570 | /** |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 571 | * Listener for host events. |
| 572 | */ |
| 573 | class InternalHostListener implements HostListener { |
| 574 | @Override |
| 575 | public void event(HostEvent event) { |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 576 | log.debug("Received HostEvent {}", event); |
| 577 | |
| 578 | Host host = event.subject(); |
| 579 | switch (event.type()) { |
| 580 | case HOST_ADDED: |
| 581 | // FALLTHROUGH |
| 582 | case HOST_UPDATED: |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 583 | for (IpAddress ipAddress : host.ipAddresses()) { |
| 584 | updateMac(ipAddress, host.mac()); |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 585 | } |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 586 | break; |
| 587 | case HOST_REMOVED: |
Pavlin Radoslavov | 3a0a52e | 2015-01-06 17:41:37 -0800 | [diff] [blame] | 588 | for (IpAddress ipAddress : host.ipAddresses()) { |
| 589 | ip2Mac.remove(ipAddress); |
Pavlin Radoslavov | 248c2ae | 2014-12-02 09:51:25 -0800 | [diff] [blame] | 590 | } |
| 591 | break; |
| 592 | default: |
| 593 | break; |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 594 | } |
| 595 | } |
| 596 | } |
| 597 | } |