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 | |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 17 | """ |
| 18 | Test cases for testing actions taken on packets |
| 19 | |
| 20 | See basic.py for other info. |
| 21 | |
| 22 | It is recommended that these definitions be kept in their own |
| 23 | namespace as different groups of tests will likely define |
| 24 | similar identifiers. |
| 25 | |
| 26 | The switch is actively attempting to contact the controller at the address |
| 27 | indicated oin oft_config |
| 28 | |
| 29 | """ |
| 30 | |
| 31 | import logging |
| 32 | import ipaddr |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 33 | |
| 34 | from oftest import config |
| 35 | import ofp |
| 36 | import oftest.oft12.testutils as testutils |
| 37 | import oftest.base_tests as base_tests |
Rich Lane | cfff0ae | 2013-05-07 15:49:10 -0700 | [diff] [blame] | 38 | import oftest.parse |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 39 | |
| 40 | TEST_VID_DEFAULT = 2 |
| 41 | |
| 42 | IPV6_ETHERTYPE = 0x86dd |
| 43 | ETHERTYPE_VLAN = 0x8100 |
| 44 | ETHERTYPE_MPLS = 0x8847 |
| 45 | TCP_PROTOCOL = 0x6 |
| 46 | UDP_PROTOCOL = 0x11 |
| 47 | ICMPV6_PROTOCOL = 0x3a |
| 48 | |
| 49 | |
| 50 | # TESTS |
| 51 | class MatchIPv6Simple(base_tests.SimpleDataPlane): |
| 52 | """ |
| 53 | Just send a packet IPv6 to match a simple entry on the matching table |
| 54 | """ |
| 55 | def runTest(self): |
| 56 | |
| 57 | of_ports = config["port_map"].keys() |
| 58 | of_ports.sort() |
| 59 | ing_port = of_ports[0] |
| 60 | egr_port = of_ports[3] |
| 61 | |
| 62 | # Remove all entries Add entry match all |
| 63 | rc = testutils.delete_all_flows(self.controller, logging) |
| 64 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 65 | |
| 66 | # Add entry match |
| 67 | |
Rich Lane | b625551 | 2013-05-07 14:58:43 -0700 | [diff] [blame] | 68 | request = ofp.message.flow_add() |
| 69 | port = ofp.oxm.in_port(of_ports[0]) |
| 70 | eth_type = ofp.oxm.eth_type(IPV6_ETHERTYPE) |
| 71 | eth_dst = ofp.oxm.eth_dst(oftest.parse.parse_mac("00:01:02:03:04:05")) |
| 72 | ipv6_src = ofp.oxm.ipv6_src(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:5189')) |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 73 | |
Rich Lane | cfff0ae | 2013-05-07 15:49:10 -0700 | [diff] [blame] | 74 | request.match.oxm_list.append(port) |
| 75 | request.match.oxm_list.append(eth_type) |
| 76 | request.match.oxm_list.append(eth_dst) |
| 77 | request.match.oxm_list.append(ipv6_src) |
Rich Lane | 6339349 | 2013-01-11 09:21:12 -0800 | [diff] [blame] | 78 | act = ofp.action.output() |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 79 | act.port = of_ports[3] |
Rich Lane | cfff0ae | 2013-05-07 15:49:10 -0700 | [diff] [blame] | 80 | inst = ofp.instruction.apply_actions() |
| 81 | inst.actions.append(act) |
| 82 | request.instructions.append(inst) |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 83 | request.buffer_id = 0xffffffff |
| 84 | |
| 85 | request.priority = 1000 |
| 86 | logging.debug("Adding flow ") |
| 87 | |
| 88 | rv = self.controller.message_send(request) |
| 89 | self.assertTrue(rv != -1, "Failed to insert test flow") |
| 90 | |
| 91 | #Send packet |
| 92 | pkt = testutils.simple_ipv6_packet(dl_dst='00:01:02:03:04:05',ip_src='fe80::2420:52ff:fe8f:5189') |
| 93 | logging.info("Sending IPv6 packet to " + str(ing_port)) |
| 94 | logging.debug("Data: " + str(pkt).encode('hex')) |
| 95 | self.dataplane.send(ing_port, str(pkt)) |
| 96 | |
| 97 | #Receive packet |
| 98 | exp_pkt = testutils.simple_ipv6_packet() |
| 99 | testutils.receive_pkt_verify(self, egr_port, exp_pkt) |
| 100 | |
| 101 | #Remove flows |
| 102 | rc = testutils.delete_all_flows(self.controller, logging) |
| 103 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 104 | |
| 105 | |
| 106 | class MatchICMPv6Simple(base_tests.SimpleDataPlane): |
| 107 | """ |
| 108 | Match on an ICMPv6 packet |
| 109 | """ |
| 110 | def runTest(self): |
| 111 | of_ports = config["port_map"].keys() |
| 112 | of_ports.sort() |
| 113 | ing_port = of_ports[0] |
| 114 | egr_port = of_ports[3] |
| 115 | |
| 116 | # Remove all entries Add entry match all |
| 117 | rc = testutils.delete_all_flows(self.controller, logging) |
| 118 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 119 | |
| 120 | # Add entry match |
| 121 | |
Rich Lane | cfff0ae | 2013-05-07 15:49:10 -0700 | [diff] [blame] | 122 | request = ofp.message.flow_add() |
| 123 | port = ofp.oxm.in_port(of_ports[0]) |
| 124 | eth_type = ofp.oxm.eth_type(IPV6_ETHERTYPE) |
| 125 | ipv6_src = ofp.oxm.ipv6_src(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:5189')) |
| 126 | ip_proto = ofp.oxm.ip_proto(ICMPV6_PROTOCOL) |
| 127 | icmpv6_type = ofp.oxm.icmpv6_type(128) |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 128 | |
Rich Lane | cfff0ae | 2013-05-07 15:49:10 -0700 | [diff] [blame] | 129 | request.match.oxm_list.append(port) |
| 130 | request.match.oxm_list.append(eth_type) |
| 131 | request.match.oxm_list.append(ipv6_src) |
| 132 | request.match.oxm_list.append(ip_proto) |
| 133 | request.match.oxm_list.append(icmpv6_type) |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 134 | |
Rich Lane | 6339349 | 2013-01-11 09:21:12 -0800 | [diff] [blame] | 135 | act = ofp.action.output() |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 136 | act.port = of_ports[3] |
Rich Lane | cfff0ae | 2013-05-07 15:49:10 -0700 | [diff] [blame] | 137 | inst = ofp.instruction.apply_actions() |
| 138 | inst.actions.append(act) |
| 139 | request.instructions.append(inst) |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 140 | request.buffer_id = 0xffffffff |
| 141 | |
| 142 | request.priority = 1000 |
| 143 | logging.debug("Adding flow ") |
| 144 | |
| 145 | rv = self.controller.message_send(request) |
| 146 | self.assertTrue(rv != -1, "Failed to insert test flow") |
| 147 | |
| 148 | #Send packet |
| 149 | pkt = testutils.simple_icmpv6_packet() |
| 150 | logging.info("Sending IPv6 packet to " + str(ing_port)) |
| 151 | logging.debug("Data: " + str(pkt).encode('hex')) |
| 152 | self.dataplane.send(ing_port, str(pkt)) |
| 153 | |
| 154 | #Receive packet |
| 155 | exp_pkt = testutils.simple_icmpv6_packet() |
| 156 | testutils.receive_pkt_verify(self, egr_port, exp_pkt) |
| 157 | |
| 158 | #Remove flows |
| 159 | rc = testutils.delete_all_flows(self.controller, logging) |
| 160 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 161 | |
| 162 | |
| 163 | class IPv6SetField(base_tests.SimpleDataPlane): |
| 164 | |
| 165 | def runTest(self): |
| 166 | of_ports = config["port_map"].keys() |
| 167 | of_ports.sort() |
| 168 | ing_port = of_ports[0] |
| 169 | egr_port = of_ports[3] |
| 170 | |
| 171 | # Remove all entries Add entry match all |
| 172 | rc = testutils.delete_all_flows(self.controller, logging) |
| 173 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 174 | |
| 175 | # Add entry match |
| 176 | |
Rich Lane | cfff0ae | 2013-05-07 15:49:10 -0700 | [diff] [blame] | 177 | request = ofp.message.flow_add() |
| 178 | port = ofp.oxm.in_port(of_ports[0]) |
| 179 | eth_type = ofp.oxm.eth_type(IPV6_ETHERTYPE) |
| 180 | ipv6_src = ofp.oxm.ipv6_src(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:5189')) |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 181 | |
Rich Lane | cfff0ae | 2013-05-07 15:49:10 -0700 | [diff] [blame] | 182 | request.match.oxm_list.append(port) |
| 183 | request.match.oxm_list.append(eth_type) |
| 184 | request.match.oxm_list.append(ipv6_src) |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 185 | |
Rich Lane | cfff0ae | 2013-05-07 15:49:10 -0700 | [diff] [blame] | 186 | field_2b_set = ofp.oxm.ipv6_dst(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:DDDD')) |
Rich Lane | 6339349 | 2013-01-11 09:21:12 -0800 | [diff] [blame] | 187 | act_setfield = ofp.action.set_field() |
Rich Lane | cfff0ae | 2013-05-07 15:49:10 -0700 | [diff] [blame] | 188 | act_setfield.field = field_2b_set.pack() # HACK |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 189 | |
| 190 | # TODO: insert action set field properly |
Rich Lane | 6339349 | 2013-01-11 09:21:12 -0800 | [diff] [blame] | 191 | act_out = ofp.action.output() |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 192 | act_out.port = of_ports[3] |
| 193 | |
| 194 | |
Rich Lane | cfff0ae | 2013-05-07 15:49:10 -0700 | [diff] [blame] | 195 | inst = ofp.instruction.apply_actions() |
| 196 | inst.actions.append(act_setfield) |
| 197 | inst.actions.append(act_out) |
| 198 | request.instructions.append(inst) |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 199 | request.buffer_id = 0xffffffff |
| 200 | |
| 201 | request.priority = 1000 |
| 202 | logging.debug("Adding flow ") |
| 203 | |
| 204 | rv = self.controller.message_send(request) |
| 205 | self.assertTrue(rv != -1, "Failed to insert test flow") |
| 206 | |
| 207 | #Send packet |
| 208 | pkt = testutils.simple_ipv6_packet(ip_src='fe80::2420:52ff:fe8f:5189',ip_dst='fe80::2420:52ff:fe8f:5190') |
| 209 | logging.info("Sending IPv6 packet to " + str(ing_port)) |
| 210 | logging.debug("Data: " + str(pkt).encode('hex')) |
| 211 | self.dataplane.send(ing_port, str(pkt)) |
| 212 | |
| 213 | #Receive packet |
| 214 | exp_pkt = testutils.simple_ipv6_packet(ip_dst='fe80::2420:52ff:fe8f:DDDD') |
| 215 | testutils.receive_pkt_verify(self, egr_port, exp_pkt) |
| 216 | |
| 217 | #See flow match |
| 218 | response = testutils.flow_stats_get(self) |
| 219 | logging.debug("Response" + response.show()) |
| 220 | |
| 221 | #Remove flows |
| 222 | rc = testutils.delete_all_flows(self.controller, logging) |
| 223 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 224 | |
| 225 | |
| 226 | class MatchIPv6TCP(base_tests.SimpleDataPlane): |
| 227 | |
| 228 | def runTest(self): |
| 229 | # Config |
| 230 | of_ports = config["port_map"].keys() |
| 231 | of_ports.sort() |
| 232 | ing_port = of_ports[0] |
| 233 | egr_port = of_ports[3] |
| 234 | |
| 235 | # Remove flows |
| 236 | rc = testutils.delete_all_flows(self.controller, logging) |
| 237 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 238 | |
| 239 | # Add entry match |
| 240 | |
Rich Lane | cfff0ae | 2013-05-07 15:49:10 -0700 | [diff] [blame] | 241 | request = ofp.message.flow_add() |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 242 | request.match.type = ofp.OFPMT_OXM |
Rich Lane | cfff0ae | 2013-05-07 15:49:10 -0700 | [diff] [blame] | 243 | port = ofp.oxm.in_port(of_ports[0]) |
| 244 | eth_type = ofp.oxm.eth_type(IPV6_ETHERTYPE) |
| 245 | ipv6_src = ofp.oxm.ipv6_src(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:5189')) |
| 246 | ip_proto = ofp.oxm.ip_proto(TCP_PROTOCOL) |
| 247 | tcp_port = ofp.oxm.tcp_src(80) |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 248 | |
| 249 | |
Rich Lane | cfff0ae | 2013-05-07 15:49:10 -0700 | [diff] [blame] | 250 | request.match.oxm_list.append(port) |
| 251 | request.match.oxm_list.append(eth_type) |
| 252 | request.match.oxm_list.append(ipv6_src) |
| 253 | request.match.oxm_list.append(ip_proto) |
| 254 | request.match.oxm_list.append(tcp_port) |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 255 | |
Rich Lane | 6339349 | 2013-01-11 09:21:12 -0800 | [diff] [blame] | 256 | act = ofp.action.output() |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 257 | act.port = of_ports[3] |
Rich Lane | cfff0ae | 2013-05-07 15:49:10 -0700 | [diff] [blame] | 258 | inst = ofp.instruction.apply_actions() |
| 259 | inst.actions.append(act) |
| 260 | request.instructions.append(inst) |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 261 | request.buffer_id = 0xffffffff |
| 262 | |
| 263 | request.priority = 1000 |
| 264 | logging.debug("Adding flow ") |
| 265 | |
| 266 | rv = self.controller.message_send(request) |
| 267 | self.assertTrue(rv != -1, "Failed to send test flow") |
| 268 | |
| 269 | #Send packet |
| 270 | pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080) |
| 271 | |
| 272 | logging.info("Sending IPv6 packet to " + str(ing_port)) |
| 273 | logging.debug("Data: " + str(pkt).encode('hex')) |
| 274 | |
| 275 | self.dataplane.send(ing_port, str(pkt)) |
| 276 | |
| 277 | #Receive packet |
| 278 | exp_pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080) |
| 279 | |
| 280 | testutils.receive_pkt_verify(self, egr_port, exp_pkt) |
| 281 | |
| 282 | #Remove flows |
| 283 | rc = testutils.delete_all_flows(self.controller, logging) |
| 284 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 285 | |
| 286 | if __name__ == "__main__": |
| 287 | print "Please run through oft script: ./oft --test-spec=ipv6" |