blob: 97c850975c9403067439475ee268b862c2416c3d [file] [log] [blame]
Brian O'Connorc67f9fa2014-08-07 18:17:46 -07001package net.floodlightcontroller.util;
2
3import static org.junit.Assert.assertEquals;
4
5import java.io.IOException;
6import java.util.EnumSet;
7
8import net.floodlightcontroller.core.FloodlightContext;
9
10import org.junit.Before;
11import org.junit.Test;
12import org.projectfloodlight.openflow.protocol.OFFactories;
13import org.projectfloodlight.openflow.protocol.OFFactory;
14import org.projectfloodlight.openflow.protocol.OFType;
15import org.projectfloodlight.openflow.protocol.OFEchoRequest;
16import org.projectfloodlight.openflow.protocol.OFHello;
17import org.projectfloodlight.openflow.protocol.OFMessage;
18import org.projectfloodlight.openflow.protocol.OFVersion;
19
20public class OFMessageDamperTest10 {
21
22 /*
23 OFFactory factory10 = OFFactories.getFactory(OFVersion.OF_10);
24 OFMessageDamper damper;
25 FloodlightContext cntx;
26
27 OFMessageDamperMockSwitch sw1;
28 OFMessageDamperMockSwitch sw2;
29
30 OFEchoRequest echoRequst1;
31 OFEchoRequest echoRequst1Clone;
32 OFEchoRequest echoRequst2;
33 OFHello hello1;
34 OFHello hello2;
35
36 @Before
37 public void setUp() throws IOException {
38 cntx = new FloodlightContext();
39
40 sw1 = new OFMessageDamperMockSwitch();
41 sw2 = new OFMessageDamperMockSwitch();
42
43 echoRequst1 = factory10.buildEchoRequest()
44 .setData(new byte[] {1}).build();
45 echoRequst1Clone = factory10.buildEchoRequest()
46 .setData(new byte[] {1}).build();
47 echoRequst2 = factory10.buildEchoRequest()
48 .setData(new byte[] {2}).build();
49
50 hello1 = factory10.buildHello()
51 .setXid(1).build();
52 hello2 = factory10.buildHello()
53 .setXid(2).build();
54
55 }
56
57 protected void doWrite(boolean expectWrite,
58 OFMessageDamperMockSwitch sw,
59 OFMessage msg,
60 FloodlightContext cntx) throws IOException {
61
62 boolean result;
63 sw.reset();
64 result = damper.write(sw, msg, cntx);
65
66 if (expectWrite) {
67 assertEquals(true, result);
68 sw.assertMessageWasWritten(msg, cntx);
69 } else {
70 assertEquals(false, result);
71 sw.assertNoMessageWritten();
72 }
73 }
74
75 @Test
76 public void testOneMessageType() throws IOException, InterruptedException {
77 int timeout = 50;
78 int sleepTime = 60;
79 damper = new OFMe ssageDamper(100,
80 EnumSet.of(OFType.ECHO_REQUEST),
81 timeout);
82
83 // echo requests should be dampened
84 doWrite(true, sw1, echoRequst1, cntx);
85 doWrite(false, sw1, echoRequst1, cntx);
86 doWrite(false, sw1, echoRequst1Clone, cntx);
87 doWrite(true, sw1, echoRequst2, cntx);
88 doWrite(false, sw1, echoRequst2, cntx);
89
90 // we don't dampen hellos. All should succeed
91 doWrite(true, sw1, hello1, cntx);
92 doWrite(true, sw1, hello1, cntx);
93 doWrite(true, sw1, hello1, cntx);
94
95 // echo request should also be dampened on sw2
96 doWrite(true, sw2, echoRequst1, cntx);
97 doWrite(false, sw2, echoRequst1, cntx);
98 doWrite(true, sw2, echoRequst2, cntx);
99
100 Thread.sleep(sleepTime);
101 doWrite(true, sw1, echoRequst1, cntx);
102 doWrite(true, sw2, echoRequst1, cntx);
103
104 }
105
106 @Test
107 public void testTwoMessageTypes() throws IOException, InterruptedException {
108 int timeout = 50;
109 int sleepTime = 60;
110 damper = new OFMessageDamper(100,
111 EnumSet.of(OFType.ECHO_REQUEST,
112 OFType.HELLO),
113 timeout);
114
115 // echo requests should be dampened
116 doWrite(true, sw1, echoRequst1, cntx);
117 doWrite(false, sw1, echoRequst1, cntx);
118 doWrite(false, sw1, echoRequst1Clone, cntx);
119 doWrite(true, sw1, echoRequst2, cntx);
120 doWrite(false, sw1, echoRequst2, cntx);
121
122 // hello should be dampened as well
123 doWrite(true, sw1, hello1, cntx);
124 doWrite(false, sw1, hello1, cntx);
125 doWrite(false, sw1, hello1, cntx);
126
127 doWrite(true, sw1, hello2, cntx);
128 doWrite(false, sw1, hello2, cntx);
129 doWrite(false, sw1, hello2, cntx);
130
131 // echo request should also be dampened on sw2
132 doWrite(true, sw2, echoRequst1, cntx);
133 doWrite(false, sw2, echoRequst1, cntx);
134 doWrite(true, sw2, echoRequst2, cntx);
135
136 Thread.sleep(sleepTime);
137 doWrite(true, sw1, echoRequst1, cntx);
138 doWrite(true, sw2, echoRequst1, cntx);
139 doWrite(true, sw1, hello1, cntx);
140 doWrite(true, sw1, hello2, cntx);
141 }
142 */
143}