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