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