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 | # |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 16 | import copy |
| 17 | from twisted.internet import reactor |
Nicolas Palpacuer | 3d0878d | 2018-08-17 11:29:42 -0400 | [diff] [blame] | 18 | import grpc |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 19 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 20 | from voltha.protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC, \ |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame^] | 21 | ofp_flow_stats, OFPMT_OXM, Flows, FlowGroups, OFPXMT_OFB_IN_PORT, \ |
| 22 | OFPXMT_OFB_VLAN_VID |
Nicolas Palpacuer | 5780e15 | 2018-09-05 17:25:42 -0400 | [diff] [blame] | 23 | from voltha.protos.device_pb2 import Port |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 24 | import voltha.core.flow_decomposer as fd |
| 25 | import openolt_platform as platform |
| 26 | from voltha.adapters.openolt.protos import openolt_pb2 |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 27 | from voltha.registry import registry |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 28 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 29 | HSIA_FLOW_INDEX = 0 # FIXME |
| 30 | DHCP_FLOW_INDEX = 1 # FIXME |
Shad Ansari | 47e0c39 | 2018-07-17 23:55:07 +0000 | [diff] [blame] | 31 | DHCP_DOWNLINK_FLOW_INDEX = 6 # FIXME |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 32 | EAPOL_FLOW_INDEX = 2 # FIXME |
| 33 | EAPOL_DOWNLINK_FLOW_INDEX = 3 # FIXME |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 34 | EAPOL_DOWNLINK_SECONDARY_FLOW_INDEX = 4 # FIXME |
| 35 | EAPOL_UPLINK_SECONDARY_FLOW_INDEX = 5 # FIXME |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame^] | 36 | LLDP_FLOW_INDEX = 7 # FIXME |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 37 | |
| 38 | EAP_ETH_TYPE = 0x888e |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame^] | 39 | LLDP_ETH_TYPE = 0x88cc |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 40 | |
| 41 | # FIXME - see also BRDCM_DEFAULT_VLAN in broadcom_onu.py |
| 42 | DEFAULT_MGMT_VLAN = 4091 |
| 43 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 44 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 45 | class OpenOltFlowMgr(object): |
| 46 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 47 | def __init__(self, log, stub, device_id, logical_device_id): |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 48 | self.log = log |
| 49 | self.stub = stub |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 50 | self.device_id = device_id |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 51 | self.logical_device_id = logical_device_id |
| 52 | self.logical_flows_proxy = registry('core').get_proxy( |
| 53 | '/logical_devices/{}/flows'.format(self.logical_device_id)) |
| 54 | self.flows_proxy = registry('core').get_proxy( |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 55 | '/devices/{}/flows'.format(self.device_id)) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 56 | self.root_proxy = registry('core').get_proxy('/') |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 57 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 58 | def add_flow(self, flow): |
| 59 | self.log.debug('add flow', flow=flow) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 60 | classifier_info = dict() |
| 61 | action_info = dict() |
| 62 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 63 | for field in fd.get_ofb_fields(flow): |
| 64 | if field.type == fd.ETH_TYPE: |
| 65 | classifier_info['eth_type'] = field.eth_type |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 66 | self.log.debug('field-type-eth-type', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 67 | eth_type=classifier_info['eth_type']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 68 | elif field.type == fd.IP_PROTO: |
| 69 | classifier_info['ip_proto'] = field.ip_proto |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 70 | self.log.debug('field-type-ip-proto', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 71 | ip_proto=classifier_info['ip_proto']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 72 | elif field.type == fd.IN_PORT: |
| 73 | classifier_info['in_port'] = field.port |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 74 | self.log.debug('field-type-in-port', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 75 | in_port=classifier_info['in_port']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 76 | elif field.type == fd.VLAN_VID: |
| 77 | classifier_info['vlan_vid'] = field.vlan_vid & 0xfff |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 78 | self.log.debug('field-type-vlan-vid', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 79 | vlan=classifier_info['vlan_vid']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 80 | elif field.type == fd.VLAN_PCP: |
| 81 | classifier_info['vlan_pcp'] = field.vlan_pcp |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 82 | self.log.debug('field-type-vlan-pcp', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 83 | pcp=classifier_info['vlan_pcp']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 84 | elif field.type == fd.UDP_DST: |
| 85 | classifier_info['udp_dst'] = field.udp_dst |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 86 | self.log.debug('field-type-udp-dst', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 87 | udp_dst=classifier_info['udp_dst']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 88 | elif field.type == fd.UDP_SRC: |
| 89 | classifier_info['udp_src'] = field.udp_src |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 90 | self.log.debug('field-type-udp-src', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 91 | udp_src=classifier_info['udp_src']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 92 | elif field.type == fd.IPV4_DST: |
| 93 | classifier_info['ipv4_dst'] = field.ipv4_dst |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 94 | self.log.debug('field-type-ipv4-dst', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 95 | ipv4_dst=classifier_info['ipv4_dst']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 96 | elif field.type == fd.IPV4_SRC: |
| 97 | classifier_info['ipv4_src'] = field.ipv4_src |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 98 | self.log.debug('field-type-ipv4-src', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 99 | ipv4_dst=classifier_info['ipv4_src']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 100 | elif field.type == fd.METADATA: |
| 101 | classifier_info['metadata'] = field.table_metadata |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 102 | self.log.debug('field-type-metadata', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 103 | metadata=classifier_info['metadata']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 104 | else: |
| 105 | raise NotImplementedError('field.type={}'.format( |
| 106 | field.type)) |
| 107 | |
| 108 | for action in fd.get_actions(flow): |
| 109 | if action.type == fd.OUTPUT: |
| 110 | action_info['output'] = action.output.port |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 111 | self.log.debug('action-type-output', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 112 | output=action_info['output'], |
| 113 | in_port=classifier_info['in_port']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 114 | elif action.type == fd.POP_VLAN: |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 115 | if fd.get_goto_table_id(flow) is None: |
| 116 | self.log.debug('being taken care of by ONU', flow=flow) |
| 117 | return |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 118 | action_info['pop_vlan'] = True |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame^] | 119 | self.log.debug('action-type-pop-vlan', |
| 120 | in_port=classifier_info['in_port']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 121 | elif action.type == fd.PUSH_VLAN: |
| 122 | action_info['push_vlan'] = True |
| 123 | action_info['tpid'] = action.push.ethertype |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 124 | self.log.debug('action-type-push-vlan', |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame^] | 125 | push_tpid=action_info['tpid'], |
| 126 | in_port=classifier_info['in_port']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 127 | if action.push.ethertype != 0x8100: |
| 128 | self.log.error('unhandled-tpid', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 129 | ethertype=action.push.ethertype) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 130 | elif action.type == fd.SET_FIELD: |
| 131 | # action_info['action_type'] = 'set_field' |
| 132 | _field = action.set_field.field.ofb_field |
| 133 | assert (action.set_field.field.oxm_class == |
| 134 | OFPXMC_OPENFLOW_BASIC) |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame^] | 135 | self.log.debug('action-type-set-field', field=_field, |
| 136 | in_port=classifier_info['in_port']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 137 | if _field.type == fd.VLAN_VID: |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 138 | self.log.debug('set-field-type-vlan-vid', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 139 | vlan_vid=_field.vlan_vid & 0xfff) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 140 | action_info['vlan_vid'] = (_field.vlan_vid & 0xfff) |
| 141 | else: |
| 142 | self.log.error('unsupported-action-set-field-type', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 143 | field_type=_field.type) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 144 | else: |
| 145 | self.log.error('unsupported-action-type', |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame^] | 146 | action_type=action.type, |
| 147 | in_port=classifier_info['in_port']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 148 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 149 | if fd.get_goto_table_id(flow) is not None and not 'pop_vlan' in \ |
| 150 | action_info: |
| 151 | self.log.debug('being taken care of by ONU', flow=flow) |
Nicolas Palpacuer | 856d3af | 2018-09-12 15:04:51 -0400 | [diff] [blame] | 152 | return |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 153 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 154 | if not 'output' in action_info and 'metadata' in classifier_info: |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame^] | 155 | # find flow in the next table |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 156 | next_flow = self.find_next_flow(flow) |
| 157 | if next_flow is None: |
| 158 | return |
| 159 | action_info['output'] = fd.get_out_port(next_flow) |
| 160 | for field in fd.get_ofb_fields(next_flow): |
| 161 | if field.type == fd.VLAN_VID: |
| 162 | classifier_info['metadata'] = field.vlan_vid & 0xfff |
| 163 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 164 | (intf_id, onu_id) = platform.extract_access_from_flow( |
| 165 | classifier_info['in_port'], action_info['output']) |
| 166 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 167 | self.divide_and_add_flow(intf_id, onu_id, classifier_info, |
| 168 | action_info, flow) |
| 169 | |
| 170 | def remove_flow(self, flow): |
| 171 | self.log.debug('trying to remove flows from logical flow :', |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame^] | 172 | logical_flow=flow) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 173 | device_flows_to_remove = [] |
| 174 | device_flows = self.flows_proxy.get('/').items |
| 175 | for f in device_flows: |
| 176 | if f.cookie == flow.id: |
| 177 | device_flows_to_remove.append(f) |
| 178 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 179 | for f in device_flows_to_remove: |
| 180 | (id, direction) = self.decode_stored_id(f.id) |
| 181 | flow_to_remove = openolt_pb2.Flow(flow_id=id, flow_type=direction) |
Nicolas Palpacuer | 3d0878d | 2018-08-17 11:29:42 -0400 | [diff] [blame] | 182 | try: |
| 183 | self.stub.FlowRemove(flow_to_remove) |
| 184 | except grpc.RpcError as grpc_e: |
| 185 | if grpc_e.code() == grpc.StatusCode.NOT_FOUND: |
| 186 | self.log.debug('This flow does not exist on the switch, ' |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame^] | 187 | 'normal after an OLT reboot', |
| 188 | flow=flow_to_remove) |
Nicolas Palpacuer | 3d0878d | 2018-08-17 11:29:42 -0400 | [diff] [blame] | 189 | else: |
| 190 | raise grpc_e |
| 191 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 192 | self.log.debug('flow removed from device', flow=f, |
| 193 | flow_key=flow_to_remove) |
| 194 | |
| 195 | if len(device_flows_to_remove) > 0: |
| 196 | new_flows = [] |
| 197 | flows_ids_to_remove = [f.id for f in device_flows_to_remove] |
| 198 | for f in device_flows: |
| 199 | if f.id not in flows_ids_to_remove: |
| 200 | new_flows.append(f) |
| 201 | |
| 202 | self.flows_proxy.update('/', Flows(items=new_flows)) |
| 203 | self.log.debug('flows removed from the data store', |
| 204 | flow_ids_removed=flows_ids_to_remove, |
| 205 | number_of_flows_removed=(len(device_flows) - len( |
| 206 | new_flows)), expected_flows_removed=len( |
| 207 | device_flows_to_remove)) |
| 208 | else: |
| 209 | self.log.debug('no device flow to remove for this flow (normal ' |
| 210 | 'for multi table flows)', flow=flow) |
| 211 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 212 | def divide_and_add_flow(self, intf_id, onu_id, classifier, |
| 213 | action, flow): |
| 214 | |
| 215 | self.log.debug('sorting flow', intf_id=intf_id, onu_id=onu_id, |
| 216 | classifier=classifier, action=action) |
| 217 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 218 | if 'ip_proto' in classifier: |
| 219 | if classifier['ip_proto'] == 17: |
| 220 | self.log.debug('dhcp flow add') |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 221 | self.add_dhcp_trap(intf_id, onu_id, classifier, |
| 222 | action, flow) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 223 | elif classifier['ip_proto'] == 2: |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 224 | self.log.warn('igmp flow add ignored, not implemented yet') |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 225 | else: |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 226 | self.log.warn("Invalid-Classifier-to-handle", |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame^] | 227 | classifier=classifier, |
| 228 | action=action) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 229 | elif 'eth_type' in classifier: |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 230 | if classifier['eth_type'] == EAP_ETH_TYPE: |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 231 | self.log.debug('eapol flow add') |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 232 | self.add_eapol_flow(intf_id, onu_id, flow) |
Nicolas Palpacuer | 4114135 | 2018-08-31 14:11:38 -0400 | [diff] [blame] | 233 | vlan_id = self.get_subscriber_vlan(fd.get_in_port(flow)) |
| 234 | if vlan_id is not None: |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame^] | 235 | self.add_eapol_flow( |
| 236 | intf_id, onu_id, flow, |
Nicolas Palpacuer | 4114135 | 2018-08-31 14:11:38 -0400 | [diff] [blame] | 237 | uplink_eapol_id=EAPOL_UPLINK_SECONDARY_FLOW_INDEX, |
| 238 | downlink_eapol_id=EAPOL_DOWNLINK_SECONDARY_FLOW_INDEX, |
| 239 | vlan_id=vlan_id) |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame^] | 240 | if classifier['eth_type'] == LLDP_ETH_TYPE: |
| 241 | self.log.debug('lldp flow add') |
| 242 | self.add_lldp_flow(intf_id, onu_id, flow, classifier, |
| 243 | action) |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 244 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 245 | elif 'push_vlan' in action: |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 246 | self.add_upstream_data_flow(intf_id, onu_id, classifier, action, |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame^] | 247 | flow) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 248 | elif 'pop_vlan' in action: |
| 249 | self.add_downstream_data_flow(intf_id, onu_id, classifier, |
| 250 | action, flow) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 251 | else: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 252 | self.log.debug('Invalid-flow-type-to-handle', |
| 253 | classifier=classifier, |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 254 | action=action, flow=flow) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 255 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 256 | def add_upstream_data_flow(self, intf_id, onu_id, uplink_classifier, |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame^] | 257 | uplink_action, logical_flow): |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 258 | |
| 259 | uplink_classifier['pkt_tag_type'] = 'single_tag' |
| 260 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 261 | self.add_hsia_flow(intf_id, onu_id, uplink_classifier, |
| 262 | uplink_action, 'upstream', HSIA_FLOW_INDEX, |
| 263 | logical_flow) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 264 | |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 265 | # Secondary EAP on the subscriber vlan |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 266 | (eap_active, eap_logical_flow) = self.is_eap_enabled(intf_id, onu_id) |
Nicolas Palpacuer | 2e0fa58 | 2018-07-16 16:04:12 -0400 | [diff] [blame] | 267 | if eap_active: |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame^] | 268 | self.add_eapol_flow( |
| 269 | intf_id, onu_id, eap_logical_flow, |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 270 | uplink_eapol_id=EAPOL_UPLINK_SECONDARY_FLOW_INDEX, |
| 271 | downlink_eapol_id=EAPOL_DOWNLINK_SECONDARY_FLOW_INDEX, |
| 272 | vlan_id=uplink_classifier['vlan_vid']) |
| 273 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 274 | def add_downstream_data_flow(self, intf_id, onu_id, downlink_classifier, |
| 275 | downlink_action, flow): |
| 276 | downlink_classifier['pkt_tag_type'] = 'double_tag' |
| 277 | # Needed ???? It should be already there |
| 278 | downlink_action['pop_vlan'] = True |
| 279 | downlink_action['vlan_vid'] = downlink_classifier['vlan_vid'] |
| 280 | |
| 281 | self.add_hsia_flow(intf_id, onu_id, downlink_classifier, |
| 282 | downlink_action, 'downstream', HSIA_FLOW_INDEX, |
| 283 | flow) |
| 284 | |
| 285 | # To-Do right now only one GEM port is supported, so below method |
| 286 | # will take care of handling all the p bits. |
| 287 | # We need to revisit when mulitple gem port per p bits is needed. |
Nicolas Palpacuer | 6152a32 | 2018-09-05 10:52:15 -0400 | [diff] [blame] | 288 | # Waiting for Technology profile |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 289 | def add_hsia_flow(self, intf_id, onu_id, classifier, action, |
| 290 | direction, hsia_id, logical_flow): |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 291 | |
Nicolas Palpacuer | e9bf83c | 2018-08-16 14:53:14 -0400 | [diff] [blame] | 292 | gemport_id = platform.mk_gemport_id(intf_id, onu_id) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 293 | flow_id = platform.mk_flow_id(intf_id, onu_id, hsia_id) |
| 294 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 295 | flow = openolt_pb2.Flow( |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 296 | onu_id=onu_id, flow_id=flow_id, flow_type=direction, |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 297 | access_intf_id=intf_id, gemport_id=gemport_id, |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 298 | priority=logical_flow.priority, |
| 299 | classifier=self.mk_classifier(classifier), |
| 300 | action=self.mk_action(action)) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 301 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 302 | self.add_flow_to_device(flow, logical_flow) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 303 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 304 | def add_dhcp_trap(self, intf_id, onu_id, classifier, action, logical_flow): |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 305 | |
Shad Ansari | 47e0c39 | 2018-07-17 23:55:07 +0000 | [diff] [blame] | 306 | self.log.debug('add dhcp upstream trap', classifier=classifier, |
| 307 | action=action) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 308 | |
| 309 | action.clear() |
| 310 | action['trap_to_host'] = True |
| 311 | classifier['pkt_tag_type'] = 'single_tag' |
| 312 | classifier.pop('vlan_vid', None) |
| 313 | |
Nicolas Palpacuer | e9bf83c | 2018-08-16 14:53:14 -0400 | [diff] [blame] | 314 | gemport_id = platform.mk_gemport_id(intf_id, onu_id) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 315 | flow_id = platform.mk_flow_id(intf_id, onu_id, DHCP_FLOW_INDEX) |
| 316 | |
| 317 | upstream_flow = openolt_pb2.Flow( |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 318 | onu_id=onu_id, flow_id=flow_id, flow_type="upstream", |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 319 | access_intf_id=intf_id, gemport_id=gemport_id, |
| 320 | priority=logical_flow.priority, |
| 321 | classifier=self.mk_classifier(classifier), |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 322 | action=self.mk_action(action)) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 323 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 324 | self.add_flow_to_device(upstream_flow, logical_flow) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 325 | |
Shad Ansari | 47e0c39 | 2018-07-17 23:55:07 +0000 | [diff] [blame] | 326 | # FIXME - ONOS should send explicit upstream and downstream |
| 327 | # exact dhcp trap flow. |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 328 | |
| 329 | downstream_logical_flow = copy.deepcopy(logical_flow) |
| 330 | for oxm_field in downstream_logical_flow.match.oxm_fields: |
| 331 | if oxm_field.ofb_field.type == OFPXMT_OFB_IN_PORT: |
Nicolas Palpacuer | 5780e15 | 2018-09-05 17:25:42 -0400 | [diff] [blame] | 332 | oxm_field.ofb_field.port = \ |
| 333 | platform.intf_id_to_port_no(0, Port.ETHERNET_NNI) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 334 | |
Shad Ansari | 47e0c39 | 2018-07-17 23:55:07 +0000 | [diff] [blame] | 335 | classifier['udp_src'] = 67 |
| 336 | classifier['udp_dst'] = 68 |
| 337 | classifier['pkt_tag_type'] = 'double_tag' |
| 338 | action.pop('push_vlan', None) |
| 339 | |
| 340 | flow_id = platform.mk_flow_id(intf_id, onu_id, |
| 341 | DHCP_DOWNLINK_FLOW_INDEX) |
| 342 | |
| 343 | downstream_flow = openolt_pb2.Flow( |
| 344 | onu_id=onu_id, flow_id=flow_id, flow_type="downstream", |
| 345 | access_intf_id=intf_id, network_intf_id=0, gemport_id=gemport_id, |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 346 | priority=logical_flow.priority, classifier=self.mk_classifier( |
| 347 | classifier), |
Shad Ansari | 47e0c39 | 2018-07-17 23:55:07 +0000 | [diff] [blame] | 348 | action=self.mk_action(action)) |
| 349 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 350 | self.add_flow_to_device(downstream_flow, downstream_logical_flow) |
| 351 | |
| 352 | def add_eapol_flow(self, intf_id, onu_id, logical_flow, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 353 | uplink_eapol_id=EAPOL_FLOW_INDEX, |
| 354 | downlink_eapol_id=EAPOL_DOWNLINK_FLOW_INDEX, |
| 355 | vlan_id=DEFAULT_MGMT_VLAN): |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 356 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 357 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 358 | |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 359 | uplink_classifier = {} |
| 360 | uplink_classifier['eth_type'] = EAP_ETH_TYPE |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 361 | uplink_classifier['pkt_tag_type'] = 'single_tag' |
| 362 | uplink_classifier['vlan_vid'] = vlan_id |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 363 | |
| 364 | uplink_action = {} |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 365 | uplink_action['trap_to_host'] = True |
| 366 | |
Nicolas Palpacuer | e9bf83c | 2018-08-16 14:53:14 -0400 | [diff] [blame] | 367 | gemport_id = platform.mk_gemport_id(intf_id, onu_id) |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 368 | |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 369 | # Add Upstream EAPOL Flow. |
| 370 | |
| 371 | uplink_flow_id = platform.mk_flow_id(intf_id, onu_id, uplink_eapol_id) |
| 372 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 373 | upstream_flow = openolt_pb2.Flow( |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 374 | onu_id=onu_id, flow_id=uplink_flow_id, flow_type="upstream", |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 375 | access_intf_id=intf_id, gemport_id=gemport_id, |
| 376 | priority=logical_flow.priority, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 377 | classifier=self.mk_classifier(uplink_classifier), |
| 378 | action=self.mk_action(uplink_action)) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 379 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 380 | logical_flow = copy.deepcopy(logical_flow) |
| 381 | logical_flow.match.oxm_fields.extend(fd.mk_oxm_fields([fd.vlan_vid( |
| 382 | vlan_id | 0x1000)])) |
| 383 | logical_flow.match.type = OFPMT_OXM |
| 384 | |
| 385 | self.add_flow_to_device(upstream_flow, logical_flow) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 386 | |
Nicolas Palpacuer | 6152a32 | 2018-09-05 10:52:15 -0400 | [diff] [blame] | 387 | if vlan_id == DEFAULT_MGMT_VLAN: |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 388 | |
Nicolas Palpacuer | 6152a32 | 2018-09-05 10:52:15 -0400 | [diff] [blame] | 389 | # Add Downstream EAPOL Flow, Only for first EAP flow |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 390 | |
Nicolas Palpacuer | 6152a32 | 2018-09-05 10:52:15 -0400 | [diff] [blame] | 391 | downlink_classifier = {} |
| 392 | downlink_classifier['pkt_tag_type'] = 'single_tag' |
| 393 | downlink_classifier['vlan_vid'] = 4000 - onu_id |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 394 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 395 | |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame^] | 396 | |
Nicolas Palpacuer | 6152a32 | 2018-09-05 10:52:15 -0400 | [diff] [blame] | 397 | downlink_action = {} |
| 398 | downlink_action['push_vlan'] = True |
| 399 | downlink_action['vlan_vid'] = vlan_id |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 400 | |
Nicolas Palpacuer | 6152a32 | 2018-09-05 10:52:15 -0400 | [diff] [blame] | 401 | downlink_flow_id = platform.mk_flow_id(intf_id, onu_id, |
| 402 | downlink_eapol_id) |
| 403 | |
| 404 | downstream_flow = openolt_pb2.Flow( |
| 405 | onu_id=onu_id, flow_id=downlink_flow_id, flow_type="downstream", |
| 406 | access_intf_id=intf_id, gemport_id=gemport_id, |
| 407 | priority=logical_flow.priority, |
| 408 | classifier=self.mk_classifier(downlink_classifier), |
| 409 | action=self.mk_action(downlink_action)) |
| 410 | |
| 411 | downstream_logical_flow = ofp_flow_stats(id=logical_flow.id, |
| 412 | cookie=logical_flow.cookie, table_id=logical_flow.table_id, |
| 413 | priority=logical_flow.priority, flags=logical_flow.flags) |
| 414 | |
| 415 | downstream_logical_flow.match.oxm_fields.extend(fd.mk_oxm_fields([ |
| 416 | fd.in_port(fd.get_out_port(logical_flow)), |
| 417 | fd.vlan_vid((4000 - onu_id) | 0x1000)])) |
| 418 | downstream_logical_flow.match.type = OFPMT_OXM |
| 419 | |
| 420 | downstream_logical_flow.instructions.extend( |
| 421 | fd.mk_instructions_from_actions([fd.output( |
| 422 | platform.mk_uni_port_num(intf_id, onu_id))])) |
| 423 | |
| 424 | self.add_flow_to_device(downstream_flow, downstream_logical_flow) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 425 | |
Nicolas Palpacuer | 4114135 | 2018-08-31 14:11:38 -0400 | [diff] [blame] | 426 | def repush_all_different_flows(self): |
| 427 | # Check if the device is supposed to have flows, if so add them |
| 428 | # Recover static flows after a reboot |
| 429 | logical_flows = self.logical_flows_proxy.get('/').items |
| 430 | devices_flows = self.flows_proxy.get('/').items |
| 431 | logical_flows_ids_provisioned = [f.cookie for f in devices_flows] |
| 432 | for logical_flow in logical_flows: |
| 433 | try: |
| 434 | if logical_flow.id not in logical_flows_ids_provisioned: |
| 435 | self.add_flow(logical_flow) |
| 436 | except Exception as e: |
| 437 | self.log.debug('Problem readding this flow', error=e) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 438 | |
Nicolas Palpacuer | 4114135 | 2018-08-31 14:11:38 -0400 | [diff] [blame] | 439 | def reset_flows(self): |
| 440 | self.flows_proxy.update('/', Flows()) |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 441 | |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame^] | 442 | def add_lldp_flow(self, intf_id, onu_id, logical_flow, classifier, action): |
| 443 | |
| 444 | self.log.debug('add lldp downstream trap', classifier=classifier, |
| 445 | action=action) |
| 446 | |
| 447 | action.clear() |
| 448 | action['trap_to_host'] = True |
| 449 | classifier['pkt_tag_type'] = 'untagged' |
| 450 | |
| 451 | gemport_id = platform.mk_gemport_id(onu_id) |
| 452 | flow_id = platform.mk_flow_id(intf_id, onu_id, LLDP_FLOW_INDEX) |
| 453 | |
| 454 | downstream_flow = openolt_pb2.Flow( |
| 455 | onu_id=onu_id, flow_id=flow_id, flow_type="downstream", |
| 456 | access_intf_id=3, network_intf_id=0, gemport_id=gemport_id, |
| 457 | priority=logical_flow.priority, |
| 458 | classifier=self.mk_classifier(classifier), |
| 459 | action=self.mk_action(action)) |
| 460 | |
| 461 | self.log.debug('add lldp downstream trap', access_intf_id=intf_id, |
| 462 | onu_id=onu_id, flow_id=flow_id) |
| 463 | self.stub.FlowAdd(downstream_flow) |
| 464 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 465 | def mk_classifier(self, classifier_info): |
| 466 | |
| 467 | classifier = openolt_pb2.Classifier() |
| 468 | |
| 469 | if 'eth_type' in classifier_info: |
| 470 | classifier.eth_type = classifier_info['eth_type'] |
| 471 | if 'ip_proto' in classifier_info: |
| 472 | classifier.ip_proto = classifier_info['ip_proto'] |
| 473 | if 'vlan_vid' in classifier_info: |
| 474 | classifier.o_vid = classifier_info['vlan_vid'] |
| 475 | if 'metadata' in classifier_info: |
| 476 | classifier.i_vid = classifier_info['metadata'] |
| 477 | if 'vlan_pcp' in classifier_info: |
| 478 | classifier.o_pbits = classifier_info['vlan_pcp'] |
| 479 | if 'udp_src' in classifier_info: |
| 480 | classifier.src_port = classifier_info['udp_src'] |
| 481 | if 'udp_dst' in classifier_info: |
| 482 | classifier.dst_port = classifier_info['udp_dst'] |
| 483 | if 'ipv4_dst' in classifier_info: |
| 484 | classifier.dst_ip = classifier_info['ipv4_dst'] |
| 485 | if 'ipv4_src' in classifier_info: |
| 486 | classifier.src_ip = classifier_info['ipv4_src'] |
| 487 | if 'pkt_tag_type' in classifier_info: |
| 488 | if classifier_info['pkt_tag_type'] == 'single_tag': |
| 489 | classifier.pkt_tag_type = 'single_tag' |
| 490 | elif classifier_info['pkt_tag_type'] == 'double_tag': |
| 491 | classifier.pkt_tag_type = 'double_tag' |
| 492 | elif classifier_info['pkt_tag_type'] == 'untagged': |
| 493 | classifier.pkt_tag_type = 'untagged' |
| 494 | else: |
| 495 | classifier.pkt_tag_type = 'none' |
| 496 | |
| 497 | return classifier |
| 498 | |
| 499 | def mk_action(self, action_info): |
| 500 | action = openolt_pb2.Action() |
| 501 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 502 | if 'pop_vlan' in action_info: |
| 503 | action.o_vid = action_info['vlan_vid'] |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 504 | action.cmd.remove_outer_tag = True |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 505 | elif 'push_vlan' in action_info: |
| 506 | action.o_vid = action_info['vlan_vid'] |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 507 | action.cmd.add_outer_tag = True |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 508 | elif 'trap_to_host' in action_info: |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 509 | action.cmd.trap_to_host = True |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 510 | else: |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 511 | self.log.info('Invalid-action-field', action_info=action_info) |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 512 | return |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 513 | return action |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 514 | |
| 515 | def is_eap_enabled(self, intf_id, onu_id): |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 516 | flows = self.logical_flows_proxy.get('/').items |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 517 | |
| 518 | for flow in flows: |
| 519 | eap_flow = False |
| 520 | eap_intf_id = None |
| 521 | eap_onu_id = None |
| 522 | for field in fd.get_ofb_fields(flow): |
| 523 | if field.type == fd.ETH_TYPE: |
| 524 | if field.eth_type == EAP_ETH_TYPE: |
| 525 | eap_flow = True |
| 526 | if field.type == fd.IN_PORT: |
Shad Ansari | 47e0c39 | 2018-07-17 23:55:07 +0000 | [diff] [blame] | 527 | eap_intf_id = platform.intf_id_from_uni_port_num( |
| 528 | field.port) |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 529 | eap_onu_id = platform.onu_id_from_port_num(field.port) |
| 530 | |
| 531 | if eap_flow: |
| 532 | self.log.debug('eap flow detected', onu_id=onu_id, |
| 533 | intf_id=intf_id, eap_intf_id=eap_intf_id, |
| 534 | eap_onu_id=eap_onu_id) |
| 535 | if eap_flow and intf_id == eap_intf_id and onu_id == eap_onu_id: |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 536 | return (True, flow) |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 537 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 538 | return (False, None) |
| 539 | |
Nicolas Palpacuer | 4114135 | 2018-08-31 14:11:38 -0400 | [diff] [blame] | 540 | def get_subscriber_vlan(self, port): |
| 541 | self.log.debug('looking from subscriber flow for port', port=port) |
| 542 | |
| 543 | flows = self.logical_flows_proxy.get('/').items |
| 544 | for flow in flows: |
| 545 | in_port = fd.get_in_port(flow) |
| 546 | out_port = fd.get_out_port(flow) |
Nicolas Palpacuer | 5780e15 | 2018-09-05 17:25:42 -0400 | [diff] [blame] | 547 | |
| 548 | if in_port == port and \ |
| 549 | platform.intf_id_to_port_type_name(out_port) == Port.ETHERNET_NNI: |
Nicolas Palpacuer | 4114135 | 2018-08-31 14:11:38 -0400 | [diff] [blame] | 550 | fields = fd.get_ofb_fields(flow) |
| 551 | self.log.debug('subscriber flow found', fields=fields) |
| 552 | for field in fields: |
| 553 | if field.type == OFPXMT_OFB_VLAN_VID: |
| 554 | self.log.debug('subscriber vlan found', |
| 555 | vlan_id=field.vlan_vid) |
| 556 | return field.vlan_vid & 0x0fff |
| 557 | self.log.debug('No subscriber flow found', port=port) |
| 558 | return None |
| 559 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 560 | def add_flow_to_device(self, flow, logical_flow): |
| 561 | self.log.debug('pushing flow to device', flow=flow) |
| 562 | self.stub.FlowAdd(flow) |
| 563 | self.register_flow(logical_flow, flow) |
| 564 | |
| 565 | def register_flow(self, logical_flow, device_flow): |
| 566 | self.log.debug('registering flow in device', |
| 567 | logical_flow=logical_flow, device_flow=device_flow) |
| 568 | stored_flow = copy.deepcopy(logical_flow) |
| 569 | stored_flow.id = self.generate_stored_id(device_flow.flow_id, |
| 570 | device_flow.flow_type) |
| 571 | self.log.debug('generated device flow id', id=stored_flow.id, |
| 572 | flow_id=device_flow.flow_id, |
| 573 | direction=device_flow.flow_type) |
| 574 | stored_flow.cookie = logical_flow.id |
| 575 | flows = self.flows_proxy.get('/') |
| 576 | flows.items.extend([stored_flow]) |
| 577 | self.flows_proxy.update('/', flows) |
| 578 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 579 | def find_next_flow(self, flow): |
| 580 | table_id = fd.get_goto_table_id(flow) |
| 581 | metadata = 0 |
| 582 | for field in fd.get_ofb_fields(flow): |
| 583 | if field.type == fd.METADATA: |
| 584 | metadata = field.table_metadata |
| 585 | if table_id is None: |
| 586 | return None |
| 587 | flows = self.logical_flows_proxy.get('/').items |
| 588 | next_flows = [] |
| 589 | for f in flows: |
| 590 | if f.table_id == table_id: |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame^] | 591 | # FIXME |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 592 | if fd.get_in_port(f) == fd.get_in_port(flow) and \ |
| 593 | fd.get_out_port(f) == metadata: |
| 594 | |
| 595 | next_flows.append(f) |
| 596 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 597 | if len(next_flows) == 0: |
| 598 | self.log.warning('no next flow found, it may be a timing issue', |
| 599 | flow=flow, number_of_flows=len(flows)) |
| 600 | reactor.callLater(5, self.add_flow, flow) |
| 601 | return None |
| 602 | |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame^] | 603 | next_flows.sort(key=lambda f: f.priority, reverse=True) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 604 | |
| 605 | return next_flows[0] |
| 606 | |
| 607 | def update_children_flows(self, device_rules_map): |
| 608 | |
| 609 | for device_id, (flows, groups) in device_rules_map.iteritems(): |
| 610 | if device_id != self.device_id: |
| 611 | self.root_proxy.update('/devices/{}/flows'.format(device_id), |
| 612 | Flows(items=flows.values())) |
| 613 | self.root_proxy.update('/devices/{}/flow_groups'.format( |
| 614 | device_id), FlowGroups(items=groups.values())) |
| 615 | |
| 616 | def generate_stored_id(self, flow_id, direction): |
| 617 | if direction == 'upstream': |
| 618 | self.log.debug('upstream flow, shifting id') |
| 619 | return 0x1 << 15 | flow_id |
| 620 | elif direction == 'downstream': |
| 621 | self.log.debug('downstream flow, not shifting id') |
| 622 | return flow_id |
| 623 | else: |
| 624 | self.log.warn('Unrecognized direction', direction=direction) |
| 625 | return flow_id |
| 626 | |
| 627 | def decode_stored_id(self, id): |
| 628 | if id >> 15 == 0x1: |
| 629 | return (id & 0x7fff, 'upstream') |
| 630 | else: |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame^] | 631 | return (id, 'downstream') |