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