alshabib | d6be76e | 2016-03-01 22:21:00 -0800 | [diff] [blame^] | 1 | import oftest.base_tests as base_tests |
| 2 | import oftest.packet as scapy |
| 3 | |
| 4 | import ofp |
| 5 | import time |
| 6 | |
| 7 | |
| 8 | class OltBaseTest(base_tests.SimpleDataPlane): |
| 9 | |
| 10 | def installDoubleTaggingRules(s_vlan_id, c_vlan_id, cookie=42): |
| 11 | |
| 12 | # upstream flow rule |
| 13 | match = ofp.match() |
| 14 | match.oxm_list.append(ofp.oxm.in_port(onu_port)) |
| 15 | if device_type == "cpqd": |
| 16 | match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_NONE)) |
| 17 | actions = [ |
| 18 | ofp.action.push_vlan(ethertype=0x8100), |
| 19 | ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)), |
| 20 | ofp.action.set_field(ofp.oxm.vlan_pcp(0)) |
| 21 | ] |
| 22 | else: # "pmc", "normal" |
| 23 | match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_PRESENT)) |
| 24 | match.oxm_list.append(ofp.oxm.vlan_pcp(value=0)) |
| 25 | actions = [ |
| 26 | ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)) |
| 27 | ] |
| 28 | cookie += 1 |
| 29 | |
| 30 | # push inner vlan (c-vlan) for upstream |
| 31 | request = ofp.message.flow_add( |
| 32 | table_id=test_param_get("table", 0), |
| 33 | cookie=cookie, |
| 34 | match=match, |
| 35 | instructions=[ |
| 36 | ofp.instruction.apply_actions(actions=actions), |
| 37 | ofp.instruction.goto_table(1)], |
| 38 | buffer_id=ofp.OFP_NO_BUFFER, |
| 39 | priority=1000) |
| 40 | |
| 41 | self.controller.message_send(request) |
| 42 | do_barrier(self.controller) |
| 43 | verify_no_errors(self.controller) |
| 44 | |
| 45 | # push outer vlan (s-vlan) for upstream |
| 46 | match = ofp.match() |
| 47 | match.oxm_list.append(ofp.oxm.in_port(onu_port)) |
| 48 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)) |
| 49 | match.oxm_list.append(ofp.oxm.vlan_pcp(0)) |
| 50 | cookie += 1 |
| 51 | |
| 52 | request = ofp.message.flow_add( |
| 53 | table_id=test_param_get("table", 1), |
| 54 | cookie=cookie, |
| 55 | match=match, |
| 56 | instructions=[ |
| 57 | ofp.instruction.apply_actions( |
| 58 | actions=[ |
| 59 | ofp.action.push_vlan(ethertype=0x8100), |
| 60 | ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id)), |
| 61 | ofp.action.set_field(ofp.oxm.vlan_pcp(0)), |
| 62 | ofp.action.output(port=olt_port)]), |
| 63 | ], |
| 64 | buffer_id=ofp.OFP_NO_BUFFER, |
| 65 | priority=1000) |
| 66 | |
| 67 | self.controller.message_send(request) |
| 68 | do_barrier(self.controller) |
| 69 | verify_no_errors(self.controller) |
| 70 | cookie += 1 |
| 71 | |
| 72 | # strip outer vlan (s-vlan) for downstream |
| 73 | match = ofp.match() |
| 74 | match.oxm_list.append(ofp.oxm.in_port(olt_port)) |
| 75 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id)) |
| 76 | match.oxm_list.append(ofp.oxm.vlan_pcp(0)) |
| 77 | request = ofp.message.flow_add( |
| 78 | table_id=test_param_get("table", 0), |
| 79 | cookie=cookie, |
| 80 | match=match, |
| 81 | instructions=[ |
| 82 | ofp.instruction.apply_actions( |
| 83 | actions=[ofp.action.pop_vlan()]), |
| 84 | ofp.instruction.goto_table(1)], |
| 85 | buffer_id=ofp.OFP_NO_BUFFER, |
| 86 | priority=1000) |
| 87 | |
| 88 | self.controller.message_send(request) |
| 89 | do_barrier(self.controller) |
| 90 | verify_no_errors(self.controller) |
| 91 | |
| 92 | # rewrite inner vlan (c-vlan) to default (0) for downstream |
| 93 | match = ofp.match() |
| 94 | match.oxm_list.append(ofp.oxm.in_port(olt_port)) |
| 95 | match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)) |
| 96 | match.oxm_list.append(ofp.oxm.vlan_pcp(0)) |
| 97 | cookie += 1 |
| 98 | |
| 99 | request = ofp.message.flow_add( |
| 100 | table_id=test_param_get("table", 1), |
| 101 | cookie=cookie, |
| 102 | match=match, |
| 103 | instructions=[ |
| 104 | ofp.instruction.apply_actions( |
| 105 | actions=[ |
| 106 | ofp.action.pop_vlan(), |
| 107 | ofp.action.output(port=onu_port)]) |
| 108 | ], |
| 109 | buffer_id=ofp.OFP_NO_BUFFER, |
| 110 | priority=1000) |
| 111 | |
| 112 | self.controller.message_send(request) |
| 113 | do_barrier(self.controller) |
| 114 | verify_no_errors(self.controller) |