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