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