alshabib | d6be76e | 2016-03-01 22:21:00 -0800 | [diff] [blame] | 1 | import oftest.base_tests as base_tests |
alshabib | cde318b | 2016-03-01 22:49:13 -0800 | [diff] [blame] | 2 | from oftest import config |
alshabib | d6be76e | 2016-03-01 22:21:00 -0800 | [diff] [blame] | 3 | import ofp |
Admin | 4ebddb8 | 2016-03-01 22:36:30 -0800 | [diff] [blame] | 4 | from oftest.testutils import * |
alshabib | cde318b | 2016-03-01 22:49:13 -0800 | [diff] [blame] | 5 | from oltconstants import * |
| 6 | import copy |
Admin | 44f754e | 2016-03-01 23:00:46 -0800 | [diff] [blame] | 7 | import logging |
alshabib | d6be76e | 2016-03-01 22:21:00 -0800 | [diff] [blame] | 8 | |
alshabib | cde318b | 2016-03-01 22:49:13 -0800 | [diff] [blame] | 9 | |
alshabib | d6be76e | 2016-03-01 22:21:00 -0800 | [diff] [blame] | 10 | class OltBaseTest(base_tests.SimpleDataPlane): |
| 11 | |
alshabib | cde318b | 2016-03-01 22:49:13 -0800 | [diff] [blame] | 12 | def testPacketIn(self, match, parsed_pkt): |
| 13 | delete_all_flows(self.controller) |
| 14 | |
| 15 | pkt = str(parsed_pkt) |
| 16 | |
| 17 | for of_port in config["port_map"]: |
| 18 | m = copy.deepcopy(match) |
| 19 | m.oxm_list.append(ofp.oxm.in_port(of_port)) |
| 20 | request = ofp.message.flow_add( |
| 21 | table_id=test_param_get("table", 0), |
| 22 | cookie=42, |
| 23 | match=m, |
| 24 | instructions=[ |
| 25 | ofp.instruction.apply_actions( |
| 26 | actions=[ |
| 27 | ofp.action.output( |
| 28 | port=ofp.OFPP_CONTROLLER, |
| 29 | max_len=ofp.OFPCML_NO_BUFFER)])], |
| 30 | buffer_id=ofp.OFP_NO_BUFFER, |
| 31 | priority=1000) |
| 32 | logging.info("Inserting flow sending matching packets to controller") |
| 33 | self.controller.message_send(request) |
| 34 | do_barrier(self.controller) |
| 35 | |
alshabib | 5339b7d | 2016-03-01 23:14:57 -0800 | [diff] [blame^] | 36 | for of_port in config["port_map"]: |
| 37 | logging.info("PacketInExact test, port %d", of_port) |
| 38 | self.dataplane.send(of_port, pkt) |
| 39 | verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION) |
| 40 | verify_packets(self, pkt, []) |
alshabib | cde318b | 2016-03-01 22:49:13 -0800 | [diff] [blame] | 41 | |
| 42 | def processEapolRule(self, in_port, install = True): |
| 43 | match = ofp.match() |
| 44 | match.oxm_list.append(ofp.oxm.eth_type(0x888e)) |
| 45 | match.oxm_list.append(ofp.oxm.in_port(in_port)) |
| 46 | if install: |
| 47 | request = ofp.message.flow_add( |
| 48 | table_id=test_param_get("table", 0), |
| 49 | cookie=42, |
| 50 | match=match, |
| 51 | instructions=[ |
| 52 | ofp.instruction.apply_actions( |
| 53 | actions=[ |
| 54 | ofp.action.output( |
| 55 | port=ofp.OFPP_CONTROLLER, |
| 56 | max_len=ofp.OFPCML_NO_BUFFER)])], |
| 57 | buffer_id=ofp.OFP_NO_BUFFER, |
| 58 | priority=1000) |
| 59 | else: |
| 60 | request = ofp.message.flow_delete( |
| 61 | table_id=test_param_get("table", 0), |
| 62 | cookie=42, |
| 63 | match=match, |
| 64 | instructions=[ |
| 65 | ofp.instruction.apply_actions( |
| 66 | actions=[ |
| 67 | ofp.action.output( |
| 68 | port=ofp.OFPP_CONTROLLER, |
| 69 | max_len=ofp.OFPCML_NO_BUFFER)])], |
| 70 | buffer_id=ofp.OFP_NO_BUFFER, |
| 71 | priority=1000) |
| 72 | logging.info("%s flow sending matching packets to controller" % "Install" if install else "Remove") |
| 73 | self.controller.message_send(request) |
| 74 | do_barrier(self.controller) |
| 75 | |
alshabib | 5339b7d | 2016-03-01 23:14:57 -0800 | [diff] [blame^] | 76 | def testPacketFlow(self, c_vlan_id, s_vlan_id, onu = None): |
alshabib | cde318b | 2016-03-01 22:49:13 -0800 | [diff] [blame] | 77 | |
| 78 | incorrectTagPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=100, vlan_pcp=1) |
| 79 | zeroTaggedPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0) |
| 80 | untaggedPkt = simple_udp_packet(pktlen=96) |
| 81 | |
| 82 | upstreamDoubleTaggedPkt = double_vlan_udp_packet(pktlen=104, dl_vlan_enable=True, |
| 83 | c_vlan_vid=c_vlan_id, |
| 84 | s_vlan_vid=s_vlan_id, |
| 85 | c_vlan_pcp=0, s_vlan_pcp=0) |
| 86 | |
alshabib | 5339b7d | 2016-03-01 23:14:57 -0800 | [diff] [blame^] | 87 | inport = onu_port if onu is None else onu |
| 88 | |
alshabib | cde318b | 2016-03-01 22:49:13 -0800 | [diff] [blame] | 89 | logging.info("Testing s-tag %d, c-tag %d" % (s_vlan_id, c_vlan_id)) |
| 90 | |
| 91 | # test upstream untagged packet got double tag at OLT |
alshabib | 5339b7d | 2016-03-01 23:14:57 -0800 | [diff] [blame^] | 92 | self.dataplane.send(inport, str(zeroTaggedPkt)) |
Admin | 44f754e | 2016-03-01 23:00:46 -0800 | [diff] [blame] | 93 | verify_packet(self, upstreamDoubleTaggedPkt, olt_port) |
alshabib | cde318b | 2016-03-01 22:49:13 -0800 | [diff] [blame] | 94 | |
| 95 | # test downstream doubletagged packet got untagged at ONU |
| 96 | self.dataplane.send(olt_port, str(upstreamDoubleTaggedPkt)) |
| 97 | if device_type == "pmc": |
alshabib | 5339b7d | 2016-03-01 23:14:57 -0800 | [diff] [blame^] | 98 | verify_packet(self, zeroTaggedPkt, inport) |
alshabib | cde318b | 2016-03-01 22:49:13 -0800 | [diff] [blame] | 99 | else: |
alshabib | 5339b7d | 2016-03-01 23:14:57 -0800 | [diff] [blame^] | 100 | verify_packet(self, untaggedPkt, inport) |
alshabib | cde318b | 2016-03-01 22:49:13 -0800 | [diff] [blame] | 101 | |
| 102 | # test upstream doubletagged packet got dropped |
alshabib | 5339b7d | 2016-03-01 23:14:57 -0800 | [diff] [blame^] | 103 | self.dataplane.send(inport, str(upstreamDoubleTaggedPkt)) |
alshabib | cde318b | 2016-03-01 22:49:13 -0800 | [diff] [blame] | 104 | verify_no_packet(self, upstreamDoubleTaggedPkt, olt_port) |
| 105 | |
| 106 | # test downstream untagged packet got dropped at ONU |
| 107 | self.dataplane.send(olt_port, str(untaggedPkt)) |
alshabib | 5339b7d | 2016-03-01 23:14:57 -0800 | [diff] [blame^] | 108 | verify_no_packet(self, untaggedPkt, inport) |
alshabib | cde318b | 2016-03-01 22:49:13 -0800 | [diff] [blame] | 109 | |
| 110 | # test upstream icorrectly tagged packet; should get dropped |
alshabib | 5339b7d | 2016-03-01 23:14:57 -0800 | [diff] [blame^] | 111 | self.dataplane.send(inport, str(incorrectTagPkt)) |
alshabib | cde318b | 2016-03-01 22:49:13 -0800 | [diff] [blame] | 112 | verify_no_packet(self, upstreamDoubleTaggedPkt, olt_port) |
| 113 | |
alshabib | 5339b7d | 2016-03-01 23:14:57 -0800 | [diff] [blame^] | 114 | def installDoubleTaggingRules(self, s_vlan_id, c_vlan_id, cookie=42, onu = None): |
| 115 | |
| 116 | inport = onu_port if onu is None else onu |
alshabib | d6be76e | 2016-03-01 22:21:00 -0800 | [diff] [blame] | 117 | |
| 118 | # upstream flow rule |
| 119 | match = ofp.match() |
alshabib | 5339b7d | 2016-03-01 23:14:57 -0800 | [diff] [blame^] | 120 | match.oxm_list.append(ofp.oxm.in_port(inport)) |
alshabib | d6be76e | 2016-03-01 22:21:00 -0800 | [diff] [blame] | 121 | if device_type == "cpqd": |
| 122 | match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_NONE)) |
| 123 | actions = [ |
| 124 | ofp.action.push_vlan(ethertype=0x8100), |
| 125 | ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)), |
| 126 | ofp.action.set_field(ofp.oxm.vlan_pcp(0)) |
| 127 | ] |
| 128 | else: # "pmc", "normal" |
| 129 | match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_PRESENT)) |
| 130 | match.oxm_list.append(ofp.oxm.vlan_pcp(value=0)) |
| 131 | actions = [ |
| 132 | ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)) |
| 133 | ] |
| 134 | cookie += 1 |
| 135 | |
| 136 | # push inner vlan (c-vlan) for upstream |
| 137 | request = ofp.message.flow_add( |
| 138 | table_id=test_param_get("table", 0), |
| 139 | cookie=cookie, |
| 140 | match=match, |
| 141 | instructions=[ |
| 142 | ofp.instruction.apply_actions(actions=actions), |
| 143 | ofp.instruction.goto_table(1)], |
| 144 | buffer_id=ofp.OFP_NO_BUFFER, |
| 145 | priority=1000) |
| 146 | |
| 147 | self.controller.message_send(request) |
| 148 | do_barrier(self.controller) |
| 149 | verify_no_errors(self.controller) |
| 150 | |
| 151 | # push outer vlan (s-vlan) for upstream |
| 152 | match = ofp.match() |
alshabib | 5339b7d | 2016-03-01 23:14:57 -0800 | [diff] [blame^] | 153 | match.oxm_list.append(ofp.oxm.in_port(inport)) |
alshabib | d6be76e | 2016-03-01 22:21:00 -0800 | [diff] [blame] | 154 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)) |
| 155 | match.oxm_list.append(ofp.oxm.vlan_pcp(0)) |
| 156 | cookie += 1 |
| 157 | |
| 158 | request = ofp.message.flow_add( |
| 159 | table_id=test_param_get("table", 1), |
| 160 | cookie=cookie, |
| 161 | match=match, |
| 162 | instructions=[ |
| 163 | ofp.instruction.apply_actions( |
| 164 | actions=[ |
| 165 | ofp.action.push_vlan(ethertype=0x8100), |
| 166 | ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id)), |
| 167 | ofp.action.set_field(ofp.oxm.vlan_pcp(0)), |
| 168 | ofp.action.output(port=olt_port)]), |
| 169 | ], |
| 170 | buffer_id=ofp.OFP_NO_BUFFER, |
| 171 | priority=1000) |
| 172 | |
| 173 | self.controller.message_send(request) |
| 174 | do_barrier(self.controller) |
| 175 | verify_no_errors(self.controller) |
| 176 | cookie += 1 |
| 177 | |
| 178 | # strip outer vlan (s-vlan) for downstream |
| 179 | match = ofp.match() |
| 180 | match.oxm_list.append(ofp.oxm.in_port(olt_port)) |
| 181 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id)) |
| 182 | match.oxm_list.append(ofp.oxm.vlan_pcp(0)) |
| 183 | request = ofp.message.flow_add( |
| 184 | table_id=test_param_get("table", 0), |
| 185 | cookie=cookie, |
| 186 | match=match, |
| 187 | instructions=[ |
| 188 | ofp.instruction.apply_actions( |
| 189 | actions=[ofp.action.pop_vlan()]), |
| 190 | ofp.instruction.goto_table(1)], |
| 191 | buffer_id=ofp.OFP_NO_BUFFER, |
| 192 | priority=1000) |
| 193 | |
| 194 | self.controller.message_send(request) |
| 195 | do_barrier(self.controller) |
| 196 | verify_no_errors(self.controller) |
| 197 | |
| 198 | # rewrite inner vlan (c-vlan) to default (0) for downstream |
| 199 | match = ofp.match() |
| 200 | match.oxm_list.append(ofp.oxm.in_port(olt_port)) |
| 201 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)) |
| 202 | match.oxm_list.append(ofp.oxm.vlan_pcp(0)) |
| 203 | cookie += 1 |
| 204 | |
| 205 | request = ofp.message.flow_add( |
| 206 | table_id=test_param_get("table", 1), |
| 207 | cookie=cookie, |
| 208 | match=match, |
| 209 | instructions=[ |
| 210 | ofp.instruction.apply_actions( |
| 211 | actions=[ |
| 212 | ofp.action.pop_vlan(), |
alshabib | 5339b7d | 2016-03-01 23:14:57 -0800 | [diff] [blame^] | 213 | ofp.action.output(port=inport)]) |
alshabib | d6be76e | 2016-03-01 22:21:00 -0800 | [diff] [blame] | 214 | ], |
| 215 | buffer_id=ofp.OFP_NO_BUFFER, |
| 216 | priority=1000) |
| 217 | |
| 218 | self.controller.message_send(request) |
| 219 | do_barrier(self.controller) |
| 220 | verify_no_errors(self.controller) |