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