Committed by
Gerrit Code Review
Adapt FIBs to new route interface
Change-Id: I8ac19ad578aac4607fd8319186b6568a21edc1fd
Showing
8 changed files
with
303 additions
and
552 deletions
... | @@ -89,9 +89,9 @@ public class IntentSynchronizer implements IntentSynchronizationService, | ... | @@ -89,9 +89,9 @@ public class IntentSynchronizer implements IntentSynchronizationService, |
89 | 89 | ||
90 | @Activate | 90 | @Activate |
91 | public void activate() { | 91 | public void activate() { |
92 | - intentsSynchronizerExecutor = createExecutor(); | ||
93 | this.localNodeId = clusterService.getLocalNode().id(); | 92 | this.localNodeId = clusterService.getLocalNode().id(); |
94 | this.appId = coreService.registerApplication(APP_NAME); | 93 | this.appId = coreService.registerApplication(APP_NAME); |
94 | + intentsSynchronizerExecutor = createExecutor(); | ||
95 | 95 | ||
96 | leadershipService.addListener(leadershipEventListener); | 96 | leadershipService.addListener(leadershipEventListener); |
97 | leadershipService.runForLeadership(appId.name()); | 97 | leadershipService.runForLeadership(appId.name()); | ... | ... |
... | @@ -17,9 +17,7 @@ | ... | @@ -17,9 +17,7 @@ |
17 | package org.onosproject.routing.impl; | 17 | package org.onosproject.routing.impl; |
18 | 18 | ||
19 | import com.google.common.collect.ConcurrentHashMultiset; | 19 | import com.google.common.collect.ConcurrentHashMultiset; |
20 | -import com.google.common.collect.HashMultimap; | ||
21 | import com.google.common.collect.Maps; | 20 | import com.google.common.collect.Maps; |
22 | -import com.google.common.collect.Multimap; | ||
23 | import com.google.common.collect.Multiset; | 21 | import com.google.common.collect.Multiset; |
24 | import org.apache.felix.scr.annotations.Activate; | 22 | import org.apache.felix.scr.annotations.Activate; |
25 | import org.apache.felix.scr.annotations.Component; | 23 | import org.apache.felix.scr.annotations.Component; |
... | @@ -40,6 +38,10 @@ import org.onosproject.incubator.net.intf.Interface; | ... | @@ -40,6 +38,10 @@ import org.onosproject.incubator.net.intf.Interface; |
40 | import org.onosproject.incubator.net.intf.InterfaceEvent; | 38 | import org.onosproject.incubator.net.intf.InterfaceEvent; |
41 | import org.onosproject.incubator.net.intf.InterfaceListener; | 39 | import org.onosproject.incubator.net.intf.InterfaceListener; |
42 | import org.onosproject.incubator.net.intf.InterfaceService; | 40 | import org.onosproject.incubator.net.intf.InterfaceService; |
41 | +import org.onosproject.incubator.net.routing.ResolvedRoute; | ||
42 | +import org.onosproject.incubator.net.routing.RouteEvent; | ||
43 | +import org.onosproject.incubator.net.routing.RouteListener; | ||
44 | +import org.onosproject.incubator.net.routing.RouteService; | ||
43 | import org.onosproject.net.ConnectPoint; | 45 | import org.onosproject.net.ConnectPoint; |
44 | import org.onosproject.net.DeviceId; | 46 | import org.onosproject.net.DeviceId; |
45 | import org.onosproject.net.config.NetworkConfigEvent; | 47 | import org.onosproject.net.config.NetworkConfigEvent; |
... | @@ -56,24 +58,19 @@ import org.onosproject.net.flow.criteria.Criteria; | ... | @@ -56,24 +58,19 @@ import org.onosproject.net.flow.criteria.Criteria; |
56 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; | 58 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; |
57 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; | 59 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
58 | import org.onosproject.net.flowobjective.DefaultNextObjective; | 60 | import org.onosproject.net.flowobjective.DefaultNextObjective; |
61 | +import org.onosproject.net.flowobjective.DefaultObjectiveContext; | ||
59 | import org.onosproject.net.flowobjective.FilteringObjective; | 62 | import org.onosproject.net.flowobjective.FilteringObjective; |
60 | import org.onosproject.net.flowobjective.FlowObjectiveService; | 63 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
61 | import org.onosproject.net.flowobjective.ForwardingObjective; | 64 | import org.onosproject.net.flowobjective.ForwardingObjective; |
62 | import org.onosproject.net.flowobjective.NextObjective; | 65 | import org.onosproject.net.flowobjective.NextObjective; |
63 | import org.onosproject.net.flowobjective.ObjectiveContext; | 66 | import org.onosproject.net.flowobjective.ObjectiveContext; |
64 | -import org.onosproject.net.flowobjective.DefaultObjectiveContext; | ||
65 | -import org.onosproject.routing.FibEntry; | ||
66 | -import org.onosproject.routing.FibListener; | ||
67 | -import org.onosproject.routing.FibUpdate; | ||
68 | import org.onosproject.routing.RoutingService; | 67 | import org.onosproject.routing.RoutingService; |
69 | import org.onosproject.routing.config.RouterConfig; | 68 | import org.onosproject.routing.config.RouterConfig; |
70 | import org.osgi.service.component.ComponentContext; | 69 | import org.osgi.service.component.ComponentContext; |
71 | import org.slf4j.Logger; | 70 | import org.slf4j.Logger; |
72 | import org.slf4j.LoggerFactory; | 71 | import org.slf4j.LoggerFactory; |
73 | 72 | ||
74 | -import java.util.Collection; | ||
75 | import java.util.Dictionary; | 73 | import java.util.Dictionary; |
76 | -import java.util.HashMap; | ||
77 | import java.util.List; | 74 | import java.util.List; |
78 | import java.util.Map; | 75 | import java.util.Map; |
79 | import java.util.Set; | 76 | import java.util.Set; |
... | @@ -96,7 +93,7 @@ public class SingleSwitchFibInstaller { | ... | @@ -96,7 +93,7 @@ public class SingleSwitchFibInstaller { |
96 | protected CoreService coreService; | 93 | protected CoreService coreService; |
97 | 94 | ||
98 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 95 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
99 | - protected RoutingService routingService; | 96 | + protected RouteService routeService; |
100 | 97 | ||
101 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 98 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
102 | protected InterfaceService interfaceService; | 99 | protected InterfaceService interfaceService; |
... | @@ -137,11 +134,9 @@ public class SingleSwitchFibInstaller { | ... | @@ -137,11 +134,9 @@ public class SingleSwitchFibInstaller { |
137 | // Mapping from next hop IP to next hop object containing group info | 134 | // Mapping from next hop IP to next hop object containing group info |
138 | private final Map<IpAddress, Integer> nextHops = Maps.newHashMap(); | 135 | private final Map<IpAddress, Integer> nextHops = Maps.newHashMap(); |
139 | 136 | ||
140 | - // Stores FIB updates that are waiting for groups to be set up | ||
141 | - private final Multimap<NextHopGroupKey, FibEntry> pendingUpdates = HashMultimap.create(); | ||
142 | - | ||
143 | //interface object for event | 137 | //interface object for event |
144 | private InternalInterfaceListener internalInterfaceList = new InternalInterfaceListener(); | 138 | private InternalInterfaceListener internalInterfaceList = new InternalInterfaceListener(); |
139 | + private InternalRouteListener routeListener = new InternalRouteListener(); | ||
145 | 140 | ||
146 | @Activate | 141 | @Activate |
147 | protected void activate(ComponentContext context) { | 142 | protected void activate(ComponentContext context) { |
... | @@ -155,9 +150,6 @@ public class SingleSwitchFibInstaller { | ... | @@ -155,9 +150,6 @@ public class SingleSwitchFibInstaller { |
155 | 150 | ||
156 | interfaceService.addListener(internalInterfaceList); | 151 | interfaceService.addListener(internalInterfaceList); |
157 | 152 | ||
158 | - routingService.addFibListener(new InternalFibListener()); | ||
159 | - routingService.start(); | ||
160 | - | ||
161 | updateConfig(); | 153 | updateConfig(); |
162 | 154 | ||
163 | log.info("Started"); | 155 | log.info("Started"); |
... | @@ -165,10 +157,8 @@ public class SingleSwitchFibInstaller { | ... | @@ -165,10 +157,8 @@ public class SingleSwitchFibInstaller { |
165 | 157 | ||
166 | @Deactivate | 158 | @Deactivate |
167 | protected void deactivate() { | 159 | protected void deactivate() { |
168 | - routingService.stop(); | 160 | + routeService.removeListener(routeListener); |
169 | - | ||
170 | deviceService.removeListener(deviceListener); | 161 | deviceService.removeListener(deviceListener); |
171 | - | ||
172 | interfaceService.removeListener(internalInterfaceList); | 162 | interfaceService.removeListener(internalInterfaceList); |
173 | 163 | ||
174 | //processIntfFilters(false, configService.getInterfaces()); //TODO necessary? | 164 | //processIntfFilters(false, configService.getInterfaces()); //TODO necessary? |
... | @@ -208,6 +198,8 @@ public class SingleSwitchFibInstaller { | ... | @@ -208,6 +198,8 @@ public class SingleSwitchFibInstaller { |
208 | interfaces = routerConfig.getInterfaces(); | 198 | interfaces = routerConfig.getInterfaces(); |
209 | log.info("Using interfaces: {}", interfaces.isEmpty() ? "all" : interfaces); | 199 | log.info("Using interfaces: {}", interfaces.isEmpty() ? "all" : interfaces); |
210 | 200 | ||
201 | + routeService.addListener(routeListener); | ||
202 | + | ||
211 | updateDevice(); | 203 | updateDevice(); |
212 | } | 204 | } |
213 | 205 | ||
... | @@ -229,55 +221,30 @@ public class SingleSwitchFibInstaller { | ... | @@ -229,55 +221,30 @@ public class SingleSwitchFibInstaller { |
229 | } | 221 | } |
230 | } | 222 | } |
231 | 223 | ||
232 | - private void updateFibEntry(Collection<FibUpdate> updates) { | 224 | + private void updateRoute(ResolvedRoute route) { |
233 | - Map<FibEntry, Integer> toInstall = new HashMap<>(updates.size()); | 225 | + addNextHop(route); |
234 | - | ||
235 | - for (FibUpdate update : updates) { | ||
236 | - FibEntry entry = update.entry(); | ||
237 | - | ||
238 | - addNextHop(entry); | ||
239 | - | ||
240 | - Integer nextId; | ||
241 | - synchronized (pendingUpdates) { | ||
242 | - nextId = nextHops.get(entry.nextHopIp()); | ||
243 | - } | ||
244 | - | ||
245 | - toInstall.put(update.entry(), nextId); | ||
246 | - } | ||
247 | - | ||
248 | - installFlows(toInstall); | ||
249 | - } | ||
250 | - | ||
251 | - private void installFlows(Map<FibEntry, Integer> entriesToInstall) { | ||
252 | - | ||
253 | - for (Map.Entry<FibEntry, Integer> entry : entriesToInstall.entrySet()) { | ||
254 | - FibEntry fibEntry = entry.getKey(); | ||
255 | - Integer nextId = entry.getValue(); | ||
256 | 226 | ||
257 | - flowObjectiveService.forward(deviceId, | 227 | + Integer nextId; |
258 | - generateRibForwardingObj(fibEntry.prefix(), nextId).add()); | 228 | + synchronized (this) { |
259 | - log.trace("Sending forwarding objective {} -> nextId:{}", fibEntry, nextId); | 229 | + nextId = nextHops.get(route.nextHop()); |
260 | } | 230 | } |
261 | 231 | ||
232 | + flowObjectiveService.forward(deviceId, | ||
233 | + generateRibForwardingObj(route.prefix(), nextId).add()); | ||
234 | + log.trace("Sending forwarding objective {} -> nextId:{}", route, nextId); | ||
262 | } | 235 | } |
263 | 236 | ||
264 | - private synchronized void deleteFibEntry(Collection<FibUpdate> withdraws) { | 237 | + private synchronized void deleteRoute(ResolvedRoute route) { |
265 | - | 238 | + //Integer nextId = nextHops.get(route.nextHop()); |
266 | - for (FibUpdate update : withdraws) { | ||
267 | - FibEntry entry = update.entry(); | ||
268 | - //Integer nextId = nextHops.get(entry.nextHopIp()); | ||
269 | - | ||
270 | - /* Group group = deleteNextHop(entry.prefix()); | ||
271 | - if (group == null) { | ||
272 | - log.warn("Group not found when deleting {}", entry); | ||
273 | - return; | ||
274 | - }*/ | ||
275 | - | ||
276 | - flowObjectiveService.forward(deviceId, | ||
277 | - generateRibForwardingObj(entry.prefix(), null).remove()); | ||
278 | 239 | ||
279 | - } | 240 | + /* Group group = deleteNextHop(route.prefix()); |
241 | + if (group == null) { | ||
242 | + log.warn("Group not found when deleting {}", route); | ||
243 | + return; | ||
244 | + }*/ | ||
280 | 245 | ||
246 | + flowObjectiveService.forward(deviceId, | ||
247 | + generateRibForwardingObj(route.prefix(), null).remove()); | ||
281 | } | 248 | } |
282 | 249 | ||
283 | private ForwardingObjective.Builder generateRibForwardingObj(IpPrefix prefix, | 250 | private ForwardingObjective.Builder generateRibForwardingObj(IpPrefix prefix, |
... | @@ -306,20 +273,20 @@ public class SingleSwitchFibInstaller { | ... | @@ -306,20 +273,20 @@ public class SingleSwitchFibInstaller { |
306 | return fwdBuilder; | 273 | return fwdBuilder; |
307 | } | 274 | } |
308 | 275 | ||
309 | - private synchronized void addNextHop(FibEntry entry) { | 276 | + private synchronized void addNextHop(ResolvedRoute route) { |
310 | - prefixToNextHop.put(entry.prefix(), entry.nextHopIp()); | 277 | + prefixToNextHop.put(route.prefix(), route.nextHop()); |
311 | - if (nextHopsCount.count(entry.nextHopIp()) == 0) { | 278 | + if (nextHopsCount.count(route.nextHop()) == 0) { |
312 | // There was no next hop in the multiset | 279 | // There was no next hop in the multiset |
313 | 280 | ||
314 | - Interface egressIntf = interfaceService.getMatchingInterface(entry.nextHopIp()); | 281 | + Interface egressIntf = interfaceService.getMatchingInterface(route.nextHop()); |
315 | if (egressIntf == null) { | 282 | if (egressIntf == null) { |
316 | - log.warn("no egress interface found for {}", entry); | 283 | + log.warn("no egress interface found for {}", route); |
317 | return; | 284 | return; |
318 | } | 285 | } |
319 | 286 | ||
320 | - NextHopGroupKey groupKey = new NextHopGroupKey(entry.nextHopIp()); | 287 | + NextHopGroupKey groupKey = new NextHopGroupKey(route.nextHop()); |
321 | 288 | ||
322 | - NextHop nextHop = new NextHop(entry.nextHopIp(), entry.nextHopMac(), groupKey); | 289 | + NextHop nextHop = new NextHop(route.nextHop(), route.nextHopMac(), groupKey); |
323 | 290 | ||
324 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder() | 291 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder() |
325 | .setEthSrc(egressIntf.mac()) | 292 | .setEthSrc(egressIntf.mac()) |
... | @@ -356,12 +323,12 @@ public class SingleSwitchFibInstaller { | ... | @@ -356,12 +323,12 @@ public class SingleSwitchFibInstaller { |
356 | if (routeToNextHop) { | 323 | if (routeToNextHop) { |
357 | // Install route to next hop | 324 | // Install route to next hop |
358 | ForwardingObjective fob = | 325 | ForwardingObjective fob = |
359 | - generateRibForwardingObj(IpPrefix.valueOf(entry.nextHopIp(), 32), nextId).add(); | 326 | + generateRibForwardingObj(IpPrefix.valueOf(route.nextHop(), 32), nextId).add(); |
360 | flowObjectiveService.forward(deviceId, fob); | 327 | flowObjectiveService.forward(deviceId, fob); |
361 | } | 328 | } |
362 | } | 329 | } |
363 | 330 | ||
364 | - nextHopsCount.add(entry.nextHopIp()); | 331 | + nextHopsCount.add(route.nextHop()); |
365 | } | 332 | } |
366 | 333 | ||
367 | /*private synchronized Group deleteNextHop(IpPrefix prefix) { | 334 | /*private synchronized Group deleteNextHop(IpPrefix prefix) { |
... | @@ -452,13 +419,21 @@ public class SingleSwitchFibInstaller { | ... | @@ -452,13 +419,21 @@ public class SingleSwitchFibInstaller { |
452 | flowObjectiveService.filter(deviceId, filter); | 419 | flowObjectiveService.filter(deviceId, filter); |
453 | } | 420 | } |
454 | 421 | ||
455 | - private class InternalFibListener implements FibListener { | 422 | + private class InternalRouteListener implements RouteListener { |
456 | - | ||
457 | @Override | 423 | @Override |
458 | - public void update(Collection<FibUpdate> updates, | 424 | + public void event(RouteEvent event) { |
459 | - Collection<FibUpdate> withdraws) { | 425 | + ResolvedRoute route = event.subject(); |
460 | - SingleSwitchFibInstaller.this.deleteFibEntry(withdraws); | 426 | + switch (event.type()) { |
461 | - SingleSwitchFibInstaller.this.updateFibEntry(updates); | 427 | + case ROUTE_ADDED: |
428 | + case ROUTE_UPDATED: | ||
429 | + updateRoute(route); | ||
430 | + break; | ||
431 | + case ROUTE_REMOVED: | ||
432 | + deleteRoute(route); | ||
433 | + break; | ||
434 | + default: | ||
435 | + break; | ||
436 | + } | ||
462 | } | 437 | } |
463 | } | 438 | } |
464 | 439 | ... | ... |
... | @@ -15,13 +15,11 @@ | ... | @@ -15,13 +15,11 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.routing.impl; | 16 | package org.onosproject.routing.impl; |
17 | 17 | ||
18 | -import com.google.common.collect.ImmutableSet; | ||
19 | import com.google.common.collect.Sets; | 18 | import com.google.common.collect.Sets; |
20 | import org.easymock.EasyMock; | 19 | import org.easymock.EasyMock; |
21 | import org.junit.Before; | 20 | import org.junit.Before; |
22 | import org.junit.Test; | 21 | import org.junit.Test; |
23 | import org.onlab.packet.Ethernet; | 22 | import org.onlab.packet.Ethernet; |
24 | -import org.onlab.packet.Ip4Address; | ||
25 | import org.onlab.packet.Ip4Prefix; | 23 | import org.onlab.packet.Ip4Prefix; |
26 | import org.onlab.packet.IpAddress; | 24 | import org.onlab.packet.IpAddress; |
27 | import org.onlab.packet.IpPrefix; | 25 | import org.onlab.packet.IpPrefix; |
... | @@ -31,11 +29,14 @@ import org.onosproject.TestApplicationId; | ... | @@ -31,11 +29,14 @@ import org.onosproject.TestApplicationId; |
31 | import org.onosproject.cfg.ComponentConfigService; | 29 | import org.onosproject.cfg.ComponentConfigService; |
32 | import org.onosproject.core.ApplicationId; | 30 | import org.onosproject.core.ApplicationId; |
33 | import org.onosproject.core.CoreService; | 31 | import org.onosproject.core.CoreService; |
34 | -import org.onosproject.core.CoreServiceAdapter; | ||
35 | import org.onosproject.incubator.net.intf.Interface; | 32 | import org.onosproject.incubator.net.intf.Interface; |
36 | import org.onosproject.incubator.net.intf.InterfaceListener; | 33 | import org.onosproject.incubator.net.intf.InterfaceListener; |
37 | import org.onosproject.incubator.net.intf.InterfaceService; | 34 | import org.onosproject.incubator.net.intf.InterfaceService; |
38 | import org.onosproject.incubator.net.intf.InterfaceServiceAdapter; | 35 | import org.onosproject.incubator.net.intf.InterfaceServiceAdapter; |
36 | +import org.onosproject.incubator.net.routing.ResolvedRoute; | ||
37 | +import org.onosproject.incubator.net.routing.RouteEvent; | ||
38 | +import org.onosproject.incubator.net.routing.RouteListener; | ||
39 | +import org.onosproject.incubator.net.routing.RouteServiceAdapter; | ||
39 | import org.onosproject.net.ConnectPoint; | 40 | import org.onosproject.net.ConnectPoint; |
40 | import org.onosproject.net.DeviceId; | 41 | import org.onosproject.net.DeviceId; |
41 | import org.onosproject.net.PortNumber; | 42 | import org.onosproject.net.PortNumber; |
... | @@ -53,25 +54,22 @@ import org.onosproject.net.flowobjective.FlowObjectiveService; | ... | @@ -53,25 +54,22 @@ import org.onosproject.net.flowobjective.FlowObjectiveService; |
53 | import org.onosproject.net.flowobjective.ForwardingObjective; | 54 | import org.onosproject.net.flowobjective.ForwardingObjective; |
54 | import org.onosproject.net.flowobjective.NextObjective; | 55 | import org.onosproject.net.flowobjective.NextObjective; |
55 | import org.onosproject.net.host.InterfaceIpAddress; | 56 | import org.onosproject.net.host.InterfaceIpAddress; |
56 | -import org.onosproject.net.intent.AbstractIntentTest; | ||
57 | -import org.onosproject.routing.FibEntry; | ||
58 | -import org.onosproject.routing.FibListener; | ||
59 | -import org.onosproject.routing.FibUpdate; | ||
60 | import org.onosproject.routing.RoutingService; | 57 | import org.onosproject.routing.RoutingService; |
61 | -import org.onosproject.routing.RoutingServiceAdapter; | ||
62 | import org.onosproject.routing.config.RouterConfig; | 58 | import org.onosproject.routing.config.RouterConfig; |
63 | import org.osgi.service.component.ComponentContext; | 59 | import org.osgi.service.component.ComponentContext; |
64 | 60 | ||
65 | import java.util.ArrayList; | 61 | import java.util.ArrayList; |
66 | import java.util.Collections; | 62 | import java.util.Collections; |
67 | -import java.util.Dictionary; | ||
68 | -import java.util.HashSet; | ||
69 | import java.util.List; | 63 | import java.util.List; |
70 | import java.util.Set; | 64 | import java.util.Set; |
71 | 65 | ||
72 | import static org.easymock.EasyMock.anyObject; | 66 | import static org.easymock.EasyMock.anyObject; |
67 | +import static org.easymock.EasyMock.anyString; | ||
73 | import static org.easymock.EasyMock.createMock; | 68 | import static org.easymock.EasyMock.createMock; |
69 | +import static org.easymock.EasyMock.createNiceMock; | ||
70 | +import static org.easymock.EasyMock.eq; | ||
74 | import static org.easymock.EasyMock.expect; | 71 | import static org.easymock.EasyMock.expect; |
72 | +import static org.easymock.EasyMock.expectLastCall; | ||
75 | import static org.easymock.EasyMock.replay; | 73 | import static org.easymock.EasyMock.replay; |
76 | import static org.easymock.EasyMock.reset; | 74 | import static org.easymock.EasyMock.reset; |
77 | import static org.easymock.EasyMock.verify; | 75 | import static org.easymock.EasyMock.verify; |
... | @@ -79,76 +77,68 @@ import static org.easymock.EasyMock.verify; | ... | @@ -79,76 +77,68 @@ import static org.easymock.EasyMock.verify; |
79 | /** | 77 | /** |
80 | * Unit tests for SingleSwitchFibInstaller. | 78 | * Unit tests for SingleSwitchFibInstaller. |
81 | */ | 79 | */ |
82 | -public class SingleSwitchFibInstallerTest extends AbstractIntentTest { | 80 | +public class SingleSwitchFibInstallerTest { |
81 | + | ||
82 | + private static final DeviceId DEVICE_ID = DeviceId.deviceId("of:0000000000000001"); | ||
83 | 83 | ||
84 | - //for interface service setup | ||
85 | private static final ConnectPoint SW1_ETH1 = new ConnectPoint( | 84 | private static final ConnectPoint SW1_ETH1 = new ConnectPoint( |
86 | - DeviceId.deviceId("of:0000000000000001"), | 85 | + DEVICE_ID, PortNumber.portNumber(1)); |
87 | - PortNumber.portNumber(1)); | 86 | + |
87 | + private static final ConnectPoint SW1_ETH2 = new ConnectPoint( | ||
88 | + DEVICE_ID, PortNumber.portNumber(2)); | ||
88 | 89 | ||
89 | - private static final ConnectPoint SW2_ETH1 = new ConnectPoint( | 90 | + private static final int NEXT_ID = 11; |
90 | - DeviceId.deviceId("of:0000000000000002"), | ||
91 | - PortNumber.portNumber(1)); | ||
92 | 91 | ||
93 | - private static final ConnectPoint SW3_ETH1 = new ConnectPoint( | 92 | + private static final VlanId VLAN1 = VlanId.vlanId((short) 1); |
94 | - DeviceId.deviceId("of:0000000000000003"), | 93 | + private static final MacAddress MAC1 = MacAddress.valueOf("00:00:00:00:00:01"); |
95 | - PortNumber.portNumber(1)); | 94 | + private static final MacAddress MAC2 = MacAddress.valueOf("00:00:00:00:00:02"); |
95 | + | ||
96 | + private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24"); | ||
97 | + private static final IpAddress NEXT_HOP1 = IpAddress.valueOf("192.168.10.1"); | ||
98 | + private static final IpAddress NEXT_HOP2 = IpAddress.valueOf("192.168.20.1"); | ||
99 | + private static final InterfaceIpAddress INTF1 = | ||
100 | + InterfaceIpAddress.valueOf("192.168.10.2/24"); | ||
101 | + private static final InterfaceIpAddress INTF2 = | ||
102 | + InterfaceIpAddress.valueOf("192.168.20.2/24"); | ||
96 | 103 | ||
97 | - private static final ConnectPoint SW4_ETH1 = new ConnectPoint( | ||
98 | - DeviceId.deviceId("of:0000000000000004"), | ||
99 | - PortNumber.portNumber(1)); | ||
100 | 104 | ||
101 | - private DeviceId deviceId = DeviceId.deviceId("of:0000000000000001"); | ||
102 | private final Set<Interface> interfaces = Sets.newHashSet(); | 105 | private final Set<Interface> interfaces = Sets.newHashSet(); |
103 | private InterfaceService interfaceService; | 106 | private InterfaceService interfaceService; |
104 | private NetworkConfigService networkConfigService; | 107 | private NetworkConfigService networkConfigService; |
105 | private FlowObjectiveService flowObjectiveService; | 108 | private FlowObjectiveService flowObjectiveService; |
106 | private DeviceService deviceService; | 109 | private DeviceService deviceService; |
107 | - private static final ApplicationId APPID = TestApplicationId.create("update fib"); | 110 | + private static final ApplicationId APPID = TestApplicationId.create("foo"); |
108 | - private FibListener fibListener; | 111 | + |
112 | + private RouteListener routeListener; | ||
109 | private DeviceListener deviceListener; | 113 | private DeviceListener deviceListener; |
110 | - private CoreService coreService; | 114 | + |
111 | private RouterConfig routerConfig; | 115 | private RouterConfig routerConfig; |
112 | - private RoutingService routingService; | ||
113 | private SingleSwitchFibInstaller sSfibInstaller; | 116 | private SingleSwitchFibInstaller sSfibInstaller; |
114 | private InterfaceListener interfaceListener; | 117 | private InterfaceListener interfaceListener; |
115 | 118 | ||
116 | @Before | 119 | @Before |
117 | public void setUp() throws Exception { | 120 | public void setUp() throws Exception { |
118 | - super.setUp(); | ||
119 | sSfibInstaller = new SingleSwitchFibInstaller(); | 121 | sSfibInstaller = new SingleSwitchFibInstaller(); |
120 | 122 | ||
121 | - //component config service | 123 | + sSfibInstaller.componentConfigService = createNiceMock(ComponentConfigService.class); |
122 | - ComponentConfigService mockComponenetConfigServ = EasyMock.createMock(ComponentConfigService.class); | 124 | + |
123 | - expect(mockComponenetConfigServ.getProperties(anyObject())).andReturn(ImmutableSet.of()); | 125 | + ComponentContext mockContext = createNiceMock(ComponentContext.class); |
124 | - mockComponenetConfigServ.registerProperties(sSfibInstaller.getClass()); | 126 | + |
125 | - EasyMock.expectLastCall(); | ||
126 | - mockComponenetConfigServ.unregisterProperties(sSfibInstaller.getClass(), false); | ||
127 | - EasyMock.expectLastCall(); | ||
128 | - expect(mockComponenetConfigServ.getProperties(anyObject())).andReturn(ImmutableSet.of()); | ||
129 | - sSfibInstaller.componentConfigService = mockComponenetConfigServ; | ||
130 | - replay(mockComponenetConfigServ); | ||
131 | - | ||
132 | - //component context | ||
133 | - ComponentContext mockContext = EasyMock.createMock(ComponentContext.class); | ||
134 | - Dictionary properties = null; | ||
135 | - expect(mockContext.getProperties()).andReturn(properties); | ||
136 | - replay(mockContext); | ||
137 | - | ||
138 | - coreService = new TestCoreService(); | ||
139 | - routingService = new TestRoutingService(); | ||
140 | routerConfig = new TestRouterConfig(); | 127 | routerConfig = new TestRouterConfig(); |
141 | - //interfaceService = createMock(InterfaceService.class); | 128 | + interfaceService = createMock(InterfaceService.class); |
142 | - interfaceService = new TestInterfaceService(); | 129 | + |
143 | networkConfigService = createMock(NetworkConfigService.class); | 130 | networkConfigService = createMock(NetworkConfigService.class); |
144 | flowObjectiveService = createMock(FlowObjectiveService.class); | 131 | flowObjectiveService = createMock(FlowObjectiveService.class); |
145 | deviceService = new TestDeviceService(); | 132 | deviceService = new TestDeviceService(); |
133 | + CoreService coreService = createNiceMock(CoreService.class); | ||
134 | + expect(coreService.registerApplication(anyString())).andReturn(APPID); | ||
135 | + replay(coreService); | ||
146 | 136 | ||
147 | sSfibInstaller.networkConfigService = networkConfigService; | 137 | sSfibInstaller.networkConfigService = networkConfigService; |
148 | sSfibInstaller.interfaceService = interfaceService; | 138 | sSfibInstaller.interfaceService = interfaceService; |
149 | sSfibInstaller.flowObjectiveService = flowObjectiveService; | 139 | sSfibInstaller.flowObjectiveService = flowObjectiveService; |
150 | sSfibInstaller.coreService = coreService; | 140 | sSfibInstaller.coreService = coreService; |
151 | - sSfibInstaller.routingService = new TestRoutingService(); | 141 | + sSfibInstaller.routeService = new TestRouteService(); |
152 | sSfibInstaller.deviceService = deviceService; | 142 | sSfibInstaller.deviceService = deviceService; |
153 | 143 | ||
154 | setUpNetworkConfigService(); | 144 | setUpNetworkConfigService(); |
... | @@ -160,48 +150,32 @@ public class SingleSwitchFibInstallerTest extends AbstractIntentTest { | ... | @@ -160,48 +150,32 @@ public class SingleSwitchFibInstallerTest extends AbstractIntentTest { |
160 | * Sets up InterfaceService. | 150 | * Sets up InterfaceService. |
161 | */ | 151 | */ |
162 | private void setUpInterfaceService() { | 152 | private void setUpInterfaceService() { |
163 | - Set<InterfaceIpAddress> interfaceIpAddresses1 = Sets.newHashSet(); | 153 | + interfaceService.addListener(anyObject(InterfaceListener.class)); |
164 | - interfaceIpAddresses1.add(new InterfaceIpAddress( | 154 | + expectLastCall().andDelegateTo(new TestInterfaceService()); |
165 | - IpAddress.valueOf("192.168.10.1"), | 155 | + |
166 | - IpPrefix.valueOf("192.168.10.0/24"))); | 156 | + // Interface with no VLAN |
167 | - Interface sw1Eth1 = new Interface(SW1_ETH1.deviceId().toString(), SW1_ETH1, | 157 | + Interface sw1Eth1 = new Interface("intf1", SW1_ETH1, |
168 | - interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"), | 158 | + Collections.singletonList(INTF1), MAC1, VlanId.NONE); |
169 | - VlanId.NONE); | 159 | + expect(interfaceService.getMatchingInterface(NEXT_HOP1)).andReturn(sw1Eth1); |
170 | interfaces.add(sw1Eth1); | 160 | interfaces.add(sw1Eth1); |
171 | 161 | ||
172 | - Set<InterfaceIpAddress> interfaceIpAddresses2 = Sets.newHashSet(); | 162 | + // Interface with a VLAN |
173 | - interfaceIpAddresses2.add(new InterfaceIpAddress(IpAddress.valueOf("192.168.20.1"), | 163 | + Interface sw2Eth1 = new Interface("intf2", SW1_ETH2, |
174 | - IpPrefix.valueOf("192.168.20.0/24"))); | 164 | + Collections.singletonList(INTF2), MAC2, VLAN1); |
175 | - Interface sw2Eth1 = new Interface(SW2_ETH1.deviceId().toString(), SW2_ETH1, | 165 | + expect(interfaceService.getMatchingInterface(NEXT_HOP2)).andReturn(sw2Eth1); |
176 | - interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"), | ||
177 | - VlanId.NONE); | ||
178 | interfaces.add(sw2Eth1); | 166 | interfaces.add(sw2Eth1); |
179 | 167 | ||
180 | - Set<InterfaceIpAddress> interfaceIpAddresses3 = Sets.newHashSet(); | 168 | + expect(interfaceService.getInterfaces()).andReturn(interfaces); |
181 | - interfaceIpAddresses3.add( | 169 | + |
182 | - new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"), | 170 | + replay(interfaceService); |
183 | - IpPrefix.valueOf("192.168.30.0/24"))); | ||
184 | - Interface sw3Eth1 = new Interface(SW3_ETH1.deviceId().toString(), SW3_ETH1, | ||
185 | - interfaceIpAddresses3, MacAddress.valueOf("00:00:00:00:00:03"), VlanId.NONE); | ||
186 | - interfaces.add(sw3Eth1); | ||
187 | - | ||
188 | - InterfaceIpAddress interfaceIpAddress4 = | ||
189 | - new InterfaceIpAddress(IpAddress.valueOf("192.168.40.1"), | ||
190 | - IpPrefix.valueOf("192.168.40.0/24")); | ||
191 | - | ||
192 | - Interface sw4Eth1 = new Interface(SW4_ETH1.deviceId().toString(), SW4_ETH1, | ||
193 | - Sets.newHashSet(interfaceIpAddress4), | ||
194 | - MacAddress.valueOf("00:00:00:00:00:04"), | ||
195 | - VlanId.vlanId((short) 1)); | ||
196 | - interfaces.add(sw4Eth1); | ||
197 | } | 171 | } |
198 | 172 | ||
199 | /* | 173 | /* |
200 | * Sets up NetworkConfigService. | 174 | * Sets up NetworkConfigService. |
201 | */ | 175 | */ |
202 | private void setUpNetworkConfigService() { | 176 | private void setUpNetworkConfigService() { |
203 | - ApplicationId routerAppId = coreService.registerApplication(RoutingService.ROUTER_APP_ID); | 177 | + expect(networkConfigService.getConfig( |
204 | - expect(networkConfigService.getConfig(routerAppId, RoutingService.ROUTER_CONFIG_CLASS)). | 178 | + anyObject(ApplicationId.class), eq(RoutingService.ROUTER_CONFIG_CLASS))). |
205 | andReturn(routerConfig); | 179 | andReturn(routerConfig); |
206 | replay(networkConfigService); | 180 | replay(networkConfigService); |
207 | } | 181 | } |
... | @@ -210,41 +184,41 @@ public class SingleSwitchFibInstallerTest extends AbstractIntentTest { | ... | @@ -210,41 +184,41 @@ public class SingleSwitchFibInstallerTest extends AbstractIntentTest { |
210 | * Sets up FlowObjectiveService. | 184 | * Sets up FlowObjectiveService. |
211 | */ | 185 | */ |
212 | private void setUpFlowObjectiveService() { | 186 | private void setUpFlowObjectiveService() { |
213 | - expect(flowObjectiveService.allocateNextId()).andReturn(11); | 187 | + expect(flowObjectiveService.allocateNextId()).andReturn(NEXT_ID); |
214 | replay(flowObjectiveService); | 188 | replay(flowObjectiveService); |
215 | } | 189 | } |
216 | 190 | ||
217 | /** | 191 | /** |
218 | - * Tests adding a FIB entry to the flowObjectiveService. | 192 | + * Creates a next objective with the given parameters. |
219 | * | 193 | * |
220 | - * We verify that the flowObjectiveService records the correct state and that the | 194 | + * @param srcMac source MAC address |
221 | - * correct flow is submitted to the flowObjectiveService. | 195 | + * @param dstMac destination MAC address |
196 | + * @param port port number | ||
197 | + * @param vlan vlan ID | ||
198 | + * @param add whether to create an add objective or remove objective | ||
199 | + * @return new next objective | ||
222 | */ | 200 | */ |
223 | - @Test | 201 | + private NextObjective createNextObjective(MacAddress srcMac, |
224 | - public void testFibAdd() { | 202 | + MacAddress dstMac, |
225 | - IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24"); | 203 | + PortNumber port, |
226 | - FibEntry fibEntry = new FibEntry(prefix, | 204 | + VlanId vlan, |
227 | - Ip4Address.valueOf("192.168.10.1"), | 205 | + boolean add) { |
228 | - MacAddress.valueOf("00:00:00:00:00:01")); | ||
229 | - | ||
230 | - //create the next Objective | ||
231 | - Interface egressIntf = interfaceService.getMatchingInterface(fibEntry.nextHopIp()); | ||
232 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder() | 206 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder() |
233 | - .setEthSrc(MacAddress.valueOf("00:00:00:00:00:01")) | 207 | + .setEthSrc(srcMac) |
234 | - .setEthDst(MacAddress.valueOf("00:00:00:00:00:01")); | 208 | + .setEthDst(dstMac); |
235 | TrafficSelector.Builder metabuilder = null; | 209 | TrafficSelector.Builder metabuilder = null; |
236 | - if (!egressIntf.vlan().equals(VlanId.NONE)) { | 210 | + if (!vlan.equals(VlanId.NONE)) { |
237 | treatment.pushVlan() | 211 | treatment.pushVlan() |
238 | - .setVlanId(egressIntf.vlan()) | 212 | + .setVlanId(vlan) |
239 | - .setVlanPcp((byte) 0); | 213 | + .setVlanPcp((byte) 0); |
240 | } else { | 214 | } else { |
241 | metabuilder = DefaultTrafficSelector.builder(); | 215 | metabuilder = DefaultTrafficSelector.builder(); |
242 | metabuilder.matchVlanId(VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN)); | 216 | metabuilder.matchVlanId(VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN)); |
243 | } | 217 | } |
244 | - treatment.setOutput(PortNumber.portNumber(1)); | 218 | + |
245 | - int nextId = 11; | 219 | + treatment.setOutput(port); |
246 | NextObjective.Builder nextBuilder = DefaultNextObjective.builder() | 220 | NextObjective.Builder nextBuilder = DefaultNextObjective.builder() |
247 | - .withId(nextId) | 221 | + .withId(NEXT_ID) |
248 | .addTreatment(treatment.build()) | 222 | .addTreatment(treatment.build()) |
249 | .withType(NextObjective.Type.SIMPLE) | 223 | .withType(NextObjective.Type.SIMPLE) |
250 | .fromApp(APPID); | 224 | .fromApp(APPID); |
... | @@ -252,10 +226,18 @@ public class SingleSwitchFibInstallerTest extends AbstractIntentTest { | ... | @@ -252,10 +226,18 @@ public class SingleSwitchFibInstallerTest extends AbstractIntentTest { |
252 | nextBuilder.withMeta(metabuilder.build()); | 226 | nextBuilder.withMeta(metabuilder.build()); |
253 | } | 227 | } |
254 | 228 | ||
255 | - NextObjective nextObjective = nextBuilder.add(); | 229 | + return add ? nextBuilder.add() : nextBuilder.remove(); |
256 | - flowObjectiveService.next(deviceId, nextObjective); | 230 | + } |
257 | 231 | ||
258 | - //set up the flowObjective | 232 | + /** |
233 | + * Creates a new forwarding objective with the given parameters. | ||
234 | + * | ||
235 | + * @param prefix IP prefix | ||
236 | + * @param add whether to create an add objective or a remove objective | ||
237 | + * @return new forwarding objective | ||
238 | + */ | ||
239 | + private ForwardingObjective createForwardingObjective(IpPrefix prefix, | ||
240 | + boolean add) { | ||
259 | TrafficSelector selector = DefaultTrafficSelector.builder() | 241 | TrafficSelector selector = DefaultTrafficSelector.builder() |
260 | .matchEthType(Ethernet.TYPE_IPV4) | 242 | .matchEthType(Ethernet.TYPE_IPV4) |
261 | .matchIPDst(prefix) | 243 | .matchIPDst(prefix) |
... | @@ -269,260 +251,134 @@ public class SingleSwitchFibInstallerTest extends AbstractIntentTest { | ... | @@ -269,260 +251,134 @@ public class SingleSwitchFibInstallerTest extends AbstractIntentTest { |
269 | .withPriority(priority) | 251 | .withPriority(priority) |
270 | .withFlag(ForwardingObjective.Flag.SPECIFIC); | 252 | .withFlag(ForwardingObjective.Flag.SPECIFIC); |
271 | 253 | ||
272 | - Integer nextId1 = 11; | 254 | + if (add) { |
273 | - fwdBuilder.nextStep(nextId1); | 255 | + fwdBuilder.nextStep(NEXT_ID); |
274 | - flowObjectiveService.forward(deviceId, fwdBuilder.add()); | 256 | + } else { |
257 | + fwdBuilder.withTreatment(DefaultTrafficTreatment.builder().build()); | ||
258 | + } | ||
259 | + | ||
260 | + return add ? fwdBuilder.add() : fwdBuilder.remove(); | ||
261 | + } | ||
262 | + | ||
263 | + /** | ||
264 | + * Tests adding a route. | ||
265 | + * | ||
266 | + * We verify that the flowObjectiveService records the correct state and that the | ||
267 | + * correct flow is submitted to the flowObjectiveService. | ||
268 | + */ | ||
269 | + @Test | ||
270 | + public void testRouteAdd() { | ||
271 | + ResolvedRoute resolvedRoute = new ResolvedRoute(PREFIX1, NEXT_HOP1, MAC1); | ||
272 | + | ||
273 | + // Create the next objective | ||
274 | + NextObjective nextObjective = createNextObjective(MAC1, MAC1, SW1_ETH1.port(), VlanId.NONE, true); | ||
275 | + flowObjectiveService.next(DEVICE_ID, nextObjective); | ||
276 | + | ||
277 | + // Create the flow objective | ||
278 | + ForwardingObjective fwd = createForwardingObjective(PREFIX1, true); | ||
279 | + flowObjectiveService.forward(DEVICE_ID, fwd); | ||
275 | EasyMock.expectLastCall().once(); | 280 | EasyMock.expectLastCall().once(); |
276 | setUpFlowObjectiveService(); | 281 | setUpFlowObjectiveService(); |
277 | 282 | ||
278 | - // Send in the UPDATE FibUpdate | 283 | + // Send in the add event |
279 | - FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, fibEntry); | 284 | + RouteEvent routeEvent = new RouteEvent(RouteEvent.Type.ROUTE_ADDED, resolvedRoute); |
280 | - fibListener.update(Collections.singleton(fibUpdate), Collections.emptyList()); | 285 | + routeListener.event(routeEvent); |
281 | verify(flowObjectiveService); | 286 | verify(flowObjectiveService); |
282 | } | 287 | } |
283 | 288 | ||
284 | /** | 289 | /** |
285 | - * Tests adding a FIB entry with to a next hop in a VLAN. | 290 | + * Tests adding a route with to a next hop in a VLAN. |
286 | * | 291 | * |
287 | * We verify that the flowObjectiveService records the correct state and that the | 292 | * We verify that the flowObjectiveService records the correct state and that the |
288 | * correct flowObjectiveService is submitted to the flowObjectiveService. | 293 | * correct flowObjectiveService is submitted to the flowObjectiveService. |
289 | */ | 294 | */ |
290 | @Test | 295 | @Test |
291 | - public void testFibAddWithVlan() { | 296 | + public void testRouteAddWithVlan() { |
292 | - IpPrefix prefix = Ip4Prefix.valueOf("3.3.3.0/24"); | 297 | + ResolvedRoute route = new ResolvedRoute(PREFIX1, NEXT_HOP2, MAC2); |
293 | - FibEntry fibEntry = new FibEntry(prefix, | ||
294 | - Ip4Address.valueOf("192.168.40.1"), | ||
295 | - MacAddress.valueOf("00:00:00:00:00:04")); | ||
296 | - | ||
297 | - //create the next Objective | ||
298 | - Interface egressIntf = interfaceService.getMatchingInterface(fibEntry.nextHopIp()); | ||
299 | - TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder() | ||
300 | - .setEthSrc(MacAddress.valueOf("00:00:00:00:00:04")) | ||
301 | - .setEthDst(MacAddress.valueOf("00:00:00:00:00:04")); | ||
302 | - TrafficSelector.Builder metabuilder = null; | ||
303 | - if (!egressIntf.vlan().equals(VlanId.NONE)) { | ||
304 | - treatment.pushVlan() | ||
305 | - .setVlanId(egressIntf.vlan()) | ||
306 | - .setVlanPcp((byte) 0); | ||
307 | - } else { | ||
308 | - metabuilder = DefaultTrafficSelector.builder(); | ||
309 | - metabuilder.matchVlanId(VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN)); | ||
310 | - } | ||
311 | - treatment.setOutput(PortNumber.portNumber(1)); | ||
312 | - int nextId = 11; | ||
313 | - NextObjective.Builder nextBuilder = DefaultNextObjective.builder() | ||
314 | - .withId(nextId) | ||
315 | - .addTreatment(treatment.build()) | ||
316 | - .withType(NextObjective.Type.SIMPLE) | ||
317 | - .fromApp(APPID); | ||
318 | - if (metabuilder != null) { | ||
319 | - nextBuilder.withMeta(metabuilder.build()); | ||
320 | - } | ||
321 | 298 | ||
322 | - NextObjective nextObjective = nextBuilder.add(); | 299 | + // Create the next objective |
323 | - flowObjectiveService.next(deviceId, nextObjective); | 300 | + NextObjective nextObjective = createNextObjective(MAC2, MAC2, SW1_ETH2.port(), VLAN1, true); |
301 | + flowObjectiveService.next(DEVICE_ID, nextObjective); | ||
324 | 302 | ||
325 | - //set up the flowObjective | 303 | + // Create the flow objective |
326 | - TrafficSelector selector = DefaultTrafficSelector.builder() | 304 | + ForwardingObjective fwd = createForwardingObjective(PREFIX1, true); |
327 | - .matchEthType(Ethernet.TYPE_IPV4) | 305 | + flowObjectiveService.forward(DEVICE_ID, fwd); |
328 | - .matchIPDst(prefix) | ||
329 | - .build(); | ||
330 | - | ||
331 | - int priority = prefix.prefixLength() * 5 + 100; | ||
332 | - ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective.builder() | ||
333 | - .fromApp(APPID) | ||
334 | - .makePermanent() | ||
335 | - .withSelector(selector) | ||
336 | - .withPriority(priority) | ||
337 | - .withFlag(ForwardingObjective.Flag.SPECIFIC); | ||
338 | - | ||
339 | - Integer nextId1 = 11; | ||
340 | - fwdBuilder.nextStep(nextId1); | ||
341 | - flowObjectiveService.forward(deviceId, fwdBuilder.add()); | ||
342 | EasyMock.expectLastCall().once(); | 306 | EasyMock.expectLastCall().once(); |
343 | setUpFlowObjectiveService(); | 307 | setUpFlowObjectiveService(); |
344 | 308 | ||
345 | - // Send in the UPDATE FibUpdate | 309 | + // Send in the add event |
346 | - FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, fibEntry); | 310 | + routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route)); |
347 | - fibListener.update(Collections.singleton(fibUpdate), Collections.emptyList()); | ||
348 | 311 | ||
349 | verify(flowObjectiveService); | 312 | verify(flowObjectiveService); |
350 | } | 313 | } |
351 | 314 | ||
352 | /** | 315 | /** |
353 | - * Tests updating a FIB entry. | 316 | + * Tests updating a route. |
354 | * | 317 | * |
355 | * We verify that the flowObjectiveService records the correct state and that the | 318 | * We verify that the flowObjectiveService records the correct state and that the |
356 | * correct flow is submitted to the flowObjectiveService. | 319 | * correct flow is submitted to the flowObjectiveService. |
357 | */ | 320 | */ |
358 | @Test | 321 | @Test |
359 | - public void testFibUpdate() { | 322 | + public void testRouteUpdate() { |
360 | // Firstly add a route | 323 | // Firstly add a route |
361 | - testFibAdd(); | 324 | + testRouteAdd(); |
362 | reset(flowObjectiveService); | 325 | reset(flowObjectiveService); |
363 | - IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24"); | ||
364 | - // Start to construct a new route entry and new intent | ||
365 | - FibEntry fibEntryUpdate = new FibEntry(prefix, | ||
366 | - Ip4Address.valueOf("192.168.20.1"), | ||
367 | - MacAddress.valueOf("00:00:00:00:00:02")); | ||
368 | - | ||
369 | - //create the next Objective | ||
370 | - Interface egressIntf = interfaceService.getMatchingInterface(fibEntryUpdate.nextHopIp()); | ||
371 | - TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder() | ||
372 | - .setEthSrc(MacAddress.valueOf("00:00:00:00:00:02")) | ||
373 | - .setEthDst(MacAddress.valueOf("00:00:00:00:00:02")); | ||
374 | - TrafficSelector.Builder metabuilder = null; | ||
375 | - if (!egressIntf.vlan().equals(VlanId.NONE)) { | ||
376 | - treatment.pushVlan() | ||
377 | - .setVlanId(egressIntf.vlan()) | ||
378 | - .setVlanPcp((byte) 0); | ||
379 | - } else { | ||
380 | - metabuilder = DefaultTrafficSelector.builder(); | ||
381 | - metabuilder.matchVlanId(VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN)); | ||
382 | - } | ||
383 | - treatment.setOutput(PortNumber.portNumber(1)); | ||
384 | - int nextId = 11; | ||
385 | - NextObjective.Builder nextBuilder = DefaultNextObjective.builder() | ||
386 | - .withId(nextId) | ||
387 | - .addTreatment(treatment.build()) | ||
388 | - .withType(NextObjective.Type.SIMPLE) | ||
389 | - .fromApp(APPID); | ||
390 | - if (metabuilder != null) { | ||
391 | - nextBuilder.withMeta(metabuilder.build()); | ||
392 | - } | ||
393 | 326 | ||
394 | - NextObjective nextObjective = nextBuilder.add(); | 327 | + ResolvedRoute route = new ResolvedRoute(PREFIX1, NEXT_HOP2, MAC2); |
395 | - flowObjectiveService.next(deviceId, nextObjective); | ||
396 | - | ||
397 | - //set up the flowObjective | ||
398 | - TrafficSelector selector = DefaultTrafficSelector.builder() | ||
399 | - .matchEthType(Ethernet.TYPE_IPV4) | ||
400 | - .matchIPDst(prefix) | ||
401 | - .build(); | ||
402 | 328 | ||
403 | - int priority = prefix.prefixLength() * 5 + 100; | 329 | + // Create the next objective |
404 | - ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective.builder() | 330 | + NextObjective nextObjective = createNextObjective(MAC2, MAC2, SW1_ETH2.port(), VLAN1, true); |
405 | - .fromApp(APPID) | 331 | + flowObjectiveService.next(DEVICE_ID, nextObjective); |
406 | - .makePermanent() | ||
407 | - .withSelector(selector) | ||
408 | - .withPriority(priority) | ||
409 | - .withFlag(ForwardingObjective.Flag.SPECIFIC); | ||
410 | 332 | ||
411 | - Integer nextId1 = 11; | 333 | + // Create the flow objective |
412 | - fwdBuilder.nextStep(nextId1); | 334 | + ForwardingObjective fwd = createForwardingObjective(PREFIX1, true); |
413 | - flowObjectiveService.forward(deviceId, fwdBuilder.add()); | 335 | + flowObjectiveService.forward(DEVICE_ID, fwd); |
414 | EasyMock.expectLastCall().once(); | 336 | EasyMock.expectLastCall().once(); |
415 | setUpFlowObjectiveService(); | 337 | setUpFlowObjectiveService(); |
416 | 338 | ||
417 | - // Send in the UPDATE FibUpdate | 339 | + // Send in the update event |
418 | - FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, | 340 | + routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_UPDATED, route)); |
419 | - fibEntryUpdate); | ||
420 | - fibListener.update(Collections.singletonList(fibUpdate), | ||
421 | - Collections.emptyList()); | ||
422 | 341 | ||
423 | verify(flowObjectiveService); | 342 | verify(flowObjectiveService); |
424 | } | 343 | } |
425 | 344 | ||
426 | /** | 345 | /** |
427 | - * Tests deleting a FIB entry. | 346 | + * Tests deleting a route. |
428 | * | 347 | * |
429 | * We verify that the flowObjectiveService records the correct state and that the | 348 | * We verify that the flowObjectiveService records the correct state and that the |
430 | * correct flow is withdrawn from the flowObjectiveService. | 349 | * correct flow is withdrawn from the flowObjectiveService. |
431 | */ | 350 | */ |
432 | @Test | 351 | @Test |
433 | - public void testFibDelete() { | 352 | + public void testRouteDelete() { |
434 | // Firstly add a route | 353 | // Firstly add a route |
435 | - testFibAdd(); | 354 | + testRouteAdd(); |
436 | - IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24"); | ||
437 | 355 | ||
438 | - // Construct the existing route entry | 356 | + // Construct the existing route |
439 | - FibEntry fibEntry = new FibEntry(prefix, null, null); | 357 | + ResolvedRoute route = new ResolvedRoute(PREFIX1, null, null); |
440 | 358 | ||
441 | - //set up the flowObjective | 359 | + // Create the flow objective |
442 | - TrafficSelector selector = DefaultTrafficSelector.builder() | ||
443 | - .matchEthType(Ethernet.TYPE_IPV4) | ||
444 | - .matchIPDst(prefix) | ||
445 | - .build(); | ||
446 | - | ||
447 | - int priority = prefix.prefixLength() * 5 + 100; | ||
448 | - | ||
449 | - ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective.builder() | ||
450 | - .fromApp(APPID) | ||
451 | - .makePermanent() | ||
452 | - .withSelector(selector) | ||
453 | - .withPriority(priority) | ||
454 | - .withFlag(ForwardingObjective.Flag.SPECIFIC); | ||
455 | - fwdBuilder.withTreatment(DefaultTrafficTreatment.builder().build()); | ||
456 | reset(flowObjectiveService); | 360 | reset(flowObjectiveService); |
457 | - flowObjectiveService.forward(deviceId, fwdBuilder.remove()); | 361 | + ForwardingObjective fwd = createForwardingObjective(PREFIX1, false); |
362 | + flowObjectiveService.forward(DEVICE_ID, fwd); | ||
458 | replay(flowObjectiveService); | 363 | replay(flowObjectiveService); |
459 | 364 | ||
460 | - // Send in the DELETE FibUpdate | 365 | + // Send in the delete event |
461 | - FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.DELETE, fibEntry); | 366 | + routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_REMOVED, route)); |
462 | - fibListener.update(Collections.emptyList(), Collections.singletonList(fibUpdate)); | ||
463 | 367 | ||
464 | verify(flowObjectiveService); | 368 | verify(flowObjectiveService); |
465 | } | 369 | } |
466 | 370 | ||
467 | private class TestInterfaceService extends InterfaceServiceAdapter { | 371 | private class TestInterfaceService extends InterfaceServiceAdapter { |
468 | - | ||
469 | @Override | 372 | @Override |
470 | public void addListener(InterfaceListener listener) { | 373 | public void addListener(InterfaceListener listener) { |
471 | - SingleSwitchFibInstallerTest.this.interfaceListener = listener; | 374 | + interfaceListener = listener; |
472 | - } | ||
473 | - | ||
474 | - @Override | ||
475 | - public Set<Interface> getInterfaces() { | ||
476 | - return interfaces; | ||
477 | - } | ||
478 | - | ||
479 | - @Override | ||
480 | - public Set<Interface> getInterfacesByPort(ConnectPoint port) { | ||
481 | - | ||
482 | - Set<Interface> setIntf = new HashSet<Interface>(); | ||
483 | - for (Interface intf : interfaces) { | ||
484 | - if (intf.connectPoint().equals(port)) { | ||
485 | - setIntf.add(intf); | ||
486 | - | ||
487 | - } | ||
488 | - } | ||
489 | - return setIntf; | ||
490 | - } | ||
491 | - | ||
492 | - @Override | ||
493 | - public Interface getMatchingInterface(IpAddress ip) { | ||
494 | - Interface intff = null; | ||
495 | - for (Interface intf : interfaces) { | ||
496 | - for (InterfaceIpAddress address : intf.ipAddresses()) { | ||
497 | - if (address.ipAddress().equals(ip)) { | ||
498 | - intff = intf; | ||
499 | - break; | ||
500 | - } | ||
501 | - } | ||
502 | - } | ||
503 | - | ||
504 | - return intff; | ||
505 | - } | ||
506 | - } | ||
507 | - | ||
508 | - private class TestCoreService extends CoreServiceAdapter { | ||
509 | - | ||
510 | - @Override | ||
511 | - public ApplicationId getAppId(String name) { | ||
512 | - return APPID; | ||
513 | - } | ||
514 | - | ||
515 | - @Override | ||
516 | - public ApplicationId registerApplication(String name) { | ||
517 | - return APPID; | ||
518 | } | 375 | } |
519 | } | 376 | } |
520 | 377 | ||
521 | - private class TestRoutingService extends RoutingServiceAdapter { | 378 | + private class TestRouteService extends RouteServiceAdapter { |
522 | - | ||
523 | @Override | 379 | @Override |
524 | - public void addFibListener(FibListener fibListener) { | 380 | + public void addListener(RouteListener listener) { |
525 | - SingleSwitchFibInstallerTest.this.fibListener = fibListener; | 381 | + SingleSwitchFibInstallerTest.this.routeListener = listener; |
526 | } | 382 | } |
527 | } | 383 | } |
528 | 384 | ||
... | @@ -532,9 +388,7 @@ public class SingleSwitchFibInstallerTest extends AbstractIntentTest { | ... | @@ -532,9 +388,7 @@ public class SingleSwitchFibInstallerTest extends AbstractIntentTest { |
532 | public List<String> getInterfaces() { | 388 | public List<String> getInterfaces() { |
533 | ArrayList<String> interfaces = new ArrayList<>(); | 389 | ArrayList<String> interfaces = new ArrayList<>(); |
534 | interfaces.add("of:0000000000000001/1"); | 390 | interfaces.add("of:0000000000000001/1"); |
535 | - interfaces.add("of:0000000000000002/1"); | 391 | + interfaces.add("of:0000000000000001/2"); |
536 | - interfaces.add("of:0000000000000003/1"); | ||
537 | - interfaces.add("of:0000000000000004/1"); | ||
538 | return interfaces; | 392 | return interfaces; |
539 | } | 393 | } |
540 | 394 | ... | ... |
... | @@ -73,7 +73,6 @@ public class SdnIp { | ... | @@ -73,7 +73,6 @@ public class SdnIp { |
73 | private static List<String> components = new ArrayList<>(); | 73 | private static List<String> components = new ArrayList<>(); |
74 | static { | 74 | static { |
75 | components.add("org.onosproject.routing.bgp.BgpSessionManager"); | 75 | components.add("org.onosproject.routing.bgp.BgpSessionManager"); |
76 | - components.add("org.onosproject.routing.impl.Router"); | ||
77 | components.add(org.onosproject.sdnip.SdnIpFib.class.getName()); | 76 | components.add(org.onosproject.sdnip.SdnIpFib.class.getName()); |
78 | } | 77 | } |
79 | 78 | ... | ... |
... | @@ -34,6 +34,10 @@ import org.onosproject.incubator.net.intf.Interface; | ... | @@ -34,6 +34,10 @@ import org.onosproject.incubator.net.intf.Interface; |
34 | import org.onosproject.incubator.net.intf.InterfaceEvent; | 34 | import org.onosproject.incubator.net.intf.InterfaceEvent; |
35 | import org.onosproject.incubator.net.intf.InterfaceListener; | 35 | import org.onosproject.incubator.net.intf.InterfaceListener; |
36 | import org.onosproject.incubator.net.intf.InterfaceService; | 36 | import org.onosproject.incubator.net.intf.InterfaceService; |
37 | +import org.onosproject.incubator.net.routing.ResolvedRoute; | ||
38 | +import org.onosproject.incubator.net.routing.RouteEvent; | ||
39 | +import org.onosproject.incubator.net.routing.RouteListener; | ||
40 | +import org.onosproject.incubator.net.routing.RouteService; | ||
37 | import org.onosproject.net.ConnectPoint; | 41 | import org.onosproject.net.ConnectPoint; |
38 | import org.onosproject.net.flow.DefaultTrafficSelector; | 42 | import org.onosproject.net.flow.DefaultTrafficSelector; |
39 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 43 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
... | @@ -43,21 +47,15 @@ import org.onosproject.net.intent.Constraint; | ... | @@ -43,21 +47,15 @@ import org.onosproject.net.intent.Constraint; |
43 | import org.onosproject.net.intent.Key; | 47 | import org.onosproject.net.intent.Key; |
44 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; | 48 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; |
45 | import org.onosproject.net.intent.constraint.PartialFailureConstraint; | 49 | import org.onosproject.net.intent.constraint.PartialFailureConstraint; |
46 | -import org.onosproject.routing.FibListener; | ||
47 | -import org.onosproject.routing.FibUpdate; | ||
48 | import org.onosproject.routing.IntentSynchronizationService; | 50 | import org.onosproject.routing.IntentSynchronizationService; |
49 | -import org.onosproject.routing.RoutingService; | ||
50 | import org.slf4j.Logger; | 51 | import org.slf4j.Logger; |
51 | import org.slf4j.LoggerFactory; | 52 | import org.slf4j.LoggerFactory; |
52 | 53 | ||
53 | -import java.util.Collection; | ||
54 | import java.util.HashSet; | 54 | import java.util.HashSet; |
55 | import java.util.Map; | 55 | import java.util.Map; |
56 | import java.util.Set; | 56 | import java.util.Set; |
57 | import java.util.concurrent.ConcurrentHashMap; | 57 | import java.util.concurrent.ConcurrentHashMap; |
58 | 58 | ||
59 | -import static com.google.common.base.Preconditions.checkArgument; | ||
60 | - | ||
61 | /** | 59 | /** |
62 | * FIB component of SDN-IP. | 60 | * FIB component of SDN-IP. |
63 | */ | 61 | */ |
... | @@ -75,9 +73,9 @@ public class SdnIpFib { | ... | @@ -75,9 +73,9 @@ public class SdnIpFib { |
75 | protected CoreService coreService; | 73 | protected CoreService coreService; |
76 | 74 | ||
77 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 75 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
78 | - protected RoutingService routingService; | 76 | + protected RouteService routeService; |
79 | 77 | ||
80 | - private final InternalFibListener fibListener = new InternalFibListener(); | 78 | + private final InternalRouteListener routeListener = new InternalRouteListener(); |
81 | private final InternalInterfaceListener interfaceListener = new InternalInterfaceListener(); | 79 | private final InternalInterfaceListener interfaceListener = new InternalInterfaceListener(); |
82 | 80 | ||
83 | private static final int PRIORITY_OFFSET = 100; | 81 | private static final int PRIORITY_OFFSET = 100; |
... | @@ -96,69 +94,41 @@ public class SdnIpFib { | ... | @@ -96,69 +94,41 @@ public class SdnIpFib { |
96 | 94 | ||
97 | interfaceService.addListener(interfaceListener); | 95 | interfaceService.addListener(interfaceListener); |
98 | 96 | ||
99 | - routingService.addFibListener(fibListener); | 97 | + routeService.addListener(routeListener); |
100 | - routingService.start(); | ||
101 | } | 98 | } |
102 | 99 | ||
103 | @Deactivate | 100 | @Deactivate |
104 | public void deactivate() { | 101 | public void deactivate() { |
105 | interfaceService.removeListener(interfaceListener); | 102 | interfaceService.removeListener(interfaceListener); |
106 | - // TODO remove listener | 103 | + routeService.removeListener(routeListener); |
107 | - routingService.stop(); | ||
108 | } | 104 | } |
109 | 105 | ||
110 | - private void update(Collection<FibUpdate> updates, Collection<FibUpdate> withdraws) { | 106 | + private void update(ResolvedRoute route) { |
111 | - int submitCount = 0, withdrawCount = 0; | ||
112 | - // | ||
113 | - // NOTE: Semantically, we MUST withdraw existing intents before | ||
114 | - // submitting new intents. | ||
115 | - // | ||
116 | synchronized (this) { | 107 | synchronized (this) { |
117 | - MultiPointToSinglePointIntent intent; | 108 | + IpPrefix prefix = route.prefix(); |
118 | - | 109 | + MultiPointToSinglePointIntent intent = |
119 | - // | 110 | + generateRouteIntent(prefix, route.nextHop(), route.nextHopMac()); |
120 | - // Prepare the Intent batch operations for the intents to withdraw | 111 | + |
121 | - // | 112 | + if (intent == null) { |
122 | - for (FibUpdate withdraw : withdraws) { | 113 | + log.debug("SDN-IP no interface found for route {}", route); |
123 | - checkArgument(withdraw.type() == FibUpdate.Type.DELETE, | 114 | + return; |
124 | - "FibUpdate with wrong type in withdraws list"); | ||
125 | - | ||
126 | - IpPrefix prefix = withdraw.entry().prefix(); | ||
127 | - intent = routeIntents.remove(prefix); | ||
128 | - if (intent == null) { | ||
129 | - log.trace("SDN-IP No intent in routeIntents to delete " + | ||
130 | - "for prefix: {}", prefix); | ||
131 | - continue; | ||
132 | - } | ||
133 | - intentSynchronizer.withdraw(intent); | ||
134 | - withdrawCount++; | ||
135 | } | 115 | } |
136 | 116 | ||
137 | - // | 117 | + routeIntents.put(prefix, intent); |
138 | - // Prepare the Intent batch operations for the intents to submit | 118 | + intentSynchronizer.submit(intent); |
139 | - // | 119 | + } |
140 | - for (FibUpdate update : updates) { | 120 | + } |
141 | - checkArgument(update.type() == FibUpdate.Type.UPDATE, | ||
142 | - "FibUpdate with wrong type in updates list"); | ||
143 | - | ||
144 | - IpPrefix prefix = update.entry().prefix(); | ||
145 | - intent = generateRouteIntent(prefix, update.entry().nextHopIp(), | ||
146 | - update.entry().nextHopMac()); | ||
147 | - | ||
148 | - if (intent == null) { | ||
149 | - // This preserves the old semantics - if an intent can't be | ||
150 | - // generated, we don't do anything with that prefix. But | ||
151 | - // perhaps we should withdraw the old intent anyway? | ||
152 | - continue; | ||
153 | - } | ||
154 | 121 | ||
155 | - routeIntents.put(prefix, intent); | 122 | + private void withdraw(ResolvedRoute route) { |
156 | - intentSynchronizer.submit(intent); | 123 | + synchronized (this) { |
157 | - submitCount++; | 124 | + IpPrefix prefix = route.prefix(); |
125 | + MultiPointToSinglePointIntent intent = routeIntents.remove(prefix); | ||
126 | + if (intent == null) { | ||
127 | + log.trace("SDN-IP no intent in routeIntents to delete " + | ||
128 | + "for prefix: {}", prefix); | ||
129 | + return; | ||
158 | } | 130 | } |
159 | - | 131 | + intentSynchronizer.withdraw(intent); |
160 | - log.debug("SDN-IP submitted {}/{}, withdrew = {}/{}", submitCount, | ||
161 | - updates.size(), withdrawCount, withdraws.size()); | ||
162 | } | 132 | } |
163 | } | 133 | } |
164 | 134 | ||
... | @@ -292,10 +262,20 @@ public class SdnIpFib { | ... | @@ -292,10 +262,20 @@ public class SdnIpFib { |
292 | } | 262 | } |
293 | } | 263 | } |
294 | 264 | ||
295 | - private class InternalFibListener implements FibListener { | 265 | + private class InternalRouteListener implements RouteListener { |
296 | @Override | 266 | @Override |
297 | - public void update(Collection<FibUpdate> updates, Collection<FibUpdate> withdraws) { | 267 | + public void event(RouteEvent event) { |
298 | - SdnIpFib.this.update(updates, withdraws); | 268 | + switch (event.type()) { |
269 | + case ROUTE_ADDED: | ||
270 | + case ROUTE_UPDATED: | ||
271 | + update(event.subject()); | ||
272 | + break; | ||
273 | + case ROUTE_REMOVED: | ||
274 | + withdraw(event.subject()); | ||
275 | + break; | ||
276 | + default: | ||
277 | + break; | ||
278 | + } | ||
299 | } | 279 | } |
300 | } | 280 | } |
301 | 281 | ... | ... |
... | @@ -23,7 +23,6 @@ import org.junit.Test; | ... | @@ -23,7 +23,6 @@ import org.junit.Test; |
23 | import org.onlab.packet.Ethernet; | 23 | import org.onlab.packet.Ethernet; |
24 | import org.onlab.packet.Ip4Address; | 24 | import org.onlab.packet.Ip4Address; |
25 | import org.onlab.packet.Ip4Prefix; | 25 | import org.onlab.packet.Ip4Prefix; |
26 | -import org.onlab.packet.IpAddress; | ||
27 | import org.onlab.packet.IpPrefix; | 26 | import org.onlab.packet.IpPrefix; |
28 | import org.onlab.packet.MacAddress; | 27 | import org.onlab.packet.MacAddress; |
29 | import org.onlab.packet.VlanId; | 28 | import org.onlab.packet.VlanId; |
... | @@ -35,6 +34,10 @@ import org.onosproject.incubator.net.intf.InterfaceEvent; | ... | @@ -35,6 +34,10 @@ import org.onosproject.incubator.net.intf.InterfaceEvent; |
35 | import org.onosproject.incubator.net.intf.InterfaceListener; | 34 | import org.onosproject.incubator.net.intf.InterfaceListener; |
36 | import org.onosproject.incubator.net.intf.InterfaceService; | 35 | import org.onosproject.incubator.net.intf.InterfaceService; |
37 | import org.onosproject.incubator.net.intf.InterfaceServiceAdapter; | 36 | import org.onosproject.incubator.net.intf.InterfaceServiceAdapter; |
37 | +import org.onosproject.incubator.net.routing.ResolvedRoute; | ||
38 | +import org.onosproject.incubator.net.routing.RouteEvent; | ||
39 | +import org.onosproject.incubator.net.routing.RouteListener; | ||
40 | +import org.onosproject.incubator.net.routing.RouteServiceAdapter; | ||
38 | import org.onosproject.net.ConnectPoint; | 41 | import org.onosproject.net.ConnectPoint; |
39 | import org.onosproject.net.DeviceId; | 42 | import org.onosproject.net.DeviceId; |
40 | import org.onosproject.net.PortNumber; | 43 | import org.onosproject.net.PortNumber; |
... | @@ -46,11 +49,7 @@ import org.onosproject.net.host.InterfaceIpAddress; | ... | @@ -46,11 +49,7 @@ import org.onosproject.net.host.InterfaceIpAddress; |
46 | import org.onosproject.net.intent.AbstractIntentTest; | 49 | import org.onosproject.net.intent.AbstractIntentTest; |
47 | import org.onosproject.net.intent.Key; | 50 | import org.onosproject.net.intent.Key; |
48 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; | 51 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; |
49 | -import org.onosproject.routing.FibEntry; | ||
50 | -import org.onosproject.routing.FibListener; | ||
51 | -import org.onosproject.routing.FibUpdate; | ||
52 | import org.onosproject.routing.IntentSynchronizationService; | 52 | import org.onosproject.routing.IntentSynchronizationService; |
53 | -import org.onosproject.routing.RoutingServiceAdapter; | ||
54 | 53 | ||
55 | import java.util.Collections; | 54 | import java.util.Collections; |
56 | import java.util.HashSet; | 55 | import java.util.HashSet; |
... | @@ -81,10 +80,6 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -81,10 +80,6 @@ public class SdnIpFibTest extends AbstractIntentTest { |
81 | DeviceId.deviceId("of:0000000000000002"), | 80 | DeviceId.deviceId("of:0000000000000002"), |
82 | PortNumber.portNumber(1)); | 81 | PortNumber.portNumber(1)); |
83 | 82 | ||
84 | - private static final ConnectPoint SW3_ETH1 = new ConnectPoint( | ||
85 | - DeviceId.deviceId("of:0000000000000003"), | ||
86 | - PortNumber.portNumber(1)); | ||
87 | - | ||
88 | private static final ConnectPoint SW4_ETH1 = new ConnectPoint( | 83 | private static final ConnectPoint SW4_ETH1 = new ConnectPoint( |
89 | DeviceId.deviceId("of:0000000000000004"), | 84 | DeviceId.deviceId("of:0000000000000004"), |
90 | PortNumber.portNumber(1)); | 85 | PortNumber.portNumber(1)); |
... | @@ -93,13 +88,15 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -93,13 +88,15 @@ public class SdnIpFibTest extends AbstractIntentTest { |
93 | DeviceId.deviceId("of:0000000000000005"), | 88 | DeviceId.deviceId("of:0000000000000005"), |
94 | PortNumber.portNumber(1)); | 89 | PortNumber.portNumber(1)); |
95 | 90 | ||
91 | + private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24"); | ||
92 | + | ||
96 | private SdnIpFib sdnipFib; | 93 | private SdnIpFib sdnipFib; |
97 | private IntentSynchronizationService intentSynchronizer; | 94 | private IntentSynchronizationService intentSynchronizer; |
98 | private final Set<Interface> interfaces = Sets.newHashSet(); | 95 | private final Set<Interface> interfaces = Sets.newHashSet(); |
99 | 96 | ||
100 | private static final ApplicationId APPID = TestApplicationId.create("SDNIP"); | 97 | private static final ApplicationId APPID = TestApplicationId.create("SDNIP"); |
101 | 98 | ||
102 | - private FibListener fibListener; | 99 | + private RouteListener routeListener; |
103 | private InterfaceListener interfaceListener; | 100 | private InterfaceListener interfaceListener; |
104 | 101 | ||
105 | @Before | 102 | @Before |
... | @@ -118,7 +115,7 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -118,7 +115,7 @@ public class SdnIpFibTest extends AbstractIntentTest { |
118 | intentSynchronizer = createMock(IntentSynchronizationService.class); | 115 | intentSynchronizer = createMock(IntentSynchronizationService.class); |
119 | 116 | ||
120 | sdnipFib = new SdnIpFib(); | 117 | sdnipFib = new SdnIpFib(); |
121 | - sdnipFib.routingService = new TestRoutingService(); | 118 | + sdnipFib.routeService = new TestRouteService(); |
122 | sdnipFib.coreService = new TestCoreService(); | 119 | sdnipFib.coreService = new TestCoreService(); |
123 | sdnipFib.interfaceService = interfaceService; | 120 | sdnipFib.interfaceService = interfaceService; |
124 | sdnipFib.intentSynchronizer = intentSynchronizer; | 121 | sdnipFib.intentSynchronizer = intentSynchronizer; |
... | @@ -131,45 +128,24 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -131,45 +128,24 @@ public class SdnIpFibTest extends AbstractIntentTest { |
131 | */ | 128 | */ |
132 | private void setUpInterfaceService() { | 129 | private void setUpInterfaceService() { |
133 | List<InterfaceIpAddress> interfaceIpAddresses1 = Lists.newArrayList(); | 130 | List<InterfaceIpAddress> interfaceIpAddresses1 = Lists.newArrayList(); |
134 | - interfaceIpAddresses1.add(new InterfaceIpAddress( | 131 | + interfaceIpAddresses1.add(InterfaceIpAddress.valueOf("192.168.10.101/24")); |
135 | - IpAddress.valueOf("192.168.10.101"), | ||
136 | - IpPrefix.valueOf("192.168.10.0/24"))); | ||
137 | Interface sw1Eth1 = new Interface("sw1-eth1", SW1_ETH1, | 132 | Interface sw1Eth1 = new Interface("sw1-eth1", SW1_ETH1, |
138 | interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"), | 133 | interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"), |
139 | VlanId.NONE); | 134 | VlanId.NONE); |
140 | interfaces.add(sw1Eth1); | 135 | interfaces.add(sw1Eth1); |
141 | 136 | ||
142 | List<InterfaceIpAddress> interfaceIpAddresses2 = Lists.newArrayList(); | 137 | List<InterfaceIpAddress> interfaceIpAddresses2 = Lists.newArrayList(); |
143 | - interfaceIpAddresses2.add( | 138 | + interfaceIpAddresses2.add(InterfaceIpAddress.valueOf("192.168.20.101/24")); |
144 | - new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"), | ||
145 | - IpPrefix.valueOf("192.168.20.0/24"))); | ||
146 | Interface sw2Eth1 = new Interface("sw2-eth1", SW2_ETH1, | 139 | Interface sw2Eth1 = new Interface("sw2-eth1", SW2_ETH1, |
147 | interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"), | 140 | interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"), |
148 | VlanId.NONE); | 141 | VlanId.NONE); |
149 | interfaces.add(sw2Eth1); | 142 | interfaces.add(sw2Eth1); |
150 | 143 | ||
151 | - List<InterfaceIpAddress> interfaceIpAddresses3 = Lists.newArrayList(); | 144 | + InterfaceIpAddress interfaceIpAddress4 = InterfaceIpAddress.valueOf("192.168.40.101/24"); |
152 | - interfaceIpAddresses3.add( | ||
153 | - new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"), | ||
154 | - IpPrefix.valueOf("192.168.30.0/24"))); | ||
155 | - Interface sw3Eth1 = new Interface("sw3-eth1", SW3_ETH1, | ||
156 | - interfaceIpAddresses3, MacAddress.valueOf("00:00:00:00:00:03"), | ||
157 | - VlanId.NONE); | ||
158 | - interfaces.add(sw3Eth1); | ||
159 | - | ||
160 | - InterfaceIpAddress interfaceIpAddress4 = | ||
161 | - new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), | ||
162 | - IpPrefix.valueOf("192.168.40.0/24")); | ||
163 | Interface sw4Eth1 = new Interface("sw4-eth1", SW4_ETH1, | 145 | Interface sw4Eth1 = new Interface("sw4-eth1", SW4_ETH1, |
164 | Lists.newArrayList(interfaceIpAddress4), | 146 | Lists.newArrayList(interfaceIpAddress4), |
165 | MacAddress.valueOf("00:00:00:00:00:04"), | 147 | MacAddress.valueOf("00:00:00:00:00:04"), |
166 | VlanId.vlanId((short) 1)); | 148 | VlanId.vlanId((short) 1)); |
167 | - | ||
168 | - expect(interfaceService.getInterfacesByPort(SW4_ETH1)).andReturn( | ||
169 | - Collections.singleton(sw4Eth1)).anyTimes(); | ||
170 | - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.40.1"))) | ||
171 | - .andReturn(sw4Eth1).anyTimes(); | ||
172 | - | ||
173 | interfaces.add(sw4Eth1); | 149 | interfaces.add(sw4Eth1); |
174 | 150 | ||
175 | expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn( | 151 | expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn( |
... | @@ -180,31 +156,29 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -180,31 +156,29 @@ public class SdnIpFibTest extends AbstractIntentTest { |
180 | Collections.singleton(sw2Eth1)).anyTimes(); | 156 | Collections.singleton(sw2Eth1)).anyTimes(); |
181 | expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.20.1"))) | 157 | expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.20.1"))) |
182 | .andReturn(sw2Eth1).anyTimes(); | 158 | .andReturn(sw2Eth1).anyTimes(); |
183 | - expect(interfaceService.getInterfacesByPort(SW3_ETH1)).andReturn( | 159 | + expect(interfaceService.getInterfacesByPort(SW4_ETH1)).andReturn( |
184 | - Collections.singleton(sw3Eth1)).anyTimes(); | 160 | + Collections.singleton(sw4Eth1)).anyTimes(); |
185 | - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.30.1"))) | 161 | + expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.40.1"))) |
186 | - .andReturn(sw3Eth1).anyTimes(); | 162 | + .andReturn(sw4Eth1).anyTimes(); |
187 | expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); | 163 | expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); |
188 | } | 164 | } |
189 | 165 | ||
190 | /** | 166 | /** |
191 | - * Tests adding a FIB entry to the IntentSynchronizer. | 167 | + * Tests adding a route. |
192 | * | 168 | * |
193 | * We verify that the synchronizer records the correct state and that the | 169 | * We verify that the synchronizer records the correct state and that the |
194 | * correct intent is submitted to the IntentService. | 170 | * correct intent is submitted to the IntentService. |
195 | */ | 171 | */ |
196 | @Test | 172 | @Test |
197 | - public void testFibAdd() { | 173 | + public void testRouteAdd() { |
198 | - IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24"); | 174 | + ResolvedRoute route = new ResolvedRoute(PREFIX1, |
199 | - FibEntry fibEntry = new FibEntry(prefix, | ||
200 | Ip4Address.valueOf("192.168.10.1"), | 175 | Ip4Address.valueOf("192.168.10.1"), |
201 | MacAddress.valueOf("00:00:00:00:00:01")); | 176 | MacAddress.valueOf("00:00:00:00:00:01")); |
202 | 177 | ||
203 | // Construct a MultiPointToSinglePointIntent intent | 178 | // Construct a MultiPointToSinglePointIntent intent |
204 | TrafficSelector.Builder selectorBuilder = | 179 | TrafficSelector.Builder selectorBuilder = |
205 | DefaultTrafficSelector.builder(); | 180 | DefaultTrafficSelector.builder(); |
206 | - selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst( | 181 | + selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(PREFIX1); |
207 | - fibEntry.prefix()); | ||
208 | 182 | ||
209 | TrafficTreatment.Builder treatmentBuilder = | 183 | TrafficTreatment.Builder treatmentBuilder = |
210 | DefaultTrafficTreatment.builder(); | 184 | DefaultTrafficTreatment.builder(); |
... | @@ -212,13 +186,12 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -212,13 +186,12 @@ public class SdnIpFibTest extends AbstractIntentTest { |
212 | 186 | ||
213 | Set<ConnectPoint> ingressPoints = new HashSet<>(); | 187 | Set<ConnectPoint> ingressPoints = new HashSet<>(); |
214 | ingressPoints.add(SW2_ETH1); | 188 | ingressPoints.add(SW2_ETH1); |
215 | - ingressPoints.add(SW3_ETH1); | ||
216 | ingressPoints.add(SW4_ETH1); | 189 | ingressPoints.add(SW4_ETH1); |
217 | 190 | ||
218 | MultiPointToSinglePointIntent intent = | 191 | MultiPointToSinglePointIntent intent = |
219 | MultiPointToSinglePointIntent.builder() | 192 | MultiPointToSinglePointIntent.builder() |
220 | .appId(APPID) | 193 | .appId(APPID) |
221 | - .key(Key.of(prefix.toString(), APPID)) | 194 | + .key(Key.of(PREFIX1.toString(), APPID)) |
222 | .selector(selectorBuilder.build()) | 195 | .selector(selectorBuilder.build()) |
223 | .treatment(treatmentBuilder.build()) | 196 | .treatment(treatmentBuilder.build()) |
224 | .ingressPoints(ingressPoints) | 197 | .ingressPoints(ingressPoints) |
... | @@ -230,23 +203,21 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -230,23 +203,21 @@ public class SdnIpFibTest extends AbstractIntentTest { |
230 | intentSynchronizer.submit(eqExceptId(intent)); | 203 | intentSynchronizer.submit(eqExceptId(intent)); |
231 | replay(intentSynchronizer); | 204 | replay(intentSynchronizer); |
232 | 205 | ||
233 | - // Send in the UPDATE FibUpdate | 206 | + // Send in the added event |
234 | - FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, fibEntry); | 207 | + routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route)); |
235 | - fibListener.update(Collections.singleton(fibUpdate), Collections.emptyList()); | ||
236 | 208 | ||
237 | verify(intentSynchronizer); | 209 | verify(intentSynchronizer); |
238 | } | 210 | } |
239 | 211 | ||
240 | /** | 212 | /** |
241 | - * Tests adding a FIB entry with to a next hop in a VLAN. | 213 | + * Tests adding a route with to a next hop in a VLAN. |
242 | * | 214 | * |
243 | * We verify that the synchronizer records the correct state and that the | 215 | * We verify that the synchronizer records the correct state and that the |
244 | * correct intent is submitted to the IntentService. | 216 | * correct intent is submitted to the IntentService. |
245 | */ | 217 | */ |
246 | @Test | 218 | @Test |
247 | - public void testFibAddWithVlan() { | 219 | + public void testRouteAddWithVlan() { |
248 | - IpPrefix prefix = Ip4Prefix.valueOf("3.3.3.0/24"); | 220 | + ResolvedRoute route = new ResolvedRoute(PREFIX1, |
249 | - FibEntry fibEntry = new FibEntry(prefix, | ||
250 | Ip4Address.valueOf("192.168.40.1"), | 221 | Ip4Address.valueOf("192.168.40.1"), |
251 | MacAddress.valueOf("00:00:00:00:00:04")); | 222 | MacAddress.valueOf("00:00:00:00:00:04")); |
252 | 223 | ||
... | @@ -254,7 +225,7 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -254,7 +225,7 @@ public class SdnIpFibTest extends AbstractIntentTest { |
254 | TrafficSelector.Builder selectorBuilder = | 225 | TrafficSelector.Builder selectorBuilder = |
255 | DefaultTrafficSelector.builder(); | 226 | DefaultTrafficSelector.builder(); |
256 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV4) | 227 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV4) |
257 | - .matchIPDst(fibEntry.prefix()) | 228 | + .matchIPDst(PREFIX1) |
258 | .matchVlanId(VlanId.ANY); | 229 | .matchVlanId(VlanId.ANY); |
259 | 230 | ||
260 | TrafficTreatment.Builder treatmentBuilder = | 231 | TrafficTreatment.Builder treatmentBuilder = |
... | @@ -265,12 +236,11 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -265,12 +236,11 @@ public class SdnIpFibTest extends AbstractIntentTest { |
265 | Set<ConnectPoint> ingressPoints = new HashSet<>(); | 236 | Set<ConnectPoint> ingressPoints = new HashSet<>(); |
266 | ingressPoints.add(SW1_ETH1); | 237 | ingressPoints.add(SW1_ETH1); |
267 | ingressPoints.add(SW2_ETH1); | 238 | ingressPoints.add(SW2_ETH1); |
268 | - ingressPoints.add(SW3_ETH1); | ||
269 | 239 | ||
270 | MultiPointToSinglePointIntent intent = | 240 | MultiPointToSinglePointIntent intent = |
271 | MultiPointToSinglePointIntent.builder() | 241 | MultiPointToSinglePointIntent.builder() |
272 | .appId(APPID) | 242 | .appId(APPID) |
273 | - .key(Key.of(prefix.toString(), APPID)) | 243 | + .key(Key.of(PREFIX1.toString(), APPID)) |
274 | .selector(selectorBuilder.build()) | 244 | .selector(selectorBuilder.build()) |
275 | .treatment(treatmentBuilder.build()) | 245 | .treatment(treatmentBuilder.build()) |
276 | .ingressPoints(ingressPoints) | 246 | .ingressPoints(ingressPoints) |
... | @@ -283,36 +253,32 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -283,36 +253,32 @@ public class SdnIpFibTest extends AbstractIntentTest { |
283 | 253 | ||
284 | replay(intentSynchronizer); | 254 | replay(intentSynchronizer); |
285 | 255 | ||
286 | - // Send in the UPDATE FibUpdate | 256 | + // Send in the added event |
287 | - FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, fibEntry); | 257 | + routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route)); |
288 | - fibListener.update(Collections.singleton(fibUpdate), Collections.emptyList()); | ||
289 | 258 | ||
290 | verify(intentSynchronizer); | 259 | verify(intentSynchronizer); |
291 | } | 260 | } |
292 | 261 | ||
293 | /** | 262 | /** |
294 | - * Tests updating a FIB entry. | 263 | + * Tests updating a route. |
295 | * | 264 | * |
296 | * We verify that the synchronizer records the correct state and that the | 265 | * We verify that the synchronizer records the correct state and that the |
297 | * correct intent is submitted to the IntentService. | 266 | * correct intent is submitted to the IntentService. |
298 | */ | 267 | */ |
299 | @Test | 268 | @Test |
300 | - public void testFibUpdate() { | 269 | + public void testRouteUpdate() { |
301 | // Firstly add a route | 270 | // Firstly add a route |
302 | - testFibAdd(); | 271 | + testRouteAdd(); |
303 | - | ||
304 | - IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24"); | ||
305 | 272 | ||
306 | // Start to construct a new route entry and new intent | 273 | // Start to construct a new route entry and new intent |
307 | - FibEntry fibEntryUpdate = new FibEntry(prefix, | 274 | + ResolvedRoute route = new ResolvedRoute(PREFIX1, |
308 | Ip4Address.valueOf("192.168.20.1"), | 275 | Ip4Address.valueOf("192.168.20.1"), |
309 | MacAddress.valueOf("00:00:00:00:00:02")); | 276 | MacAddress.valueOf("00:00:00:00:00:02")); |
310 | 277 | ||
311 | // Construct a new MultiPointToSinglePointIntent intent | 278 | // Construct a new MultiPointToSinglePointIntent intent |
312 | TrafficSelector.Builder selectorBuilderNew = | 279 | TrafficSelector.Builder selectorBuilderNew = |
313 | DefaultTrafficSelector.builder(); | 280 | DefaultTrafficSelector.builder(); |
314 | - selectorBuilderNew.matchEthType(Ethernet.TYPE_IPV4).matchIPDst( | 281 | + selectorBuilderNew.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(PREFIX1); |
315 | - fibEntryUpdate.prefix()); | ||
316 | 282 | ||
317 | TrafficTreatment.Builder treatmentBuilderNew = | 283 | TrafficTreatment.Builder treatmentBuilderNew = |
318 | DefaultTrafficTreatment.builder(); | 284 | DefaultTrafficTreatment.builder(); |
... | @@ -320,13 +286,12 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -320,13 +286,12 @@ public class SdnIpFibTest extends AbstractIntentTest { |
320 | 286 | ||
321 | Set<ConnectPoint> ingressPointsNew = new HashSet<>(); | 287 | Set<ConnectPoint> ingressPointsNew = new HashSet<>(); |
322 | ingressPointsNew.add(SW1_ETH1); | 288 | ingressPointsNew.add(SW1_ETH1); |
323 | - ingressPointsNew.add(SW3_ETH1); | ||
324 | ingressPointsNew.add(SW4_ETH1); | 289 | ingressPointsNew.add(SW4_ETH1); |
325 | 290 | ||
326 | MultiPointToSinglePointIntent intentNew = | 291 | MultiPointToSinglePointIntent intentNew = |
327 | MultiPointToSinglePointIntent.builder() | 292 | MultiPointToSinglePointIntent.builder() |
328 | .appId(APPID) | 293 | .appId(APPID) |
329 | - .key(Key.of(prefix.toString(), APPID)) | 294 | + .key(Key.of(PREFIX1.toString(), APPID)) |
330 | .selector(selectorBuilderNew.build()) | 295 | .selector(selectorBuilderNew.build()) |
331 | .treatment(treatmentBuilderNew.build()) | 296 | .treatment(treatmentBuilderNew.build()) |
332 | .ingressPoints(ingressPointsNew) | 297 | .ingressPoints(ingressPointsNew) |
... | @@ -341,36 +306,30 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -341,36 +306,30 @@ public class SdnIpFibTest extends AbstractIntentTest { |
341 | intentSynchronizer.submit(eqExceptId(intentNew)); | 306 | intentSynchronizer.submit(eqExceptId(intentNew)); |
342 | replay(intentSynchronizer); | 307 | replay(intentSynchronizer); |
343 | 308 | ||
344 | - // Send in the UPDATE FibUpdate | 309 | + // Send in the update event |
345 | - FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, | 310 | + routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_UPDATED, route)); |
346 | - fibEntryUpdate); | ||
347 | - fibListener.update(Collections.singletonList(fibUpdate), | ||
348 | - Collections.emptyList()); | ||
349 | 311 | ||
350 | verify(intentSynchronizer); | 312 | verify(intentSynchronizer); |
351 | } | 313 | } |
352 | 314 | ||
353 | /** | 315 | /** |
354 | - * Tests deleting a FIB entry. | 316 | + * Tests deleting a route. |
355 | * | 317 | * |
356 | * We verify that the synchronizer records the correct state and that the | 318 | * We verify that the synchronizer records the correct state and that the |
357 | * correct intent is withdrawn from the IntentService. | 319 | * correct intent is withdrawn from the IntentService. |
358 | */ | 320 | */ |
359 | @Test | 321 | @Test |
360 | - public void testFibDelete() { | 322 | + public void testRouteDelete() { |
361 | // Firstly add a route | 323 | // Firstly add a route |
362 | - testFibAdd(); | 324 | + testRouteAdd(); |
363 | - | ||
364 | - IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24"); | ||
365 | 325 | ||
366 | // Construct the existing route entry | 326 | // Construct the existing route entry |
367 | - FibEntry fibEntry = new FibEntry(prefix, null, null); | 327 | + ResolvedRoute route = new ResolvedRoute(PREFIX1, null, null); |
368 | 328 | ||
369 | // Construct the existing MultiPointToSinglePoint intent | 329 | // Construct the existing MultiPointToSinglePoint intent |
370 | TrafficSelector.Builder selectorBuilder = | 330 | TrafficSelector.Builder selectorBuilder = |
371 | DefaultTrafficSelector.builder(); | 331 | DefaultTrafficSelector.builder(); |
372 | - selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst( | 332 | + selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(PREFIX1); |
373 | - fibEntry.prefix()); | ||
374 | 333 | ||
375 | TrafficTreatment.Builder treatmentBuilder = | 334 | TrafficTreatment.Builder treatmentBuilder = |
376 | DefaultTrafficTreatment.builder(); | 335 | DefaultTrafficTreatment.builder(); |
... | @@ -378,13 +337,12 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -378,13 +337,12 @@ public class SdnIpFibTest extends AbstractIntentTest { |
378 | 337 | ||
379 | Set<ConnectPoint> ingressPoints = new HashSet<>(); | 338 | Set<ConnectPoint> ingressPoints = new HashSet<>(); |
380 | ingressPoints.add(SW2_ETH1); | 339 | ingressPoints.add(SW2_ETH1); |
381 | - ingressPoints.add(SW3_ETH1); | ||
382 | ingressPoints.add(SW4_ETH1); | 340 | ingressPoints.add(SW4_ETH1); |
383 | 341 | ||
384 | MultiPointToSinglePointIntent addedIntent = | 342 | MultiPointToSinglePointIntent addedIntent = |
385 | MultiPointToSinglePointIntent.builder() | 343 | MultiPointToSinglePointIntent.builder() |
386 | .appId(APPID) | 344 | .appId(APPID) |
387 | - .key(Key.of(prefix.toString(), APPID)) | 345 | + .key(Key.of(PREFIX1.toString(), APPID)) |
388 | .selector(selectorBuilder.build()) | 346 | .selector(selectorBuilder.build()) |
389 | .treatment(treatmentBuilder.build()) | 347 | .treatment(treatmentBuilder.build()) |
390 | .ingressPoints(ingressPoints) | 348 | .ingressPoints(ingressPoints) |
... | @@ -398,23 +356,20 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -398,23 +356,20 @@ public class SdnIpFibTest extends AbstractIntentTest { |
398 | intentSynchronizer.withdraw(eqExceptId(addedIntent)); | 356 | intentSynchronizer.withdraw(eqExceptId(addedIntent)); |
399 | replay(intentSynchronizer); | 357 | replay(intentSynchronizer); |
400 | 358 | ||
401 | - // Send in the DELETE FibUpdate | 359 | + // Send in the removed event |
402 | - FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.DELETE, fibEntry); | 360 | + routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_REMOVED, route)); |
403 | - fibListener.update(Collections.emptyList(), Collections.singletonList(fibUpdate)); | ||
404 | 361 | ||
405 | verify(intentSynchronizer); | 362 | verify(intentSynchronizer); |
406 | } | 363 | } |
407 | 364 | ||
408 | @Test | 365 | @Test |
409 | public void testAddInterface() { | 366 | public void testAddInterface() { |
410 | - testFibAdd(); | 367 | + testRouteAdd(); |
411 | - | ||
412 | - IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24"); | ||
413 | 368 | ||
414 | // Construct the existing MultiPointToSinglePoint intent | 369 | // Construct the existing MultiPointToSinglePoint intent |
415 | TrafficSelector.Builder selectorBuilder = | 370 | TrafficSelector.Builder selectorBuilder = |
416 | DefaultTrafficSelector.builder(); | 371 | DefaultTrafficSelector.builder(); |
417 | - selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(prefix); | 372 | + selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(PREFIX1); |
418 | 373 | ||
419 | TrafficTreatment.Builder treatmentBuilder = | 374 | TrafficTreatment.Builder treatmentBuilder = |
420 | DefaultTrafficTreatment.builder(); | 375 | DefaultTrafficTreatment.builder(); |
... | @@ -422,14 +377,13 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -422,14 +377,13 @@ public class SdnIpFibTest extends AbstractIntentTest { |
422 | 377 | ||
423 | Set<ConnectPoint> ingressPoints = new HashSet<>(); | 378 | Set<ConnectPoint> ingressPoints = new HashSet<>(); |
424 | ingressPoints.add(SW2_ETH1); | 379 | ingressPoints.add(SW2_ETH1); |
425 | - ingressPoints.add(SW3_ETH1); | ||
426 | ingressPoints.add(SW4_ETH1); | 380 | ingressPoints.add(SW4_ETH1); |
427 | ingressPoints.add(SW5_ETH1); | 381 | ingressPoints.add(SW5_ETH1); |
428 | 382 | ||
429 | MultiPointToSinglePointIntent addedIntent = | 383 | MultiPointToSinglePointIntent addedIntent = |
430 | MultiPointToSinglePointIntent.builder() | 384 | MultiPointToSinglePointIntent.builder() |
431 | .appId(APPID) | 385 | .appId(APPID) |
432 | - .key(Key.of(prefix.toString(), APPID)) | 386 | + .key(Key.of(PREFIX1.toString(), APPID)) |
433 | .selector(selectorBuilder.build()) | 387 | .selector(selectorBuilder.build()) |
434 | .treatment(treatmentBuilder.build()) | 388 | .treatment(treatmentBuilder.build()) |
435 | .ingressPoints(ingressPoints) | 389 | .ingressPoints(ingressPoints) |
... | @@ -455,14 +409,12 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -455,14 +409,12 @@ public class SdnIpFibTest extends AbstractIntentTest { |
455 | 409 | ||
456 | @Test | 410 | @Test |
457 | public void testRemoveInterface() { | 411 | public void testRemoveInterface() { |
458 | - testFibAdd(); | 412 | + testRouteAdd(); |
459 | - | ||
460 | - IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24"); | ||
461 | 413 | ||
462 | // Construct the existing MultiPointToSinglePoint intent | 414 | // Construct the existing MultiPointToSinglePoint intent |
463 | TrafficSelector.Builder selectorBuilder = | 415 | TrafficSelector.Builder selectorBuilder = |
464 | DefaultTrafficSelector.builder(); | 416 | DefaultTrafficSelector.builder(); |
465 | - selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(prefix); | 417 | + selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(PREFIX1); |
466 | 418 | ||
467 | TrafficTreatment.Builder treatmentBuilder = | 419 | TrafficTreatment.Builder treatmentBuilder = |
468 | DefaultTrafficTreatment.builder(); | 420 | DefaultTrafficTreatment.builder(); |
... | @@ -470,12 +422,11 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -470,12 +422,11 @@ public class SdnIpFibTest extends AbstractIntentTest { |
470 | 422 | ||
471 | Set<ConnectPoint> ingressPoints = new HashSet<>(); | 423 | Set<ConnectPoint> ingressPoints = new HashSet<>(); |
472 | ingressPoints.add(SW2_ETH1); | 424 | ingressPoints.add(SW2_ETH1); |
473 | - ingressPoints.add(SW3_ETH1); | ||
474 | 425 | ||
475 | MultiPointToSinglePointIntent addedIntent = | 426 | MultiPointToSinglePointIntent addedIntent = |
476 | MultiPointToSinglePointIntent.builder() | 427 | MultiPointToSinglePointIntent.builder() |
477 | .appId(APPID) | 428 | .appId(APPID) |
478 | - .key(Key.of(prefix.toString(), APPID)) | 429 | + .key(Key.of(PREFIX1.toString(), APPID)) |
479 | .selector(selectorBuilder.build()) | 430 | .selector(selectorBuilder.build()) |
480 | .treatment(treatmentBuilder.build()) | 431 | .treatment(treatmentBuilder.build()) |
481 | .ingressPoints(ingressPoints) | 432 | .ingressPoints(ingressPoints) |
... | @@ -506,16 +457,14 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -506,16 +457,14 @@ public class SdnIpFibTest extends AbstractIntentTest { |
506 | } | 457 | } |
507 | } | 458 | } |
508 | 459 | ||
509 | - private class TestRoutingService extends RoutingServiceAdapter { | 460 | + private class TestRouteService extends RouteServiceAdapter { |
510 | - | ||
511 | @Override | 461 | @Override |
512 | - public void addFibListener(FibListener fibListener) { | 462 | + public void addListener(RouteListener routeListener) { |
513 | - SdnIpFibTest.this.fibListener = fibListener; | 463 | + SdnIpFibTest.this.routeListener = routeListener; |
514 | } | 464 | } |
515 | } | 465 | } |
516 | 466 | ||
517 | private class InterfaceServiceDelegate extends InterfaceServiceAdapter { | 467 | private class InterfaceServiceDelegate extends InterfaceServiceAdapter { |
518 | - | ||
519 | @Override | 468 | @Override |
520 | public void addListener(InterfaceListener listener) { | 469 | public void addListener(InterfaceListener listener) { |
521 | SdnIpFibTest.this.interfaceListener = listener; | 470 | SdnIpFibTest.this.interfaceListener = listener; | ... | ... |
... | @@ -49,7 +49,6 @@ public class Vrouter { | ... | @@ -49,7 +49,6 @@ public class Vrouter { |
49 | 49 | ||
50 | private final List<String> components = ImmutableList.<String>builder() | 50 | private final List<String> components = ImmutableList.<String>builder() |
51 | .add("org.onosproject.routing.fpm.FpmManager") | 51 | .add("org.onosproject.routing.fpm.FpmManager") |
52 | - .add("org.onosproject.routing.impl.Router") | ||
53 | .add("org.onosproject.routing.impl.SingleSwitchFibInstaller") | 52 | .add("org.onosproject.routing.impl.SingleSwitchFibInstaller") |
54 | .add("org.onosproject.routing.impl.ControlPlaneRedirectManager") | 53 | .add("org.onosproject.routing.impl.ControlPlaneRedirectManager") |
55 | .build(); | 54 | .build(); | ... | ... |
... | @@ -182,11 +182,6 @@ public class InterfaceIpAddress { | ... | @@ -182,11 +182,6 @@ public class InterfaceIpAddress { |
182 | 182 | ||
183 | @Override | 183 | @Override |
184 | public String toString() { | 184 | public String toString() { |
185 | - /*return toStringHelper(this).add("ipAddress", ipAddress) | ||
186 | - .add("subnetAddress", subnetAddress) | ||
187 | - .add("broadcastAddress", broadcastAddress) | ||
188 | - .add("peerAddress", peerAddress) | ||
189 | - .omitNullValues().toString();*/ | ||
190 | return ipAddress.toString() + "/" + subnetAddress.prefixLength(); | 185 | return ipAddress.toString() + "/" + subnetAddress.prefixLength(); |
191 | } | 186 | } |
192 | } | 187 | } | ... | ... |
-
Please register or login to post a comment