Jonathan Hart
Committed by Gerrit Code Review

NeighbourMessageService: Don't push ARP flows when there are no handlers registered.

Fixes ONOS-5277

Change-Id: Ie7ff6ed10d14f4ec8f96327d323ace50c85c8a19
...@@ -111,7 +111,7 @@ public class NeighbourResolutionManager implements NeighbourResolutionService { ...@@ -111,7 +111,7 @@ public class NeighbourResolutionManager implements NeighbourResolutionService {
111 private static final String APP_NAME = "org.onosproject.neighbour"; 111 private static final String APP_NAME = "org.onosproject.neighbour";
112 private ApplicationId appId; 112 private ApplicationId appId;
113 113
114 - private SetMultimap<ConnectPoint, NeighbourHandlerRegistration> packetHandlers = 114 + private final SetMultimap<ConnectPoint, NeighbourHandlerRegistration> packetHandlers =
115 Multimaps.synchronizedSetMultimap(HashMultimap.create()); 115 Multimaps.synchronizedSetMultimap(HashMultimap.create());
116 116
117 private final InternalPacketProcessor processor = new InternalPacketProcessor(); 117 private final InternalPacketProcessor processor = new InternalPacketProcessor();
...@@ -146,7 +146,11 @@ public class NeighbourResolutionManager implements NeighbourResolutionService { ...@@ -146,7 +146,11 @@ public class NeighbourResolutionManager implements NeighbourResolutionService {
146 ndpEnabled ? "enabled" : "disabled"); 146 ndpEnabled ? "enabled" : "disabled");
147 } 147 }
148 148
149 - requestPackets(); 149 + synchronized (packetHandlers) {
150 + if (!packetHandlers.isEmpty()) {
151 + requestPackets();
152 + }
153 + }
150 } 154 }
151 155
152 private void requestPackets() { 156 private void requestPackets() {
...@@ -199,30 +203,47 @@ public class NeighbourResolutionManager implements NeighbourResolutionService { ...@@ -199,30 +203,47 @@ public class NeighbourResolutionManager implements NeighbourResolutionService {
199 public void registerNeighbourHandler(ConnectPoint connectPoint, 203 public void registerNeighbourHandler(ConnectPoint connectPoint,
200 NeighbourMessageHandler handler, 204 NeighbourMessageHandler handler,
201 ApplicationId appId) { 205 ApplicationId appId) {
202 - packetHandlers.put(connectPoint, new HandlerRegistration(handler, appId)); 206 + register(connectPoint, new HandlerRegistration(handler, appId));
203 } 207 }
204 208
205 @Override 209 @Override
206 public void registerNeighbourHandler(Interface intf, 210 public void registerNeighbourHandler(Interface intf,
207 NeighbourMessageHandler handler, 211 NeighbourMessageHandler handler,
208 ApplicationId appId) { 212 ApplicationId appId) {
209 - packetHandlers.put(intf.connectPoint(), 213 + register(intf.connectPoint(), new HandlerRegistration(handler, intf, appId));
210 - new HandlerRegistration(handler, intf, appId)); 214 + }
215 +
216 + private void register(ConnectPoint connectPoint, HandlerRegistration registration) {
217 + synchronized (packetHandlers) {
218 + if (packetHandlers.isEmpty()) {
219 + requestPackets();
220 + }
221 + packetHandlers.put(connectPoint, registration);
222 + }
211 } 223 }
212 224
213 @Override 225 @Override
214 public void unregisterNeighbourHandler(ConnectPoint connectPoint, 226 public void unregisterNeighbourHandler(ConnectPoint connectPoint,
215 NeighbourMessageHandler handler, 227 NeighbourMessageHandler handler,
216 ApplicationId appId) { 228 ApplicationId appId) {
217 - packetHandlers.remove(connectPoint, new HandlerRegistration(handler, appId)); 229 + unregister(connectPoint, new HandlerRegistration(handler, appId));
218 } 230 }
219 231
220 @Override 232 @Override
221 public void unregisterNeighbourHandler(Interface intf, 233 public void unregisterNeighbourHandler(Interface intf,
222 NeighbourMessageHandler handler, 234 NeighbourMessageHandler handler,
223 ApplicationId appId) { 235 ApplicationId appId) {
224 - packetHandlers.remove(intf.connectPoint(), 236 + unregister(intf.connectPoint(), new HandlerRegistration(handler, intf, appId));
225 - new HandlerRegistration(handler, intf, appId)); 237 + }
238 +
239 + private void unregister(ConnectPoint connectPoint, HandlerRegistration registration) {
240 + synchronized (packetHandlers) {
241 + packetHandlers.remove(connectPoint, registration);
242 +
243 + if (packetHandlers.isEmpty()) {
244 + cancelPackets();
245 + }
246 + }
226 } 247 }
227 248
228 @Override 249 @Override
...@@ -236,6 +257,10 @@ public class NeighbourResolutionManager implements NeighbourResolutionService { ...@@ -236,6 +257,10 @@ public class NeighbourResolutionManager implements NeighbourResolutionService {
236 it.remove(); 257 it.remove();
237 } 258 }
238 } 259 }
260 +
261 + if (packetHandlers.isEmpty()) {
262 + cancelPackets();
263 + }
239 } 264 }
240 } 265 }
241 266
...@@ -317,7 +342,6 @@ public class NeighbourResolutionManager implements NeighbourResolutionService { ...@@ -317,7 +342,6 @@ public class NeighbourResolutionManager implements NeighbourResolutionService {
317 .anyMatch(intfAddress -> intfAddress.ipAddress().equals(ip)); 342 .anyMatch(intfAddress -> intfAddress.ipAddress().equals(ip));
318 } 343 }
319 344
320 -
321 private void reply(NeighbourMessageContext context, MacAddress targetMac) { 345 private void reply(NeighbourMessageContext context, MacAddress targetMac) {
322 switch (context.protocol()) { 346 switch (context.protocol()) {
323 case ARP: 347 case ARP:
......