Skip to content

Commit

Permalink
Toggle SingleSwitchFibInstaller via component config
Browse files Browse the repository at this point in the history
Fix deactivation issues of vRouter components in addition
Clean up flows installed by SingleSwitchFibInstaller when it is deactivated

Change-Id: I398a38852deaafa693ea20a6cd17b9dd70053f21
  • Loading branch information
charlesmcchan authored and jonohart committed Jan 11, 2017
1 parent 2df0e8a commit 00d8b5f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ public void activate() {
interfaceService.addListener(interfaceListener);

readConfig();

// FIXME There can be an issue when this component is deactivated before vRouter
applicationService.registerDeactivateHook(this.appId, () -> provisionDevice(false));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,8 @@ public class DirectHostManager {
@Activate
public void activate(ComponentContext context) {
componentConfigService.registerProperties(getClass());
modified(context);

appId = coreService.registerApplication(APP_NAME);

if (enabled) {
enable();
}
modified(context);
}

@Modified
Expand Down Expand Up @@ -156,7 +151,9 @@ private void disable() {

@Deactivate
public void deactivate() {
disable();
if (enabled) {
disable();
}

componentConfigService.unregisterProperties(getClass(), false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,19 @@ protected void activate(ComponentContext context) {

updateConfig();

// FIXME: There can be an issue when this component is deactivated before vRouter.
// This will be addressed in CORD-710.
applicationService.registerDeactivateHook(vrouterAppId, () -> cleanUp());

log.info("Started");
}

@Deactivate
protected void deactivate() {
routeService.removeListener(routeListener);
// FIXME: This will also remove flows when an instance goes down.
// This is a temporary solution and should be addressed in CORD-710.
cleanUp();

deviceService.removeListener(deviceListener);
interfaceService.removeListener(internalInterfaceList);
networkConfigService.removeListener(configListener);
Expand Down Expand Up @@ -292,11 +297,10 @@ private Set<Interface> getInterfaces() {
}

private Set<Interface> filterInterfaces(List<String> interfaces) {
Set<Interface> intfs = interfaceService.getInterfaces().stream()
return interfaceService.getInterfaces().stream()
.filter(intf -> intf.connectPoint().deviceId().equals(deviceId))
.filter(intf -> interfaces.contains(intf.name()))
.collect(Collectors.toSet());
return intfs;
}

private void updateRoute(ResolvedRoute route) {
Expand Down
58 changes: 45 additions & 13 deletions apps/vrouter/src/main/java/org/onosproject/vrouter/Vrouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,24 @@
*/
package org.onosproject.vrouter;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Modified;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.util.Tools;
import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.incubator.component.ComponentService;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Dictionary;
import java.util.List;

/**
Expand All @@ -39,35 +44,46 @@ public class Vrouter {
private final Logger log = LoggerFactory.getLogger(getClass());

private static final String APP_NAME = "org.onosproject.vrouter";
private static final String FPM_MANAGER = "org.onosproject.routing.fpm.FpmManager";
private static final String FIB_INSTALLER = "org.onosproject.routing.impl.SingleSwitchFibInstaller";
private static final String CP_REDIRECT = "org.onosproject.routing.impl.ControlPlaneRedirectManager";
private static final String DIRECT_HOST_MGR = "org.onosproject.routing.impl.DirectHostManager";

@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected CoreService coreService;
private CoreService coreService;

@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ComponentService componentService;
private ComponentService componentService;

@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ComponentConfigService componentConfigService;
private ComponentConfigService componentConfigService;

/**
* vRouter will push flows to the switches when receiving routes by enabling
* FIB installer.
* <p>
* It should be turned off when vRouter is deployed in a scenario where
* other components that pushes the routes.
*/
@Property(boolValue = true,
label = "Enable single switch fib installer; default is true")
private static final String FIB_INSTALLED_ENABLED = "fibInstalledEnabled";

private ApplicationId appId;

private final List<String> components = ImmutableList.<String>builder()
.add("org.onosproject.routing.fpm.FpmManager")
.add("org.onosproject.routing.impl.SingleSwitchFibInstaller")
.add("org.onosproject.routing.impl.ControlPlaneRedirectManager")
.add("org.onosproject.routing.impl.DirectHostManager")
.build();

private List<String> baseComponents = Lists.newArrayList(FPM_MANAGER, CP_REDIRECT, DIRECT_HOST_MGR);

@Activate
protected void activate() {
protected void activate(ComponentContext context) {
appId = coreService.registerApplication(APP_NAME);
componentConfigService.registerProperties(getClass());

componentConfigService.preSetProperty(
"org.onosproject.incubator.store.routing.impl.RouteStoreImpl",
"distributed", "true");

components.forEach(name -> componentService.activate(appId, name));
baseComponents.forEach(name -> componentService.activate(appId, name));
modified(context);

log.info("Started");
}
Expand All @@ -81,4 +97,20 @@ protected void deactivate() {
log.info("Stopped");
}

@Modified
private void modified(ComponentContext context) {
Dictionary<?, ?> properties = context.getProperties();
if (properties == null) {
return;
}

boolean fibInstallerEnabled = Boolean.parseBoolean(Tools.get(properties, FIB_INSTALLED_ENABLED));
log.info("fibInstallerEnabled set to {}", fibInstallerEnabled);

if (fibInstallerEnabled) {
componentService.activate(appId, FIB_INSTALLER);
} else {
componentService.deactivate(appId, FIB_INSTALLER);
}
}
}

0 comments on commit 00d8b5f

Please sign in to comment.