blob: 7ffe8e9134cf2d63dc471a34987ee812216fdcb0 [file] [log] [blame]
Jonathan Hart23701d12014-04-03 10:45:48 -07001package net.onrc.onos.core.flowprogrammer;
Naoki Shiota75b7dd62013-12-03 18:09:21 -08002
Naoki Shiota75b7dd62013-12-03 18:09:21 -08003import net.floodlightcontroller.core.FloodlightContext;
4import net.floodlightcontroller.core.IFloodlightProviderService;
5import net.floodlightcontroller.core.IOFSwitch;
6import net.floodlightcontroller.core.module.FloodlightModuleContext;
7import net.floodlightcontroller.threadpool.IThreadPoolService;
8import net.floodlightcontroller.util.OFMessageDamper;
Jonathan Hart23701d12014-04-03 10:45:48 -07009import net.onrc.onos.core.util.Dpid;
10import net.onrc.onos.core.util.FlowEntry;
11import net.onrc.onos.core.util.FlowEntryActions;
12import net.onrc.onos.core.util.FlowEntryErrorState;
13import net.onrc.onos.core.util.FlowEntryId;
14import net.onrc.onos.core.util.FlowEntryMatch;
15import net.onrc.onos.core.util.FlowEntryUserState;
16import net.onrc.onos.core.util.FlowId;
Ray Milkey10643572014-06-10 15:17:39 -070017import net.onrc.onos.core.util.IntegrationTest;
Jonathan Hart23701d12014-04-03 10:45:48 -070018import net.onrc.onos.core.util.Port;
Naoki Shiota75b7dd62013-12-03 18:09:21 -080019import org.easymock.EasyMock;
20import org.easymock.IAnswer;
Ray Milkey10643572014-06-10 15:17:39 -070021import org.junit.Assert;
Naoki Shiota75b7dd62013-12-03 18:09:21 -080022import org.junit.Test;
Ray Milkey10643572014-06-10 15:17:39 -070023import org.junit.experimental.categories.Category;
Naoki Shiota75b7dd62013-12-03 18:09:21 -080024import org.openflow.protocol.OFBarrierRequest;
25import org.openflow.protocol.OFFlowMod;
26import org.openflow.protocol.OFMatch;
27import org.openflow.protocol.OFMessage;
28import org.openflow.protocol.OFType;
29import org.openflow.protocol.action.OFAction;
30import org.openflow.protocol.factory.BasicFactory;
31
Ray Milkey10643572014-06-10 15:17:39 -070032import java.io.IOException;
33import java.util.ArrayList;
34import java.util.HashMap;
35import java.util.List;
36import java.util.Map;
37import java.util.concurrent.ScheduledExecutorService;
38import java.util.concurrent.TimeUnit;
39
40import static org.junit.Assert.assertEquals;
41import static org.junit.Assert.assertNotNull;
42import static org.junit.Assert.assertTrue;
43import static org.junit.Assert.fail;
44
45@Category(IntegrationTest.class)
Naoki Shiota75b7dd62013-12-03 18:09:21 -080046public class FlowPusherTest {
Ray Milkey269ffb92014-04-03 14:43:30 -070047 private FlowPusher pusher;
48 private FloodlightContext context;
49 private FloodlightModuleContext modContext;
50 private BasicFactory factory;
51 private OFMessageDamper damper;
52 private IFloodlightProviderService flProviderService;
53 private IThreadPoolService threadPoolService;
Naoki Shiota75b7dd62013-12-03 18:09:21 -080054
Ray Milkey269ffb92014-04-03 14:43:30 -070055 /**
56 * Test single OFMessage is correctly sent to single switch via MessageDamper.
57 */
58 @Test
59 public void testAddMessage() {
60 beginInitMock();
Naoki Shiota75b7dd62013-12-03 18:09:21 -080061
Ray Milkey269ffb92014-04-03 14:43:30 -070062 OFMessage msg = EasyMock.createMock(OFMessage.class);
63 EasyMock.expect(msg.getXid()).andReturn(1).anyTimes();
64 EasyMock.expect(msg.getLength()).andReturn((short) 100).anyTimes();
65 EasyMock.replay(msg);
Naoki Shiota75b7dd62013-12-03 18:09:21 -080066
Ray Milkey269ffb92014-04-03 14:43:30 -070067 IOFSwitch sw = EasyMock.createMock(IOFSwitch.class);
68 EasyMock.expect(sw.getId()).andReturn((long) 1).anyTimes();
69 sw.flush();
70 EasyMock.expectLastCall().once();
71 EasyMock.replay(sw);
Naoki Shiotad6ef3b32014-03-13 18:42:23 -070072
Ray Milkey269ffb92014-04-03 14:43:30 -070073 try {
74 EasyMock.expect(damper.write(EasyMock.eq(sw), EasyMock.eq(msg), EasyMock.eq(context)))
75 .andReturn(true).once();
76 } catch (IOException e1) {
77 fail("Failed in OFMessageDamper#write()");
78 }
Naoki Shiota75b7dd62013-12-03 18:09:21 -080079
Ray Milkey269ffb92014-04-03 14:43:30 -070080 endInitMock();
81 initPusher(1);
Naoki Shiotad6ef3b32014-03-13 18:42:23 -070082
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070083 boolean addResult = pusher.add(sw, msg);
84 assertTrue(addResult);
Naoki Shiota75b7dd62013-12-03 18:09:21 -080085
Ray Milkey269ffb92014-04-03 14:43:30 -070086 try {
87 // wait until message is processed.
88 Thread.sleep(1000);
89 } catch (InterruptedException e) {
90 fail("Failed in Thread.sleep()");
91 }
92 EasyMock.verify(msg);
93 EasyMock.verify(sw);
94 verifyAll();
Naoki Shiota75b7dd62013-12-03 18:09:21 -080095
Ray Milkey269ffb92014-04-03 14:43:30 -070096 pusher.stop();
97 }
Naoki Shiota75b7dd62013-12-03 18:09:21 -080098
Ray Milkey269ffb92014-04-03 14:43:30 -070099 /**
100 * Test bunch of OFMessages are correctly sent to single switch via MessageDamper.
101 */
102 @Test
103 public void testMassiveAddMessage() {
Yuta HIGUCHI7c39c842014-06-09 16:33:03 -0700104 // Some number larger than FlowPusher.MAX_MESSAGE_SEND
105 final int NUM_MSG = FlowPusher.MAX_MESSAGE_SEND * 2;
Naoki Shiotad6ef3b32014-03-13 18:42:23 -0700106
Ray Milkey269ffb92014-04-03 14:43:30 -0700107 beginInitMock();
Naoki Shiota75b7dd62013-12-03 18:09:21 -0800108
Ray Milkey269ffb92014-04-03 14:43:30 -0700109 IOFSwitch sw = EasyMock.createMock(IOFSwitch.class);
110 EasyMock.expect(sw.getId()).andReturn((long) 1).anyTimes();
111 sw.flush();
112 EasyMock.expectLastCall().atLeastOnce();
113 EasyMock.replay(sw);
Naoki Shiota75b7dd62013-12-03 18:09:21 -0800114
Ray Milkey269ffb92014-04-03 14:43:30 -0700115 List<OFMessage> messages = new ArrayList<OFMessage>();
Naoki Shiota75b7dd62013-12-03 18:09:21 -0800116
Ray Milkey269ffb92014-04-03 14:43:30 -0700117 for (int i = 0; i < NUM_MSG; ++i) {
118 OFMessage msg = EasyMock.createMock(OFMessage.class);
119 EasyMock.expect(msg.getXid()).andReturn(i).anyTimes();
120 EasyMock.expect(msg.getLength()).andReturn((short) 100).anyTimes();
121 EasyMock.replay(msg);
122 messages.add(msg);
Naoki Shiota75b7dd62013-12-03 18:09:21 -0800123
Ray Milkey269ffb92014-04-03 14:43:30 -0700124 try {
125 EasyMock.expect(damper.write(EasyMock.eq(sw), EasyMock.eq(msg), EasyMock.eq(context)))
126 .andReturn(true).once();
127 } catch (IOException e1) {
128 fail("Failed in OFMessageDamper#write()");
129 }
130 }
Naoki Shiotad6ef3b32014-03-13 18:42:23 -0700131
Ray Milkey269ffb92014-04-03 14:43:30 -0700132 endInitMock();
133 initPusher(1);
Naoki Shiota75b7dd62013-12-03 18:09:21 -0800134
Ray Milkey269ffb92014-04-03 14:43:30 -0700135 for (OFMessage msg : messages) {
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700136 boolean addResult = pusher.add(sw, msg);
137 assertTrue(addResult);
Ray Milkey269ffb92014-04-03 14:43:30 -0700138 }
Naoki Shiota75b7dd62013-12-03 18:09:21 -0800139
Ray Milkey269ffb92014-04-03 14:43:30 -0700140 try {
141 // wait until message is processed.
Yuta HIGUCHI7c39c842014-06-09 16:33:03 -0700142 Thread.sleep(1000);
Ray Milkey269ffb92014-04-03 14:43:30 -0700143 } catch (InterruptedException e) {
144 fail("Failed in Thread.sleep()");
145 }
Naoki Shiotad6ef3b32014-03-13 18:42:23 -0700146
Ray Milkey269ffb92014-04-03 14:43:30 -0700147 for (OFMessage msg : messages) {
148 EasyMock.verify(msg);
149 }
150 EasyMock.verify(sw);
151 verifyAll();
152
153 pusher.stop();
154 }
155
156 /**
157 * Test bunch of OFMessages are correctly sent to multiple switches with single threads.
158 */
159 @Test
160 public void testMultiSwitchAddMessage() {
161 final int NUM_SWITCH = 10;
162 final int NUM_MSG = 100; // messages per thread
163
164 beginInitMock();
165
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700166 Map<IOFSwitch, List<OFMessage>> swMap = new HashMap<IOFSwitch, List<OFMessage>>();
Ray Milkey269ffb92014-04-03 14:43:30 -0700167 for (int i = 0; i < NUM_SWITCH; ++i) {
168 IOFSwitch sw = EasyMock.createMock(IOFSwitch.class);
169 EasyMock.expect(sw.getId()).andReturn((long) i).anyTimes();
170 sw.flush();
171 EasyMock.expectLastCall().atLeastOnce();
172 EasyMock.replay(sw);
173
174 List<OFMessage> messages = new ArrayList<OFMessage>();
175
176 for (int j = 0; j < NUM_MSG; ++j) {
177 OFMessage msg = EasyMock.createMock(OFMessage.class);
178 EasyMock.expect(msg.getXid()).andReturn(j).anyTimes();
179 EasyMock.expect(msg.getLength()).andReturn((short) 100).anyTimes();
180 EasyMock.replay(msg);
181 messages.add(msg);
182
183 try {
184 EasyMock.expect(damper.write(EasyMock.eq(sw), EasyMock.eq(msg), EasyMock.eq(context)))
185 .andReturn(true).once();
186 } catch (IOException e1) {
187 fail("Failed in OFMessageDamper#write()");
188 }
189 }
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700190 swMap.put(sw, messages);
Ray Milkey269ffb92014-04-03 14:43:30 -0700191 }
192
193 endInitMock();
194 initPusher(1);
195
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700196 for (IOFSwitch sw : swMap.keySet()) {
197 for (OFMessage msg : swMap.get(sw)) {
198 boolean addResult = pusher.add(sw, msg);
199 assertTrue(addResult);
Ray Milkey269ffb92014-04-03 14:43:30 -0700200 }
201 }
202
203 try {
204 // wait until message is processed.
205 Thread.sleep(1000);
206 } catch (InterruptedException e) {
207 fail("Failed in Thread.sleep()");
208 }
209
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700210 for (IOFSwitch sw : swMap.keySet()) {
211 for (OFMessage msg : swMap.get(sw)) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700212 EasyMock.verify(msg);
213 }
214
215 EasyMock.verify(sw);
216 }
217 verifyAll();
218
219 pusher.stop();
220 }
221
222 /**
223 * Test bunch of OFMessages are correctly sent to multiple switches using multiple threads.
224 */
225 @Test
226 public void testMultiThreadedAddMessage() {
227 final int NUM_THREAD = 10;
228 final int NUM_MSG = 100; // messages per thread
229
230 beginInitMock();
231
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700232 Map<IOFSwitch, List<OFMessage>> swMap = new HashMap<IOFSwitch, List<OFMessage>>();
Ray Milkey269ffb92014-04-03 14:43:30 -0700233 for (int i = 0; i < NUM_THREAD; ++i) {
234 IOFSwitch sw = EasyMock.createMock(IOFSwitch.class);
235 EasyMock.expect(sw.getId()).andReturn((long) i).anyTimes();
236 sw.flush();
237 EasyMock.expectLastCall().atLeastOnce();
238 EasyMock.replay(sw);
239
240 List<OFMessage> messages = new ArrayList<OFMessage>();
241
242 for (int j = 0; j < NUM_MSG; ++j) {
243 OFMessage msg = EasyMock.createMock(OFMessage.class);
244 EasyMock.expect(msg.getXid()).andReturn(j).anyTimes();
245 EasyMock.expect(msg.getLength()).andReturn((short) 100).anyTimes();
246 EasyMock.replay(msg);
247 messages.add(msg);
248
249 try {
250 EasyMock.expect(damper.write(EasyMock.eq(sw), EasyMock.eq(msg), EasyMock.eq(context)))
251 .andReturn(true).once();
252 } catch (IOException e1) {
253 fail("Failed in OFMessageDamper#write()");
254 }
255 }
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700256 swMap.put(sw, messages);
Ray Milkey269ffb92014-04-03 14:43:30 -0700257 }
258
259 endInitMock();
260 initPusher(NUM_THREAD);
261
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700262 for (IOFSwitch sw : swMap.keySet()) {
263 for (OFMessage msg : swMap.get(sw)) {
264 boolean addResult = pusher.add(sw, msg);
265 assertTrue(addResult);
Ray Milkey269ffb92014-04-03 14:43:30 -0700266 }
267 }
268
269 try {
270 // wait until message is processed.
271 Thread.sleep(1000);
272 } catch (InterruptedException e) {
273 fail("Failed in Thread.sleep()");
274 }
275
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700276 for (IOFSwitch sw : swMap.keySet()) {
277 for (OFMessage msg : swMap.get(sw)) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700278 EasyMock.verify(msg);
279 }
280
281 EasyMock.verify(sw);
282 }
283 verifyAll();
284
285 pusher.stop();
286 }
287
288 private long barrierTime = 0;
289
290 /**
291 * Test rate limitation of messages works correctly.
292 */
293 @Test
294 public void testRateLimitedAddMessage() {
295 final long LIMIT_RATE = 100; // [bytes/ms]
296 final int NUM_MSG = 1000;
297
298 // Accuracy of FlowPusher's rate calculation can't be measured by unit test
299 // because switch doesn't return BARRIER_REPLY.
300 // In unit test we use approximate way to measure rate. This value is
301 // acceptable margin of measured rate.
302 final double ACCEPTABLE_RATE = LIMIT_RATE * 1.2;
303
304 beginInitMock();
305
306 IOFSwitch sw = EasyMock.createMock(IOFSwitch.class);
307 EasyMock.expect(sw.getId()).andReturn((long) 1).anyTimes();
308 sw.flush();
309 EasyMock.expectLastCall().atLeastOnce();
310 prepareBarrier(sw);
311 EasyMock.replay(sw);
312
313 List<OFMessage> messages = new ArrayList<OFMessage>();
314
315 for (int i = 0; i < NUM_MSG; ++i) {
316 OFMessage msg = EasyMock.createMock(OFMessage.class);
317 EasyMock.expect(msg.getXid()).andReturn(1).anyTimes();
318 EasyMock.expect(msg.getLength()).andReturn((short) 100).anyTimes();
319 EasyMock.expect(msg.getLengthU()).andReturn(100).anyTimes();
320 EasyMock.replay(msg);
321 messages.add(msg);
322
323 try {
324 EasyMock.expect(damper.write(EasyMock.eq(sw), EasyMock.eq(msg), EasyMock.eq(context)))
325 .andReturn(true).once();
326 } catch (IOException e) {
327 fail("Failed in OFMessageDamper#write()");
328 }
329 }
330
331 try {
332 EasyMock.expect(damper.write(EasyMock.eq(sw), (OFMessage) EasyMock.anyObject(), EasyMock.eq(context)))
333 .andAnswer(new IAnswer<Boolean>() {
334 @Override
335 public Boolean answer() throws Throwable {
336 OFMessage msg = (OFMessage) EasyMock.getCurrentArguments()[1];
337 if (msg.getType() == OFType.BARRIER_REQUEST) {
338 barrierTime = System.currentTimeMillis();
339 }
340 return true;
341 }
342 }).once();
343 } catch (IOException e1) {
344 fail("Failed in OFMessageDamper#write()");
345 }
346
347 endInitMock();
348 initPusher(1);
349
350 pusher.createQueue(sw);
351 pusher.setRate(sw, LIMIT_RATE);
352
353 long beginTime = System.currentTimeMillis();
354 for (OFMessage msg : messages) {
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700355 boolean addResult = pusher.add(sw, msg);
356 assertTrue(addResult);
Ray Milkey269ffb92014-04-03 14:43:30 -0700357 }
358
359 pusher.barrierAsync(sw);
360
361 try {
362 do {
363 Thread.sleep(1000);
364 } while (barrierTime == 0);
365 } catch (InterruptedException e) {
366 fail("Failed to sleep");
367 }
368
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700369 double measuredRate = NUM_MSG * 100 / (barrierTime - beginTime);
370 assertTrue(measuredRate < ACCEPTABLE_RATE);
Ray Milkey269ffb92014-04-03 14:43:30 -0700371
372 for (OFMessage msg : messages) {
373 EasyMock.verify(msg);
374 }
375 EasyMock.verify(sw);
376 verifyAll();
377
378 pusher.stop();
379 }
380
381 /**
382 * Test barrier message is correctly sent to a switch.
383 */
384 @Test
385 public void testBarrierMessage() {
386 beginInitMock();
387
388 IOFSwitch sw = EasyMock.createMock(IOFSwitch.class);
389 EasyMock.expect(sw.getId()).andReturn((long) 1).anyTimes();
390 sw.flush();
391 EasyMock.expectLastCall().atLeastOnce();
392 prepareBarrier(sw);
393 EasyMock.replay(sw);
394
395 try {
396 EasyMock.expect(damper.write(EasyMock.eq(sw), (OFMessage) EasyMock.anyObject(), EasyMock.eq(context)))
397 .andReturn(true).once();
398 } catch (IOException e1) {
399 fail("Failed in OFMessageDamper#write()");
400 }
401
402 endInitMock();
403 initPusher(1);
404
405 OFBarrierReplyFuture future = pusher.barrierAsync(sw);
406
407 assertNotNull(future);
408
409 try {
410 Thread.sleep(1000);
411 } catch (InterruptedException e) {
412 fail("Failed to sleep");
413 }
414
415 verifyAll();
416
417 pusher.stop();
418 }
419
420 static final int XID_TO_VERIFY = 100;
421 static final long DPID_TO_VERIFY = 10;
422
423 /**
424 * Test FlowObject is correctly converted to message and is sent to a switch.
425 */
426 @SuppressWarnings("unchecked")
427 @Test
428 public void testAddFlow() {
429 // instantiate required objects
430 FlowEntry flowEntry1 = new FlowEntry();
431 flowEntry1.setDpid(new Dpid(DPID_TO_VERIFY));
432 flowEntry1.setFlowId(new FlowId(1));
433 flowEntry1.setInPort(new Port((short) 1));
434 flowEntry1.setOutPort(new Port((short) 11));
435 flowEntry1.setFlowEntryId(new FlowEntryId(1));
436 flowEntry1.setFlowEntryMatch(new FlowEntryMatch());
437 flowEntry1.setFlowEntryActions(new FlowEntryActions());
438 flowEntry1.setFlowEntryErrorState(new FlowEntryErrorState());
439 flowEntry1.setFlowEntryUserState(FlowEntryUserState.FE_USER_ADD);
440
441 beginInitMock();
442
443 OFFlowMod msg = EasyMock.createMock(OFFlowMod.class);
444 EasyMock.expect(msg.setIdleTimeout(EasyMock.anyShort())).andReturn(msg);
445 EasyMock.expect(msg.setHardTimeout(EasyMock.anyShort())).andReturn(msg);
446 EasyMock.expect(msg.setPriority(EasyMock.anyShort())).andReturn(msg);
447 EasyMock.expect(msg.setBufferId(EasyMock.anyInt())).andReturn(msg);
448 EasyMock.expect(msg.setCookie(EasyMock.anyLong())).andReturn(msg);
449 EasyMock.expect(msg.setCommand(EasyMock.anyShort())).andReturn(msg);
450 EasyMock.expect(msg.setMatch(EasyMock.anyObject(OFMatch.class))).andReturn(msg);
451 EasyMock.expect(msg.setActions((List<OFAction>) EasyMock.anyObject())).andReturn(msg);
452 EasyMock.expect(msg.setLengthU(EasyMock.anyShort())).andReturn(msg);
453 EasyMock.expect(msg.setOutPort(EasyMock.anyShort())).andReturn(msg).atLeastOnce();
454 EasyMock.expect(msg.getXid()).andReturn(XID_TO_VERIFY).anyTimes();
455 EasyMock.expect(msg.getType()).andReturn(OFType.FLOW_MOD).anyTimes();
456 EasyMock.expect(msg.getLength()).andReturn((short) 100).anyTimes();
457 EasyMock.replay(msg);
458
459 EasyMock.expect(factory.getMessage(EasyMock.eq(OFType.FLOW_MOD))).andReturn(msg);
460
461 IOFSwitch sw = EasyMock.createMock(IOFSwitch.class);
462 EasyMock.expect(sw.getId()).andReturn(DPID_TO_VERIFY).anyTimes();
463 EasyMock.expect(sw.getStringId()).andReturn("1").anyTimes();
464 sw.flush();
465 EasyMock.expectLastCall().once();
466
467 try {
468 EasyMock.expect(damper.write(EasyMock.eq(sw), EasyMock.anyObject(OFMessage.class), EasyMock.eq(context)))
469 .andAnswer(new IAnswer<Boolean>() {
470 @Override
471 public Boolean answer() throws Throwable {
472 OFMessage msg = (OFMessage) EasyMock.getCurrentArguments()[1];
473 if (msg.getType() == OFType.FLOW_MOD) {
474 assertEquals(msg.getXid(), XID_TO_VERIFY);
475 }
476 return true;
477 }
478 }).atLeastOnce();
479 } catch (IOException e1) {
480 fail("Failed in OFMessageDamper#write()");
481 }
482
483 EasyMock.replay(sw);
484
485 endInitMock();
486 initPusher(1);
487
488 pusher.pushFlowEntry(sw, flowEntry1);
489
490 try {
491 Thread.sleep(1000);
492 } catch (InterruptedException e) {
493 fail("Failed to sleep");
494 }
495
496 EasyMock.verify(sw);
497 verifyAll();
498
499 pusher.stop();
500 }
501
502 private void beginInitMock() {
503 context = EasyMock.createMock(FloodlightContext.class);
504 modContext = EasyMock.createMock(FloodlightModuleContext.class);
505 factory = EasyMock.createMock(BasicFactory.class);
506 damper = EasyMock.createMock(OFMessageDamper.class);
507 flProviderService = EasyMock.createMock(IFloodlightProviderService.class);
508 threadPoolService = EasyMock.createMock(IThreadPoolService.class);
509
510 EasyMock.expect(modContext.getServiceImpl(EasyMock.eq(IThreadPoolService.class)))
511 .andReturn(threadPoolService).once();
512 EasyMock.expect(modContext.getServiceImpl(EasyMock.eq(IFloodlightProviderService.class)))
513 .andReturn(flProviderService).once();
514 flProviderService.addOFMessageListener(EasyMock.eq(OFType.BARRIER_REPLY),
515 (FlowPusher) EasyMock.anyObject());
516 EasyMock.expectLastCall().once();
517
518 ScheduledExecutorService executor = EasyMock.createMock(ScheduledExecutorService.class);
519 EasyMock.expect(executor.schedule((Runnable) EasyMock.anyObject(), EasyMock.anyLong(),
520 (TimeUnit) EasyMock.anyObject())).andReturn(null).once();
521 EasyMock.replay(executor);
522 EasyMock.expect(threadPoolService.getScheduledExecutor()).andReturn(executor).anyTimes();
523 }
524
525 private void endInitMock() {
526 EasyMock.replay(threadPoolService);
527 EasyMock.replay(flProviderService);
528 EasyMock.replay(damper);
529 EasyMock.replay(factory);
530 EasyMock.replay(modContext);
531 EasyMock.replay(context);
532 }
533
534 private void verifyAll() {
535 EasyMock.verify(threadPoolService);
536 EasyMock.verify(flProviderService);
537 EasyMock.verify(damper);
538 EasyMock.verify(factory);
539 EasyMock.verify(modContext);
540 EasyMock.verify(context);
541 }
542
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700543 private void initPusher(int numThread) {
544 pusher = new FlowPusher(numThread);
Ray Milkey269ffb92014-04-03 14:43:30 -0700545 pusher.init(context, modContext, factory, damper);
546 pusher.start();
547 }
548
549 private void prepareBarrier(IOFSwitch sw) {
550 OFBarrierRequest req = EasyMock.createMock(OFBarrierRequest.class);
551 req.setXid(EasyMock.anyInt());
552 EasyMock.expectLastCall().once();
553 EasyMock.expect(req.getXid()).andReturn(1).anyTimes();
554 EasyMock.expect(req.getType()).andReturn(OFType.BARRIER_REQUEST).anyTimes();
555 EasyMock.expect(req.getLength()).andReturn((short) 100).anyTimes();
556 EasyMock.replay(req);
557 EasyMock.expect(factory.getMessage(EasyMock.eq(OFType.BARRIER_REQUEST))).andReturn(req).anyTimes();
558 EasyMock.expect(sw.getNextTransactionId()).andReturn(1);
559 }
560
Naoki Shiota75b7dd62013-12-03 18:09:21 -0800561}