macauley | 6095251 | 2015-07-16 17:40:59 +0800 | [diff] [blame] | 1 | # Distributed under the OpenFlow Software License (see LICENSE) |
| 2 | # Copyright (c) 2010 The Board of Trustees of The Leland Stanford Junior University |
| 3 | # Copyright (c) 2012, 2013 Big Switch Networks, Inc. |
| 4 | # Copyright (c) 2012, 2013 CPqD |
| 5 | # Copyright (c) 2012, 2013 Ericsson |
| 6 | # Copyright (c) 2015 Research Education and Advanced Network New Zealand Ltd. |
| 7 | """ |
| 8 | Basic test cases |
| 9 | |
| 10 | Test cases in other modules depend on this functionality. |
| 11 | """ |
| 12 | |
| 13 | import logging |
| 14 | |
| 15 | from oftest import config |
| 16 | import oftest.base_tests as base_tests |
| 17 | import ofp |
| 18 | import time |
| 19 | from oftest.testutils import * |
| 20 | |
| 21 | |
| 22 | |
| 23 | class case1(base_tests.SimpleDataPlane): |
macauley | d72b867 | 2015-08-04 17:33:14 +0800 | [diff] [blame^] | 24 | """ |
| 25 | packet come from port 1 (DIP=192.168.1.100 and DMAC=00:00:00:00:00:10, VLAN=100), |
| 26 | forward to port 2 untag |
| 27 | """ |
macauley | 6095251 | 2015-07-16 17:40:59 +0800 | [diff] [blame] | 28 | def runTest(self): |
| 29 | ports = sorted(config["port_map"].keys()) |
| 30 | |
| 31 | delete_all_flows(self.controller) |
| 32 | delete_all_groups(self.controller) |
| 33 | |
| 34 | #l2-interface-grup_port1_vlann100_untag |
| 35 | grouptype = 0 |
| 36 | vlanid = 100 |
| 37 | of_port=1 |
| 38 | group_id = of_port + (vlanid << 16) + (grouptype << 28) |
| 39 | actions = [ |
| 40 | ofp.action.pop_vlan(), |
| 41 | ofp.action.output(of_port), |
| 42 | ] |
| 43 | buckets = [ |
| 44 | ofp.bucket(actions=actions), |
| 45 | ] |
| 46 | request = ofp.message.group_add( |
| 47 | group_type=ofp.OFPGT_INDIRECT, |
| 48 | group_id=group_id, |
| 49 | buckets=buckets |
| 50 | ) |
| 51 | self.controller.message_send(request) |
| 52 | #l2-interface-grup_port2_vlann100_untag |
| 53 | grouptype = 0 |
| 54 | vlanid = 100 |
| 55 | of_port=2 |
| 56 | group_id = of_port + (vlanid << 16) + (grouptype << 28) |
| 57 | actions = [ |
| 58 | ofp.action.pop_vlan(), |
| 59 | ofp.action.output(of_port), |
| 60 | ] |
| 61 | buckets = [ |
| 62 | ofp.bucket(actions=actions), |
| 63 | ] |
| 64 | request = ofp.message.group_add( |
| 65 | group_type=ofp.OFPGT_INDIRECT, |
| 66 | group_id=group_id, |
| 67 | buckets=buckets |
| 68 | ) |
| 69 | self.controller.message_send(request) |
| 70 | |
| 71 | #10_add_port1_allow_rx_tag_vid_100 |
| 72 | match = ofp.match() |
| 73 | of_port=1 |
| 74 | vlanid=100 |
| 75 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
| 76 | match.oxm_list.append(ofp.oxm.vlan_vid(0x1000|vlanid)) |
| 77 | request = ofp.message.flow_add( |
| 78 | table_id=10, |
| 79 | cookie=42, |
| 80 | match=match, |
| 81 | instructions=[ |
| 82 | ofp.instruction.goto_table(20) |
| 83 | ], |
| 84 | priority=0) |
| 85 | logging.info("Set vlan-1 tagged on port %d, and goto table 20" % of_port) |
| 86 | self.controller.message_send(request) |
| 87 | """ |
| 88 | #50_mac_0000000010_vlan_100 |
| 89 | grouptype = 0 |
| 90 | vlanid = 100 |
| 91 | out_port=2 |
| 92 | group_id = out_port + (vlanid << 16) + (grouptype << 28) |
| 93 | match = ofp.match() |
| 94 | match.oxm_list.append(ofp.oxm.eth_dst([0x00, 0x00, 0x00, 0x00, 0x00, 0x10])) |
| 95 | match.oxm_list.append(ofp.oxm.vlan_vid(vlanid)) |
| 96 | request = ofp.message.flow_add( |
| 97 | table_id=50, |
| 98 | cookie=42, |
| 99 | match=match, |
| 100 | instructions=[ |
| 101 | ofp.instruction.write_actions( |
| 102 | actions=[ |
| 103 | ofp.action.group(group_id)]), |
| 104 | ofp.instruction.goto_table(60) |
| 105 | ], |
| 106 | buffer_id=ofp.OFP_NO_BUFFER, |
| 107 | priority=1000) |
| 108 | |
| 109 | logging.info("Inserting Bridge flow sending matching packets to port %d", out_port) |
| 110 | self.controller.message_send(request) |
| 111 | do_barrier(self.controller) |
| 112 | """ |
| 113 | #60_acl |
| 114 | |
| 115 | grouptype = 0 |
| 116 | vlanid = 100 |
| 117 | out_port=2 |
| 118 | group_id = out_port + (vlanid << 16) + (grouptype << 28) |
| 119 | match = ofp.match() |
| 120 | match.oxm_list.append(ofp.oxm.eth_dst([0x00, 0x00, 0x00, 0x00, 0x00, 0x10])) |
| 121 | match.oxm_list.append(ofp.oxm.vlan_vid(vlanid)) |
| 122 | match.oxm_list.append(ofp.oxm.eth_type(0x0800)) |
| 123 | match.oxm_list.append(ofp.oxm.ipv4_dst_masked(0xc0010164, 32)) |
| 124 | request = ofp.message.flow_add( |
| 125 | table_id=60, |
| 126 | cookie=42, |
| 127 | match=match, |
| 128 | instructions=[ |
| 129 | ofp.instruction.apply_actions( |
| 130 | actions=[ |
| 131 | ofp.action.group(group_id)]) |
| 132 | ], |
| 133 | buffer_id=ofp.OFP_NO_BUFFER, |
| 134 | priority=1000) |
| 135 | |
| 136 | logging.info("Inserting ACL flow sending matching packets to port %d", out_port) |
| 137 | self.controller.message_send(request) |
| 138 | do_barrier(self.controller) |
| 139 | |
| 140 | #send packet on port 1 |
| 141 | in_port=1 |
| 142 | out_port=2 |
| 143 | parsed_pkt = simple_tcp_packet(pktlen=104, |
| 144 | eth_dst='00:00:00:00:00:10', |
| 145 | dl_vlan_enable=True, |
| 146 | vlan_vid=100, |
| 147 | ip_dst='192.168.1.100') |
| 148 | pkt = str(parsed_pkt) |
| 149 | logging.info("Send packet on port %d, out port %d", in_port, out_port) |
| 150 | self.dataplane.send(in_port, pkt) |
| 151 | #construct verify packet content |
| 152 | parsed_pkt = simple_tcp_packet(pktlen=100, |
| 153 | eth_dst='00:00:00:00:00:10', |
| 154 | ip_dst='192.168.1.100') |
| 155 | verify_packet(self, parsed_pkt, out_port) |
| 156 | |
| 157 | verify_no_other_packets(self) |
| 158 | |
| 159 | #send packet on port 1, again but diff DST IP |
| 160 | in_port=1 |
| 161 | out_port=2 |
| 162 | parsed_pkt = simple_tcp_packet(pktlen=104, |
| 163 | eth_dst='00:00:00:00:00:10', |
| 164 | dl_vlan_enable=True, |
| 165 | vlan_vid=100, |
| 166 | ip_dst='192.168.1.200') |
| 167 | pkt = str(parsed_pkt) |
| 168 | logging.info("Send packet on port %d, out port %d", in_port, out_port) |
| 169 | self.dataplane.send(in_port, pkt) |
| 170 | #construct verify packet content |
| 171 | parsed_pkt = simple_tcp_packet(pktlen=100, |
| 172 | eth_dst='00:00:00:00:00:10', |
| 173 | ip_dst='192.168.1.200') |
| 174 | verify_no_packet(self, parsed_pkt, out_port) |
| 175 | |
| 176 | verify_no_other_packets(self) |
macauley | d72b867 | 2015-08-04 17:33:14 +0800 | [diff] [blame^] | 177 | |
| 178 | |
| 179 | class case2(base_tests.SimpleDataPlane): |
| 180 | """ |
| 181 | packet come from port 1 (SIP=192.168.1.100 and SMAC=00:00:00:00:00:20, VLAN=200, TCP), |
| 182 | forward to port 2 VLAN 300 |
| 183 | """ |
| 184 | def runTest(self): |
| 185 | ports = sorted(config["port_map"].keys()) |
| 186 | |
| 187 | delete_all_flows(self.controller) |
| 188 | delete_all_groups(self.controller) |
| 189 | |
| 190 | #l2-interface-grup_port1_vlann200_untag |
| 191 | grouptype = 0 |
| 192 | vlanid = 200 |
| 193 | of_port=1 |
| 194 | group_id = of_port + (vlanid << 16) + (grouptype << 28) |
| 195 | actions = [ |
| 196 | ofp.action.pop_vlan(), |
| 197 | ofp.action.output(of_port), |
| 198 | ] |
| 199 | buckets = [ |
| 200 | ofp.bucket(actions=actions), |
| 201 | ] |
| 202 | request = ofp.message.group_add( |
| 203 | group_type=ofp.OFPGT_INDIRECT, |
| 204 | group_id=group_id, |
| 205 | buckets=buckets |
| 206 | ) |
| 207 | self.controller.message_send(request) |
| 208 | #l2-interface-grup_port2_vlann300 |
| 209 | grouptype = 0 |
| 210 | vlanid = 300 |
| 211 | of_port=2 |
| 212 | group_id = of_port + (vlanid << 16) + (grouptype << 28) |
| 213 | actions = [ |
| 214 | ofp.action.output(of_port), |
| 215 | ] |
| 216 | buckets = [ |
| 217 | ofp.bucket(actions=actions), |
| 218 | ] |
| 219 | request = ofp.message.group_add( |
| 220 | group_type=ofp.OFPGT_INDIRECT, |
| 221 | group_id=group_id, |
| 222 | buckets=buckets |
| 223 | ) |
| 224 | self.controller.message_send(request) |
| 225 | |
| 226 | #rewrite_group_vlan_200_to_300, use l2-interface-grup_port2_vlann300 group_id |
| 227 | grouptype = 1 |
| 228 | vlanid = 300 |
| 229 | rw_group_id = 2 + (grouptype << 28) |
| 230 | |
| 231 | action=[] |
| 232 | action.append(ofp.action.set_field(ofp.oxm.vlan_vid(vlanid))) |
| 233 | action.append(ofp.action.group(group_id)) |
| 234 | buckets = [ofp.bucket(actions=action)] |
| 235 | request = ofp.message.group_add( |
| 236 | group_type=ofp.OFPGT_INDIRECT, |
| 237 | group_id=rw_group_id, |
| 238 | buckets=buckets |
| 239 | ) |
| 240 | self.controller.message_send(request) |
| 241 | |
| 242 | #10_add_port1_allow_rx_tag_vid_200 |
| 243 | match = ofp.match() |
| 244 | of_port=1 |
| 245 | vlanid=200 |
| 246 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
| 247 | match.oxm_list.append(ofp.oxm.vlan_vid(0x1000|vlanid)) |
| 248 | request = ofp.message.flow_add( |
| 249 | table_id=10, |
| 250 | cookie=42, |
| 251 | match=match, |
| 252 | instructions=[ |
| 253 | ofp.instruction.goto_table(20) |
| 254 | ], |
| 255 | priority=0) |
| 256 | logging.info("Set vlan-1 tagged on port %d, and goto table 20" % of_port) |
| 257 | self.controller.message_send(request) |
| 258 | |
| 259 | |
| 260 | #60_acl |
| 261 | grouptype = 1 |
| 262 | vlanid = 200 |
| 263 | rw_group_id = 2 + (grouptype << 28) |
| 264 | match = ofp.match() |
| 265 | match.oxm_list.append(ofp.oxm.in_port(1)) |
| 266 | match.oxm_list.append(ofp.oxm.eth_src([0x00, 0x00, 0x00, 0x00, 0x00, 0x20])) |
| 267 | match.oxm_list.append(ofp.oxm.vlan_vid(vlanid)) |
| 268 | match.oxm_list.append(ofp.oxm.eth_type(0x0800)) |
| 269 | match.oxm_list.append(ofp.oxm.ipv4_src(0xc0a80164)) |
| 270 | match.oxm_list.append(ofp.oxm.ip_proto(6)) |
| 271 | |
| 272 | request = ofp.message.flow_add( |
| 273 | table_id=60, |
| 274 | cookie=42, |
| 275 | match=match, |
| 276 | instructions=[ |
| 277 | ofp.instruction.apply_actions( |
| 278 | actions=[ |
| 279 | ofp.action.group(rw_group_id)]) |
| 280 | ], |
| 281 | buffer_id=ofp.OFP_NO_BUFFER, |
| 282 | priority=1000) |
| 283 | |
| 284 | self.controller.message_send(request) |
| 285 | do_barrier(self.controller) |
| 286 | |
| 287 | #send packet on port 1 |
| 288 | in_port=1 |
| 289 | out_port=2 |
| 290 | parsed_pkt = simple_tcp_packet(pktlen=104, |
| 291 | eth_src='00:00:00:00:00:20', |
| 292 | dl_vlan_enable=True, |
| 293 | vlan_vid=200, |
| 294 | ip_src='192.168.1.100') |
| 295 | pkt = str(parsed_pkt) |
| 296 | logging.info("Send packet on port %d, out port %d", in_port, out_port) |
| 297 | self.dataplane.send(in_port, pkt) |
| 298 | #construct verify packet content |
| 299 | parsed_pkt = simple_tcp_packet(pktlen=104, |
| 300 | eth_src='00:00:00:00:00:20', |
| 301 | dl_vlan_enable=True, |
| 302 | vlan_vid=300, |
| 303 | ip_src='192.168.1.100') |
| 304 | verify_packet(self, parsed_pkt, out_port) |
| 305 | |
| 306 | verify_no_other_packets(self) |
| 307 | |
| 308 | #send packet on port 1, again but diff SRC IP |
| 309 | in_port=1 |
| 310 | out_port=2 |
| 311 | parsed_pkt = simple_tcp_packet(pktlen=104, |
| 312 | eth_src='00:00:00:00:00:20', |
| 313 | dl_vlan_enable=True, |
| 314 | vlan_vid=100, |
| 315 | ip_src='192.168.1.200') |
| 316 | pkt = str(parsed_pkt) |
| 317 | logging.info("Send packet on port %d, out port %d", in_port, out_port) |
| 318 | self.dataplane.send(in_port, pkt) |
| 319 | verify_no_packet(self, pkt, out_port) |
| 320 | |
| 321 | verify_no_other_packets(self) |