Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 1 | ''' |
| 2 | OFTests for functionality needed from the OLT. |
| 3 | ''' |
| 4 | import logging |
| 5 | from oftest import config |
| 6 | import oftest.base_tests as base_tests |
| 7 | import oftest.packet as scapy |
| 8 | |
| 9 | import ofp |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 10 | import time |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 11 | |
| 12 | from oftest.testutils import * |
| 13 | |
| 14 | onu_port = test_param_get("onu_port", 1) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 15 | onu_port2 = test_param_get("onu_port2", 2) |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 16 | olt_port = test_param_get("olt_port", 129) |
| 17 | |
| 18 | def testPacketIn(self, match, parsed_pkt): |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 19 | |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 20 | delete_all_flows(self.controller) |
| 21 | |
| 22 | pkt = str(parsed_pkt) |
| 23 | |
| 24 | request = ofp.message.flow_add( |
| 25 | table_id=test_param_get("table", 0), |
| 26 | cookie=42, |
| 27 | match=match, |
| 28 | instructions=[ |
| 29 | ofp.instruction.apply_actions( |
| 30 | actions=[ |
| 31 | ofp.action.output( |
| 32 | port=ofp.OFPP_CONTROLLER, |
| 33 | max_len=ofp.OFPCML_NO_BUFFER)])], |
| 34 | buffer_id=ofp.OFP_NO_BUFFER, |
| 35 | priority=1000) |
| 36 | |
| 37 | logging.info("Inserting flow sending matching packets to controller") |
| 38 | self.controller.message_send(request) |
| 39 | do_barrier(self.controller) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 40 | |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 41 | for of_port in config["port_map"]: |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 42 | logging.info("PacketInExact test, port %d", of_port) |
| 43 | self.dataplane.send(of_port, pkt) |
| 44 | verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION) |
| 45 | verify_packets(self, pkt, []) |
| 46 | |
| 47 | class EapolPacketIn(base_tests.SimpleDataPlane): |
| 48 | |
| 49 | """Verify packet-ins are sent for EAPOL packets """ |
| 50 | |
| 51 | def runTest(self): |
| 52 | logging.info("Running EAPOL Packet In test") |
| 53 | |
| 54 | match = ofp.match() |
| 55 | match.oxm_list.append(ofp.oxm.eth_type(0x888e)) |
| 56 | # Use ethertype 0x888e and multicast destination MAC address |
| 57 | pkt = simple_eth_packet(pktlen=60, eth_dst='01:00:5E:7F:FF:FF', eth_type=0x888e) |
| 58 | |
| 59 | testPacketIn(self, match, pkt) |
| 60 | |
| 61 | class ARPPacketIn(base_tests.SimpleDataPlane): |
| 62 | |
| 63 | """Verify packet-ins are sent for ARP packets """ |
| 64 | |
| 65 | def runTest(self): |
| 66 | logging.info("Running ARP Packet In test") |
| 67 | |
| 68 | match = ofp.match() |
| 69 | match.oxm_list.append(ofp.oxm.eth_type(0x0806)) |
| 70 | |
| 71 | # Use ethertype 0x0806 |
| 72 | pkt = simple_eth_packet(eth_type=0x0806) |
| 73 | |
| 74 | testPacketIn(self, match, pkt) |
| 75 | |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 76 | class DHCPPacketIn(base_tests.SimpleDataPlane): |
| 77 | |
| 78 | """Verify packet-ins are sent for DHCP packets """ |
| 79 | |
| 80 | def runTest(self): |
| 81 | logging.info("Running DHCP Packet In test") |
| 82 | |
| 83 | pkt = simple_udp_packet(udp_sport=68, udp_dport=67) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 84 | |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 85 | match = ofp.match() |
| 86 | match.oxm_list.append(ofp.oxm.eth_type(0x0800)) |
| 87 | match.oxm_list.append(ofp.oxm.ip_proto(17)) |
| 88 | match.oxm_list.append(ofp.oxm.udp_src(68)) |
| 89 | match.oxm_list.append(ofp.oxm.udp_dst(67)) |
| 90 | |
| 91 | testPacketIn(self, match, pkt) |
| 92 | |
| 93 | # Other UDP packets should not match the rule |
| 94 | radiusPkt = simple_udp_packet(udp_sport=1812, udp_dport=1812) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 95 | |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 96 | self.dataplane.send(1, str(radiusPkt)) |
| 97 | verify_no_packet_in(self, radiusPkt, 1) |
| 98 | |
| 99 | class IGMPPacketIn(base_tests.SimpleDataPlane): |
| 100 | |
| 101 | """Verify packet-ins are sent for IGMP packets """ |
| 102 | |
| 103 | def runTest(self): |
| 104 | logging.info("Running IGMP Packet In test") |
| 105 | |
| 106 | match = ofp.match() |
| 107 | match.oxm_list.append(ofp.oxm.eth_type(0x800)) |
| 108 | match.oxm_list.append(ofp.oxm.ip_proto(2)) |
| 109 | |
| 110 | pkt = scapy.Ether(dst='01:00:5E:7F:FF:FF', src='00:00:00:00:00:01')/ \ |
| 111 | scapy.IP(src='10.0.0.1', dst='10.0.0.2', ttl=60, tos=0, id=0, proto=2) |
| 112 | |
| 113 | pkt = pkt/("0" * (100 - len(pkt))) |
| 114 | |
| 115 | testPacketIn(self, match, pkt) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 116 | |
| 117 | class TestMeter(base_tests.SimpleDataPlane): |
| 118 | |
| 119 | def runTest(self): |
| 120 | logging.info("Running Meter tests") |
| 121 | dropMeterBand = ofp.meter_band.drop(rate = 500) |
| 122 | meter_mod = ofp.message.meter_mod(xid = 1, command = ofp.OFPMC_ADD, meter_id = 1, meters = [ dropMeterBand ]) |
| 123 | self.controller.message_send(meter_mod) |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 124 | |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 125 | time.sleep(1) |
| 126 | |
| 127 | verify_no_errors(self.controller) |
| 128 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 129 | vlan_id = 201 |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 130 | match = ofp.match() |
| 131 | match.oxm_list.append(ofp.oxm.in_port(onu_port)) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 132 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id )) |
| 133 | |
| 134 | request = ofp.message.flow_add( |
| 135 | table_id=test_param_get("table", 0), |
| 136 | cookie=42, |
| 137 | match=match, |
| 138 | instructions=[ |
| 139 | ofp.instruction.apply_actions( |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 140 | actions=[ofp.action.output(port=olt_port)] |
| 141 | ), |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 142 | ofp.instruction.meter(meter_id = 1) |
| 143 | ], |
| 144 | buffer_id=ofp.OFP_NO_BUFFER, |
| 145 | priority=1000) |
| 146 | |
| 147 | self.controller.message_send(request) |
| 148 | time.sleep(1) |
| 149 | verify_no_errors(self.controller) |
| 150 | |
| 151 | match = ofp.match() |
| 152 | match.oxm_list.append(ofp.oxm.in_port(olt_port)) |
| 153 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 154 | |
| 155 | request = ofp.message.flow_add( |
| 156 | table_id=test_param_get("table", 0), |
| 157 | cookie=43, |
| 158 | match=match, |
| 159 | instructions=[ |
| 160 | ofp.instruction.apply_actions( |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 161 | actions=[ofp.action.output(port=onu_port)] |
| 162 | ), |
| 163 | ofp.instruction.meter(meter_id = 1) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 164 | ], |
| 165 | buffer_id=ofp.OFP_NO_BUFFER, |
| 166 | priority=1000) |
| 167 | |
| 168 | self.controller.message_send(request) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 169 | time.sleep(1) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 170 | verify_no_errors(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 171 | do_barrier(self.controller) |
| 172 | time.sleep(5) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 173 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 174 | inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0) |
| 175 | # downstream |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 176 | self.dataplane.send(olt_port, str(inPkt)) |
| 177 | verify_packet(self, inPkt, onu_port) |
| 178 | # upstream |
| 179 | self.dataplane.send(olt_port, str(inPkt)) |
| 180 | verify_packet(self, inPkt, onu_port) |
| 181 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 182 | # clean up the test |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 183 | meter_mod = ofp.message.meter_mod(xid = 2, command = ofp.OFPMC_DELETE, meter_id = 1) |
| 184 | self.controller.message_send(meter_mod) |
| 185 | time.sleep(1) |
| 186 | delete_all_flows(self.controller) |
| 187 | verify_no_errors(self.controller) |
| 188 | |
| 189 | |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 190 | class TestDuplicateMeter(base_tests.SimpleDataPlane): |
| 191 | |
| 192 | def runTest(self): |
| 193 | logging.info("Running Duplicate Meter Test") |
| 194 | dropMeterBand = ofp.meter_band.drop(rate = 500) |
| 195 | meter_mod = ofp.message.meter_mod(xid = 1, command = ofp.OFPMC_ADD, meter_id = 1, meters = [ dropMeterBand ]) |
| 196 | self.controller.message_send(meter_mod) |
| 197 | self.controller.message_send(meter_mod) |
| 198 | |
| 199 | time.sleep(1) |
| 200 | |
| 201 | try: |
| 202 | verify_no_errors(self.controller) |
| 203 | except AssertionError as e: |
| 204 | if (not e.message is "unexpected error type=12 code=1"): |
| 205 | raise AssertionError("Incorrect error type: %s" % e.message) |
| 206 | |
| 207 | |
| 208 | class VlanTest(base_tests.SimpleDataPlane): |
| 209 | |
| 210 | """Verify the switch can push/pop a VLAN tag and forward out a port """ |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 211 | |
| 212 | def runTest(self): |
| 213 | logging.info("Running push VLAN test") |
| 214 | |
| 215 | vlan_id = 200 |
| 216 | |
| 217 | delete_all_flows(self.controller) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 218 | |
| 219 | #PUSH |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 220 | match = ofp.match() |
| 221 | match.oxm_list.append(ofp.oxm.in_port(onu_port)) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 222 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(value=ofp.OFPVID_PRESENT, value_mask=ofp.OFPVID_PRESENT)) |
| 223 | match.oxm_list.append(ofp.oxm.vlan_pcp(value = 0)) |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 224 | |
| 225 | request = ofp.message.flow_add( |
| 226 | table_id=test_param_get("table", 0), |
| 227 | cookie=42, |
| 228 | match=match, |
| 229 | instructions=[ |
| 230 | ofp.instruction.apply_actions( |
| 231 | actions=[ |
| 232 | ofp.action.push_vlan(ethertype=0x8100), |
| 233 | ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)), |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 234 | ofp.action.set_field(ofp.oxm.vlan_pcp(0)), |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 235 | ofp.action.output(port=olt_port)])], |
| 236 | buffer_id=ofp.OFP_NO_BUFFER, |
| 237 | priority=1000) |
| 238 | |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 239 | logging.info("Inserting flow tagging upstream") |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 240 | self.controller.message_send(request) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 241 | |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 242 | #POP |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 243 | match = ofp.match() |
| 244 | match.oxm_list.append(ofp.oxm.in_port(olt_port)) |
| 245 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 246 | |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 247 | request = ofp.message.flow_add( |
| 248 | table_id=test_param_get("table", 0), |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 249 | cookie=43, |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 250 | match=match, |
| 251 | instructions=[ |
| 252 | ofp.instruction.apply_actions( |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 253 | actions=[ |
| 254 | ofp.action.pop_vlan(), |
| 255 | ofp.action.output(port=1)])], |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 256 | buffer_id=ofp.OFP_NO_BUFFER, |
| 257 | priority=1000) |
| 258 | |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 259 | logging.info("Inserting flow tagging downstream") |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 260 | self.controller.message_send(request) |
| 261 | do_barrier(self.controller) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 262 | time.sleep(5) |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 263 | |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 264 | inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0) |
| 265 | outPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, |
| 266 | vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0) |
| 267 | |
| 268 | # Send untagged packet in the ONU port and expect tagged packet out the OLT port |
| 269 | self.dataplane.send(onu_port, str(inPkt)) |
| 270 | verify_packet(self, outPkt, olt_port) |
| 271 | |
| 272 | # Send untagged packet in the OLT port and expect no packets to come out |
| 273 | self.dataplane.send(olt_port, str(inPkt)) |
| 274 | verify_packets(self, outPkt, []) |
| 275 | |
| 276 | inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True, |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 277 | vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 278 | outPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0) |
| 279 | |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 280 | # Send tagged packet in the OLT port and expect untagged packet out the OLT port |
| 281 | self.dataplane.send(olt_port, str(inPkt)) |
| 282 | verify_packet(self, outPkt, onu_port) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 283 | |
Jonathan Hart | f2511ca | 2015-07-07 14:18:19 -0700 | [diff] [blame] | 284 | # Send tagged packet in the ONU port and expect no packets to come out |
| 285 | self.dataplane.send(onu_port, str(inPkt)) |
Admin | 7e9c91d | 2015-08-25 15:53:49 -0700 | [diff] [blame] | 286 | verify_packets(self, outPkt, []) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 287 | |
| 288 | def createAllGroupAdd(group_id, ports=[]): |
| 289 | buckets = [] |
| 290 | |
| 291 | for portNum in ports: |
| 292 | buckets.append(ofp.common.bucket(watch_port=ofp.OFPP_ANY, watch_group=ofp.OFPG_ANY, |
| 293 | actions=[ofp.action.output(port=portNum)])) |
| 294 | |
| 295 | group_add = ofp.message.group_add(group_type = ofp.OFPGT_ALL, group_id=group_id, buckets=buckets) |
| 296 | |
| 297 | return group_add |
| 298 | |
| 299 | def createAllGroupMod(group_id, ports=[]): |
| 300 | buckets = [] |
| 301 | |
| 302 | for portNum in ports: |
| 303 | buckets.append(ofp.common.bucket(watch_port=ofp.OFPP_ANY, watch_group=ofp.OFPG_ANY, |
| 304 | actions=[ofp.action.output(port=portNum)])) |
| 305 | |
| 306 | group_mod = ofp.message.group_mod(command=ofp.OFPGC_MODIFY, group_type = ofp.OFPGT_ALL, group_id=group_id, buckets=buckets) |
| 307 | |
| 308 | return group_mod |
| 309 | |
| 310 | |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 311 | class TestGroupAdd(base_tests.SimpleDataPlane): |
| 312 | |
| 313 | def runTest(self): |
| 314 | logging.info("Running Group tests") |
| 315 | delete_all_flows(self.controller) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 316 | delete_all_groups(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 317 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 318 | test_group_id = 1 |
| 319 | |
| 320 | # output to two ONU |
| 321 | group_add = createAllGroupAdd(test_group_id, ports=[onu_port, onu_port2]) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 322 | |
| 323 | self.controller.message_send(group_add) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 324 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 325 | verify_no_errors(self.controller) |
| 326 | |
| 327 | # Remove the group and then readd it. |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 328 | group_delete = ofp.message.group_delete(group_id = test_group_id) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 329 | self.controller.message_send(group_delete) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 330 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 331 | verify_no_errors(self.controller) |
| 332 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 333 | group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2]) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 334 | self.controller.message_send(group_add) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 335 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 336 | verify_no_errors(self.controller) |
| 337 | |
| 338 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 339 | # clean up the test |
| 340 | group_delete = ofp.message.group_delete(group_id = test_group_id) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 341 | self.controller.message_send(group_delete) |
| 342 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 343 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 344 | verify_no_errors(self.controller) |
| 345 | |
| 346 | class TestGroupMod(base_tests.SimpleDataPlane): |
| 347 | |
| 348 | def runTest(self): |
| 349 | logging.info("Running Group tests") |
| 350 | delete_all_flows(self.controller) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 351 | delete_all_groups(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 352 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 353 | test_group_id = 1 |
| 354 | |
| 355 | group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2]) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 356 | |
| 357 | self.controller.message_send(group_add) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 358 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 359 | verify_no_errors(self.controller) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 360 | |
| 361 | # Modifying the group |
| 362 | group_mod = createAllGroupMod(test_group_id, [onu_port2]) |
| 363 | |
| 364 | self.controller.message_send(group_mod) |
| 365 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 366 | verify_no_errors(self.controller) |
| 367 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 368 | # Add a bucket into the group |
| 369 | group_mod = createAllGroupMod(test_group_id, [onu_port, onu_port2]) |
| 370 | self.controller.message_send(group_mod) |
| 371 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 372 | verify_no_errors(self.controller) |
| 373 | |
| 374 | # Modifying a non-existing group |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 375 | group_mod = createAllGroupMod(777, [onu_port2]) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 376 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 377 | self.controller.message_send(group_mod) |
| 378 | do_barrier(self.controller) |
| 379 | errorExperienced = 0 |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 380 | try: |
| 381 | verify_no_errors(self.controller) |
| 382 | except AssertionError as e: |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 383 | errorExperienced = 1 |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 384 | if (not (e.message == "unexpected error type=6 code=8")): |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 385 | raise AssertionError("Incorrect error type: %s" % e.message) |
| 386 | if not errorExperienced: |
| 387 | raise AssertionError("An error message is expected, but not shown.") |
| 388 | |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 389 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 390 | # clean up the test |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 391 | group_delete = ofp.message.group_delete(xid = 2, group_id = test_group_id) |
| 392 | self.controller.message_send(group_delete) |
| 393 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 394 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 395 | verify_no_errors(self.controller) |
| 396 | |
| 397 | class TestDuplicateGroup(base_tests.SimpleDataPlane): |
| 398 | |
| 399 | def runTest(self): |
| 400 | logging.info("Running Group tests") |
| 401 | delete_all_flows(self.controller) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 402 | delete_all_groups(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 403 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 404 | test_group_id = 1 |
| 405 | group_add = createAllGroupAdd(test_group_id, ports=[onu_port]) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 406 | |
| 407 | self.controller.message_send(group_add) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 408 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 409 | verify_no_errors(self.controller) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 410 | |
| 411 | # Add the same group id |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 412 | duplicate_group_fail = 0 |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 413 | |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 414 | self.controller.message_send(group_add) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 415 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 416 | try: |
| 417 | verify_no_errors(self.controller) |
| 418 | except AssertionError as e: |
| 419 | duplicate_group_fail = 1 |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 420 | if (not e.message == "unexpected error type=6 code=0"): |
| 421 | raise AssertionError("Incorrect error type: %s" % e.message) |
| 422 | if not duplicate_group_fail: |
| 423 | raise AssertionError("Adding duplicate groups didn't raise an error.") |
| 424 | |
| 425 | # clean up the test |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 426 | group_delete = ofp.message.group_delete(xid = 2, group_id = test_group_id) |
| 427 | self.controller.message_send(group_delete) |
| 428 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 429 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 430 | verify_no_errors(self.controller) |
| 431 | |
| 432 | class TestGroupAndFlow(base_tests.SimpleDataPlane): |
| 433 | |
| 434 | def runTest(self): |
| 435 | logging.info("Running Group tests") |
| 436 | delete_all_flows(self.controller) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 437 | delete_all_groups(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 438 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 439 | # Create a group |
| 440 | test_group_id = 1 |
| 441 | group_add = createAllGroupAdd(test_group_id, ports=[onu_port]) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 442 | |
| 443 | self.controller.message_send(group_add) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 444 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 445 | verify_no_errors(self.controller) |
| 446 | |
| 447 | # Create a flow rule matching olt port and vlan id |
| 448 | match = ofp.match() |
| 449 | match.oxm_list.append(ofp.oxm.in_port(olt_port)) |
| 450 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | 201)) |
| 451 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 452 | flow_pointing_to_group = ofp.message.flow_add( |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 453 | table_id=test_param_get("table", 0), |
| 454 | cookie=43, |
| 455 | match=match, |
| 456 | instructions=[ |
| 457 | ofp.instruction.apply_actions( |
| 458 | actions=[ ofp.action.group( group_id = test_group_id ) ] ) ], |
| 459 | buffer_id=ofp.OFP_NO_BUFFER, priority=1000) |
| 460 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 461 | self.controller.message_send(flow_pointing_to_group) |
| 462 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 463 | verify_no_errors(self.controller) |
| 464 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 465 | # After letting a flow rule point to the group, test we can do group_mod |
| 466 | group_mod = createAllGroupMod(test_group_id, ports=[onu_port2]) |
| 467 | self.controller.message_send(group_mod) |
| 468 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 469 | verify_no_errors(self.controller) |
| 470 | |
| 471 | # Test we can remove flows and then remove group |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 472 | flow_delete = ofp.message.flow_delete( table_id=test_param_get("table", 0)) |
| 473 | self.controller.message_send(flow_delete) |
| 474 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 475 | verify_no_errors(self.controller) |
| 476 | |
| 477 | group_delete = ofp.message.group_delete(xid = 3, group_id = test_group_id) |
| 478 | self.controller.message_send(group_delete) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 479 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 480 | verify_no_errors(self.controller) |
| 481 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 482 | # Add the group and flow back, test it we can first remove group and then remove the flow. |
| 483 | group_add = createAllGroupAdd(test_group_id, ports=[onu_port]) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 484 | self.controller.message_send(group_add) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 485 | |
| 486 | self.controller.message_send(flow_pointing_to_group) |
| 487 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 488 | verify_no_errors(self.controller) |
| 489 | |
| 490 | group_delete = ofp.message.group_delete(xid = 4, group_id = test_group_id) |
| 491 | self.controller.message_send(group_delete) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 492 | |
| 493 | self.controller.message_send(flow_delete) |
| 494 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 495 | verify_no_errors(self.controller) |
| 496 | |
| 497 | |
| 498 | class TestGroupForwarding(base_tests.SimpleDataPlane): |
| 499 | |
| 500 | def runTest(self): |
| 501 | logging.info("Running Group datapath forwarding tests") |
| 502 | delete_all_flows(self.controller) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 503 | delete_all_groups(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 504 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 505 | vlan_id = 200 |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 506 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 507 | # Create a group |
| 508 | test_group_id = 1 |
| 509 | group_add = createAllGroupAdd(test_group_id, [onu_port]) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 510 | |
| 511 | self.controller.message_send(group_add) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 512 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 513 | verify_no_errors(self.controller) |
| 514 | |
| 515 | # Create a flow rule matching olt port and vlan id |
| 516 | match = ofp.match() |
| 517 | match.oxm_list.append(ofp.oxm.in_port(olt_port)) |
| 518 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)) |
| 519 | |
| 520 | request = ofp.message.flow_add( |
| 521 | table_id=test_param_get("table", 0), |
| 522 | cookie=43, |
| 523 | match=match, |
| 524 | instructions=[ |
| 525 | ofp.instruction.apply_actions( |
| 526 | actions=[ ofp.action.group( group_id = test_group_id ) ] ), |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 527 | ], |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 528 | buffer_id=ofp.OFP_NO_BUFFER, priority=1000) |
| 529 | |
| 530 | self.controller.message_send(request) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 531 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 532 | verify_no_errors(self.controller) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 533 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 534 | |
| 535 | inPkt = simple_udp_packet(pktlen=104,dl_vlan_enable=True, |
| 536 | vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0) |
| 537 | outPkt = inPkt |
| 538 | self.dataplane.send(olt_port, str(inPkt)) |
| 539 | verify_packet(self, outPkt, onu_port) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 540 | |
| 541 | # Now put 2 ONU ports in the group and test that the input packet is |
| 542 | # duplicated out both ports |
| 543 | group_mod = createAllGroupMod(test_group_id, ports=[onu_port, onu_port2]) |
| 544 | self.controller.message_send(group_mod) |
| 545 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 546 | verify_no_errors(self.controller) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 547 | |
| 548 | self.dataplane.send(olt_port, str(inPkt)) |
| 549 | verify_packet(self, outPkt, onu_port) |
| 550 | verify_packet(self, outPkt, onu_port2) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 551 | |
| 552 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 553 | # clean up the test |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 554 | request = ofp.message.flow_delete( table_id=test_param_get("table", 0)) |
| 555 | self.controller.message_send(request) |
| 556 | group_delete = ofp.message.group_delete(xid = 2, group_id = test_group_id) |
| 557 | self.controller.message_send(group_delete) |
| 558 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 559 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 560 | verify_no_errors(self.controller) |
| 561 | |
| 562 | class TransparentVlanTest(base_tests.SimpleDataPlane): |
| 563 | |
| 564 | def runTest(self): |
| 565 | logging.info("Running transparent vlan tests") |
| 566 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 567 | vlan_id = 201 |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 568 | match = ofp.match() |
| 569 | match.oxm_list.append(ofp.oxm.in_port(onu_port)) |
| 570 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id )) |
| 571 | |
| 572 | request = ofp.message.flow_add( |
| 573 | table_id=test_param_get("table", 0), |
| 574 | cookie=42, |
| 575 | match=match, |
| 576 | instructions=[ |
| 577 | ofp.instruction.apply_actions( |
| 578 | actions=[ |
| 579 | ofp.action.output(port=olt_port)]), |
| 580 | ], |
| 581 | buffer_id=ofp.OFP_NO_BUFFER, |
| 582 | priority=1000) |
| 583 | |
| 584 | self.controller.message_send(request) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 585 | |
| 586 | match = ofp.match() |
| 587 | match.oxm_list.append(ofp.oxm.in_port(olt_port)) |
| 588 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)) |
| 589 | |
| 590 | request = ofp.message.flow_add( |
| 591 | table_id=test_param_get("table", 0), |
| 592 | cookie=43, |
| 593 | match=match, |
| 594 | instructions=[ |
| 595 | ofp.instruction.apply_actions( |
| 596 | actions=[ |
| 597 | ofp.action.output(port=onu_port)]), |
| 598 | ], |
| 599 | buffer_id=ofp.OFP_NO_BUFFER, |
| 600 | priority=1000) |
| 601 | |
| 602 | self.controller.message_send(request) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 603 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 604 | verify_no_errors(self.controller) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 605 | |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 606 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 607 | inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0) |
| 608 | # downstream |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 609 | self.dataplane.send(olt_port, str(inPkt)) |
| 610 | verify_packet(self, inPkt, onu_port) |
| 611 | # upstream |
| 612 | self.dataplane.send(onu_port, str(inPkt)) |
| 613 | verify_packet(self, inPkt, olt_port) |
| 614 | |
| 615 | |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 616 | # clean up the test |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 617 | delete_all_flows(self.controller) |
Jonathan Hart | f65e181 | 2015-10-05 15:15:37 -0700 | [diff] [blame^] | 618 | do_barrier(self.controller) |
Admin | 02d052c | 2015-10-10 19:08:26 -0700 | [diff] [blame] | 619 | verify_no_errors(self.controller) |
| 620 | |
| 621 | |