ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 1 | """These tests fall under Conformance Test-Suite (OF-SWITCH-1.0.0 TestCases). |
| 2 | Refer Documentation -- Detailed testing methodology |
| 3 | <Some of test-cases are directly taken from oftest> """ |
| 4 | |
| 5 | "Test Suite 6 --> Flow Matches" |
| 6 | |
| 7 | |
| 8 | import logging |
| 9 | |
| 10 | import unittest |
| 11 | import random |
| 12 | |
| 13 | import oftest.controller as controller |
| 14 | import oftest.cstruct as ofp |
| 15 | import oftest.message as message |
| 16 | import oftest.dataplane as dataplane |
| 17 | import oftest.action as action |
| 18 | import oftest.parse as parse |
| 19 | import oftest.base_tests as base_tests |
| 20 | import time |
| 21 | |
| 22 | from oftest.testutils import * |
| 23 | from time import sleep |
| 24 | from FuncUtils import * |
| 25 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 26 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 27 | |
| 28 | class AllWildcardMatch(base_tests.SimpleDataPlane): |
| 29 | |
| 30 | """Verify for an all wildcarded flow all the injected packets would match that flow""" |
| 31 | |
| 32 | def runTest(self): |
| 33 | |
| 34 | logging.info("Running All Wildcard Match test") |
| 35 | |
| 36 | of_ports = config["port_map"].keys() |
| 37 | of_ports.sort() |
| 38 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 39 | |
| 40 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 41 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 42 | |
| 43 | logging.info("Inserting an all wildcarded flow and sending packets with various match fields") |
| 44 | logging.info("Expecting all sent packets to match") |
| 45 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 46 | egress_port=of_ports[1] |
| 47 | no_ports=set(of_ports).difference([egress_port]) |
| 48 | yes_ports = of_ports[1] |
| 49 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 50 | #Insert an All Wildcarded flow. |
| 51 | wildcard_all(self,of_ports) |
| 52 | |
| 53 | #check for different match fields and verify packet implements the action specified in the flow |
| 54 | pkt1 = simple_tcp_packet(dl_src="00:01:01:01:01:01"); |
| 55 | self.dataplane.send(of_ports[0], str(pkt1)) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 56 | receive_pkt_check(self.dataplane,pkt1,[yes_ports],no_ports,self) |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 57 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 58 | pkt2 = simple_tcp_packet(dl_dst="00:01:01:01:01:01"); |
| 59 | self.dataplane.send(of_ports[0], str(pkt2)) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 60 | receive_pkt_check(self.dataplane,pkt2,[yes_ports],no_ports,self) |
| 61 | |
| 62 | pkt3 = simple_tcp_packet(ip_src="192.168.2.1"); |
| 63 | self.dataplane.send(of_ports[0], str(pkt3)) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 64 | receive_pkt_check(self.dataplane,pkt3,[yes_ports],no_ports,self) |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 65 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 66 | pkt4 = simple_tcp_packet(ip_dst="192.168.2.2"); |
| 67 | self.dataplane.send(of_ports[0], str(pkt4)) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 68 | receive_pkt_check(self.dataplane,pkt4,[yes_ports],no_ports,self) |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 69 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 70 | pkt5 = simple_tcp_packet(ip_tos=2); |
| 71 | self.dataplane.send(of_ports[0], str(pkt5)) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 72 | receive_pkt_check(self.dataplane,pkt5,[yes_ports],no_ports,self) |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 73 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 74 | pkt6 = simple_tcp_packet(tcp_sport=8080); |
| 75 | self.dataplane.send(of_ports[0], str(pkt6)) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 76 | receive_pkt_check(self.dataplane,pkt6,[yes_ports],no_ports,self) |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 77 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 78 | pkt7 = simple_tcp_packet(tcp_dport=8081); |
| 79 | self.dataplane.send(of_ports[0], str(pkt7)) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 80 | receive_pkt_check(self.dataplane,pkt7,[yes_ports],no_ports,self) |
| 81 | |
| 82 | |
| 83 | |
| 84 | class EthernetSrcAddress(base_tests.SimpleDataPlane): |
| 85 | |
| 86 | """Verify match on single header field -- Ethernet Src Address """ |
| 87 | |
| 88 | def runTest(self): |
| 89 | |
| 90 | logging.info("Running Ethernet Src Address test") |
| 91 | |
| 92 | of_ports = config["port_map"].keys() |
| 93 | of_ports.sort() |
| 94 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 95 | |
| 96 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 97 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 98 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 99 | egress_port=of_ports[1] |
| 100 | no_ports=set(of_ports).difference([egress_port]) |
| 101 | yes_ports = of_ports[1] |
| 102 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 103 | logging.info("Inserting a flow with match on Ethernet Source Address ") |
| 104 | logging.info("Sending matching and non-matching ethernet packets") |
| 105 | logging.info("Verifying only matching packets implements the action specified in the flow") |
| 106 | |
| 107 | #Insert a Match On Ethernet Src Address flow |
| 108 | (pkt,match) = match_ethernet_src_address(self,of_ports) |
| 109 | |
| 110 | #Sending packet matching the flow, verify it implements the action |
| 111 | self.dataplane.send(of_ports[0], str(pkt)) |
| 112 | |
| 113 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 114 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 115 | |
| 116 | #Sending non matching packet , verify Packetin event gets triggered. |
| 117 | pkt2 = simple_eth_packet(dl_src='00:01:01:01:01:02'); |
| 118 | self.dataplane.send(of_ports[0], str(pkt2)) |
| 119 | |
| 120 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4) |
| 121 | self.assertTrue(response is not None, "PacketIn not received for non matching packets") |
| 122 | |
| 123 | class EthernetDstAddress(base_tests.SimpleDataPlane): |
| 124 | |
| 125 | """Verify match on single Header Field Field -- Ethernet Dst Address """ |
| 126 | |
| 127 | def runTest(self): |
| 128 | |
| 129 | logging.info("Running Ethernet Dst Address test") |
| 130 | |
| 131 | of_ports = config["port_map"].keys() |
| 132 | of_ports.sort() |
| 133 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 134 | |
| 135 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 136 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 137 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 138 | egress_port=of_ports[1] |
| 139 | no_ports=set(of_ports).difference([egress_port]) |
| 140 | yes_ports = of_ports[1] |
| 141 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 142 | logging.info("Inserting a flow with match on Ethernet Destination Address ") |
| 143 | logging.info("Sending matching and non-matching ethernet packets") |
| 144 | logging.info("Verifying only matching packets implements the action specified in the flow") |
| 145 | |
| 146 | #Insert a Match on Destination Address flow |
| 147 | (pkt,match) = match_ethernet_dst_address(self,of_ports) |
| 148 | |
| 149 | #Send Packet matching the flow |
| 150 | self.dataplane.send(of_ports[0], str(pkt)) |
| 151 | |
| 152 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 153 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 154 | |
| 155 | #Send Non-matching packet |
| 156 | pkt2 = simple_eth_packet(dl_dst='00:01:01:01:01:02'); |
| 157 | self.dataplane.send(of_ports[0], str(pkt2)) |
| 158 | |
| 159 | #Verify PacketIn event gets triggered |
| 160 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4) |
| 161 | self.assertTrue(response is not None, "PacketIn not received for non matching packet") |
| 162 | |
| 163 | |
| 164 | class EthernetType(base_tests.SimpleDataPlane): |
| 165 | |
| 166 | """Verify match on single header field -- Ethernet Type """ |
| 167 | |
| 168 | def runTest(self): |
| 169 | |
| 170 | logging.info("Running Ethernet Type test") |
| 171 | |
| 172 | of_ports = config["port_map"].keys() |
| 173 | of_ports.sort() |
| 174 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 175 | |
| 176 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 177 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 178 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 179 | egress_port=of_ports[1] |
| 180 | no_ports=set(of_ports).difference([egress_port]) |
| 181 | yes_ports = of_ports[1] |
| 182 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 183 | logging.info("Inserting a flow with match on Ethernet Type ") |
| 184 | logging.info("Sending matching and non-matching ethernet packets") |
| 185 | logging.info("Verifying only matching packets implements the action specified in the flow") |
| 186 | |
| 187 | #Insert a Match on Ethernet-Type flow |
| 188 | (pkt,match) = match_ethernet_type(self,of_ports) |
| 189 | |
| 190 | #Sending packet matching the flow |
| 191 | self.dataplane.send(of_ports[0], str(pkt)) |
| 192 | |
| 193 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 194 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 195 | |
| 196 | #Sending non matching packet , |
| 197 | pkt2 = simple_eth_packet(dl_type=0x0806); |
| 198 | self.dataplane.send(of_ports[0], str(pkt2)) |
| 199 | |
| 200 | #verify Packetin event gets triggered. |
| 201 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4) |
| 202 | self.assertTrue(response is not None, "PacketIn not received for non-matching packet") |
| 203 | |
| 204 | |
| 205 | class IngressPort(base_tests.SimpleDataPlane): |
| 206 | |
| 207 | """Verify match on single Header Field Field -- In_port """ |
| 208 | |
| 209 | def runTest(self): |
| 210 | |
| 211 | logging.info("Running Ingress Port test") |
| 212 | |
| 213 | of_ports = config["port_map"].keys() |
| 214 | of_ports.sort() |
| 215 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 216 | |
| 217 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 218 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 219 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 220 | egress_port=of_ports[1] |
| 221 | no_ports=set(of_ports).difference([egress_port]) |
| 222 | yes_ports = of_ports[1] |
| 223 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 224 | logging.info("Inserting a flow with match on Ingress Port ") |
| 225 | logging.info("Sending matching and non-matching packets") |
| 226 | logging.info("Verifying only matching packets implements the action specified in the flow") |
| 227 | |
| 228 | #Insert a Match on Ingress Port FLow |
| 229 | (pkt,match) = wildcard_all_except_ingress(self,of_ports,priority=0) |
| 230 | |
| 231 | #Send Packet matching the flow i.e on in_port specified in the flow |
| 232 | self.dataplane.send(of_ports[0], str(pkt)) |
| 233 | |
| 234 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 235 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 236 | |
| 237 | #Send Non-Matching Packet |
| 238 | self.dataplane.send(of_ports[1],str(pkt)) |
| 239 | |
| 240 | #Verify PacketIn event gets triggered |
| 241 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4) |
| 242 | self.assertTrue(response is not None, "PacketIn not received for non-matching packet") |
| 243 | |
| 244 | class VlanId(base_tests.SimpleDataPlane): |
| 245 | |
| 246 | """Verify match on single Header Field Field -- Vlan Id """ |
| 247 | |
| 248 | def runTest(self): |
| 249 | |
| 250 | of_ports = config["port_map"].keys() |
| 251 | of_ports.sort() |
| 252 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 253 | |
| 254 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 255 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 256 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 257 | egress_port=of_ports[1] |
| 258 | no_ports=set(of_ports).difference([egress_port]) |
| 259 | yes_ports = of_ports[1] |
| 260 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 261 | logging.info("Inserting a flow with match on VLAN ID ") |
| 262 | logging.info("Sending matching and non-matching tagged packets") |
| 263 | logging.info("Verifying matching packets implements the action specified in the flow") |
| 264 | |
| 265 | #Create a flow with match on Vlan Id |
| 266 | (pkt,match) = match_vlan_id(self,of_ports) |
| 267 | |
| 268 | #Send tagged packet matching the flow i.e packet with same vlan id as in flow |
| 269 | self.dataplane.send(of_ports[0], str(pkt)) |
| 270 | |
| 271 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 272 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 273 | |
| 274 | #Send Non-matching packet, i.e packet with different Vlan Id |
| 275 | pkt2 = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=4); |
| 276 | self.dataplane.send(of_ports[0], str(pkt2)) |
| 277 | |
| 278 | #Verify PacketIn event gets triggered |
| 279 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4) |
| 280 | self.assertTrue(response is not None, "PacketIn not received for non matching packet") |
| 281 | |
| 282 | class VlanPCP(base_tests.SimpleDataPlane): |
| 283 | |
| 284 | """"Verify match on single Header Field Field -- Vlan Priority""" |
| 285 | |
| 286 | def runTest(self): |
| 287 | |
| 288 | logging.info("Running VlanPCP1 test") |
| 289 | |
| 290 | of_ports = config["port_map"].keys() |
| 291 | of_ports.sort() |
| 292 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 293 | |
| 294 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 295 | delete_all_flows(self.controller) |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 296 | |
| 297 | egress_port=of_ports[1] |
| 298 | no_ports=set(of_ports).difference([egress_port]) |
| 299 | yes_ports = of_ports[1] |
| 300 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 301 | logging.info("Inserting a flow with match on VLAN Priority ") |
| 302 | logging.info("Sending matching and non-matching tagged packets") |
| 303 | logging.info("Verifying matching packet implements the action specified in the flow") |
| 304 | |
| 305 | #Create a flow matching on VLAN Priority |
| 306 | (pkt,match) = match_vlan_pcp(self,of_ports) |
| 307 | |
| 308 | #Send tagged Packet matching the flow |
| 309 | self.dataplane.send(of_ports[0], str(pkt)) |
| 310 | |
| 311 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 312 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 313 | |
| 314 | #Send tagged packet with same vlan_id but different vlan priority |
| 315 | pkt2 = simple_tcp_packet(dl_vlan_enable=True,dl_vlan=1,dl_vlan_pcp=20); |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 316 | self.dataplane.send(of_ports[0], str(pkt2)) |
| 317 | |
| 318 | #Verify Packet_In event gets triggered |
| 319 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4) |
| 320 | self.assertTrue(response is not None, "PacketIn not received for non matching packet") |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 321 | |
| 322 | class MultipleHeaderFieldL2(base_tests.SimpleDataPlane): |
| 323 | |
| 324 | """Verify match on multiple header field -- Ethernet Type, Ethernet Source Address, Ethernet Destination Address """ |
| 325 | |
| 326 | def runTest(self): |
| 327 | |
| 328 | logging.info("Running Multiple Header Field L2 test") |
| 329 | |
| 330 | of_ports = config["port_map"].keys() |
| 331 | of_ports.sort() |
| 332 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 333 | |
| 334 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 335 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 336 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 337 | egress_port=of_ports[1] |
| 338 | no_ports=set(of_ports).difference([egress_port]) |
| 339 | yes_ports = of_ports[1] |
| 340 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 341 | logging.info("Inserting a flow with match on Multiple Header Fields in L2 ") |
| 342 | logging.info("Sending matching and non-matching packets") |
| 343 | logging.info("Verifying matching packets implements the action specified in the flow") |
| 344 | |
| 345 | (pkt,match) = match_mul_l2(self,of_ports) |
| 346 | |
| 347 | #Send eth packet matching the dl_type field, verify it implements the action |
| 348 | self.dataplane.send(of_ports[0], str(pkt)) |
| 349 | |
| 350 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 351 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 352 | |
| 353 | #Sending non matching packet (only dl_dst is different) , verify Packetin event gets triggered. |
| 354 | pkt2 = simple_eth_packet(dl_type=0x88cc,dl_src='00:01:01:01:01:01',dl_dst='00:01:01:02:01:01'); |
| 355 | self.dataplane.send(of_ports[0], str(pkt2)) |
| 356 | |
| 357 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4) |
| 358 | self.assertTrue(response is not None, "PacketIn not received for non matching packet") |
| 359 | |
| 360 | #Sending non matching packet (only dl_src is different) , verify Packetin event gets triggered. |
| 361 | pkt2 = simple_eth_packet(dl_type=0x88cc,dl_src='00:01:01:01:01:02',dl_dst='00:01:01:01:01:02'); |
| 362 | self.dataplane.send(of_ports[0], str(pkt2)) |
| 363 | |
| 364 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4) |
| 365 | self.assertTrue(response is not None, "PacketIn not received for non matching packet") |
| 366 | |
| 367 | #Sending non matching packet (only ether_type is different) , verify Packetin event gets triggered. |
| 368 | pkt2 = simple_eth_packet(dl_type=0x0806,dl_src='00:01:01:01:01:01',dl_dst='00:01:01:01:01:02'); |
| 369 | self.dataplane.send(of_ports[0], str(pkt2)) |
| 370 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 371 | #Verify packet_in event gets triggered |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 372 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4) |
| 373 | self.assertTrue(response is not None, "PacketIn not received for non matching packet") |
| 374 | |
| 375 | class IpTos(base_tests.SimpleDataPlane): |
| 376 | |
| 377 | """"Verify match on single Header Field Field -- Type of service""" |
| 378 | |
| 379 | def runTest(self): |
| 380 | |
| 381 | logging.info("Running Ip_Tos test") |
| 382 | |
| 383 | of_ports = config["port_map"].keys() |
| 384 | of_ports.sort() |
| 385 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 386 | |
| 387 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 388 | delete_all_flows(self.controller) |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 389 | |
| 390 | egress_port=of_ports[1] |
| 391 | no_ports=set(of_ports).difference([egress_port]) |
| 392 | yes_ports = of_ports[1] |
| 393 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 394 | logging.info("Inserting a flow with match on Ip_Tos ") |
| 395 | logging.info("Sending matching and non-matching tcp/ip packets") |
| 396 | logging.info("Verifying only matching packets implements the action specified in the flow") |
| 397 | |
| 398 | #Create a flow matching on VLAN Priority |
| 399 | (pkt,match) = match_ip_tos(self,of_ports) |
| 400 | |
| 401 | #Send Packet matching the flow |
| 402 | self.dataplane.send(of_ports[0], str(pkt)) |
| 403 | |
| 404 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 405 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 406 | |
| 407 | #Create a non-matching packet , verify packet_in get generated |
Rich Lane | b5c7379 | 2012-12-03 17:12:32 -0800 | [diff] [blame] | 408 | pkt2 = simple_tcp_packet(ip_tos=4); |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 409 | self.dataplane.send(of_ports[0], str(pkt2)) |
| 410 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4) |
| 411 | self.assertTrue(response is not None, "PacketIn not received for non matching packet") |
| 412 | |
| 413 | class IpProtocol(base_tests.SimpleDataPlane): |
| 414 | |
| 415 | """"Verify match on single Header Field Field -- Ip Protocol""" |
| 416 | |
| 417 | def runTest(self): |
| 418 | |
| 419 | logging.info("Running Ip Protocol test") |
| 420 | |
| 421 | of_ports = config["port_map"].keys() |
| 422 | of_ports.sort() |
| 423 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 424 | |
| 425 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 426 | delete_all_flows(self.controller) |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 427 | |
| 428 | egress_port=of_ports[1] |
| 429 | no_ports=set(of_ports).difference([egress_port]) |
| 430 | yes_ports = of_ports[1] |
| 431 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 432 | logging.info("Inserting a flow with match on Ip Protocol ") |
| 433 | logging.info("Sending matching and non-matching tcp/ip packets") |
| 434 | logging.info("Verifying only matching packets implements the action specified in the flow") |
| 435 | |
| 436 | #Create a flow matching on VLAN Priority |
| 437 | (pkt,match) = match_ip_protocol(self,of_ports) |
| 438 | |
| 439 | #Send Packet matching the flow |
| 440 | self.dataplane.send(of_ports[0], str(pkt)) |
| 441 | |
| 442 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 443 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 444 | |
| 445 | #Create a non-matching packet , verify packet_in get generated |
| 446 | pkt2 = simple_icmp_packet(); |
| 447 | self.dataplane.send(of_ports[0], str(pkt2)) |
| 448 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4) |
| 449 | self.assertTrue(response is not None, "PacketIn not received for non matching packet") |
| 450 | |
| 451 | |
| 452 | class TcpSrcPort(base_tests.SimpleDataPlane): |
| 453 | |
| 454 | """Verify match on Single header field -- Tcp Source Port, """ |
| 455 | |
| 456 | def runTest(self): |
| 457 | |
| 458 | logging.info("Running Tcp Src Port test") |
| 459 | |
| 460 | of_ports = config["port_map"].keys() |
| 461 | of_ports.sort() |
| 462 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 463 | |
| 464 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 465 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 466 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 467 | egress_port=of_ports[1] |
| 468 | no_ports=set(of_ports).difference([egress_port]) |
| 469 | yes_ports = of_ports[1] |
| 470 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 471 | logging.info("Inserting a flow with match on Tcp Tcp Source Port ") |
| 472 | logging.info("Sending matching and non-matching tcp packets") |
| 473 | logging.info("Verifying matching packets implements the action specified in the flow") |
| 474 | |
| 475 | (pkt,match) = match_tcp_src(self,of_ports) |
| 476 | |
| 477 | #Sending packet matching the tcp_sport, verify it implements the action |
| 478 | self.dataplane.send(of_ports[0], str(pkt)) |
| 479 | |
| 480 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 481 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 482 | |
| 483 | #Sending non matching packet , verify Packetin event gets triggered. |
| 484 | pkt2 = simple_tcp_packet(tcp_sport=540); |
| 485 | self.dataplane.send(of_ports[0], str(pkt2)) |
| 486 | |
| 487 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4) |
| 488 | self.assertTrue(response is not None, "PacketIn not received for non matching packet") |
| 489 | |
| 490 | class TcpDstPort(base_tests.SimpleDataPlane): |
| 491 | |
| 492 | """Verify match on Single header field -- Tcp Destination Port """ |
| 493 | |
| 494 | def runTest(self): |
| 495 | |
| 496 | logging.info("Running Tcp Destination Port test") |
| 497 | |
| 498 | of_ports = config["port_map"].keys() |
| 499 | of_ports.sort() |
| 500 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 501 | |
| 502 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 503 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 504 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 505 | egress_port=of_ports[1] |
| 506 | no_ports=set(of_ports).difference([egress_port]) |
| 507 | yes_ports = of_ports[1] |
| 508 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 509 | logging.info("Inserting a flow with match on Tcp Destination Port ") |
| 510 | logging.info("Sending matching and non-matching packets") |
| 511 | logging.info("Verifying matching packets implements the action specified in the flow") |
| 512 | |
| 513 | (pkt,match) = match_tcp_dst(self,of_ports) |
| 514 | |
| 515 | #Sending packet matching the tcp_dport, verify it implements the action |
| 516 | self.dataplane.send(of_ports[0], str(pkt)) |
| 517 | |
| 518 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 519 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 520 | |
| 521 | #Sending non matching packet , verify Packetin event gets triggered. |
| 522 | pkt2 = simple_tcp_packet(tcp_dport=541); |
| 523 | self.dataplane.send(of_ports[0], str(pkt2)) |
| 524 | |
| 525 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=10) |
| 526 | self.assertTrue(response is not None, "PacketIn not received for non matching packet") |
| 527 | |
| 528 | |
| 529 | class ExactMatch(base_tests.SimpleDataPlane): |
| 530 | |
| 531 | """Verify match on Single header field -- Exact Match """ |
| 532 | |
| 533 | def runTest(self): |
| 534 | |
| 535 | logging.info("Running Tcp Exact Match test") |
| 536 | |
| 537 | of_ports = config["port_map"].keys() |
| 538 | of_ports.sort() |
| 539 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 540 | |
| 541 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 542 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 543 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 544 | egress_port=of_ports[1] |
| 545 | no_ports=set(of_ports).difference([egress_port]) |
| 546 | yes_ports = of_ports[1] |
| 547 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 548 | logging.info("Inserting a flow with match for Exact Match ") |
| 549 | logging.info("Sending matching and non-matching packets") |
| 550 | logging.info("Verifying matching packets implements the action specified in the flow") |
| 551 | |
| 552 | (pkt,match) = exact_match(self,of_ports) |
| 553 | |
| 554 | #Sending packet matching all the fields of a tcp_packet, verify it implements the action |
| 555 | self.dataplane.send(of_ports[0], str(pkt)) |
| 556 | |
| 557 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 558 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 559 | |
| 560 | #Sending non matching packet , verify Packetin event gets triggered. |
| 561 | pkt2 = simple_tcp_packet(tcp_sport=540); |
| 562 | self.dataplane.send(of_ports[0], str(pkt2)) |
| 563 | |
| 564 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4) |
| 565 | self.assertTrue(response is not None, "PacketIn not received for non matching packet") |
| 566 | |
| 567 | |
| 568 | class MultipleHeaderFieldL4(base_tests.SimpleDataPlane): |
| 569 | |
| 570 | """Verify match on multiple header field -- Tcp Source Port, Tcp Destination Port """ |
| 571 | |
| 572 | def runTest(self): |
| 573 | |
| 574 | logging.info("Running Multiple Header Field L4 test") |
| 575 | |
| 576 | of_ports = config["port_map"].keys() |
| 577 | of_ports.sort() |
| 578 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 579 | |
| 580 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 581 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 582 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 583 | egress_port=of_ports[1] |
| 584 | no_ports=set(of_ports).difference([egress_port]) |
| 585 | yes_ports = of_ports[1] |
| 586 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 587 | logging.info("Inserting a flow with match on Multiple Header Field L4 ") |
| 588 | logging.info("Sending matching and non-matching packets") |
| 589 | logging.info("Verifying matching packets implements the action specified in the flow") |
| 590 | |
| 591 | (pkt,match) = match_mul_l4(self,of_ports) |
| 592 | |
| 593 | #Sending packet matching the tcp_sport and tcp_dport field, verify it implements the action |
| 594 | self.dataplane.send(of_ports[0], str(pkt)) |
| 595 | |
| 596 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 597 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 598 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 599 | #Sending non matching packet (tcp_dport different), verify Packetin event gets triggered. |
| 600 | pkt2 = simple_tcp_packet(tcp_sport=111,tcp_dport=541); |
| 601 | self.dataplane.send(of_ports[0], str(pkt2)) |
| 602 | |
| 603 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4) |
| 604 | self.assertTrue(response is not None, "PacketIn not received for non matching packet") |
| 605 | |
| 606 | #Sending non matching packet (tcp_sport different), verify Packetin event gets triggered. |
| 607 | pkt2 = simple_tcp_packet(tcp_sport=100,tcp_dport=112); |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 608 | self.dataplane.send(of_ports[0], str(pkt2)) |
| 609 | |
| 610 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN,timeout=4) |
| 611 | self.assertTrue(response is not None, "PacketIn not received for non matching packet") |
| 612 | |
| 613 | |
| 614 | class ExactMatchPrio(base_tests.SimpleDataPlane): |
| 615 | |
| 616 | """Verify that Exact Match has highest priority """ |
| 617 | |
| 618 | def runTest(self): |
| 619 | |
| 620 | logging.info("Running Exact Match High Priority test") |
| 621 | |
| 622 | of_ports = config["port_map"].keys() |
| 623 | of_ports.sort() |
| 624 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 625 | |
| 626 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 627 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 628 | |
Rich Lane | ed13065 | 2012-12-31 17:35:33 -0800 | [diff] [blame] | 629 | egress_port=of_ports[2] |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 630 | no_ports=set(of_ports).difference([egress_port]) |
Rich Lane | ed13065 | 2012-12-31 17:35:33 -0800 | [diff] [blame] | 631 | yes_ports = egress_port |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 632 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 633 | logging.info("Inserting a flow with Exact Match (low priority)") |
| 634 | logging.info("Inserting an overlapping wildcarded flow (higher priority)") |
| 635 | logging.info("Sending packets matching both the flows ") |
| 636 | logging.info("Verifying matching packets implements the action specified in the exact match flow") |
| 637 | |
| 638 | #Insert two Overlapping Flows : Exact Match and Wildcard All. |
| 639 | (pkt,match) = exact_match_with_prio(self,of_ports,priority=10) |
| 640 | (pkt2,match2) = wildcard_all(self,of_ports,priority=20); |
| 641 | |
| 642 | #Sending packet matching both the flows , |
| 643 | self.dataplane.send(of_ports[0], str(pkt2)) |
| 644 | |
| 645 | #verify it implements the action specified in Exact Match Flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 646 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 647 | |
| 648 | |
| 649 | class WildcardMatchPrio(base_tests.SimpleDataPlane): |
| 650 | |
| 651 | """Verify that Wildcard Match with highest priority overrides the low priority WildcardMatch """ |
| 652 | |
| 653 | def runTest(self): |
| 654 | |
| 655 | logging.info("Running Wildcard Match High Priority test") |
| 656 | |
| 657 | of_ports = config["port_map"].keys() |
| 658 | of_ports.sort() |
| 659 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 660 | |
| 661 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 662 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 663 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 664 | egress_port=of_ports[1] |
| 665 | no_ports=set(of_ports).difference([egress_port]) |
| 666 | yes_ports = of_ports[1] |
| 667 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 668 | logging.info("Inserting two wildcarded flows with priorities ") |
| 669 | logging.info("Sending packets matching the flows") |
| 670 | logging.info("Verifying matching packets implements the action specified in the flow with higher priority") |
| 671 | |
| 672 | (pkt,match) = wildcard_all(self,of_ports,priority=20) |
| 673 | (pkt1,match1) = wildcard_all_except_ingress1(self,of_ports,priority=10) |
| 674 | |
| 675 | #Sending packet matching both the flows , verify it implements the action specified by Higher Priority flow |
| 676 | self.dataplane.send(of_ports[0], str(pkt1)) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 677 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 678 | |
| 679 | |
| 680 | |
| 681 | |
| 682 | |