Committed by
Gerrit Code Review
[CORD-209] Improve config loading of SegmentRouting
Change-Id: I8707a26a9c25d35467e58556f9d3167c91f46e08
Showing
2 changed files
with
36 additions
and
28 deletions
... | @@ -62,6 +62,11 @@ public class DeviceConfiguration implements DeviceProperties { | ... | @@ -62,6 +62,11 @@ public class DeviceConfiguration implements DeviceProperties { |
62 | HashMap<PortNumber, Ip4Address> gatewayIps; | 62 | HashMap<PortNumber, Ip4Address> gatewayIps; |
63 | HashMap<PortNumber, Ip4Prefix> subnets; | 63 | HashMap<PortNumber, Ip4Prefix> subnets; |
64 | List<AdjacencySid> adjacencySids; | 64 | List<AdjacencySid> adjacencySids; |
65 | + | ||
66 | + public SegmentRouterInfo() { | ||
67 | + this.gatewayIps = new HashMap<>(); | ||
68 | + this.subnets = new HashMap<>(); | ||
69 | + } | ||
65 | } | 70 | } |
66 | 71 | ||
67 | /** | 72 | /** |
... | @@ -84,8 +89,6 @@ public class DeviceConfiguration implements DeviceProperties { | ... | @@ -84,8 +89,6 @@ public class DeviceConfiguration implements DeviceProperties { |
84 | info.mac = config.getMac(); | 89 | info.mac = config.getMac(); |
85 | info.isEdge = config.isEdgeRouter(); | 90 | info.isEdge = config.isEdgeRouter(); |
86 | info.adjacencySids = config.getAdjacencySids(); | 91 | info.adjacencySids = config.getAdjacencySids(); |
87 | - info.gatewayIps = new HashMap<>(); | ||
88 | - info.subnets = new HashMap<>(); | ||
89 | 92 | ||
90 | this.deviceConfigMap.put(info.deviceId, info); | 93 | this.deviceConfigMap.put(info.deviceId, info); |
91 | this.allSegmentIds.add(info.nodeSid); | 94 | this.allSegmentIds.add(info.nodeSid); |
... | @@ -109,11 +112,14 @@ public class DeviceConfiguration implements DeviceProperties { | ... | @@ -109,11 +112,14 @@ public class DeviceConfiguration implements DeviceProperties { |
109 | PortNumber port = networkInterface.connectPoint().port(); | 112 | PortNumber port = networkInterface.connectPoint().port(); |
110 | SegmentRouterInfo info = this.deviceConfigMap.get(dpid); | 113 | SegmentRouterInfo info = this.deviceConfigMap.get(dpid); |
111 | 114 | ||
115 | + // skip if there is no corresponding device for this ConenctPoint | ||
116 | + if (info != null) { | ||
112 | Set<InterfaceIpAddress> interfaceAddresses = networkInterface.ipAddresses(); | 117 | Set<InterfaceIpAddress> interfaceAddresses = networkInterface.ipAddresses(); |
113 | interfaceAddresses.forEach(interfaceAddress -> { | 118 | interfaceAddresses.forEach(interfaceAddress -> { |
114 | info.gatewayIps.put(port, interfaceAddress.ipAddress().getIp4Address()); | 119 | info.gatewayIps.put(port, interfaceAddress.ipAddress().getIp4Address()); |
115 | info.subnets.put(port, interfaceAddress.subnetAddress().getIp4Prefix()); | 120 | info.subnets.put(port, interfaceAddress.subnetAddress().getIp4Prefix()); |
116 | }); | 121 | }); |
122 | + } | ||
117 | }); | 123 | }); |
118 | 124 | ||
119 | }); | 125 | }); | ... | ... |
... | @@ -116,11 +116,12 @@ public class SegmentRoutingManager implements SegmentRoutingService { | ... | @@ -116,11 +116,12 @@ public class SegmentRoutingManager implements SegmentRoutingService { |
116 | protected ApplicationId appId; | 116 | protected ApplicationId appId; |
117 | protected DeviceConfiguration deviceConfiguration = null; | 117 | protected DeviceConfiguration deviceConfiguration = null; |
118 | 118 | ||
119 | - | ||
120 | private DefaultRoutingHandler defaultRoutingHandler = null; | 119 | private DefaultRoutingHandler defaultRoutingHandler = null; |
121 | private TunnelHandler tunnelHandler = null; | 120 | private TunnelHandler tunnelHandler = null; |
122 | private PolicyHandler policyHandler = null; | 121 | private PolicyHandler policyHandler = null; |
123 | - private InternalPacketProcessor processor = new InternalPacketProcessor(); | 122 | + private InternalPacketProcessor processor = null; |
123 | + private InternalLinkListener linkListener = null; | ||
124 | + private InternalDeviceListener deviceListener = null; | ||
124 | private InternalEventHandler eventHandler = new InternalEventHandler(); | 125 | private InternalEventHandler eventHandler = new InternalEventHandler(); |
125 | 126 | ||
126 | private ScheduledExecutorService executorService = Executors | 127 | private ScheduledExecutorService executorService = Executors |
... | @@ -214,6 +215,16 @@ public class SegmentRoutingManager implements SegmentRoutingService { | ... | @@ -214,6 +215,16 @@ public class SegmentRoutingManager implements SegmentRoutingService { |
214 | cfgService.addListener(cfgListener); | 215 | cfgService.addListener(cfgListener); |
215 | cfgService.registerConfigFactory(cfgFactory); | 216 | cfgService.registerConfigFactory(cfgFactory); |
216 | 217 | ||
218 | + processor = new InternalPacketProcessor(); | ||
219 | + linkListener = new InternalLinkListener(); | ||
220 | + deviceListener = new InternalDeviceListener(); | ||
221 | + | ||
222 | + packetService.addProcessor(processor, PacketProcessor.director(2)); | ||
223 | + linkService.addListener(linkListener); | ||
224 | + deviceService.addListener(deviceListener); | ||
225 | + | ||
226 | + cfgListener.configureNetwork(); | ||
227 | + | ||
217 | log.info("Started"); | 228 | log.info("Started"); |
218 | } | 229 | } |
219 | 230 | ||
... | @@ -223,7 +234,14 @@ public class SegmentRoutingManager implements SegmentRoutingService { | ... | @@ -223,7 +234,14 @@ public class SegmentRoutingManager implements SegmentRoutingService { |
223 | cfgService.unregisterConfigFactory(cfgFactory); | 234 | cfgService.unregisterConfigFactory(cfgFactory); |
224 | 235 | ||
225 | packetService.removeProcessor(processor); | 236 | packetService.removeProcessor(processor); |
237 | + linkService.removeListener(linkListener); | ||
238 | + deviceService.removeListener(deviceListener); | ||
226 | processor = null; | 239 | processor = null; |
240 | + linkListener = null; | ||
241 | + deviceService = null; | ||
242 | + | ||
243 | + groupHandlerMap.clear(); | ||
244 | + | ||
227 | log.info("Stopped"); | 245 | log.info("Stopped"); |
228 | } | 246 | } |
229 | 247 | ||
... | @@ -284,7 +302,6 @@ public class SegmentRoutingManager implements SegmentRoutingService { | ... | @@ -284,7 +302,6 @@ public class SegmentRoutingManager implements SegmentRoutingService { |
284 | * @return GroupKey object for the NeighborSet | 302 | * @return GroupKey object for the NeighborSet |
285 | */ | 303 | */ |
286 | public GroupKey getGroupKey(NeighborSet ns) { | 304 | public GroupKey getGroupKey(NeighborSet ns) { |
287 | - | ||
288 | for (DefaultGroupHandler groupHandler : groupHandlerMap.values()) { | 305 | for (DefaultGroupHandler groupHandler : groupHandlerMap.values()) { |
289 | return groupHandler.getGroupKey(ns); | 306 | return groupHandler.getGroupKey(ns); |
290 | } | 307 | } |
... | @@ -301,7 +318,6 @@ public class SegmentRoutingManager implements SegmentRoutingService { | ... | @@ -301,7 +318,6 @@ public class SegmentRoutingManager implements SegmentRoutingService { |
301 | * @return next objective ID | 318 | * @return next objective ID |
302 | */ | 319 | */ |
303 | public int getNextObjectiveId(DeviceId deviceId, NeighborSet ns) { | 320 | public int getNextObjectiveId(DeviceId deviceId, NeighborSet ns) { |
304 | - | ||
305 | if (groupHandlerMap.get(deviceId) != null) { | 321 | if (groupHandlerMap.get(deviceId) != null) { |
306 | log.trace("getNextObjectiveId query in device {}", deviceId); | 322 | log.trace("getNextObjectiveId query in device {}", deviceId); |
307 | return groupHandlerMap | 323 | return groupHandlerMap |
... | @@ -313,7 +329,6 @@ public class SegmentRoutingManager implements SegmentRoutingService { | ... | @@ -313,7 +329,6 @@ public class SegmentRoutingManager implements SegmentRoutingService { |
313 | } | 329 | } |
314 | 330 | ||
315 | private class InternalPacketProcessor implements PacketProcessor { | 331 | private class InternalPacketProcessor implements PacketProcessor { |
316 | - | ||
317 | @Override | 332 | @Override |
318 | public void process(PacketContext context) { | 333 | public void process(PacketContext context) { |
319 | 334 | ||
... | @@ -350,16 +365,8 @@ public class SegmentRoutingManager implements SegmentRoutingService { | ... | @@ -350,16 +365,8 @@ public class SegmentRoutingManager implements SegmentRoutingService { |
350 | } | 365 | } |
351 | 366 | ||
352 | private class InternalDeviceListener implements DeviceListener { | 367 | private class InternalDeviceListener implements DeviceListener { |
353 | - | ||
354 | @Override | 368 | @Override |
355 | public void event(DeviceEvent event) { | 369 | public void event(DeviceEvent event) { |
356 | - /*if (mastershipService.getLocalRole(event.subject().id()) != MastershipRole.MASTER) { | ||
357 | - log.debug("Local role {} is not MASTER for device {}", | ||
358 | - mastershipService.getLocalRole(event.subject().id()), | ||
359 | - event.subject().id()); | ||
360 | - return; | ||
361 | - }*/ | ||
362 | - | ||
363 | switch (event.type()) { | 370 | switch (event.type()) { |
364 | case DEVICE_ADDED: | 371 | case DEVICE_ADDED: |
365 | case PORT_REMOVED: | 372 | case PORT_REMOVED: |
... | @@ -374,7 +381,6 @@ public class SegmentRoutingManager implements SegmentRoutingService { | ... | @@ -374,7 +381,6 @@ public class SegmentRoutingManager implements SegmentRoutingService { |
374 | } | 381 | } |
375 | 382 | ||
376 | private void scheduleEventHandlerIfNotScheduled(Event event) { | 383 | private void scheduleEventHandlerIfNotScheduled(Event event) { |
377 | - | ||
378 | synchronized (threadSchedulerLock) { | 384 | synchronized (threadSchedulerLock) { |
379 | eventQueue.add(event); | 385 | eventQueue.add(event); |
380 | numOfEventsQueued++; | 386 | numOfEventsQueued++; |
... | @@ -392,7 +398,6 @@ public class SegmentRoutingManager implements SegmentRoutingService { | ... | @@ -392,7 +398,6 @@ public class SegmentRoutingManager implements SegmentRoutingService { |
392 | } | 398 | } |
393 | 399 | ||
394 | private class InternalEventHandler implements Runnable { | 400 | private class InternalEventHandler implements Runnable { |
395 | - | ||
396 | @Override | 401 | @Override |
397 | public void run() { | 402 | public void run() { |
398 | try { | 403 | try { |
... | @@ -413,8 +418,6 @@ public class SegmentRoutingManager implements SegmentRoutingService { | ... | @@ -413,8 +418,6 @@ public class SegmentRoutingManager implements SegmentRoutingService { |
413 | processLinkAdded((Link) event.subject()); | 418 | processLinkAdded((Link) event.subject()); |
414 | } else if (event.type() == LinkEvent.Type.LINK_REMOVED) { | 419 | } else if (event.type() == LinkEvent.Type.LINK_REMOVED) { |
415 | processLinkRemoved((Link) event.subject()); | 420 | processLinkRemoved((Link) event.subject()); |
416 | - //} else if (event.type() == GroupEvent.Type.GROUP_ADDED) { | ||
417 | - // processGroupAdded((Group) event.subject()); | ||
418 | } else if (event.type() == DeviceEvent.Type.DEVICE_ADDED || | 421 | } else if (event.type() == DeviceEvent.Type.DEVICE_ADDED || |
419 | event.type() == DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED || | 422 | event.type() == DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED || |
420 | event.type() == DeviceEvent.Type.DEVICE_UPDATED) { | 423 | event.type() == DeviceEvent.Type.DEVICE_UPDATED) { |
... | @@ -526,10 +529,6 @@ public class SegmentRoutingManager implements SegmentRoutingService { | ... | @@ -526,10 +529,6 @@ public class SegmentRoutingManager implements SegmentRoutingService { |
526 | flowObjectiveService, | 529 | flowObjectiveService, |
527 | tunnelHandler, policyStore); | 530 | tunnelHandler, policyStore); |
528 | 531 | ||
529 | - packetService.addProcessor(processor, PacketProcessor.director(2)); | ||
530 | - linkService.addListener(new InternalLinkListener()); | ||
531 | - deviceService.addListener(new InternalDeviceListener()); | ||
532 | - | ||
533 | for (Device device : deviceService.getDevices()) { | 532 | for (Device device : deviceService.getDevices()) { |
534 | //Irrespective whether the local is a MASTER or not for this device, | 533 | //Irrespective whether the local is a MASTER or not for this device, |
535 | //create group handler instance and push default TTP flow rules. | 534 | //create group handler instance and push default TTP flow rules. |
... | @@ -550,12 +549,15 @@ public class SegmentRoutingManager implements SegmentRoutingService { | ... | @@ -550,12 +549,15 @@ public class SegmentRoutingManager implements SegmentRoutingService { |
550 | 549 | ||
551 | @Override | 550 | @Override |
552 | public void event(NetworkConfigEvent event) { | 551 | public void event(NetworkConfigEvent event) { |
553 | - if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED || | 552 | + if (event.configClass().equals(SegmentRoutingConfig.class)) { |
554 | - event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) && | 553 | + if (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED) { |
555 | - event.configClass().equals(SegmentRoutingConfig.class)) { | 554 | + log.info("Network configuration added."); |
556 | - log.info("Network configuration change detected. (Re)Configuring..."); | ||
557 | configureNetwork(); | 555 | configureNetwork(); |
558 | - return; | 556 | + } |
557 | + if (event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) { | ||
558 | + log.info("Network configuration updated."); | ||
559 | + // TODO support dynamic configuration | ||
560 | + } | ||
559 | } | 561 | } |
560 | } | 562 | } |
561 | } | 563 | } | ... | ... |
-
Please register or login to post a comment