blob: 515a6311bfb73dd69af2dde69676cb4286b6c179 [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;
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() );
HIGUCHI Yuta744ea0c2013-08-06 07:34:17 +090059 assertEquals("default null", null, def.ipProto() );
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +090060 assertEquals("default null", null, def.ipToS() );
61 assertEquals("default null", null, def.srcTcpUdpPort() );
62 assertEquals("default null", null, def.dstTcpUdpPort() );
63 }
64
65 @Test
66 public void testFlowEntryMatchFlowEntryMatch(){
67 FlowEntryMatch def_base = new FlowEntryMatch();
68 FlowEntryMatch def = new FlowEntryMatch(def_base);
69
70 assertEquals("default null", null, def.inPort() );
71 assertEquals("default null", null, def.srcMac() );
72 assertEquals("default null", null, def.dstMac() );
73 assertEquals("default null", null, def.ethernetFrameType() );
74 assertEquals("default null", null, def.vlanId() );
75 assertEquals("default null", null, def.vlanPriority() );
76 assertEquals("default null", null, def.srcIPv4Net() );
77 assertEquals("default null", null, def.dstIPv4Net() );
78 assertEquals("default null", null, def.ipProto() );
79 assertEquals("default null", null, def.ipToS() );
80 assertEquals("default null", null, def.srcTcpUdpPort() );
81 assertEquals("default null", null, def.dstTcpUdpPort() );
82
83 FlowEntryMatch copy = new FlowEntryMatch( match );
84
85 assertEquals("inport", inport, copy.inPort() );
86 assertEquals("mac1", mac1, copy.srcMac() );
87 assertEquals("mac2", mac2, copy.dstMac() );
88 assertEquals("ether", ether, copy.ethernetFrameType() );
89 assertEquals("vlan id", vlanid, copy.vlanId() );
90 assertEquals("vlan prio", vlanprio, copy.vlanPriority() );
91 assertEquals("ip1", ip1, copy.srcIPv4Net() );
92 assertEquals("ip2", ip2, copy.dstIPv4Net() );
93 assertEquals("ip proto", ipproto, copy.ipProto() );
94 assertEquals("tos", ipToS, copy.ipToS() );
95 assertEquals("src port", tport1, copy.srcTcpUdpPort() );
96 assertEquals("dst port", tport2, copy.dstTcpUdpPort() );
97
98 }
99
100 @Test
101 public void testInPort(){
102 assertEquals("inport", inport, match.inPort() );
103 }
104
105 @Test
106 public void testDisableInPort(){
107 match.disableInPort();
108 assertEquals("inport", null, match.inPort() );
109 assertFalse( match.matchInPort() );
110 }
111
112 @Test
113 public void testMatchInPort(){
114 assertTrue( match.matchInPort() );
115 }
116
117 @Test
118 public void testSrcMac(){
119 assertEquals("mac1", mac1, match.srcMac() );
120 }
121
122 @Test
123 public void testDisableSrcMac(){
124 match.disableSrcMac();
125 assertEquals("srcMac", null, match.srcMac() );
126 assertFalse( match.matchSrcMac() );
127 }
128
129 @Test
130 public void testMatchSrcMac(){
131 assertTrue( match.matchSrcMac() );
132 }
133
134 @Test
135 public void testDstMac(){
136 assertEquals("mac2", mac2, match.dstMac() );
137 }
138
139 @Test
140 public void testDisableDstMac(){
141 match.disableDstMac();
142 assertEquals("dstMac", null, match.dstMac() );
143 assertFalse( match.matchDstMac() );
144 }
145
146 @Test
147 public void testMatchDstMac(){
148 assertTrue( match.matchDstMac() );
149 }
150
151 @Test
152 public void testEthernetFrameType(){
153 assertEquals("ether", ether, match.ethernetFrameType() );
154 }
155
156 @Test
157 public void testDisableEthernetFrameType(){
158 match.disableEthernetFrameType();
159 assertEquals("ethernetFrameType", null, match.ethernetFrameType() );
160 assertFalse( match.matchEthernetFrameType() );
161 }
162
163 @Test
164 public void testMatchEthernetFrameType(){
165 assertTrue( match.matchEthernetFrameType() );
166 }
167
168 @Test
169 public void testVlanId(){
170 assertEquals("vlan id", vlanid, match.vlanId() );
171 }
172
173 @Test
174 public void testDisableVlanId(){
175 match.disableVlanId();
176 assertEquals("vlanId", null, match.vlanId() );
177 assertFalse( match.matchVlanId() );
178 }
179
180 @Test
181 public void testMatchVlanId(){
182 assertTrue( match.matchVlanId() );
183 }
184
185 @Test
186 public void testVlanPriority(){
187 assertEquals("vlan prio", vlanprio, match.vlanPriority() );
188 }
189
190 @Test
191 public void testDisableVlanPriority(){
192 match.disableVlanPriority();
193 assertEquals("vlanPriority", null, match.vlanPriority() );
194 assertFalse( match.matchVlanPriority() );
195 }
196
197 @Test
198 public void testMatchVlanPriority(){
199 assertTrue( match.matchVlanPriority() );
200 }
201
202 @Test
203 public void testSrcIPv4Net(){
204 assertEquals("ip1", ip1, match.srcIPv4Net() );
205 }
206
207 @Test
208 public void testDisableSrcIPv4Net(){
209 match.disableSrcIPv4Net();
210 assertEquals("srcIPv4Net", null, match.srcIPv4Net() );
211 assertFalse( match.matchSrcIPv4Net() );
212 }
213
214 @Test
215 public void testMatchSrcIPv4Net(){
216 assertTrue( match.matchSrcIPv4Net() );
217 }
218
219 @Test
220 public void testDstIPv4Net(){
221 assertEquals("ip2", ip2, match.dstIPv4Net() );
222 }
223
224 @Test
225 public void testDisableDstIPv4Net(){
226 match.disableDstIPv4Net();
227 assertEquals("dstIPv4Net", null, match.dstIPv4Net() );
228 assertFalse( match.matchDstIPv4Net() );
229 }
230
231 @Test
232 public void testMatchDstIPv4Net(){
233 assertTrue( match.matchDstIPv4Net() );
234 }
235
236 @Test
237 public void testIpProto(){
238 assertEquals("ip proto", ipproto, match.ipProto() );
239 }
240
241 @Test
242 public void testDisableIpProto(){
243 match.disableIpProto();
244 assertEquals("ipProto", null, match.ipProto() );
245 assertFalse( match.matchIpProto() );
246 }
247
248 @Test
249 public void testMatchIpProto(){
250 assertTrue( match.matchIpProto() );
251 }
252
253 @Test
254 public void testIpToS(){
255 assertEquals("tos", ipToS, match.ipToS() );
256 }
257
258 @Test
259 public void testDisableIpToS(){
260 match.disableIpToS();
261 assertEquals("ipToS", null, match.ipToS() );
262 assertFalse( match.matchIpToS() );
263 }
264
265 @Test
266 public void testMatchIpToS(){
267 assertTrue( match.matchIpToS() );
268 }
269
270 @Test
271 public void testSrcTcpUdpPort(){
272 assertEquals("src port", tport1, match.srcTcpUdpPort() );
273 }
274
275 @Test
276 public void testDisableSrcTcpUdpPort(){
277 match.disableSrcTcpUdpPort();
278 assertEquals("srcTcpUdpPort", null, match.srcTcpUdpPort() );
279 assertFalse( match.matchSrcTcpUdpPort() );
280 }
281
282 @Test
283 public void testMatchSrcTcpUdpPort(){
284 assertTrue( match.matchSrcTcpUdpPort() );
285 }
286
287 @Test
288 public void testDstTcpUdpPort(){
289 assertEquals("dst port", tport2, match.dstTcpUdpPort() );
290 }
291
292 @Test
293 public void testDisableDstTcpUdpPort(){
294 match.disableDstTcpUdpPort();
295 assertEquals("dstTcpUdpPort", null, match.dstTcpUdpPort() );
296 assertFalse( match.matchDstTcpUdpPort() );
297 }
298
299 @Test
300 public void testMatchDstTcpUdpPort(){
301 assertTrue( match.matchDstTcpUdpPort() );
302 }
303
304 @Test
305 public void testToString(){
306 FlowEntryMatch def = new FlowEntryMatch();
307 assertEquals("match default", def.toString(), "[]");
308
309 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]");
310 }
311
312}