blob: dd9da4b634caac7775bd99a7628f0f994c977aaa [file] [log] [blame]
Jonathan Hart9bdaaec2016-08-22 13:33:45 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Jonathan Hart9bdaaec2016-08-22 13:33:45 -07003 *
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
Ray Milkeyb65d7842017-08-03 16:28:24 -070017package org.onosproject.net.neighbour.impl;
Jonathan Hart9bdaaec2016-08-22 13:33:45 -070018
Jonathan Hartc4f681c2016-09-09 07:14:25 -070019import com.google.common.collect.HashMultimap;
20import com.google.common.collect.ImmutableMap;
Jonathan Hart9bdaaec2016-08-22 13:33:45 -070021import com.google.common.collect.Multimaps;
Jonathan Hartc4f681c2016-09-09 07:14:25 -070022import com.google.common.collect.SetMultimap;
Jonathan Hart9bdaaec2016-08-22 13:33:45 -070023import org.onlab.packet.Ethernet;
24import org.onlab.packet.ICMP6;
25import org.onlab.packet.IPv6;
Jonathan Hartc4f681c2016-09-09 07:14:25 -070026import org.onlab.packet.IpAddress;
Jonathan Hart9bdaaec2016-08-22 13:33:45 -070027import org.onlab.packet.MacAddress;
28import org.onlab.packet.VlanId;
Jonathan Hart9bdaaec2016-08-22 13:33:45 -070029import org.onlab.util.Tools;
30import org.onosproject.cfg.ComponentConfigService;
31import org.onosproject.core.ApplicationId;
32import org.onosproject.core.CoreService;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070033import org.onosproject.net.ConnectPoint;
34import org.onosproject.net.edge.EdgePortService;
35import org.onosproject.net.flow.DefaultTrafficSelector;
36import org.onosproject.net.flow.TrafficSelector;
37import org.onosproject.net.host.HostService;
Ray Milkeyfacf2862017-08-03 11:58:29 -070038import org.onosproject.net.intf.Interface;
Ray Milkeyb65d7842017-08-03 16:28:24 -070039import org.onosproject.net.neighbour.NeighbourHandlerRegistration;
40import org.onosproject.net.neighbour.NeighbourMessageActions;
41import org.onosproject.net.neighbour.NeighbourMessageContext;
42import org.onosproject.net.neighbour.NeighbourMessageHandler;
43import org.onosproject.net.neighbour.NeighbourResolutionService;
Jonathan Hart9bdaaec2016-08-22 13:33:45 -070044import org.onosproject.net.packet.InboundPacket;
45import org.onosproject.net.packet.PacketContext;
46import org.onosproject.net.packet.PacketProcessor;
47import org.onosproject.net.packet.PacketService;
48import org.osgi.service.component.ComponentContext;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070049import org.osgi.service.component.annotations.Activate;
50import org.osgi.service.component.annotations.Component;
51import org.osgi.service.component.annotations.Deactivate;
52import org.osgi.service.component.annotations.Modified;
53import org.osgi.service.component.annotations.Reference;
54import org.osgi.service.component.annotations.ReferenceCardinality;
Jonathan Hart9bdaaec2016-08-22 13:33:45 -070055import org.slf4j.Logger;
56import org.slf4j.LoggerFactory;
57
Jonathan Hartc4f681c2016-09-09 07:14:25 -070058import java.util.Collection;
Jonathan Hart9bdaaec2016-08-22 13:33:45 -070059import java.util.Dictionary;
Jonathan Hartc4f681c2016-09-09 07:14:25 -070060import java.util.Iterator;
61import java.util.Map;
Jonathan Hart9bdaaec2016-08-22 13:33:45 -070062import java.util.Objects;
Pier Ventre0ba98522016-09-19 15:49:14 -070063import java.util.stream.Collectors;
Jonathan Hart9bdaaec2016-08-22 13:33:45 -070064
65import static com.google.common.base.Preconditions.checkNotNull;
66import static org.onlab.packet.Ethernet.TYPE_ARP;
67import static org.onlab.packet.Ethernet.TYPE_IPV6;
68import static org.onlab.packet.ICMP6.NEIGHBOR_ADVERTISEMENT;
69import static org.onlab.packet.ICMP6.NEIGHBOR_SOLICITATION;
70import static org.onlab.packet.IPv6.PROTOCOL_ICMP6;
Ray Milkeyd04e2272018-10-16 18:20:18 -070071import static org.onosproject.net.OsgiPropertyConstants.NRM_ARP_ENABLED;
72import static org.onosproject.net.OsgiPropertyConstants.NRM_ARP_ENABLED_DEFAULT;
73import static org.onosproject.net.OsgiPropertyConstants.NRM_NDP_ENABLED;
74import static org.onosproject.net.OsgiPropertyConstants.NRM_NDP_ENABLED_DEFAULT;
75import static org.onosproject.net.OsgiPropertyConstants.NRM_REQUEST_INTERCEPTS_ENABLED;
76import static org.onosproject.net.OsgiPropertyConstants.NRM_REQUEST_INTERCEPTS_ENABLED_DEFAULT;
Jonathan Hart9bdaaec2016-08-22 13:33:45 -070077import static org.onosproject.net.packet.PacketPriority.CONTROL;
78
79/**
80 * Manages handlers for neighbour messages.
81 */
Ray Milkeyd04e2272018-10-16 18:20:18 -070082@Component(
83 immediate = true,
84 service = NeighbourResolutionService.class,
85 property = {
Ray Milkey2d7bca12018-10-17 14:51:52 -070086 NRM_ARP_ENABLED + ":Boolean=" + NRM_ARP_ENABLED_DEFAULT,
87 NRM_NDP_ENABLED + ":Boolean=" + NRM_NDP_ENABLED,
88 NRM_REQUEST_INTERCEPTS_ENABLED + ":Boolean=" + NRM_REQUEST_INTERCEPTS_ENABLED_DEFAULT
Ray Milkeyd04e2272018-10-16 18:20:18 -070089 }
90)
Jonathan Hart1e393bb2016-09-14 08:51:09 -070091public class NeighbourResolutionManager implements NeighbourResolutionService {
Jonathan Hart9bdaaec2016-08-22 13:33:45 -070092
93 private final Logger log = LoggerFactory.getLogger(getClass());
94
Ray Milkeyd84f89b2018-08-17 14:54:17 -070095 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Jonathan Hart9bdaaec2016-08-22 13:33:45 -070096 protected CoreService coreService;
97
Ray Milkeyd84f89b2018-08-17 14:54:17 -070098 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Jonathan Hart9bdaaec2016-08-22 13:33:45 -070099 protected HostService hostService;
100
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700101 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700102 protected EdgePortService edgeService;
103
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700104 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700105 protected PacketService packetService;
106
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700107 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700108 protected ComponentConfigService componentConfigService;
109
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700110 //@Property(name = "arpEnabled", boolValue = true,
111 // label = "Enable Address resolution protocol")
Ray Milkeyd04e2272018-10-16 18:20:18 -0700112 protected boolean arpEnabled = NRM_ARP_ENABLED_DEFAULT;
Pier Luigi65a0ab32017-01-12 20:52:38 -0800113
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700114 //@Property(name = "ndpEnabled", boolValue = false,
115 // label = "Enable IPv6 neighbour discovery")
Ray Milkeyd04e2272018-10-16 18:20:18 -0700116 protected boolean ndpEnabled = NRM_NDP_ENABLED_DEFAULT;
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700117
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700118 //@Property(name = "requestInterceptsEnabled", boolValue = true,
119 // label = "Enable requesting packet intercepts")
Ray Milkeyd04e2272018-10-16 18:20:18 -0700120 private boolean requestInterceptsEnabled = NRM_REQUEST_INTERCEPTS_ENABLED_DEFAULT;
Pier Luigi65a0ab32017-01-12 20:52:38 -0800121
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700122 private static final String APP_NAME = "org.onosproject.neighbour";
123 private ApplicationId appId;
124
Jonathan Hartc004adf2016-09-15 16:50:04 -0700125 private final SetMultimap<ConnectPoint, NeighbourHandlerRegistration> packetHandlers =
Jonathan Hartc4f681c2016-09-09 07:14:25 -0700126 Multimaps.synchronizedSetMultimap(HashMultimap.create());
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700127
128 private final InternalPacketProcessor processor = new InternalPacketProcessor();
Jonathan Hart584ea2d2016-10-11 10:49:16 +0200129 private NeighbourMessageActions actions;
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700130
131 @Activate
132 protected void activate(ComponentContext context) {
133 appId = coreService.registerApplication(APP_NAME);
134
135 componentConfigService.registerProperties(getClass());
136 modified(context);
137
Jonathan Hart584ea2d2016-10-11 10:49:16 +0200138 actions = new DefaultNeighbourMessageActions(packetService, edgeService);
139
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700140 packetService.addProcessor(processor, PacketProcessor.director(1));
141 }
142
143 @Deactivate
144 protected void deactivate() {
145 cancelPackets();
146 packetService.removeProcessor(processor);
147 componentConfigService.unregisterProperties(getClass(), false);
148 }
149
150 @Modified
151 protected void modified(ComponentContext context) {
152 Dictionary<?, ?> properties = context.getProperties();
153 Boolean flag;
154
155 flag = Tools.isPropertyEnabled(properties, "ndpEnabled");
156 if (flag != null) {
157 ndpEnabled = flag;
158 log.info("IPv6 neighbor discovery is {}",
159 ndpEnabled ? "enabled" : "disabled");
160 }
161
Pier Luigi65a0ab32017-01-12 20:52:38 -0800162 flag = Tools.isPropertyEnabled(properties, "arpEnabled");
163 if (flag != null) {
164 arpEnabled = flag;
165 log.info("Address resolution protocol is {}",
166 arpEnabled ? "enabled" : "disabled");
167 }
168
169 flag = Tools.isPropertyEnabled(properties, "requestInterceptsEnabled");
170 if (flag == null) {
171 log.info("Request intercepts is not configured, " +
172 "using current value of {}", requestInterceptsEnabled);
173 } else {
174 requestInterceptsEnabled = flag;
175 log.info("Configured. Request intercepts is {}",
176 requestInterceptsEnabled ? "enabled" : "disabled");
177 }
178
Jonathan Hartc004adf2016-09-15 16:50:04 -0700179 synchronized (packetHandlers) {
Pier Luigi65a0ab32017-01-12 20:52:38 -0800180 if (!packetHandlers.isEmpty() && requestInterceptsEnabled) {
Jonathan Hartc004adf2016-09-15 16:50:04 -0700181 requestPackets();
Pier Luigi65a0ab32017-01-12 20:52:38 -0800182 } else {
183 cancelPackets();
Jonathan Hartc004adf2016-09-15 16:50:04 -0700184 }
185 }
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700186 }
187
188 private void requestPackets() {
Pier Luigi65a0ab32017-01-12 20:52:38 -0800189 if (arpEnabled) {
190 packetService.requestPackets(buildArpSelector(), CONTROL, appId);
191 } else {
192 packetService.cancelPackets(buildArpSelector(), CONTROL, appId);
193 }
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700194
195 if (ndpEnabled) {
196 packetService.requestPackets(buildNeighborSolicitationSelector(),
197 CONTROL, appId);
198 packetService.requestPackets(buildNeighborAdvertisementSelector(),
199 CONTROL, appId);
200 } else {
201 packetService.cancelPackets(buildNeighborSolicitationSelector(),
202 CONTROL, appId);
203 packetService.cancelPackets(buildNeighborAdvertisementSelector(),
204 CONTROL, appId);
205 }
206 }
207
208 private void cancelPackets() {
209 packetService.cancelPackets(buildArpSelector(), CONTROL, appId);
210 packetService.cancelPackets(buildNeighborSolicitationSelector(),
211 CONTROL, appId);
212 packetService.cancelPackets(buildNeighborAdvertisementSelector(),
213 CONTROL, appId);
214 }
215
216 private TrafficSelector buildArpSelector() {
217 return DefaultTrafficSelector.builder()
218 .matchEthType(TYPE_ARP)
219 .build();
220 }
221
222 private TrafficSelector buildNeighborSolicitationSelector() {
223 return DefaultTrafficSelector.builder()
224 .matchEthType(TYPE_IPV6)
225 .matchIPProtocol(PROTOCOL_ICMP6)
226 .matchIcmpv6Type(NEIGHBOR_SOLICITATION)
227 .build();
228 }
229
230 private TrafficSelector buildNeighborAdvertisementSelector() {
231 return DefaultTrafficSelector.builder()
232 .matchEthType(TYPE_IPV6)
233 .matchIPProtocol(PROTOCOL_ICMP6)
234 .matchIcmpv6Type(NEIGHBOR_ADVERTISEMENT)
235 .build();
236 }
237
238 @Override
Jonathan Hartc4f681c2016-09-09 07:14:25 -0700239 public void registerNeighbourHandler(ConnectPoint connectPoint,
240 NeighbourMessageHandler handler,
241 ApplicationId appId) {
Jonathan Hartc004adf2016-09-15 16:50:04 -0700242 register(connectPoint, new HandlerRegistration(handler, appId));
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700243 }
244
245 @Override
Jonathan Hartc4f681c2016-09-09 07:14:25 -0700246 public void registerNeighbourHandler(Interface intf,
247 NeighbourMessageHandler handler,
248 ApplicationId appId) {
Jonathan Hartc004adf2016-09-15 16:50:04 -0700249 register(intf.connectPoint(), new HandlerRegistration(handler, intf, appId));
250 }
251
252 private void register(ConnectPoint connectPoint, HandlerRegistration registration) {
253 synchronized (packetHandlers) {
Pier Ventre09f88b82017-01-09 23:01:05 -0800254 if (packetHandlers.isEmpty() && requestInterceptsEnabled) {
Jonathan Hartc004adf2016-09-15 16:50:04 -0700255 requestPackets();
256 }
257 packetHandlers.put(connectPoint, registration);
258 }
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700259 }
260
261 @Override
Jonathan Hartc4f681c2016-09-09 07:14:25 -0700262 public void unregisterNeighbourHandler(ConnectPoint connectPoint,
263 NeighbourMessageHandler handler,
264 ApplicationId appId) {
Jonathan Hartc004adf2016-09-15 16:50:04 -0700265 unregister(connectPoint, new HandlerRegistration(handler, appId));
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700266 }
267
268 @Override
Jonathan Hartc4f681c2016-09-09 07:14:25 -0700269 public void unregisterNeighbourHandler(Interface intf,
270 NeighbourMessageHandler handler,
271 ApplicationId appId) {
Jonathan Hartc004adf2016-09-15 16:50:04 -0700272 unregister(intf.connectPoint(), new HandlerRegistration(handler, intf, appId));
273 }
274
275 private void unregister(ConnectPoint connectPoint, HandlerRegistration registration) {
276 synchronized (packetHandlers) {
277 packetHandlers.remove(connectPoint, registration);
278
279 if (packetHandlers.isEmpty()) {
280 cancelPackets();
281 }
282 }
Jonathan Hartc4f681c2016-09-09 07:14:25 -0700283 }
284
285 @Override
286 public void unregisterNeighbourHandlers(ApplicationId appId) {
287 synchronized (packetHandlers) {
288 Iterator<NeighbourHandlerRegistration> it = packetHandlers.values().iterator();
289
290 while (it.hasNext()) {
291 NeighbourHandlerRegistration registration = it.next();
292 if (registration.appId().equals(appId)) {
293 it.remove();
294 }
295 }
Jonathan Hartc004adf2016-09-15 16:50:04 -0700296
297 if (packetHandlers.isEmpty()) {
298 cancelPackets();
299 }
Jonathan Hartc4f681c2016-09-09 07:14:25 -0700300 }
301 }
302
303 @Override
304 public Map<ConnectPoint, Collection<NeighbourHandlerRegistration>> getHandlerRegistrations() {
Ray Milkeyfb1c7622018-05-18 10:16:53 -0700305 synchronized (packetHandlers) {
306 return ImmutableMap.copyOf(Multimaps.asMap(packetHandlers));
307 }
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700308 }
309
Jonathan Hart584ea2d2016-10-11 10:49:16 +0200310 private void handlePacket(PacketContext context) {
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700311 InboundPacket pkt = context.inPacket();
312 Ethernet ethPkt = pkt.parsed();
313
314 NeighbourMessageContext msgContext =
315 DefaultNeighbourMessageContext.createContext(ethPkt, pkt.receivedFrom(), actions);
316
317 if (msgContext == null) {
318 return;
319 }
320
Pier Ventre0ba98522016-09-19 15:49:14 -0700321 if (handleMessage(msgContext)) {
322 context.block();
323 }
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700324
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700325 }
326
Pier Ventre0ba98522016-09-19 15:49:14 -0700327 private boolean handleMessage(NeighbourMessageContext context) {
Ray Milkeyfb1c7622018-05-18 10:16:53 -0700328 Collection<NeighbourHandlerRegistration> handled;
329 synchronized (packetHandlers) {
330 handled = packetHandlers.get(context.inPort())
331 .stream()
332 .filter(registration -> registration.intf() == null || matches(context, registration.intf()))
333 .collect(Collectors.toSet());
334 }
Pier Ventre0ba98522016-09-19 15:49:14 -0700335 handled.forEach(registration -> registration.handler().handleMessage(context, hostService));
336
337 return !handled.isEmpty();
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700338 }
339
Jonathan Hartc4f681c2016-09-09 07:14:25 -0700340 /**
341 * Checks that incoming packet matches the parameters of the interface.
342 * This means that if the interface specifies a particular parameter
343 * (VLAN, IP address, etc.) then the incoming packet should match those
344 * parameters.
345 *
346 * @param context incoming message context
347 * @param intf interface to check
348 * @return true if the incoming message matches the interface, otherwise false
349 */
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700350 private boolean matches(NeighbourMessageContext context, Interface intf) {
351 checkNotNull(context);
352 checkNotNull(intf);
353
354 boolean matches = true;
Jonathan Hartc4f681c2016-09-09 07:14:25 -0700355 // For non-broadcast packets, if the interface has a MAC address check that
356 // the destination MAC address of the packet matches the interface MAC
357 if (!context.dstMac().isBroadcast() &&
358 !intf.mac().equals(MacAddress.NONE) &&
359 !intf.mac().equals(context.dstMac())) {
360 matches = false;
361 }
362 // If the interface has a VLAN, check that the packet's VLAN matches
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700363 if (!intf.vlan().equals(VlanId.NONE) && !intf.vlan().equals(context.vlan())) {
364 matches = false;
365 }
Jonathan Hartc4f681c2016-09-09 07:14:25 -0700366 // If the interface has IP addresses, check that the packet's target IP
367 // address matches one of the interface IP addresses
368 if (!intf.ipAddressesList().isEmpty() && !hasIp(intf, context.target())) {
369 matches = false;
370 }
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700371
372 return matches;
373 }
374
Jonathan Hartc4f681c2016-09-09 07:14:25 -0700375 /**
376 * Returns true if the interface has the given IP address.
377 *
378 * @param intf interface to check
379 * @param ip IP address
380 * @return true if the IP is configured on the interface, otherwise false
381 */
382 private boolean hasIp(Interface intf, IpAddress ip) {
383 return intf.ipAddressesList().stream()
384 .anyMatch(intfAddress -> intfAddress.ipAddress().equals(ip));
385 }
386
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700387 /**
388 * Stores a neighbour message handler registration.
389 */
Jonathan Hartc4f681c2016-09-09 07:14:25 -0700390 private class HandlerRegistration implements NeighbourHandlerRegistration {
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700391 private final Interface intf;
392 private final NeighbourMessageHandler handler;
Jonathan Hartc4f681c2016-09-09 07:14:25 -0700393 private final ApplicationId appId;
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700394
395 /**
396 * Creates a new handler registration.
397 *
398 * @param handler neighbour message handler
399 */
Jonathan Hartc4f681c2016-09-09 07:14:25 -0700400 public HandlerRegistration(NeighbourMessageHandler handler, ApplicationId appId) {
401 this(handler, null, appId);
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700402 }
403
404 /**
405 * Creates a new handler registration.
406 *
407 * @param handler neighbour message handler
408 * @param intf interface
409 */
Jonathan Hartc4f681c2016-09-09 07:14:25 -0700410 public HandlerRegistration(NeighbourMessageHandler handler, Interface intf, ApplicationId appId) {
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700411 this.intf = intf;
412 this.handler = handler;
Jonathan Hartc4f681c2016-09-09 07:14:25 -0700413 this.appId = appId;
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700414 }
415
Jonathan Hartc4f681c2016-09-09 07:14:25 -0700416 @Override
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700417 public Interface intf() {
418 return intf;
419 }
420
Jonathan Hartc4f681c2016-09-09 07:14:25 -0700421 @Override
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700422 public NeighbourMessageHandler handler() {
423 return handler;
424 }
425
426 @Override
Jonathan Hartc4f681c2016-09-09 07:14:25 -0700427 public ApplicationId appId() {
428 return appId;
429 }
430
431 @Override
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700432 public boolean equals(Object other) {
433 if (this == other) {
434 return true;
435 }
436
437 if (!(other instanceof HandlerRegistration)) {
438 return false;
439 }
440
441 HandlerRegistration that = (HandlerRegistration) other;
442
443 return Objects.equals(intf, that.intf) &&
Jonathan Hartc4f681c2016-09-09 07:14:25 -0700444 Objects.equals(handler, that.handler) &&
445 Objects.equals(appId, that.appId);
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700446 }
447
448 @Override
449 public int hashCode() {
Jonathan Hartc4f681c2016-09-09 07:14:25 -0700450 return Objects.hash(intf, handler, appId);
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700451 }
452 }
453
454 /**
455 * Packet processor for incoming packets.
456 */
457 private class InternalPacketProcessor implements PacketProcessor {
458
459 @Override
460 public void process(PacketContext context) {
461 // Stop processing if the packet has been handled, since we
462 // can't do any more to it.
463 if (context.isHandled()) {
464 return;
465 }
466
467 InboundPacket pkt = context.inPacket();
468 Ethernet ethPkt = pkt.parsed();
469 if (ethPkt == null) {
470 return;
471 }
472
473 if (ethPkt.getEtherType() == TYPE_ARP) {
474 // handle ARP packets
475 handlePacket(context);
476 } else if (ethPkt.getEtherType() == TYPE_IPV6) {
477 IPv6 ipv6 = (IPv6) ethPkt.getPayload();
478 if (ipv6.getNextHeader() == IPv6.PROTOCOL_ICMP6) {
479 ICMP6 icmp6 = (ICMP6) ipv6.getPayload();
480 if (icmp6.getIcmpType() == NEIGHBOR_SOLICITATION ||
481 icmp6.getIcmpType() == NEIGHBOR_ADVERTISEMENT) {
482 // handle ICMPv6 solicitations and advertisements (NDP)
483 handlePacket(context);
484 }
485 }
486 }
487 }
488 }
Jonathan Hart9bdaaec2016-08-22 13:33:45 -0700489}