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