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 | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 19 | from google.protobuf.json_format import MessageToDict |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 20 | import hashlib |
| 21 | from simplejson import dumps |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 22 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 23 | from voltha.protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC, \ |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame] | 24 | ofp_flow_stats, OFPMT_OXM, Flows, FlowGroups, OFPXMT_OFB_IN_PORT, \ |
| 25 | OFPXMT_OFB_VLAN_VID |
Nicolas Palpacuer | 5780e15 | 2018-09-05 17:25:42 -0400 | [diff] [blame] | 26 | from voltha.protos.device_pb2 import Port |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 27 | import voltha.core.flow_decomposer as fd |
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 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 31 | from common.tech_profile.tech_profile import DEFAULT_TECH_PROFILE_TABLE_ID |
| 32 | |
| 33 | # Flow categories |
| 34 | HSIA_FLOW = "HSIA_FLOW" |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 35 | |
| 36 | EAP_ETH_TYPE = 0x888e |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame] | 37 | LLDP_ETH_TYPE = 0x88cc |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 38 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 39 | IGMP_PROTO = 2 |
| 40 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 41 | # FIXME - see also BRDCM_DEFAULT_VLAN in broadcom_onu.py |
| 42 | DEFAULT_MGMT_VLAN = 4091 |
Thiyagarajan Subramani | 3b62d6c | 2019-02-15 08:48:01 -0800 | [diff] [blame] | 43 | RESERVED_VLAN = 4095 |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 44 | |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 45 | # Openolt Flow |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 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" |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 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 | |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 71 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 72 | class OpenOltFlowMgr(object): |
| 73 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 74 | def __init__(self, adapter_agent, log, stub, device_id, logical_device_id, |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 75 | platform, resource_mgr): |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 76 | self.adapter_agent = adapter_agent |
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 |
Girish Gowdru | be328a0 | 2019-01-26 21:44:40 -0800 | [diff] [blame] | 81 | self.nni_intf_id = None |
Shad Ansari | cd20a6d | 2018-10-02 14:36:33 +0000 | [diff] [blame] | 82 | self.platform = platform |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 83 | self.logical_flows_proxy = registry('core').get_proxy( |
| 84 | '/logical_devices/{}/flows'.format(self.logical_device_id)) |
| 85 | self.flows_proxy = registry('core').get_proxy( |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 86 | '/devices/{}/flows'.format(self.device_id)) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 87 | self.root_proxy = registry('core').get_proxy('/') |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 88 | self.resource_mgr = resource_mgr |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 89 | self.tech_profile = dict() |
| 90 | self._populate_tech_profile_per_pon_port() |
Scott Baker | be5a9ea | 2018-11-19 19:24:21 -0800 | [diff] [blame] | 91 | self.retry_add_flow_list = [] |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 92 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 93 | def add_flow(self, flow): |
| 94 | self.log.debug('add flow', flow=flow) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 95 | classifier_info = dict() |
| 96 | action_info = dict() |
| 97 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 98 | for field in fd.get_ofb_fields(flow): |
| 99 | if field.type == fd.ETH_TYPE: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 100 | classifier_info[ETH_TYPE] = field.eth_type |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 101 | self.log.debug('field-type-eth-type', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 102 | eth_type=classifier_info[ETH_TYPE]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 103 | elif field.type == fd.IP_PROTO: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 104 | classifier_info[IP_PROTO] = field.ip_proto |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 105 | self.log.debug('field-type-ip-proto', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 106 | ip_proto=classifier_info[IP_PROTO]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 107 | elif field.type == fd.IN_PORT: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 108 | classifier_info[IN_PORT] = field.port |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 109 | self.log.debug('field-type-in-port', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 110 | in_port=classifier_info[IN_PORT]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 111 | elif field.type == fd.VLAN_VID: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 112 | classifier_info[VLAN_VID] = field.vlan_vid & 0xfff |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 113 | self.log.debug('field-type-vlan-vid', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 114 | vlan=classifier_info[VLAN_VID]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 115 | elif field.type == fd.VLAN_PCP: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 116 | classifier_info[VLAN_PCP] = field.vlan_pcp |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 117 | self.log.debug('field-type-vlan-pcp', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 118 | pcp=classifier_info[VLAN_PCP]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 119 | elif field.type == fd.UDP_DST: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 120 | classifier_info[UDP_DST] = field.udp_dst |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 121 | self.log.debug('field-type-udp-dst', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 122 | udp_dst=classifier_info[UDP_DST]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 123 | elif field.type == fd.UDP_SRC: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 124 | classifier_info[UDP_SRC] = field.udp_src |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 125 | self.log.debug('field-type-udp-src', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 126 | udp_src=classifier_info[UDP_SRC]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 127 | elif field.type == fd.IPV4_DST: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 128 | classifier_info[IPV4_DST] = field.ipv4_dst |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 129 | self.log.debug('field-type-ipv4-dst', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 130 | ipv4_dst=classifier_info[IPV4_DST]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 131 | elif field.type == fd.IPV4_SRC: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 132 | classifier_info[IPV4_SRC] = field.ipv4_src |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 133 | self.log.debug('field-type-ipv4-src', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 134 | ipv4_dst=classifier_info[IPV4_SRC]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 135 | elif field.type == fd.METADATA: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 136 | classifier_info[METADATA] = field.table_metadata |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 137 | self.log.debug('field-type-metadata', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 138 | metadata=classifier_info[METADATA]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 139 | else: |
| 140 | raise NotImplementedError('field.type={}'.format( |
| 141 | field.type)) |
| 142 | |
| 143 | for action in fd.get_actions(flow): |
| 144 | if action.type == fd.OUTPUT: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 145 | action_info[OUTPUT] = action.output.port |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 146 | self.log.debug('action-type-output', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 147 | output=action_info[OUTPUT], |
| 148 | in_port=classifier_info[IN_PORT]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 149 | elif action.type == fd.POP_VLAN: |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 150 | if fd.get_goto_table_id(flow) is None: |
| 151 | self.log.debug('being taken care of by ONU', flow=flow) |
| 152 | return |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 153 | action_info[POP_VLAN] = True |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame] | 154 | self.log.debug('action-type-pop-vlan', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 155 | in_port=classifier_info[IN_PORT]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 156 | elif action.type == fd.PUSH_VLAN: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 157 | action_info[PUSH_VLAN] = True |
| 158 | action_info[TPID] = action.push.ethertype |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 159 | self.log.debug('action-type-push-vlan', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 160 | push_tpid=action_info[TPID], in_port=classifier_info[IN_PORT]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 161 | if action.push.ethertype != 0x8100: |
| 162 | self.log.error('unhandled-tpid', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 163 | ethertype=action.push.ethertype) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 164 | elif action.type == fd.SET_FIELD: |
| 165 | # action_info['action_type'] = 'set_field' |
| 166 | _field = action.set_field.field.ofb_field |
| 167 | assert (action.set_field.field.oxm_class == |
| 168 | OFPXMC_OPENFLOW_BASIC) |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 169 | self.log.debug('action-type-set-field', |
| 170 | field=_field, in_port=classifier_info[IN_PORT]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 171 | if _field.type == fd.VLAN_VID: |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 172 | self.log.debug('set-field-type-vlan-vid', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 173 | vlan_vid=_field.vlan_vid & 0xfff) |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 174 | action_info[VLAN_VID] = (_field.vlan_vid & 0xfff) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 175 | else: |
| 176 | self.log.error('unsupported-action-set-field-type', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 177 | field_type=_field.type) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 178 | else: |
| 179 | self.log.error('unsupported-action-type', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 180 | action_type=action.type, in_port=classifier_info[IN_PORT]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 181 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 182 | if fd.get_goto_table_id(flow) is not None and POP_VLAN not in action_info: |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 183 | self.log.debug('being taken care of by ONU', flow=flow) |
Nicolas Palpacuer | 856d3af | 2018-09-12 15:04:51 -0400 | [diff] [blame] | 184 | return |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 185 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 186 | if OUTPUT not in action_info and METADATA in classifier_info: |
| 187 | # find flow in the next table |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 188 | next_flow = self.find_next_flow(flow) |
| 189 | if next_flow is None: |
| 190 | return |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 191 | action_info[OUTPUT] = fd.get_out_port(next_flow) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 192 | for field in fd.get_ofb_fields(next_flow): |
| 193 | if field.type == fd.VLAN_VID: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 194 | classifier_info[METADATA] = field.vlan_vid & 0xfff |
| 195 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 196 | self.log.debug('flow-ports', classifier_inport=classifier_info[IN_PORT], action_output=action_info[OUTPUT]) |
| 197 | (port_no, intf_id, onu_id, uni_id) = self.platform.extract_access_from_flow( |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 198 | classifier_info[IN_PORT], action_info[OUTPUT]) |
| 199 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 200 | self.divide_and_add_flow(intf_id, onu_id, uni_id, port_no, classifier_info, |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 201 | action_info, flow) |
| 202 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 203 | def _is_uni_port(self, port_no): |
| 204 | try: |
| 205 | port = self.adapter_agent.get_logical_port(self.logical_device_id, |
| 206 | 'uni-{}'.format(port_no)) |
| 207 | if port is not None: |
| 208 | return (not port.root_port), port.device_id |
| 209 | else: |
| 210 | return False, None |
| 211 | except Exception as e: |
| 212 | self.log.error("error-retrieving-port", e=e) |
| 213 | return False, None |
| 214 | |
| 215 | def _clear_flow_id_from_rm(self, flow, flow_id, flow_direction): |
| 216 | uni_port_no = None |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 217 | child_device_id = None |
| 218 | if flow_direction == UPSTREAM: |
| 219 | for field in fd.get_ofb_fields(flow): |
| 220 | if field.type == fd.IN_PORT: |
| 221 | is_uni, child_device_id = self._is_uni_port(field.port) |
| 222 | if is_uni: |
| 223 | uni_port_no = field.port |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 224 | elif flow_direction == DOWNSTREAM: |
| 225 | for field in fd.get_ofb_fields(flow): |
| 226 | if field.type == fd.METADATA: |
| 227 | uni_port = field.table_metadata & 0xFFFFFFFF |
| 228 | is_uni, child_device_id = self._is_uni_port(uni_port) |
| 229 | if is_uni: |
| 230 | uni_port_no = field.port |
| 231 | |
| 232 | if uni_port_no is None: |
| 233 | for action in fd.get_actions(flow): |
| 234 | if action.type == fd.OUTPUT: |
| 235 | is_uni, child_device_id = \ |
| 236 | self._is_uni_port(action.output.port) |
| 237 | if is_uni: |
| 238 | uni_port_no = action.output.port |
| 239 | |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 240 | if child_device_id: |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 241 | child_device = self.adapter_agent.get_device(child_device_id) |
| 242 | pon_intf = child_device.proxy_address.channel_id |
| 243 | onu_id = child_device.proxy_address.onu_id |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 244 | uni_id = self.platform.uni_id_from_port_num(uni_port_no) if uni_port_no is not None else None |
| 245 | flows = self.resource_mgr.get_flow_id_info(pon_intf, onu_id, uni_id, flow_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 246 | assert (isinstance(flows, list)) |
| 247 | self.log.debug("retrieved-flows", flows=flows) |
| 248 | for idx in range(len(flows)): |
| 249 | if flow_direction == flows[idx]['flow_type']: |
| 250 | flows.pop(idx) |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 251 | self.update_flow_info_to_kv_store(pon_intf, onu_id, uni_id, flow_id, flows) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 252 | if len(flows) > 0: |
| 253 | # There are still flows referencing the same flow_id. |
| 254 | # So the flow should not be freed yet. |
| 255 | # For ex: Case of HSIA where same flow is shared |
| 256 | # between DS and US. |
| 257 | return |
| 258 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 259 | self.resource_mgr.free_flow_id(pon_intf, onu_id, uni_id, flow_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 260 | else: |
| 261 | self.log.error("invalid-info", uni_port_no=uni_port_no, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 262 | child_device_id=child_device_id) |
| 263 | |
Scott Baker | be5a9ea | 2018-11-19 19:24:21 -0800 | [diff] [blame] | 264 | def retry_add_flow(self, flow): |
| 265 | self.log.debug("retry-add-flow") |
| 266 | if flow.id in self.retry_add_flow_list: |
| 267 | self.retry_add_flow_list.remove(flow.id) |
| 268 | self.add_flow(flow) |
| 269 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 270 | def remove_flow(self, flow): |
| 271 | self.log.debug('trying to remove flows from logical flow :', |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame] | 272 | logical_flow=flow) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 273 | device_flows_to_remove = [] |
| 274 | device_flows = self.flows_proxy.get('/').items |
| 275 | for f in device_flows: |
| 276 | if f.cookie == flow.id: |
| 277 | device_flows_to_remove.append(f) |
| 278 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 279 | for f in device_flows_to_remove: |
| 280 | (id, direction) = self.decode_stored_id(f.id) |
| 281 | flow_to_remove = openolt_pb2.Flow(flow_id=id, flow_type=direction) |
Nicolas Palpacuer | 3d0878d | 2018-08-17 11:29:42 -0400 | [diff] [blame] | 282 | try: |
| 283 | self.stub.FlowRemove(flow_to_remove) |
| 284 | except grpc.RpcError as grpc_e: |
| 285 | if grpc_e.code() == grpc.StatusCode.NOT_FOUND: |
| 286 | self.log.debug('This flow does not exist on the switch, ' |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame] | 287 | 'normal after an OLT reboot', |
| 288 | flow=flow_to_remove) |
Nicolas Palpacuer | 3d0878d | 2018-08-17 11:29:42 -0400 | [diff] [blame] | 289 | else: |
| 290 | raise grpc_e |
| 291 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 292 | # once we have successfully deleted the flow on the device |
| 293 | # release the flow_id on resource pool and also clear any |
| 294 | # data associated with the flow_id on KV store. |
| 295 | self._clear_flow_id_from_rm(f, id, direction) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 296 | self.log.debug('flow removed from device', flow=f, |
| 297 | flow_key=flow_to_remove) |
| 298 | |
| 299 | if len(device_flows_to_remove) > 0: |
| 300 | new_flows = [] |
| 301 | flows_ids_to_remove = [f.id for f in device_flows_to_remove] |
| 302 | for f in device_flows: |
| 303 | if f.id not in flows_ids_to_remove: |
| 304 | new_flows.append(f) |
| 305 | |
| 306 | self.flows_proxy.update('/', Flows(items=new_flows)) |
| 307 | self.log.debug('flows removed from the data store', |
| 308 | flow_ids_removed=flows_ids_to_remove, |
| 309 | number_of_flows_removed=(len(device_flows) - len( |
| 310 | new_flows)), expected_flows_removed=len( |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 311 | device_flows_to_remove)) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 312 | else: |
| 313 | self.log.debug('no device flow to remove for this flow (normal ' |
| 314 | 'for multi table flows)', flow=flow) |
| 315 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 316 | def _get_ofp_port_name(self, intf_id, onu_id, uni_id): |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 317 | parent_port_no = self.platform.intf_id_to_port_no(intf_id, Port.PON_OLT) |
| 318 | child_device = self.adapter_agent.get_child_device(self.device_id, |
| 319 | parent_port_no=parent_port_no, onu_id=onu_id) |
| 320 | if child_device is None: |
| 321 | self.log.error("could-not-find-child-device", |
| 322 | parent_port_no=intf_id, onu_id=onu_id) |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 323 | return (None, None) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 324 | ports = self.adapter_agent.get_ports(child_device.id, Port.ETHERNET_UNI) |
| 325 | logical_port = self.adapter_agent.get_logical_port( |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 326 | self.logical_device_id, ports[uni_id].label) |
| 327 | ofp_port_name = (logical_port.ofp_port.name, logical_port.ofp_port.port_no) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 328 | return ofp_port_name |
| 329 | |
Thiyagarajan Subramani | 353af12 | 2019-02-20 23:14:24 -0800 | [diff] [blame^] | 330 | def get_tp_path(self, intf_id, ofp_port_name, techprofile_id): |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 331 | return self.tech_profile[intf_id]. \ |
Thiyagarajan Subramani | 353af12 | 2019-02-20 23:14:24 -0800 | [diff] [blame^] | 332 | get_tp_path(techprofile_id, |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 333 | ofp_port_name) |
| 334 | |
Thiyagarajan Subramani | 353af12 | 2019-02-20 23:14:24 -0800 | [diff] [blame^] | 335 | def delete_tech_profile_instance(self, intf_id, onu_id, uni_id, ofp_port_name): |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 336 | # Remove the TP instance associated with the ONU |
Thiyagarajan Subramani | 353af12 | 2019-02-20 23:14:24 -0800 | [diff] [blame^] | 337 | if ofp_port_name is None: |
| 338 | ofp_port_name, ofp_port_no = self._get_ofp_port_name(intf_id, onu_id, uni_id) |
| 339 | tp_id = self.resource_mgr.get_tech_profile_id_for_onu(intf_id, onu_id, uni_id) |
| 340 | tp_path = self.get_tp_path(intf_id, ofp_port_name, tp_id) |
| 341 | self.log.debug(" tp-path-in-delete",tp_path=tp_path) |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 342 | return self.tech_profile[intf_id].delete_tech_profile_instance(tp_path) |
| 343 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 344 | def divide_and_add_flow(self, intf_id, onu_id, uni_id, port_no, classifier, |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 345 | action, flow): |
| 346 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 347 | self.log.debug('sorting flow', intf_id=intf_id, onu_id=onu_id, uni_id=uni_id, port_no=port_no, |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 348 | classifier=classifier, action=action) |
| 349 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 350 | alloc_id, gem_ports = self.create_tcont_gemport(intf_id, onu_id, uni_id, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 351 | flow.table_id) |
| 352 | if alloc_id is None or gem_ports is None: |
| 353 | self.log.error("alloc-id-gem-ports-unavailable", alloc_id=alloc_id, |
| 354 | gem_ports=gem_ports) |
| 355 | return |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 356 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 357 | self.log.debug('Generated required alloc and gemport ids', |
| 358 | alloc_id=alloc_id, gemports=gem_ports) |
| 359 | |
| 360 | # Flows can't be added specific to gemport unless p-bits are received. |
| 361 | # Hence adding flows for all gemports |
| 362 | for gemport_id in gem_ports: |
| 363 | if IP_PROTO in classifier: |
| 364 | if classifier[IP_PROTO] == 17: |
| 365 | self.log.debug('dhcp flow add') |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 366 | self.add_dhcp_trap(intf_id, onu_id, uni_id, port_no, classifier, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 367 | action, flow, alloc_id, gemport_id) |
| 368 | elif classifier[IP_PROTO] == 2: |
| 369 | self.log.warn('igmp flow add ignored, not implemented yet') |
| 370 | else: |
| 371 | self.log.warn("Invalid-Classifier-to-handle", |
| 372 | classifier=classifier, |
| 373 | action=action) |
| 374 | elif ETH_TYPE in classifier: |
| 375 | if classifier[ETH_TYPE] == EAP_ETH_TYPE: |
| 376 | self.log.debug('eapol flow add') |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 377 | self.add_eapol_flow(intf_id, onu_id, uni_id, port_no, flow, alloc_id, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 378 | gemport_id) |
| 379 | vlan_id = self.get_subscriber_vlan(fd.get_in_port(flow)) |
| 380 | if vlan_id is not None: |
| 381 | self.add_eapol_flow( |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 382 | intf_id, onu_id, uni_id, port_no, flow, alloc_id, gemport_id, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 383 | vlan_id=vlan_id) |
| 384 | parent_port_no = self.platform.intf_id_to_port_no(intf_id, Port.PON_OLT) |
| 385 | onu_device = self.adapter_agent.get_child_device(self.device_id, |
| 386 | onu_id=onu_id, |
| 387 | parent_port_no=parent_port_no) |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 388 | (ofp_port_name, ofp_port_no) = self._get_ofp_port_name(intf_id, onu_id, uni_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 389 | if ofp_port_name is None: |
| 390 | self.log.error("port-name-not-found") |
| 391 | return |
Thiyagarajan Subramani | 353af12 | 2019-02-20 23:14:24 -0800 | [diff] [blame^] | 392 | tp_id = self.resource_mgr.get_tech_profile_id_for_onu(intf_id, onu_id, uni_id) |
| 393 | tp_path = self.get_tp_path(intf_id, ofp_port_name, tp_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 394 | |
| 395 | self.log.debug('Load-tech-profile-request-to-brcm-handler', |
| 396 | tp_path=tp_path) |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 397 | msg = {'proxy_address': onu_device.proxy_address, 'uni_id': uni_id, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 398 | 'event': 'download_tech_profile', 'event_data': tp_path} |
| 399 | |
| 400 | # Send the event message to the ONU adapter |
| 401 | self.adapter_agent.publish_inter_adapter_message(onu_device.id, |
| 402 | msg) |
| 403 | |
| 404 | if classifier[ETH_TYPE] == LLDP_ETH_TYPE: |
| 405 | self.log.debug('lldp flow add') |
Girish Gowdru | be328a0 | 2019-01-26 21:44:40 -0800 | [diff] [blame] | 406 | nni_intf_id = self.get_nni_intf_id() |
| 407 | self.add_lldp_flow(flow, port_no, nni_intf_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 408 | |
| 409 | elif PUSH_VLAN in action: |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 410 | self.add_upstream_data_flow(intf_id, onu_id, uni_id, port_no, classifier, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 411 | action, flow, alloc_id, gemport_id) |
| 412 | elif POP_VLAN in action: |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 413 | self.add_downstream_data_flow(intf_id, onu_id, uni_id, port_no, classifier, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 414 | action, flow, alloc_id, gemport_id) |
| 415 | else: |
| 416 | self.log.debug('Invalid-flow-type-to-handle', |
| 417 | classifier=classifier, |
| 418 | action=action, flow=flow) |
| 419 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 420 | def create_tcont_gemport(self, intf_id, onu_id, uni_id, table_id): |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 421 | alloc_id, gem_port_ids = None, None |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 422 | pon_intf_onu_id = (intf_id, onu_id) |
| 423 | |
| 424 | # If we already have allocated alloc_id and gem_ports earlier, render them |
| 425 | alloc_id = \ |
| 426 | self.resource_mgr.get_current_alloc_ids_for_onu(pon_intf_onu_id) |
| 427 | gem_port_ids = \ |
| 428 | self.resource_mgr.get_current_gemport_ids_for_onu(pon_intf_onu_id) |
| 429 | if alloc_id is not None and gem_port_ids is not None: |
| 430 | return alloc_id, gem_port_ids |
| 431 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 432 | try: |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 433 | (ofp_port_name, ofp_port_no) = self._get_ofp_port_name(intf_id, onu_id, uni_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 434 | if ofp_port_name is None: |
| 435 | self.log.error("port-name-not-found") |
| 436 | return alloc_id, gem_port_ids |
| 437 | # FIXME: If table id is <= 63 using 64 as table id |
| 438 | if table_id < DEFAULT_TECH_PROFILE_TABLE_ID: |
| 439 | table_id = DEFAULT_TECH_PROFILE_TABLE_ID |
| 440 | |
| 441 | # Check tech profile instance already exists for derived port name |
| 442 | tech_profile_instance = self.tech_profile[intf_id]. \ |
| 443 | get_tech_profile_instance(table_id, ofp_port_name) |
| 444 | self.log.debug('Get-tech-profile-instance-status', tech_profile_instance=tech_profile_instance) |
| 445 | |
| 446 | if tech_profile_instance is None: |
| 447 | # create tech profile instance |
| 448 | tech_profile_instance = self.tech_profile[intf_id]. \ |
| 449 | create_tech_profile_instance(table_id, ofp_port_name, |
| 450 | intf_id) |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 451 | if tech_profile_instance is None: |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 452 | raise Exception('Tech-profile-instance-creation-failed') |
| 453 | else: |
| 454 | self.log.debug( |
| 455 | 'Tech-profile-instance-already-exist-for-given port-name', |
| 456 | ofp_port_name=ofp_port_name) |
| 457 | |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 458 | # upstream scheduler |
| 459 | us_scheduler = self.tech_profile[intf_id].get_us_scheduler( |
| 460 | tech_profile_instance) |
| 461 | # downstream scheduler |
| 462 | ds_scheduler = self.tech_profile[intf_id].get_ds_scheduler( |
| 463 | tech_profile_instance) |
| 464 | # create Tcont |
| 465 | tconts = self.tech_profile[intf_id].get_tconts(tech_profile_instance, |
| 466 | us_scheduler, |
| 467 | ds_scheduler) |
| 468 | |
| 469 | self.stub.CreateTconts(openolt_pb2.Tconts(intf_id=intf_id, |
| 470 | onu_id=onu_id, |
| 471 | uni_id=uni_id, |
| 472 | port_no=ofp_port_no, |
| 473 | tconts=tconts)) |
| 474 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 475 | # Fetch alloc id and gemports from tech profile instance |
| 476 | alloc_id = tech_profile_instance.us_scheduler.alloc_id |
| 477 | gem_port_ids = [] |
| 478 | for i in range(len( |
| 479 | tech_profile_instance.upstream_gem_port_attribute_list)): |
| 480 | gem_port_ids.append( |
| 481 | tech_profile_instance.upstream_gem_port_attribute_list[i]. |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 482 | gemport_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 483 | except BaseException as e: |
| 484 | self.log.exception(exception=e) |
| 485 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 486 | # Update the allocated alloc_id and gem_port_id for the ONU/UNI to KV store |
| 487 | pon_intf_onu_id = (intf_id, onu_id, uni_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 488 | self.resource_mgr.resource_mgrs[intf_id].update_alloc_ids_for_onu( |
| 489 | pon_intf_onu_id, |
| 490 | list([alloc_id]) |
| 491 | ) |
| 492 | self.resource_mgr.resource_mgrs[intf_id].update_gemport_ids_for_onu( |
| 493 | pon_intf_onu_id, |
| 494 | gem_port_ids |
| 495 | ) |
| 496 | |
| 497 | self.resource_mgr.update_gemports_ponport_to_onu_map_on_kv_store( |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 498 | gem_port_ids, intf_id, onu_id, uni_id |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 499 | ) |
| 500 | |
| 501 | return alloc_id, gem_port_ids |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 502 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 503 | def add_upstream_data_flow(self, intf_id, onu_id, uni_id, port_no, uplink_classifier, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 504 | uplink_action, logical_flow, alloc_id, |
| 505 | gemport_id): |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 506 | |
| 507 | uplink_classifier[PACKET_TAG_TYPE] = SINGLE_TAG |
| 508 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 509 | self.add_hsia_flow(intf_id, onu_id, uni_id, port_no, uplink_classifier, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 510 | uplink_action, UPSTREAM, |
| 511 | logical_flow, alloc_id, gemport_id) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 512 | |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 513 | # Secondary EAP on the subscriber vlan |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 514 | (eap_active, eap_logical_flow) = self.is_eap_enabled(intf_id, onu_id, uni_id) |
Nicolas Palpacuer | 2e0fa58 | 2018-07-16 16:04:12 -0400 | [diff] [blame] | 515 | if eap_active: |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 516 | self.add_eapol_flow(intf_id, onu_id, uni_id, port_no, eap_logical_flow, alloc_id, |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 517 | gemport_id, vlan_id=uplink_classifier[VLAN_VID]) |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 518 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 519 | def add_downstream_data_flow(self, intf_id, onu_id, uni_id, port_no, downlink_classifier, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 520 | downlink_action, flow, alloc_id, gemport_id): |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 521 | downlink_classifier[PACKET_TAG_TYPE] = DOUBLE_TAG |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 522 | # Needed ???? It should be already there |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 523 | downlink_action[POP_VLAN] = True |
| 524 | downlink_action[VLAN_VID] = downlink_classifier[VLAN_VID] |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 525 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 526 | self.add_hsia_flow(intf_id, onu_id, uni_id, port_no, downlink_classifier, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 527 | downlink_action, DOWNSTREAM, |
| 528 | flow, alloc_id, gemport_id) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 529 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 530 | def add_hsia_flow(self, intf_id, onu_id, uni_id, port_no, classifier, action, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 531 | direction, logical_flow, alloc_id, gemport_id): |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 532 | |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 533 | flow_store_cookie = self._get_flow_store_cookie(classifier, |
| 534 | gemport_id) |
| 535 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 536 | if self.resource_mgr.is_flow_cookie_on_kv_store(intf_id, onu_id, uni_id, |
| 537 | flow_store_cookie): |
| 538 | self.log.debug('flow-exists--not-re-adding') |
| 539 | else: |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 540 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 541 | # One of the OLT platform (Broadcom BAL) requires that symmetric |
| 542 | # flows require the same flow_id to be used across UL and DL. |
| 543 | # Since HSIA flow is the only symmetric flow currently, we need to |
| 544 | # re-use the flow_id across both direction. The 'flow_category' |
| 545 | # takes priority over flow_cookie to find any available HSIA_FLOW |
| 546 | # id for the ONU. |
| 547 | flow_id = self.resource_mgr.get_flow_id(intf_id, onu_id, uni_id, |
| 548 | flow_store_cookie, |
| 549 | HSIA_FLOW) |
| 550 | if flow_id is None: |
| 551 | self.log.error("hsia-flow-unavailable") |
| 552 | return |
| 553 | |
| 554 | flow = openolt_pb2.Flow( |
| 555 | access_intf_id=intf_id, onu_id=onu_id, uni_id=uni_id, flow_id=flow_id, |
| 556 | flow_type=direction, alloc_id=alloc_id, network_intf_id=self.get_nni_intf_id(), |
| 557 | gemport_id=gemport_id, |
| 558 | classifier=self.mk_classifier(classifier), |
| 559 | action=self.mk_action(action), |
| 560 | priority=logical_flow.priority, |
| 561 | port_no=port_no, |
| 562 | cookie=logical_flow.cookie) |
| 563 | |
| 564 | if self.add_flow_to_device(flow, logical_flow): |
| 565 | flow_info = self._get_flow_info_as_json_blob(flow, |
| 566 | flow_store_cookie, |
| 567 | HSIA_FLOW) |
| 568 | self.update_flow_info_to_kv_store(flow.access_intf_id, |
| 569 | flow.onu_id, flow.uni_id, |
| 570 | flow.flow_id, flow_info) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 571 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 572 | def add_dhcp_trap(self, intf_id, onu_id, uni_id, port_no, classifier, action, logical_flow, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 573 | alloc_id, gemport_id): |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 574 | |
Shad Ansari | 47e0c39 | 2018-07-17 23:55:07 +0000 | [diff] [blame] | 575 | self.log.debug('add dhcp upstream trap', classifier=classifier, |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 576 | intf_id=intf_id, onu_id=onu_id, uni_id=uni_id, action=action) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 577 | |
| 578 | action.clear() |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 579 | action[TRAP_TO_HOST] = True |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 580 | classifier[UDP_SRC] = 68 |
| 581 | classifier[UDP_DST] = 67 |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 582 | classifier[PACKET_TAG_TYPE] = SINGLE_TAG |
| 583 | classifier.pop(VLAN_VID, None) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 584 | |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 585 | flow_store_cookie = self._get_flow_store_cookie(classifier, |
| 586 | gemport_id) |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 587 | if self.resource_mgr.is_flow_cookie_on_kv_store(intf_id, onu_id, uni_id, |
| 588 | flow_store_cookie): |
| 589 | self.log.debug('flow-exists--not-re-adding') |
| 590 | else: |
| 591 | flow_id = self.resource_mgr.get_flow_id( |
| 592 | intf_id, onu_id, uni_id, flow_store_cookie |
| 593 | ) |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 594 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 595 | dhcp_flow = openolt_pb2.Flow( |
| 596 | onu_id=onu_id, uni_id=uni_id, flow_id=flow_id, flow_type=UPSTREAM, |
| 597 | access_intf_id=intf_id, gemport_id=gemport_id, |
| 598 | alloc_id=alloc_id, network_intf_id=self.get_nni_intf_id(), |
| 599 | priority=logical_flow.priority, |
| 600 | classifier=self.mk_classifier(classifier), |
| 601 | action=self.mk_action(action), |
| 602 | port_no=port_no, |
| 603 | cookie=logical_flow.cookie) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 604 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 605 | if self.add_flow_to_device(dhcp_flow, logical_flow): |
| 606 | flow_info = self._get_flow_info_as_json_blob(dhcp_flow, flow_store_cookie) |
| 607 | self.update_flow_info_to_kv_store(dhcp_flow.access_intf_id, |
| 608 | dhcp_flow.onu_id, |
| 609 | dhcp_flow.uni_id, |
| 610 | dhcp_flow.flow_id, |
| 611 | flow_info) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 612 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 613 | def add_eapol_flow(self, intf_id, onu_id, uni_id, port_no, logical_flow, alloc_id, |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 614 | gemport_id, vlan_id=DEFAULT_MGMT_VLAN): |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 615 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 616 | uplink_classifier = dict() |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 617 | uplink_classifier[ETH_TYPE] = EAP_ETH_TYPE |
| 618 | uplink_classifier[PACKET_TAG_TYPE] = SINGLE_TAG |
| 619 | uplink_classifier[VLAN_VID] = vlan_id |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 620 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 621 | uplink_action = dict() |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 622 | uplink_action[TRAP_TO_HOST] = True |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 623 | |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 624 | flow_store_cookie = self._get_flow_store_cookie(uplink_classifier, |
| 625 | gemport_id) |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 626 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 627 | if self.resource_mgr.is_flow_cookie_on_kv_store(intf_id, onu_id, uni_id, |
| 628 | flow_store_cookie): |
| 629 | self.log.debug('flow-exists--not-re-adding') |
| 630 | else: |
| 631 | # Add Upstream EAPOL Flow. |
| 632 | uplink_flow_id = self.resource_mgr.get_flow_id( |
| 633 | intf_id, onu_id, uni_id, flow_store_cookie |
| 634 | ) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 635 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 636 | upstream_flow = openolt_pb2.Flow( |
| 637 | access_intf_id=intf_id, onu_id=onu_id, uni_id=uni_id, flow_id=uplink_flow_id, |
| 638 | flow_type=UPSTREAM, alloc_id=alloc_id, network_intf_id=self.get_nni_intf_id(), |
| 639 | gemport_id=gemport_id, |
| 640 | classifier=self.mk_classifier(uplink_classifier), |
| 641 | action=self.mk_action(uplink_action), |
| 642 | priority=logical_flow.priority, |
| 643 | port_no=port_no, |
| 644 | cookie=logical_flow.cookie) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 645 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 646 | logical_flow = copy.deepcopy(logical_flow) |
| 647 | logical_flow.match.oxm_fields.extend(fd.mk_oxm_fields([fd.vlan_vid( |
| 648 | vlan_id | 0x1000)])) |
| 649 | logical_flow.match.type = OFPMT_OXM |
| 650 | |
| 651 | if self.add_flow_to_device(upstream_flow, logical_flow): |
| 652 | flow_info = self._get_flow_info_as_json_blob(upstream_flow, |
| 653 | flow_store_cookie) |
| 654 | self.update_flow_info_to_kv_store(upstream_flow.access_intf_id, |
| 655 | upstream_flow.onu_id, |
| 656 | upstream_flow.uni_id, |
| 657 | upstream_flow.flow_id, |
| 658 | flow_info) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 659 | |
Nicolas Palpacuer | 6152a32 | 2018-09-05 10:52:15 -0400 | [diff] [blame] | 660 | if vlan_id == DEFAULT_MGMT_VLAN: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 661 | # Add Downstream EAPOL Flow, Only for first EAP flow (BAL |
| 662 | # requirement) |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 663 | # On one of the platforms (Broadcom BAL), when same DL classifier |
| 664 | # vlan was used across multiple ONUs, eapol flow re-adds after |
| 665 | # flow delete (cases of onu reboot/disable) fails. |
| 666 | # In order to generate unique vlan, a combination of intf_id |
| 667 | # onu_id and uni_id is used. |
| 668 | # uni_id defaults to 0, so add 1 to it. |
| 669 | special_vlan_downstream_flow = 4090 - intf_id * onu_id * (uni_id+1) |
| 670 | # Assert that we do not generate invalid vlans under no condition |
| 671 | assert (special_vlan_downstream_flow >= 2, 'invalid-vlan-generated') |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 672 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 673 | downlink_classifier = dict() |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 674 | downlink_classifier[PACKET_TAG_TYPE] = SINGLE_TAG |
| 675 | downlink_classifier[VLAN_VID] = special_vlan_downstream_flow |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 676 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 677 | downlink_action = dict() |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 678 | downlink_action[PUSH_VLAN] = True |
| 679 | downlink_action[VLAN_VID] = vlan_id |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 680 | |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 681 | |
| 682 | flow_store_cookie = self._get_flow_store_cookie(downlink_classifier, |
| 683 | gemport_id) |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 684 | if self.resource_mgr.is_flow_cookie_on_kv_store(intf_id, onu_id, uni_id, |
| 685 | flow_store_cookie): |
| 686 | self.log.debug('flow-exists--not-re-adding') |
| 687 | else: |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 688 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 689 | downlink_flow_id = self.resource_mgr.get_flow_id( |
| 690 | intf_id, onu_id, uni_id, flow_store_cookie |
| 691 | ) |
Nicolas Palpacuer | 6152a32 | 2018-09-05 10:52:15 -0400 | [diff] [blame] | 692 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 693 | downstream_flow = openolt_pb2.Flow( |
| 694 | access_intf_id=intf_id, onu_id=onu_id, uni_id=uni_id, flow_id=downlink_flow_id, |
| 695 | flow_type=DOWNSTREAM, alloc_id=alloc_id, network_intf_id=self.get_nni_intf_id(), |
| 696 | gemport_id=gemport_id, |
| 697 | classifier=self.mk_classifier(downlink_classifier), |
| 698 | action=self.mk_action(downlink_action), |
| 699 | priority=logical_flow.priority, |
| 700 | port_no=port_no, |
| 701 | cookie=logical_flow.cookie) |
Nicolas Palpacuer | 6152a32 | 2018-09-05 10:52:15 -0400 | [diff] [blame] | 702 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 703 | downstream_logical_flow = ofp_flow_stats( |
| 704 | id=logical_flow.id, cookie=logical_flow.cookie, |
| 705 | table_id=logical_flow.table_id, priority=logical_flow.priority, |
| 706 | flags=logical_flow.flags) |
Nicolas Palpacuer | 6152a32 | 2018-09-05 10:52:15 -0400 | [diff] [blame] | 707 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 708 | downstream_logical_flow.match.oxm_fields.extend(fd.mk_oxm_fields([ |
| 709 | fd.in_port(fd.get_out_port(logical_flow)), |
| 710 | fd.vlan_vid(special_vlan_downstream_flow | 0x1000)])) |
| 711 | downstream_logical_flow.match.type = OFPMT_OXM |
Nicolas Palpacuer | 6152a32 | 2018-09-05 10:52:15 -0400 | [diff] [blame] | 712 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 713 | downstream_logical_flow.instructions.extend( |
| 714 | fd.mk_instructions_from_actions([fd.output( |
| 715 | self.platform.mk_uni_port_num(intf_id, onu_id, uni_id))])) |
Nicolas Palpacuer | 6152a32 | 2018-09-05 10:52:15 -0400 | [diff] [blame] | 716 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 717 | if self.add_flow_to_device(downstream_flow, downstream_logical_flow): |
| 718 | flow_info = self._get_flow_info_as_json_blob(downstream_flow, |
| 719 | flow_store_cookie) |
| 720 | self.update_flow_info_to_kv_store(downstream_flow.access_intf_id, |
| 721 | downstream_flow.onu_id, |
| 722 | downstream_flow.uni_id, |
| 723 | downstream_flow.flow_id, |
| 724 | flow_info) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 725 | |
Nicolas Palpacuer | 4114135 | 2018-08-31 14:11:38 -0400 | [diff] [blame] | 726 | def repush_all_different_flows(self): |
| 727 | # Check if the device is supposed to have flows, if so add them |
| 728 | # Recover static flows after a reboot |
| 729 | logical_flows = self.logical_flows_proxy.get('/').items |
| 730 | devices_flows = self.flows_proxy.get('/').items |
| 731 | logical_flows_ids_provisioned = [f.cookie for f in devices_flows] |
| 732 | for logical_flow in logical_flows: |
| 733 | try: |
| 734 | if logical_flow.id not in logical_flows_ids_provisioned: |
| 735 | self.add_flow(logical_flow) |
| 736 | except Exception as e: |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 737 | self.log.exception('Problem reading this flow', e=e) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 738 | |
Nicolas Palpacuer | 4114135 | 2018-08-31 14:11:38 -0400 | [diff] [blame] | 739 | def reset_flows(self): |
| 740 | self.flows_proxy.update('/', Flows()) |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 741 | |
Shad Ansari | fd0111d | 2018-09-13 21:33:06 +0000 | [diff] [blame] | 742 | """ Add a downstream LLDP trap flow on the NNI interface |
| 743 | """ |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 744 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 745 | def add_lldp_flow(self, logical_flow, port_no, network_intf_id=0): |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame] | 746 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 747 | classifier = dict() |
Shad Ansari | fd0111d | 2018-09-13 21:33:06 +0000 | [diff] [blame] | 748 | classifier[ETH_TYPE] = LLDP_ETH_TYPE |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 749 | classifier[PACKET_TAG_TYPE] = UNTAGGED |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 750 | action = dict() |
Shad Ansari | fd0111d | 2018-09-13 21:33:06 +0000 | [diff] [blame] | 751 | action[TRAP_TO_HOST] = True |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame] | 752 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 753 | # LLDP flow is installed to trap LLDP packets on the NNI port. |
| 754 | # We manage flow_id resource pool on per PON port basis. |
| 755 | # Since this situation is tricky, as a hack, we pass the NNI port |
| 756 | # index (network_intf_id) as PON port Index for the flow_id resource |
| 757 | # pool. Also, there is no ONU Id available for trapping LLDP packets |
| 758 | # on NNI port, use onu_id as -1 (invalid) |
| 759 | # ****************** CAVEAT ******************* |
| 760 | # This logic works if the NNI Port Id falls within the same valid |
| 761 | # range of PON Port Ids. If this doesn't work for some OLT Vendor |
| 762 | # we need to have a re-look at this. |
| 763 | # ********************************************* |
| 764 | onu_id = -1 |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 765 | uni_id = -1 |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 766 | flow_store_cookie = self._get_flow_store_cookie(classifier) |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame] | 767 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 768 | if self.resource_mgr.is_flow_cookie_on_kv_store(network_intf_id, onu_id, uni_id, |
| 769 | flow_store_cookie): |
| 770 | self.log.debug('flow-exists--not-re-adding') |
| 771 | else: |
| 772 | flow_id = self.resource_mgr.get_flow_id(network_intf_id, onu_id, uni_id, |
| 773 | flow_store_cookie) |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame] | 774 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 775 | downstream_flow = openolt_pb2.Flow( |
| 776 | access_intf_id=-1, # access_intf_id not required |
| 777 | onu_id=onu_id, # onu_id not required |
| 778 | uni_id=uni_id, # uni_id not used |
| 779 | flow_id=flow_id, |
| 780 | flow_type=DOWNSTREAM, |
| 781 | network_intf_id=network_intf_id, |
| 782 | gemport_id=-1, # gemport_id not required |
| 783 | classifier=self.mk_classifier(classifier), |
| 784 | action=self.mk_action(action), |
| 785 | priority=logical_flow.priority, |
| 786 | port_no=port_no, |
| 787 | cookie=logical_flow.cookie) |
| 788 | |
| 789 | self.log.debug('add lldp downstream trap', classifier=classifier, |
| 790 | action=action, flow=downstream_flow, port_no=port_no) |
| 791 | if self.add_flow_to_device(downstream_flow, logical_flow): |
| 792 | flow_info = self._get_flow_info_as_json_blob(downstream_flow, |
| 793 | flow_store_cookie) |
| 794 | self.update_flow_info_to_kv_store(network_intf_id, onu_id, uni_id, |
| 795 | flow_id, flow_info) |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame] | 796 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 797 | def mk_classifier(self, classifier_info): |
| 798 | |
| 799 | classifier = openolt_pb2.Classifier() |
| 800 | |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 801 | if ETH_TYPE in classifier_info: |
| 802 | classifier.eth_type = classifier_info[ETH_TYPE] |
| 803 | if IP_PROTO in classifier_info: |
| 804 | classifier.ip_proto = classifier_info[IP_PROTO] |
Thiyagarajan Subramani | 3b62d6c | 2019-02-15 08:48:01 -0800 | [diff] [blame] | 805 | if VLAN_VID in classifier_info and \ |
| 806 | classifier_info[VLAN_VID] != RESERVED_VLAN: |
| 807 | classifier.o_vid = classifier_info[VLAN_VID] |
| 808 | if METADATA in classifier_info and \ |
| 809 | classifier_info[METADATA] != RESERVED_VLAN: |
| 810 | classifier.i_vid = classifier_info[METADATA] |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 811 | if VLAN_PCP in classifier_info: |
| 812 | classifier.o_pbits = classifier_info[VLAN_PCP] |
| 813 | if UDP_SRC in classifier_info: |
| 814 | classifier.src_port = classifier_info[UDP_SRC] |
| 815 | if UDP_DST in classifier_info: |
| 816 | classifier.dst_port = classifier_info[UDP_DST] |
| 817 | if IPV4_DST in classifier_info: |
| 818 | classifier.dst_ip = classifier_info[IPV4_DST] |
| 819 | if IPV4_SRC in classifier_info: |
| 820 | classifier.src_ip = classifier_info[IPV4_SRC] |
| 821 | if PACKET_TAG_TYPE in classifier_info: |
| 822 | if classifier_info[PACKET_TAG_TYPE] == SINGLE_TAG: |
| 823 | classifier.pkt_tag_type = SINGLE_TAG |
| 824 | elif classifier_info[PACKET_TAG_TYPE] == DOUBLE_TAG: |
| 825 | classifier.pkt_tag_type = DOUBLE_TAG |
| 826 | elif classifier_info[PACKET_TAG_TYPE] == UNTAGGED: |
| 827 | classifier.pkt_tag_type = UNTAGGED |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 828 | else: |
| 829 | classifier.pkt_tag_type = 'none' |
| 830 | |
| 831 | return classifier |
| 832 | |
| 833 | def mk_action(self, action_info): |
| 834 | action = openolt_pb2.Action() |
| 835 | |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 836 | if POP_VLAN in action_info: |
| 837 | action.o_vid = action_info[VLAN_VID] |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 838 | action.cmd.remove_outer_tag = True |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 839 | elif PUSH_VLAN in action_info: |
| 840 | action.o_vid = action_info[VLAN_VID] |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 841 | action.cmd.add_outer_tag = True |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 842 | elif TRAP_TO_HOST in action_info: |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 843 | action.cmd.trap_to_host = True |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 844 | else: |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 845 | self.log.info('Invalid-action-field', action_info=action_info) |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 846 | return |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 847 | return action |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 848 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 849 | def is_eap_enabled(self, intf_id, onu_id, uni_id): |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 850 | flows = self.logical_flows_proxy.get('/').items |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 851 | |
| 852 | for flow in flows: |
| 853 | eap_flow = False |
| 854 | eap_intf_id = None |
| 855 | eap_onu_id = None |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 856 | eap_uni_id = None |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 857 | for field in fd.get_ofb_fields(flow): |
| 858 | if field.type == fd.ETH_TYPE: |
| 859 | if field.eth_type == EAP_ETH_TYPE: |
| 860 | eap_flow = True |
| 861 | if field.type == fd.IN_PORT: |
Shad Ansari | cd20a6d | 2018-10-02 14:36:33 +0000 | [diff] [blame] | 862 | eap_intf_id = self.platform.intf_id_from_uni_port_num( |
Shad Ansari | 47e0c39 | 2018-07-17 23:55:07 +0000 | [diff] [blame] | 863 | field.port) |
Shad Ansari | cd20a6d | 2018-10-02 14:36:33 +0000 | [diff] [blame] | 864 | eap_onu_id = self.platform.onu_id_from_port_num(field.port) |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 865 | eap_uni_id = self.platform.uni_id_from_port_num(field.port) |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 866 | |
| 867 | if eap_flow: |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 868 | self.log.debug('eap flow detected', onu_id=onu_id, uni_id=uni_id, |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 869 | intf_id=intf_id, eap_intf_id=eap_intf_id, |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 870 | eap_onu_id=eap_onu_id, |
| 871 | eap_uni_id=eap_uni_id) |
| 872 | if eap_flow and intf_id == eap_intf_id and onu_id == eap_onu_id and uni_id == eap_uni_id: |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 873 | return True, flow |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 874 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 875 | return False, None |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 876 | |
Nicolas Palpacuer | 4114135 | 2018-08-31 14:11:38 -0400 | [diff] [blame] | 877 | def get_subscriber_vlan(self, port): |
| 878 | self.log.debug('looking from subscriber flow for port', port=port) |
| 879 | |
| 880 | flows = self.logical_flows_proxy.get('/').items |
| 881 | for flow in flows: |
| 882 | in_port = fd.get_in_port(flow) |
| 883 | out_port = fd.get_out_port(flow) |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 884 | if in_port == port and out_port is not None and \ |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 885 | self.platform.intf_id_to_port_type_name(out_port) \ |
Shad Ansari | fd0111d | 2018-09-13 21:33:06 +0000 | [diff] [blame] | 886 | == Port.ETHERNET_NNI: |
Nicolas Palpacuer | 4114135 | 2018-08-31 14:11:38 -0400 | [diff] [blame] | 887 | fields = fd.get_ofb_fields(flow) |
| 888 | self.log.debug('subscriber flow found', fields=fields) |
| 889 | for field in fields: |
| 890 | if field.type == OFPXMT_OFB_VLAN_VID: |
| 891 | self.log.debug('subscriber vlan found', |
| 892 | vlan_id=field.vlan_vid) |
| 893 | return field.vlan_vid & 0x0fff |
| 894 | self.log.debug('No subscriber flow found', port=port) |
| 895 | return None |
| 896 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 897 | def add_flow_to_device(self, flow, logical_flow): |
| 898 | self.log.debug('pushing flow to device', flow=flow) |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 899 | try: |
| 900 | self.stub.FlowAdd(flow) |
| 901 | except grpc.RpcError as grpc_e: |
| 902 | if grpc_e.code() == grpc.StatusCode.ALREADY_EXISTS: |
| 903 | self.log.warn('flow already exists', e=grpc_e, flow=flow) |
| 904 | else: |
| 905 | self.log.error('failed to add flow', |
| 906 | logical_flow=logical_flow, flow=flow, |
| 907 | grpc_error=grpc_e) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 908 | return False |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 909 | else: |
| 910 | self.register_flow(logical_flow, flow) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 911 | return True |
| 912 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 913 | def update_flow_info_to_kv_store(self, intf_id, onu_id, uni_id, flow_id, flow): |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 914 | self.resource_mgr.update_flow_id_info(intf_id, onu_id, uni_id, |
| 915 | flow_id, flow) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 916 | |
| 917 | def register_flow(self, logical_flow, device_flow): |
| 918 | self.log.debug('registering flow in device', |
| 919 | logical_flow=logical_flow, device_flow=device_flow) |
| 920 | stored_flow = copy.deepcopy(logical_flow) |
| 921 | stored_flow.id = self.generate_stored_id(device_flow.flow_id, |
| 922 | device_flow.flow_type) |
| 923 | self.log.debug('generated device flow id', id=stored_flow.id, |
| 924 | flow_id=device_flow.flow_id, |
| 925 | direction=device_flow.flow_type) |
| 926 | stored_flow.cookie = logical_flow.id |
| 927 | flows = self.flows_proxy.get('/') |
| 928 | flows.items.extend([stored_flow]) |
| 929 | self.flows_proxy.update('/', flows) |
| 930 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 931 | def find_next_flow(self, flow): |
| 932 | table_id = fd.get_goto_table_id(flow) |
| 933 | metadata = 0 |
Chip Boling | 41f795a | 2018-10-04 15:45:34 -0500 | [diff] [blame] | 934 | # Prior to ONOS 1.13.5, Metadata contained the UNI output port number. In |
| 935 | # 1.13.5 and later, the lower 32-bits is the output port number and the |
| 936 | # upper 32-bits is the inner-vid we are looking for. Use just the lower 32 |
| 937 | # bits. Allows this code to work with pre- and post-1.13.5 ONOS OltPipeline |
| 938 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 939 | for field in fd.get_ofb_fields(flow): |
| 940 | if field.type == fd.METADATA: |
Chip Boling | 41f795a | 2018-10-04 15:45:34 -0500 | [diff] [blame] | 941 | metadata = field.table_metadata & 0xFFFFFFFF |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 942 | if table_id is None: |
| 943 | return None |
| 944 | flows = self.logical_flows_proxy.get('/').items |
| 945 | next_flows = [] |
| 946 | for f in flows: |
| 947 | if f.table_id == table_id: |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame] | 948 | # FIXME |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 949 | if fd.get_in_port(f) == fd.get_in_port(flow) and \ |
| 950 | fd.get_out_port(f) == metadata: |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 951 | next_flows.append(f) |
| 952 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 953 | if len(next_flows) == 0: |
| 954 | self.log.warning('no next flow found, it may be a timing issue', |
| 955 | flow=flow, number_of_flows=len(flows)) |
Scott Baker | be5a9ea | 2018-11-19 19:24:21 -0800 | [diff] [blame] | 956 | if flow.id in self.retry_add_flow_list: |
| 957 | self.log.debug('flow is already in retry list', flow_id=flow.id) |
| 958 | else: |
| 959 | self.retry_add_flow_list.append(flow.id) |
| 960 | reactor.callLater(5, self.retry_add_flow, flow) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 961 | return None |
| 962 | |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame] | 963 | next_flows.sort(key=lambda f: f.priority, reverse=True) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 964 | |
| 965 | return next_flows[0] |
| 966 | |
| 967 | def update_children_flows(self, device_rules_map): |
| 968 | |
| 969 | for device_id, (flows, groups) in device_rules_map.iteritems(): |
| 970 | if device_id != self.device_id: |
| 971 | self.root_proxy.update('/devices/{}/flows'.format(device_id), |
| 972 | Flows(items=flows.values())) |
| 973 | self.root_proxy.update('/devices/{}/flow_groups'.format( |
| 974 | device_id), FlowGroups(items=groups.values())) |
| 975 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 976 | def clear_flows_and_scheduler_for_logical_port(self, child_device, logical_port): |
| 977 | ofp_port_name = logical_port.ofp_port.name |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 978 | port_no = logical_port.ofp_port.port_no |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 979 | pon_port = child_device.proxy_address.channel_id |
| 980 | onu_id = child_device.proxy_address.onu_id |
Thiyagarajan Subramani | 353af12 | 2019-02-20 23:14:24 -0800 | [diff] [blame^] | 981 | uni_id = self.platform.uni_id_from_port_num(port_no) |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 982 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 983 | # TODO: The DEFAULT_TECH_PROFILE_ID is assumed. Right way to do, |
| 984 | # is probably to maintain a list of Tech-profile table IDs associated |
| 985 | # with the UNI logical_port. This way, when the logical port is deleted, |
| 986 | # all the associated tech-profile configuration with the UNI logical_port |
| 987 | # can be cleared. |
Thiyagarajan Subramani | 353af12 | 2019-02-20 23:14:24 -0800 | [diff] [blame^] | 988 | tp_id = self.resource_mgr.get_tech_profile_id_for_onu(pon_port, onu_id, uni_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 989 | tech_profile_instance = self.tech_profile[pon_port]. \ |
| 990 | get_tech_profile_instance( |
Thiyagarajan Subramani | 353af12 | 2019-02-20 23:14:24 -0800 | [diff] [blame^] | 991 | tp_id, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 992 | ofp_port_name) |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 993 | flow_ids = self.resource_mgr.get_current_flow_ids(pon_port, onu_id, uni_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 994 | self.log.debug("outstanding-flows-to-be-cleared", flow_ids=flow_ids) |
| 995 | for flow_id in flow_ids: |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 996 | flow_infos = self.resource_mgr.get_flow_id_info(pon_port, onu_id, uni_id, flow_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 997 | for flow_info in flow_infos: |
| 998 | direction = flow_info['flow_type'] |
| 999 | flow_to_remove = openolt_pb2.Flow(flow_id=flow_id, |
| 1000 | flow_type=direction) |
| 1001 | try: |
| 1002 | self.stub.FlowRemove(flow_to_remove) |
| 1003 | except grpc.RpcError as grpc_e: |
| 1004 | if grpc_e.code() == grpc.StatusCode.NOT_FOUND: |
| 1005 | self.log.debug('This flow does not exist on the switch, ' |
| 1006 | 'normal after an OLT reboot', |
| 1007 | flow=flow_to_remove) |
| 1008 | else: |
| 1009 | raise grpc_e |
| 1010 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 1011 | self.resource_mgr.free_flow_id(pon_port, onu_id, uni_id, flow_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1012 | |
| 1013 | try: |
| 1014 | tconts = self.tech_profile[pon_port].get_tconts(tech_profile_instance) |
| 1015 | self.stub.RemoveTconts(openolt_pb2.Tconts(intf_id=pon_port, |
| 1016 | onu_id=onu_id, |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 1017 | uni_id=uni_id, |
| 1018 | port_no=port_no, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1019 | tconts=tconts)) |
| 1020 | except grpc.RpcError as grpc_e: |
| 1021 | self.log.error('error-removing-tcont-scheduler-queues', |
| 1022 | err=grpc_e) |
| 1023 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 1024 | def generate_stored_id(self, flow_id, direction): |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 1025 | if direction == UPSTREAM: |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 1026 | self.log.debug('upstream flow, shifting id') |
| 1027 | return 0x1 << 15 | flow_id |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 1028 | elif direction == DOWNSTREAM: |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 1029 | self.log.debug('downstream flow, not shifting id') |
| 1030 | return flow_id |
| 1031 | else: |
| 1032 | self.log.warn('Unrecognized direction', direction=direction) |
| 1033 | return flow_id |
| 1034 | |
| 1035 | def decode_stored_id(self, id): |
| 1036 | if id >> 15 == 0x1: |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1037 | return id & 0x7fff, UPSTREAM |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 1038 | else: |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1039 | return id, DOWNSTREAM |
| 1040 | |
| 1041 | def _populate_tech_profile_per_pon_port(self): |
| 1042 | for arange in self.resource_mgr.device_info.ranges: |
| 1043 | for intf_id in arange.intf_ids: |
| 1044 | self.tech_profile[intf_id] = \ |
| 1045 | self.resource_mgr.resource_mgrs[intf_id].tech_profile |
| 1046 | |
| 1047 | # Make sure we have as many tech_profiles as there are pon ports on |
| 1048 | # the device |
| 1049 | assert len(self.tech_profile) == self.resource_mgr.device_info.pon_ports |
| 1050 | |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 1051 | def _get_flow_info_as_json_blob(self, flow, flow_store_cookie, |
| 1052 | flow_category=None): |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1053 | json_blob = MessageToDict(message=flow, |
| 1054 | preserving_proto_field_name=True) |
| 1055 | self.log.debug("flow-info", json_blob=json_blob) |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 1056 | json_blob['flow_store_cookie'] = flow_store_cookie |
| 1057 | if flow_category is not None: |
| 1058 | json_blob['flow_category'] = flow_category |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 1059 | |
| 1060 | # For flows which trap out of the NNI, the access_intf_id is invalid (set to -1). |
| 1061 | # In such cases, we need to refer to the network_intf_id. |
| 1062 | if flow.access_intf_id != -1: |
| 1063 | flow_info = self.resource_mgr.get_flow_id_info(flow.access_intf_id, |
| 1064 | flow.onu_id, flow.uni_id, |
| 1065 | flow.flow_id) |
| 1066 | else: |
| 1067 | # Case of LLDP trap flow from the NNI. We can't use flow.access_intf_id |
| 1068 | # in that case, as it is invalid. We use flow.network_intf_id. |
| 1069 | flow_info = self.resource_mgr.get_flow_id_info(flow.network_intf_id, |
| 1070 | flow.onu_id, flow.uni_id, |
| 1071 | flow.flow_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1072 | |
| 1073 | if flow_info is None: |
| 1074 | flow_info = list() |
| 1075 | flow_info.append(json_blob) |
| 1076 | else: |
| 1077 | assert (isinstance(flow_info, list)) |
| 1078 | flow_info.append(json_blob) |
| 1079 | |
| 1080 | return flow_info |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 1081 | |
| 1082 | @staticmethod |
| 1083 | def _get_flow_store_cookie(classifier, gem_port=None): |
| 1084 | assert isinstance(classifier, dict) |
| 1085 | # We need unique flows per gem_port |
| 1086 | if gem_port is not None: |
| 1087 | to_hash = dumps(classifier, sort_keys=True) + str(gem_port) |
| 1088 | else: |
| 1089 | to_hash = dumps(classifier, sort_keys=True) |
| 1090 | return hashlib.md5(to_hash).hexdigest()[:12] |
Girish Gowdru | be328a0 | 2019-01-26 21:44:40 -0800 | [diff] [blame] | 1091 | |
| 1092 | def get_nni_intf_id(self): |
| 1093 | if self.nni_intf_id is not None: |
| 1094 | return self.nni_intf_id |
| 1095 | |
| 1096 | port_list = self.adapter_agent.get_ports(self.device_id, Port.ETHERNET_NNI) |
| 1097 | logical_port = self.adapter_agent.get_logical_port(self.logical_device_id, |
| 1098 | port_list[0].label) |
| 1099 | self.nni_intf_id = self.platform.intf_id_from_nni_port_num(logical_port.ofp_port.port_no) |
| 1100 | self.log.debug("nni-intf-d ", nni_intf_id=self.nni_intf_id) |
| 1101 | return self.nni_intf_id |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 1102 | |