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 |
| 22 | |
| 23 | TEST_VID_DEFAULT = 2 |
| 24 | |
| 25 | IPV6_ETHERTYPE = 0x86dd |
| 26 | ETHERTYPE_VLAN = 0x8100 |
| 27 | ETHERTYPE_MPLS = 0x8847 |
| 28 | TCP_PROTOCOL = 0x6 |
| 29 | UDP_PROTOCOL = 0x11 |
| 30 | ICMPV6_PROTOCOL = 0x3a |
| 31 | |
| 32 | |
| 33 | # TESTS |
| 34 | class MatchIPv6Simple(base_tests.SimpleDataPlane): |
| 35 | """ |
| 36 | Just send a packet IPv6 to match a simple entry on the matching table |
| 37 | """ |
| 38 | def runTest(self): |
| 39 | |
| 40 | of_ports = config["port_map"].keys() |
| 41 | of_ports.sort() |
| 42 | ing_port = of_ports[0] |
| 43 | egr_port = of_ports[3] |
| 44 | |
| 45 | # Remove all entries Add entry match all |
| 46 | rc = testutils.delete_all_flows(self.controller, logging) |
| 47 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 48 | |
| 49 | # Add entry match |
| 50 | |
Rich Lane | b625551 | 2013-05-07 14:58:43 -0700 | [diff] [blame^] | 51 | request = ofp.message.flow_add() |
| 52 | port = ofp.oxm.in_port(of_ports[0]) |
| 53 | eth_type = ofp.oxm.eth_type(IPV6_ETHERTYPE) |
| 54 | eth_dst = ofp.oxm.eth_dst(oftest.parse.parse_mac("00:01:02:03:04:05")) |
| 55 | 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] | 56 | |
| 57 | request.match_fields.tlvs.append(port) |
| 58 | request.match_fields.tlvs.append(eth_type) |
| 59 | request.match_fields.tlvs.append(eth_dst) |
| 60 | request.match_fields.tlvs.append(ipv6_src) |
Rich Lane | 6339349 | 2013-01-11 09:21:12 -0800 | [diff] [blame] | 61 | act = ofp.action.output() |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 62 | act.port = of_ports[3] |
| 63 | inst = ofp.instruction.instruction_apply_actions() |
| 64 | inst.actions.add(act) |
| 65 | request.instructions.add(inst) |
| 66 | request.buffer_id = 0xffffffff |
| 67 | |
| 68 | request.priority = 1000 |
| 69 | logging.debug("Adding flow ") |
| 70 | |
| 71 | rv = self.controller.message_send(request) |
| 72 | self.assertTrue(rv != -1, "Failed to insert test flow") |
| 73 | |
| 74 | #Send packet |
| 75 | pkt = testutils.simple_ipv6_packet(dl_dst='00:01:02:03:04:05',ip_src='fe80::2420:52ff:fe8f:5189') |
| 76 | logging.info("Sending IPv6 packet to " + str(ing_port)) |
| 77 | logging.debug("Data: " + str(pkt).encode('hex')) |
| 78 | self.dataplane.send(ing_port, str(pkt)) |
| 79 | |
| 80 | #Receive packet |
| 81 | exp_pkt = testutils.simple_ipv6_packet() |
| 82 | testutils.receive_pkt_verify(self, egr_port, exp_pkt) |
| 83 | |
| 84 | #Remove flows |
| 85 | rc = testutils.delete_all_flows(self.controller, logging) |
| 86 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 87 | |
| 88 | |
| 89 | class MatchICMPv6Simple(base_tests.SimpleDataPlane): |
| 90 | """ |
| 91 | Match on an ICMPv6 packet |
| 92 | """ |
| 93 | def runTest(self): |
| 94 | of_ports = config["port_map"].keys() |
| 95 | of_ports.sort() |
| 96 | ing_port = of_ports[0] |
| 97 | egr_port = of_ports[3] |
| 98 | |
| 99 | # Remove all entries Add entry match all |
| 100 | rc = testutils.delete_all_flows(self.controller, logging) |
| 101 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 102 | |
| 103 | # Add entry match |
| 104 | |
| 105 | request = ofp.message.flow_mod() |
| 106 | request.match.type = ofp.OFPMT_OXM |
| 107 | port = ofp.match.in_port(of_ports[0]) |
| 108 | eth_type = ofp.match.eth_type(IPV6_ETHERTYPE) |
Rich Lane | b625551 | 2013-05-07 14:58:43 -0700 | [diff] [blame^] | 109 | ipv6_src = ofp.match.ipv6_src(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:5189')) |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 110 | ip_proto = ofp.match.ip_proto(ICMPV6_PROTOCOL) |
| 111 | icmpv6_type = ofp.match.icmpv6_type(128) |
| 112 | |
| 113 | request.match_fields.tlvs.append(port) |
| 114 | request.match_fields.tlvs.append(eth_type) |
| 115 | request.match_fields.tlvs.append(ipv6_src) |
| 116 | request.match_fields.tlvs.append(ip_proto) |
| 117 | request.match_fields.tlvs.append(icmpv6_type) |
| 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] |
| 121 | inst = ofp.instruction.instruction_apply_actions() |
| 122 | inst.actions.add(act) |
| 123 | request.instructions.add(inst) |
| 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 | |
| 161 | request = ofp.message.flow_mod() |
| 162 | request.match.type = ofp.OFPMT_OXM |
| 163 | port = ofp.match.in_port(of_ports[0]) |
| 164 | eth_type = ofp.match.eth_type(IPV6_ETHERTYPE) |
Rich Lane | b625551 | 2013-05-07 14:58:43 -0700 | [diff] [blame^] | 165 | ipv6_src = ofp.match.ipv6_src(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:5189')) |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 166 | |
| 167 | request.match_fields.tlvs.append(port) |
| 168 | request.match_fields.tlvs.append(eth_type) |
| 169 | request.match_fields.tlvs.append(ipv6_src) |
| 170 | |
Rich Lane | b625551 | 2013-05-07 14:58:43 -0700 | [diff] [blame^] | 171 | field_2b_set = ofp.match.ipv6_dst(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:DDDD')) |
Rich Lane | 6339349 | 2013-01-11 09:21:12 -0800 | [diff] [blame] | 172 | act_setfield = ofp.action.set_field() |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 173 | act_setfield.field = field_2b_set |
| 174 | |
| 175 | # TODO: insert action set field properly |
Rich Lane | 6339349 | 2013-01-11 09:21:12 -0800 | [diff] [blame] | 176 | act_out = ofp.action.output() |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 177 | act_out.port = of_ports[3] |
| 178 | |
| 179 | |
| 180 | inst = ofp.instruction.instruction_apply_actions() |
| 181 | inst.actions.add(act_setfield) |
| 182 | inst.actions.add(act_out) |
| 183 | request.instructions.add(inst) |
| 184 | request.buffer_id = 0xffffffff |
| 185 | |
| 186 | request.priority = 1000 |
| 187 | logging.debug("Adding flow ") |
| 188 | |
| 189 | rv = self.controller.message_send(request) |
| 190 | self.assertTrue(rv != -1, "Failed to insert test flow") |
| 191 | |
| 192 | #Send packet |
| 193 | pkt = testutils.simple_ipv6_packet(ip_src='fe80::2420:52ff:fe8f:5189',ip_dst='fe80::2420:52ff:fe8f:5190') |
| 194 | logging.info("Sending IPv6 packet to " + str(ing_port)) |
| 195 | logging.debug("Data: " + str(pkt).encode('hex')) |
| 196 | self.dataplane.send(ing_port, str(pkt)) |
| 197 | |
| 198 | #Receive packet |
| 199 | exp_pkt = testutils.simple_ipv6_packet(ip_dst='fe80::2420:52ff:fe8f:DDDD') |
| 200 | testutils.receive_pkt_verify(self, egr_port, exp_pkt) |
| 201 | |
| 202 | #See flow match |
| 203 | response = testutils.flow_stats_get(self) |
| 204 | logging.debug("Response" + response.show()) |
| 205 | |
| 206 | #Remove flows |
| 207 | rc = testutils.delete_all_flows(self.controller, logging) |
| 208 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 209 | |
| 210 | |
| 211 | class MatchIPv6TCP(base_tests.SimpleDataPlane): |
| 212 | |
| 213 | def runTest(self): |
| 214 | # Config |
| 215 | of_ports = config["port_map"].keys() |
| 216 | of_ports.sort() |
| 217 | ing_port = of_ports[0] |
| 218 | egr_port = of_ports[3] |
| 219 | |
| 220 | # Remove flows |
| 221 | rc = testutils.delete_all_flows(self.controller, logging) |
| 222 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 223 | |
| 224 | # Add entry match |
| 225 | |
| 226 | request = ofp.message.flow_mod() |
| 227 | request.match.type = ofp.OFPMT_OXM |
| 228 | port = ofp.match.in_port(of_ports[0]) |
| 229 | eth_type = ofp.match.eth_type(IPV6_ETHERTYPE) |
Rich Lane | b625551 | 2013-05-07 14:58:43 -0700 | [diff] [blame^] | 230 | ipv6_src = ofp.match.ipv6_src(oftest.parse.parse_ipv6('fe80::2420:52ff:fe8f:5189')) |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 231 | ip_proto = ofp.match.ip_proto(TCP_PROTOCOL) |
| 232 | tcp_port = ofp.match.tcp_src(80) |
| 233 | |
| 234 | |
| 235 | request.match_fields.tlvs.append(port) |
| 236 | request.match_fields.tlvs.append(eth_type) |
| 237 | request.match_fields.tlvs.append(ipv6_src) |
| 238 | request.match_fields.tlvs.append(ip_proto) |
| 239 | request.match_fields.tlvs.append(tcp_port) |
| 240 | |
Rich Lane | 6339349 | 2013-01-11 09:21:12 -0800 | [diff] [blame] | 241 | act = ofp.action.output() |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 242 | act.port = of_ports[3] |
| 243 | inst = ofp.instruction.instruction_apply_actions() |
| 244 | inst.actions.add(act) |
| 245 | request.instructions.add(inst) |
| 246 | request.buffer_id = 0xffffffff |
| 247 | |
| 248 | request.priority = 1000 |
| 249 | logging.debug("Adding flow ") |
| 250 | |
| 251 | rv = self.controller.message_send(request) |
| 252 | self.assertTrue(rv != -1, "Failed to send test flow") |
| 253 | |
| 254 | #Send packet |
| 255 | pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080) |
| 256 | |
| 257 | logging.info("Sending IPv6 packet to " + str(ing_port)) |
| 258 | logging.debug("Data: " + str(pkt).encode('hex')) |
| 259 | |
| 260 | self.dataplane.send(ing_port, str(pkt)) |
| 261 | |
| 262 | #Receive packet |
| 263 | exp_pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080) |
| 264 | |
| 265 | testutils.receive_pkt_verify(self, egr_port, exp_pkt) |
| 266 | |
| 267 | #Remove flows |
| 268 | rc = testutils.delete_all_flows(self.controller, logging) |
| 269 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 270 | |
| 271 | if __name__ == "__main__": |
| 272 | print "Please run through oft script: ./oft --test-spec=ipv6" |