Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -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.vpls; |
| 17 | |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableSet; |
| 19 | import com.google.common.collect.Lists; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 20 | import com.google.common.collect.SetMultimap; |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 21 | import com.google.common.collect.Sets; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 22 | import org.apache.felix.scr.annotations.Activate; |
| 23 | import org.apache.felix.scr.annotations.Component; |
| 24 | import org.apache.felix.scr.annotations.Deactivate; |
| 25 | import org.apache.felix.scr.annotations.Reference; |
| 26 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 27 | import org.onlab.packet.MacAddress; |
| 28 | import org.onlab.packet.VlanId; |
| 29 | import org.onosproject.app.ApplicationService; |
| 30 | import org.onosproject.core.ApplicationId; |
| 31 | import org.onosproject.core.CoreService; |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 32 | import org.onosproject.incubator.net.intf.Interface; |
Luca Prete | a885482 | 2016-04-26 16:30:55 -0700 | [diff] [blame] | 33 | import org.onosproject.incubator.net.intf.InterfaceEvent; |
| 34 | import org.onosproject.incubator.net.intf.InterfaceListener; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 35 | import org.onosproject.incubator.net.intf.InterfaceService; |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 36 | import org.onosproject.net.FilteredConnectPoint; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 37 | import org.onosproject.net.Host; |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 38 | import org.onosproject.net.config.NetworkConfigEvent; |
| 39 | import org.onosproject.net.config.NetworkConfigListener; |
| 40 | import org.onosproject.net.config.NetworkConfigService; |
| 41 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 42 | import org.onosproject.net.flow.TrafficSelector; |
| 43 | import org.onosproject.net.flow.criteria.Criterion; |
| 44 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 45 | import org.onosproject.net.host.HostEvent; |
| 46 | import org.onosproject.net.host.HostListener; |
| 47 | import org.onosproject.net.host.HostService; |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 48 | import org.onosproject.net.intent.Intent; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 49 | import org.onosproject.net.intent.IntentService; |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 50 | import org.onosproject.net.intent.Key; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 51 | import org.onosproject.routing.IntentSynchronizationService; |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 52 | import org.onosproject.vpls.config.VplsConfigurationService; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 53 | import org.slf4j.Logger; |
| 54 | |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 55 | import java.util.Collection; |
| 56 | import java.util.HashSet; |
| 57 | import java.util.List; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 58 | import java.util.Set; |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 59 | import java.util.stream.Collectors; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 60 | |
| 61 | import static org.slf4j.LoggerFactory.getLogger; |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 62 | import static org.onosproject.vpls.IntentInstaller.PREFIX_BROADCAST; |
| 63 | import static org.onosproject.vpls.IntentInstaller.PREFIX_UNICAST; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * Application to create L2 broadcast overlay networks using VLAN. |
| 67 | */ |
| 68 | @Component(immediate = true) |
| 69 | public class Vpls { |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 70 | /** |
| 71 | * Application name of VPLS. |
| 72 | */ |
| 73 | static final String VPLS_APP = "org.onosproject.vpls"; |
| 74 | |
| 75 | private static final String HOST_FCP_NOT_FOUND = |
| 76 | "Filtered connected point for host {} not found"; |
| 77 | private static final String HOST_EVENT = "Received HostEvent {}"; |
| 78 | private static final String INTF_CONF_EVENT = |
| 79 | "Received InterfaceConfigEvent {}"; |
| 80 | private static final String NET_CONF_EVENT = |
| 81 | "Received NetworkConfigEvent {}"; |
Yi Tseng | 28767f0 | 2016-09-13 04:27:20 -0700 | [diff] [blame] | 82 | |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 83 | private final Logger log = getLogger(getClass()); |
| 84 | |
| 85 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 86 | protected ApplicationService applicationService; |
| 87 | |
| 88 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 89 | protected CoreService coreService; |
| 90 | |
| 91 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 92 | protected HostService hostService; |
| 93 | |
| 94 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 95 | protected IntentService intentService; |
| 96 | |
| 97 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 98 | protected InterfaceService interfaceService; |
| 99 | |
| 100 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 101 | protected IntentSynchronizationService intentSynchronizer; |
| 102 | |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 103 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 104 | protected NetworkConfigService configService; |
| 105 | |
| 106 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 107 | protected VplsConfigurationService vplsConfigService; |
| 108 | |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 109 | private final HostListener hostListener = new InternalHostListener(); |
| 110 | |
Luca Prete | a885482 | 2016-04-26 16:30:55 -0700 | [diff] [blame] | 111 | private final InternalInterfaceListener interfaceListener |
| 112 | = new InternalInterfaceListener(); |
| 113 | |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 114 | private final InternalNetworkConfigListener configListener = |
| 115 | new InternalNetworkConfigListener(); |
| 116 | |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 117 | private IntentInstaller intentInstaller; |
| 118 | |
| 119 | private ApplicationId appId; |
| 120 | |
Yi Tseng | 28767f0 | 2016-09-13 04:27:20 -0700 | [diff] [blame] | 121 | |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 122 | @Activate |
| 123 | public void activate() { |
| 124 | appId = coreService.registerApplication(VPLS_APP); |
| 125 | |
| 126 | intentInstaller = new IntentInstaller(appId, |
| 127 | intentService, |
| 128 | intentSynchronizer); |
| 129 | |
Luca Prete | 2705d66 | 2016-04-29 15:30:23 -0700 | [diff] [blame] | 130 | applicationService.registerDeactivateHook(appId, () -> { |
| 131 | intentSynchronizer.removeIntentsByAppId(appId); |
| 132 | }); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 133 | |
| 134 | hostService.addListener(hostListener); |
Luca Prete | a885482 | 2016-04-26 16:30:55 -0700 | [diff] [blame] | 135 | interfaceService.addListener(interfaceListener); |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 136 | configService.addListener(configListener); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 137 | |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 138 | setupConnectivity(false); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 139 | |
Luca Prete | c21c6e6 | 2016-09-22 14:52:21 -0700 | [diff] [blame] | 140 | log.info("Activated"); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | @Deactivate |
| 144 | public void deactivate() { |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 145 | configService.removeListener(configListener); |
Yi Tseng | 28767f0 | 2016-09-13 04:27:20 -0700 | [diff] [blame] | 146 | intentSynchronizer.removeIntentsByAppId(appId); |
Luca Prete | c21c6e6 | 2016-09-22 14:52:21 -0700 | [diff] [blame] | 147 | log.info("Deactivated"); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 148 | } |
| 149 | |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 150 | /** |
| 151 | * Sets up connectivity for all VPLSs. |
| 152 | * |
| 153 | * @param isNetworkConfigEvent true if this function is triggered |
| 154 | * by NetworkConfigEvent; false otherwise |
| 155 | */ |
| 156 | private void setupConnectivity(boolean isNetworkConfigEvent) { |
| 157 | SetMultimap<String, Interface> networkInterfaces = |
| 158 | vplsConfigService.getVplsNetworks(); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 159 | |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 160 | Set<String> vplsAffectedByApi = |
| 161 | new HashSet<>(vplsConfigService.getVplsAffectedByApi()); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 162 | |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 163 | if (isNetworkConfigEvent && vplsAffectedByApi.isEmpty()) { |
| 164 | vplsAffectedByApi.addAll(vplsConfigService.getOldVpls()); |
| 165 | } |
Yi Tseng | 28767f0 | 2016-09-13 04:27:20 -0700 | [diff] [blame] | 166 | |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 167 | networkInterfaces.asMap().forEach((networkName, interfaces) -> { |
| 168 | Set<Host> hosts = Sets.newHashSet(); |
| 169 | interfaces.forEach(intf -> { |
| 170 | // Add hosts that belongs to the specific VPLS |
| 171 | hostService.getConnectedHosts(intf.connectPoint()) |
| 172 | .stream() |
| 173 | .filter(host -> host.vlan().equals(intf.vlan())) |
| 174 | .forEach(hosts::add); |
| 175 | }); |
| 176 | |
| 177 | setupConnectivity(networkName, interfaces, hosts, |
| 178 | vplsAffectedByApi.contains(networkName)); |
| 179 | vplsAffectedByApi.remove(networkName); |
| 180 | }); |
| 181 | |
| 182 | if (!vplsAffectedByApi.isEmpty()) { |
| 183 | for (String networkName:vplsAffectedByApi) { |
| 184 | withdrawIntents(networkName, Lists.newArrayList()); |
| 185 | } |
| 186 | } |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | /** |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 190 | * Sets up connectivity for specific VPLS. |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 191 | * |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 192 | * @param networkName the VPLS name |
| 193 | * @param interfaces the interfaces that belong to the VPLS |
| 194 | * @param hosts the hosts that belong to the VPLS |
| 195 | * @param affectedByApi true if this function is triggered from the APIs; |
| 196 | * false otherwise |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 197 | */ |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 198 | private void setupConnectivity(String networkName, |
| 199 | Collection<Interface> interfaces, |
| 200 | Set<Host> hosts, |
| 201 | boolean affectedByApi) { |
| 202 | List<Intent> intents = Lists.newArrayList(); |
| 203 | List<Key> keys = Lists.newArrayList(); |
| 204 | Set<FilteredConnectPoint> fcPoints = buildFCPoints(interfaces); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 205 | |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 206 | intents.addAll(buildUnicastIntents( |
| 207 | networkName, hosts, fcPoints, affectedByApi)); |
| 208 | intents.addAll(buildBroadcastIntents( |
| 209 | networkName, fcPoints, affectedByApi)); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 210 | |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 211 | if (affectedByApi) { |
| 212 | intents.forEach(intent -> keys.add(intent.key())); |
| 213 | withdrawIntents(networkName, keys); |
| 214 | } |
| 215 | |
| 216 | intentInstaller.submitIntents(intents); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | /** |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 220 | * Withdraws intents belonging to a VPLS, given a VPLS name. |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 221 | * |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 222 | * @param networkName the VPLS name |
| 223 | * @param keys the keys of the intents to be installed |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 224 | */ |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 225 | private void withdrawIntents(String networkName, |
| 226 | List<Key> keys) { |
| 227 | List<Intent> intents = Lists.newArrayList(); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 228 | |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 229 | intentInstaller.getIntentsFromVpls(networkName) |
| 230 | .forEach(intent -> { |
| 231 | if (!keys.contains(intent.key())) { |
| 232 | intents.add(intent); |
| 233 | } |
| 234 | }); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 235 | |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 236 | intentInstaller.withdrawIntents(intents); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 237 | } |
| 238 | |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 239 | /** |
| 240 | * Sets up broadcast intents between any given filtered connect point. |
| 241 | * |
| 242 | * @param networkName the VPLS name |
| 243 | * @param fcPoints the set of filtered connect points |
| 244 | * @param affectedByApi true if the function triggered from APIs; |
| 245 | * false otherwise |
| 246 | * @return the set of broadcast intents |
| 247 | */ |
| 248 | private Set<Intent> buildBroadcastIntents(String networkName, |
| 249 | Set<FilteredConnectPoint> fcPoints, |
| 250 | boolean affectedByApi) { |
| 251 | Set<Intent> intents = Sets.newHashSet(); |
| 252 | fcPoints.forEach(point -> { |
| 253 | Set<FilteredConnectPoint> otherPoints = |
| 254 | fcPoints.stream() |
| 255 | .filter(fcp -> !fcp.equals(point)) |
| 256 | .collect(Collectors.toSet()); |
| 257 | |
| 258 | Key brcKey = intentInstaller.buildKey(PREFIX_BROADCAST, |
| 259 | point.connectPoint(), |
| 260 | networkName, |
| 261 | MacAddress.BROADCAST); |
| 262 | |
| 263 | if ((!intentInstaller.intentExists(brcKey) || affectedByApi) && |
| 264 | !otherPoints.isEmpty()) { |
| 265 | intents.add(intentInstaller.buildBrcIntent(brcKey, |
| 266 | point, |
| 267 | otherPoints)); |
Yi Tseng | bf8b67e | 2016-09-01 15:02:11 +0800 | [diff] [blame] | 268 | } |
| 269 | }); |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 270 | |
| 271 | return ImmutableSet.copyOf(intents); |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * Sets up unicast intents between any given filtered connect point. |
| 276 | * |
| 277 | * @param networkName the VPLS name |
| 278 | * @param hosts the set of destination hosts |
| 279 | * @param fcPoints the set of filtered connect points |
| 280 | * @param affectedByApi true if the function triggered from APIs; |
| 281 | * false otherwise |
| 282 | * @return the set of unicast intents |
| 283 | */ |
| 284 | private Set<Intent> buildUnicastIntents(String networkName, |
| 285 | Set<Host> hosts, |
| 286 | Set<FilteredConnectPoint> fcPoints, |
| 287 | boolean affectedByApi) { |
| 288 | Set<Intent> intents = Sets.newHashSet(); |
| 289 | hosts.forEach(host -> { |
| 290 | FilteredConnectPoint hostPoint = getHostPoint(host, fcPoints); |
| 291 | |
| 292 | if (hostPoint == null) { |
| 293 | log.warn(HOST_FCP_NOT_FOUND, host); |
| 294 | return; |
| 295 | } |
| 296 | |
| 297 | Set<FilteredConnectPoint> otherPoints = |
| 298 | fcPoints.stream() |
| 299 | .filter(fcp -> !fcp.equals(hostPoint)) |
| 300 | .collect(Collectors.toSet()); |
| 301 | |
| 302 | Key uniKey = intentInstaller.buildKey(PREFIX_UNICAST, |
| 303 | host.location(), |
| 304 | networkName, |
| 305 | host.mac()); |
| 306 | |
| 307 | if ((!intentInstaller.intentExists(uniKey) || affectedByApi) && |
| 308 | !otherPoints.isEmpty()) { |
| 309 | intents.add(intentInstaller.buildUniIntent(uniKey, |
| 310 | otherPoints, |
| 311 | hostPoint, |
| 312 | host)); |
| 313 | } |
| 314 | }); |
| 315 | |
| 316 | return ImmutableSet.copyOf(intents); |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * Finds the filtered connect point a host is attached to. |
| 321 | * |
| 322 | * @param host the target host |
| 323 | * @param fcps the filtered connected points |
| 324 | * @return null if not found; the filtered connect point otherwise |
| 325 | */ |
| 326 | private FilteredConnectPoint getHostPoint(Host host, |
| 327 | Set<FilteredConnectPoint> fcps) { |
| 328 | return fcps.stream() |
| 329 | .filter(fcp -> fcp.connectPoint().equals(host.location())) |
| 330 | .filter(fcp -> { |
| 331 | VlanIdCriterion vlanCriterion = |
| 332 | (VlanIdCriterion) fcp.trafficSelector(). |
| 333 | getCriterion(Criterion.Type.VLAN_VID); |
| 334 | |
| 335 | return vlanCriterion != null && |
| 336 | vlanCriterion.vlanId().equals(host.vlan()); |
| 337 | }) |
| 338 | .findFirst() |
| 339 | .orElse(null); |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * Computes a set of filtered connect points from a list of given interfaces. |
| 344 | * |
| 345 | * @param interfaces the interfaces to compute |
| 346 | * @return the set of filtered connect points |
| 347 | */ |
| 348 | private Set<FilteredConnectPoint> buildFCPoints(Collection<Interface> interfaces) { |
| 349 | // Build all filtered connected points in the network |
| 350 | return interfaces |
| 351 | .stream() |
| 352 | .map(intf -> { |
| 353 | TrafficSelector.Builder selectorBuilder = |
| 354 | DefaultTrafficSelector.builder(); |
| 355 | |
| 356 | if (!intf.vlan().equals(VlanId.NONE)) { |
| 357 | selectorBuilder.matchVlanId(intf.vlan()); |
| 358 | } |
| 359 | |
| 360 | return new FilteredConnectPoint(intf.connectPoint(), |
| 361 | selectorBuilder.build()); |
| 362 | }) |
| 363 | .collect(Collectors.toSet()); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | /** |
| 367 | * Listener for host events. |
| 368 | */ |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 369 | private class InternalHostListener implements HostListener { |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 370 | @Override |
| 371 | public void event(HostEvent event) { |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 372 | log.debug(HOST_EVENT, event); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 373 | switch (event.type()) { |
| 374 | case HOST_ADDED: |
| 375 | case HOST_UPDATED: |
| 376 | case HOST_REMOVED: |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 377 | setupConnectivity(false); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 378 | break; |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 379 | |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 380 | default: |
| 381 | break; |
| 382 | } |
| 383 | } |
| 384 | } |
Luca Prete | a885482 | 2016-04-26 16:30:55 -0700 | [diff] [blame] | 385 | |
| 386 | /** |
| 387 | * Listener for interface configuration events. |
| 388 | */ |
| 389 | private class InternalInterfaceListener implements InterfaceListener { |
| 390 | @Override |
| 391 | public void event(InterfaceEvent event) { |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 392 | log.debug(INTF_CONF_EVENT, event); |
Luca Prete | a885482 | 2016-04-26 16:30:55 -0700 | [diff] [blame] | 393 | switch (event.type()) { |
| 394 | case INTERFACE_ADDED: |
| 395 | case INTERFACE_UPDATED: |
| 396 | case INTERFACE_REMOVED: |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 397 | setupConnectivity(false); |
Luca Prete | a885482 | 2016-04-26 16:30:55 -0700 | [diff] [blame] | 398 | break; |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 399 | |
Luca Prete | a885482 | 2016-04-26 16:30:55 -0700 | [diff] [blame] | 400 | default: |
| 401 | break; |
| 402 | } |
| 403 | } |
| 404 | } |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 405 | |
| 406 | /** |
| 407 | * Listener for VPLS configuration events. |
| 408 | */ |
| 409 | private class InternalNetworkConfigListener implements NetworkConfigListener { |
| 410 | @Override |
| 411 | public void event(NetworkConfigEvent event) { |
| 412 | if (event.configClass() == VplsConfigurationService.CONFIG_CLASS) { |
| 413 | log.debug(NET_CONF_EVENT, event.configClass()); |
| 414 | switch (event.type()) { |
| 415 | case CONFIG_ADDED: |
| 416 | case CONFIG_UPDATED: |
| 417 | case CONFIG_REMOVED: |
| 418 | setupConnectivity(true); |
| 419 | break; |
| 420 | |
| 421 | default: |
| 422 | break; |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | } |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 427 | } |