Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [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 | # |
| 16 | |
| 17 | import structlog |
| 18 | |
| 19 | from common.pon_resource_manager.resource_manager import PONResourceManager |
| 20 | from voltha.registry import registry |
| 21 | from voltha.core.config.config_backend import ConsulStore |
| 22 | from voltha.core.config.config_backend import EtcdStore |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 23 | from voltha.adapters.openolt.openolt_flow_mgr import * |
| 24 | |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 25 | from voltha.adapters.openolt.protos import openolt_pb2 |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 26 | from voltha.adapters.openolt.openolt_platform import OpenOltPlatform |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 27 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 28 | |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 29 | class OpenOltResourceMgr(object): |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame^] | 30 | BASE_PATH_KV_STORE = "service/voltha/openolt/{}" # service/voltha/openolt/<device_id> |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 31 | |
| 32 | def __init__(self, device_id, host_and_port, extra_args, device_info): |
| 33 | self.log = structlog.get_logger(id=device_id, |
| 34 | ip=host_and_port) |
| 35 | self.device_id = device_id |
| 36 | self.host_and_port = host_and_port |
| 37 | self.extra_args = extra_args |
| 38 | self.device_info = device_info |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 39 | self.max_uni_id_per_onu = 0 #OpenOltPlatform.MAX_UNIS_PER_ONU, Uncomment or override to make default multi-uni |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 40 | self.args = registry('main').get_args() |
| 41 | |
| 42 | # KV store's IP Address and PORT |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 43 | if self.args.backend == 'etcd': |
| 44 | host, port = self.args.etcd.split(':', 1) |
| 45 | self.kv_store = EtcdStore(host, port, |
| 46 | OpenOltResourceMgr.BASE_PATH_KV_STORE.format(device_id)) |
| 47 | elif self.args.backend == 'consul': |
| 48 | host, port = self.args.consul.split(':', 1) |
| 49 | self.kv_store = ConsulStore(host, port, |
| 50 | OpenOltResourceMgr.BASE_PATH_KV_STORE.format(device_id)) |
| 51 | else: |
| 52 | self.log.error('Invalid-backend') |
| 53 | raise Exception("Invalid-backend-for-kv-store") |
| 54 | |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 55 | ranges = dict() |
| 56 | resource_mgrs_by_tech = dict() |
| 57 | self.resource_mgrs = dict() |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 58 | |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 59 | # If a legacy driver returns protobuf without any ranges,s synthesize one from |
| 60 | # the legacy global per-device informaiton. This, in theory, is temporary until |
| 61 | # the legacy drivers are upgrade to support pool ranges. |
| 62 | if len(self.device_info.ranges) == 0: |
| 63 | arange = self.device_info.ranges.add() |
| 64 | arange.technology = self.device_info.technology |
| 65 | arange.intf_ids.extend(range(0, device_info.pon_ports)) |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 66 | |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 67 | pool = arange.pools.add() |
| 68 | pool.type = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.ONU_ID |
| 69 | pool.start = self.device_info.onu_id_start |
| 70 | pool.end = self.device_info.onu_id_end |
| 71 | pool.sharing = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.DEDICATED_PER_INTF |
| 72 | |
| 73 | pool = arange.pools.add() |
| 74 | pool.type = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.ALLOC_ID |
| 75 | pool.start = self.device_info.alloc_id_start |
| 76 | pool.end = self.device_info.alloc_id_end |
| 77 | pool.sharing = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH |
| 78 | |
| 79 | pool = arange.pools.add() |
| 80 | pool.type = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.GEMPORT_ID |
| 81 | pool.start = self.device_info.gemport_id_start |
| 82 | pool.end = self.device_info.gemport_id_end |
| 83 | pool.sharing = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH |
| 84 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 85 | pool = arange.pools.add() |
| 86 | pool.type = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.FLOW_ID |
| 87 | pool.start = self.device_info.flow_id_start |
| 88 | pool.end = self.device_info.flow_id_end |
| 89 | pool.sharing = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH |
| 90 | |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 91 | # Create a separate Resource Manager instance for each range. This assumes that |
| 92 | # each technology is represented by only a single range |
| 93 | global_resource_mgr = None |
| 94 | for arange in self.device_info.ranges: |
| 95 | technology = arange.technology |
| 96 | self.log.info("device-info", technology=technology) |
| 97 | ranges[technology] = arange |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 98 | extra_args = self.extra_args + ' ' + PONResourceManager.OLT_MODEL_ARG + ' {}'.format(self.device_info.model) |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 99 | resource_mgr = PONResourceManager(technology, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 100 | extra_args, self.device_id, self.args.backend, host, port) |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 101 | resource_mgrs_by_tech[technology] = resource_mgr |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 102 | if global_resource_mgr is None: |
| 103 | global_resource_mgr = resource_mgr |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 104 | for intf_id in arange.intf_ids: |
| 105 | self.resource_mgrs[intf_id] = resource_mgrs_by_tech[technology] |
| 106 | self.initialize_device_resource_range_and_pool(resource_mgr, global_resource_mgr, arange) |
| 107 | |
| 108 | # After we have initialized resource ranges, initialize the |
| 109 | # resource pools accordingly. |
| 110 | for technology, resource_mgr in resource_mgrs_by_tech.iteritems(): |
| 111 | resource_mgr.init_device_resource_pool() |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 112 | |
| 113 | def __del__(self): |
| 114 | self.log.info("clearing-device-resource-pool") |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 115 | for key, resource_mgr in self.resource_mgrs.iteritems(): |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 116 | resource_mgr.clear_device_resource_pool() |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 117 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 118 | def assert_pon_id_limit(self, pon_intf_id): |
| 119 | assert pon_intf_id in self.resource_mgrs |
| 120 | |
| 121 | def assert_onu_id_limit(self, pon_intf_id, onu_id): |
| 122 | self.assert_pon_id_limit(pon_intf_id) |
| 123 | self.resource_mgrs[pon_intf_id].assert_resource_limits(onu_id, PONResourceManager.ONU_ID) |
| 124 | |
| 125 | def assert_uni_id_limit(self, pon_intf_id, onu_id, uni_id): |
| 126 | self.assert_onu_id_limit(pon_intf_id, onu_id) |
| 127 | self.resource_mgrs[pon_intf_id].assert_resource_limits(uni_id, PONResourceManager.UNI_ID) |
| 128 | |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 129 | def get_onu_id(self, pon_intf_id): |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 130 | onu_id = self.resource_mgrs[pon_intf_id].get_resource_id( |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 131 | pon_intf_id, PONResourceManager.ONU_ID, 1) |
| 132 | |
| 133 | if onu_id is not None: |
| 134 | pon_intf_onu_id = (pon_intf_id, onu_id) |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 135 | self.resource_mgrs[pon_intf_id].init_resource_map( |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 136 | pon_intf_onu_id) |
| 137 | |
| 138 | return onu_id |
| 139 | |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame^] | 140 | def get_flow_id(self, pon_intf_id, onu_id, uni_id, flow_store_cookie, |
| 141 | flow_category=None): |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 142 | pon_intf_onu_id = (pon_intf_id, onu_id, uni_id) |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame^] | 143 | try: |
| 144 | flow_ids = self.resource_mgrs[pon_intf_id]. \ |
| 145 | get_current_flow_ids_for_onu(pon_intf_onu_id) |
| 146 | if flow_ids is not None: |
| 147 | for flow_id in flow_ids: |
| 148 | flows = self.get_flow_id_info(pon_intf_id, onu_id, uni_id, flow_id) |
| 149 | assert (isinstance(flows, list)) |
| 150 | for flow in flows: |
| 151 | |
| 152 | if flow_category is not None and \ |
| 153 | 'flow_category' in flow and \ |
| 154 | flow['flow_category'] == flow_category: |
| 155 | return flow_id |
| 156 | if flow['flow_store_cookie'] == flow_store_cookie: |
| 157 | return flow_id |
| 158 | except Exception as e: |
| 159 | self.log.error("error-retrieving-flow-info", e=e) |
| 160 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 161 | flow_id = self.resource_mgrs[pon_intf_id].get_resource_id( |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame^] | 162 | pon_intf_onu_id[0], PONResourceManager.FLOW_ID) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 163 | if flow_id is not None: |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame^] | 164 | self.resource_mgrs[pon_intf_id].update_flow_id_for_onu( |
| 165 | pon_intf_onu_id, flow_id |
| 166 | ) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 167 | |
| 168 | return flow_id |
| 169 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 170 | def get_flow_id_info(self, pon_intf_id, onu_id, uni_id, flow_id): |
| 171 | pon_intf_onu_id = (pon_intf_id, onu_id, uni_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 172 | return self.resource_mgrs[pon_intf_id].get_flow_id_info(pon_intf_onu_id, flow_id) |
| 173 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 174 | def get_current_flow_ids_for_uni(self, pon_intf_id, onu_id, uni_id): |
| 175 | pon_intf_onu_id = (pon_intf_id, onu_id, uni_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 176 | return self.resource_mgrs[pon_intf_id].get_current_flow_ids_for_onu(pon_intf_onu_id) |
| 177 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 178 | def update_flow_id_info_for_uni(self, pon_intf_id, onu_id, uni_id, flow_id, flow_data): |
| 179 | pon_intf_onu_id = (pon_intf_id, onu_id, uni_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 180 | return self.resource_mgrs[pon_intf_id].update_flow_id_info_for_onu( |
| 181 | pon_intf_onu_id, flow_id, flow_data) |
| 182 | |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 183 | def get_alloc_id(self, pon_intf_onu_id): |
| 184 | # Derive the pon_intf from the pon_intf_onu_id tuple |
| 185 | pon_intf = pon_intf_onu_id[0] |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 186 | alloc_id_list = self.resource_mgrs[pon_intf].get_current_alloc_ids_for_onu( |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 187 | pon_intf_onu_id) |
| 188 | |
| 189 | if alloc_id_list and len(alloc_id_list) > 0: |
| 190 | # Since we support only one alloc_id for the ONU at the moment, |
| 191 | # return the first alloc_id in the list, if available, for that |
| 192 | # ONU. |
| 193 | return alloc_id_list[0] |
| 194 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 195 | alloc_id = self.resource_mgrs[pon_intf].get_resource_id( |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 196 | pon_intf_id=pon_intf, |
| 197 | resource_type=PONResourceManager.ALLOC_ID, |
| 198 | num_of_id=1 |
| 199 | ) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 200 | if alloc_id is None: |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 201 | self.log.error("no-alloc-id-available") |
| 202 | return None |
| 203 | |
| 204 | # update the resource map on KV store with the list of alloc_id |
| 205 | # allocated for the pon_intf_onu_id tuple |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 206 | self.resource_mgrs[pon_intf].update_alloc_ids_for_onu(pon_intf_onu_id, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 207 | list(alloc_id)) |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 208 | |
| 209 | return alloc_id |
| 210 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 211 | def get_current_gemport_ids_for_onu(self, pon_intf_onu_id): |
| 212 | pon_intf_id = pon_intf_onu_id[0] |
| 213 | return self.resource_mgrs[pon_intf_id].get_current_gemport_ids_for_onu(pon_intf_onu_id) |
| 214 | |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame^] | 215 | def get_current_alloc_ids_for_onu(self, pon_intf_onu_id): |
| 216 | pon_intf_id = pon_intf_onu_id[0] |
| 217 | alloc_ids = self.resource_mgrs[pon_intf_id].get_current_alloc_ids_for_onu(pon_intf_onu_id) |
| 218 | if alloc_ids is None: |
| 219 | return None |
| 220 | # We support only one tcont at the moment |
| 221 | return alloc_ids[0] |
| 222 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 223 | def update_gemports_ponport_to_onu_map_on_kv_store(self, gemport_list, pon_port, onu_id, uni_id): |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 224 | for gemport in gemport_list: |
| 225 | pon_intf_gemport = (pon_port, gemport) |
| 226 | # This information is used when packet_indication is received and |
| 227 | # we need to derive the ONU Id for which the packet arrived based |
| 228 | # on the pon_intf and gemport available in the packet_indication |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 229 | self.kv_store[str(pon_intf_gemport)] = ' '.join(map(str, (onu_id, uni_id))) |
| 230 | |
| 231 | def get_onu_uni_from_ponport_gemport(self, pon_port, gemport): |
| 232 | pon_intf_gemport = (pon_port, gemport) |
| 233 | return tuple(map(int, self.kv_store[str(pon_intf_gemport)].split(' '))) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 234 | |
| 235 | def get_gemport_id(self, pon_intf_onu_id, num_of_id=1): |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 236 | # Derive the pon_intf and onu_id from the pon_intf_onu_id tuple |
| 237 | pon_intf = pon_intf_onu_id[0] |
| 238 | onu_id = pon_intf_onu_id[1] |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 239 | uni_id = pon_intf_onu_id[2] |
| 240 | assert False, 'unused function' |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 241 | |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 242 | gemport_id_list = self.resource_mgrs[pon_intf].get_current_gemport_ids_for_onu( |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 243 | pon_intf_onu_id) |
| 244 | if gemport_id_list and len(gemport_id_list) > 0: |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 245 | return gemport_id_list |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 246 | |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 247 | gemport_id_list = self.resource_mgrs[pon_intf].get_resource_id( |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 248 | pon_intf_id=pon_intf, |
| 249 | resource_type=PONResourceManager.GEMPORT_ID, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 250 | num_of_id=num_of_id |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 251 | ) |
| 252 | |
| 253 | if gemport_id_list and len(gemport_id_list) == 0: |
| 254 | self.log.error("no-gemport-id-available") |
| 255 | return None |
| 256 | |
| 257 | # update the resource map on KV store with the list of gemport_id |
| 258 | # allocated for the pon_intf_onu_id tuple |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 259 | self.resource_mgrs[pon_intf].update_gemport_ids_for_onu(pon_intf_onu_id, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 260 | gemport_id_list) |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 261 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 262 | self.update_gemports_ponport_to_onu_map_on_kv_store(gemport_id_list, |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 263 | pon_intf, onu_id, uni_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 264 | return gemport_id_list |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 265 | |
| 266 | def free_onu_id(self, pon_intf_id, onu_id): |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 267 | _ = self.resource_mgrs[pon_intf_id].free_resource_id( |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 268 | pon_intf_id, PONResourceManager.ONU_ID, onu_id) |
| 269 | |
| 270 | pon_intf_onu_id = (pon_intf_id, onu_id) |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 271 | self.resource_mgrs[pon_intf_id].remove_resource_map( |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 272 | pon_intf_onu_id) |
| 273 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 274 | def free_flow_id_for_uni(self, pon_intf_id, onu_id, uni_id, flow_id): |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 275 | self.resource_mgrs[pon_intf_id].free_resource_id( |
| 276 | pon_intf_id, PONResourceManager.FLOW_ID, flow_id) |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 277 | pon_intf_onu_id = (pon_intf_id, onu_id, uni_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 278 | self.resource_mgrs[pon_intf_id].update_flow_id_for_onu(pon_intf_onu_id, |
| 279 | flow_id, False) |
| 280 | self.resource_mgrs[pon_intf_id].remove_flow_id_info(pon_intf_onu_id, |
| 281 | flow_id) |
| 282 | |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 283 | def free_pon_resources_for_onu(self, pon_intf_id_onu_id): |
| 284 | |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 285 | pon_intf_id = pon_intf_id_onu_id[0] |
| 286 | onu_id = pon_intf_id_onu_id[1] |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 287 | alloc_ids = \ |
| 288 | self.resource_mgrs[pon_intf_id].get_current_alloc_ids_for_onu(pon_intf_id_onu_id) |
| 289 | self.resource_mgrs[pon_intf_id].free_resource_id(pon_intf_id, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 290 | PONResourceManager.ALLOC_ID, |
| 291 | alloc_ids) |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 292 | |
| 293 | gemport_ids = \ |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 294 | self.resource_mgrs[pon_intf_id].get_current_gemport_ids_for_onu(pon_intf_id_onu_id) |
| 295 | self.resource_mgrs[pon_intf_id].free_resource_id(pon_intf_id, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 296 | PONResourceManager.GEMPORT_ID, |
| 297 | gemport_ids) |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 298 | |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame^] | 299 | flow_ids = \ |
| 300 | self.resource_mgrs[pon_intf_id].get_current_flow_ids_for_onu(pon_intf_id_onu_id) |
| 301 | self.resource_mgrs[pon_intf_id].free_resource_id(pon_intf_id, |
| 302 | PONResourceManager.FLOW_ID, |
| 303 | flow_ids) |
| 304 | |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 305 | self.resource_mgrs[pon_intf_id].free_resource_id(pon_intf_id, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 306 | PONResourceManager.ONU_ID, |
| 307 | onu_id) |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 308 | |
| 309 | # Clear resource map associated with (pon_intf_id, gemport_id) tuple. |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 310 | self.resource_mgrs[pon_intf_id].remove_resource_map(pon_intf_id_onu_id) |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 311 | |
| 312 | # Clear the ONU Id associated with the (pon_intf_id, gemport_id) tuple. |
| 313 | for gemport_id in gemport_ids: |
| 314 | del self.kv_store[str((pon_intf_id, gemport_id))] |
| 315 | |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 316 | def initialize_device_resource_range_and_pool(self, resource_mgr, global_resource_mgr, arange): |
| 317 | self.log.info("resource-range-pool-init", technology=resource_mgr.technology) |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 318 | |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 319 | # first load from KV profiles |
| 320 | status = resource_mgr.init_resource_ranges_from_kv_store() |
| 321 | if not status: |
| 322 | self.log.info("failed-to-load-resource-range-from-kv-store", technology=resource_mgr.technology) |
| 323 | |
| 324 | # Then apply device specific information. If KV doesn't exist |
| 325 | # or is broader than the device, the device's informationw ill |
| 326 | # dictate the range limits |
| 327 | self.log.info("using-device-info-to-init-pon-resource-ranges", technology=resource_mgr.technology) |
| 328 | |
| 329 | onu_id_start = self.device_info.onu_id_start |
| 330 | onu_id_end = self.device_info.onu_id_end |
| 331 | onu_id_shared = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.DEDICATED_PER_INTF |
| 332 | onu_id_shared_pool_id = None |
| 333 | alloc_id_start = self.device_info.alloc_id_start |
| 334 | alloc_id_end = self.device_info.alloc_id_end |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 335 | alloc_id_shared = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH # TODO EdgeCore/BAL limitation |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 336 | alloc_id_shared_pool_id = None |
| 337 | gemport_id_start = self.device_info.gemport_id_start |
| 338 | gemport_id_end = self.device_info.gemport_id_end |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 339 | gemport_id_shared = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH # TODO EdgeCore/BAL limitation |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 340 | gemport_id_shared_pool_id = None |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 341 | flow_id_start = self.device_info.flow_id_start |
| 342 | flow_id_end = self.device_info.flow_id_end |
| 343 | flow_id_shared = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH # TODO EdgeCore/BAL limitation |
| 344 | flow_id_shared_pool_id = None |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 345 | |
| 346 | global_pool_id = 0 |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 347 | for first_intf_pool_id in arange.intf_ids: |
| 348 | break |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 349 | |
| 350 | for pool in arange.pools: |
| 351 | shared_pool_id = global_pool_id if pool.sharing == openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH else \ |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 352 | first_intf_pool_id if pool.sharing == openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_SAME_TECH else \ |
| 353 | None |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 354 | |
| 355 | if pool.type == openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.ONU_ID: |
| 356 | onu_id_start = pool.start |
| 357 | onu_id_end = pool.end |
| 358 | onu_id_shared = pool.sharing |
| 359 | onu_id_shared_pool_id = shared_pool_id |
| 360 | elif pool.type == openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.ALLOC_ID: |
| 361 | alloc_id_start = pool.start |
| 362 | alloc_id_end = pool.end |
| 363 | alloc_id_shared = pool.sharing |
| 364 | alloc_id_shared_pool_id = shared_pool_id |
| 365 | elif pool.type == openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.GEMPORT_ID: |
| 366 | gemport_id_start = pool.start |
| 367 | gemport_id_end = pool.end |
| 368 | gemport_id_shared = pool.sharing |
| 369 | gemport_id_shared_pool_id = shared_pool_id |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 370 | elif pool.type == openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.FLOW_ID: |
| 371 | flow_id_start = pool.start |
| 372 | flow_id_end = pool.end |
| 373 | flow_id_shared = pool.sharing |
| 374 | flow_id_shared_pool_id = shared_pool_id |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 375 | |
| 376 | self.log.info("device-info-init", technology=arange.technology, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 377 | onu_id_start=onu_id_start, onu_id_end=onu_id_end, onu_id_shared_pool_id=onu_id_shared_pool_id, |
| 378 | alloc_id_start=alloc_id_start, alloc_id_end=alloc_id_end, |
| 379 | alloc_id_shared_pool_id=alloc_id_shared_pool_id, |
| 380 | gemport_id_start=gemport_id_start, gemport_id_end=gemport_id_end, |
| 381 | gemport_id_shared_pool_id=gemport_id_shared_pool_id, |
| 382 | flow_id_start_idx=flow_id_start, |
| 383 | flow_id_end_idx=flow_id_end, |
| 384 | flow_id_shared_pool_id=flow_id_shared_pool_id, |
| 385 | intf_ids=arange.intf_ids) |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 386 | |
| 387 | resource_mgr.init_default_pon_resource_ranges( |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 388 | onu_id_start_idx=onu_id_start, |
| 389 | onu_id_end_idx=onu_id_end, |
| 390 | onu_id_shared_pool_id=onu_id_shared_pool_id, |
| 391 | alloc_id_start_idx=alloc_id_start, |
| 392 | alloc_id_end_idx=alloc_id_end, |
| 393 | alloc_id_shared_pool_id=alloc_id_shared_pool_id, |
| 394 | gemport_id_start_idx=gemport_id_start, |
| 395 | gemport_id_end_idx=gemport_id_end, |
| 396 | gemport_id_shared_pool_id=gemport_id_shared_pool_id, |
| 397 | flow_id_start_idx=flow_id_start, |
| 398 | flow_id_end_idx=flow_id_end, |
| 399 | flow_id_shared_pool_id=flow_id_shared_pool_id, |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 400 | uni_id_start_idx=0, uni_id_end_idx=self.max_uni_id_per_onu, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 401 | num_of_pon_ports=self.device_info.pon_ports, |
| 402 | intf_ids=arange.intf_ids |
| 403 | ) |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 404 | |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 405 | # For global sharing, make sure to refresh both local and global resource manager instances' range |
| 406 | if global_resource_mgr is not self: |
| 407 | if onu_id_shared == openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH: |
| 408 | global_resource_mgr.update_ranges(onu_id_start_idx=onu_id_start, onu_id_end_idx=onu_id_end) |
| 409 | resource_mgr.update_ranges(onu_id_start_idx=onu_id_start, onu_id_end_idx=onu_id_end, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 410 | onu_id_shared_resource_mgr=global_resource_mgr) |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 411 | |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 412 | if alloc_id_shared == openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH: |
| 413 | global_resource_mgr.update_ranges(alloc_id_start_idx=alloc_id_start, alloc_id_end_idx=alloc_id_end) |
| 414 | resource_mgr.update_ranges(alloc_id_start_idx=alloc_id_start, alloc_id_end_idx=alloc_id_end, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 415 | alloc_id_shared_resource_mgr=global_resource_mgr) |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 416 | |
| 417 | if gemport_id_shared == openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH: |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 418 | global_resource_mgr.update_ranges(gemport_id_start_idx=gemport_id_start, |
| 419 | gemport_id_end_idx=gemport_id_end) |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 420 | resource_mgr.update_ranges(gemport_id_start_idx=gemport_id_start, gemport_id_end_idx=gemport_id_end, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 421 | gemport_id_shared_resource_mgr=global_resource_mgr) |
| 422 | |
| 423 | if flow_id_shared == openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH: |
| 424 | global_resource_mgr.update_ranges(flow_id_start_idx=flow_id_start, |
| 425 | flow_id_end_idx=flow_id_end) |
| 426 | resource_mgr.update_ranges(flow_id_start_idx=flow_id_start, flow_id_end_idx=flow_id_end, |
| 427 | flow_id_shared_resource_mgr=global_resource_mgr) |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 428 | |
| 429 | # Make sure loaded range fits the platform bit encoding ranges |
| 430 | resource_mgr.update_ranges(uni_id_start_idx=0, uni_id_end_idx=OpenOltPlatform.MAX_UNIS_PER_ONU-1) |