Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2018 the original author or authors. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 17 | from voltha.protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC |
| 18 | import voltha.core.flow_decomposer as fd |
| 19 | import openolt_platform as platform |
| 20 | from voltha.adapters.openolt.protos import openolt_pb2 |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 21 | from voltha.registry import registry |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 22 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 23 | HSIA_FLOW_INDEX = 0 # FIXME |
| 24 | DHCP_FLOW_INDEX = 1 # FIXME |
Shad Ansari | 47e0c39 | 2018-07-17 23:55:07 +0000 | [diff] [blame^] | 25 | DHCP_DOWNLINK_FLOW_INDEX = 6 # FIXME |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 26 | EAPOL_FLOW_INDEX = 2 # FIXME |
| 27 | EAPOL_DOWNLINK_FLOW_INDEX = 3 # FIXME |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 28 | EAPOL_DOWNLINK_SECONDARY_FLOW_INDEX = 4 # FIXME |
| 29 | EAPOL_UPLINK_SECONDARY_FLOW_INDEX = 5 # FIXME |
| 30 | |
| 31 | |
| 32 | EAP_ETH_TYPE = 0x888e |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 33 | |
| 34 | # FIXME - see also BRDCM_DEFAULT_VLAN in broadcom_onu.py |
| 35 | DEFAULT_MGMT_VLAN = 4091 |
| 36 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 37 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 38 | class OpenOltFlowMgr(object): |
| 39 | |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 40 | def __init__(self, log, stub, device_id): |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 41 | self.log = log |
| 42 | self.stub = stub |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 43 | self.device_id = device_id |
| 44 | self.flow_proxy = registry('core').get_proxy( |
| 45 | '/devices/{}/flows'.format(self.device_id)) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 46 | |
| 47 | def add_flow(self, flow, is_down_stream): |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 48 | self.log.debug('add flow', flow=flow, is_down_stream=is_down_stream) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 49 | classifier_info = dict() |
| 50 | action_info = dict() |
| 51 | |
| 52 | in_port = fd.get_in_port(flow) |
| 53 | assert in_port is not None |
| 54 | |
| 55 | for field in fd.get_ofb_fields(flow): |
| 56 | if field.type == fd.ETH_TYPE: |
| 57 | classifier_info['eth_type'] = field.eth_type |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 58 | self.log.debug('field-type-eth-type', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 59 | eth_type=classifier_info['eth_type']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 60 | elif field.type == fd.IP_PROTO: |
| 61 | classifier_info['ip_proto'] = field.ip_proto |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 62 | self.log.debug('field-type-ip-proto', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 63 | ip_proto=classifier_info['ip_proto']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 64 | elif field.type == fd.IN_PORT: |
| 65 | classifier_info['in_port'] = field.port |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 66 | self.log.debug('field-type-in-port', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 67 | in_port=classifier_info['in_port']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 68 | elif field.type == fd.VLAN_VID: |
| 69 | classifier_info['vlan_vid'] = field.vlan_vid & 0xfff |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 70 | self.log.debug('field-type-vlan-vid', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 71 | vlan=classifier_info['vlan_vid']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 72 | elif field.type == fd.VLAN_PCP: |
| 73 | classifier_info['vlan_pcp'] = field.vlan_pcp |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 74 | self.log.debug('field-type-vlan-pcp', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 75 | pcp=classifier_info['vlan_pcp']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 76 | elif field.type == fd.UDP_DST: |
| 77 | classifier_info['udp_dst'] = field.udp_dst |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 78 | self.log.debug('field-type-udp-dst', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 79 | udp_dst=classifier_info['udp_dst']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 80 | elif field.type == fd.UDP_SRC: |
| 81 | classifier_info['udp_src'] = field.udp_src |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 82 | self.log.debug('field-type-udp-src', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 83 | udp_src=classifier_info['udp_src']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 84 | elif field.type == fd.IPV4_DST: |
| 85 | classifier_info['ipv4_dst'] = field.ipv4_dst |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 86 | self.log.debug('field-type-ipv4-dst', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 87 | ipv4_dst=classifier_info['ipv4_dst']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 88 | elif field.type == fd.IPV4_SRC: |
| 89 | classifier_info['ipv4_src'] = field.ipv4_src |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 90 | self.log.debug('field-type-ipv4-src', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 91 | ipv4_dst=classifier_info['ipv4_src']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 92 | elif field.type == fd.METADATA: |
| 93 | classifier_info['metadata'] = field.table_metadata |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 94 | self.log.debug('field-type-metadata', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 95 | metadata=classifier_info['metadata']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 96 | else: |
| 97 | raise NotImplementedError('field.type={}'.format( |
| 98 | field.type)) |
| 99 | |
| 100 | for action in fd.get_actions(flow): |
| 101 | if action.type == fd.OUTPUT: |
| 102 | action_info['output'] = action.output.port |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 103 | self.log.debug('action-type-output', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 104 | output=action_info['output'], |
| 105 | in_port=classifier_info['in_port']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 106 | elif action.type == fd.POP_VLAN: |
| 107 | action_info['pop_vlan'] = True |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 108 | self.log.debug('action-type-pop-vlan', in_port=in_port) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 109 | elif action.type == fd.PUSH_VLAN: |
| 110 | action_info['push_vlan'] = True |
| 111 | action_info['tpid'] = action.push.ethertype |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 112 | self.log.debug('action-type-push-vlan', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 113 | push_tpid=action_info['tpid'], in_port=in_port) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 114 | if action.push.ethertype != 0x8100: |
| 115 | self.log.error('unhandled-tpid', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 116 | ethertype=action.push.ethertype) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 117 | elif action.type == fd.SET_FIELD: |
| 118 | # action_info['action_type'] = 'set_field' |
| 119 | _field = action.set_field.field.ofb_field |
| 120 | assert (action.set_field.field.oxm_class == |
| 121 | OFPXMC_OPENFLOW_BASIC) |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 122 | self.log.debug('action-type-set-field', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 123 | field=_field, in_port=in_port) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 124 | if _field.type == fd.VLAN_VID: |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 125 | self.log.debug('set-field-type-vlan-vid', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 126 | vlan_vid=_field.vlan_vid & 0xfff) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 127 | action_info['vlan_vid'] = (_field.vlan_vid & 0xfff) |
| 128 | else: |
| 129 | self.log.error('unsupported-action-set-field-type', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 130 | field_type=_field.type) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 131 | else: |
| 132 | self.log.error('unsupported-action-type', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 133 | action_type=action.type, in_port=in_port) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 134 | |
| 135 | # FIXME - Why ignore downstream flows? |
| 136 | if is_down_stream is False: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 137 | intf_id = platform.intf_id_from_uni_port_num( |
| 138 | classifier_info['in_port']) |
| 139 | onu_id = platform.onu_id_from_port_num( |
| 140 | classifier_info['in_port']) |
Nicolas Palpacuer | 2e0fa58 | 2018-07-16 16:04:12 -0400 | [diff] [blame] | 141 | self.divide_and_add_flow(intf_id, onu_id, |
| 142 | flow.priority, classifier_info, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 143 | action_info) |
| 144 | # else: |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 145 | # self.log.info('ignore downstream flow', flow=flow, |
| 146 | # classifier_info=classifier_info, |
| 147 | # action_info=action_info) |
| 148 | |
| 149 | # FIXME - No need for divide_and_add_flow if |
| 150 | # both upstream and downstream flows |
| 151 | # are acted upon (not just upstream flows). |
Nicolas Palpacuer | 2e0fa58 | 2018-07-16 16:04:12 -0400 | [diff] [blame] | 152 | def divide_and_add_flow(self, intf_id, onu_id, priority, classifier, |
| 153 | action): |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 154 | if 'ip_proto' in classifier: |
| 155 | if classifier['ip_proto'] == 17: |
| 156 | self.log.debug('dhcp flow add') |
Nicolas Palpacuer | 2e0fa58 | 2018-07-16 16:04:12 -0400 | [diff] [blame] | 157 | self.add_dhcp_trap(intf_id, onu_id, priority, classifier, |
| 158 | action) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 159 | elif classifier['ip_proto'] == 2: |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 160 | self.log.debug('igmp flow add ignored') |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 161 | else: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 162 | self.log.debug("Invalid-Classifier-to-handle", |
| 163 | classifier=classifier, |
| 164 | action=action) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 165 | elif 'eth_type' in classifier: |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 166 | if classifier['eth_type'] == EAP_ETH_TYPE: |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 167 | self.log.debug('eapol flow add') |
Nicolas Palpacuer | 2e0fa58 | 2018-07-16 16:04:12 -0400 | [diff] [blame] | 168 | self.add_eapol_flow(intf_id, onu_id, priority) |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 169 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 170 | elif 'push_vlan' in action: |
Nicolas Palpacuer | 2e0fa58 | 2018-07-16 16:04:12 -0400 | [diff] [blame] | 171 | self.add_data_flow(intf_id, onu_id, priority, classifier, action) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 172 | else: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 173 | self.log.debug('Invalid-flow-type-to-handle', |
| 174 | classifier=classifier, |
| 175 | action=action) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 176 | |
Shad Ansari | 47e0c39 | 2018-07-17 23:55:07 +0000 | [diff] [blame^] | 177 | def add_data_flow(self, intf_id, onu_id, priority, uplink_classifier, |
| 178 | uplink_action): |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 179 | |
| 180 | downlink_classifier = dict(uplink_classifier) |
| 181 | downlink_action = dict(uplink_action) |
| 182 | |
| 183 | uplink_classifier['pkt_tag_type'] = 'single_tag' |
| 184 | |
| 185 | downlink_classifier['pkt_tag_type'] = 'double_tag' |
| 186 | downlink_classifier['vlan_vid'] = uplink_action['vlan_vid'] |
| 187 | downlink_classifier['metadata'] = uplink_classifier['vlan_vid'] |
| 188 | del downlink_action['push_vlan'] |
| 189 | downlink_action['pop_vlan'] = True |
| 190 | |
| 191 | # To-Do right now only one GEM port is supported, so below method |
| 192 | # will take care of handling all the p bits. |
| 193 | # We need to revisit when mulitple gem port per p bits is needed. |
Shad Ansari | 47e0c39 | 2018-07-17 23:55:07 +0000 | [diff] [blame^] | 194 | self.add_hsia_flow(intf_id, onu_id, priority, uplink_classifier, |
| 195 | uplink_action, downlink_classifier, downlink_action, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 196 | HSIA_FLOW_INDEX) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 197 | |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 198 | # Secondary EAP on the subscriber vlan |
Nicolas Palpacuer | 2e0fa58 | 2018-07-16 16:04:12 -0400 | [diff] [blame] | 199 | (eap_active, eap_priority) = self.is_eap_enabled(intf_id, onu_id) |
| 200 | if eap_active: |
| 201 | self.add_eapol_flow(intf_id, onu_id, eap_priority, |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 202 | uplink_eapol_id=EAPOL_UPLINK_SECONDARY_FLOW_INDEX, |
| 203 | downlink_eapol_id=EAPOL_DOWNLINK_SECONDARY_FLOW_INDEX, |
| 204 | vlan_id=uplink_classifier['vlan_vid']) |
| 205 | |
Shad Ansari | 47e0c39 | 2018-07-17 23:55:07 +0000 | [diff] [blame^] | 206 | def add_hsia_flow(self, intf_id, onu_id, priority, uplink_classifier, |
| 207 | uplink_action, downlink_classifier, downlink_action, |
| 208 | hsia_id): |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 209 | |
| 210 | gemport_id = platform.mk_gemport_id(onu_id) |
| 211 | flow_id = platform.mk_flow_id(intf_id, onu_id, hsia_id) |
| 212 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 213 | self.log.debug('add upstream flow', onu_id=onu_id, |
| 214 | classifier=uplink_classifier, action=uplink_action, |
| 215 | gemport_id=gemport_id, flow_id=flow_id) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 216 | |
| 217 | flow = openolt_pb2.Flow( |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 218 | onu_id=onu_id, flow_id=flow_id, flow_type="upstream", |
Nicolas Palpacuer | 2e0fa58 | 2018-07-16 16:04:12 -0400 | [diff] [blame] | 219 | access_intf_id=intf_id, gemport_id=gemport_id, priority=priority, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 220 | classifier=self.mk_classifier(uplink_classifier), |
| 221 | action=self.mk_action(uplink_action)) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 222 | |
| 223 | self.stub.FlowAdd(flow) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 224 | |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 225 | self.log.debug('add downstream flow', classifier=downlink_classifier, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 226 | action=downlink_action, gemport_id=gemport_id, |
| 227 | flow_id=flow_id) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 228 | |
| 229 | flow = openolt_pb2.Flow( |
| 230 | onu_id=onu_id, flow_id=flow_id, flow_type="downstream", |
| 231 | access_intf_id=intf_id, gemport_id=gemport_id, |
Nicolas Palpacuer | 2e0fa58 | 2018-07-16 16:04:12 -0400 | [diff] [blame] | 232 | priority=priority, |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 233 | classifier=self.mk_classifier(downlink_classifier), |
| 234 | action=self.mk_action(downlink_action)) |
| 235 | |
| 236 | self.stub.FlowAdd(flow) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 237 | |
Nicolas Palpacuer | 2e0fa58 | 2018-07-16 16:04:12 -0400 | [diff] [blame] | 238 | def add_dhcp_trap(self, intf_id, onu_id, priority, classifier, action): |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 239 | |
Shad Ansari | 47e0c39 | 2018-07-17 23:55:07 +0000 | [diff] [blame^] | 240 | self.log.debug('add dhcp upstream trap', classifier=classifier, |
| 241 | action=action) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 242 | |
| 243 | action.clear() |
| 244 | action['trap_to_host'] = True |
| 245 | classifier['pkt_tag_type'] = 'single_tag' |
| 246 | classifier.pop('vlan_vid', None) |
| 247 | |
| 248 | gemport_id = platform.mk_gemport_id(onu_id) |
| 249 | flow_id = platform.mk_flow_id(intf_id, onu_id, DHCP_FLOW_INDEX) |
| 250 | |
| 251 | upstream_flow = openolt_pb2.Flow( |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 252 | onu_id=onu_id, flow_id=flow_id, flow_type="upstream", |
Shad Ansari | 47e0c39 | 2018-07-17 23:55:07 +0000 | [diff] [blame^] | 253 | access_intf_id=intf_id, network_intf_id=0, gemport_id=gemport_id, |
| 254 | priority=priority, classifier=self.mk_classifier(classifier), |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 255 | action=self.mk_action(action)) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 256 | |
| 257 | self.stub.FlowAdd(upstream_flow) |
| 258 | |
Shad Ansari | 47e0c39 | 2018-07-17 23:55:07 +0000 | [diff] [blame^] | 259 | # FIXME - Fix OpenOLT handling of downstream flows instead |
| 260 | # of duplicating the downstream flow from the upstream |
| 261 | # flow. |
| 262 | # FIXME - ONOS should send explicit upstream and downstream |
| 263 | # exact dhcp trap flow. |
| 264 | classifier['udp_src'] = 67 |
| 265 | classifier['udp_dst'] = 68 |
| 266 | classifier['pkt_tag_type'] = 'double_tag' |
| 267 | action.pop('push_vlan', None) |
| 268 | |
| 269 | flow_id = platform.mk_flow_id(intf_id, onu_id, |
| 270 | DHCP_DOWNLINK_FLOW_INDEX) |
| 271 | |
| 272 | downstream_flow = openolt_pb2.Flow( |
| 273 | onu_id=onu_id, flow_id=flow_id, flow_type="downstream", |
| 274 | access_intf_id=intf_id, network_intf_id=0, gemport_id=gemport_id, |
| 275 | priority=priority, classifier=self.mk_classifier(classifier), |
| 276 | action=self.mk_action(action)) |
| 277 | |
| 278 | self.log.debug('add dhcp downstream trap', access_intf_id=intf_id, |
| 279 | onu_id=onu_id, flow_id=flow_id) |
| 280 | self.stub.FlowAdd(downstream_flow) |
| 281 | |
Nicolas Palpacuer | 2e0fa58 | 2018-07-16 16:04:12 -0400 | [diff] [blame] | 282 | def add_eapol_flow(self, intf_id, onu_id, priority, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 283 | uplink_eapol_id=EAPOL_FLOW_INDEX, |
| 284 | downlink_eapol_id=EAPOL_DOWNLINK_FLOW_INDEX, |
| 285 | vlan_id=DEFAULT_MGMT_VLAN): |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 286 | |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 287 | # self.log.debug('add eapol flow pre-process', |
| 288 | # classifier=uplink_classifier) |
| 289 | # #action=uplink_action) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 290 | |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 291 | downlink_classifier = {} |
| 292 | downlink_classifier['eth_type'] = EAP_ETH_TYPE |
| 293 | downlink_classifier['pkt_tag_type'] = 'single_tag' |
| 294 | downlink_classifier['vlan_vid'] = vlan_id |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 295 | |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 296 | downlink_action = {} |
| 297 | downlink_action['push_vlan'] = True |
| 298 | downlink_action['vlan_vid'] = vlan_id |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 299 | |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 300 | uplink_classifier = {} |
| 301 | uplink_classifier['eth_type'] = EAP_ETH_TYPE |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 302 | uplink_classifier['pkt_tag_type'] = 'single_tag' |
| 303 | uplink_classifier['vlan_vid'] = vlan_id |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 304 | |
| 305 | uplink_action = {} |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 306 | uplink_action['trap_to_host'] = True |
| 307 | |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 308 | gemport_id = platform.mk_gemport_id(onu_id) |
| 309 | |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 310 | # Add Upstream EAPOL Flow. |
| 311 | |
| 312 | uplink_flow_id = platform.mk_flow_id(intf_id, onu_id, uplink_eapol_id) |
| 313 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 314 | upstream_flow = openolt_pb2.Flow( |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 315 | onu_id=onu_id, flow_id=uplink_flow_id, flow_type="upstream", |
Nicolas Palpacuer | 2e0fa58 | 2018-07-16 16:04:12 -0400 | [diff] [blame] | 316 | access_intf_id=intf_id, gemport_id=gemport_id, priority=priority, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 317 | classifier=self.mk_classifier(uplink_classifier), |
| 318 | action=self.mk_action(uplink_action)) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 319 | |
| 320 | self.stub.FlowAdd(upstream_flow) |
| 321 | |
| 322 | # Add Downstream EAPOL Flow. |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 323 | downlink_flow_id = platform.mk_flow_id(intf_id, onu_id, |
| 324 | downlink_eapol_id) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 325 | |
| 326 | downstream_flow = openolt_pb2.Flow( |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 327 | onu_id=onu_id, flow_id=downlink_flow_id, flow_type="downstream", |
| 328 | access_intf_id=intf_id, gemport_id=gemport_id, |
| 329 | classifier=self.mk_classifier(downlink_classifier), |
| 330 | action=self.mk_action(downlink_action)) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 331 | |
| 332 | self.stub.FlowAdd(downstream_flow) |
| 333 | |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 334 | self.log.debug('eap flows', upstream_flow=upstream_flow, |
| 335 | downstream_flow=downstream_flow) |
| 336 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 337 | def mk_classifier(self, classifier_info): |
| 338 | |
| 339 | classifier = openolt_pb2.Classifier() |
| 340 | |
| 341 | if 'eth_type' in classifier_info: |
| 342 | classifier.eth_type = classifier_info['eth_type'] |
| 343 | if 'ip_proto' in classifier_info: |
| 344 | classifier.ip_proto = classifier_info['ip_proto'] |
| 345 | if 'vlan_vid' in classifier_info: |
| 346 | classifier.o_vid = classifier_info['vlan_vid'] |
| 347 | if 'metadata' in classifier_info: |
| 348 | classifier.i_vid = classifier_info['metadata'] |
| 349 | if 'vlan_pcp' in classifier_info: |
| 350 | classifier.o_pbits = classifier_info['vlan_pcp'] |
| 351 | if 'udp_src' in classifier_info: |
| 352 | classifier.src_port = classifier_info['udp_src'] |
| 353 | if 'udp_dst' in classifier_info: |
| 354 | classifier.dst_port = classifier_info['udp_dst'] |
| 355 | if 'ipv4_dst' in classifier_info: |
| 356 | classifier.dst_ip = classifier_info['ipv4_dst'] |
| 357 | if 'ipv4_src' in classifier_info: |
| 358 | classifier.src_ip = classifier_info['ipv4_src'] |
| 359 | if 'pkt_tag_type' in classifier_info: |
| 360 | if classifier_info['pkt_tag_type'] == 'single_tag': |
| 361 | classifier.pkt_tag_type = 'single_tag' |
| 362 | elif classifier_info['pkt_tag_type'] == 'double_tag': |
| 363 | classifier.pkt_tag_type = 'double_tag' |
| 364 | elif classifier_info['pkt_tag_type'] == 'untagged': |
| 365 | classifier.pkt_tag_type = 'untagged' |
| 366 | else: |
| 367 | classifier.pkt_tag_type = 'none' |
| 368 | |
| 369 | return classifier |
| 370 | |
| 371 | def mk_action(self, action_info): |
| 372 | action = openolt_pb2.Action() |
| 373 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 374 | if 'pop_vlan' in action_info: |
| 375 | action.o_vid = action_info['vlan_vid'] |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 376 | action.cmd.remove_outer_tag = True |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 377 | elif 'push_vlan' in action_info: |
| 378 | action.o_vid = action_info['vlan_vid'] |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 379 | action.cmd.add_outer_tag = True |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 380 | elif 'trap_to_host' in action_info: |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 381 | action.cmd.trap_to_host = True |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 382 | else: |
| 383 | self.log.info('Invalid-action-field') |
| 384 | return |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 385 | return action |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 386 | |
| 387 | def is_eap_enabled(self, intf_id, onu_id): |
| 388 | flows = self.flow_proxy.get('/').items |
| 389 | |
| 390 | for flow in flows: |
| 391 | eap_flow = False |
| 392 | eap_intf_id = None |
| 393 | eap_onu_id = None |
| 394 | for field in fd.get_ofb_fields(flow): |
| 395 | if field.type == fd.ETH_TYPE: |
| 396 | if field.eth_type == EAP_ETH_TYPE: |
| 397 | eap_flow = True |
| 398 | if field.type == fd.IN_PORT: |
Shad Ansari | 47e0c39 | 2018-07-17 23:55:07 +0000 | [diff] [blame^] | 399 | eap_intf_id = platform.intf_id_from_uni_port_num( |
| 400 | field.port) |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 401 | eap_onu_id = platform.onu_id_from_port_num(field.port) |
| 402 | |
| 403 | if eap_flow: |
| 404 | self.log.debug('eap flow detected', onu_id=onu_id, |
| 405 | intf_id=intf_id, eap_intf_id=eap_intf_id, |
| 406 | eap_onu_id=eap_onu_id) |
| 407 | if eap_flow and intf_id == eap_intf_id and onu_id == eap_onu_id: |
Nicolas Palpacuer | 2e0fa58 | 2018-07-16 16:04:12 -0400 | [diff] [blame] | 408 | return (True, flow.priority) |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 409 | |
Shad Ansari | 47e0c39 | 2018-07-17 23:55:07 +0000 | [diff] [blame^] | 410 | return (False, 0) |