Committed by
Gerrit Code Review
Small cleanups for vRouter app
Change-Id: Ibee46d3b95ee76dd3547e11d046c4620b3b3306d
Showing
5 changed files
with
150 additions
and
129 deletions
... | @@ -16,16 +16,8 @@ | ... | @@ -16,16 +16,8 @@ |
16 | 16 | ||
17 | package org.onosproject.routing.impl; | 17 | package org.onosproject.routing.impl; |
18 | 18 | ||
19 | -import static com.google.common.base.Preconditions.checkState; | 19 | +import com.google.common.collect.ImmutableSortedSet; |
20 | -import static org.slf4j.LoggerFactory.getLogger; | 20 | +import com.google.common.collect.Maps; |
21 | - | ||
22 | -import java.util.Collections; | ||
23 | -import java.util.Iterator; | ||
24 | -import java.util.List; | ||
25 | -import java.util.Map; | ||
26 | -import java.util.Optional; | ||
27 | -import java.util.Set; | ||
28 | - | ||
29 | import org.apache.felix.scr.annotations.Activate; | 21 | import org.apache.felix.scr.annotations.Activate; |
30 | import org.apache.felix.scr.annotations.Component; | 22 | import org.apache.felix.scr.annotations.Component; |
31 | import org.apache.felix.scr.annotations.Deactivate; | 23 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -69,8 +61,15 @@ import org.onosproject.routing.RoutingService; | ... | @@ -69,8 +61,15 @@ import org.onosproject.routing.RoutingService; |
69 | import org.onosproject.routing.config.RouterConfig; | 61 | import org.onosproject.routing.config.RouterConfig; |
70 | import org.slf4j.Logger; | 62 | import org.slf4j.Logger; |
71 | 63 | ||
72 | -import com.google.common.collect.ImmutableSortedSet; | 64 | +import java.util.Collections; |
73 | -import com.google.common.collect.Maps; | 65 | +import java.util.Iterator; |
66 | +import java.util.List; | ||
67 | +import java.util.Map; | ||
68 | +import java.util.Optional; | ||
69 | +import java.util.Set; | ||
70 | + | ||
71 | +import static com.google.common.base.Preconditions.checkState; | ||
72 | +import static org.slf4j.LoggerFactory.getLogger; | ||
74 | 73 | ||
75 | /** | 74 | /** |
76 | * Manages connectivity between peers redirecting control traffic to a routing | 75 | * Manages connectivity between peers redirecting control traffic to a routing |
... | @@ -183,7 +182,7 @@ public class ControlPlaneRedirectManager { | ... | @@ -183,7 +182,7 @@ public class ControlPlaneRedirectManager { |
183 | updateOspfForwarding(intf, true); | 182 | updateOspfForwarding(intf, true); |
184 | } | 183 | } |
185 | /** | 184 | /** |
186 | - * Install or removes the basic forwarding flows for each interface | 185 | + * Installs or removes the basic forwarding flows for each interface |
187 | * based on the flag used. | 186 | * based on the flag used. |
188 | * | 187 | * |
189 | * @param intf the Interface on which event is received | 188 | * @param intf the Interface on which event is received |
... | @@ -266,9 +265,9 @@ public class ControlPlaneRedirectManager { | ... | @@ -266,9 +265,9 @@ public class ControlPlaneRedirectManager { |
266 | } | 265 | } |
267 | 266 | ||
268 | /** | 267 | /** |
269 | - * Install or removes ospf forwarding rules. | 268 | + * Installs or removes OSPF forwarding rules. |
270 | * | 269 | * |
271 | - * @param intf the Interface on which event is received | 270 | + * @param intf the interface on which event is received |
272 | * @param install true to create an add objective, false to create a remove | 271 | * @param install true to create an add objective, false to create a remove |
273 | * objective | 272 | * objective |
274 | **/ | 273 | **/ |
... | @@ -293,7 +292,7 @@ public class ControlPlaneRedirectManager { | ... | @@ -293,7 +292,7 @@ public class ControlPlaneRedirectManager { |
293 | cpNextId = modifyNextObjective(deviceId, controlPlanePort, | 292 | cpNextId = modifyNextObjective(deviceId, controlPlanePort, |
294 | intf.vlan(), false, install); | 293 | intf.vlan(), false, install); |
295 | } | 294 | } |
296 | - log.debug("ospf flows intf:{} nextid:{}", intf, cpNextId); | 295 | + log.debug("OSPF flows intf:{} nextid:{}", intf, cpNextId); |
297 | flowObjectiveService.forward(controlPlaneConnectPoint.deviceId(), | 296 | flowObjectiveService.forward(controlPlaneConnectPoint.deviceId(), |
298 | buildForwardingObjective(toSelector, null, cpNextId, install ? ospfEnabled : install)); | 297 | buildForwardingObjective(toSelector, null, cpNextId, install ? ospfEnabled : install)); |
299 | } | 298 | } |
... | @@ -331,7 +330,7 @@ public class ControlPlaneRedirectManager { | ... | @@ -331,7 +330,7 @@ public class ControlPlaneRedirectManager { |
331 | 330 | ||
332 | nextObjBuilder.withMeta(metabuilder.build()); | 331 | nextObjBuilder.withMeta(metabuilder.build()); |
333 | nextObjBuilder.addTreatment(ttBuilder.build()); | 332 | nextObjBuilder.addTreatment(ttBuilder.build()); |
334 | - log.debug("Submited next objective {} in device {} for port/vlan {}/{}", | 333 | + log.debug("Submitted next objective {} in device {} for port/vlan {}/{}", |
335 | nextId, deviceId, portNumber, vlanId); | 334 | nextId, deviceId, portNumber, vlanId); |
336 | if (install) { | 335 | if (install) { |
337 | flowObjectiveService.next(deviceId, nextObjBuilder.add()); | 336 | flowObjectiveService.next(deviceId, nextObjBuilder.add()); |
... | @@ -385,7 +384,6 @@ public class ControlPlaneRedirectManager { | ... | @@ -385,7 +384,6 @@ public class ControlPlaneRedirectManager { |
385 | log.info("Device connected {}", event.subject().id()); | 384 | log.info("Device connected {}", event.subject().id()); |
386 | updateDevice(); | 385 | updateDevice(); |
387 | } | 386 | } |
388 | - | ||
389 | break; | 387 | break; |
390 | case DEVICE_UPDATED: | 388 | case DEVICE_UPDATED: |
391 | case DEVICE_REMOVED: | 389 | case DEVICE_REMOVED: | ... | ... |
... | @@ -60,9 +60,8 @@ import org.onosproject.net.flowobjective.FilteringObjective; | ... | @@ -60,9 +60,8 @@ import org.onosproject.net.flowobjective.FilteringObjective; |
60 | import org.onosproject.net.flowobjective.FlowObjectiveService; | 60 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
61 | import org.onosproject.net.flowobjective.ForwardingObjective; | 61 | import org.onosproject.net.flowobjective.ForwardingObjective; |
62 | import org.onosproject.net.flowobjective.NextObjective; | 62 | import org.onosproject.net.flowobjective.NextObjective; |
63 | -import org.onosproject.net.flowobjective.Objective; | ||
64 | import org.onosproject.net.flowobjective.ObjectiveContext; | 63 | import org.onosproject.net.flowobjective.ObjectiveContext; |
65 | -import org.onosproject.net.flowobjective.ObjectiveError; | 64 | +import org.onosproject.net.flowobjective.DefaultObjectiveContext; |
66 | import org.onosproject.routing.FibEntry; | 65 | import org.onosproject.routing.FibEntry; |
67 | import org.onosproject.routing.FibListener; | 66 | import org.onosproject.routing.FibListener; |
68 | import org.onosproject.routing.FibUpdate; | 67 | import org.onosproject.routing.FibUpdate; |
... | @@ -442,43 +441,15 @@ public class SingleSwitchFibInstaller { | ... | @@ -442,43 +441,15 @@ public class SingleSwitchFibInstaller { |
442 | 441 | ||
443 | private void sendFilteringObjective(boolean install, FilteringObjective.Builder fob, | 442 | private void sendFilteringObjective(boolean install, FilteringObjective.Builder fob, |
444 | Interface intf) { | 443 | Interface intf) { |
445 | - if (install) { | ||
446 | - flowObjectiveService.filter( | ||
447 | - deviceId, | ||
448 | - fob.add(new ObjectiveContext() { | ||
449 | - @Override | ||
450 | - public void onSuccess(Objective objective) { | ||
451 | - log.info("Successfully installed interface based " | ||
452 | - + "filtering objectives for intf {}", intf); | ||
453 | - } | ||
454 | 444 | ||
455 | - @Override | 445 | + ObjectiveContext context = new DefaultObjectiveContext( |
456 | - public void onError(Objective objective, | 446 | + (objective) -> log.info("Installed filter for interface {}", intf), |
457 | - ObjectiveError error) { | 447 | + (objective, error) -> |
458 | - log.error("Failed to install interface filters for intf {}: {}", | 448 | + log.error("Failed to install filter for interface {}: {}", intf, error)); |
459 | - intf, error); | ||
460 | - // TODO something more than just logging | ||
461 | - } | ||
462 | - })); | ||
463 | - } else { | ||
464 | - flowObjectiveService.filter( | ||
465 | - deviceId, | ||
466 | - fob.remove(new ObjectiveContext() { | ||
467 | - @Override | ||
468 | - public void onSuccess(Objective objective) { | ||
469 | - log.info("Successfully removed interface based " | ||
470 | - + "filtering objectives for intf {}", intf); | ||
471 | - } | ||
472 | 449 | ||
473 | - @Override | 450 | + FilteringObjective filter = install ? fob.add(context) : fob.remove(context); |
474 | - public void onError(Objective objective, | 451 | + |
475 | - ObjectiveError error) { | 452 | + flowObjectiveService.filter(deviceId, filter); |
476 | - log.error("Failed to install interface filters for intf {}: {}", | ||
477 | - intf, error); | ||
478 | - // TODO something more than just logging | ||
479 | - } | ||
480 | - })); | ||
481 | - } | ||
482 | } | 453 | } |
483 | 454 | ||
484 | private class InternalFibListener implements FibListener { | 455 | private class InternalFibListener implements FibListener { | ... | ... |
... | @@ -15,19 +15,7 @@ | ... | @@ -15,19 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.routing.impl; | 16 | package org.onosproject.routing.impl; |
17 | 17 | ||
18 | -import static org.easymock.EasyMock.createMock; | 18 | +import com.google.common.collect.Sets; |
19 | -import static org.easymock.EasyMock.expect; | ||
20 | -import static org.easymock.EasyMock.expectLastCall; | ||
21 | -import static org.easymock.EasyMock.replay; | ||
22 | -import static org.easymock.EasyMock.verify; | ||
23 | -import static org.slf4j.LoggerFactory.getLogger; | ||
24 | - | ||
25 | -import java.util.ArrayList; | ||
26 | -import java.util.HashSet; | ||
27 | -import java.util.List; | ||
28 | -import java.util.Objects; | ||
29 | -import java.util.Set; | ||
30 | - | ||
31 | import org.easymock.EasyMock; | 19 | import org.easymock.EasyMock; |
32 | import org.junit.Before; | 20 | import org.junit.Before; |
33 | import org.junit.Test; | 21 | import org.junit.Test; |
... | @@ -70,23 +58,29 @@ import org.onosproject.net.flowobjective.DefaultNextObjective; | ... | @@ -70,23 +58,29 @@ import org.onosproject.net.flowobjective.DefaultNextObjective; |
70 | import org.onosproject.net.flowobjective.FlowObjectiveService; | 58 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
71 | import org.onosproject.net.flowobjective.ForwardingObjective; | 59 | import org.onosproject.net.flowobjective.ForwardingObjective; |
72 | import org.onosproject.net.flowobjective.NextObjective; | 60 | import org.onosproject.net.flowobjective.NextObjective; |
73 | -import org.onosproject.net.host.HostListener; | ||
74 | import org.onosproject.net.host.HostService; | 61 | import org.onosproject.net.host.HostService; |
75 | -import org.onosproject.net.host.HostServiceAdapter; | ||
76 | import org.onosproject.net.host.InterfaceIpAddress; | 62 | import org.onosproject.net.host.InterfaceIpAddress; |
77 | -import org.onosproject.net.intent.AbstractIntentTest; | ||
78 | import org.onosproject.routing.RoutingService; | 63 | import org.onosproject.routing.RoutingService; |
79 | import org.onosproject.routing.config.RouterConfig; | 64 | import org.onosproject.routing.config.RouterConfig; |
80 | -import org.slf4j.Logger; | ||
81 | 65 | ||
82 | -import com.google.common.collect.Sets; | 66 | +import java.util.ArrayList; |
67 | +import java.util.HashSet; | ||
68 | +import java.util.List; | ||
69 | +import java.util.Objects; | ||
70 | +import java.util.Set; | ||
71 | + | ||
72 | +import static org.easymock.EasyMock.createMock; | ||
73 | +import static org.easymock.EasyMock.createNiceMock; | ||
74 | +import static org.easymock.EasyMock.expect; | ||
75 | +import static org.easymock.EasyMock.expectLastCall; | ||
76 | +import static org.easymock.EasyMock.replay; | ||
77 | +import static org.easymock.EasyMock.verify; | ||
83 | 78 | ||
84 | /** | 79 | /** |
85 | * UnitTests for ControlPlaneRedirectManager. | 80 | * UnitTests for ControlPlaneRedirectManager. |
86 | */ | 81 | */ |
87 | -public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { | 82 | +public class ControlPlaneRedirectManagerTest { |
88 | 83 | ||
89 | - private final Logger log = getLogger(getClass()); | ||
90 | private DeviceService deviceService; | 84 | private DeviceService deviceService; |
91 | private FlowObjectiveService flowObjectiveService; | 85 | private FlowObjectiveService flowObjectiveService; |
92 | private NetworkConfigService networkConfigService; | 86 | private NetworkConfigService networkConfigService; |
... | @@ -97,39 +91,34 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { | ... | @@ -97,39 +91,34 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { |
97 | private InterfaceService interfaceService; | 91 | private InterfaceService interfaceService; |
98 | private static final ApplicationId APPID = TestApplicationId.create("org.onosproject.cpredirect"); | 92 | private static final ApplicationId APPID = TestApplicationId.create("org.onosproject.cpredirect"); |
99 | 93 | ||
100 | - /** | 94 | + private static final DeviceId DEVICE_ID = DeviceId.deviceId("of:0000000000000001"); |
101 | - * Interface Configuration. | 95 | + |
102 | - * | 96 | + private ConnectPoint controlPlaneConnectPoint = new ConnectPoint(DEVICE_ID, |
103 | - **/ | ||
104 | - private ConnectPoint controlPlaneConnectPoint = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), | ||
105 | PortNumber.portNumber(1)); | 97 | PortNumber.portNumber(1)); |
106 | - private static final ConnectPoint SW1_ETH1 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), | 98 | + |
99 | + private static final ConnectPoint SW1_ETH1 = new ConnectPoint(DEVICE_ID, | ||
107 | PortNumber.portNumber(1)); | 100 | PortNumber.portNumber(1)); |
108 | 101 | ||
109 | - private static final ConnectPoint SW1_ETH2 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), | 102 | + private static final ConnectPoint SW1_ETH2 = new ConnectPoint(DEVICE_ID, |
110 | PortNumber.portNumber(2)); | 103 | PortNumber.portNumber(2)); |
111 | 104 | ||
112 | - private static final ConnectPoint SW1_ETH3 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), | 105 | + private static final ConnectPoint SW1_ETH3 = new ConnectPoint(DEVICE_ID, |
113 | PortNumber.portNumber(3)); | 106 | PortNumber.portNumber(3)); |
114 | - protected HostService hostService; | ||
115 | 107 | ||
116 | - private ControlPlaneRedirectManager controlPlaneRedirectManager = new ControlPlaneRedirectManager();; | 108 | + private ControlPlaneRedirectManager controlPlaneRedirectManager = new ControlPlaneRedirectManager(); |
117 | private RouterConfig routerConfig = new TestRouterConfig(); | 109 | private RouterConfig routerConfig = new TestRouterConfig(); |
118 | private NetworkConfigListener networkConfigListener; | 110 | private NetworkConfigListener networkConfigListener; |
119 | private DeviceListener deviceListener; | 111 | private DeviceListener deviceListener; |
120 | private MastershipService mastershipService = new InternalMastershipServiceTest(); | 112 | private MastershipService mastershipService = new InternalMastershipServiceTest(); |
121 | - private HostListener hostListener; | ||
122 | private InterfaceListener interfaceListener; | 113 | private InterfaceListener interfaceListener; |
123 | - @Override | 114 | + |
124 | @Before | 115 | @Before |
125 | public void setUp() { | 116 | public void setUp() { |
126 | networkConfigListener = createMock(NetworkConfigListener.class); | 117 | networkConfigListener = createMock(NetworkConfigListener.class); |
127 | - hostService = new TestHostService(); | ||
128 | deviceService = new TestDeviceService(); | 118 | deviceService = new TestDeviceService(); |
129 | deviceListener = createMock(DeviceListener.class); | 119 | deviceListener = createMock(DeviceListener.class); |
130 | - hostListener = createMock(HostListener.class); | 120 | + |
131 | interfaceListener = createMock(InterfaceListener.class); | 121 | interfaceListener = createMock(InterfaceListener.class); |
132 | - hostService.addListener(hostListener); | ||
133 | deviceService.addListener(deviceListener); | 122 | deviceService.addListener(deviceListener); |
134 | setUpInterfaceService(); | 123 | setUpInterfaceService(); |
135 | interfaceService = new InternalInterfaceService(); | 124 | interfaceService = new InternalInterfaceService(); |
... | @@ -143,7 +132,7 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { | ... | @@ -143,7 +132,7 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { |
143 | controlPlaneRedirectManager.networkConfigService = networkConfigService; | 132 | controlPlaneRedirectManager.networkConfigService = networkConfigService; |
144 | controlPlaneRedirectManager.interfaceService = interfaceService; | 133 | controlPlaneRedirectManager.interfaceService = interfaceService; |
145 | controlPlaneRedirectManager.deviceService = deviceService; | 134 | controlPlaneRedirectManager.deviceService = deviceService; |
146 | - controlPlaneRedirectManager.hostService = hostService; | 135 | + controlPlaneRedirectManager.hostService = createNiceMock(HostService.class); |
147 | controlPlaneRedirectManager.mastershipService = mastershipService; | 136 | controlPlaneRedirectManager.mastershipService = mastershipService; |
148 | controlPlaneRedirectManager.activate(); | 137 | controlPlaneRedirectManager.activate(); |
149 | verify(flowObjectiveService); | 138 | verify(flowObjectiveService); |
... | @@ -154,7 +143,7 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { | ... | @@ -154,7 +143,7 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { |
154 | */ | 143 | */ |
155 | @Test | 144 | @Test |
156 | public void testAddDevice() { | 145 | public void testAddDevice() { |
157 | - ConnectPoint sw1eth4 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(4)); | 146 | + ConnectPoint sw1eth4 = new ConnectPoint(DEVICE_ID, PortNumber.portNumber(4)); |
158 | Set<InterfaceIpAddress> interfaceIpAddresses4 = Sets.newHashSet(); | 147 | Set<InterfaceIpAddress> interfaceIpAddresses4 = Sets.newHashSet(); |
159 | interfaceIpAddresses4 | 148 | interfaceIpAddresses4 |
160 | .add(new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24"))); | 149 | .add(new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24"))); |
... | @@ -173,7 +162,7 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { | ... | @@ -173,7 +162,7 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { |
173 | */ | 162 | */ |
174 | @Test | 163 | @Test |
175 | public void testUpdateNetworkConfig() { | 164 | public void testUpdateNetworkConfig() { |
176 | - ConnectPoint sw1eth4 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(4)); | 165 | + ConnectPoint sw1eth4 = new ConnectPoint(DEVICE_ID, PortNumber.portNumber(4)); |
177 | Set<InterfaceIpAddress> interfaceIpAddresses4 = Sets.newHashSet(); | 166 | Set<InterfaceIpAddress> interfaceIpAddresses4 = Sets.newHashSet(); |
178 | interfaceIpAddresses4 | 167 | interfaceIpAddresses4 |
179 | .add(new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24"))); | 168 | .add(new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24"))); |
... | @@ -194,7 +183,7 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { | ... | @@ -194,7 +183,7 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { |
194 | */ | 183 | */ |
195 | @Test | 184 | @Test |
196 | public void testAddInterface() { | 185 | public void testAddInterface() { |
197 | - ConnectPoint sw1eth4 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(4)); | 186 | + ConnectPoint sw1eth4 = new ConnectPoint(DEVICE_ID, PortNumber.portNumber(4)); |
198 | Set<InterfaceIpAddress> interfaceIpAddresses4 = Sets.newHashSet(); | 187 | Set<InterfaceIpAddress> interfaceIpAddresses4 = Sets.newHashSet(); |
199 | interfaceIpAddresses4 | 188 | interfaceIpAddresses4 |
200 | .add(new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24"))); | 189 | .add(new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24"))); |
... | @@ -208,14 +197,13 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { | ... | @@ -208,14 +197,13 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { |
208 | 197 | ||
209 | setUpInterfaceConfiguration(sw1Eth4, true); | 198 | setUpInterfaceConfiguration(sw1Eth4, true); |
210 | replay(flowObjectiveService); | 199 | replay(flowObjectiveService); |
211 | - interfaceListener.event(new InterfaceEvent( | 200 | + interfaceListener.event(new InterfaceEvent(InterfaceEvent.Type.INTERFACE_ADDED, sw1Eth4, 500L)); |
212 | - org.onosproject.incubator.net.intf.InterfaceEvent.Type.INTERFACE_ADDED, sw1Eth4, 500L)); | ||
213 | verify(flowObjectiveService); | 201 | verify(flowObjectiveService); |
214 | } | 202 | } |
215 | 203 | ||
216 | @Test | 204 | @Test |
217 | public void testRemoveInterface() { | 205 | public void testRemoveInterface() { |
218 | - ConnectPoint sw1eth4 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(4)); | 206 | + ConnectPoint sw1eth4 = new ConnectPoint(DEVICE_ID, PortNumber.portNumber(4)); |
219 | Set<InterfaceIpAddress> interfaceIpAddresses4 = Sets.newHashSet(); | 207 | Set<InterfaceIpAddress> interfaceIpAddresses4 = Sets.newHashSet(); |
220 | interfaceIpAddresses4 | 208 | interfaceIpAddresses4 |
221 | .add(new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24"))); | 209 | .add(new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24"))); |
... | @@ -227,8 +215,7 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { | ... | @@ -227,8 +215,7 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { |
227 | 215 | ||
228 | setUpInterfaceConfiguration(sw1Eth4, false); | 216 | setUpInterfaceConfiguration(sw1Eth4, false); |
229 | replay(flowObjectiveService); | 217 | replay(flowObjectiveService); |
230 | - interfaceListener.event(new InterfaceEvent( | 218 | + interfaceListener.event(new InterfaceEvent(InterfaceEvent.Type.INTERFACE_REMOVED, sw1Eth4, 500L)); |
231 | - org.onosproject.incubator.net.intf.InterfaceEvent.Type.INTERFACE_REMOVED, sw1Eth4, 500L)); | ||
232 | verify(flowObjectiveService); | 219 | verify(flowObjectiveService); |
233 | } | 220 | } |
234 | 221 | ||
... | @@ -407,15 +394,6 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { | ... | @@ -407,15 +394,6 @@ public class ControlPlaneRedirectManagerTest extends AbstractIntentTest { |
407 | 394 | ||
408 | } | 395 | } |
409 | 396 | ||
410 | - private class TestHostService extends HostServiceAdapter { | ||
411 | - | ||
412 | - @Override | ||
413 | - public void addListener(HostListener listener) { | ||
414 | - ControlPlaneRedirectManagerTest.this.hostListener = listener; | ||
415 | - } | ||
416 | - | ||
417 | - } | ||
418 | - | ||
419 | private class TestRouterConfig extends RouterConfig { | 397 | private class TestRouterConfig extends RouterConfig { |
420 | 398 | ||
421 | @Override | 399 | @Override | ... | ... |
... | @@ -15,20 +15,8 @@ | ... | @@ -15,20 +15,8 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.routing.impl; | 16 | package org.onosproject.routing.impl; |
17 | 17 | ||
18 | -import static org.easymock.EasyMock.anyObject; | 18 | +import com.google.common.collect.ImmutableSet; |
19 | -import static org.easymock.EasyMock.createMock; | 19 | +import com.google.common.collect.Sets; |
20 | -import static org.easymock.EasyMock.expect; | ||
21 | -import static org.easymock.EasyMock.replay; | ||
22 | -import static org.easymock.EasyMock.reset; | ||
23 | -import static org.easymock.EasyMock.verify; | ||
24 | - | ||
25 | -import java.util.ArrayList; | ||
26 | -import java.util.Collections; | ||
27 | -import java.util.Dictionary; | ||
28 | -import java.util.HashSet; | ||
29 | -import java.util.List; | ||
30 | -import java.util.Set; | ||
31 | - | ||
32 | import org.easymock.EasyMock; | 20 | import org.easymock.EasyMock; |
33 | import org.junit.Before; | 21 | import org.junit.Before; |
34 | import org.junit.Test; | 22 | import org.junit.Test; |
... | @@ -40,11 +28,10 @@ import org.onlab.packet.IpPrefix; | ... | @@ -40,11 +28,10 @@ import org.onlab.packet.IpPrefix; |
40 | import org.onlab.packet.MacAddress; | 28 | import org.onlab.packet.MacAddress; |
41 | import org.onlab.packet.VlanId; | 29 | import org.onlab.packet.VlanId; |
42 | import org.onosproject.TestApplicationId; | 30 | import org.onosproject.TestApplicationId; |
31 | +import org.onosproject.cfg.ComponentConfigService; | ||
43 | import org.onosproject.core.ApplicationId; | 32 | import org.onosproject.core.ApplicationId; |
44 | import org.onosproject.core.CoreService; | 33 | import org.onosproject.core.CoreService; |
45 | import org.onosproject.core.CoreServiceAdapter; | 34 | import org.onosproject.core.CoreServiceAdapter; |
46 | -import org.osgi.service.component.ComponentContext; | ||
47 | -import org.onosproject.cfg.ComponentConfigService; | ||
48 | import org.onosproject.incubator.net.intf.Interface; | 35 | import org.onosproject.incubator.net.intf.Interface; |
49 | import org.onosproject.incubator.net.intf.InterfaceListener; | 36 | import org.onosproject.incubator.net.intf.InterfaceListener; |
50 | import org.onosproject.incubator.net.intf.InterfaceService; | 37 | import org.onosproject.incubator.net.intf.InterfaceService; |
... | @@ -73,8 +60,21 @@ import org.onosproject.routing.FibUpdate; | ... | @@ -73,8 +60,21 @@ import org.onosproject.routing.FibUpdate; |
73 | import org.onosproject.routing.RoutingService; | 60 | import org.onosproject.routing.RoutingService; |
74 | import org.onosproject.routing.RoutingServiceAdapter; | 61 | import org.onosproject.routing.RoutingServiceAdapter; |
75 | import org.onosproject.routing.config.RouterConfig; | 62 | import org.onosproject.routing.config.RouterConfig; |
76 | -import com.google.common.collect.ImmutableSet; | 63 | +import org.osgi.service.component.ComponentContext; |
77 | -import com.google.common.collect.Sets; | 64 | + |
65 | +import java.util.ArrayList; | ||
66 | +import java.util.Collections; | ||
67 | +import java.util.Dictionary; | ||
68 | +import java.util.HashSet; | ||
69 | +import java.util.List; | ||
70 | +import java.util.Set; | ||
71 | + | ||
72 | +import static org.easymock.EasyMock.anyObject; | ||
73 | +import static org.easymock.EasyMock.createMock; | ||
74 | +import static org.easymock.EasyMock.expect; | ||
75 | +import static org.easymock.EasyMock.replay; | ||
76 | +import static org.easymock.EasyMock.reset; | ||
77 | +import static org.easymock.EasyMock.verify; | ||
78 | 78 | ||
79 | /** | 79 | /** |
80 | * Unit tests for SingleSwitchFibInstaller. | 80 | * Unit tests for SingleSwitchFibInstaller. |
... | @@ -198,7 +198,7 @@ public class SingleSwitchFibInstallerTest extends AbstractIntentTest { | ... | @@ -198,7 +198,7 @@ public class SingleSwitchFibInstallerTest extends AbstractIntentTest { |
198 | 198 | ||
199 | /* | 199 | /* |
200 | * Sets up NetworkConfigService. | 200 | * Sets up NetworkConfigService. |
201 | - */ | 201 | + */ |
202 | private void setUpNetworkConfigService() { | 202 | private void setUpNetworkConfigService() { |
203 | ApplicationId routerAppId = coreService.registerApplication(RoutingService.ROUTER_APP_ID); | 203 | ApplicationId routerAppId = coreService.registerApplication(RoutingService.ROUTER_APP_ID); |
204 | expect(networkConfigService.getConfig(routerAppId, RoutingService.ROUTER_CONFIG_CLASS)). | 204 | expect(networkConfigService.getConfig(routerAppId, RoutingService.ROUTER_CONFIG_CLASS)). |
... | @@ -423,13 +423,12 @@ public class SingleSwitchFibInstallerTest extends AbstractIntentTest { | ... | @@ -423,13 +423,12 @@ public class SingleSwitchFibInstallerTest extends AbstractIntentTest { |
423 | verify(flowObjectiveService); | 423 | verify(flowObjectiveService); |
424 | } | 424 | } |
425 | 425 | ||
426 | - /** | 426 | + /** |
427 | * Tests deleting a FIB entry. | 427 | * Tests deleting a FIB entry. |
428 | * | 428 | * |
429 | * We verify that the flowObjectiveService records the correct state and that the | 429 | * We verify that the flowObjectiveService records the correct state and that the |
430 | * correct flow is withdrawn from the flowObjectiveService. | 430 | * correct flow is withdrawn from the flowObjectiveService. |
431 | */ | 431 | */ |
432 | - | ||
433 | @Test | 432 | @Test |
434 | public void testFibDelete() { | 433 | public void testFibDelete() { |
435 | // Firstly add a route | 434 | // Firstly add a route | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.net.flowobjective; | ||
18 | + | ||
19 | +import java.util.function.BiConsumer; | ||
20 | +import java.util.function.Consumer; | ||
21 | + | ||
22 | +/** | ||
23 | + * Implementation of objective context that delegates calls to provided | ||
24 | + * consumers. | ||
25 | + */ | ||
26 | +public class DefaultObjectiveContext implements ObjectiveContext { | ||
27 | + | ||
28 | + private final Consumer<Objective> onSuccess; | ||
29 | + private final BiConsumer<Objective, ObjectiveError> onError; | ||
30 | + | ||
31 | + /** | ||
32 | + * Creates a new objective context using the given success and error | ||
33 | + * consumers. | ||
34 | + * | ||
35 | + * @param onSuccess consumer to be called on success | ||
36 | + * @param onError consumer to be called on error | ||
37 | + */ | ||
38 | + public DefaultObjectiveContext(Consumer<Objective> onSuccess, | ||
39 | + BiConsumer<Objective, ObjectiveError> onError) { | ||
40 | + this.onSuccess = onSuccess; | ||
41 | + this.onError = onError; | ||
42 | + } | ||
43 | + | ||
44 | + /** | ||
45 | + * Creates a new objective context using the given success consumer. | ||
46 | + * | ||
47 | + * @param onSuccess consumer to be called on success | ||
48 | + */ | ||
49 | + public DefaultObjectiveContext(Consumer<Objective> onSuccess) { | ||
50 | + this(onSuccess, null); | ||
51 | + } | ||
52 | + | ||
53 | + /** | ||
54 | + * Creates a new objective context using the given error consumer. | ||
55 | + * | ||
56 | + * @param onError consumer to be called on error | ||
57 | + */ | ||
58 | + public DefaultObjectiveContext(BiConsumer<Objective, ObjectiveError> onError) { | ||
59 | + this(null, onError); | ||
60 | + } | ||
61 | + | ||
62 | + @Override | ||
63 | + public void onSuccess(Objective objective) { | ||
64 | + if (onSuccess != null) { | ||
65 | + onSuccess.accept(objective); | ||
66 | + } | ||
67 | + } | ||
68 | + | ||
69 | + @Override | ||
70 | + public void onError(Objective objective, ObjectiveError error) { | ||
71 | + if (onError != null) { | ||
72 | + onError.accept(objective, error); | ||
73 | + } | ||
74 | + } | ||
75 | +} |
-
Please register or login to post a comment