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