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