Rusty Eddy | 4ae5aa8 | 2015-12-15 12:58:27 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Rusty Eddy | 4ae5aa8 | 2015-12-15 12:58:27 -0800 | [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 | package org.onosproject.pim.impl; |
| 17 | |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableSet; |
Rusty Eddy | 4ae5aa8 | 2015-12-15 12:58:27 -0800 | [diff] [blame] | 19 | import com.google.common.collect.Maps; |
| 20 | import org.apache.felix.scr.annotations.Activate; |
| 21 | import org.apache.felix.scr.annotations.Component; |
| 22 | import org.apache.felix.scr.annotations.Deactivate; |
| 23 | import org.apache.felix.scr.annotations.Reference; |
| 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 25 | import org.apache.felix.scr.annotations.Service; |
Jonathan Hart | 54119bb | 2016-02-06 18:48:27 -0800 | [diff] [blame] | 26 | import org.onlab.util.SafeRecurringTask; |
Rusty Eddy | 4ae5aa8 | 2015-12-15 12:58:27 -0800 | [diff] [blame] | 27 | import org.onosproject.incubator.net.intf.Interface; |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 28 | import org.onosproject.incubator.net.intf.InterfaceEvent; |
| 29 | import org.onosproject.incubator.net.intf.InterfaceListener; |
Rusty Eddy | 4ae5aa8 | 2015-12-15 12:58:27 -0800 | [diff] [blame] | 30 | import org.onosproject.incubator.net.intf.InterfaceService; |
Jonathan Hart | 92ca5d3 | 2016-04-14 18:05:52 -0700 | [diff] [blame] | 31 | import org.onosproject.incubator.net.routing.Route; |
| 32 | import org.onosproject.incubator.net.routing.RouteService; |
Rusty Eddy | 4ae5aa8 | 2015-12-15 12:58:27 -0800 | [diff] [blame] | 33 | import org.onosproject.net.ConnectPoint; |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 34 | import org.onosproject.net.Host; |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 35 | import org.onosproject.net.config.ConfigFactory; |
| 36 | import org.onosproject.net.config.NetworkConfigEvent; |
| 37 | import org.onosproject.net.config.NetworkConfigListener; |
| 38 | import org.onosproject.net.config.NetworkConfigRegistry; |
| 39 | import org.onosproject.net.config.basics.SubjectFactories; |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 40 | import org.onosproject.net.host.HostService; |
| 41 | import org.onosproject.net.mcast.McastEvent; |
| 42 | import org.onosproject.net.mcast.McastListener; |
| 43 | import org.onosproject.net.mcast.McastRoute; |
| 44 | import org.onosproject.net.mcast.MulticastRouteService; |
Jonathan Hart | 36fd31e | 2016-01-28 15:55:31 -0800 | [diff] [blame] | 45 | import org.onosproject.net.packet.PacketService; |
Rusty Eddy | 4ae5aa8 | 2015-12-15 12:58:27 -0800 | [diff] [blame] | 46 | import org.slf4j.Logger; |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 47 | |
Rusty Eddy | 4ae5aa8 | 2015-12-15 12:58:27 -0800 | [diff] [blame] | 48 | import java.util.Map; |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 49 | import java.util.Set; |
Rusty Eddy | 4d5a92f | 2016-01-25 17:12:14 -0800 | [diff] [blame] | 50 | import java.util.concurrent.Executors; |
| 51 | import java.util.concurrent.ScheduledExecutorService; |
| 52 | import java.util.concurrent.TimeUnit; |
Rusty Eddy | 4ae5aa8 | 2015-12-15 12:58:27 -0800 | [diff] [blame] | 53 | |
| 54 | import static org.slf4j.LoggerFactory.getLogger; |
| 55 | |
| 56 | /** |
| 57 | * Manages PIMInterfaces. |
| 58 | * |
| 59 | * TODO: Do we need to add a ServiceListener? |
| 60 | */ |
| 61 | @Component(immediate = true) |
| 62 | @Service |
Jonathan Hart | fbfe2a8 | 2016-03-29 11:36:33 -0700 | [diff] [blame] | 63 | public class PimInterfaceManager implements PimInterfaceService { |
Rusty Eddy | 4ae5aa8 | 2015-12-15 12:58:27 -0800 | [diff] [blame] | 64 | |
| 65 | private final Logger log = getLogger(getClass()); |
| 66 | |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 67 | private static final Class<PimInterfaceConfig> PIM_INTERFACE_CONFIG_CLASS = PimInterfaceConfig.class; |
| 68 | private static final String PIM_INTERFACE_CONFIG_KEY = "pimInterface"; |
Rusty Eddy | 4ae5aa8 | 2015-12-15 12:58:27 -0800 | [diff] [blame] | 69 | |
Jonathan Hart | 6be7095 | 2016-02-12 21:11:26 -0800 | [diff] [blame] | 70 | public static final int DEFAULT_HELLO_INTERVAL = 30; // seconds |
| 71 | |
| 72 | private static final int DEFAULT_TASK_PERIOD_MS = 250; |
Jonathan Hart | 54119bb | 2016-02-06 18:48:27 -0800 | [diff] [blame] | 73 | |
| 74 | // Create a Scheduled Executor service for recurring tasks |
| 75 | private final ScheduledExecutorService scheduledExecutorService = |
Rusty Eddy | 4d5a92f | 2016-01-25 17:12:14 -0800 | [diff] [blame] | 76 | Executors.newScheduledThreadPool(1); |
| 77 | |
Jonathan Hart | 6be7095 | 2016-02-12 21:11:26 -0800 | [diff] [blame] | 78 | private final long initialHelloDelay = 1000; |
Rusty Eddy | 4d5a92f | 2016-01-25 17:12:14 -0800 | [diff] [blame] | 79 | |
Jonathan Hart | 6be7095 | 2016-02-12 21:11:26 -0800 | [diff] [blame] | 80 | private final long pimHelloPeriod = DEFAULT_TASK_PERIOD_MS; |
Rusty Eddy | 4ae5aa8 | 2015-12-15 12:58:27 -0800 | [diff] [blame] | 81 | |
Jonathan Hart | 6be7095 | 2016-02-12 21:11:26 -0800 | [diff] [blame] | 82 | private final int timeoutTaskPeriod = DEFAULT_TASK_PERIOD_MS; |
Jonathan Hart | 54119bb | 2016-02-06 18:48:27 -0800 | [diff] [blame] | 83 | |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 84 | private final int joinTaskPeriod = 10000; |
| 85 | |
Jonathan Hart | 36fd31e | 2016-01-28 15:55:31 -0800 | [diff] [blame] | 86 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 87 | protected PacketService packetService; |
| 88 | |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 89 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 90 | protected NetworkConfigRegistry networkConfig; |
| 91 | |
| 92 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 93 | protected InterfaceService interfaceService; |
| 94 | |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 95 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 96 | protected HostService hostService; |
| 97 | |
| 98 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 99 | protected MulticastRouteService multicastRouteService; |
| 100 | |
| 101 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Jonathan Hart | 92ca5d3 | 2016-04-14 18:05:52 -0700 | [diff] [blame] | 102 | protected RouteService unicastRouteService; |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 103 | |
Rusty Eddy | 4ae5aa8 | 2015-12-15 12:58:27 -0800 | [diff] [blame] | 104 | // Store PIM Interfaces in a map key'd by ConnectPoint |
Jonathan Hart | fbfe2a8 | 2016-03-29 11:36:33 -0700 | [diff] [blame] | 105 | private final Map<ConnectPoint, PimInterface> pimInterfaces = Maps.newConcurrentMap(); |
Rusty Eddy | 4ae5aa8 | 2015-12-15 12:58:27 -0800 | [diff] [blame] | 106 | |
Jonathan Hart | fbfe2a8 | 2016-03-29 11:36:33 -0700 | [diff] [blame] | 107 | private final Map<McastRoute, PimInterface> routes = Maps.newConcurrentMap(); |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 108 | |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 109 | private final InternalNetworkConfigListener configListener = |
| 110 | new InternalNetworkConfigListener(); |
| 111 | private final InternalInterfaceListener interfaceListener = |
| 112 | new InternalInterfaceListener(); |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 113 | private final InternalMulticastListener multicastListener = |
| 114 | new InternalMulticastListener(); |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 115 | |
| 116 | private final ConfigFactory<ConnectPoint, PimInterfaceConfig> pimConfigFactory |
| 117 | = new ConfigFactory<ConnectPoint, PimInterfaceConfig>( |
| 118 | SubjectFactories.CONNECT_POINT_SUBJECT_FACTORY, PIM_INTERFACE_CONFIG_CLASS, |
| 119 | PIM_INTERFACE_CONFIG_KEY) { |
| 120 | |
| 121 | @Override |
| 122 | public PimInterfaceConfig createConfig() { |
| 123 | return new PimInterfaceConfig(); |
| 124 | } |
| 125 | }; |
| 126 | |
Rusty Eddy | 4ae5aa8 | 2015-12-15 12:58:27 -0800 | [diff] [blame] | 127 | @Activate |
| 128 | public void activate() { |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 129 | networkConfig.registerConfigFactory(pimConfigFactory); |
Rusty Eddy | 4ae5aa8 | 2015-12-15 12:58:27 -0800 | [diff] [blame] | 130 | |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 131 | // Create PIM Interfaces for each of the existing configured interfaces. |
| 132 | Set<ConnectPoint> subjects = networkConfig.getSubjects( |
| 133 | ConnectPoint.class, PIM_INTERFACE_CONFIG_CLASS); |
| 134 | for (ConnectPoint cp : subjects) { |
| 135 | PimInterfaceConfig config = networkConfig.getConfig(cp, PIM_INTERFACE_CONFIG_CLASS); |
| 136 | updateInterface(config); |
Rusty Eddy | 4ae5aa8 | 2015-12-15 12:58:27 -0800 | [diff] [blame] | 137 | } |
Rusty Eddy | 4d5a92f | 2016-01-25 17:12:14 -0800 | [diff] [blame] | 138 | |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 139 | networkConfig.addListener(configListener); |
| 140 | interfaceService.addListener(interfaceListener); |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 141 | multicastRouteService.addListener(multicastListener); |
| 142 | |
| 143 | multicastRouteService.getRoutes().forEach(this::addRoute); |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 144 | |
Rusty Eddy | 4d5a92f | 2016-01-25 17:12:14 -0800 | [diff] [blame] | 145 | // Schedule the periodic hello sender. |
Jonathan Hart | 54119bb | 2016-02-06 18:48:27 -0800 | [diff] [blame] | 146 | scheduledExecutorService.scheduleAtFixedRate( |
| 147 | SafeRecurringTask.wrap( |
Jonathan Hart | fbfe2a8 | 2016-03-29 11:36:33 -0700 | [diff] [blame] | 148 | () -> pimInterfaces.values().forEach(PimInterface::sendHello)), |
Jonathan Hart | 6be7095 | 2016-02-12 21:11:26 -0800 | [diff] [blame] | 149 | initialHelloDelay, pimHelloPeriod, TimeUnit.MILLISECONDS); |
Jonathan Hart | 54119bb | 2016-02-06 18:48:27 -0800 | [diff] [blame] | 150 | |
| 151 | // Schedule task to periodically time out expired neighbors |
| 152 | scheduledExecutorService.scheduleAtFixedRate( |
| 153 | SafeRecurringTask.wrap( |
Jonathan Hart | fbfe2a8 | 2016-03-29 11:36:33 -0700 | [diff] [blame] | 154 | () -> pimInterfaces.values().forEach(PimInterface::checkNeighborTimeouts)), |
Jonathan Hart | 54119bb | 2016-02-06 18:48:27 -0800 | [diff] [blame] | 155 | 0, timeoutTaskPeriod, TimeUnit.MILLISECONDS); |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 156 | |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 157 | scheduledExecutorService.scheduleAtFixedRate( |
| 158 | SafeRecurringTask.wrap( |
Jonathan Hart | fbfe2a8 | 2016-03-29 11:36:33 -0700 | [diff] [blame] | 159 | () -> pimInterfaces.values().forEach(PimInterface::sendJoins)), |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 160 | 0, joinTaskPeriod, TimeUnit.MILLISECONDS); |
| 161 | |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 162 | log.info("Started"); |
Rusty Eddy | 4ae5aa8 | 2015-12-15 12:58:27 -0800 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | @Deactivate |
| 166 | public void deactivate() { |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 167 | interfaceService.removeListener(interfaceListener); |
| 168 | networkConfig.removeListener(configListener); |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 169 | multicastRouteService.removeListener(multicastListener); |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 170 | networkConfig.unregisterConfigFactory(pimConfigFactory); |
Rusty Eddy | 4d5a92f | 2016-01-25 17:12:14 -0800 | [diff] [blame] | 171 | |
| 172 | // Shutdown the periodic hello task. |
Jonathan Hart | 54119bb | 2016-02-06 18:48:27 -0800 | [diff] [blame] | 173 | scheduledExecutorService.shutdown(); |
Rusty Eddy | 4d5a92f | 2016-01-25 17:12:14 -0800 | [diff] [blame] | 174 | |
Rusty Eddy | 4ae5aa8 | 2015-12-15 12:58:27 -0800 | [diff] [blame] | 175 | log.info("Stopped"); |
| 176 | } |
| 177 | |
Rusty Eddy | 4ae5aa8 | 2015-12-15 12:58:27 -0800 | [diff] [blame] | 178 | @Override |
Jonathan Hart | fbfe2a8 | 2016-03-29 11:36:33 -0700 | [diff] [blame] | 179 | public PimInterface getPimInterface(ConnectPoint cp) { |
| 180 | PimInterface pi = pimInterfaces.get(cp); |
Jonathan Hart | 7f4bc52 | 2016-02-20 11:32:43 -0800 | [diff] [blame] | 181 | if (pi == null && log.isTraceEnabled()) { |
| 182 | log.trace("We have been asked for an Interface we don't have: {}", cp); |
Rusty Eddy | 4ae5aa8 | 2015-12-15 12:58:27 -0800 | [diff] [blame] | 183 | } |
| 184 | return pi; |
| 185 | } |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 186 | |
| 187 | @Override |
Jonathan Hart | fbfe2a8 | 2016-03-29 11:36:33 -0700 | [diff] [blame] | 188 | public Set<PimInterface> getPimInterfaces() { |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 189 | return ImmutableSet.copyOf(pimInterfaces.values()); |
| 190 | } |
| 191 | |
| 192 | private void updateInterface(PimInterfaceConfig config) { |
| 193 | ConnectPoint cp = config.subject(); |
| 194 | |
| 195 | if (!config.isEnabled()) { |
| 196 | removeInterface(cp); |
| 197 | return; |
| 198 | } |
| 199 | |
| 200 | String intfName = config.getInterfaceName(); |
| 201 | Interface intf = interfaceService.getInterfaceByName(cp, intfName); |
| 202 | |
| 203 | if (intf == null) { |
| 204 | log.debug("Interface configuration missing: {}", config.getInterfaceName()); |
| 205 | return; |
| 206 | } |
| 207 | |
| 208 | |
| 209 | log.debug("Updating Interface for " + intf.connectPoint().toString()); |
| 210 | pimInterfaces.computeIfAbsent(cp, k -> buildPimInterface(config, intf)); |
| 211 | } |
| 212 | |
| 213 | private void removeInterface(ConnectPoint cp) { |
| 214 | pimInterfaces.remove(cp); |
| 215 | } |
| 216 | |
Jonathan Hart | fbfe2a8 | 2016-03-29 11:36:33 -0700 | [diff] [blame] | 217 | private PimInterface buildPimInterface(PimInterfaceConfig config, Interface intf) { |
| 218 | PimInterface.Builder builder = PimInterface.builder() |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 219 | .withPacketService(packetService) |
| 220 | .withInterface(intf); |
| 221 | |
Sho SHIMIZU | ef7e290 | 2016-02-12 18:38:29 -0800 | [diff] [blame] | 222 | config.getHelloInterval().ifPresent(builder::withHelloInterval); |
| 223 | config.getHoldTime().ifPresent(builder::withHoldTime); |
| 224 | config.getPriority().ifPresent(builder::withPriority); |
| 225 | config.getPropagationDelay().ifPresent(builder::withPropagationDelay); |
| 226 | config.getOverrideInterval().ifPresent(builder::withOverrideInterval); |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 227 | |
| 228 | return builder.build(); |
| 229 | } |
| 230 | |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 231 | private void addRoute(McastRoute route) { |
Jonathan Hart | fbfe2a8 | 2016-03-29 11:36:33 -0700 | [diff] [blame] | 232 | PimInterface pimInterface = getSourceInterface(route); |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 233 | |
| 234 | if (pimInterface == null) { |
| 235 | return; |
| 236 | } |
| 237 | |
Jonathan Hart | 32be517 | 2016-05-24 21:13:36 -0700 | [diff] [blame] | 238 | multicastRouteService.addSource(route, pimInterface.getInterface().connectPoint()); |
| 239 | |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 240 | routes.put(route, pimInterface); |
| 241 | } |
| 242 | |
| 243 | private void removeRoute(McastRoute route) { |
Jonathan Hart | fbfe2a8 | 2016-03-29 11:36:33 -0700 | [diff] [blame] | 244 | PimInterface pimInterface = routes.remove(route); |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 245 | |
| 246 | if (pimInterface == null) { |
| 247 | return; |
| 248 | } |
| 249 | |
| 250 | pimInterface.removeRoute(route); |
| 251 | } |
| 252 | |
Jonathan Hart | fbfe2a8 | 2016-03-29 11:36:33 -0700 | [diff] [blame] | 253 | private PimInterface getSourceInterface(McastRoute route) { |
Jonathan Hart | 92ca5d3 | 2016-04-14 18:05:52 -0700 | [diff] [blame] | 254 | Route unicastRoute = unicastRouteService.longestPrefixMatch(route.source()); |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 255 | |
Jonathan Hart | 92ca5d3 | 2016-04-14 18:05:52 -0700 | [diff] [blame] | 256 | if (unicastRoute == null) { |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 257 | log.warn("No route to source {}", route.source()); |
| 258 | return null; |
| 259 | } |
| 260 | |
Jonathan Hart | 92ca5d3 | 2016-04-14 18:05:52 -0700 | [diff] [blame] | 261 | Interface intf = interfaceService.getMatchingInterface(unicastRoute.nextHop()); |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 262 | |
| 263 | if (intf == null) { |
Jonathan Hart | 92ca5d3 | 2016-04-14 18:05:52 -0700 | [diff] [blame] | 264 | log.warn("No interface with route to next hop {}", unicastRoute.nextHop()); |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 265 | return null; |
| 266 | } |
| 267 | |
Jonathan Hart | fbfe2a8 | 2016-03-29 11:36:33 -0700 | [diff] [blame] | 268 | PimInterface pimInterface = pimInterfaces.get(intf.connectPoint()); |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 269 | |
| 270 | if (pimInterface == null) { |
| 271 | log.warn("PIM is not enabled on interface {}", intf); |
| 272 | return null; |
| 273 | } |
| 274 | |
Jonathan Hart | 92ca5d3 | 2016-04-14 18:05:52 -0700 | [diff] [blame] | 275 | Set<Host> hosts = hostService.getHostsByIp(unicastRoute.nextHop()); |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 276 | Host host = null; |
| 277 | for (Host h : hosts) { |
| 278 | if (h.vlan().equals(intf.vlan())) { |
| 279 | host = h; |
| 280 | } |
| 281 | } |
| 282 | if (host == null) { |
Jonathan Hart | 92ca5d3 | 2016-04-14 18:05:52 -0700 | [diff] [blame] | 283 | log.warn("Next hop host entry not found: {}", unicastRoute.nextHop()); |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 284 | return null; |
| 285 | } |
| 286 | |
Jonathan Hart | 92ca5d3 | 2016-04-14 18:05:52 -0700 | [diff] [blame] | 287 | pimInterface.addRoute(route, unicastRoute.nextHop(), host.mac()); |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 288 | |
| 289 | return pimInterface; |
| 290 | } |
| 291 | |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 292 | /** |
| 293 | * Listener for network config events. |
| 294 | */ |
| 295 | private class InternalNetworkConfigListener implements NetworkConfigListener { |
| 296 | |
| 297 | @Override |
| 298 | public void event(NetworkConfigEvent event) { |
| 299 | if (event.configClass() != PIM_INTERFACE_CONFIG_CLASS) { |
| 300 | return; |
| 301 | } |
| 302 | |
| 303 | switch (event.type()) { |
| 304 | case CONFIG_REGISTERED: |
| 305 | case CONFIG_UNREGISTERED: |
| 306 | break; |
| 307 | case CONFIG_ADDED: |
| 308 | case CONFIG_UPDATED: |
| 309 | ConnectPoint cp = (ConnectPoint) event.subject(); |
| 310 | PimInterfaceConfig config = networkConfig.getConfig( |
| 311 | cp, PIM_INTERFACE_CONFIG_CLASS); |
| 312 | |
| 313 | updateInterface(config); |
| 314 | break; |
| 315 | case CONFIG_REMOVED: |
| 316 | removeInterface((ConnectPoint) event.subject()); |
| 317 | break; |
| 318 | default: |
| 319 | break; |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * Listener for interface events. |
| 326 | */ |
| 327 | private class InternalInterfaceListener implements InterfaceListener { |
| 328 | |
| 329 | @Override |
| 330 | public void event(InterfaceEvent event) { |
| 331 | switch (event.type()) { |
| 332 | case INTERFACE_ADDED: |
| 333 | PimInterfaceConfig config = networkConfig.getConfig( |
| 334 | event.subject().connectPoint(), PIM_INTERFACE_CONFIG_CLASS); |
| 335 | |
| 336 | if (config != null) { |
| 337 | updateInterface(config); |
| 338 | } |
| 339 | break; |
| 340 | case INTERFACE_UPDATED: |
| 341 | break; |
| 342 | case INTERFACE_REMOVED: |
| 343 | removeInterface(event.subject().connectPoint()); |
| 344 | break; |
| 345 | default: |
| 346 | break; |
| 347 | |
| 348 | } |
| 349 | } |
| 350 | } |
Jonathan Hart | 00cddda | 2016-02-16 10:30:37 -0800 | [diff] [blame] | 351 | |
| 352 | /** |
| 353 | * Listener for multicast route events. |
| 354 | */ |
| 355 | private class InternalMulticastListener implements McastListener { |
| 356 | @Override |
| 357 | public void event(McastEvent event) { |
| 358 | switch (event.type()) { |
| 359 | case ROUTE_ADDED: |
| 360 | addRoute(event.subject().route()); |
| 361 | break; |
| 362 | case ROUTE_REMOVED: |
| 363 | removeRoute(event.subject().route()); |
| 364 | break; |
| 365 | case SOURCE_ADDED: |
| 366 | case SINK_ADDED: |
| 367 | case SINK_REMOVED: |
| 368 | default: |
| 369 | break; |
| 370 | } |
| 371 | } |
| 372 | } |
Rusty Eddy | 4ae5aa8 | 2015-12-15 12:58:27 -0800 | [diff] [blame] | 373 | } |