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.provider.host.impl; |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 17 | |
Pavlin Radoslavov | 93b606b | 2015-02-25 17:28:39 -0800 | [diff] [blame] | 18 | import static com.google.common.base.Strings.isNullOrEmpty; |
Jonathan Hart | e8600eb | 2015-01-12 10:30:45 -0800 | [diff] [blame] | 19 | import static org.slf4j.LoggerFactory.getLogger; |
| 20 | |
| 21 | import java.util.Dictionary; |
| 22 | import java.util.Set; |
| 23 | |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 24 | import org.apache.felix.scr.annotations.Activate; |
| 25 | import org.apache.felix.scr.annotations.Component; |
| 26 | import org.apache.felix.scr.annotations.Deactivate; |
Thomas Vachuska | 3360160 | 2014-11-19 03:32:15 -0800 | [diff] [blame] | 27 | import org.apache.felix.scr.annotations.Modified; |
| 28 | import org.apache.felix.scr.annotations.Property; |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 29 | import org.apache.felix.scr.annotations.Reference; |
| 30 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Jonathan Hart | e8600eb | 2015-01-12 10:30:45 -0800 | [diff] [blame] | 31 | import org.onlab.packet.ARP; |
| 32 | import org.onlab.packet.Ethernet; |
| 33 | import org.onlab.packet.IPacket; |
Pavlin Radoslavov | d6612f9 | 2015-02-23 13:53:32 -0800 | [diff] [blame] | 34 | import org.onlab.packet.ICMP6; |
Jonathan Hart | e8600eb | 2015-01-12 10:30:45 -0800 | [diff] [blame] | 35 | import org.onlab.packet.IPv6; |
| 36 | import org.onlab.packet.IpAddress; |
| 37 | import org.onlab.packet.VlanId; |
| 38 | import org.onlab.packet.ndp.NeighborAdvertisement; |
| 39 | import org.onlab.packet.ndp.NeighborSolicitation; |
Thomas Vachuska | 6519e6f | 2015-03-11 02:29:31 -0700 | [diff] [blame^] | 40 | import org.onosproject.cfg.ComponentConfigService; |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 41 | import org.onosproject.core.ApplicationId; |
| 42 | import org.onosproject.core.CoreService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 43 | import org.onosproject.net.ConnectPoint; |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 44 | import org.onosproject.net.Device; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 45 | import org.onosproject.net.Host; |
| 46 | import org.onosproject.net.HostId; |
| 47 | import org.onosproject.net.HostLocation; |
| 48 | import org.onosproject.net.device.DeviceEvent; |
| 49 | import org.onosproject.net.device.DeviceListener; |
| 50 | import org.onosproject.net.device.DeviceService; |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 51 | import org.onosproject.net.flow.DefaultTrafficSelector; |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 52 | import org.onosproject.net.flow.TrafficSelector; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 53 | import org.onosproject.net.host.DefaultHostDescription; |
| 54 | import org.onosproject.net.host.HostDescription; |
| 55 | import org.onosproject.net.host.HostProvider; |
| 56 | import org.onosproject.net.host.HostProviderRegistry; |
| 57 | import org.onosproject.net.host.HostProviderService; |
| 58 | import org.onosproject.net.host.HostService; |
| 59 | import org.onosproject.net.packet.PacketContext; |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 60 | import org.onosproject.net.packet.PacketPriority; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 61 | import org.onosproject.net.packet.PacketProcessor; |
| 62 | import org.onosproject.net.packet.PacketService; |
| 63 | import org.onosproject.net.provider.AbstractProvider; |
| 64 | import org.onosproject.net.provider.ProviderId; |
| 65 | import org.onosproject.net.topology.Topology; |
| 66 | import org.onosproject.net.topology.TopologyService; |
Thomas Vachuska | 3360160 | 2014-11-19 03:32:15 -0800 | [diff] [blame] | 67 | import org.osgi.service.component.ComponentContext; |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 68 | import org.slf4j.Logger; |
| 69 | |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 70 | /** |
| 71 | * Provider which uses an OpenFlow controller to detect network |
| 72 | * end-station hosts. |
| 73 | */ |
| 74 | @Component(immediate = true) |
| 75 | public class HostLocationProvider extends AbstractProvider implements HostProvider { |
| 76 | |
| 77 | private final Logger log = getLogger(getClass()); |
| 78 | |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 79 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 80 | protected CoreService coreService; |
| 81 | |
| 82 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 83 | protected HostProviderRegistry providerRegistry; |
| 84 | |
| 85 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Pavlin Radoslavov | d6612f9 | 2015-02-23 13:53:32 -0800 | [diff] [blame] | 86 | protected PacketService packetService; |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 87 | |
| 88 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 89 | protected TopologyService topologyService; |
| 90 | |
Thomas Vachuska | 3360160 | 2014-11-19 03:32:15 -0800 | [diff] [blame] | 91 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 92 | protected HostService hostService; |
| 93 | |
| 94 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 95 | protected DeviceService deviceService; |
| 96 | |
Thomas Vachuska | 6519e6f | 2015-03-11 02:29:31 -0700 | [diff] [blame^] | 97 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 98 | protected ComponentConfigService cfgService; |
| 99 | |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 100 | private HostProviderService providerService; |
| 101 | |
| 102 | private final InternalHostProvider processor = new InternalHostProvider(); |
Thomas Vachuska | 3360160 | 2014-11-19 03:32:15 -0800 | [diff] [blame] | 103 | private final DeviceListener deviceListener = new InternalDeviceListener(); |
| 104 | |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 105 | private ApplicationId appId; |
| 106 | |
Thomas Vachuska | 3360160 | 2014-11-19 03:32:15 -0800 | [diff] [blame] | 107 | @Property(name = "hostRemovalEnabled", boolValue = true, |
| 108 | label = "Enable host removal on port/device down events") |
| 109 | private boolean hostRemovalEnabled = true; |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 110 | |
Pavlin Radoslavov | 93b606b | 2015-02-25 17:28:39 -0800 | [diff] [blame] | 111 | @Property(name = "ipv6NeighborDiscovery", boolValue = false, |
| 112 | label = "Enable using IPv6 Neighbor Discovery by the " + |
| 113 | "Host Location Provider; default is false") |
| 114 | private boolean ipv6NeighborDiscovery = false; |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 115 | |
| 116 | /** |
| 117 | * Creates an OpenFlow host provider. |
| 118 | */ |
| 119 | public HostLocationProvider() { |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 120 | super(new ProviderId("of", "org.onosproject.provider.host")); |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | @Activate |
Thomas Vachuska | 3360160 | 2014-11-19 03:32:15 -0800 | [diff] [blame] | 124 | public void activate(ComponentContext context) { |
Thomas Vachuska | 6519e6f | 2015-03-11 02:29:31 -0700 | [diff] [blame^] | 125 | cfgService.registerProperties(getClass()); |
| 126 | appId = coreService.registerApplication("org.onosproject.provider.host"); |
Pavlin Radoslavov | 93b606b | 2015-02-25 17:28:39 -0800 | [diff] [blame] | 127 | readComponentConfiguration(context); |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 128 | |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 129 | providerService = providerRegistry.register(this); |
Pavlin Radoslavov | d6612f9 | 2015-02-23 13:53:32 -0800 | [diff] [blame] | 130 | packetService.addProcessor(processor, 1); |
Thomas Vachuska | 3360160 | 2014-11-19 03:32:15 -0800 | [diff] [blame] | 131 | deviceService.addListener(deviceListener); |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 132 | |
| 133 | TrafficSelector.Builder selectorBuilder = |
| 134 | DefaultTrafficSelector.builder(); |
| 135 | selectorBuilder.matchEthType(Ethernet.TYPE_ARP); |
Pavlin Radoslavov | d6612f9 | 2015-02-23 13:53:32 -0800 | [diff] [blame] | 136 | packetService.requestPackets(selectorBuilder.build(), |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 137 | PacketPriority.CONTROL, appId); |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 138 | |
Pavlin Radoslavov | 93b606b | 2015-02-25 17:28:39 -0800 | [diff] [blame] | 139 | if (ipv6NeighborDiscovery) { |
| 140 | // IPv6 Neighbor Solicitation packet. |
| 141 | selectorBuilder = DefaultTrafficSelector.builder(); |
| 142 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV6); |
| 143 | selectorBuilder.matchIPProtocol(IPv6.PROTOCOL_ICMP6); |
| 144 | selectorBuilder.matchIcmpv6Type(ICMP6.NEIGHBOR_SOLICITATION); |
| 145 | packetService.requestPackets(selectorBuilder.build(), |
| 146 | PacketPriority.CONTROL, appId); |
Pavlin Radoslavov | d6612f9 | 2015-02-23 13:53:32 -0800 | [diff] [blame] | 147 | |
Pavlin Radoslavov | 93b606b | 2015-02-25 17:28:39 -0800 | [diff] [blame] | 148 | // IPv6 Neighbor Advertisement packet. |
| 149 | selectorBuilder = DefaultTrafficSelector.builder(); |
| 150 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV6); |
| 151 | selectorBuilder.matchIPProtocol(IPv6.PROTOCOL_ICMP6); |
| 152 | selectorBuilder.matchIcmpv6Type(ICMP6.NEIGHBOR_ADVERTISEMENT); |
| 153 | packetService.requestPackets(selectorBuilder.build(), |
| 154 | PacketPriority.CONTROL, appId); |
| 155 | } |
Pavlin Radoslavov | d6612f9 | 2015-02-23 13:53:32 -0800 | [diff] [blame] | 156 | |
| 157 | log.info("Started with Application ID {}", appId.id()); |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | @Deactivate |
| 161 | public void deactivate() { |
Thomas Vachuska | 6519e6f | 2015-03-11 02:29:31 -0700 | [diff] [blame^] | 162 | cfgService.unregisterProperties(getClass(), false); |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 163 | providerRegistry.unregister(this); |
Pavlin Radoslavov | d6612f9 | 2015-02-23 13:53:32 -0800 | [diff] [blame] | 164 | packetService.removeProcessor(processor); |
alshabib | bfc6b72 | 2014-11-29 12:53:48 -0800 | [diff] [blame] | 165 | deviceService.removeListener(deviceListener); |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 166 | providerService = null; |
| 167 | log.info("Stopped"); |
| 168 | } |
| 169 | |
Thomas Vachuska | 3360160 | 2014-11-19 03:32:15 -0800 | [diff] [blame] | 170 | @Modified |
| 171 | public void modified(ComponentContext context) { |
Pavlin Radoslavov | 93b606b | 2015-02-25 17:28:39 -0800 | [diff] [blame] | 172 | readComponentConfiguration(context); |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Extracts properties from the component configuration context. |
| 177 | * |
| 178 | * @param context the component context |
| 179 | */ |
| 180 | private void readComponentConfiguration(ComponentContext context) { |
| 181 | Dictionary<?, ?> properties = context.getProperties(); |
| 182 | Boolean flag; |
| 183 | |
| 184 | flag = isPropertyEnabled(properties, "hostRemovalEnabled"); |
| 185 | if (flag == null) { |
| 186 | log.info("Host removal on port/device down events is not configured, " + |
| 187 | "using current value of {}", hostRemovalEnabled); |
| 188 | } else { |
| 189 | hostRemovalEnabled = flag; |
| 190 | log.info("Configured. Host removal on port/device down events is {}", |
| 191 | hostRemovalEnabled ? "enabled" : "disabled"); |
Thomas Vachuska | 3360160 | 2014-11-19 03:32:15 -0800 | [diff] [blame] | 192 | } |
Pavlin Radoslavov | 93b606b | 2015-02-25 17:28:39 -0800 | [diff] [blame] | 193 | |
| 194 | flag = isPropertyEnabled(properties, "ipv6NeighborDiscovery"); |
| 195 | if (flag == null) { |
| 196 | log.info("Using IPv6 Neighbor Discovery is not configured, " + |
| 197 | "using current value of {}", ipv6NeighborDiscovery); |
| 198 | } else { |
| 199 | ipv6NeighborDiscovery = flag; |
| 200 | log.info("Configured. Using IPv6 Neighbor Discovery is {}", |
| 201 | ipv6NeighborDiscovery ? "enabled" : "disabled"); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Check property name is defined and set to true. |
| 207 | * |
| 208 | * @param properties properties to be looked up |
| 209 | * @param propertyName the name of the property to look up |
| 210 | * @return value when the propertyName is defined or return null |
| 211 | */ |
| 212 | private static Boolean isPropertyEnabled(Dictionary<?, ?> properties, |
| 213 | String propertyName) { |
| 214 | Boolean value = null; |
| 215 | try { |
| 216 | String s = (String) properties.get(propertyName); |
| 217 | value = isNullOrEmpty(s) ? null : s.trim().equals("true"); |
| 218 | } catch (ClassCastException e) { |
| 219 | // No propertyName defined. |
| 220 | value = null; |
| 221 | } |
| 222 | return value; |
Thomas Vachuska | 3360160 | 2014-11-19 03:32:15 -0800 | [diff] [blame] | 223 | } |
| 224 | |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 225 | @Override |
| 226 | public void triggerProbe(Host host) { |
| 227 | log.info("Triggering probe on device {}", host); |
| 228 | } |
| 229 | |
| 230 | private class InternalHostProvider implements PacketProcessor { |
| 231 | |
| 232 | @Override |
| 233 | public void process(PacketContext context) { |
alshabib | 4a179dc | 2014-10-17 17:17:01 -0700 | [diff] [blame] | 234 | if (context == null) { |
| 235 | return; |
| 236 | } |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 237 | Ethernet eth = context.inPacket().parsed(); |
| 238 | |
Jonathan Hart | e8600eb | 2015-01-12 10:30:45 -0800 | [diff] [blame] | 239 | if (eth == null) { |
| 240 | return; |
| 241 | } |
| 242 | |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 243 | VlanId vlan = VlanId.vlanId(eth.getVlanID()); |
| 244 | ConnectPoint heardOn = context.inPacket().receivedFrom(); |
| 245 | |
| 246 | // If this is not an edge port, bail out. |
| 247 | Topology topology = topologyService.currentTopology(); |
| 248 | if (topologyService.isInfrastructure(topology, heardOn)) { |
| 249 | return; |
| 250 | } |
| 251 | |
Pavlin Radoslavov | d6612f9 | 2015-02-23 13:53:32 -0800 | [diff] [blame] | 252 | HostLocation hloc = |
| 253 | new HostLocation(heardOn, System.currentTimeMillis()); |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 254 | |
| 255 | HostId hid = HostId.hostId(eth.getSourceMAC(), vlan); |
| 256 | |
Charles M.C. Chan | 7fee36a | 2014-12-31 00:19:59 +0800 | [diff] [blame] | 257 | // ARP: possible new hosts, update both location and IP |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 258 | if (eth.getEtherType() == Ethernet.TYPE_ARP) { |
| 259 | ARP arp = (ARP) eth.getPayload(); |
Pavlin Radoslavov | d6612f9 | 2015-02-23 13:53:32 -0800 | [diff] [blame] | 260 | IpAddress ip = IpAddress.valueOf(IpAddress.Version.INET, |
| 261 | arp.getSenderProtocolAddress()); |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 262 | HostDescription hdescr = |
Pavlin Radoslavov | d6612f9 | 2015-02-23 13:53:32 -0800 | [diff] [blame] | 263 | new DefaultHostDescription(eth.getSourceMAC(), vlan, |
| 264 | hloc, ip); |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 265 | providerService.hostDetected(hid, hdescr); |
| 266 | |
Charles M.C. Chan | 7fee36a | 2014-12-31 00:19:59 +0800 | [diff] [blame] | 267 | // IPv4: update location only |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 268 | } else if (eth.getEtherType() == Ethernet.TYPE_IPV4) { |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 269 | HostDescription hdescr = |
Pavlin Radoslavov | d6612f9 | 2015-02-23 13:53:32 -0800 | [diff] [blame] | 270 | new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc); |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 271 | providerService.hostDetected(hid, hdescr); |
| 272 | |
Pavlin Radoslavov | d6612f9 | 2015-02-23 13:53:32 -0800 | [diff] [blame] | 273 | // |
| 274 | // NeighborAdvertisement and NeighborSolicitation: possible |
| 275 | // new hosts, update both location and IP. |
| 276 | // |
| 277 | // IPv6: update location only |
Charles M.C. Chan | 7fee36a | 2014-12-31 00:19:59 +0800 | [diff] [blame] | 278 | } else if (eth.getEtherType() == Ethernet.TYPE_IPV6) { |
| 279 | IpAddress ip = null; |
| 280 | IPv6 ipv6 = (IPv6) eth.getPayload(); |
| 281 | |
| 282 | IPacket iPkt = ipv6; |
| 283 | while (iPkt != null) { |
Pavlin Radoslavov | d6612f9 | 2015-02-23 13:53:32 -0800 | [diff] [blame] | 284 | if (iPkt instanceof NeighborAdvertisement || |
| 285 | iPkt instanceof NeighborSolicitation) { |
Charles M.C. Chan | 7fee36a | 2014-12-31 00:19:59 +0800 | [diff] [blame] | 286 | IpAddress sourceAddress = |
Pavlin Radoslavov | d6612f9 | 2015-02-23 13:53:32 -0800 | [diff] [blame] | 287 | IpAddress.valueOf(IpAddress.Version.INET6, |
| 288 | ipv6.getSourceAddress()); |
| 289 | // Ignore DAD packets, in which source address is zero |
Charles M.C. Chan | 7fee36a | 2014-12-31 00:19:59 +0800 | [diff] [blame] | 290 | if (!sourceAddress.isZero()) { |
| 291 | ip = sourceAddress; |
| 292 | break; |
| 293 | } |
| 294 | } |
| 295 | iPkt = iPkt.getPayload(); |
| 296 | } |
| 297 | HostDescription hdescr = (ip == null) ? |
Pavlin Radoslavov | d6612f9 | 2015-02-23 13:53:32 -0800 | [diff] [blame] | 298 | new DefaultHostDescription(eth.getSourceMAC(), vlan, |
| 299 | hloc) : |
| 300 | new DefaultHostDescription(eth.getSourceMAC(), vlan, |
| 301 | hloc, ip); |
Charles M.C. Chan | 7fee36a | 2014-12-31 00:19:59 +0800 | [diff] [blame] | 302 | providerService.hostDetected(hid, hdescr); |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | } |
Thomas Vachuska | 3360160 | 2014-11-19 03:32:15 -0800 | [diff] [blame] | 306 | |
| 307 | // Auxiliary listener to device events. |
| 308 | private class InternalDeviceListener implements DeviceListener { |
| 309 | @Override |
| 310 | public void event(DeviceEvent event) { |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 311 | Device device = event.subject(); |
| 312 | switch (event.type()) { |
| 313 | case DEVICE_ADDED: |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 314 | break; |
| 315 | case DEVICE_AVAILABILITY_CHANGED: |
| 316 | if (hostRemovalEnabled && |
| 317 | !deviceService.isAvailable(device.id())) { |
| 318 | removeHosts(hostService.getConnectedHosts(device.id())); |
Thomas Vachuska | 3360160 | 2014-11-19 03:32:15 -0800 | [diff] [blame] | 319 | } |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 320 | break; |
| 321 | case DEVICE_SUSPENDED: |
| 322 | case DEVICE_UPDATED: |
| 323 | // Nothing to do? |
| 324 | break; |
| 325 | case DEVICE_REMOVED: |
| 326 | if (hostRemovalEnabled) { |
| 327 | removeHosts(hostService.getConnectedHosts(device.id())); |
| 328 | } |
| 329 | break; |
| 330 | case PORT_ADDED: |
| 331 | break; |
| 332 | case PORT_UPDATED: |
| 333 | if (hostRemovalEnabled) { |
| 334 | ConnectPoint point = |
| 335 | new ConnectPoint(device.id(), event.port().number()); |
| 336 | removeHosts(hostService.getConnectedHosts(point)); |
| 337 | } |
| 338 | break; |
| 339 | case PORT_REMOVED: |
| 340 | // Nothing to do? |
| 341 | break; |
| 342 | default: |
| 343 | break; |
Thomas Vachuska | 3360160 | 2014-11-19 03:32:15 -0800 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | // Signals host vanish for all specified hosts. |
| 349 | private void removeHosts(Set<Host> hosts) { |
| 350 | for (Host host : hosts) { |
| 351 | providerService.hostVanished(host.id()); |
| 352 | } |
| 353 | } |
| 354 | |
alshabib | e1cf87d | 2014-10-17 09:23:50 -0700 | [diff] [blame] | 355 | } |