Add route to each next hop
Change-Id: I4a581545d9539c46194d6f5a6a202120779a60db
diff --git a/apps/routing/src/main/java/org/onosproject/routing/impl/SingleSwitchFibInstaller.java b/apps/routing/src/main/java/org/onosproject/routing/impl/SingleSwitchFibInstaller.java
index 4abd489..aabe8f6 100644
--- a/apps/routing/src/main/java/org/onosproject/routing/impl/SingleSwitchFibInstaller.java
+++ b/apps/routing/src/main/java/org/onosproject/routing/impl/SingleSwitchFibInstaller.java
@@ -24,12 +24,16 @@
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.packet.Ethernet;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.VlanId;
+import org.onlab.util.Tools;
+import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.incubator.net.intf.Interface;
@@ -62,10 +66,12 @@
import org.onosproject.routing.FibUpdate;
import org.onosproject.routing.RoutingService;
import org.onosproject.routing.config.RouterConfig;
+import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
+import java.util.Dictionary;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -98,11 +104,18 @@
protected NetworkConfigService networkConfigService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected ComponentConfigService componentConfigService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected FlowObjectiveService flowObjectiveService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceService deviceService;
+ @Property(name = "routeToNextHop", boolValue = false,
+ label = "Install a /32 route to each next hop")
+ private boolean routeToNextHop = false;
+
private InternalDeviceListener deviceListener;
// Device id of data-plane switch - should be learned from config
@@ -128,9 +141,12 @@
@Activate
- protected void activate() {
+ protected void activate(ComponentContext context) {
+ modified(context);
routerAppId = coreService.registerApplication(RoutingService.ROUTER_APP_ID);
+ componentConfigService.registerProperties(getClass());
+
deviceListener = new InternalDeviceListener();
deviceService.addListener(deviceListener);
@@ -150,9 +166,24 @@
//processIntfFilters(false, configService.getInterfaces()); //TODO necessary?
+ componentConfigService.unregisterProperties(getClass(), false);
+
log.info("Stopped");
}
+ @Modified
+ protected void modified(ComponentContext context) {
+ Dictionary<?, ?> properties = context.getProperties();
+ if (properties == null) {
+ return;
+ }
+
+ String strRouteToNextHop = Tools.get(properties, "routeToNextHop");
+ routeToNextHop = Boolean.parseBoolean(strRouteToNextHop);
+
+ log.info("routeToNextHop set to {}", routeToNextHop);
+ }
+
private void updateConfig() {
RouterConfig routerConfig =
networkConfigService.getConfig(routerAppId, RoutingService.ROUTER_CONFIG_CLASS);
@@ -315,6 +346,12 @@
nextHops.put(nextHop.ip(), nextId);
+ if (routeToNextHop) {
+ // Install route to next hop
+ ForwardingObjective fob =
+ generateRibForwardingObj(IpPrefix.valueOf(entry.nextHopIp(), 32), nextId).add();
+ flowObjectiveService.forward(deviceId, fob);
+ }
}
nextHopsCount.add(entry.nextHopIp());