Charles Chan
Committed by Gerrit Code Review

Fix NPE in SegmentRoutingManager

NetworkConfigEventHandler must be initialized before adding NetworkConfigEventListener

Change-Id: I8eb40c8b7345b915e613a678df8e8c103980ee21
1 /* 1 /*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015-2016 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -100,6 +100,8 @@ import java.util.concurrent.ScheduledExecutorService; ...@@ -100,6 +100,8 @@ import java.util.concurrent.ScheduledExecutorService;
100 import java.util.concurrent.ScheduledFuture; 100 import java.util.concurrent.ScheduledFuture;
101 import java.util.concurrent.TimeUnit; 101 import java.util.concurrent.TimeUnit;
102 102
103 +import static com.google.common.base.Preconditions.checkState;
104 +
103 @Service 105 @Service
104 @Component(immediate = true) 106 @Component(immediate = true)
105 /** 107 /**
...@@ -321,15 +323,14 @@ public class SegmentRoutingManager implements SegmentRoutingService { ...@@ -321,15 +323,14 @@ public class SegmentRoutingManager implements SegmentRoutingService {
321 .withTimestampProvider((k, v) -> new WallClockTimestamp()) 323 .withTimestampProvider((k, v) -> new WallClockTimestamp())
322 .build(); 324 .build();
323 325
324 - cfgService.addListener(cfgListener);
325 - cfgService.registerConfigFactory(cfgDeviceFactory);
326 - cfgService.registerConfigFactory(cfgAppFactory);
327 -
328 processor = new InternalPacketProcessor(); 326 processor = new InternalPacketProcessor();
329 linkListener = new InternalLinkListener(); 327 linkListener = new InternalLinkListener();
330 deviceListener = new InternalDeviceListener(); 328 deviceListener = new InternalDeviceListener();
331 netcfgHandler = new NetworkConfigEventHandler(this); 329 netcfgHandler = new NetworkConfigEventHandler(this);
332 330
331 + cfgService.addListener(cfgListener);
332 + cfgService.registerConfigFactory(cfgDeviceFactory);
333 + cfgService.registerConfigFactory(cfgAppFactory);
333 hostService.addListener(hostListener); 334 hostService.addListener(hostListener);
334 packetService.addProcessor(processor, PacketProcessor.director(2)); 335 packetService.addProcessor(processor, PacketProcessor.director(2));
335 linkService.addListener(linkListener); 336 linkService.addListener(linkListener);
...@@ -891,6 +892,7 @@ public class SegmentRoutingManager implements SegmentRoutingService { ...@@ -891,6 +892,7 @@ public class SegmentRoutingManager implements SegmentRoutingService {
891 break; 892 break;
892 } 893 }
893 } else if (event.configClass().equals(SegmentRoutingAppConfig.class)) { 894 } else if (event.configClass().equals(SegmentRoutingAppConfig.class)) {
895 + checkState(netcfgHandler != null, "NetworkConfigEventHandler is not initialized");
894 switch (event.type()) { 896 switch (event.type()) {
895 case CONFIG_ADDED: 897 case CONFIG_ADDED:
896 netcfgHandler.processVRouterConfigAdded(event); 898 netcfgHandler.processVRouterConfigAdded(event);
......