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