blob: 6ad8bc45b38712e3b75e3c12689f6722e3ae9e2a [file] [log] [blame]
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +09001package net.onrc.onos.ofcontroller.util;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertFalse;
5import static org.junit.Assert.assertTrue;
6import net.floodlightcontroller.util.MACAddress;
7
8import org.junit.Before;
9import org.junit.Test;
10
11public class FlowEntryMatchTest {
12
13 FlowEntryMatch match;
14
15 Port inport = new Port((short)1);
16 byte[] byte1 = { 1, 2, 3, 4, 5, 6 };
17 byte[] byte2 = { 6, 5, 4, 3, 2, 1 };
18 MACAddress mac1 = new MACAddress(byte1);
19 MACAddress mac2 = new MACAddress(byte2);
20 Short ether = Short.valueOf((short)2);
21 Short vlanid = Short.valueOf((short)3);
22 Byte vlanprio = Byte.valueOf((byte)4);
23 IPv4Net ip1 = new IPv4Net("127.0.0.1/32");
24 IPv4Net ip2 = new IPv4Net("127.0.0.2/32");
25 Byte ipproto = Byte.valueOf((byte)5);
26 Byte ipToS = Byte.valueOf((byte)6);
27 Short tport1 = Short.valueOf((short)7);
28 Short tport2 = Short.valueOf((short)8);
29
30 @Before
31 public void setUp() throws Exception{
32 match = new FlowEntryMatch();
33 match.enableInPort( inport);
34 match.enableSrcMac( mac1 );
35 match.enableDstMac( mac2 );
36 match.enableEthernetFrameType( ether );
37 match.enableVlanId( vlanid );
38 match.enableVlanPriority( vlanprio );
39 match.enableSrcIPv4Net( ip1 );
40 match.enableDstIPv4Net( ip2 );
41 match.enableIpProto( ipproto );
42 match.enableIpToS( ipToS );
43 match.enableSrcTcpUdpPort( tport1 );
44 match.enableDstTcpUdpPort( tport2 );
45 }
46
47 @Test
48 public void testFlowEntryMatch(){
49 FlowEntryMatch def = new FlowEntryMatch();
50
51 assertEquals("default null", null, def.inPort() );
52 assertEquals("default null", null, def.srcMac() );
53 assertEquals("default null", null, def.dstMac() );
54 assertEquals("default null", null, def.ethernetFrameType() );
55 assertEquals("default null", null, def.vlanId() );
56 assertEquals("default null", null, def.vlanPriority() );
57 assertEquals("default null", null, def.srcIPv4Net() );
58 assertEquals("default null", null, def.dstIPv4Net() );
59 assertEquals("default null", null, def.ipToS() );
60 assertEquals("default null", null, def.srcTcpUdpPort() );
61 assertEquals("default null", null, def.dstTcpUdpPort() );
62 }
63
64 @Test
65 public void testFlowEntryMatchFlowEntryMatch(){
66 FlowEntryMatch def_base = new FlowEntryMatch();
67 FlowEntryMatch def = new FlowEntryMatch(def_base);
68
69 assertEquals("default null", null, def.inPort() );
70 assertEquals("default null", null, def.srcMac() );
71 assertEquals("default null", null, def.dstMac() );
72 assertEquals("default null", null, def.ethernetFrameType() );
73 assertEquals("default null", null, def.vlanId() );
74 assertEquals("default null", null, def.vlanPriority() );
75 assertEquals("default null", null, def.srcIPv4Net() );
76 assertEquals("default null", null, def.dstIPv4Net() );
77 assertEquals("default null", null, def.ipProto() );
78 assertEquals("default null", null, def.ipToS() );
79 assertEquals("default null", null, def.srcTcpUdpPort() );
80 assertEquals("default null", null, def.dstTcpUdpPort() );
81
82 FlowEntryMatch copy = new FlowEntryMatch( match );
83
84 assertEquals("inport", inport, copy.inPort() );
85 assertEquals("mac1", mac1, copy.srcMac() );
86 assertEquals("mac2", mac2, copy.dstMac() );
87 assertEquals("ether", ether, copy.ethernetFrameType() );
88 assertEquals("vlan id", vlanid, copy.vlanId() );
89 assertEquals("vlan prio", vlanprio, copy.vlanPriority() );
90 assertEquals("ip1", ip1, copy.srcIPv4Net() );
91 assertEquals("ip2", ip2, copy.dstIPv4Net() );
92 assertEquals("ip proto", ipproto, copy.ipProto() );
93 assertEquals("tos", ipToS, copy.ipToS() );
94 assertEquals("src port", tport1, copy.srcTcpUdpPort() );
95 assertEquals("dst port", tport2, copy.dstTcpUdpPort() );
96
97 }
98
99 @Test
100 public void testInPort(){
101 assertEquals("inport", inport, match.inPort() );
102 }
103
104 @Test
105 public void testDisableInPort(){
106 match.disableInPort();
107 assertEquals("inport", null, match.inPort() );
108 assertFalse( match.matchInPort() );
109 }
110
111 @Test
112 public void testMatchInPort(){
113 assertTrue( match.matchInPort() );
114 }
115
116 @Test
117 public void testSrcMac(){
118 assertEquals("mac1", mac1, match.srcMac() );
119 }
120
121 @Test
122 public void testDisableSrcMac(){
123 match.disableSrcMac();
124 assertEquals("srcMac", null, match.srcMac() );
125 assertFalse( match.matchSrcMac() );
126 }
127
128 @Test
129 public void testMatchSrcMac(){
130 assertTrue( match.matchSrcMac() );
131 }
132
133 @Test
134 public void testDstMac(){
135 assertEquals("mac2", mac2, match.dstMac() );
136 }
137
138 @Test
139 public void testDisableDstMac(){
140 match.disableDstMac();
141 assertEquals("dstMac", null, match.dstMac() );
142 assertFalse( match.matchDstMac() );
143 }
144
145 @Test
146 public void testMatchDstMac(){
147 assertTrue( match.matchDstMac() );
148 }
149
150 @Test
151 public void testEthernetFrameType(){
152 assertEquals("ether", ether, match.ethernetFrameType() );
153 }
154
155 @Test
156 public void testDisableEthernetFrameType(){
157 match.disableEthernetFrameType();
158 assertEquals("ethernetFrameType", null, match.ethernetFrameType() );
159 assertFalse( match.matchEthernetFrameType() );
160 }
161
162 @Test
163 public void testMatchEthernetFrameType(){
164 assertTrue( match.matchEthernetFrameType() );
165 }
166
167 @Test
168 public void testVlanId(){
169 assertEquals("vlan id", vlanid, match.vlanId() );
170 }
171
172 @Test
173 public void testDisableVlanId(){
174 match.disableVlanId();
175 assertEquals("vlanId", null, match.vlanId() );
176 assertFalse( match.matchVlanId() );
177 }
178
179 @Test
180 public void testMatchVlanId(){
181 assertTrue( match.matchVlanId() );
182 }
183
184 @Test
185 public void testVlanPriority(){
186 assertEquals("vlan prio", vlanprio, match.vlanPriority() );
187 }
188
189 @Test
190 public void testDisableVlanPriority(){
191 match.disableVlanPriority();
192 assertEquals("vlanPriority", null, match.vlanPriority() );
193 assertFalse( match.matchVlanPriority() );
194 }
195
196 @Test
197 public void testMatchVlanPriority(){
198 assertTrue( match.matchVlanPriority() );
199 }
200
201 @Test
202 public void testSrcIPv4Net(){
203 assertEquals("ip1", ip1, match.srcIPv4Net() );
204 }
205
206 @Test
207 public void testDisableSrcIPv4Net(){
208 match.disableSrcIPv4Net();
209 assertEquals("srcIPv4Net", null, match.srcIPv4Net() );
210 assertFalse( match.matchSrcIPv4Net() );
211 }
212
213 @Test
214 public void testMatchSrcIPv4Net(){
215 assertTrue( match.matchSrcIPv4Net() );
216 }
217
218 @Test
219 public void testDstIPv4Net(){
220 assertEquals("ip2", ip2, match.dstIPv4Net() );
221 }
222
223 @Test
224 public void testDisableDstIPv4Net(){
225 match.disableDstIPv4Net();
226 assertEquals("dstIPv4Net", null, match.dstIPv4Net() );
227 assertFalse( match.matchDstIPv4Net() );
228 }
229
230 @Test
231 public void testMatchDstIPv4Net(){
232 assertTrue( match.matchDstIPv4Net() );
233 }
234
235 @Test
236 public void testIpProto(){
237 assertEquals("ip proto", ipproto, match.ipProto() );
238 }
239
240 @Test
241 public void testDisableIpProto(){
242 match.disableIpProto();
243 assertEquals("ipProto", null, match.ipProto() );
244 assertFalse( match.matchIpProto() );
245 }
246
247 @Test
248 public void testMatchIpProto(){
249 assertTrue( match.matchIpProto() );
250 }
251
252 @Test
253 public void testIpToS(){
254 assertEquals("tos", ipToS, match.ipToS() );
255 }
256
257 @Test
258 public void testDisableIpToS(){
259 match.disableIpToS();
260 assertEquals("ipToS", null, match.ipToS() );
261 assertFalse( match.matchIpToS() );
262 }
263
264 @Test
265 public void testMatchIpToS(){
266 assertTrue( match.matchIpToS() );
267 }
268
269 @Test
270 public void testSrcTcpUdpPort(){
271 assertEquals("src port", tport1, match.srcTcpUdpPort() );
272 }
273
274 @Test
275 public void testDisableSrcTcpUdpPort(){
276 match.disableSrcTcpUdpPort();
277 assertEquals("srcTcpUdpPort", null, match.srcTcpUdpPort() );
278 assertFalse( match.matchSrcTcpUdpPort() );
279 }
280
281 @Test
282 public void testMatchSrcTcpUdpPort(){
283 assertTrue( match.matchSrcTcpUdpPort() );
284 }
285
286 @Test
287 public void testDstTcpUdpPort(){
288 assertEquals("dst port", tport2, match.dstTcpUdpPort() );
289 }
290
291 @Test
292 public void testDisableDstTcpUdpPort(){
293 match.disableDstTcpUdpPort();
294 assertEquals("dstTcpUdpPort", null, match.dstTcpUdpPort() );
295 assertFalse( match.matchDstTcpUdpPort() );
296 }
297
298 @Test
299 public void testMatchDstTcpUdpPort(){
300 assertTrue( match.matchDstTcpUdpPort() );
301 }
302
303 @Test
304 public void testToString(){
305 FlowEntryMatch def = new FlowEntryMatch();
306 assertEquals("match default", def.toString(), "[]");
307
308 assertEquals("match set", match.toString(), "[inPort=1 srcMac=01:02:03:04:05:06 dstMac=06:05:04:03:02:01 ethernetFrameType=2 vlanId=3 vlanPriority=4 srcIPv4Net=127.0.0.1/32 dstIPv4Net=127.0.0.2/32 ipProto=5 ipToS=6 srcTcpUdpPort=7 dstTcpUdpPort=8]");
309 }
310
311}