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 |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 21 | import ast |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 22 | from simplejson import dumps |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 23 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 24 | from voltha.protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC, \ |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 25 | ofp_flow_stats, OFPMT_OXM, Flows, FlowGroups, \ |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame] | 26 | OFPXMT_OFB_VLAN_VID |
Nicolas Palpacuer | 5780e15 | 2018-09-05 17:25:42 -0400 | [diff] [blame] | 27 | from voltha.protos.device_pb2 import Port |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 28 | import voltha.core.flow_decomposer as fd |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 29 | from voltha.adapters.openolt.protos import openolt_pb2 |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 30 | from voltha.protos import tech_profile_pb2 |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 31 | from voltha.registry import registry |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 32 | from common.tech_profile.tech_profile import Direction, TechProfile |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 33 | |
| 34 | # Flow categories |
| 35 | HSIA_FLOW = "HSIA_FLOW" |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 36 | |
| 37 | EAP_ETH_TYPE = 0x888e |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame] | 38 | LLDP_ETH_TYPE = 0x88cc |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 39 | IPV4_ETH_TYPE = 0x800 |
| 40 | IPv6_ETH_TYPE = 0x86dd |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 41 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 42 | IGMP_PROTO = 2 |
| 43 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 44 | # FIXME - see also BRDCM_DEFAULT_VLAN in broadcom_onu.py |
| 45 | DEFAULT_MGMT_VLAN = 4091 |
Thiyagarajan Subramani | 3b62d6c | 2019-02-15 08:48:01 -0800 | [diff] [blame] | 46 | RESERVED_VLAN = 4095 |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 47 | |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 48 | # Openolt Flow |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 49 | UPSTREAM = "upstream" |
| 50 | DOWNSTREAM = "downstream" |
| 51 | PACKET_TAG_TYPE = "pkt_tag_type" |
| 52 | UNTAGGED = "untagged" |
| 53 | SINGLE_TAG = "single_tag" |
| 54 | DOUBLE_TAG = "double_tag" |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 55 | |
| 56 | # Classifier |
| 57 | ETH_TYPE = 'eth_type' |
| 58 | TPID = 'tpid' |
| 59 | IP_PROTO = 'ip_proto' |
| 60 | IN_PORT = 'in_port' |
| 61 | VLAN_VID = 'vlan_vid' |
| 62 | VLAN_PCP = 'vlan_pcp' |
| 63 | UDP_DST = 'udp_dst' |
| 64 | UDP_SRC = 'udp_src' |
| 65 | IPV4_DST = 'ipv4_dst' |
| 66 | IPV4_SRC = 'ipv4_src' |
| 67 | METADATA = 'metadata' |
| 68 | OUTPUT = 'output' |
| 69 | # Action |
| 70 | POP_VLAN = 'pop_vlan' |
| 71 | PUSH_VLAN = 'push_vlan' |
| 72 | TRAP_TO_HOST = 'trap_to_host' |
| 73 | |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 74 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 75 | class OpenOltFlowMgr(object): |
| 76 | |
Shad Ansari | f9b9b89 | 2019-02-27 17:10:27 -0800 | [diff] [blame] | 77 | def __init__(self, log, stub, device_id, logical_device_id, |
| 78 | platform, resource_mgr, data_model): |
| 79 | self.data_model = data_model |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 80 | self.log = log |
| 81 | self.stub = stub |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 82 | self.device_id = device_id |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 83 | self.logical_device_id = logical_device_id |
Shad Ansari | cd20a6d | 2018-10-02 14:36:33 +0000 | [diff] [blame] | 84 | self.platform = platform |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 85 | self.logical_flows_proxy = registry('core').get_proxy( |
| 86 | '/logical_devices/{}/flows'.format(self.logical_device_id)) |
| 87 | self.flows_proxy = registry('core').get_proxy( |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 88 | '/devices/{}/flows'.format(self.device_id)) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 89 | self.root_proxy = registry('core').get_proxy('/') |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 90 | self.resource_mgr = resource_mgr |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 91 | self.tech_profile = dict() |
| 92 | self._populate_tech_profile_per_pon_port() |
Scott Baker | be5a9ea | 2018-11-19 19:24:21 -0800 | [diff] [blame] | 93 | self.retry_add_flow_list = [] |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 94 | |
Shad Ansari | 4f9a973 | 2019-03-08 16:47:08 -0800 | [diff] [blame] | 95 | def update_logical_flows(self, flows_to_add, flows_to_remove, |
| 96 | device_rules_map): |
| 97 | try: |
| 98 | self.update_children_flows(device_rules_map) |
| 99 | except Exception as e: |
| 100 | self.log.error('Error updating children flows', error=e) |
| 101 | |
| 102 | self.log.debug('logical flows update', flows_to_add=flows_to_add, |
| 103 | flows_to_remove=flows_to_remove) |
| 104 | |
| 105 | for flow in flows_to_add: |
| 106 | |
| 107 | try: |
| 108 | self.add_flow(flow) |
| 109 | except Exception as e: |
| 110 | self.log.error('failed to add flow', flow=flow, e=e) |
| 111 | |
| 112 | for flow in flows_to_remove: |
| 113 | |
| 114 | try: |
| 115 | self.remove_flow(flow) |
| 116 | except Exception as e: |
| 117 | self.log.error('failed to remove flow', flow=flow, e=e) |
| 118 | |
| 119 | self.repush_all_different_flows() |
| 120 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 121 | def add_flow(self, flow): |
| 122 | self.log.debug('add flow', flow=flow) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 123 | classifier_info = dict() |
| 124 | action_info = dict() |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 125 | us_meter_id = None |
| 126 | ds_meter_id = None |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 127 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 128 | for field in fd.get_ofb_fields(flow): |
| 129 | if field.type == fd.ETH_TYPE: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 130 | classifier_info[ETH_TYPE] = field.eth_type |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 131 | self.log.debug('field-type-eth-type', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 132 | eth_type=classifier_info[ETH_TYPE]) |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 133 | if classifier_info[ETH_TYPE] == IPv6_ETH_TYPE: |
| 134 | self.log.debug('Not handling IPv6 flows') |
| 135 | return |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 136 | elif field.type == fd.IP_PROTO: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 137 | classifier_info[IP_PROTO] = field.ip_proto |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 138 | self.log.debug('field-type-ip-proto', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 139 | ip_proto=classifier_info[IP_PROTO]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 140 | elif field.type == fd.IN_PORT: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 141 | classifier_info[IN_PORT] = field.port |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 142 | self.log.debug('field-type-in-port', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 143 | in_port=classifier_info[IN_PORT]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 144 | elif field.type == fd.VLAN_VID: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 145 | classifier_info[VLAN_VID] = field.vlan_vid & 0xfff |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 146 | self.log.debug('field-type-vlan-vid', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 147 | vlan=classifier_info[VLAN_VID]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 148 | elif field.type == fd.VLAN_PCP: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 149 | classifier_info[VLAN_PCP] = field.vlan_pcp |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 150 | self.log.debug('field-type-vlan-pcp', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 151 | pcp=classifier_info[VLAN_PCP]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 152 | elif field.type == fd.UDP_DST: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 153 | classifier_info[UDP_DST] = field.udp_dst |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 154 | self.log.debug('field-type-udp-dst', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 155 | udp_dst=classifier_info[UDP_DST]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 156 | elif field.type == fd.UDP_SRC: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 157 | classifier_info[UDP_SRC] = field.udp_src |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 158 | self.log.debug('field-type-udp-src', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 159 | udp_src=classifier_info[UDP_SRC]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 160 | elif field.type == fd.IPV4_DST: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 161 | classifier_info[IPV4_DST] = field.ipv4_dst |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 162 | self.log.debug('field-type-ipv4-dst', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 163 | ipv4_dst=classifier_info[IPV4_DST]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 164 | elif field.type == fd.IPV4_SRC: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 165 | classifier_info[IPV4_SRC] = field.ipv4_src |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 166 | self.log.debug('field-type-ipv4-src', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 167 | ipv4_dst=classifier_info[IPV4_SRC]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 168 | else: |
| 169 | raise NotImplementedError('field.type={}'.format( |
| 170 | field.type)) |
| 171 | |
| 172 | for action in fd.get_actions(flow): |
| 173 | if action.type == fd.OUTPUT: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 174 | action_info[OUTPUT] = action.output.port |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 175 | self.log.debug('action-type-output', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 176 | output=action_info[OUTPUT], |
| 177 | in_port=classifier_info[IN_PORT]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 178 | elif action.type == fd.POP_VLAN: |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 179 | if fd.get_goto_table_id(flow) is None: |
| 180 | self.log.debug('being taken care of by ONU', flow=flow) |
| 181 | return |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 182 | action_info[POP_VLAN] = True |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame] | 183 | self.log.debug('action-type-pop-vlan', |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 184 | in_port=classifier_info[IN_PORT]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 185 | elif action.type == fd.PUSH_VLAN: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 186 | action_info[PUSH_VLAN] = True |
| 187 | action_info[TPID] = action.push.ethertype |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 188 | self.log.debug('action-type-push-vlan', |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 189 | push_tpid=action_info[TPID], |
| 190 | in_port=classifier_info[IN_PORT]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 191 | if action.push.ethertype != 0x8100: |
| 192 | self.log.error('unhandled-tpid', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 193 | ethertype=action.push.ethertype) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 194 | elif action.type == fd.SET_FIELD: |
| 195 | # action_info['action_type'] = 'set_field' |
| 196 | _field = action.set_field.field.ofb_field |
| 197 | assert (action.set_field.field.oxm_class == |
| 198 | OFPXMC_OPENFLOW_BASIC) |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 199 | self.log.debug('action-type-set-field', |
| 200 | field=_field, in_port=classifier_info[IN_PORT]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 201 | if _field.type == fd.VLAN_VID: |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 202 | self.log.debug('set-field-type-vlan-vid', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 203 | vlan_vid=_field.vlan_vid & 0xfff) |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 204 | action_info[VLAN_VID] = (_field.vlan_vid & 0xfff) |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 205 | elif _field.type == fd.VLAN_PCP: |
| 206 | self.log.debug('set-field-type-vlan-pcp', |
| 207 | vlan_pcp=_field.vlan_pcp & 0x7) |
| 208 | action_info[VLAN_PCP] = (_field.vlan_pcp & 0x7) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 209 | else: |
| 210 | self.log.error('unsupported-action-set-field-type', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 211 | field_type=_field.type) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 212 | else: |
| 213 | self.log.error('unsupported-action-type', |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 214 | action_type=action.type, |
| 215 | in_port=classifier_info[IN_PORT]) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 216 | |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 217 | if fd.get_goto_table_id(flow) is not None \ |
| 218 | and POP_VLAN not in action_info: |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 219 | self.log.debug('being taken care of by ONU', flow=flow) |
Nicolas Palpacuer | 856d3af | 2018-09-12 15:04:51 -0400 | [diff] [blame] | 220 | return |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 221 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 222 | flow_metadata = fd.get_metadata_from_write_metadata(flow) |
| 223 | |
| 224 | if OUTPUT not in action_info and flow_metadata is not None: |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 225 | # find flow in the next table |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 226 | next_flow = self.find_next_flow(flow, flow_metadata) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 227 | if next_flow is None: |
| 228 | return |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 229 | action_info[OUTPUT] = fd.get_out_port(next_flow) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 230 | for field in fd.get_ofb_fields(next_flow): |
| 231 | if field.type == fd.VLAN_VID: |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 232 | classifier_info[METADATA] = field.vlan_vid & 0xfff |
| 233 | |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 234 | self.log.debug('flow-ports', |
| 235 | classifier_inport=classifier_info[IN_PORT], |
| 236 | action_output=action_info[OUTPUT]) |
| 237 | (port_no, intf_id, onu_id, uni_id) \ |
| 238 | = self.platform.extract_access_from_flow( |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 239 | classifier_info[IN_PORT], action_info[OUTPUT]) |
| 240 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 241 | # LLDP flow has nothing to do with any particular subscriber. |
| 242 | # So, lets not care about the Tech-profile, meters etc. |
| 243 | # Just add the flow and return. |
| 244 | if ETH_TYPE in classifier_info and \ |
| 245 | classifier_info[ETH_TYPE] == LLDP_ETH_TYPE: |
| 246 | self.log.debug('lldp flow add') |
| 247 | self.add_lldp_flow(flow, port_no) |
| 248 | return |
| 249 | |
| 250 | if ETH_TYPE in classifier_info and \ |
| 251 | classifier_info[ETH_TYPE] == IPV4_ETH_TYPE and \ |
| 252 | IP_PROTO in classifier_info and \ |
| 253 | classifier_info[IP_PROTO] == 2: |
| 254 | self.log.debug('igmp flow add ignored, not implemented yet') |
| 255 | return |
| 256 | |
| 257 | if IP_PROTO in classifier_info and \ |
| 258 | classifier_info[IP_PROTO] == 17 and \ |
| 259 | UDP_SRC in classifier_info and \ |
| 260 | classifier_info[UDP_SRC] == 67: |
| 261 | self.log.debug('trap-dhcp-from-nni-flow') |
| 262 | self.add_dhcp_trap_nni(flow, classifier_info, port_no, |
| 263 | network_intf_id=0) |
| 264 | return |
| 265 | |
| 266 | # Metadata 8 bytes: |
| 267 | # Most Significant 2 Bytes = Inner VLAN |
| 268 | # Next 2 Bytes = Tech Profile ID(TPID) |
| 269 | # Least Significant 4 Bytes = Port ID |
| 270 | # Flow METADATA carries Tech-Profile (TP) ID and is mandatory in all |
| 271 | # subscriber related flows. |
| 272 | # Note: If we are here, assert that the flow_metadata is not None |
| 273 | assert flow_metadata is not None |
| 274 | |
| 275 | # Retrieve the TP-ID if one exists for the subscriber already |
| 276 | tp_id = self.resource_mgr.get_tech_profile_id_for_onu(intf_id, onu_id, uni_id) |
| 277 | |
| 278 | if tp_id is not None: |
| 279 | # Assert that the tp_id received in flow metadata is same is the tp_id in use |
| 280 | # TODO: |
| 281 | # For now, tp_id updates, require that we tear down the service and |
| 282 | # and re-provision the service, i.e., dynamic TP updates not supported. |
| 283 | |
| 284 | assert tp_id == fd.get_tp_id_from_metadata(flow_metadata), \ |
| 285 | "tp-updates-not-supported" |
| 286 | else: |
| 287 | tp_id = fd.get_tp_id_from_metadata(flow_metadata) |
| 288 | self.log.info("received-tp-id-from-flow", tp_id=tp_id) |
| 289 | |
| 290 | if self.platform.is_upstream(action_info[OUTPUT]): |
| 291 | us_meter_id = fd.get_meter_id_from_flow(flow) |
| 292 | else: |
| 293 | ds_meter_id = fd.get_meter_id_from_flow(flow) |
| 294 | |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 295 | self.divide_and_add_flow(intf_id, onu_id, uni_id, port_no, |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 296 | classifier_info, action_info, flow, tp_id, us_meter_id, ds_meter_id) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 297 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 298 | def _clear_flow_id_from_rm(self, flow, flow_id, flow_direction): |
Shad Ansari | f9b9b89 | 2019-02-27 17:10:27 -0800 | [diff] [blame] | 299 | try: |
| 300 | pon_intf, onu_id, uni_id \ |
Shad Ansari | e497ad4 | 2019-03-11 21:11:38 -0700 | [diff] [blame] | 301 | = self.platform.flow_extract_info(flow, flow_direction) |
Shad Ansari | f9b9b89 | 2019-02-27 17:10:27 -0800 | [diff] [blame] | 302 | except ValueError: |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 303 | self.log.error("failure extracting pon_intf, onu_id, uni_id info from flow") |
Shad Ansari | f9b9b89 | 2019-02-27 17:10:27 -0800 | [diff] [blame] | 304 | else: |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 305 | 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] | 306 | assert (isinstance(flows, list)) |
| 307 | self.log.debug("retrieved-flows", flows=flows) |
| 308 | for idx in range(len(flows)): |
| 309 | if flow_direction == flows[idx]['flow_type']: |
| 310 | flows.pop(idx) |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 311 | self.update_flow_info_to_kv_store(pon_intf, onu_id, |
| 312 | uni_id, flow_id, flows) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 313 | if len(flows) > 0: |
| 314 | # There are still flows referencing the same flow_id. |
| 315 | # So the flow should not be freed yet. |
| 316 | # For ex: Case of HSIA where same flow is shared |
| 317 | # between DS and US. |
| 318 | return |
| 319 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 320 | self.resource_mgr.free_flow_id(pon_intf, onu_id, uni_id, flow_id) |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 321 | flow_list = self.resource_mgr.get_current_flow_ids(pon_intf, onu_id, uni_id) |
| 322 | if flow_list is None: |
| 323 | tp_id = self.resource_mgr.get_tech_profile_id_for_onu(pon_intf, onu_id, uni_id) |
| 324 | tp_instance = self.get_tech_profile_instance(pon_intf, onu_id, uni_id, tp_id) |
| 325 | self.log.info("all-flows-cleared-for-onu") |
| 326 | self.log.info("initiate-sched-queue-teardown") |
| 327 | self.remove_us_scheduler_queues(pon_intf, onu_id, uni_id, tp_instance) |
| 328 | self.remove_ds_scheduler_queues(pon_intf, onu_id, uni_id, tp_instance) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 329 | |
Scott Baker | be5a9ea | 2018-11-19 19:24:21 -0800 | [diff] [blame] | 330 | def retry_add_flow(self, flow): |
| 331 | self.log.debug("retry-add-flow") |
| 332 | if flow.id in self.retry_add_flow_list: |
| 333 | self.retry_add_flow_list.remove(flow.id) |
| 334 | self.add_flow(flow) |
| 335 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 336 | def remove_flow(self, flow): |
| 337 | self.log.debug('trying to remove flows from logical flow :', |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame] | 338 | logical_flow=flow) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 339 | device_flows_to_remove = [] |
| 340 | device_flows = self.flows_proxy.get('/').items |
| 341 | for f in device_flows: |
| 342 | if f.cookie == flow.id: |
| 343 | device_flows_to_remove.append(f) |
| 344 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 345 | for f in device_flows_to_remove: |
| 346 | (id, direction) = self.decode_stored_id(f.id) |
| 347 | flow_to_remove = openolt_pb2.Flow(flow_id=id, flow_type=direction) |
Nicolas Palpacuer | 3d0878d | 2018-08-17 11:29:42 -0400 | [diff] [blame] | 348 | try: |
| 349 | self.stub.FlowRemove(flow_to_remove) |
| 350 | except grpc.RpcError as grpc_e: |
| 351 | if grpc_e.code() == grpc.StatusCode.NOT_FOUND: |
| 352 | self.log.debug('This flow does not exist on the switch, ' |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame] | 353 | 'normal after an OLT reboot', |
| 354 | flow=flow_to_remove) |
Nicolas Palpacuer | 3d0878d | 2018-08-17 11:29:42 -0400 | [diff] [blame] | 355 | else: |
| 356 | raise grpc_e |
| 357 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 358 | # once we have successfully deleted the flow on the device |
| 359 | # release the flow_id on resource pool and also clear any |
| 360 | # data associated with the flow_id on KV store. |
| 361 | self._clear_flow_id_from_rm(f, id, direction) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 362 | self.log.debug('flow removed from device', flow=f, |
| 363 | flow_key=flow_to_remove) |
| 364 | |
| 365 | if len(device_flows_to_remove) > 0: |
| 366 | new_flows = [] |
| 367 | flows_ids_to_remove = [f.id for f in device_flows_to_remove] |
| 368 | for f in device_flows: |
| 369 | if f.id not in flows_ids_to_remove: |
| 370 | new_flows.append(f) |
| 371 | |
| 372 | self.flows_proxy.update('/', Flows(items=new_flows)) |
| 373 | self.log.debug('flows removed from the data store', |
| 374 | flow_ids_removed=flows_ids_to_remove, |
| 375 | number_of_flows_removed=(len(device_flows) - len( |
| 376 | new_flows)), expected_flows_removed=len( |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 377 | device_flows_to_remove)) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 378 | else: |
| 379 | self.log.debug('no device flow to remove for this flow (normal ' |
| 380 | 'for multi table flows)', flow=flow) |
| 381 | |
Thiyagarajan Subramani | 353af12 | 2019-02-20 23:14:24 -0800 | [diff] [blame] | 382 | def get_tp_path(self, intf_id, ofp_port_name, techprofile_id): |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 383 | return self.tech_profile[intf_id]. \ |
Thiyagarajan Subramani | 353af12 | 2019-02-20 23:14:24 -0800 | [diff] [blame] | 384 | get_tp_path(techprofile_id, |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 385 | ofp_port_name) |
| 386 | |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 387 | def delete_tech_profile_instance(self, intf_id, onu_id, uni_id, |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 388 | ofp_port_name=None): |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 389 | # Remove the TP instance associated with the ONU |
Thiyagarajan Subramani | 353af12 | 2019-02-20 23:14:24 -0800 | [diff] [blame] | 390 | if ofp_port_name is None: |
Shad Ansari | e497ad4 | 2019-03-11 21:11:38 -0700 | [diff] [blame] | 391 | ofp_port_name = self.data_model.serial_number(intf_id, onu_id) |
| 392 | |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 393 | tp_id = self.resource_mgr.get_tech_profile_id_for_onu(intf_id, onu_id, |
| 394 | uni_id) |
Thiyagarajan Subramani | 353af12 | 2019-02-20 23:14:24 -0800 | [diff] [blame] | 395 | tp_path = self.get_tp_path(intf_id, ofp_port_name, tp_id) |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 396 | self.log.debug(" tp-path-in-delete", tp_path=tp_path) |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 397 | return self.tech_profile[intf_id].delete_tech_profile_instance(tp_path) |
| 398 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 399 | def divide_and_add_flow(self, intf_id, onu_id, uni_id, port_no, classifier, |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 400 | action, flow, tp_id, us_meter_id, ds_meter_id): |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 401 | |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 402 | self.log.debug('sorting flow', intf_id=intf_id, onu_id=onu_id, |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 403 | uni_id=uni_id, port_no=port_no, |
| 404 | classifier=classifier, action=action, |
| 405 | tp_id=tp_id, us_meter=us_meter_id, |
| 406 | ds_meter=ds_meter_id) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 407 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 408 | tp_instance = self.get_tech_profile_instance(intf_id, onu_id, uni_id, tp_id) |
| 409 | if tp_instance is None: |
| 410 | self.log.error("flow-not-added--tp-instance-unavailable") |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 411 | return |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 412 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 413 | pon_intf_onu_id = (intf_id, onu_id, uni_id) |
| 414 | alloc_id = \ |
| 415 | self.resource_mgr.get_current_alloc_ids_for_onu(pon_intf_onu_id) |
| 416 | gem_ports = \ |
| 417 | self.resource_mgr.get_current_gemport_ids_for_onu(pon_intf_onu_id) |
| 418 | |
| 419 | if alloc_id is None or gem_ports is None: |
| 420 | self.log.error("alloc-id-or-gem-ports-unavailable", |
| 421 | alloc_id=alloc_id, gem_ports=gem_ports) |
| 422 | return |
| 423 | |
| 424 | self.create_us_scheduler_queues(intf_id, onu_id, uni_id, tp_instance, us_meter_id) |
| 425 | self.create_ds_scheduler_queues(intf_id, onu_id, uni_id, tp_instance, ds_meter_id) |
| 426 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 427 | self.log.debug('Generated required alloc and gemport ids', |
| 428 | alloc_id=alloc_id, gemports=gem_ports) |
| 429 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 430 | ds_gem_port_attr_list = tp_instance.downstream_gem_port_attribute_list |
| 431 | us_gem_port_attr_list = tp_instance.upstream_gem_port_attribute_list |
| 432 | kwargs = dict() |
| 433 | kwargs['intf_id'] = intf_id |
| 434 | kwargs['onu_id'] = onu_id |
| 435 | kwargs['uni_id'] = uni_id |
| 436 | kwargs['port_no'] = port_no |
| 437 | kwargs['classifier'] = classifier |
| 438 | kwargs['action'] = action |
| 439 | kwargs['logical_flow'] = flow |
| 440 | kwargs['alloc_id'] = alloc_id |
| 441 | |
| 442 | if IP_PROTO in classifier: |
| 443 | if classifier[IP_PROTO] == 17: |
| 444 | self.log.debug('dhcp flow add') |
| 445 | if VLAN_PCP in classifier: |
| 446 | gemport_id = self._get_gem_port_for_pcp( |
| 447 | classifier[VLAN_PCP], us_gem_port_attr_list |
| 448 | ) |
| 449 | self.add_dhcp_trap_uni(intf_id, onu_id, uni_id, port_no, |
| 450 | classifier, action, flow, alloc_id, |
| 451 | gemport_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 452 | else: |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 453 | self._install_flow_on_all_gemports(self.add_dhcp_trap_uni, |
| 454 | kwargs, |
| 455 | us_gem_port_attr_list) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 456 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 457 | elif classifier[IP_PROTO] == 2: |
| 458 | self.log.warn('igmp flow add ignored, not implemented yet') |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 459 | else: |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 460 | self.log.warn("Invalid-Classifier-to-handle", |
| 461 | classifier=classifier, |
| 462 | action=action) |
| 463 | elif ETH_TYPE in classifier: |
| 464 | if classifier[ETH_TYPE] == EAP_ETH_TYPE: |
| 465 | self.log.debug('eapol flow add') |
| 466 | vlan_id = classifier[VLAN_VID] |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 467 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 468 | if vlan_id is None: |
| 469 | vlan_id = DEFAULT_MGMT_VLAN |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 470 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 471 | if VLAN_PCP in classifier: |
| 472 | gemport_id = self._get_gem_port_for_pcp( |
| 473 | classifier[VLAN_PCP], us_gem_port_attr_list |
| 474 | ) |
| 475 | self.add_eapol_flow( |
| 476 | intf_id, onu_id, uni_id, port_no, flow, alloc_id, gemport_id, |
| 477 | vlan_id=vlan_id) |
| 478 | else: |
| 479 | kwargs['vlan_id'] = vlan_id |
| 480 | self._install_flow_on_all_gemports(self.add_eapol_flow, |
| 481 | kwargs, |
| 482 | us_gem_port_attr_list) |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 483 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 484 | (ofp_port_name, ofp_port_no) = \ |
| 485 | self.data_model.get_ofp_port_name(intf_id, onu_id, uni_id) |
| 486 | if ofp_port_name is None: |
| 487 | self.log.error("port-name-not-found") |
| 488 | return |
| 489 | |
| 490 | tp_id = self.resource_mgr.get_tech_profile_id_for_onu(intf_id, onu_id, uni_id) |
| 491 | tp_path = self.get_tp_path(intf_id, ofp_port_name, tp_id) |
| 492 | |
| 493 | self.log.debug('Load-tech-profile-request-to-brcm-handler', |
| 494 | tp_path=tp_path) |
| 495 | self.data_model.onu_download_tech_profile( |
| 496 | intf_id, onu_id, uni_id, tp_path) |
| 497 | elif PUSH_VLAN in action: |
| 498 | if VLAN_PCP in classifier: |
| 499 | gemport_id = self._get_gem_port_for_pcp( |
| 500 | classifier[VLAN_PCP], us_gem_port_attr_list |
| 501 | ) |
| 502 | self.add_upstream_data_flow(intf_id, onu_id, uni_id, port_no, classifier, |
| 503 | action, flow, alloc_id, gemport_id) |
| 504 | else: |
| 505 | self._install_flow_on_all_gemports(self.add_upstream_data_flow, |
| 506 | kwargs, us_gem_port_attr_list |
| 507 | ) |
| 508 | elif POP_VLAN in action: |
| 509 | if VLAN_PCP in classifier: |
| 510 | gemport_id = self._get_gem_port_for_pcp( |
Girish Gowdru | 80f8e40 | 2019-05-07 00:22:59 -0700 | [diff] [blame] | 511 | classifier[VLAN_PCP], ds_gem_port_attr_list |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 512 | ) |
| 513 | self.add_downstream_data_flow(intf_id, onu_id, uni_id, port_no, classifier, |
| 514 | action, flow, alloc_id, gemport_id) |
| 515 | else: |
| 516 | self._install_flow_on_all_gemports(self.add_downstream_data_flow, |
| 517 | kwargs, ds_gem_port_attr_list |
| 518 | ) |
| 519 | else: |
| 520 | self.log.debug('Invalid-flow-type-to-handle', |
| 521 | classifier=classifier, |
| 522 | action=action, flow=flow) |
| 523 | |
| 524 | def get_scheduler(self, tech_profile_instance, direction, meter_id): |
| 525 | if direction == Direction.UPSTREAM: |
| 526 | scheduler = tech_profile_instance.us_scheduler |
| 527 | elif direction == Direction.DOWNSTREAM: |
| 528 | scheduler = tech_profile_instance.ds_scheduler |
| 529 | else: |
| 530 | raise Exception("invalid-direction") |
| 531 | |
| 532 | meter_band = self.data_model.meter_band(meter_id) |
| 533 | |
| 534 | traffic_shaping_info = None |
| 535 | |
| 536 | if meter_band is not None: |
| 537 | cir = meter_band.bands[0].rate |
| 538 | cbs = meter_band.bands[0].burst_size |
| 539 | eir = meter_band.bands[1].rate |
| 540 | ebs = meter_band.bands[1].burst_size |
| 541 | pir = cir + eir |
| 542 | pbs = cbs + ebs |
| 543 | |
| 544 | traffic_shaping_info = tech_profile_pb2.TrafficShapingInfo( |
| 545 | cir=cir, |
| 546 | cbs=cbs, |
| 547 | pir=pir, |
| 548 | pbs=pbs |
| 549 | ) |
| 550 | |
| 551 | scheduler_config = tech_profile_pb2.SchedulerConfig( |
| 552 | direction=TechProfile.get_parameter( |
| 553 | 'direction', scheduler.direction), |
| 554 | additional_bw=TechProfile.get_parameter( |
| 555 | 'additional_bw', scheduler.additional_bw), |
| 556 | priority=scheduler.priority, |
| 557 | weight=scheduler.weight, |
| 558 | sched_policy=TechProfile.get_parameter( |
| 559 | 'q_sched_policy', scheduler.q_sched_policy) |
| 560 | ) |
| 561 | |
| 562 | traffic_scheduler = tech_profile_pb2.TrafficScheduler( |
| 563 | direction=scheduler.direction, |
| 564 | scheduler=scheduler_config, |
| 565 | alloc_id=scheduler.alloc_id, |
| 566 | traffic_shaping_info=traffic_shaping_info |
| 567 | ) |
| 568 | |
| 569 | return traffic_scheduler |
| 570 | |
| 571 | @staticmethod |
| 572 | def get_traffic_queues(tech_profile_instance, direction): |
| 573 | if direction == Direction.UPSTREAM: |
| 574 | gemport_attribute_list = tech_profile_instance. \ |
| 575 | upstream_gem_port_attribute_list |
| 576 | tp_scheduler_direction = tech_profile_instance.us_scheduler.direction |
| 577 | elif direction == Direction.DOWNSTREAM: |
| 578 | gemport_attribute_list = tech_profile_instance. \ |
| 579 | downstream_gem_port_attribute_list |
| 580 | tp_scheduler_direction = tech_profile_instance.ds_scheduler.direction |
| 581 | else: |
| 582 | raise Exception("invalid-direction") |
| 583 | traffic_queues = list() |
| 584 | for i in range(len(gemport_attribute_list)): |
| 585 | traffic_queues.append(tech_profile_pb2.TrafficQueue( |
| 586 | direction=TechProfile.get_parameter('direction', |
| 587 | tp_scheduler_direction), |
| 588 | gemport_id=gemport_attribute_list[i].gemport_id, |
| 589 | pbit_map=gemport_attribute_list[i].pbit_map, |
| 590 | aes_encryption=ast.literal_eval(gemport_attribute_list[i]. |
| 591 | aes_encryption), |
| 592 | sched_policy=TechProfile.get_parameter( |
| 593 | 'sched_policy', gemport_attribute_list[i]. |
| 594 | scheduling_policy), |
| 595 | priority=gemport_attribute_list[i].priority_q, |
| 596 | weight=gemport_attribute_list[i].weight, |
| 597 | discard_policy=TechProfile.get_parameter( |
| 598 | 'discard_policy', gemport_attribute_list[i]. |
| 599 | discard_policy))) |
| 600 | |
| 601 | return traffic_queues |
| 602 | |
| 603 | def create_us_scheduler_queues(self, intf_id, onu_id, uni_id, tp_instance, us_meter_id): |
| 604 | if us_meter_id is None: |
| 605 | self.log.debug("us-meter-unavailable--no-action") |
| 606 | return |
| 607 | |
| 608 | kv_store_meter_id = self.resource_mgr.get_meter_id_for_onu(UPSTREAM, |
| 609 | intf_id, |
| 610 | onu_id, uni_id) |
| 611 | |
| 612 | # Lets make a simple assumption that if the meter-id is present on the KV store, |
| 613 | # then the scheduler and queues configuration is applied on the OLT device |
| 614 | # in the given direction. |
| 615 | if kv_store_meter_id is not None: |
| 616 | # TODO: Dynamic meter update not supported for now |
| 617 | # TODO: The subscriber has to be un-provisioned and re-provisioned for meter update |
| 618 | assert kv_store_meter_id == us_meter_id |
| 619 | self.log.debug("scheduler-already-created-in-us") |
| 620 | return |
| 621 | |
| 622 | traffic_sched = self.get_scheduler(tp_instance, Direction.UPSTREAM, us_meter_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 623 | try: |
Shad Ansari | e497ad4 | 2019-03-11 21:11:38 -0700 | [diff] [blame] | 624 | ofp_port_no = self.platform.mk_uni_port_num(intf_id, |
| 625 | onu_id, uni_id) |
| 626 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 627 | self.stub.CreateTrafficSchedulers( |
| 628 | tech_profile_pb2.TrafficSchedulers( |
| 629 | intf_id=intf_id, |
| 630 | onu_id=onu_id, |
| 631 | uni_id=uni_id, |
| 632 | port_no=ofp_port_no, |
| 633 | traffic_scheds=[traffic_sched] |
| 634 | )) |
| 635 | except grpc.RpcError as grpc_e: |
| 636 | if grpc_e.code() == grpc.StatusCode.ALREADY_EXISTS: |
| 637 | self.log.warn("us-scheduler-already-exists") |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 638 | else: |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 639 | self.log.error("failure-to-create-us-scheduler") |
| 640 | return |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 641 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 642 | # On receiving the CreateTrafficQueues request, the driver should create corresponding |
| 643 | # downstream queues. |
| 644 | try: |
| 645 | self.stub.CreateTrafficQueues( |
| 646 | tech_profile_pb2.TrafficQueues( |
| 647 | intf_id=intf_id, |
| 648 | onu_id=onu_id, |
| 649 | uni_id=uni_id, |
| 650 | port_no=ofp_port_no, |
| 651 | traffic_queues= |
| 652 | OpenOltFlowMgr.get_traffic_queues(tp_instance, Direction.UPSTREAM) |
| 653 | )) |
| 654 | except grpc.RpcError as grpc_e: |
| 655 | if grpc_e.code() == grpc.StatusCode.ALREADY_EXISTS: |
| 656 | self.log.warn("ds-queues-already-exists") |
| 657 | else: |
| 658 | self.log.error("failure-to-create-ds-queues") |
| 659 | return |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 660 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 661 | # After we succesfully applied the scheduler configuration on the OLT device, |
| 662 | # store the meter id on the KV store, for further reference |
| 663 | self.resource_mgr.update_meter_id_for_onu(UPSTREAM, intf_id, onu_id, uni_id, us_meter_id) |
| 664 | |
| 665 | def create_ds_scheduler_queues(self, intf_id, onu_id, uni_id, tp_instance, ds_meter_id): |
| 666 | if ds_meter_id is None: |
| 667 | self.log.debug("ds-meter-unavailable--no-action") |
| 668 | return |
| 669 | |
| 670 | kv_store_meter_id = self.resource_mgr.get_meter_id_for_onu(DOWNSTREAM, |
| 671 | intf_id, |
| 672 | onu_id, uni_id) |
| 673 | # Lets make a simple assumption that if the meter-id is present on the KV store, |
| 674 | # then the scheduler and queues configuration is applied on the OLT device |
| 675 | if kv_store_meter_id is not None: |
| 676 | # TODO: Dynamic meter update not supported for now |
| 677 | # TODO: The subscriber has to be un-provisioned and re-provisioned for meter update |
| 678 | assert kv_store_meter_id == ds_meter_id |
| 679 | self.log.debug("scheduler-already-created-in-ds") |
| 680 | return |
| 681 | |
| 682 | traffic_sched = self.get_scheduler(tp_instance, Direction.DOWNSTREAM, ds_meter_id) |
| 683 | _, ofp_port_no = self.data_model.get_ofp_port_name(intf_id, onu_id, uni_id) |
| 684 | try: |
| 685 | self.stub.CreateTrafficSchedulers( |
| 686 | tech_profile_pb2.TrafficSchedulers( |
| 687 | intf_id=intf_id, |
| 688 | onu_id=onu_id, |
| 689 | uni_id=uni_id, |
| 690 | port_no=ofp_port_no, |
| 691 | traffic_scheds=[traffic_sched] |
| 692 | )) |
| 693 | except grpc.RpcError as grpc_e: |
| 694 | if grpc_e.code() == grpc.StatusCode.ALREADY_EXISTS: |
| 695 | self.log.warn("ds-scheduler-already-exists") |
| 696 | else: |
| 697 | self.log.error("failure-to-create-ds-scheduler") |
| 698 | return |
| 699 | |
| 700 | # On receiving the CreateTrafficQueues request, the driver should create corresponding |
| 701 | # downstream queues. |
| 702 | try: |
| 703 | self.stub.CreateTrafficQueues( |
| 704 | tech_profile_pb2.TrafficQueues( |
| 705 | intf_id=intf_id, |
| 706 | onu_id=onu_id, |
| 707 | uni_id=uni_id, |
| 708 | port_no=ofp_port_no, |
| 709 | traffic_queues= |
| 710 | OpenOltFlowMgr.get_traffic_queues(tp_instance, Direction.DOWNSTREAM) |
| 711 | )) |
| 712 | except grpc.RpcError as grpc_e: |
| 713 | if grpc_e.code() == grpc.StatusCode.ALREADY_EXISTS: |
| 714 | self.log.warn("ds-queues-already-exists") |
| 715 | else: |
| 716 | self.log.error("failure-to-create-ds-queues") |
| 717 | return |
| 718 | |
| 719 | # After we successfully applied the scheduler configuration on the OLT device, |
| 720 | # store the meter id on the KV store, for further reference |
| 721 | self.resource_mgr.update_meter_id_for_onu(DOWNSTREAM, intf_id, onu_id, uni_id, ds_meter_id) |
| 722 | |
| 723 | def remove_us_scheduler_queues(self, intf_id, onu_id, uni_id, tp_instance): |
| 724 | us_meter_id = self.resource_mgr.get_meter_id_for_onu(UPSTREAM, |
| 725 | intf_id, |
| 726 | onu_id, uni_id) |
| 727 | traffic_sched = self.get_scheduler(tp_instance, Direction.UPSTREAM, us_meter_id) |
| 728 | _, ofp_port_no = self.data_model.get_ofp_port_name(intf_id, onu_id, uni_id) |
| 729 | |
| 730 | try: |
| 731 | self.stub.RemoveTrafficQueues( |
| 732 | tech_profile_pb2.TrafficQueues( |
| 733 | intf_id=intf_id, |
| 734 | onu_id=onu_id, |
| 735 | uni_id=uni_id, |
| 736 | port_no=ofp_port_no, |
| 737 | traffic_queues= |
| 738 | OpenOltFlowMgr.get_traffic_queues(tp_instance, Direction.UPSTREAM) |
| 739 | )) |
| 740 | self.log.debug("removed-upstream-Queues") |
| 741 | except grpc.RpcError as e: |
| 742 | self.log.error("failure-to-remove-us-queues", e=e) |
| 743 | |
| 744 | try: |
| 745 | self.stub.RemoveTrafficSchedulers( |
| 746 | tech_profile_pb2.TrafficSchedulers( |
| 747 | intf_id=intf_id, |
| 748 | onu_id=onu_id, |
| 749 | uni_id=uni_id, |
| 750 | port_no=ofp_port_no, |
| 751 | traffic_scheds=[traffic_sched] |
| 752 | )) |
| 753 | self.log.debug("removed-upstream-Schedulers") |
| 754 | except grpc.RpcError as e: |
| 755 | self.log.error("failure-to-remove-us-scheduler", e=e) |
| 756 | |
| 757 | self.resource_mgr.remove_meter_id_for_onu(UPSTREAM, intf_id, onu_id, uni_id) |
| 758 | |
| 759 | def remove_ds_scheduler_queues(self, intf_id, onu_id, uni_id, tp_instance): |
| 760 | ds_meter_id = self.resource_mgr.get_meter_id_for_onu(DOWNSTREAM, |
| 761 | intf_id, |
| 762 | onu_id, uni_id) |
| 763 | |
| 764 | traffic_sched = self.get_scheduler(tp_instance, Direction.DOWNSTREAM, ds_meter_id) |
| 765 | _, ofp_port_no = self.data_model.get_ofp_port_name(intf_id, onu_id, uni_id) |
| 766 | |
| 767 | try: |
| 768 | self.stub.RemoveTrafficQueues( |
| 769 | tech_profile_pb2.TrafficQueues( |
| 770 | intf_id=intf_id, |
| 771 | onu_id=onu_id, |
| 772 | uni_id=uni_id, |
| 773 | port_no=ofp_port_no, |
| 774 | traffic_queues= |
| 775 | OpenOltFlowMgr.get_traffic_queues(tp_instance, Direction.DOWNSTREAM) |
| 776 | )) |
| 777 | self.log.debug("removed-downstream-Queues") |
| 778 | except grpc.RpcError as grpc_e: |
| 779 | self.log.error("failure-to-remove-ds-queues") |
| 780 | |
| 781 | try: |
| 782 | self.stub.RemoveTrafficSchedulers( |
| 783 | tech_profile_pb2.TrafficSchedulers( |
| 784 | intf_id=intf_id, |
| 785 | onu_id=onu_id, |
| 786 | uni_id=uni_id, |
| 787 | port_no=ofp_port_no, |
| 788 | traffic_scheds=[traffic_sched] |
| 789 | )) |
| 790 | self.log.debug("removed-downstream-Schedulers") |
| 791 | except grpc.RpcError as grpc_e: |
| 792 | self.log.error("failure-to-remove-ds-scheduler") |
| 793 | |
| 794 | self.resource_mgr.remove_meter_id_for_onu(DOWNSTREAM, intf_id, onu_id, uni_id) |
| 795 | |
| 796 | def get_tech_profile_instance(self, intf_id, onu_id, uni_id, tp_id): |
| 797 | (ofp_port_name, ofp_port_no) \ |
| 798 | = self.data_model.get_ofp_port_name(intf_id, onu_id, uni_id) |
| 799 | if ofp_port_name is None: |
| 800 | self.log.error("port-name-not-found") |
| 801 | return None |
| 802 | |
| 803 | # Check tech profile instance already exists for derived port name |
| 804 | tech_profile_instance = self.tech_profile[intf_id]. \ |
| 805 | get_tech_profile_instance(tp_id, ofp_port_name) |
| 806 | |
| 807 | if tech_profile_instance is None: |
| 808 | # create tech profile instance |
| 809 | tech_profile_instance = self.tech_profile[intf_id]. \ |
| 810 | create_tech_profile_instance(tp_id, ofp_port_name, |
| 811 | intf_id) |
| 812 | if tech_profile_instance is None: |
| 813 | raise Exception('Tech-profile-instance-creation-failed') |
| 814 | |
| 815 | self.resource_mgr.update_tech_profile_id_for_onu(intf_id, onu_id, |
| 816 | uni_id, tp_id) |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 817 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 818 | # Fetch alloc id and gemports from tech profile instance |
| 819 | alloc_id = tech_profile_instance.us_scheduler.alloc_id |
| 820 | gem_port_ids = [] |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 821 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 822 | for i in range(len( |
| 823 | tech_profile_instance.upstream_gem_port_attribute_list)): |
| 824 | gem_port_ids.append( |
| 825 | tech_profile_instance.upstream_gem_port_attribute_list[i]. |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 826 | gemport_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 827 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 828 | # Update the allocated alloc_id and gem_port_id for the ONU/UNI to KV |
| 829 | # store |
| 830 | pon_intf_onu_id = (intf_id, onu_id, uni_id) |
| 831 | self.resource_mgr.resource_mgrs[intf_id].update_alloc_ids_for_onu( |
| 832 | pon_intf_onu_id, |
| 833 | list([alloc_id]) |
| 834 | ) |
| 835 | self.resource_mgr.resource_mgrs[intf_id].update_gemport_ids_for_onu( |
| 836 | pon_intf_onu_id, |
| 837 | gem_port_ids |
| 838 | ) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 839 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 840 | self.resource_mgr.update_gemports_ponport_to_onu_map_on_kv_store( |
| 841 | gem_port_ids, intf_id, onu_id, uni_id |
| 842 | ) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 843 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 844 | for gemport_id in gem_port_ids: |
| 845 | self.data_model.gemport_id_add(intf_id, onu_id, gemport_id) |
| 846 | else: |
| 847 | self.log.debug( |
| 848 | 'Tech-profile-instance-already-exist-for-given port-name', |
| 849 | ofp_port_name=ofp_port_name) |
Shad Ansari | 4f9a973 | 2019-03-08 16:47:08 -0800 | [diff] [blame] | 850 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 851 | return tech_profile_instance |
| 852 | |
| 853 | def get_alloc_id_gem_port(self, intf_id, onu_id): |
| 854 | pon_intf_onu_id = (intf_id, onu_id) |
| 855 | # If we already have allocated alloc_id and gem_ports earlier, render them |
| 856 | alloc_id = \ |
| 857 | self.resource_mgr.get_current_alloc_ids_for_onu(pon_intf_onu_id) |
| 858 | gem_port_ids = \ |
| 859 | self.resource_mgr.get_current_gemport_ids_for_onu(pon_intf_onu_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 860 | return alloc_id, gem_port_ids |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 861 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 862 | def add_upstream_data_flow(self, intf_id, onu_id, uni_id, port_no, classifier, |
| 863 | action, logical_flow, alloc_id, gemport_id): |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 864 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 865 | classifier[PACKET_TAG_TYPE] = SINGLE_TAG |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 866 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 867 | self.add_hsia_flow(intf_id, onu_id, uni_id, port_no, classifier, |
| 868 | action, UPSTREAM, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 869 | logical_flow, alloc_id, gemport_id) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 870 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 871 | def add_downstream_data_flow(self, intf_id, onu_id, uni_id, port_no, classifier, |
| 872 | action, logical_flow, alloc_id, gemport_id): |
| 873 | classifier[PACKET_TAG_TYPE] = DOUBLE_TAG |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 874 | # Needed ???? It should be already there |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 875 | action[POP_VLAN] = True |
| 876 | action[VLAN_VID] = classifier[VLAN_VID] |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 877 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 878 | self.add_hsia_flow(intf_id, onu_id, uni_id, port_no, classifier, |
| 879 | action, DOWNSTREAM, |
| 880 | logical_flow, alloc_id, gemport_id) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 881 | |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 882 | def add_hsia_flow(self, intf_id, onu_id, uni_id, port_no, classifier, |
| 883 | action, direction, logical_flow, alloc_id, gemport_id): |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 884 | |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 885 | flow_store_cookie = self._get_flow_store_cookie(classifier, |
| 886 | gemport_id) |
| 887 | |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 888 | if self.resource_mgr.is_flow_cookie_on_kv_store(intf_id, onu_id, |
| 889 | uni_id, |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 890 | flow_store_cookie): |
| 891 | self.log.debug('flow-exists--not-re-adding') |
| 892 | else: |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 893 | # One of the OLT platform (Broadcom BAL) requires that symmetric |
| 894 | # flows require the same flow_id to be used across UL and DL. |
| 895 | # Since HSIA flow is the only symmetric flow currently, we need to |
| 896 | # re-use the flow_id across both direction. The 'flow_category' |
| 897 | # takes priority over flow_cookie to find any available HSIA_FLOW |
| 898 | # id for the ONU. |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 899 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 900 | flow_id = self.resource_mgr.get_flow_id(intf_id, onu_id, uni_id, |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 901 | flow_category=HSIA_FLOW, |
| 902 | flow_pcp=classifier[VLAN_PCP]) |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 903 | if flow_id is None: |
| 904 | self.log.error("hsia-flow-unavailable") |
| 905 | return |
| 906 | |
| 907 | flow = openolt_pb2.Flow( |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 908 | access_intf_id=intf_id, onu_id=onu_id, uni_id=uni_id, |
| 909 | flow_id=flow_id, flow_type=direction, alloc_id=alloc_id, |
Shad Ansari | f9b9b89 | 2019-02-27 17:10:27 -0800 | [diff] [blame] | 910 | network_intf_id=self.data_model.olt_nni_intf_id(), |
| 911 | gemport_id=gemport_id, |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 912 | classifier=self.mk_classifier(classifier), |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 913 | action=self.mk_action(action), priority=logical_flow.priority, |
| 914 | port_no=port_no, cookie=logical_flow.cookie) |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 915 | |
| 916 | if self.add_flow_to_device(flow, logical_flow): |
| 917 | flow_info = self._get_flow_info_as_json_blob(flow, |
| 918 | flow_store_cookie, |
| 919 | HSIA_FLOW) |
| 920 | self.update_flow_info_to_kv_store(flow.access_intf_id, |
| 921 | flow.onu_id, flow.uni_id, |
| 922 | flow.flow_id, flow_info) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 923 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 924 | def add_dhcp_trap_uni(self, intf_id, onu_id, uni_id, port_no, classifier, |
| 925 | action, logical_flow, alloc_id, gemport_id): |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 926 | |
Shad Ansari | 47e0c39 | 2018-07-17 23:55:07 +0000 | [diff] [blame] | 927 | self.log.debug('add dhcp upstream trap', classifier=classifier, |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 928 | intf_id=intf_id, onu_id=onu_id, uni_id=uni_id, |
| 929 | action=action) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 930 | |
| 931 | action.clear() |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 932 | action[TRAP_TO_HOST] = True |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 933 | classifier[UDP_SRC] = 68 |
| 934 | classifier[UDP_DST] = 67 |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 935 | classifier[PACKET_TAG_TYPE] = SINGLE_TAG |
| 936 | classifier.pop(VLAN_VID, None) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 937 | |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 938 | flow_store_cookie = self._get_flow_store_cookie(classifier, |
| 939 | gemport_id) |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 940 | |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 941 | if self.resource_mgr.is_flow_cookie_on_kv_store(intf_id, onu_id, |
| 942 | uni_id, |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 943 | flow_store_cookie): |
| 944 | self.log.debug('flow-exists--not-re-adding') |
| 945 | else: |
| 946 | flow_id = self.resource_mgr.get_flow_id( |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 947 | intf_id, onu_id, uni_id, |
| 948 | flow_store_cookie=flow_store_cookie, |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 949 | ) |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 950 | dhcp_flow = openolt_pb2.Flow( |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 951 | onu_id=onu_id, uni_id=uni_id, flow_id=flow_id, |
| 952 | flow_type=UPSTREAM, access_intf_id=intf_id, |
| 953 | gemport_id=gemport_id, alloc_id=alloc_id, |
Shad Ansari | f9b9b89 | 2019-02-27 17:10:27 -0800 | [diff] [blame] | 954 | network_intf_id=self.data_model.olt_nni_intf_id(), |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 955 | priority=logical_flow.priority, |
| 956 | classifier=self.mk_classifier(classifier), |
| 957 | action=self.mk_action(action), |
| 958 | port_no=port_no, |
| 959 | cookie=logical_flow.cookie) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 960 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 961 | if self.add_flow_to_device(dhcp_flow, logical_flow): |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 962 | flow_info = self._get_flow_info_as_json_blob(dhcp_flow, |
| 963 | flow_store_cookie) |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 964 | self.update_flow_info_to_kv_store(dhcp_flow.access_intf_id, |
| 965 | dhcp_flow.onu_id, |
| 966 | dhcp_flow.uni_id, |
| 967 | dhcp_flow.flow_id, |
| 968 | flow_info) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 969 | |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 970 | def add_eapol_flow(self, intf_id, onu_id, uni_id, port_no, logical_flow, |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 971 | alloc_id, gemport_id, vlan_id=DEFAULT_MGMT_VLAN, classifier=None, action=None): |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 972 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 973 | uplink_classifier = dict() |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 974 | uplink_classifier[ETH_TYPE] = EAP_ETH_TYPE |
| 975 | uplink_classifier[PACKET_TAG_TYPE] = SINGLE_TAG |
| 976 | uplink_classifier[VLAN_VID] = vlan_id |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 977 | if classifier is not None: |
| 978 | uplink_classifier[VLAN_PCP] = classifier[VLAN_PCP] |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 979 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 980 | uplink_action = dict() |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 981 | uplink_action[TRAP_TO_HOST] = True |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 982 | |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 983 | flow_store_cookie = self._get_flow_store_cookie(uplink_classifier, |
| 984 | gemport_id) |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 985 | if self.resource_mgr.is_flow_cookie_on_kv_store(intf_id, onu_id, |
| 986 | uni_id, |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 987 | flow_store_cookie): |
| 988 | self.log.debug('flow-exists--not-re-adding') |
| 989 | else: |
| 990 | # Add Upstream EAPOL Flow. |
| 991 | uplink_flow_id = self.resource_mgr.get_flow_id( |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 992 | intf_id, onu_id, uni_id, |
| 993 | flow_store_cookie=flow_store_cookie |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 994 | ) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 995 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 996 | upstream_flow = openolt_pb2.Flow( |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 997 | access_intf_id=intf_id, onu_id=onu_id, uni_id=uni_id, |
| 998 | flow_id=uplink_flow_id, flow_type=UPSTREAM, alloc_id=alloc_id, |
Shad Ansari | f9b9b89 | 2019-02-27 17:10:27 -0800 | [diff] [blame] | 999 | network_intf_id=self.data_model.olt_nni_intf_id(), |
| 1000 | gemport_id=gemport_id, |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 1001 | classifier=self.mk_classifier(uplink_classifier), |
| 1002 | action=self.mk_action(uplink_action), |
| 1003 | priority=logical_flow.priority, |
| 1004 | port_no=port_no, |
| 1005 | cookie=logical_flow.cookie) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 1006 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 1007 | logical_flow = copy.deepcopy(logical_flow) |
| 1008 | logical_flow.match.oxm_fields.extend(fd.mk_oxm_fields([fd.vlan_vid( |
| 1009 | vlan_id | 0x1000)])) |
| 1010 | logical_flow.match.type = OFPMT_OXM |
| 1011 | |
| 1012 | if self.add_flow_to_device(upstream_flow, logical_flow): |
| 1013 | flow_info = self._get_flow_info_as_json_blob(upstream_flow, |
| 1014 | flow_store_cookie) |
| 1015 | self.update_flow_info_to_kv_store(upstream_flow.access_intf_id, |
| 1016 | upstream_flow.onu_id, |
| 1017 | upstream_flow.uni_id, |
| 1018 | upstream_flow.flow_id, |
| 1019 | flow_info) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 1020 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 1021 | # Add Downstream EAPOL Flow, Only for first EAP flow (BAL |
| 1022 | # requirement) |
| 1023 | # On one of the platforms (Broadcom BAL), when same DL classifier |
| 1024 | # vlan was used across multiple ONUs, eapol flow re-adds after |
| 1025 | # flow delete (cases of onu reboot/disable) fails. |
| 1026 | # In order to generate unique vlan, a combination of intf_id |
| 1027 | # onu_id and uni_id is used. |
| 1028 | # uni_id defaults to 0, so add 1 to it. |
| 1029 | special_vlan_downstream_flow = 4090 - intf_id * onu_id * (uni_id + 1) |
| 1030 | # Assert that we do not generate invalid vlans under no condition |
| 1031 | assert special_vlan_downstream_flow >= 2 |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 1032 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 1033 | downlink_classifier = dict() |
| 1034 | downlink_classifier[PACKET_TAG_TYPE] = SINGLE_TAG |
| 1035 | downlink_classifier[ETH_TYPE] = EAP_ETH_TYPE |
| 1036 | downlink_classifier[VLAN_VID] = special_vlan_downstream_flow |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 1037 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 1038 | downlink_action = dict() |
| 1039 | downlink_action[PUSH_VLAN] = True |
| 1040 | downlink_action[VLAN_VID] = vlan_id |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 1041 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 1042 | flow_store_cookie = self._get_flow_store_cookie( |
| 1043 | downlink_classifier, gemport_id) |
| 1044 | if self.resource_mgr.is_flow_cookie_on_kv_store( |
| 1045 | intf_id, onu_id, uni_id, flow_store_cookie): |
| 1046 | self.log.debug('flow-exists--not-re-adding') |
| 1047 | else: |
| 1048 | downlink_flow_id = self.resource_mgr.get_flow_id( |
| 1049 | intf_id, onu_id, uni_id, |
| 1050 | flow_store_cookie=flow_store_cookie |
| 1051 | ) |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 1052 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 1053 | downstream_flow = openolt_pb2.Flow( |
| 1054 | access_intf_id=intf_id, onu_id=onu_id, uni_id=uni_id, |
| 1055 | flow_id=downlink_flow_id, flow_type=DOWNSTREAM, |
| 1056 | alloc_id=alloc_id, |
| 1057 | network_intf_id=self.data_model.olt_nni_intf_id(), |
| 1058 | gemport_id=gemport_id, |
| 1059 | classifier=self.mk_classifier(downlink_classifier), |
| 1060 | action=self.mk_action(downlink_action), |
| 1061 | priority=logical_flow.priority, |
| 1062 | port_no=port_no, |
| 1063 | cookie=logical_flow.cookie) |
Nicolas Palpacuer | 6152a32 | 2018-09-05 10:52:15 -0400 | [diff] [blame] | 1064 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 1065 | downstream_logical_flow = ofp_flow_stats( |
| 1066 | id=logical_flow.id, cookie=logical_flow.cookie, |
| 1067 | table_id=logical_flow.table_id, |
| 1068 | priority=logical_flow.priority, flags=logical_flow.flags) |
Nicolas Palpacuer | 6152a32 | 2018-09-05 10:52:15 -0400 | [diff] [blame] | 1069 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 1070 | downstream_logical_flow.match.oxm_fields.extend( |
| 1071 | fd.mk_oxm_fields( |
| 1072 | [fd.in_port(fd.get_out_port(logical_flow)), |
| 1073 | fd.vlan_vid(special_vlan_downstream_flow | 0x1000)])) |
| 1074 | downstream_logical_flow.match.type = OFPMT_OXM |
Nicolas Palpacuer | 6152a32 | 2018-09-05 10:52:15 -0400 | [diff] [blame] | 1075 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 1076 | downstream_logical_flow.instructions.extend( |
| 1077 | fd.mk_instructions_from_actions([fd.output( |
| 1078 | self.platform.mk_uni_port_num(intf_id, onu_id, |
| 1079 | uni_id))])) |
Nicolas Palpacuer | 6152a32 | 2018-09-05 10:52:15 -0400 | [diff] [blame] | 1080 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 1081 | if self.add_flow_to_device(downstream_flow, |
| 1082 | downstream_logical_flow): |
| 1083 | flow_info = self._get_flow_info_as_json_blob( |
| 1084 | downstream_flow, flow_store_cookie) |
| 1085 | self.update_flow_info_to_kv_store( |
| 1086 | downstream_flow.access_intf_id, downstream_flow.onu_id, |
| 1087 | downstream_flow.uni_id, downstream_flow.flow_id, |
| 1088 | flow_info) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 1089 | |
Nicolas Palpacuer | 4114135 | 2018-08-31 14:11:38 -0400 | [diff] [blame] | 1090 | def repush_all_different_flows(self): |
| 1091 | # Check if the device is supposed to have flows, if so add them |
| 1092 | # Recover static flows after a reboot |
| 1093 | logical_flows = self.logical_flows_proxy.get('/').items |
| 1094 | devices_flows = self.flows_proxy.get('/').items |
| 1095 | logical_flows_ids_provisioned = [f.cookie for f in devices_flows] |
| 1096 | for logical_flow in logical_flows: |
| 1097 | try: |
| 1098 | if logical_flow.id not in logical_flows_ids_provisioned: |
| 1099 | self.add_flow(logical_flow) |
| 1100 | except Exception as e: |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 1101 | self.log.exception('Problem reading this flow', e=e) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 1102 | |
Nicolas Palpacuer | 4114135 | 2018-08-31 14:11:38 -0400 | [diff] [blame] | 1103 | def reset_flows(self): |
Girish Gowdru | 7596229 | 2019-05-03 04:33:34 -0700 | [diff] [blame^] | 1104 | self.flows_proxy.update('/', Flows(items=[])) |
| 1105 | self.log.debug("purged-all-device-flows") |
| 1106 | |
| 1107 | self.logical_flows_proxy.update('/', Flows(items=[])) |
| 1108 | self.log.debug("purged-all-logical-flows") |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 1109 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 1110 | """ Add a downstream DHCP trap flow on the NNI interface |
Shad Ansari | fd0111d | 2018-09-13 21:33:06 +0000 | [diff] [blame] | 1111 | """ |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 1112 | def add_dhcp_trap_nni(self, logical_flow, classifier, |
| 1113 | port_no, network_intf_id=0): |
| 1114 | self.log.info("trap-dhcp-of-nni-flow") |
| 1115 | classifier[PACKET_TAG_TYPE] = DOUBLE_TAG |
| 1116 | action = dict() |
| 1117 | action[TRAP_TO_HOST] = True |
| 1118 | |
| 1119 | # We manage flow_id resource pool on per PON port basis. |
| 1120 | # Since this situation is tricky, as a hack, we pass the NNI port |
| 1121 | # index (network_intf_id) as PON port Index for the flow_id resource |
| 1122 | # pool. Also, there is no ONU Id available for trapping LLDP packets |
| 1123 | # on NNI port, use onu_id as -1 (invalid) |
| 1124 | # ****************** CAVEAT ******************* |
| 1125 | # This logic works if the NNI Port Id falls within the same valid |
| 1126 | # range of PON Port Ids. If this doesn't work for some OLT Vendor |
| 1127 | # we need to have a re-look at this. |
| 1128 | # ********************************************* |
| 1129 | onu_id = -1 |
| 1130 | uni_id = -1 |
| 1131 | flow_store_cookie = self._get_flow_store_cookie(classifier) |
| 1132 | |
| 1133 | if self.resource_mgr.is_flow_cookie_on_kv_store( |
| 1134 | network_intf_id, onu_id, uni_id, flow_store_cookie): |
| 1135 | self.log.debug('flow-exists--not-re-adding') |
| 1136 | else: |
| 1137 | flow_id = self.resource_mgr.get_flow_id( |
| 1138 | network_intf_id, onu_id, uni_id, |
| 1139 | flow_store_cookie=flow_store_cookie) |
| 1140 | |
| 1141 | downstream_flow = openolt_pb2.Flow( |
| 1142 | access_intf_id=-1, # access_intf_id not required |
| 1143 | onu_id=onu_id, # onu_id not required |
| 1144 | uni_id=uni_id, # uni_id not used |
| 1145 | flow_id=flow_id, |
| 1146 | flow_type=DOWNSTREAM, |
| 1147 | network_intf_id=network_intf_id, |
| 1148 | gemport_id=-1, # gemport_id not required |
| 1149 | classifier=self.mk_classifier(classifier), |
| 1150 | action=self.mk_action(action), |
| 1151 | priority=logical_flow.priority, |
| 1152 | port_no=port_no, |
| 1153 | cookie=logical_flow.cookie) |
| 1154 | |
| 1155 | self.log.debug('add dhcp downstream trap', classifier=classifier, |
| 1156 | action=action, flow=downstream_flow, |
| 1157 | port_no=port_no) |
| 1158 | if self.add_flow_to_device(downstream_flow, logical_flow): |
| 1159 | flow_info = self._get_flow_info_as_json_blob(downstream_flow, |
| 1160 | flow_store_cookie) |
| 1161 | self.update_flow_info_to_kv_store( |
| 1162 | network_intf_id, onu_id, uni_id, flow_id, flow_info) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1163 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 1164 | 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] | 1165 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1166 | classifier = dict() |
Shad Ansari | fd0111d | 2018-09-13 21:33:06 +0000 | [diff] [blame] | 1167 | classifier[ETH_TYPE] = LLDP_ETH_TYPE |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 1168 | classifier[PACKET_TAG_TYPE] = UNTAGGED |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1169 | action = dict() |
Shad Ansari | fd0111d | 2018-09-13 21:33:06 +0000 | [diff] [blame] | 1170 | action[TRAP_TO_HOST] = True |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame] | 1171 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1172 | # LLDP flow is installed to trap LLDP packets on the NNI port. |
| 1173 | # We manage flow_id resource pool on per PON port basis. |
| 1174 | # Since this situation is tricky, as a hack, we pass the NNI port |
| 1175 | # index (network_intf_id) as PON port Index for the flow_id resource |
| 1176 | # pool. Also, there is no ONU Id available for trapping LLDP packets |
| 1177 | # on NNI port, use onu_id as -1 (invalid) |
| 1178 | # ****************** CAVEAT ******************* |
| 1179 | # This logic works if the NNI Port Id falls within the same valid |
| 1180 | # range of PON Port Ids. If this doesn't work for some OLT Vendor |
| 1181 | # we need to have a re-look at this. |
| 1182 | # ********************************************* |
| 1183 | onu_id = -1 |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 1184 | uni_id = -1 |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 1185 | flow_store_cookie = self._get_flow_store_cookie(classifier) |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame] | 1186 | |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 1187 | if self.resource_mgr.is_flow_cookie_on_kv_store( |
| 1188 | network_intf_id, onu_id, uni_id, flow_store_cookie): |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 1189 | self.log.debug('flow-exists--not-re-adding') |
| 1190 | else: |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 1191 | flow_id = self.resource_mgr.get_flow_id( |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 1192 | network_intf_id, onu_id, uni_id, flow_store_cookie=flow_store_cookie) |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame] | 1193 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 1194 | downstream_flow = openolt_pb2.Flow( |
| 1195 | access_intf_id=-1, # access_intf_id not required |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 1196 | onu_id=onu_id, # onu_id not required |
| 1197 | uni_id=uni_id, # uni_id not used |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 1198 | flow_id=flow_id, |
| 1199 | flow_type=DOWNSTREAM, |
| 1200 | network_intf_id=network_intf_id, |
| 1201 | gemport_id=-1, # gemport_id not required |
| 1202 | classifier=self.mk_classifier(classifier), |
| 1203 | action=self.mk_action(action), |
| 1204 | priority=logical_flow.priority, |
| 1205 | port_no=port_no, |
| 1206 | cookie=logical_flow.cookie) |
| 1207 | |
| 1208 | self.log.debug('add lldp downstream trap', classifier=classifier, |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 1209 | action=action, flow=downstream_flow, |
| 1210 | port_no=port_no) |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 1211 | if self.add_flow_to_device(downstream_flow, logical_flow): |
| 1212 | flow_info = self._get_flow_info_as_json_blob(downstream_flow, |
| 1213 | flow_store_cookie) |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 1214 | self.update_flow_info_to_kv_store( |
| 1215 | network_intf_id, onu_id, uni_id, flow_id, flow_info) |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame] | 1216 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 1217 | @staticmethod |
| 1218 | def mk_classifier(classifier_info): |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 1219 | |
| 1220 | classifier = openolt_pb2.Classifier() |
| 1221 | |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 1222 | if ETH_TYPE in classifier_info: |
| 1223 | classifier.eth_type = classifier_info[ETH_TYPE] |
| 1224 | if IP_PROTO in classifier_info: |
| 1225 | classifier.ip_proto = classifier_info[IP_PROTO] |
Thiyagarajan Subramani | 3b62d6c | 2019-02-15 08:48:01 -0800 | [diff] [blame] | 1226 | if VLAN_VID in classifier_info and \ |
| 1227 | classifier_info[VLAN_VID] != RESERVED_VLAN: |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 1228 | classifier.o_vid = classifier_info[VLAN_VID] |
Thiyagarajan Subramani | 3b62d6c | 2019-02-15 08:48:01 -0800 | [diff] [blame] | 1229 | if METADATA in classifier_info and \ |
| 1230 | classifier_info[METADATA] != RESERVED_VLAN: |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 1231 | classifier.i_vid = classifier_info[METADATA] |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 1232 | if VLAN_PCP in classifier_info: |
| 1233 | classifier.o_pbits = classifier_info[VLAN_PCP] |
| 1234 | if UDP_SRC in classifier_info: |
| 1235 | classifier.src_port = classifier_info[UDP_SRC] |
| 1236 | if UDP_DST in classifier_info: |
| 1237 | classifier.dst_port = classifier_info[UDP_DST] |
| 1238 | if IPV4_DST in classifier_info: |
| 1239 | classifier.dst_ip = classifier_info[IPV4_DST] |
| 1240 | if IPV4_SRC in classifier_info: |
| 1241 | classifier.src_ip = classifier_info[IPV4_SRC] |
| 1242 | if PACKET_TAG_TYPE in classifier_info: |
| 1243 | if classifier_info[PACKET_TAG_TYPE] == SINGLE_TAG: |
| 1244 | classifier.pkt_tag_type = SINGLE_TAG |
| 1245 | elif classifier_info[PACKET_TAG_TYPE] == DOUBLE_TAG: |
| 1246 | classifier.pkt_tag_type = DOUBLE_TAG |
| 1247 | elif classifier_info[PACKET_TAG_TYPE] == UNTAGGED: |
| 1248 | classifier.pkt_tag_type = UNTAGGED |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 1249 | else: |
| 1250 | classifier.pkt_tag_type = 'none' |
| 1251 | |
| 1252 | return classifier |
| 1253 | |
| 1254 | def mk_action(self, action_info): |
| 1255 | action = openolt_pb2.Action() |
| 1256 | |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 1257 | if POP_VLAN in action_info: |
| 1258 | action.o_vid = action_info[VLAN_VID] |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 1259 | action.cmd.remove_outer_tag = True |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 1260 | elif PUSH_VLAN in action_info: |
| 1261 | action.o_vid = action_info[VLAN_VID] |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 1262 | action.cmd.add_outer_tag = True |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 1263 | if VLAN_PCP in action_info: |
| 1264 | action.o_pbits = action_info[VLAN_PCP] |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 1265 | elif TRAP_TO_HOST in action_info: |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 1266 | action.cmd.trap_to_host = True |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 1267 | else: |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 1268 | self.log.info('Invalid-action-field', action_info=action_info) |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 1269 | return |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 1270 | return action |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 1271 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 1272 | def is_eap_enabled(self, intf_id, onu_id, uni_id): |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 1273 | flows = self.logical_flows_proxy.get('/').items |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 1274 | |
| 1275 | for flow in flows: |
| 1276 | eap_flow = False |
| 1277 | eap_intf_id = None |
| 1278 | eap_onu_id = None |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 1279 | eap_uni_id = None |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 1280 | for field in fd.get_ofb_fields(flow): |
| 1281 | if field.type == fd.ETH_TYPE: |
| 1282 | if field.eth_type == EAP_ETH_TYPE: |
| 1283 | eap_flow = True |
| 1284 | if field.type == fd.IN_PORT: |
Shad Ansari | cd20a6d | 2018-10-02 14:36:33 +0000 | [diff] [blame] | 1285 | eap_intf_id = self.platform.intf_id_from_uni_port_num( |
Shad Ansari | 47e0c39 | 2018-07-17 23:55:07 +0000 | [diff] [blame] | 1286 | field.port) |
Shad Ansari | cd20a6d | 2018-10-02 14:36:33 +0000 | [diff] [blame] | 1287 | eap_onu_id = self.platform.onu_id_from_port_num(field.port) |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 1288 | eap_uni_id = self.platform.uni_id_from_port_num(field.port) |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 1289 | |
| 1290 | if eap_flow: |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 1291 | self.log.debug('eap flow detected', onu_id=onu_id, |
| 1292 | uni_id=uni_id, intf_id=intf_id, |
| 1293 | eap_intf_id=eap_intf_id, eap_onu_id=eap_onu_id, |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 1294 | eap_uni_id=eap_uni_id) |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 1295 | if eap_flow and intf_id == eap_intf_id \ |
| 1296 | and onu_id == eap_onu_id and uni_id == eap_uni_id: |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1297 | return True, flow |
Nicolas Palpacuer | 6181516 | 2018-06-20 18:12:04 -0400 | [diff] [blame] | 1298 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1299 | return False, None |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 1300 | |
Nicolas Palpacuer | 4114135 | 2018-08-31 14:11:38 -0400 | [diff] [blame] | 1301 | def get_subscriber_vlan(self, port): |
| 1302 | self.log.debug('looking from subscriber flow for port', port=port) |
| 1303 | |
| 1304 | flows = self.logical_flows_proxy.get('/').items |
| 1305 | for flow in flows: |
| 1306 | in_port = fd.get_in_port(flow) |
| 1307 | out_port = fd.get_out_port(flow) |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 1308 | if in_port == port and out_port is not None and \ |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1309 | self.platform.intf_id_to_port_type_name(out_port) \ |
Shad Ansari | fd0111d | 2018-09-13 21:33:06 +0000 | [diff] [blame] | 1310 | == Port.ETHERNET_NNI: |
Nicolas Palpacuer | 4114135 | 2018-08-31 14:11:38 -0400 | [diff] [blame] | 1311 | fields = fd.get_ofb_fields(flow) |
| 1312 | self.log.debug('subscriber flow found', fields=fields) |
| 1313 | for field in fields: |
| 1314 | if field.type == OFPXMT_OFB_VLAN_VID: |
| 1315 | self.log.debug('subscriber vlan found', |
| 1316 | vlan_id=field.vlan_vid) |
| 1317 | return field.vlan_vid & 0x0fff |
| 1318 | self.log.debug('No subscriber flow found', port=port) |
| 1319 | return None |
| 1320 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 1321 | def add_flow_to_device(self, flow, logical_flow): |
| 1322 | self.log.debug('pushing flow to device', flow=flow) |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 1323 | try: |
| 1324 | self.stub.FlowAdd(flow) |
| 1325 | except grpc.RpcError as grpc_e: |
| 1326 | if grpc_e.code() == grpc.StatusCode.ALREADY_EXISTS: |
| 1327 | self.log.warn('flow already exists', e=grpc_e, flow=flow) |
| 1328 | else: |
| 1329 | self.log.error('failed to add flow', |
| 1330 | logical_flow=logical_flow, flow=flow, |
| 1331 | grpc_error=grpc_e) |
Girish Gowdru | 58b1d38 | 2019-05-08 23:35:39 -0700 | [diff] [blame] | 1332 | # If the flow addition failed on the device, immediately |
| 1333 | # free up the flow_id resource from the pool |
| 1334 | intf_id = flow.access_intf_id if flow.access_intf_id > 0 else flow.network_intf_id |
| 1335 | onu_id = flow.onu_id |
| 1336 | uni_id = flow.uni_id |
| 1337 | flow_id = flow.flow_id |
| 1338 | self.resource_mgr.free_flow_id(intf_id, onu_id, uni_id, flow_id) |
| 1339 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1340 | return False |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 1341 | else: |
| 1342 | self.register_flow(logical_flow, flow) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1343 | return True |
| 1344 | |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 1345 | def update_flow_info_to_kv_store(self, intf_id, onu_id, uni_id, flow_id, |
| 1346 | flow): |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 1347 | self.resource_mgr.update_flow_id_info(intf_id, onu_id, uni_id, |
| 1348 | flow_id, flow) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 1349 | |
| 1350 | def register_flow(self, logical_flow, device_flow): |
| 1351 | self.log.debug('registering flow in device', |
| 1352 | logical_flow=logical_flow, device_flow=device_flow) |
| 1353 | stored_flow = copy.deepcopy(logical_flow) |
| 1354 | stored_flow.id = self.generate_stored_id(device_flow.flow_id, |
| 1355 | device_flow.flow_type) |
| 1356 | self.log.debug('generated device flow id', id=stored_flow.id, |
| 1357 | flow_id=device_flow.flow_id, |
| 1358 | direction=device_flow.flow_type) |
| 1359 | stored_flow.cookie = logical_flow.id |
| 1360 | flows = self.flows_proxy.get('/') |
| 1361 | flows.items.extend([stored_flow]) |
| 1362 | self.flows_proxy.update('/', flows) |
| 1363 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 1364 | def find_next_flow(self, flow, metadata): |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 1365 | table_id = fd.get_goto_table_id(flow) |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 1366 | # Prior to ONOS 1.13.5, Metadata contained the UNI output port number. |
| 1367 | # In 1.13.5 and later, the lower 32-bits is the output port number and |
| 1368 | # the # upper 32-bits is the inner-vid we are looking for. Use just the |
| 1369 | # lower 32 # bits. Allows this code to work with pre- and post-1.13.5 |
| 1370 | # ONOS OltPipeline |
Chip Boling | 41f795a | 2018-10-04 15:45:34 -0500 | [diff] [blame] | 1371 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 1372 | port = metadata & 0xFFFFFFFF |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 1373 | if table_id is None: |
| 1374 | return None |
| 1375 | flows = self.logical_flows_proxy.get('/').items |
| 1376 | next_flows = [] |
| 1377 | for f in flows: |
| 1378 | if f.table_id == table_id: |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame] | 1379 | # FIXME |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 1380 | if fd.get_in_port(f) == fd.get_in_port(flow) and \ |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 1381 | fd.get_out_port(f) == port: |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 1382 | next_flows.append(f) |
| 1383 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 1384 | if len(next_flows) == 0: |
| 1385 | self.log.warning('no next flow found, it may be a timing issue', |
| 1386 | flow=flow, number_of_flows=len(flows)) |
Scott Baker | be5a9ea | 2018-11-19 19:24:21 -0800 | [diff] [blame] | 1387 | if flow.id in self.retry_add_flow_list: |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 1388 | self.log.debug('flow is already in retry list', |
| 1389 | flow_id=flow.id) |
Scott Baker | be5a9ea | 2018-11-19 19:24:21 -0800 | [diff] [blame] | 1390 | else: |
| 1391 | self.retry_add_flow_list.append(flow.id) |
| 1392 | reactor.callLater(5, self.retry_add_flow, flow) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 1393 | return None |
| 1394 | |
Jonathan Hart | 5b43564 | 2018-08-20 08:50:05 -0700 | [diff] [blame] | 1395 | next_flows.sort(key=lambda f: f.priority, reverse=True) |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 1396 | |
| 1397 | return next_flows[0] |
| 1398 | |
| 1399 | def update_children_flows(self, device_rules_map): |
| 1400 | |
| 1401 | for device_id, (flows, groups) in device_rules_map.iteritems(): |
| 1402 | if device_id != self.device_id: |
| 1403 | self.root_proxy.update('/devices/{}/flows'.format(device_id), |
| 1404 | Flows(items=flows.values())) |
| 1405 | self.root_proxy.update('/devices/{}/flow_groups'.format( |
| 1406 | device_id), FlowGroups(items=groups.values())) |
| 1407 | |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 1408 | def clear_flows_and_scheduler_for_logical_port(self, child_device, |
| 1409 | logical_port): |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1410 | ofp_port_name = logical_port.ofp_port.name |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 1411 | port_no = logical_port.ofp_port.port_no |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1412 | pon_port = child_device.proxy_address.channel_id |
| 1413 | onu_id = child_device.proxy_address.onu_id |
Thiyagarajan Subramani | 353af12 | 2019-02-20 23:14:24 -0800 | [diff] [blame] | 1414 | uni_id = self.platform.uni_id_from_port_num(port_no) |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 1415 | |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 1416 | tp_id = self.resource_mgr.get_tech_profile_id_for_onu(pon_port, onu_id, |
| 1417 | uni_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1418 | tech_profile_instance = self.tech_profile[pon_port]. \ |
| 1419 | get_tech_profile_instance( |
Thiyagarajan Subramani | 353af12 | 2019-02-20 23:14:24 -0800 | [diff] [blame] | 1420 | tp_id, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1421 | ofp_port_name) |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 1422 | flow_ids = self.resource_mgr.get_current_flow_ids(pon_port, onu_id, |
| 1423 | uni_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1424 | self.log.debug("outstanding-flows-to-be-cleared", flow_ids=flow_ids) |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 1425 | if flow_ids: |
| 1426 | for flow_id in flow_ids: |
| 1427 | flow_infos = self.resource_mgr.get_flow_id_info(pon_port, onu_id, |
| 1428 | uni_id, flow_id) |
| 1429 | for flow_info in flow_infos: |
| 1430 | direction = flow_info['flow_type'] |
| 1431 | flow_to_remove = openolt_pb2.Flow(flow_id=flow_id, |
| 1432 | flow_type=direction) |
| 1433 | try: |
| 1434 | self.stub.FlowRemove(flow_to_remove) |
| 1435 | except grpc.RpcError as grpc_e: |
| 1436 | if grpc_e.code() == grpc.StatusCode.NOT_FOUND: |
| 1437 | self.log.debug('This flow does not exist on switch, ' |
| 1438 | 'normal after an OLT reboot', |
| 1439 | flow=flow_to_remove) |
| 1440 | else: |
| 1441 | raise grpc_e |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1442 | |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 1443 | self.remove_us_scheduler_queues(pon_port, onu_id, uni_id, tech_profile_instance) |
| 1444 | self.remove_ds_scheduler_queues(pon_port, onu_id, uni_id, tech_profile_instance) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1445 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 1446 | def generate_stored_id(self, flow_id, direction): |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 1447 | if direction == UPSTREAM: |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 1448 | self.log.debug('upstream flow, shifting id') |
| 1449 | return 0x1 << 15 | flow_id |
Nicolas Palpacuer | 2789f04 | 2018-09-17 09:10:29 -0400 | [diff] [blame] | 1450 | elif direction == DOWNSTREAM: |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 1451 | self.log.debug('downstream flow, not shifting id') |
| 1452 | return flow_id |
| 1453 | else: |
| 1454 | self.log.warn('Unrecognized direction', direction=direction) |
| 1455 | return flow_id |
| 1456 | |
| 1457 | def decode_stored_id(self, id): |
| 1458 | if id >> 15 == 0x1: |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1459 | return id & 0x7fff, UPSTREAM |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 1460 | else: |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1461 | return id, DOWNSTREAM |
| 1462 | |
| 1463 | def _populate_tech_profile_per_pon_port(self): |
| 1464 | for arange in self.resource_mgr.device_info.ranges: |
| 1465 | for intf_id in arange.intf_ids: |
| 1466 | self.tech_profile[intf_id] = \ |
| 1467 | self.resource_mgr.resource_mgrs[intf_id].tech_profile |
| 1468 | |
| 1469 | # Make sure we have as many tech_profiles as there are pon ports on |
| 1470 | # the device |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 1471 | assert len(self.tech_profile) \ |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 1472 | == self.resource_mgr.device_info.pon_ports |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1473 | |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 1474 | def _get_flow_info_as_json_blob(self, flow, flow_store_cookie, |
| 1475 | flow_category=None): |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1476 | json_blob = MessageToDict(message=flow, |
| 1477 | preserving_proto_field_name=True) |
| 1478 | self.log.debug("flow-info", json_blob=json_blob) |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 1479 | json_blob['flow_store_cookie'] = flow_store_cookie |
| 1480 | if flow_category is not None: |
| 1481 | json_blob['flow_category'] = flow_category |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 1482 | |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 1483 | # For flows which trap out of the NNI, the access_intf_id is invalid |
| 1484 | # (set to -1). In such cases, we need to refer to the network_intf_id. |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 1485 | if flow.access_intf_id != -1: |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 1486 | flow_info = self.resource_mgr.get_flow_id_info( |
| 1487 | flow.access_intf_id, flow.onu_id, flow.uni_id, flow.flow_id) |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 1488 | else: |
Shad Ansari | 7a5d217 | 2019-02-26 13:35:36 -0800 | [diff] [blame] | 1489 | # Case of LLDP trap flow from the NNI. We can't use |
| 1490 | # flow.access_intf_id in that case, as it is invalid. |
| 1491 | # We use flow.network_intf_id. |
| 1492 | flow_info = self.resource_mgr.get_flow_id_info( |
| 1493 | flow.network_intf_id, flow.onu_id, flow.uni_id, flow.flow_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 1494 | |
| 1495 | if flow_info is None: |
| 1496 | flow_info = list() |
| 1497 | flow_info.append(json_blob) |
| 1498 | else: |
| 1499 | assert (isinstance(flow_info, list)) |
| 1500 | flow_info.append(json_blob) |
| 1501 | |
| 1502 | return flow_info |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 1503 | |
| 1504 | @staticmethod |
| 1505 | def _get_flow_store_cookie(classifier, gem_port=None): |
| 1506 | assert isinstance(classifier, dict) |
| 1507 | # We need unique flows per gem_port |
| 1508 | if gem_port is not None: |
| 1509 | to_hash = dumps(classifier, sort_keys=True) + str(gem_port) |
| 1510 | else: |
| 1511 | to_hash = dumps(classifier, sort_keys=True) |
| 1512 | return hashlib.md5(to_hash).hexdigest()[:12] |
Girish Gowdru | 841708f | 2019-02-08 04:29:48 -0800 | [diff] [blame] | 1513 | |
| 1514 | @staticmethod |
| 1515 | def _get_gem_port_for_pcp(pcp, get_gem_port_for_pcp): |
| 1516 | """ |
| 1517 | Return gem_port id corresponding to a given pcp bit |
| 1518 | |
| 1519 | :param pcp: Represents the p_bit |
| 1520 | :param get_gem_port_for_pcp: Represents a list of gemport_attributes (DS or US) |
| 1521 | :return: Gemport ID servicing the given pcp if found, else None |
| 1522 | """ |
| 1523 | for gem_port_attr in get_gem_port_for_pcp: |
| 1524 | # The pbit_map appears as "0b00011010" in the Tech-Profile instance. |
| 1525 | # The initial '0b' has to be stripped. |
| 1526 | # The remaining string is reversed, then enumerated and matched against pcp index. |
| 1527 | for i, p in enumerate(reversed(gem_port_attr.pbit_map[2:])): |
| 1528 | if i == pcp and p == '1': |
| 1529 | return gem_port_attr.gemport_id |
| 1530 | return None |
| 1531 | |
| 1532 | @staticmethod |
| 1533 | def _install_flow_on_all_gemports(func, kwargs, gem_attr_list): |
| 1534 | for gem_attr in gem_attr_list: |
| 1535 | # The pbit_map appears as "0b00011010" in the Tech-Profile instance. |
| 1536 | # The initial '0b' has to be stripped. |
| 1537 | # The remaining string is reversed, then enumerated and matched against pbit 1. |
| 1538 | for i, p in enumerate(reversed(gem_attr.pbit_map[2:])): |
| 1539 | if p == '1': |
| 1540 | kwargs['classifier'][VLAN_PCP] = i |
| 1541 | # Add the gemport corresponding to this PCP |
| 1542 | kwargs['gemport_id'] = gem_attr.gemport_id |
| 1543 | func(**kwargs) |
| 1544 | |