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