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