blob: a8ef2200ec581f1344284bc7454e61b75db92d91 [file] [log] [blame]
Jonathan Hart23701d12014-04-03 10:45:48 -07001package net.onrc.onos.core.flowprogrammer;
Naoki Shiota75b7dd62013-12-03 18:09:21 -08002
Jonathan Harta88fd242014-04-03 11:24:54 -07003import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertNotNull;
5import static org.junit.Assert.assertTrue;
6import static org.junit.Assert.fail;
Naoki Shiota75b7dd62013-12-03 18:09:21 -08007
8import java.io.IOException;
9import java.util.ArrayList;
10import java.util.HashMap;
11import java.util.List;
12import java.util.Map;
13import java.util.concurrent.ScheduledExecutorService;
14import java.util.concurrent.TimeUnit;
15
16import net.floodlightcontroller.core.FloodlightContext;
17import net.floodlightcontroller.core.IFloodlightProviderService;
18import net.floodlightcontroller.core.IOFSwitch;
19import net.floodlightcontroller.core.module.FloodlightModuleContext;
20import net.floodlightcontroller.threadpool.IThreadPoolService;
21import net.floodlightcontroller.util.OFMessageDamper;
Jonathan Hart23701d12014-04-03 10:45:48 -070022import net.onrc.onos.core.util.Dpid;
23import net.onrc.onos.core.util.FlowEntry;
24import net.onrc.onos.core.util.FlowEntryActions;
25import net.onrc.onos.core.util.FlowEntryErrorState;
26import net.onrc.onos.core.util.FlowEntryId;
27import net.onrc.onos.core.util.FlowEntryMatch;
28import net.onrc.onos.core.util.FlowEntryUserState;
29import net.onrc.onos.core.util.FlowId;
30import net.onrc.onos.core.util.Port;
Naoki Shiota75b7dd62013-12-03 18:09:21 -080031
32import org.easymock.EasyMock;
33import org.easymock.IAnswer;
Naoki Shiota75b7dd62013-12-03 18:09:21 -080034import org.junit.Test;
35import org.openflow.protocol.OFBarrierRequest;
36import org.openflow.protocol.OFFlowMod;
37import org.openflow.protocol.OFMatch;
38import org.openflow.protocol.OFMessage;
39import org.openflow.protocol.OFType;
40import org.openflow.protocol.action.OFAction;
41import org.openflow.protocol.factory.BasicFactory;
42
43public class FlowPusherTest {
Ray Milkey269ffb92014-04-03 14:43:30 -070044 private FlowPusher pusher;
45 private FloodlightContext context;
46 private FloodlightModuleContext modContext;
47 private BasicFactory factory;
48 private OFMessageDamper damper;
49 private IFloodlightProviderService flProviderService;
50 private IThreadPoolService threadPoolService;
Naoki Shiota75b7dd62013-12-03 18:09:21 -080051
Ray Milkey269ffb92014-04-03 14:43:30 -070052 /**
53 * Test single OFMessage is correctly sent to single switch via MessageDamper.
54 */
55 @Test
56 public void testAddMessage() {
57 beginInitMock();
Naoki Shiota75b7dd62013-12-03 18:09:21 -080058
Ray Milkey269ffb92014-04-03 14:43:30 -070059 OFMessage msg = EasyMock.createMock(OFMessage.class);
60 EasyMock.expect(msg.getXid()).andReturn(1).anyTimes();
61 EasyMock.expect(msg.getLength()).andReturn((short) 100).anyTimes();
62 EasyMock.replay(msg);
Naoki Shiota75b7dd62013-12-03 18:09:21 -080063
Ray Milkey269ffb92014-04-03 14:43:30 -070064 IOFSwitch sw = EasyMock.createMock(IOFSwitch.class);
65 EasyMock.expect(sw.getId()).andReturn((long) 1).anyTimes();
66 sw.flush();
67 EasyMock.expectLastCall().once();
68 EasyMock.replay(sw);
Naoki Shiotad6ef3b32014-03-13 18:42:23 -070069
Ray Milkey269ffb92014-04-03 14:43:30 -070070 try {
71 EasyMock.expect(damper.write(EasyMock.eq(sw), EasyMock.eq(msg), EasyMock.eq(context)))
72 .andReturn(true).once();
73 } catch (IOException e1) {
74 fail("Failed in OFMessageDamper#write()");
75 }
Naoki Shiota75b7dd62013-12-03 18:09:21 -080076
Ray Milkey269ffb92014-04-03 14:43:30 -070077 endInitMock();
78 initPusher(1);
Naoki Shiotad6ef3b32014-03-13 18:42:23 -070079
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070080 boolean addResult = pusher.add(sw, msg);
81 assertTrue(addResult);
Naoki Shiota75b7dd62013-12-03 18:09:21 -080082
Ray Milkey269ffb92014-04-03 14:43:30 -070083 try {
84 // wait until message is processed.
85 Thread.sleep(1000);
86 } catch (InterruptedException e) {
87 fail("Failed in Thread.sleep()");
88 }
89 EasyMock.verify(msg);
90 EasyMock.verify(sw);
91 verifyAll();
Naoki Shiota75b7dd62013-12-03 18:09:21 -080092
Ray Milkey269ffb92014-04-03 14:43:30 -070093 pusher.stop();
94 }
Naoki Shiota75b7dd62013-12-03 18:09:21 -080095
Ray Milkey269ffb92014-04-03 14:43:30 -070096 /**
97 * Test bunch of OFMessages are correctly sent to single switch via MessageDamper.
98 */
99 @Test
100 public void testMassiveAddMessage() {
Yuta HIGUCHI7c39c842014-06-09 16:33:03 -0700101 // Some number larger than FlowPusher.MAX_MESSAGE_SEND
102 final int NUM_MSG = FlowPusher.MAX_MESSAGE_SEND * 2;
Naoki Shiotad6ef3b32014-03-13 18:42:23 -0700103
Ray Milkey269ffb92014-04-03 14:43:30 -0700104 beginInitMock();
Naoki Shiota75b7dd62013-12-03 18:09:21 -0800105
Ray Milkey269ffb92014-04-03 14:43:30 -0700106 IOFSwitch sw = EasyMock.createMock(IOFSwitch.class);
107 EasyMock.expect(sw.getId()).andReturn((long) 1).anyTimes();
108 sw.flush();
109 EasyMock.expectLastCall().atLeastOnce();
110 EasyMock.replay(sw);
Naoki Shiota75b7dd62013-12-03 18:09:21 -0800111
Ray Milkey269ffb92014-04-03 14:43:30 -0700112 List<OFMessage> messages = new ArrayList<OFMessage>();
Naoki Shiota75b7dd62013-12-03 18:09:21 -0800113
Ray Milkey269ffb92014-04-03 14:43:30 -0700114 for (int i = 0; i < NUM_MSG; ++i) {
115 OFMessage msg = EasyMock.createMock(OFMessage.class);
116 EasyMock.expect(msg.getXid()).andReturn(i).anyTimes();
117 EasyMock.expect(msg.getLength()).andReturn((short) 100).anyTimes();
118 EasyMock.replay(msg);
119 messages.add(msg);
Naoki Shiota75b7dd62013-12-03 18:09:21 -0800120
Ray Milkey269ffb92014-04-03 14:43:30 -0700121 try {
122 EasyMock.expect(damper.write(EasyMock.eq(sw), EasyMock.eq(msg), EasyMock.eq(context)))
123 .andReturn(true).once();
124 } catch (IOException e1) {
125 fail("Failed in OFMessageDamper#write()");
126 }
127 }
Naoki Shiotad6ef3b32014-03-13 18:42:23 -0700128
Ray Milkey269ffb92014-04-03 14:43:30 -0700129 endInitMock();
130 initPusher(1);
Naoki Shiota75b7dd62013-12-03 18:09:21 -0800131
Ray Milkey269ffb92014-04-03 14:43:30 -0700132 for (OFMessage msg : messages) {
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700133 boolean addResult = pusher.add(sw, msg);
134 assertTrue(addResult);
Ray Milkey269ffb92014-04-03 14:43:30 -0700135 }
Naoki Shiota75b7dd62013-12-03 18:09:21 -0800136
Ray Milkey269ffb92014-04-03 14:43:30 -0700137 try {
138 // wait until message is processed.
Yuta HIGUCHI7c39c842014-06-09 16:33:03 -0700139 Thread.sleep(1000);
Ray Milkey269ffb92014-04-03 14:43:30 -0700140 } catch (InterruptedException e) {
141 fail("Failed in Thread.sleep()");
142 }
Naoki Shiotad6ef3b32014-03-13 18:42:23 -0700143
Ray Milkey269ffb92014-04-03 14:43:30 -0700144 for (OFMessage msg : messages) {
145 EasyMock.verify(msg);
146 }
147 EasyMock.verify(sw);
148 verifyAll();
149
150 pusher.stop();
151 }
152
153 /**
154 * Test bunch of OFMessages are correctly sent to multiple switches with single threads.
155 */
156 @Test
157 public void testMultiSwitchAddMessage() {
158 final int NUM_SWITCH = 10;
159 final int NUM_MSG = 100; // messages per thread
160
161 beginInitMock();
162
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700163 Map<IOFSwitch, List<OFMessage>> swMap = new HashMap<IOFSwitch, List<OFMessage>>();
Ray Milkey269ffb92014-04-03 14:43:30 -0700164 for (int i = 0; i < NUM_SWITCH; ++i) {
165 IOFSwitch sw = EasyMock.createMock(IOFSwitch.class);
166 EasyMock.expect(sw.getId()).andReturn((long) i).anyTimes();
167 sw.flush();
168 EasyMock.expectLastCall().atLeastOnce();
169 EasyMock.replay(sw);
170
171 List<OFMessage> messages = new ArrayList<OFMessage>();
172
173 for (int j = 0; j < NUM_MSG; ++j) {
174 OFMessage msg = EasyMock.createMock(OFMessage.class);
175 EasyMock.expect(msg.getXid()).andReturn(j).anyTimes();
176 EasyMock.expect(msg.getLength()).andReturn((short) 100).anyTimes();
177 EasyMock.replay(msg);
178 messages.add(msg);
179
180 try {
181 EasyMock.expect(damper.write(EasyMock.eq(sw), EasyMock.eq(msg), EasyMock.eq(context)))
182 .andReturn(true).once();
183 } catch (IOException e1) {
184 fail("Failed in OFMessageDamper#write()");
185 }
186 }
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700187 swMap.put(sw, messages);
Ray Milkey269ffb92014-04-03 14:43:30 -0700188 }
189
190 endInitMock();
191 initPusher(1);
192
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700193 for (IOFSwitch sw : swMap.keySet()) {
194 for (OFMessage msg : swMap.get(sw)) {
195 boolean addResult = pusher.add(sw, msg);
196 assertTrue(addResult);
Ray Milkey269ffb92014-04-03 14:43:30 -0700197 }
198 }
199
200 try {
201 // wait until message is processed.
202 Thread.sleep(1000);
203 } catch (InterruptedException e) {
204 fail("Failed in Thread.sleep()");
205 }
206
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700207 for (IOFSwitch sw : swMap.keySet()) {
208 for (OFMessage msg : swMap.get(sw)) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700209 EasyMock.verify(msg);
210 }
211
212 EasyMock.verify(sw);
213 }
214 verifyAll();
215
216 pusher.stop();
217 }
218
219 /**
220 * Test bunch of OFMessages are correctly sent to multiple switches using multiple threads.
221 */
222 @Test
223 public void testMultiThreadedAddMessage() {
224 final int NUM_THREAD = 10;
225 final int NUM_MSG = 100; // messages per thread
226
227 beginInitMock();
228
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700229 Map<IOFSwitch, List<OFMessage>> swMap = new HashMap<IOFSwitch, List<OFMessage>>();
Ray Milkey269ffb92014-04-03 14:43:30 -0700230 for (int i = 0; i < NUM_THREAD; ++i) {
231 IOFSwitch sw = EasyMock.createMock(IOFSwitch.class);
232 EasyMock.expect(sw.getId()).andReturn((long) i).anyTimes();
233 sw.flush();
234 EasyMock.expectLastCall().atLeastOnce();
235 EasyMock.replay(sw);
236
237 List<OFMessage> messages = new ArrayList<OFMessage>();
238
239 for (int j = 0; j < NUM_MSG; ++j) {
240 OFMessage msg = EasyMock.createMock(OFMessage.class);
241 EasyMock.expect(msg.getXid()).andReturn(j).anyTimes();
242 EasyMock.expect(msg.getLength()).andReturn((short) 100).anyTimes();
243 EasyMock.replay(msg);
244 messages.add(msg);
245
246 try {
247 EasyMock.expect(damper.write(EasyMock.eq(sw), EasyMock.eq(msg), EasyMock.eq(context)))
248 .andReturn(true).once();
249 } catch (IOException e1) {
250 fail("Failed in OFMessageDamper#write()");
251 }
252 }
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700253 swMap.put(sw, messages);
Ray Milkey269ffb92014-04-03 14:43:30 -0700254 }
255
256 endInitMock();
257 initPusher(NUM_THREAD);
258
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700259 for (IOFSwitch sw : swMap.keySet()) {
260 for (OFMessage msg : swMap.get(sw)) {
261 boolean addResult = pusher.add(sw, msg);
262 assertTrue(addResult);
Ray Milkey269ffb92014-04-03 14:43:30 -0700263 }
264 }
265
266 try {
267 // wait until message is processed.
268 Thread.sleep(1000);
269 } catch (InterruptedException e) {
270 fail("Failed in Thread.sleep()");
271 }
272
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700273 for (IOFSwitch sw : swMap.keySet()) {
274 for (OFMessage msg : swMap.get(sw)) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700275 EasyMock.verify(msg);
276 }
277
278 EasyMock.verify(sw);
279 }
280 verifyAll();
281
282 pusher.stop();
283 }
284
285 private long barrierTime = 0;
286
287 /**
288 * Test rate limitation of messages works correctly.
289 */
290 @Test
291 public void testRateLimitedAddMessage() {
292 final long LIMIT_RATE = 100; // [bytes/ms]
293 final int NUM_MSG = 1000;
294
295 // Accuracy of FlowPusher's rate calculation can't be measured by unit test
296 // because switch doesn't return BARRIER_REPLY.
297 // In unit test we use approximate way to measure rate. This value is
298 // acceptable margin of measured rate.
299 final double ACCEPTABLE_RATE = LIMIT_RATE * 1.2;
300
301 beginInitMock();
302
303 IOFSwitch sw = EasyMock.createMock(IOFSwitch.class);
304 EasyMock.expect(sw.getId()).andReturn((long) 1).anyTimes();
305 sw.flush();
306 EasyMock.expectLastCall().atLeastOnce();
307 prepareBarrier(sw);
308 EasyMock.replay(sw);
309
310 List<OFMessage> messages = new ArrayList<OFMessage>();
311
312 for (int i = 0; i < NUM_MSG; ++i) {
313 OFMessage msg = EasyMock.createMock(OFMessage.class);
314 EasyMock.expect(msg.getXid()).andReturn(1).anyTimes();
315 EasyMock.expect(msg.getLength()).andReturn((short) 100).anyTimes();
316 EasyMock.expect(msg.getLengthU()).andReturn(100).anyTimes();
317 EasyMock.replay(msg);
318 messages.add(msg);
319
320 try {
321 EasyMock.expect(damper.write(EasyMock.eq(sw), EasyMock.eq(msg), EasyMock.eq(context)))
322 .andReturn(true).once();
323 } catch (IOException e) {
324 fail("Failed in OFMessageDamper#write()");
325 }
326 }
327
328 try {
329 EasyMock.expect(damper.write(EasyMock.eq(sw), (OFMessage) EasyMock.anyObject(), EasyMock.eq(context)))
330 .andAnswer(new IAnswer<Boolean>() {
331 @Override
332 public Boolean answer() throws Throwable {
333 OFMessage msg = (OFMessage) EasyMock.getCurrentArguments()[1];
334 if (msg.getType() == OFType.BARRIER_REQUEST) {
335 barrierTime = System.currentTimeMillis();
336 }
337 return true;
338 }
339 }).once();
340 } catch (IOException e1) {
341 fail("Failed in OFMessageDamper#write()");
342 }
343
344 endInitMock();
345 initPusher(1);
346
347 pusher.createQueue(sw);
348 pusher.setRate(sw, LIMIT_RATE);
349
350 long beginTime = System.currentTimeMillis();
351 for (OFMessage msg : messages) {
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700352 boolean addResult = pusher.add(sw, msg);
353 assertTrue(addResult);
Ray Milkey269ffb92014-04-03 14:43:30 -0700354 }
355
356 pusher.barrierAsync(sw);
357
358 try {
359 do {
360 Thread.sleep(1000);
361 } while (barrierTime == 0);
362 } catch (InterruptedException e) {
363 fail("Failed to sleep");
364 }
365
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700366 double measuredRate = NUM_MSG * 100 / (barrierTime - beginTime);
367 assertTrue(measuredRate < ACCEPTABLE_RATE);
Ray Milkey269ffb92014-04-03 14:43:30 -0700368
369 for (OFMessage msg : messages) {
370 EasyMock.verify(msg);
371 }
372 EasyMock.verify(sw);
373 verifyAll();
374
375 pusher.stop();
376 }
377
378 /**
379 * Test barrier message is correctly sent to a switch.
380 */
381 @Test
382 public void testBarrierMessage() {
383 beginInitMock();
384
385 IOFSwitch sw = EasyMock.createMock(IOFSwitch.class);
386 EasyMock.expect(sw.getId()).andReturn((long) 1).anyTimes();
387 sw.flush();
388 EasyMock.expectLastCall().atLeastOnce();
389 prepareBarrier(sw);
390 EasyMock.replay(sw);
391
392 try {
393 EasyMock.expect(damper.write(EasyMock.eq(sw), (OFMessage) EasyMock.anyObject(), EasyMock.eq(context)))
394 .andReturn(true).once();
395 } catch (IOException e1) {
396 fail("Failed in OFMessageDamper#write()");
397 }
398
399 endInitMock();
400 initPusher(1);
401
402 OFBarrierReplyFuture future = pusher.barrierAsync(sw);
403
404 assertNotNull(future);
405
406 try {
407 Thread.sleep(1000);
408 } catch (InterruptedException e) {
409 fail("Failed to sleep");
410 }
411
412 verifyAll();
413
414 pusher.stop();
415 }
416
417 static final int XID_TO_VERIFY = 100;
418 static final long DPID_TO_VERIFY = 10;
419
420 /**
421 * Test FlowObject is correctly converted to message and is sent to a switch.
422 */
423 @SuppressWarnings("unchecked")
424 @Test
425 public void testAddFlow() {
426 // instantiate required objects
427 FlowEntry flowEntry1 = new FlowEntry();
428 flowEntry1.setDpid(new Dpid(DPID_TO_VERIFY));
429 flowEntry1.setFlowId(new FlowId(1));
430 flowEntry1.setInPort(new Port((short) 1));
431 flowEntry1.setOutPort(new Port((short) 11));
432 flowEntry1.setFlowEntryId(new FlowEntryId(1));
433 flowEntry1.setFlowEntryMatch(new FlowEntryMatch());
434 flowEntry1.setFlowEntryActions(new FlowEntryActions());
435 flowEntry1.setFlowEntryErrorState(new FlowEntryErrorState());
436 flowEntry1.setFlowEntryUserState(FlowEntryUserState.FE_USER_ADD);
437
438 beginInitMock();
439
440 OFFlowMod msg = EasyMock.createMock(OFFlowMod.class);
441 EasyMock.expect(msg.setIdleTimeout(EasyMock.anyShort())).andReturn(msg);
442 EasyMock.expect(msg.setHardTimeout(EasyMock.anyShort())).andReturn(msg);
443 EasyMock.expect(msg.setPriority(EasyMock.anyShort())).andReturn(msg);
444 EasyMock.expect(msg.setBufferId(EasyMock.anyInt())).andReturn(msg);
445 EasyMock.expect(msg.setCookie(EasyMock.anyLong())).andReturn(msg);
446 EasyMock.expect(msg.setCommand(EasyMock.anyShort())).andReturn(msg);
447 EasyMock.expect(msg.setMatch(EasyMock.anyObject(OFMatch.class))).andReturn(msg);
448 EasyMock.expect(msg.setActions((List<OFAction>) EasyMock.anyObject())).andReturn(msg);
449 EasyMock.expect(msg.setLengthU(EasyMock.anyShort())).andReturn(msg);
450 EasyMock.expect(msg.setOutPort(EasyMock.anyShort())).andReturn(msg).atLeastOnce();
451 EasyMock.expect(msg.getXid()).andReturn(XID_TO_VERIFY).anyTimes();
452 EasyMock.expect(msg.getType()).andReturn(OFType.FLOW_MOD).anyTimes();
453 EasyMock.expect(msg.getLength()).andReturn((short) 100).anyTimes();
454 EasyMock.replay(msg);
455
456 EasyMock.expect(factory.getMessage(EasyMock.eq(OFType.FLOW_MOD))).andReturn(msg);
457
458 IOFSwitch sw = EasyMock.createMock(IOFSwitch.class);
459 EasyMock.expect(sw.getId()).andReturn(DPID_TO_VERIFY).anyTimes();
460 EasyMock.expect(sw.getStringId()).andReturn("1").anyTimes();
461 sw.flush();
462 EasyMock.expectLastCall().once();
463
464 try {
465 EasyMock.expect(damper.write(EasyMock.eq(sw), EasyMock.anyObject(OFMessage.class), EasyMock.eq(context)))
466 .andAnswer(new IAnswer<Boolean>() {
467 @Override
468 public Boolean answer() throws Throwable {
469 OFMessage msg = (OFMessage) EasyMock.getCurrentArguments()[1];
470 if (msg.getType() == OFType.FLOW_MOD) {
471 assertEquals(msg.getXid(), XID_TO_VERIFY);
472 }
473 return true;
474 }
475 }).atLeastOnce();
476 } catch (IOException e1) {
477 fail("Failed in OFMessageDamper#write()");
478 }
479
480 EasyMock.replay(sw);
481
482 endInitMock();
483 initPusher(1);
484
485 pusher.pushFlowEntry(sw, flowEntry1);
486
487 try {
488 Thread.sleep(1000);
489 } catch (InterruptedException e) {
490 fail("Failed to sleep");
491 }
492
493 EasyMock.verify(sw);
494 verifyAll();
495
496 pusher.stop();
497 }
498
499 private void beginInitMock() {
500 context = EasyMock.createMock(FloodlightContext.class);
501 modContext = EasyMock.createMock(FloodlightModuleContext.class);
502 factory = EasyMock.createMock(BasicFactory.class);
503 damper = EasyMock.createMock(OFMessageDamper.class);
504 flProviderService = EasyMock.createMock(IFloodlightProviderService.class);
505 threadPoolService = EasyMock.createMock(IThreadPoolService.class);
506
507 EasyMock.expect(modContext.getServiceImpl(EasyMock.eq(IThreadPoolService.class)))
508 .andReturn(threadPoolService).once();
509 EasyMock.expect(modContext.getServiceImpl(EasyMock.eq(IFloodlightProviderService.class)))
510 .andReturn(flProviderService).once();
511 flProviderService.addOFMessageListener(EasyMock.eq(OFType.BARRIER_REPLY),
512 (FlowPusher) EasyMock.anyObject());
513 EasyMock.expectLastCall().once();
514
515 ScheduledExecutorService executor = EasyMock.createMock(ScheduledExecutorService.class);
516 EasyMock.expect(executor.schedule((Runnable) EasyMock.anyObject(), EasyMock.anyLong(),
517 (TimeUnit) EasyMock.anyObject())).andReturn(null).once();
518 EasyMock.replay(executor);
519 EasyMock.expect(threadPoolService.getScheduledExecutor()).andReturn(executor).anyTimes();
520 }
521
522 private void endInitMock() {
523 EasyMock.replay(threadPoolService);
524 EasyMock.replay(flProviderService);
525 EasyMock.replay(damper);
526 EasyMock.replay(factory);
527 EasyMock.replay(modContext);
528 EasyMock.replay(context);
529 }
530
531 private void verifyAll() {
532 EasyMock.verify(threadPoolService);
533 EasyMock.verify(flProviderService);
534 EasyMock.verify(damper);
535 EasyMock.verify(factory);
536 EasyMock.verify(modContext);
537 EasyMock.verify(context);
538 }
539
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700540 private void initPusher(int numThread) {
541 pusher = new FlowPusher(numThread);
Ray Milkey269ffb92014-04-03 14:43:30 -0700542 pusher.init(context, modContext, factory, damper);
543 pusher.start();
544 }
545
546 private void prepareBarrier(IOFSwitch sw) {
547 OFBarrierRequest req = EasyMock.createMock(OFBarrierRequest.class);
548 req.setXid(EasyMock.anyInt());
549 EasyMock.expectLastCall().once();
550 EasyMock.expect(req.getXid()).andReturn(1).anyTimes();
551 EasyMock.expect(req.getType()).andReturn(OFType.BARRIER_REQUEST).anyTimes();
552 EasyMock.expect(req.getLength()).andReturn((short) 100).anyTimes();
553 EasyMock.replay(req);
554 EasyMock.expect(factory.getMessage(EasyMock.eq(OFType.BARRIER_REQUEST))).andReturn(req).anyTimes();
555 EasyMock.expect(sw.getNextTransactionId()).andReturn(1);
556 }
557
Naoki Shiota75b7dd62013-12-03 18:09:21 -0800558}