Jonathan Hart
Committed by Gerrit Code Review

Minor cleanups and renaming in vRouter

Change-Id: I9f5334a0d428f77789880bb9caef5a5d12084f1c
...@@ -133,10 +133,8 @@ public class ControlPlaneRedirectManager { ...@@ -133,10 +133,8 @@ public class ControlPlaneRedirectManager {
133 hostService.addListener(hostListener); 133 hostService.addListener(hostListener);
134 interfaceService.addListener(interfaceListener); 134 interfaceService.addListener(interfaceListener);
135 135
136 - updateConfig(true); 136 + readConfig();
137 - applicationService.registerDeactivateHook(this.appId, () -> { 137 + applicationService.registerDeactivateHook(this.appId, () -> provisionDevice(false));
138 - this.updateConfig(false);
139 - });
140 } 138 }
141 139
142 @Deactivate 140 @Deactivate
...@@ -151,10 +149,8 @@ public class ControlPlaneRedirectManager { ...@@ -151,10 +149,8 @@ public class ControlPlaneRedirectManager {
151 * Installs or removes interface configuration 149 * Installs or removes interface configuration
152 * based on the flag used on activate or deactivate. 150 * based on the flag used on activate or deactivate.
153 * 151 *
154 - * @param operation true on activate application, false on deactivate
155 - * the application
156 **/ 152 **/
157 - private void updateConfig(boolean operation) { 153 + private void readConfig() {
158 ApplicationId routingAppId = 154 ApplicationId routingAppId =
159 coreService.registerApplication(RoutingService.ROUTER_APP_ID); 155 coreService.registerApplication(RoutingService.ROUTER_APP_ID);
160 156
...@@ -170,17 +166,16 @@ public class ControlPlaneRedirectManager { ...@@ -170,17 +166,16 @@ public class ControlPlaneRedirectManager {
170 ospfEnabled = config.getOspfEnabled(); 166 ospfEnabled = config.getOspfEnabled();
171 interfaces = config.getInterfaces(); 167 interfaces = config.getInterfaces();
172 168
173 - updateDevice(operation); 169 + provisionDevice(true);
174 } 170 }
175 171
176 /** 172 /**
177 * Installs or removes interface configuration for each interface 173 * Installs or removes interface configuration for each interface
178 * based on the flag used on activate or deactivate. 174 * based on the flag used on activate or deactivate.
179 * 175 *
180 - * @param operation true on activate application, false on deactivate 176 + * @param install true to install flows, false to remove them
181 - * the application
182 **/ 177 **/
183 - private void updateDevice(boolean operation) { 178 + private void provisionDevice(boolean install) {
184 if (controlPlaneConnectPoint != null && 179 if (controlPlaneConnectPoint != null &&
185 deviceService.isAvailable(controlPlaneConnectPoint.deviceId())) { 180 deviceService.isAvailable(controlPlaneConnectPoint.deviceId())) {
186 DeviceId deviceId = controlPlaneConnectPoint.deviceId(); 181 DeviceId deviceId = controlPlaneConnectPoint.deviceId();
...@@ -188,21 +183,17 @@ public class ControlPlaneRedirectManager { ...@@ -188,21 +183,17 @@ public class ControlPlaneRedirectManager {
188 interfaceService.getInterfaces().stream() 183 interfaceService.getInterfaces().stream()
189 .filter(intf -> intf.connectPoint().deviceId().equals(deviceId)) 184 .filter(intf -> intf.connectPoint().deviceId().equals(deviceId))
190 .filter(intf -> interfaces.isEmpty() || interfaces.contains(intf.name())) 185 .filter(intf -> interfaces.isEmpty() || interfaces.contains(intf.name()))
191 - .forEach(operation ? this::provisionInterface : this::removeInterface); 186 + .forEach(intf -> provisionInterface(intf, install));
192 187
193 log.info("Set up interfaces on {}", controlPlaneConnectPoint.deviceId()); 188 log.info("Set up interfaces on {}", controlPlaneConnectPoint.deviceId());
194 } 189 }
195 } 190 }
196 191
197 - private void removeInterface(Interface intf) { 192 + private void provisionInterface(Interface intf, boolean install) {
198 - modifyBasicInterfaceForwarding(intf, false); 193 + updateInterfaceForwarding(intf, install);
199 - updateOspfForwarding(intf, false); 194 + updateOspfForwarding(intf, install);
200 } 195 }
201 196
202 - private void provisionInterface(Interface intf) {
203 - modifyBasicInterfaceForwarding(intf, true);
204 - updateOspfForwarding(intf, true);
205 - }
206 /** 197 /**
207 * Installs or removes the basic forwarding flows for each interface 198 * Installs or removes the basic forwarding flows for each interface
208 * based on the flag used. 199 * based on the flag used.
...@@ -211,7 +202,7 @@ public class ControlPlaneRedirectManager { ...@@ -211,7 +202,7 @@ public class ControlPlaneRedirectManager {
211 * @param install true to create an add objective, false to create a remove 202 * @param install true to create an add objective, false to create a remove
212 * objective 203 * objective
213 **/ 204 **/
214 - private void modifyBasicInterfaceForwarding(Interface intf, boolean install) { 205 + private void updateInterfaceForwarding(Interface intf, boolean install) {
215 log.debug("Adding interface objectives for {}", intf); 206 log.debug("Adding interface objectives for {}", intf);
216 207
217 DeviceId deviceId = controlPlaneConnectPoint.deviceId(); 208 DeviceId deviceId = controlPlaneConnectPoint.deviceId();
...@@ -361,6 +352,7 @@ public class ControlPlaneRedirectManager { ...@@ -361,6 +352,7 @@ public class ControlPlaneRedirectManager {
361 } 352 }
362 return nextId; 353 return nextId;
363 } 354 }
355 +
364 /** 356 /**
365 * Builds a forwarding objective from the given selector, treatment and nextId. 357 * Builds a forwarding objective from the given selector, treatment and nextId.
366 * 358 *
...@@ -404,7 +396,7 @@ public class ControlPlaneRedirectManager { ...@@ -404,7 +396,7 @@ public class ControlPlaneRedirectManager {
404 case DEVICE_AVAILABILITY_CHANGED: 396 case DEVICE_AVAILABILITY_CHANGED:
405 if (deviceService.isAvailable(event.subject().id())) { 397 if (deviceService.isAvailable(event.subject().id())) {
406 log.info("Device connected {}", event.subject().id()); 398 log.info("Device connected {}", event.subject().id());
407 - updateDevice(true); 399 + provisionDevice(true);
408 } 400 }
409 break; 401 break;
410 case DEVICE_UPDATED: 402 case DEVICE_UPDATED:
...@@ -431,7 +423,7 @@ public class ControlPlaneRedirectManager { ...@@ -431,7 +423,7 @@ public class ControlPlaneRedirectManager {
431 switch (event.type()) { 423 switch (event.type()) {
432 case CONFIG_ADDED: 424 case CONFIG_ADDED:
433 case CONFIG_UPDATED: 425 case CONFIG_UPDATED:
434 - updateConfig(true); 426 + readConfig();
435 break; 427 break;
436 case CONFIG_REGISTERED: 428 case CONFIG_REGISTERED:
437 case CONFIG_UNREGISTERED: 429 case CONFIG_UNREGISTERED:
...@@ -494,7 +486,6 @@ public class ControlPlaneRedirectManager { ...@@ -494,7 +486,6 @@ public class ControlPlaneRedirectManager {
494 return; 486 return;
495 } 487 }
496 488
497 - Set<Integer> nextIds = peerNextId.get(peer);
498 checkState(peerNextId.get(peer) != null, 489 checkState(peerNextId.get(peer) != null,
499 "Peer nextId should not be null"); 490 "Peer nextId should not be null");
500 checkState(peerNextId.get(peer).size() == 2, 491 checkState(peerNextId.get(peer).size() == 2,
...@@ -593,12 +584,12 @@ public class ControlPlaneRedirectManager { ...@@ -593,12 +584,12 @@ public class ControlPlaneRedirectManager {
593 * Update the flows comparing previous event and current event. 584 * Update the flows comparing previous event and current event.
594 * 585 *
595 * @param prevIntf the previous interface event 586 * @param prevIntf the previous interface event
596 - * @param intf the current occured update envent 587 + * @param intf the current occurred update event
597 **/ 588 **/
598 private void updateInterface(Interface prevIntf, Interface intf) { 589 private void updateInterface(Interface prevIntf, Interface intf) {
599 if (!prevIntf.vlan().equals(intf.vlan()) || !prevIntf.mac().equals(intf)) { 590 if (!prevIntf.vlan().equals(intf.vlan()) || !prevIntf.mac().equals(intf)) {
600 - removeInterface(prevIntf); 591 + provisionInterface(prevIntf, false);
601 - provisionInterface(intf); 592 + provisionInterface(intf, true);
602 } else { 593 } else {
603 List<InterfaceIpAddress> removeIps = 594 List<InterfaceIpAddress> removeIps =
604 prevIntf.ipAddressesList().stream() 595 prevIntf.ipAddressesList().stream()
...@@ -609,10 +600,10 @@ public class ControlPlaneRedirectManager { ...@@ -609,10 +600,10 @@ public class ControlPlaneRedirectManager {
609 .filter(cur -> !prevIntf.ipAddressesList().contains(cur)) 600 .filter(cur -> !prevIntf.ipAddressesList().contains(cur))
610 .collect(Collectors.toList()); 601 .collect(Collectors.toList());
611 // removing flows with match parameters present in previous subject 602 // removing flows with match parameters present in previous subject
612 - modifyBasicInterfaceForwarding(new Interface(prevIntf.name(), prevIntf.connectPoint(), 603 + updateInterfaceForwarding(new Interface(prevIntf.name(), prevIntf.connectPoint(),
613 removeIps, prevIntf.mac(), prevIntf.vlan()), false); 604 removeIps, prevIntf.mac(), prevIntf.vlan()), false);
614 // adding flows with match parameters present in event subject 605 // adding flows with match parameters present in event subject
615 - modifyBasicInterfaceForwarding(new Interface(intf.name(), intf.connectPoint(), 606 + updateInterfaceForwarding(new Interface(intf.name(), intf.connectPoint(),
616 addIps, intf.mac(), intf.vlan()), true); 607 addIps, intf.mac(), intf.vlan()), true);
617 } 608 }
618 } 609 }
...@@ -626,7 +617,7 @@ public class ControlPlaneRedirectManager { ...@@ -626,7 +617,7 @@ public class ControlPlaneRedirectManager {
626 switch (event.type()) { 617 switch (event.type()) {
627 case INTERFACE_ADDED: 618 case INTERFACE_ADDED:
628 if (intf != null && !intf.connectPoint().equals(controlPlaneConnectPoint)) { 619 if (intf != null && !intf.connectPoint().equals(controlPlaneConnectPoint)) {
629 - provisionInterface(intf); 620 + provisionInterface(intf, true);
630 } 621 }
631 break; 622 break;
632 case INTERFACE_UPDATED: 623 case INTERFACE_UPDATED:
...@@ -636,7 +627,7 @@ public class ControlPlaneRedirectManager { ...@@ -636,7 +627,7 @@ public class ControlPlaneRedirectManager {
636 break; 627 break;
637 case INTERFACE_REMOVED: 628 case INTERFACE_REMOVED:
638 if (intf != null && !intf.connectPoint().equals(controlPlaneConnectPoint)) { 629 if (intf != null && !intf.connectPoint().equals(controlPlaneConnectPoint)) {
639 - removeInterface(intf); 630 + provisionInterface(intf, false);
640 } 631 }
641 break; 632 break;
642 default: 633 default:
......
...@@ -178,9 +178,7 @@ public class SingleSwitchFibInstaller { ...@@ -178,9 +178,7 @@ public class SingleSwitchFibInstaller {
178 178
179 updateConfig(); 179 updateConfig();
180 180
181 - applicationService.registerDeactivateHook(vrouterAppId, () -> { 181 + applicationService.registerDeactivateHook(vrouterAppId, () -> cleanUp());
182 - this.cleanUp();
183 - });
184 182
185 log.info("Started"); 183 log.info("Started");
186 } 184 }
...@@ -192,8 +190,6 @@ public class SingleSwitchFibInstaller { ...@@ -192,8 +190,6 @@ public class SingleSwitchFibInstaller {
192 interfaceService.removeListener(internalInterfaceList); 190 interfaceService.removeListener(internalInterfaceList);
193 networkConfigService.removeListener(configListener); 191 networkConfigService.removeListener(configListener);
194 192
195 - //processIntfFilters(false, configService.getInterfaces()); //TODO necessary?
196 -
197 componentConfigService.unregisterProperties(getClass(), false); 193 componentConfigService.unregisterProperties(getClass(), false);
198 194
199 log.info("Stopped"); 195 log.info("Stopped");
......
...@@ -261,7 +261,7 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe ...@@ -261,7 +261,7 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe
261 } 261 }
262 } 262 }
263 263
264 - log.debug("adding Port/VLAN/MAC filtering rules in filter table: {}/{}/{}", 264 + log.debug("Modifying Port/VLAN/MAC filtering rules in filter table: {}/{}/{}",
265 p.port(), v.vlanId(), e.mac()); 265 p.port(), v.vlanId(), e.mac());
266 TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); 266 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
267 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); 267 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
...@@ -287,7 +287,6 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe ...@@ -287,7 +287,6 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe
287 .fromApp(applicationId) 287 .fromApp(applicationId)
288 .makePermanent() 288 .makePermanent()
289 .forTable(FILTER_TABLE).build(); 289 .forTable(FILTER_TABLE).build();
290 - ops = ops.add(rule);
291 290
292 ops = install ? ops.add(rule) : ops.remove(rule); 291 ops = install ? ops.add(rule) : ops.remove(rule);
293 // apply filtering flow rules 292 // apply filtering flow rules
......