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 | |
Rich Lane | cd97d3d | 2013-01-07 18:50:06 -0800 | [diff] [blame] | 13 | from oftest import config |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 14 | import oftest.controller as controller |
Rich Lane | d7b0ffa | 2013-03-08 15:53:42 -0800 | [diff] [blame] | 15 | import ofp |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 16 | import oftest.dataplane as dataplane |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 17 | import oftest.parse as parse |
| 18 | import oftest.base_tests as base_tests |
| 19 | import time |
| 20 | |
| 21 | from oftest.testutils import * |
| 22 | from time import sleep |
| 23 | from FuncUtils import * |
| 24 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 25 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 26 | |
| 27 | class AllWildcardMatch(base_tests.SimpleDataPlane): |
| 28 | |
| 29 | """Verify for an all wildcarded flow all the injected packets would match that flow""" |
| 30 | |
| 31 | def runTest(self): |
| 32 | |
| 33 | logging.info("Running All Wildcard Match test") |
| 34 | |
| 35 | of_ports = config["port_map"].keys() |
| 36 | of_ports.sort() |
| 37 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 38 | |
| 39 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 40 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 41 | |
| 42 | logging.info("Inserting an all wildcarded flow and sending packets with various match fields") |
| 43 | logging.info("Expecting all sent packets to match") |
| 44 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 45 | egress_port=of_ports[1] |
| 46 | no_ports=set(of_ports).difference([egress_port]) |
| 47 | yes_ports = of_ports[1] |
| 48 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 49 | #Insert an All Wildcarded flow. |
| 50 | wildcard_all(self,of_ports) |
| 51 | |
| 52 | #check for different match fields and verify packet implements the action specified in the flow |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 53 | pkt1 = simple_tcp_packet(eth_src="00:01:01:01:01:01"); |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 54 | self.dataplane.send(of_ports[0], str(pkt1)) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 55 | receive_pkt_check(self.dataplane,pkt1,[yes_ports],no_ports,self) |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 56 | |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 57 | pkt2 = simple_tcp_packet(eth_dst="00:01:01:01:01:01"); |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 58 | self.dataplane.send(of_ports[0], str(pkt2)) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 59 | receive_pkt_check(self.dataplane,pkt2,[yes_ports],no_ports,self) |
| 60 | |
| 61 | pkt3 = simple_tcp_packet(ip_src="192.168.2.1"); |
| 62 | self.dataplane.send(of_ports[0], str(pkt3)) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 63 | receive_pkt_check(self.dataplane,pkt3,[yes_ports],no_ports,self) |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 64 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 65 | pkt4 = simple_tcp_packet(ip_dst="192.168.2.2"); |
| 66 | self.dataplane.send(of_ports[0], str(pkt4)) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 67 | receive_pkt_check(self.dataplane,pkt4,[yes_ports],no_ports,self) |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 68 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 69 | pkt5 = simple_tcp_packet(ip_tos=2); |
| 70 | self.dataplane.send(of_ports[0], str(pkt5)) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 71 | receive_pkt_check(self.dataplane,pkt5,[yes_ports],no_ports,self) |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 72 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 73 | pkt6 = simple_tcp_packet(tcp_sport=8080); |
| 74 | self.dataplane.send(of_ports[0], str(pkt6)) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 75 | receive_pkt_check(self.dataplane,pkt6,[yes_ports],no_ports,self) |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 76 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 77 | pkt7 = simple_tcp_packet(tcp_dport=8081); |
| 78 | self.dataplane.send(of_ports[0], str(pkt7)) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 79 | receive_pkt_check(self.dataplane,pkt7,[yes_ports],no_ports,self) |
| 80 | |
| 81 | |
| 82 | |
| 83 | class EthernetSrcAddress(base_tests.SimpleDataPlane): |
| 84 | |
| 85 | """Verify match on single header field -- Ethernet Src Address """ |
| 86 | |
| 87 | def runTest(self): |
| 88 | |
| 89 | logging.info("Running Ethernet Src Address test") |
| 90 | |
| 91 | of_ports = config["port_map"].keys() |
| 92 | of_ports.sort() |
| 93 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 94 | |
| 95 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 96 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 97 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 98 | egress_port=of_ports[1] |
| 99 | no_ports=set(of_ports).difference([egress_port]) |
| 100 | yes_ports = of_ports[1] |
| 101 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 102 | logging.info("Inserting a flow with match on Ethernet Source Address ") |
| 103 | logging.info("Sending matching and non-matching ethernet packets") |
| 104 | logging.info("Verifying only matching packets implements the action specified in the flow") |
| 105 | |
| 106 | #Insert a Match On Ethernet Src Address flow |
| 107 | (pkt,match) = match_ethernet_src_address(self,of_ports) |
| 108 | |
| 109 | #Sending packet matching the flow, verify it implements the action |
| 110 | self.dataplane.send(of_ports[0], str(pkt)) |
| 111 | |
| 112 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 113 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 114 | |
| 115 | #Sending non matching packet , verify Packetin event gets triggered. |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 116 | pkt2 = simple_eth_packet(eth_src='00:01:01:01:01:02'); |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 117 | self.dataplane.send(of_ports[0], str(pkt2)) |
Rich Lane | 4c504f3 | 2013-06-07 17:24:14 -0700 | [diff] [blame] | 118 | verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 119 | |
| 120 | class EthernetDstAddress(base_tests.SimpleDataPlane): |
| 121 | |
| 122 | """Verify match on single Header Field Field -- Ethernet Dst Address """ |
| 123 | |
| 124 | def runTest(self): |
| 125 | |
| 126 | logging.info("Running Ethernet Dst Address test") |
| 127 | |
| 128 | of_ports = config["port_map"].keys() |
| 129 | of_ports.sort() |
| 130 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 131 | |
| 132 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 133 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 134 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 135 | egress_port=of_ports[1] |
| 136 | no_ports=set(of_ports).difference([egress_port]) |
| 137 | yes_ports = of_ports[1] |
| 138 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 139 | logging.info("Inserting a flow with match on Ethernet Destination Address ") |
| 140 | logging.info("Sending matching and non-matching ethernet packets") |
| 141 | logging.info("Verifying only matching packets implements the action specified in the flow") |
| 142 | |
| 143 | #Insert a Match on Destination Address flow |
| 144 | (pkt,match) = match_ethernet_dst_address(self,of_ports) |
| 145 | |
| 146 | #Send Packet matching the flow |
| 147 | self.dataplane.send(of_ports[0], str(pkt)) |
| 148 | |
| 149 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 150 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 151 | |
| 152 | #Send Non-matching packet |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 153 | pkt2 = simple_eth_packet(eth_dst='00:01:01:01:01:02'); |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 154 | self.dataplane.send(of_ports[0], str(pkt2)) |
| 155 | |
| 156 | #Verify PacketIn event gets triggered |
Rich Lane | 4c504f3 | 2013-06-07 17:24:14 -0700 | [diff] [blame] | 157 | verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 158 | |
| 159 | |
| 160 | class EthernetType(base_tests.SimpleDataPlane): |
| 161 | |
| 162 | """Verify match on single header field -- Ethernet Type """ |
| 163 | |
| 164 | def runTest(self): |
| 165 | |
| 166 | logging.info("Running Ethernet Type test") |
| 167 | |
| 168 | of_ports = config["port_map"].keys() |
| 169 | of_ports.sort() |
| 170 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 171 | |
| 172 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 173 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 174 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 175 | egress_port=of_ports[1] |
| 176 | no_ports=set(of_ports).difference([egress_port]) |
| 177 | yes_ports = of_ports[1] |
| 178 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 179 | logging.info("Inserting a flow with match on Ethernet Type ") |
| 180 | logging.info("Sending matching and non-matching ethernet packets") |
| 181 | logging.info("Verifying only matching packets implements the action specified in the flow") |
| 182 | |
| 183 | #Insert a Match on Ethernet-Type flow |
| 184 | (pkt,match) = match_ethernet_type(self,of_ports) |
| 185 | |
| 186 | #Sending packet matching the flow |
| 187 | self.dataplane.send(of_ports[0], str(pkt)) |
| 188 | |
| 189 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 190 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 191 | |
| 192 | #Sending non matching packet , |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 193 | pkt2 = simple_eth_packet(eth_type=0x0806); |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 194 | self.dataplane.send(of_ports[0], str(pkt2)) |
| 195 | |
| 196 | #verify Packetin event gets triggered. |
Rich Lane | 4c504f3 | 2013-06-07 17:24:14 -0700 | [diff] [blame] | 197 | verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 198 | |
| 199 | |
| 200 | class IngressPort(base_tests.SimpleDataPlane): |
| 201 | |
| 202 | """Verify match on single Header Field Field -- In_port """ |
| 203 | |
| 204 | def runTest(self): |
| 205 | |
| 206 | logging.info("Running Ingress Port test") |
| 207 | |
| 208 | of_ports = config["port_map"].keys() |
| 209 | of_ports.sort() |
| 210 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 211 | |
| 212 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 213 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 214 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 215 | egress_port=of_ports[1] |
| 216 | no_ports=set(of_ports).difference([egress_port]) |
| 217 | yes_ports = of_ports[1] |
| 218 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 219 | logging.info("Inserting a flow with match on Ingress Port ") |
| 220 | logging.info("Sending matching and non-matching packets") |
| 221 | logging.info("Verifying only matching packets implements the action specified in the flow") |
| 222 | |
| 223 | #Insert a Match on Ingress Port FLow |
| 224 | (pkt,match) = wildcard_all_except_ingress(self,of_ports,priority=0) |
| 225 | |
| 226 | #Send Packet matching the flow i.e on in_port specified in the flow |
| 227 | self.dataplane.send(of_ports[0], str(pkt)) |
| 228 | |
| 229 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 230 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 231 | |
| 232 | #Send Non-Matching Packet |
| 233 | self.dataplane.send(of_ports[1],str(pkt)) |
| 234 | |
| 235 | #Verify PacketIn event gets triggered |
Rich Lane | 4c504f3 | 2013-06-07 17:24:14 -0700 | [diff] [blame] | 236 | verify_packet_in(self, str(pkt), of_ports[1], ofp.OFPR_NO_MATCH) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 237 | |
| 238 | class VlanId(base_tests.SimpleDataPlane): |
| 239 | |
| 240 | """Verify match on single Header Field Field -- Vlan Id """ |
| 241 | |
| 242 | def runTest(self): |
| 243 | |
| 244 | of_ports = config["port_map"].keys() |
| 245 | of_ports.sort() |
| 246 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 247 | |
| 248 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 249 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 250 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 251 | egress_port=of_ports[1] |
| 252 | no_ports=set(of_ports).difference([egress_port]) |
| 253 | yes_ports = of_ports[1] |
| 254 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 255 | logging.info("Inserting a flow with match on VLAN ID ") |
| 256 | logging.info("Sending matching and non-matching tagged packets") |
| 257 | logging.info("Verifying matching packets implements the action specified in the flow") |
| 258 | |
| 259 | #Create a flow with match on Vlan Id |
| 260 | (pkt,match) = match_vlan_id(self,of_ports) |
| 261 | |
| 262 | #Send tagged packet matching the flow i.e packet with same vlan id as in flow |
| 263 | self.dataplane.send(of_ports[0], str(pkt)) |
| 264 | |
| 265 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 266 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 267 | |
| 268 | #Send Non-matching packet, i.e packet with different Vlan Id |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 269 | pkt2 = simple_tcp_packet(dl_vlan_enable=True,vlan_vid=4); |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 270 | self.dataplane.send(of_ports[0], str(pkt2)) |
| 271 | |
| 272 | #Verify PacketIn event gets triggered |
Rich Lane | 4c504f3 | 2013-06-07 17:24:14 -0700 | [diff] [blame] | 273 | verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 274 | |
| 275 | class VlanPCP(base_tests.SimpleDataPlane): |
| 276 | |
| 277 | """"Verify match on single Header Field Field -- Vlan Priority""" |
| 278 | |
| 279 | def runTest(self): |
| 280 | |
| 281 | logging.info("Running VlanPCP1 test") |
| 282 | |
| 283 | of_ports = config["port_map"].keys() |
| 284 | of_ports.sort() |
| 285 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 286 | |
| 287 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 288 | delete_all_flows(self.controller) |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 289 | |
| 290 | egress_port=of_ports[1] |
| 291 | no_ports=set(of_ports).difference([egress_port]) |
| 292 | yes_ports = of_ports[1] |
| 293 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 294 | logging.info("Inserting a flow with match on VLAN Priority ") |
| 295 | logging.info("Sending matching and non-matching tagged packets") |
| 296 | logging.info("Verifying matching packet implements the action specified in the flow") |
| 297 | |
| 298 | #Create a flow matching on VLAN Priority |
| 299 | (pkt,match) = match_vlan_pcp(self,of_ports) |
| 300 | |
| 301 | #Send tagged Packet matching the flow |
| 302 | self.dataplane.send(of_ports[0], str(pkt)) |
| 303 | |
| 304 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 305 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 306 | |
| 307 | #Send tagged packet with same vlan_id but different vlan priority |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 308 | pkt2 = simple_tcp_packet(dl_vlan_enable=True,vlan_vid=1,vlan_pcp=20); |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 309 | self.dataplane.send(of_ports[0], str(pkt2)) |
| 310 | |
| 311 | #Verify Packet_In event gets triggered |
Rich Lane | 4c504f3 | 2013-06-07 17:24:14 -0700 | [diff] [blame] | 312 | verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 313 | |
| 314 | class MultipleHeaderFieldL2(base_tests.SimpleDataPlane): |
| 315 | |
| 316 | """Verify match on multiple header field -- Ethernet Type, Ethernet Source Address, Ethernet Destination Address """ |
| 317 | |
| 318 | def runTest(self): |
| 319 | |
| 320 | logging.info("Running Multiple Header Field L2 test") |
| 321 | |
| 322 | of_ports = config["port_map"].keys() |
| 323 | of_ports.sort() |
| 324 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 325 | |
| 326 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 327 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 328 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 329 | egress_port=of_ports[1] |
| 330 | no_ports=set(of_ports).difference([egress_port]) |
| 331 | yes_ports = of_ports[1] |
| 332 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 333 | logging.info("Inserting a flow with match on Multiple Header Fields in L2 ") |
| 334 | logging.info("Sending matching and non-matching packets") |
| 335 | logging.info("Verifying matching packets implements the action specified in the flow") |
| 336 | |
| 337 | (pkt,match) = match_mul_l2(self,of_ports) |
| 338 | |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 339 | #Send eth packet matching the eth_type field, verify it implements the action |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 340 | self.dataplane.send(of_ports[0], str(pkt)) |
| 341 | |
| 342 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 343 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 344 | |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 345 | #Sending non matching packet (only eth_dst is different) , verify Packetin event gets triggered. |
| 346 | pkt2 = simple_eth_packet(eth_type=0x88cc,eth_src='00:01:01:01:01:01',eth_dst='00:01:01:02:01:01'); |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 347 | self.dataplane.send(of_ports[0], str(pkt2)) |
Rich Lane | 4c504f3 | 2013-06-07 17:24:14 -0700 | [diff] [blame] | 348 | verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 349 | |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 350 | #Sending non matching packet (only eth_src is different) , verify Packetin event gets triggered. |
| 351 | pkt2 = simple_eth_packet(eth_type=0x88cc,eth_src='00:01:01:01:01:02',eth_dst='00:01:01:01:01:02'); |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 352 | self.dataplane.send(of_ports[0], str(pkt2)) |
Rich Lane | 4c504f3 | 2013-06-07 17:24:14 -0700 | [diff] [blame] | 353 | verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 354 | |
| 355 | #Sending non matching packet (only ether_type is different) , verify Packetin event gets triggered. |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 356 | pkt2 = simple_eth_packet(eth_type=0x0806,eth_src='00:01:01:01:01:01',eth_dst='00:01:01:01:01:02'); |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 357 | self.dataplane.send(of_ports[0], str(pkt2)) |
| 358 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 359 | #Verify packet_in event gets triggered |
Rich Lane | 4c504f3 | 2013-06-07 17:24:14 -0700 | [diff] [blame] | 360 | verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 361 | |
| 362 | class IpTos(base_tests.SimpleDataPlane): |
| 363 | |
| 364 | """"Verify match on single Header Field Field -- Type of service""" |
| 365 | |
| 366 | def runTest(self): |
| 367 | |
| 368 | logging.info("Running Ip_Tos test") |
| 369 | |
| 370 | of_ports = config["port_map"].keys() |
| 371 | of_ports.sort() |
| 372 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 373 | |
| 374 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 375 | delete_all_flows(self.controller) |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 376 | |
| 377 | egress_port=of_ports[1] |
| 378 | no_ports=set(of_ports).difference([egress_port]) |
| 379 | yes_ports = of_ports[1] |
| 380 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 381 | logging.info("Inserting a flow with match on Ip_Tos ") |
| 382 | logging.info("Sending matching and non-matching tcp/ip packets") |
| 383 | logging.info("Verifying only matching packets implements the action specified in the flow") |
| 384 | |
| 385 | #Create a flow matching on VLAN Priority |
| 386 | (pkt,match) = match_ip_tos(self,of_ports) |
| 387 | |
| 388 | #Send Packet matching the flow |
| 389 | self.dataplane.send(of_ports[0], str(pkt)) |
| 390 | |
| 391 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 392 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 393 | |
| 394 | #Create a non-matching packet , verify packet_in get generated |
Rich Lane | b5c7379 | 2012-12-03 17:12:32 -0800 | [diff] [blame] | 395 | pkt2 = simple_tcp_packet(ip_tos=4); |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 396 | self.dataplane.send(of_ports[0], str(pkt2)) |
Rich Lane | 4c504f3 | 2013-06-07 17:24:14 -0700 | [diff] [blame] | 397 | verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 398 | |
| 399 | class IpProtocol(base_tests.SimpleDataPlane): |
| 400 | |
| 401 | """"Verify match on single Header Field Field -- Ip Protocol""" |
| 402 | |
| 403 | def runTest(self): |
| 404 | |
| 405 | logging.info("Running Ip Protocol test") |
| 406 | |
| 407 | of_ports = config["port_map"].keys() |
| 408 | of_ports.sort() |
| 409 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 410 | |
| 411 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 412 | delete_all_flows(self.controller) |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 413 | |
| 414 | egress_port=of_ports[1] |
| 415 | no_ports=set(of_ports).difference([egress_port]) |
| 416 | yes_ports = of_ports[1] |
| 417 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 418 | logging.info("Inserting a flow with match on Ip Protocol ") |
| 419 | logging.info("Sending matching and non-matching tcp/ip packets") |
| 420 | logging.info("Verifying only matching packets implements the action specified in the flow") |
| 421 | |
| 422 | #Create a flow matching on VLAN Priority |
| 423 | (pkt,match) = match_ip_protocol(self,of_ports) |
| 424 | |
| 425 | #Send Packet matching the flow |
| 426 | self.dataplane.send(of_ports[0], str(pkt)) |
| 427 | |
| 428 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 429 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 430 | |
| 431 | #Create a non-matching packet , verify packet_in get generated |
| 432 | pkt2 = simple_icmp_packet(); |
| 433 | self.dataplane.send(of_ports[0], str(pkt2)) |
Rich Lane | 4c504f3 | 2013-06-07 17:24:14 -0700 | [diff] [blame] | 434 | verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 435 | |
| 436 | |
| 437 | class TcpSrcPort(base_tests.SimpleDataPlane): |
| 438 | |
| 439 | """Verify match on Single header field -- Tcp Source Port, """ |
| 440 | |
| 441 | def runTest(self): |
| 442 | |
| 443 | logging.info("Running Tcp Src Port test") |
| 444 | |
| 445 | of_ports = config["port_map"].keys() |
| 446 | of_ports.sort() |
| 447 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 448 | |
| 449 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 450 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 451 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 452 | egress_port=of_ports[1] |
| 453 | no_ports=set(of_ports).difference([egress_port]) |
| 454 | yes_ports = of_ports[1] |
| 455 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 456 | logging.info("Inserting a flow with match on Tcp Tcp Source Port ") |
| 457 | logging.info("Sending matching and non-matching tcp packets") |
| 458 | logging.info("Verifying matching packets implements the action specified in the flow") |
| 459 | |
| 460 | (pkt,match) = match_tcp_src(self,of_ports) |
| 461 | |
| 462 | #Sending packet matching the tcp_sport, verify it implements the action |
| 463 | self.dataplane.send(of_ports[0], str(pkt)) |
| 464 | |
| 465 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 466 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 467 | |
| 468 | #Sending non matching packet , verify Packetin event gets triggered. |
| 469 | pkt2 = simple_tcp_packet(tcp_sport=540); |
| 470 | self.dataplane.send(of_ports[0], str(pkt2)) |
Rich Lane | 4c504f3 | 2013-06-07 17:24:14 -0700 | [diff] [blame] | 471 | verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 472 | |
| 473 | class TcpDstPort(base_tests.SimpleDataPlane): |
| 474 | |
| 475 | """Verify match on Single header field -- Tcp Destination Port """ |
| 476 | |
| 477 | def runTest(self): |
| 478 | |
| 479 | logging.info("Running Tcp Destination Port test") |
| 480 | |
| 481 | of_ports = config["port_map"].keys() |
| 482 | of_ports.sort() |
| 483 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 484 | |
| 485 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 486 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 487 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 488 | egress_port=of_ports[1] |
| 489 | no_ports=set(of_ports).difference([egress_port]) |
| 490 | yes_ports = of_ports[1] |
| 491 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 492 | logging.info("Inserting a flow with match on Tcp Destination Port ") |
| 493 | logging.info("Sending matching and non-matching packets") |
| 494 | logging.info("Verifying matching packets implements the action specified in the flow") |
| 495 | |
| 496 | (pkt,match) = match_tcp_dst(self,of_ports) |
| 497 | |
| 498 | #Sending packet matching the tcp_dport, verify it implements the action |
| 499 | self.dataplane.send(of_ports[0], str(pkt)) |
| 500 | |
| 501 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 502 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 503 | |
| 504 | #Sending non matching packet , verify Packetin event gets triggered. |
| 505 | pkt2 = simple_tcp_packet(tcp_dport=541); |
| 506 | self.dataplane.send(of_ports[0], str(pkt2)) |
Rich Lane | 4c504f3 | 2013-06-07 17:24:14 -0700 | [diff] [blame] | 507 | verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 508 | |
Shudong Zhou | c2f1876 | 2013-01-11 00:12:44 -0800 | [diff] [blame] | 509 | class UdpSrcPort(base_tests.SimpleDataPlane): |
| 510 | |
| 511 | """Verify match on Single header field -- Udp Source Port, """ |
| 512 | |
| 513 | def runTest(self): |
| 514 | |
| 515 | logging.info("Running Udp Src Port test") |
| 516 | |
| 517 | of_ports = config["port_map"].keys() |
| 518 | of_ports.sort() |
| 519 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 520 | |
| 521 | #Clear Switch State |
| 522 | delete_all_flows(self.controller) |
| 523 | |
| 524 | egress_port=of_ports[1] |
| 525 | no_ports=set(of_ports).difference([egress_port]) |
| 526 | yes_ports = of_ports[1] |
| 527 | |
| 528 | logging.info("Inserting a flow with match on Udp Udp Source Port ") |
| 529 | logging.info("Sending matching and non-matching tcp packets") |
| 530 | logging.info("Verifying matching packets implements the action specified in the flow") |
| 531 | |
| 532 | (pkt,match) = match_udp_src(self,of_ports) |
| 533 | |
| 534 | #Sending packet matching the tcp_sport, verify it implements the action |
| 535 | self.dataplane.send(of_ports[0], str(pkt)) |
| 536 | |
| 537 | #Verify packet implements the action specified in the flow |
| 538 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 539 | |
| 540 | #Sending non matching packet , verify Packetin event gets triggered. |
| 541 | pkt2 = simple_udp_packet(udp_sport=540); |
| 542 | self.dataplane.send(of_ports[0], str(pkt2)) |
Rich Lane | 4c504f3 | 2013-06-07 17:24:14 -0700 | [diff] [blame] | 543 | verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH) |
Shudong Zhou | c2f1876 | 2013-01-11 00:12:44 -0800 | [diff] [blame] | 544 | |
| 545 | class UdpDstPort(base_tests.SimpleDataPlane): |
| 546 | |
| 547 | """Verify match on Single header field -- Udp Destination Port """ |
| 548 | |
| 549 | def runTest(self): |
| 550 | |
| 551 | logging.info("Running Udp Destination Port test") |
| 552 | |
| 553 | of_ports = config["port_map"].keys() |
| 554 | of_ports.sort() |
| 555 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 556 | |
| 557 | #Clear Switch State |
| 558 | delete_all_flows(self.controller) |
| 559 | |
| 560 | egress_port=of_ports[1] |
| 561 | no_ports=set(of_ports).difference([egress_port]) |
| 562 | yes_ports = of_ports[1] |
| 563 | |
| 564 | logging.info("Inserting a flow with match on Udp Destination Port ") |
| 565 | logging.info("Sending matching and non-matching packets") |
| 566 | logging.info("Verifying matching packets implements the action specified in the flow") |
| 567 | |
| 568 | (pkt,match) = match_udp_dst(self,of_ports) |
| 569 | |
| 570 | #Sending packet matching the tcp_dport, verify it implements the action |
| 571 | self.dataplane.send(of_ports[0], str(pkt)) |
| 572 | |
| 573 | #Verify packet implements the action specified in the flow |
| 574 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 575 | |
| 576 | #Sending non matching packet , verify Packetin event gets triggered. |
| 577 | pkt2 = simple_udp_packet(udp_dport=541); |
| 578 | self.dataplane.send(of_ports[0], str(pkt2)) |
Rich Lane | 4c504f3 | 2013-06-07 17:24:14 -0700 | [diff] [blame] | 579 | verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH) |
Shudong Zhou | c2f1876 | 2013-01-11 00:12:44 -0800 | [diff] [blame] | 580 | |
| 581 | class ICMPType(base_tests.SimpleDataPlane): |
| 582 | |
| 583 | """Verify match on Single header field -- ICMP type, """ |
| 584 | |
| 585 | def runTest(self): |
| 586 | |
| 587 | logging.info("Running ICMP type test") |
| 588 | |
| 589 | of_ports = config["port_map"].keys() |
| 590 | of_ports.sort() |
| 591 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 592 | |
| 593 | #Clear Switch State |
| 594 | delete_all_flows(self.controller) |
| 595 | |
| 596 | egress_port=of_ports[1] |
| 597 | no_ports=set(of_ports).difference([egress_port]) |
| 598 | yes_ports = of_ports[1] |
| 599 | |
| 600 | logging.info("Inserting a flow with match on ICMP type") |
| 601 | logging.info("Sending matching and non-matching ICMP packets") |
| 602 | logging.info("Verifying matching packets implements the action specified in the flow") |
| 603 | |
| 604 | (pkt,match) = match_icmp_type(self,of_ports) |
| 605 | |
| 606 | #Sending packet matching the tcp_sport, verify it implements the action |
| 607 | self.dataplane.send(of_ports[0], str(pkt)) |
| 608 | |
| 609 | #Verify packet implements the action specified in the flow |
| 610 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 611 | |
| 612 | #Sending non matching packet , verify Packetin event gets triggered. |
| 613 | pkt2 = simple_icmp_packet(icmp_type=10); |
| 614 | self.dataplane.send(of_ports[0], str(pkt2)) |
Rich Lane | 4c504f3 | 2013-06-07 17:24:14 -0700 | [diff] [blame] | 615 | verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH) |
Shudong Zhou | c2f1876 | 2013-01-11 00:12:44 -0800 | [diff] [blame] | 616 | |
| 617 | class ICMPCode(base_tests.SimpleDataPlane): |
| 618 | |
| 619 | """Verify match on Single header field -- ICMP code, """ |
| 620 | |
| 621 | def runTest(self): |
| 622 | |
| 623 | logging.info("Running ICMP code test") |
| 624 | |
| 625 | of_ports = config["port_map"].keys() |
| 626 | of_ports.sort() |
| 627 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 628 | |
| 629 | #Clear Switch State |
| 630 | delete_all_flows(self.controller) |
| 631 | |
| 632 | egress_port=of_ports[1] |
| 633 | no_ports=set(of_ports).difference([egress_port]) |
| 634 | yes_ports = of_ports[1] |
| 635 | |
| 636 | logging.info("Inserting a flow with match on ICMP type") |
| 637 | logging.info("Sending matching and non-matching ICMP packets") |
| 638 | logging.info("Verifying matching packets implements the action specified in the flow") |
| 639 | |
| 640 | (pkt,match) = match_icmp_code(self,of_ports) |
| 641 | |
| 642 | #Sending packet matching the tcp_dport, verify it implements the action |
| 643 | self.dataplane.send(of_ports[0], str(pkt)) |
| 644 | |
| 645 | #Verify packet implements the action specified in the flow |
| 646 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 647 | |
| 648 | #Sending non matching packet , verify Packetin event gets triggered. |
| 649 | pkt2 = simple_icmp_packet(icmp_code=10); |
| 650 | self.dataplane.send(of_ports[0], str(pkt2)) |
Rich Lane | 4c504f3 | 2013-06-07 17:24:14 -0700 | [diff] [blame] | 651 | verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH) |
Shudong Zhou | c2f1876 | 2013-01-11 00:12:44 -0800 | [diff] [blame] | 652 | |
Kiran Poola | ff12e48 | 2013-07-02 14:19:52 -0700 | [diff] [blame] | 653 | class ArpOpcode(base_tests.SimpleDataPlane): |
| 654 | |
| 655 | """"Verify match on single Header Field -- Arp Protocol""" |
| 656 | |
| 657 | def runTest(self): |
| 658 | |
| 659 | logging.info("Running Arp Protocol test") |
| 660 | |
| 661 | of_ports = config["port_map"].keys() |
| 662 | of_ports.sort() |
| 663 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 664 | |
| 665 | #Clear Switch State |
| 666 | delete_all_flows(self.controller) |
| 667 | |
| 668 | egress_port=of_ports[1] |
| 669 | no_ports=set(of_ports).difference([egress_port]) |
| 670 | yes_ports = of_ports[1] |
| 671 | |
| 672 | logging.info("Inserting a flow with match on Arp Protocol Opcode") |
| 673 | logging.info("Sending matching and non-matching arp packets") |
| 674 | logging.info("Verifying only matching packets implements the action specified in the flow") |
| 675 | |
| 676 | #Create a flow matching on ARP Opcode |
| 677 | (pkt,match) = match_arp_opcode(self,of_ports) |
| 678 | |
| 679 | #Send Packet matching the flow |
| 680 | self.dataplane.send(of_ports[0], str(pkt)) |
| 681 | |
| 682 | #Verify packet implements the action specified in the flow |
| 683 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 684 | |
| 685 | #Create a non-matching packet , verify packet_in get generated |
| 686 | pkt2 = simple_arp_packet(arp_op=2) |
| 687 | self.dataplane.send(of_ports[0], str(pkt2)) |
| 688 | verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 689 | |
Shudong Zhou | dceec93 | 2013-02-06 01:12:54 -0800 | [diff] [blame] | 690 | class ArpSenderIP(base_tests.SimpleDataPlane): |
| 691 | |
| 692 | """"Verify match on single Header Field -- Arp Protocol""" |
| 693 | |
| 694 | def runTest(self): |
| 695 | |
| 696 | logging.info("Running Arp Protocol test") |
| 697 | |
| 698 | of_ports = config["port_map"].keys() |
| 699 | of_ports.sort() |
| 700 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 701 | |
| 702 | #Clear Switch State |
| 703 | delete_all_flows(self.controller) |
| 704 | |
| 705 | egress_port=of_ports[1] |
| 706 | no_ports=set(of_ports).difference([egress_port]) |
| 707 | yes_ports = of_ports[1] |
| 708 | |
| 709 | logging.info("Inserting a flow with match on Arp Protocol ") |
| 710 | logging.info("Sending matching and non-matching arp packets") |
| 711 | logging.info("Verifying only matching packets implements the action specified in the flow") |
| 712 | |
| 713 | #Create a flow matching on ARP sender IP |
| 714 | (pkt,match) = match_arp_sender(self,of_ports) |
| 715 | |
| 716 | #Send Packet matching the flow |
| 717 | self.dataplane.send(of_ports[0], str(pkt)) |
| 718 | |
| 719 | #Verify packet implements the action specified in the flow |
| 720 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 721 | |
| 722 | #Create a non-matching packet , verify packet_in get generated |
| 723 | pkt2 = simple_arp_packet(ip_snd="10.10.0.10"); |
| 724 | self.dataplane.send(of_ports[0], str(pkt2)) |
Rich Lane | 4c504f3 | 2013-06-07 17:24:14 -0700 | [diff] [blame] | 725 | verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH) |
Shudong Zhou | dceec93 | 2013-02-06 01:12:54 -0800 | [diff] [blame] | 726 | |
| 727 | class ArpTargetIP(base_tests.SimpleDataPlane): |
| 728 | |
| 729 | """"Verify match on single Header Field -- Arp Protocol""" |
| 730 | |
| 731 | def runTest(self): |
| 732 | |
| 733 | logging.info("Running Arp Protocol test") |
| 734 | |
| 735 | of_ports = config["port_map"].keys() |
| 736 | of_ports.sort() |
| 737 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 738 | |
| 739 | #Clear Switch State |
| 740 | delete_all_flows(self.controller) |
| 741 | |
| 742 | egress_port=of_ports[1] |
| 743 | no_ports=set(of_ports).difference([egress_port]) |
| 744 | yes_ports = of_ports[1] |
| 745 | |
| 746 | logging.info("Inserting a flow with match on Arp Protocol ") |
| 747 | logging.info("Sending matching and non-matching arp packets") |
| 748 | logging.info("Verifying only matching packets implements the action specified in the flow") |
| 749 | |
| 750 | #Create a flow matching on ARP target IP |
| 751 | (pkt,match) = match_arp_target(self,of_ports) |
| 752 | |
| 753 | #Send Packet matching the flow |
| 754 | self.dataplane.send(of_ports[0], str(pkt)) |
| 755 | |
| 756 | #Verify packet implements the action specified in the flow |
| 757 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 758 | |
| 759 | #Create a non-matching packet , verify packet_in get generated |
| 760 | pkt2 = simple_arp_packet(ip_tgt="10.10.0.10"); |
| 761 | self.dataplane.send(of_ports[0], str(pkt2)) |
Rich Lane | 4c504f3 | 2013-06-07 17:24:14 -0700 | [diff] [blame] | 762 | verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH) |
Shudong Zhou | dceec93 | 2013-02-06 01:12:54 -0800 | [diff] [blame] | 763 | |
| 764 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 765 | class ExactMatch(base_tests.SimpleDataPlane): |
| 766 | |
| 767 | """Verify match on Single header field -- Exact Match """ |
| 768 | |
| 769 | def runTest(self): |
| 770 | |
| 771 | logging.info("Running Tcp Exact Match test") |
| 772 | |
| 773 | of_ports = config["port_map"].keys() |
| 774 | of_ports.sort() |
| 775 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 776 | |
| 777 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 778 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 779 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 780 | egress_port=of_ports[1] |
| 781 | no_ports=set(of_ports).difference([egress_port]) |
| 782 | yes_ports = of_ports[1] |
| 783 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 784 | logging.info("Inserting a flow with match for Exact Match ") |
| 785 | logging.info("Sending matching and non-matching packets") |
| 786 | logging.info("Verifying matching packets implements the action specified in the flow") |
| 787 | |
| 788 | (pkt,match) = exact_match(self,of_ports) |
| 789 | |
| 790 | #Sending packet matching all the fields of a tcp_packet, verify it implements the action |
| 791 | self.dataplane.send(of_ports[0], str(pkt)) |
| 792 | |
| 793 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 794 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 795 | |
| 796 | #Sending non matching packet , verify Packetin event gets triggered. |
| 797 | pkt2 = simple_tcp_packet(tcp_sport=540); |
| 798 | self.dataplane.send(of_ports[0], str(pkt2)) |
Rich Lane | 4c504f3 | 2013-06-07 17:24:14 -0700 | [diff] [blame] | 799 | verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 800 | |
| 801 | |
| 802 | class MultipleHeaderFieldL4(base_tests.SimpleDataPlane): |
| 803 | |
| 804 | """Verify match on multiple header field -- Tcp Source Port, Tcp Destination Port """ |
| 805 | |
| 806 | def runTest(self): |
| 807 | |
| 808 | logging.info("Running Multiple Header Field L4 test") |
| 809 | |
| 810 | of_ports = config["port_map"].keys() |
| 811 | of_ports.sort() |
| 812 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 813 | |
| 814 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 815 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 816 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 817 | egress_port=of_ports[1] |
| 818 | no_ports=set(of_ports).difference([egress_port]) |
| 819 | yes_ports = of_ports[1] |
| 820 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 821 | logging.info("Inserting a flow with match on Multiple Header Field L4 ") |
| 822 | logging.info("Sending matching and non-matching packets") |
| 823 | logging.info("Verifying matching packets implements the action specified in the flow") |
| 824 | |
| 825 | (pkt,match) = match_mul_l4(self,of_ports) |
| 826 | |
| 827 | #Sending packet matching the tcp_sport and tcp_dport field, verify it implements the action |
| 828 | self.dataplane.send(of_ports[0], str(pkt)) |
| 829 | |
| 830 | #Verify packet implements the action specified in the flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 831 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 832 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 833 | #Sending non matching packet (tcp_dport different), verify Packetin event gets triggered. |
| 834 | pkt2 = simple_tcp_packet(tcp_sport=111,tcp_dport=541); |
| 835 | self.dataplane.send(of_ports[0], str(pkt2)) |
Rich Lane | 4c504f3 | 2013-06-07 17:24:14 -0700 | [diff] [blame] | 836 | verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH) |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 837 | |
| 838 | #Sending non matching packet (tcp_sport different), verify Packetin event gets triggered. |
| 839 | pkt2 = simple_tcp_packet(tcp_sport=100,tcp_dport=112); |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 840 | self.dataplane.send(of_ports[0], str(pkt2)) |
Rich Lane | 4c504f3 | 2013-06-07 17:24:14 -0700 | [diff] [blame] | 841 | verify_packet_in(self, str(pkt2), of_ports[0], ofp.OFPR_NO_MATCH) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 842 | |
| 843 | |
| 844 | class ExactMatchPrio(base_tests.SimpleDataPlane): |
| 845 | |
| 846 | """Verify that Exact Match has highest priority """ |
| 847 | |
| 848 | def runTest(self): |
| 849 | |
| 850 | logging.info("Running Exact Match High Priority test") |
| 851 | |
| 852 | of_ports = config["port_map"].keys() |
| 853 | of_ports.sort() |
| 854 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 855 | |
| 856 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 857 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 858 | |
Rich Lane | ed13065 | 2012-12-31 17:35:33 -0800 | [diff] [blame] | 859 | egress_port=of_ports[2] |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 860 | no_ports=set(of_ports).difference([egress_port]) |
Rich Lane | ed13065 | 2012-12-31 17:35:33 -0800 | [diff] [blame] | 861 | yes_ports = egress_port |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 862 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 863 | logging.info("Inserting a flow with Exact Match (low priority)") |
| 864 | logging.info("Inserting an overlapping wildcarded flow (higher priority)") |
| 865 | logging.info("Sending packets matching both the flows ") |
| 866 | logging.info("Verifying matching packets implements the action specified in the exact match flow") |
| 867 | |
| 868 | #Insert two Overlapping Flows : Exact Match and Wildcard All. |
| 869 | (pkt,match) = exact_match_with_prio(self,of_ports,priority=10) |
| 870 | (pkt2,match2) = wildcard_all(self,of_ports,priority=20); |
| 871 | |
| 872 | #Sending packet matching both the flows , |
| 873 | self.dataplane.send(of_ports[0], str(pkt2)) |
| 874 | |
| 875 | #verify it implements the action specified in Exact Match Flow |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 876 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 877 | |
| 878 | |
| 879 | class WildcardMatchPrio(base_tests.SimpleDataPlane): |
| 880 | |
| 881 | """Verify that Wildcard Match with highest priority overrides the low priority WildcardMatch """ |
| 882 | |
| 883 | def runTest(self): |
| 884 | |
| 885 | logging.info("Running Wildcard Match High Priority test") |
| 886 | |
| 887 | of_ports = config["port_map"].keys() |
| 888 | of_ports.sort() |
| 889 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 890 | |
| 891 | #Clear Switch State |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 892 | delete_all_flows(self.controller) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 893 | |
ShreyaPandita | efdff31 | 2012-11-21 13:35:34 -0500 | [diff] [blame] | 894 | egress_port=of_ports[1] |
| 895 | no_ports=set(of_ports).difference([egress_port]) |
| 896 | yes_ports = of_ports[1] |
| 897 | |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 898 | logging.info("Inserting two wildcarded flows with priorities ") |
| 899 | logging.info("Sending packets matching the flows") |
| 900 | logging.info("Verifying matching packets implements the action specified in the flow with higher priority") |
| 901 | |
| 902 | (pkt,match) = wildcard_all(self,of_ports,priority=20) |
| 903 | (pkt1,match1) = wildcard_all_except_ingress1(self,of_ports,priority=10) |
| 904 | |
| 905 | #Sending packet matching both the flows , verify it implements the action specified by Higher Priority flow |
| 906 | self.dataplane.send(of_ports[0], str(pkt1)) |
ShreyaPandita | 6fbff25 | 2012-11-13 16:56:48 -0500 | [diff] [blame] | 907 | receive_pkt_check(self.dataplane,pkt,[yes_ports],no_ports,self) |
| 908 | |
| 909 | |
| 910 | |
| 911 | |
| 912 | |