Added IPv6 support to HostLocationProvider
This fixes ONOS-637 Change-Id: Ic3a411b7e1a1fcf18e7bc7a1b70d1e57c23a52ce
Showing
2 changed files
with
46 additions
and
18 deletions
... | @@ -30,6 +30,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; | ... | @@ -30,6 +30,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; |
30 | import org.onlab.packet.ARP; | 30 | import org.onlab.packet.ARP; |
31 | import org.onlab.packet.Ethernet; | 31 | import org.onlab.packet.Ethernet; |
32 | import org.onlab.packet.IPacket; | 32 | import org.onlab.packet.IPacket; |
33 | +import org.onlab.packet.ICMP6; | ||
33 | import org.onlab.packet.IPv6; | 34 | import org.onlab.packet.IPv6; |
34 | import org.onlab.packet.IpAddress; | 35 | import org.onlab.packet.IpAddress; |
35 | import org.onlab.packet.VlanId; | 36 | import org.onlab.packet.VlanId; |
... | @@ -80,7 +81,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid | ... | @@ -80,7 +81,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid |
80 | protected HostProviderRegistry providerRegistry; | 81 | protected HostProviderRegistry providerRegistry; |
81 | 82 | ||
82 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 83 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
83 | - protected PacketService pktService; | 84 | + protected PacketService packetService; |
84 | 85 | ||
85 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 86 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
86 | protected TopologyService topologyService; | 87 | protected TopologyService topologyService; |
... | @@ -117,22 +118,38 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid | ... | @@ -117,22 +118,38 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid |
117 | 118 | ||
118 | modified(context); | 119 | modified(context); |
119 | providerService = providerRegistry.register(this); | 120 | providerService = providerRegistry.register(this); |
120 | - pktService.addProcessor(processor, 1); | 121 | + packetService.addProcessor(processor, 1); |
121 | deviceService.addListener(deviceListener); | 122 | deviceService.addListener(deviceListener); |
122 | 123 | ||
123 | TrafficSelector.Builder selectorBuilder = | 124 | TrafficSelector.Builder selectorBuilder = |
124 | DefaultTrafficSelector.builder(); | 125 | DefaultTrafficSelector.builder(); |
125 | selectorBuilder.matchEthType(Ethernet.TYPE_ARP); | 126 | selectorBuilder.matchEthType(Ethernet.TYPE_ARP); |
126 | - pktService.requestPackets(selectorBuilder.build(), | 127 | + packetService.requestPackets(selectorBuilder.build(), |
127 | PacketPriority.CONTROL, appId); | 128 | PacketPriority.CONTROL, appId); |
128 | 129 | ||
129 | - log.info("Started"); | 130 | + // IPv6 Neighbor Solicitation packet. |
131 | + selectorBuilder = DefaultTrafficSelector.builder(); | ||
132 | + selectorBuilder.matchEthType(Ethernet.TYPE_IPV6); | ||
133 | + selectorBuilder.matchIPProtocol(IPv6.PROTOCOL_ICMP6); | ||
134 | + selectorBuilder.matchIcmpv6Type(ICMP6.NEIGHBOR_SOLICITATION); | ||
135 | + packetService.requestPackets(selectorBuilder.build(), | ||
136 | + PacketPriority.CONTROL, appId); | ||
137 | + | ||
138 | + // IPv6 Neighbor Advertisement packet. | ||
139 | + selectorBuilder = DefaultTrafficSelector.builder(); | ||
140 | + selectorBuilder.matchEthType(Ethernet.TYPE_IPV6); | ||
141 | + selectorBuilder.matchIPProtocol(IPv6.PROTOCOL_ICMP6); | ||
142 | + selectorBuilder.matchIcmpv6Type(ICMP6.NEIGHBOR_ADVERTISEMENT); | ||
143 | + packetService.requestPackets(selectorBuilder.build(), | ||
144 | + PacketPriority.CONTROL, appId); | ||
145 | + | ||
146 | + log.info("Started with Application ID {}", appId.id()); | ||
130 | } | 147 | } |
131 | 148 | ||
132 | @Deactivate | 149 | @Deactivate |
133 | public void deactivate() { | 150 | public void deactivate() { |
134 | providerRegistry.unregister(this); | 151 | providerRegistry.unregister(this); |
135 | - pktService.removeProcessor(processor); | 152 | + packetService.removeProcessor(processor); |
136 | deviceService.removeListener(deviceListener); | 153 | deviceService.removeListener(deviceListener); |
137 | providerService = null; | 154 | providerService = null; |
138 | log.info("Stopped"); | 155 | log.info("Stopped"); |
... | @@ -149,7 +166,8 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid | ... | @@ -149,7 +166,8 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid |
149 | } catch (ClassCastException e) { | 166 | } catch (ClassCastException e) { |
150 | hostRemovalEnabled = true; | 167 | hostRemovalEnabled = true; |
151 | } | 168 | } |
152 | - log.info("Host removal is {}", hostRemovalEnabled ? "enabled" : "disabled"); | 169 | + log.info("Host removal is {}", |
170 | + hostRemovalEnabled ? "enabled" : "disabled"); | ||
153 | } | 171 | } |
154 | 172 | ||
155 | @Override | 173 | @Override |
... | @@ -179,36 +197,44 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid | ... | @@ -179,36 +197,44 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid |
179 | return; | 197 | return; |
180 | } | 198 | } |
181 | 199 | ||
182 | - HostLocation hloc = new HostLocation(heardOn, System.currentTimeMillis()); | 200 | + HostLocation hloc = |
201 | + new HostLocation(heardOn, System.currentTimeMillis()); | ||
183 | 202 | ||
184 | HostId hid = HostId.hostId(eth.getSourceMAC(), vlan); | 203 | HostId hid = HostId.hostId(eth.getSourceMAC(), vlan); |
185 | 204 | ||
186 | // ARP: possible new hosts, update both location and IP | 205 | // ARP: possible new hosts, update both location and IP |
187 | if (eth.getEtherType() == Ethernet.TYPE_ARP) { | 206 | if (eth.getEtherType() == Ethernet.TYPE_ARP) { |
188 | ARP arp = (ARP) eth.getPayload(); | 207 | ARP arp = (ARP) eth.getPayload(); |
189 | - IpAddress ip = IpAddress.valueOf(IpAddress.Version.INET, arp.getSenderProtocolAddress()); | 208 | + IpAddress ip = IpAddress.valueOf(IpAddress.Version.INET, |
209 | + arp.getSenderProtocolAddress()); | ||
190 | HostDescription hdescr = | 210 | HostDescription hdescr = |
191 | - new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ip); | 211 | + new DefaultHostDescription(eth.getSourceMAC(), vlan, |
212 | + hloc, ip); | ||
192 | providerService.hostDetected(hid, hdescr); | 213 | providerService.hostDetected(hid, hdescr); |
193 | 214 | ||
194 | // IPv4: update location only | 215 | // IPv4: update location only |
195 | } else if (eth.getEtherType() == Ethernet.TYPE_IPV4) { | 216 | } else if (eth.getEtherType() == Ethernet.TYPE_IPV4) { |
196 | HostDescription hdescr = | 217 | HostDescription hdescr = |
197 | - new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc); | 218 | + new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc); |
198 | providerService.hostDetected(hid, hdescr); | 219 | providerService.hostDetected(hid, hdescr); |
199 | 220 | ||
200 | - // NeighborAdvertisement and NeighborSolicitation: possible new hosts, update both location and IP | 221 | + // |
201 | - // IPv6: update location only | 222 | + // NeighborAdvertisement and NeighborSolicitation: possible |
223 | + // new hosts, update both location and IP. | ||
224 | + // | ||
225 | + // IPv6: update location only | ||
202 | } else if (eth.getEtherType() == Ethernet.TYPE_IPV6) { | 226 | } else if (eth.getEtherType() == Ethernet.TYPE_IPV6) { |
203 | IpAddress ip = null; | 227 | IpAddress ip = null; |
204 | IPv6 ipv6 = (IPv6) eth.getPayload(); | 228 | IPv6 ipv6 = (IPv6) eth.getPayload(); |
205 | 229 | ||
206 | IPacket iPkt = ipv6; | 230 | IPacket iPkt = ipv6; |
207 | while (iPkt != null) { | 231 | while (iPkt != null) { |
208 | - if (iPkt instanceof NeighborAdvertisement || iPkt instanceof NeighborSolicitation) { | 232 | + if (iPkt instanceof NeighborAdvertisement || |
233 | + iPkt instanceof NeighborSolicitation) { | ||
209 | IpAddress sourceAddress = | 234 | IpAddress sourceAddress = |
210 | - IpAddress.valueOf(IpAddress.Version.INET6, ipv6.getSourceAddress()); | 235 | + IpAddress.valueOf(IpAddress.Version.INET6, |
211 | - // Ignore DAD packets, in which source address is all zeros. | 236 | + ipv6.getSourceAddress()); |
237 | + // Ignore DAD packets, in which source address is zero | ||
212 | if (!sourceAddress.isZero()) { | 238 | if (!sourceAddress.isZero()) { |
213 | ip = sourceAddress; | 239 | ip = sourceAddress; |
214 | break; | 240 | break; |
... | @@ -217,8 +243,10 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid | ... | @@ -217,8 +243,10 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid |
217 | iPkt = iPkt.getPayload(); | 243 | iPkt = iPkt.getPayload(); |
218 | } | 244 | } |
219 | HostDescription hdescr = (ip == null) ? | 245 | HostDescription hdescr = (ip == null) ? |
220 | - new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc) : | 246 | + new DefaultHostDescription(eth.getSourceMAC(), vlan, |
221 | - new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ip); | 247 | + hloc) : |
248 | + new DefaultHostDescription(eth.getSourceMAC(), vlan, | ||
249 | + hloc, ip); | ||
222 | providerService.hostDetected(hid, hdescr); | 250 | providerService.hostDetected(hid, hdescr); |
223 | } | 251 | } |
224 | } | 252 | } | ... | ... |
... | @@ -148,7 +148,7 @@ public class HostLocationProviderTest { | ... | @@ -148,7 +148,7 @@ public class HostLocationProviderTest { |
148 | 148 | ||
149 | provider.providerRegistry = hostRegistry; | 149 | provider.providerRegistry = hostRegistry; |
150 | provider.topologyService = topoService; | 150 | provider.topologyService = topoService; |
151 | - provider.pktService = packetService; | 151 | + provider.packetService = packetService; |
152 | provider.deviceService = deviceService; | 152 | provider.deviceService = deviceService; |
153 | provider.hostService = hostService; | 153 | provider.hostService = hostService; |
154 | 154 | ... | ... |
-
Please register or login to post a comment