Committed by
Gerrit Code Review
Add route to each next hop
Change-Id: I4a581545d9539c46194d6f5a6a202120779a60db
Showing
1 changed file
with
38 additions
and
1 deletions
... | @@ -24,12 +24,16 @@ import com.google.common.collect.Multiset; | ... | @@ -24,12 +24,16 @@ import com.google.common.collect.Multiset; |
24 | import org.apache.felix.scr.annotations.Activate; | 24 | import org.apache.felix.scr.annotations.Activate; |
25 | import org.apache.felix.scr.annotations.Component; | 25 | import org.apache.felix.scr.annotations.Component; |
26 | import org.apache.felix.scr.annotations.Deactivate; | 26 | import org.apache.felix.scr.annotations.Deactivate; |
27 | +import org.apache.felix.scr.annotations.Modified; | ||
28 | +import org.apache.felix.scr.annotations.Property; | ||
27 | import org.apache.felix.scr.annotations.Reference; | 29 | import org.apache.felix.scr.annotations.Reference; |
28 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 30 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
29 | import org.onlab.packet.Ethernet; | 31 | import org.onlab.packet.Ethernet; |
30 | import org.onlab.packet.IpAddress; | 32 | import org.onlab.packet.IpAddress; |
31 | import org.onlab.packet.IpPrefix; | 33 | import org.onlab.packet.IpPrefix; |
32 | import org.onlab.packet.VlanId; | 34 | import org.onlab.packet.VlanId; |
35 | +import org.onlab.util.Tools; | ||
36 | +import org.onosproject.cfg.ComponentConfigService; | ||
33 | import org.onosproject.core.ApplicationId; | 37 | import org.onosproject.core.ApplicationId; |
34 | import org.onosproject.core.CoreService; | 38 | import org.onosproject.core.CoreService; |
35 | import org.onosproject.incubator.net.intf.Interface; | 39 | import org.onosproject.incubator.net.intf.Interface; |
... | @@ -62,10 +66,12 @@ import org.onosproject.routing.FibListener; | ... | @@ -62,10 +66,12 @@ import org.onosproject.routing.FibListener; |
62 | import org.onosproject.routing.FibUpdate; | 66 | import org.onosproject.routing.FibUpdate; |
63 | import org.onosproject.routing.RoutingService; | 67 | import org.onosproject.routing.RoutingService; |
64 | import org.onosproject.routing.config.RouterConfig; | 68 | import org.onosproject.routing.config.RouterConfig; |
69 | +import org.osgi.service.component.ComponentContext; | ||
65 | import org.slf4j.Logger; | 70 | import org.slf4j.Logger; |
66 | import org.slf4j.LoggerFactory; | 71 | import org.slf4j.LoggerFactory; |
67 | 72 | ||
68 | import java.util.Collection; | 73 | import java.util.Collection; |
74 | +import java.util.Dictionary; | ||
69 | import java.util.HashMap; | 75 | import java.util.HashMap; |
70 | import java.util.List; | 76 | import java.util.List; |
71 | import java.util.Map; | 77 | import java.util.Map; |
... | @@ -98,11 +104,18 @@ public class SingleSwitchFibInstaller { | ... | @@ -98,11 +104,18 @@ public class SingleSwitchFibInstaller { |
98 | protected NetworkConfigService networkConfigService; | 104 | protected NetworkConfigService networkConfigService; |
99 | 105 | ||
100 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 106 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
107 | + protected ComponentConfigService componentConfigService; | ||
108 | + | ||
109 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
101 | protected FlowObjectiveService flowObjectiveService; | 110 | protected FlowObjectiveService flowObjectiveService; |
102 | 111 | ||
103 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 112 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
104 | protected DeviceService deviceService; | 113 | protected DeviceService deviceService; |
105 | 114 | ||
115 | + @Property(name = "routeToNextHop", boolValue = false, | ||
116 | + label = "Install a /32 route to each next hop") | ||
117 | + private boolean routeToNextHop = false; | ||
118 | + | ||
106 | private InternalDeviceListener deviceListener; | 119 | private InternalDeviceListener deviceListener; |
107 | 120 | ||
108 | // Device id of data-plane switch - should be learned from config | 121 | // Device id of data-plane switch - should be learned from config |
... | @@ -128,9 +141,12 @@ public class SingleSwitchFibInstaller { | ... | @@ -128,9 +141,12 @@ public class SingleSwitchFibInstaller { |
128 | 141 | ||
129 | 142 | ||
130 | @Activate | 143 | @Activate |
131 | - protected void activate() { | 144 | + protected void activate(ComponentContext context) { |
145 | + modified(context); | ||
132 | routerAppId = coreService.registerApplication(RoutingService.ROUTER_APP_ID); | 146 | routerAppId = coreService.registerApplication(RoutingService.ROUTER_APP_ID); |
133 | 147 | ||
148 | + componentConfigService.registerProperties(getClass()); | ||
149 | + | ||
134 | deviceListener = new InternalDeviceListener(); | 150 | deviceListener = new InternalDeviceListener(); |
135 | deviceService.addListener(deviceListener); | 151 | deviceService.addListener(deviceListener); |
136 | 152 | ||
... | @@ -150,9 +166,24 @@ public class SingleSwitchFibInstaller { | ... | @@ -150,9 +166,24 @@ public class SingleSwitchFibInstaller { |
150 | 166 | ||
151 | //processIntfFilters(false, configService.getInterfaces()); //TODO necessary? | 167 | //processIntfFilters(false, configService.getInterfaces()); //TODO necessary? |
152 | 168 | ||
169 | + componentConfigService.unregisterProperties(getClass(), false); | ||
170 | + | ||
153 | log.info("Stopped"); | 171 | log.info("Stopped"); |
154 | } | 172 | } |
155 | 173 | ||
174 | + @Modified | ||
175 | + protected void modified(ComponentContext context) { | ||
176 | + Dictionary<?, ?> properties = context.getProperties(); | ||
177 | + if (properties == null) { | ||
178 | + return; | ||
179 | + } | ||
180 | + | ||
181 | + String strRouteToNextHop = Tools.get(properties, "routeToNextHop"); | ||
182 | + routeToNextHop = Boolean.parseBoolean(strRouteToNextHop); | ||
183 | + | ||
184 | + log.info("routeToNextHop set to {}", routeToNextHop); | ||
185 | + } | ||
186 | + | ||
156 | private void updateConfig() { | 187 | private void updateConfig() { |
157 | RouterConfig routerConfig = | 188 | RouterConfig routerConfig = |
158 | networkConfigService.getConfig(routerAppId, RoutingService.ROUTER_CONFIG_CLASS); | 189 | networkConfigService.getConfig(routerAppId, RoutingService.ROUTER_CONFIG_CLASS); |
... | @@ -315,6 +346,12 @@ public class SingleSwitchFibInstaller { | ... | @@ -315,6 +346,12 @@ public class SingleSwitchFibInstaller { |
315 | 346 | ||
316 | nextHops.put(nextHop.ip(), nextId); | 347 | nextHops.put(nextHop.ip(), nextId); |
317 | 348 | ||
349 | + if (routeToNextHop) { | ||
350 | + // Install route to next hop | ||
351 | + ForwardingObjective fob = | ||
352 | + generateRibForwardingObj(IpPrefix.valueOf(entry.nextHopIp(), 32), nextId).add(); | ||
353 | + flowObjectiveService.forward(deviceId, fob); | ||
354 | + } | ||
318 | } | 355 | } |
319 | 356 | ||
320 | nextHopsCount.add(entry.nextHopIp()); | 357 | nextHopsCount.add(entry.nextHopIp()); | ... | ... |
-
Please register or login to post a comment