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