blob: 524997ae505c7233a09be0803030f2427fb25e26 [file] [log] [blame]
Abhilash S.L7f17e402019-03-15 17:40:41 +05301/*
2 * Copyright 2019-present Open Networking Foundation
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
manikkaraj kbf256be2019-03-25 00:13:48 +053017package resourcemanager
Abhilash S.L7f17e402019-03-15 17:40:41 +053018
19import (
Girish Gowdru0c588b22019-04-23 23:24:56 -040020 "encoding/json"
21 "errors"
22 "fmt"
23 "strconv"
24 "strings"
Abhilash S.L7f17e402019-03-15 17:40:41 +053025
Girish Gowdru0c588b22019-04-23 23:24:56 -040026 "github.com/opencord/voltha-go/common/log"
27 ponrmgr "github.com/opencord/voltha-go/common/ponresourcemanager"
28 "github.com/opencord/voltha-go/db/kvstore"
29 "github.com/opencord/voltha-go/db/model"
30 "github.com/opencord/voltha-protos/go/openolt"
Abhilash S.L7f17e402019-03-15 17:40:41 +053031)
32
manikkaraj kbf256be2019-03-25 00:13:48 +053033const KVSTORE_TIMEOUT = 5
Abhilash S.L7f17e402019-03-15 17:40:41 +053034const BASE_PATH_KV_STORE = "service/voltha/openolt/{%s}" // service/voltha/openolt/<device_id>
35
Abhilash S.L8ee90712019-04-29 16:24:22 +053036type FlowInfo struct {
37 Flow *openolt.Flow
38 FlowStoreCookie uint64
39 FlowCategory string
40}
Abhilash S.L7f17e402019-03-15 17:40:41 +053041type OpenOltResourceMgr struct {
Girish Gowdru0c588b22019-04-23 23:24:56 -040042 DeviceID string //OLT device id
43 HostAndPort string // Host and port of the kv store to connect to
44 Args string // args
45 KVStore *model.Backend // backend kv store connection handle
46 DeviceType string
47 Host string // Host ip of the kv store
48 Port int // port of the kv store
49 DevInfo *openolt.DeviceInfo // device information
50 // array of pon resource managers per interface technology
51 ResourceMgrs map[uint32]*ponrmgr.PONResourceManager
Abhilash S.L7f17e402019-03-15 17:40:41 +053052}
53
54func newKVClient(storeType string, address string, timeout uint32) (kvstore.Client, error) {
Girish Gowdru0c588b22019-04-23 23:24:56 -040055 log.Infow("kv-store-type", log.Fields{"store": storeType})
56 switch storeType {
57 case "consul":
58 return kvstore.NewConsulClient(address, int(timeout))
59 case "etcd":
60 return kvstore.NewEtcdClient(address, int(timeout))
61 }
62 return nil, errors.New("unsupported-kv-store")
Abhilash S.L7f17e402019-03-15 17:40:41 +053063}
64
65func SetKVClient(Backend string, Host string, Port int, DeviceID string) *model.Backend {
Girish Gowdru0c588b22019-04-23 23:24:56 -040066 addr := Host + ":" + strconv.Itoa(Port)
67 // TODO : Make sure direct call to NewBackend is working fine with backend , currently there is some
68 // issue between kv store and backend , core is not calling NewBackend directly
69 kvClient, err := newKVClient(Backend, addr, KVSTORE_TIMEOUT)
70 if err != nil {
71 log.Fatalw("Failed to init KV client\n", log.Fields{"err": err})
72 return nil
73 }
74 kvbackend := &model.Backend{
75 Client: kvClient,
76 StoreType: Backend,
77 Host: Host,
78 Port: Port,
79 Timeout: KVSTORE_TIMEOUT,
80 PathPrefix: fmt.Sprintf(BASE_PATH_KV_STORE, DeviceID)}
Abhilash S.L7f17e402019-03-15 17:40:41 +053081
Girish Gowdru0c588b22019-04-23 23:24:56 -040082 return kvbackend
Abhilash S.L7f17e402019-03-15 17:40:41 +053083}
84
Abhilash S.L8ee90712019-04-29 16:24:22 +053085func NewResourceMgr(DeviceID string, KVStoreHostPort string, KVStoreType string, DeviceType string, DevInfo *openolt.DeviceInfo) *OpenOltResourceMgr {
Abhilash S.L7f17e402019-03-15 17:40:41 +053086
Girish Gowdru0c588b22019-04-23 23:24:56 -040087 /* init a New resource maanger instance which in turn instantiates pon resource manager
88 instances according to technology. Initializes the default resource ranges for all
89 the reources.
90 */
91 var ResourceMgr OpenOltResourceMgr
Abhilash S.L8ee90712019-04-29 16:24:22 +053092 log.Debugf("Init new resource manager , host_port: %s, deviceid: %s", KVStoreHostPort, DeviceID)
93 ResourceMgr.HostAndPort = KVStoreHostPort
Girish Gowdru0c588b22019-04-23 23:24:56 -040094 ResourceMgr.DeviceType = DeviceType
95 ResourceMgr.DevInfo = DevInfo
Abhilash S.L8ee90712019-04-29 16:24:22 +053096 IpPort := strings.Split(KVStoreHostPort, ":")
Girish Gowdru0c588b22019-04-23 23:24:56 -040097 ResourceMgr.Host = IpPort[0]
98 ResourceMgr.Port, _ = strconv.Atoi(IpPort[1])
Abhilash S.L7f17e402019-03-15 17:40:41 +053099
Abhilash S.L8ee90712019-04-29 16:24:22 +0530100 Backend := KVStoreType
Girish Gowdru0c588b22019-04-23 23:24:56 -0400101 ResourceMgr.KVStore = SetKVClient(Backend, ResourceMgr.Host,
102 ResourceMgr.Port, DeviceID)
103 if ResourceMgr.KVStore == nil {
104 log.Error("Failed to setup KV store")
105 }
106 Ranges := make(map[string]*openolt.DeviceInfo_DeviceResourceRanges)
107 RsrcMgrsByTech := make(map[string]*ponrmgr.PONResourceManager)
108 ResourceMgr.ResourceMgrs = make(map[uint32]*ponrmgr.PONResourceManager)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530109
Girish Gowdru0c588b22019-04-23 23:24:56 -0400110 // TODO self.args = registry('main').get_args()
Abhilash S.L7f17e402019-03-15 17:40:41 +0530111
Girish Gowdru0c588b22019-04-23 23:24:56 -0400112 /*
113 If a legacy driver returns protobuf without any ranges,s synthesize one from
114 the legacy global per-device informaiton. This, in theory, is temporary until
115 the legacy drivers are upgrade to support pool ranges.
116 */
117 if DevInfo.Ranges == nil {
118 var ranges openolt.DeviceInfo_DeviceResourceRanges
119 ranges.Technology = DevInfo.GetTechnology()
Abhilash S.L7f17e402019-03-15 17:40:41 +0530120
Girish Gowdru0c588b22019-04-23 23:24:56 -0400121 NumPONPorts := DevInfo.GetPonPorts()
122 var index uint32
123 for index = 0; index < NumPONPorts; index++ {
124 ranges.IntfIds = append(ranges.IntfIds, index)
125 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530126
Abhilash S.L8ee90712019-04-29 16:24:22 +0530127 var Pool openolt.DeviceInfo_DeviceResourceRanges_Pool
Girish Gowdru0c588b22019-04-23 23:24:56 -0400128 Pool.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_ONU_ID
129 Pool.Start = DevInfo.OnuIdStart
130 Pool.End = DevInfo.OnuIdEnd
131 Pool.Sharing = openolt.DeviceInfo_DeviceResourceRanges_Pool_DEDICATED_PER_INTF
Abhilash S.L8ee90712019-04-29 16:24:22 +0530132 ranges.Pools = append(ranges.Pools, &Pool)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530133
Girish Gowdru0c588b22019-04-23 23:24:56 -0400134 Pool.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_ALLOC_ID
135 Pool.Start = DevInfo.AllocIdStart
136 Pool.End = DevInfo.AllocIdEnd
137 Pool.Sharing = openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH
Abhilash S.L8ee90712019-04-29 16:24:22 +0530138 ranges.Pools = append(ranges.Pools, &Pool)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530139
Girish Gowdru0c588b22019-04-23 23:24:56 -0400140 Pool.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_GEMPORT_ID
141 Pool.Start = DevInfo.GemportIdStart
142 Pool.End = DevInfo.GemportIdEnd
143 Pool.Sharing = openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH
Abhilash S.L8ee90712019-04-29 16:24:22 +0530144 ranges.Pools = append(ranges.Pools, &Pool)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530145
Girish Gowdru0c588b22019-04-23 23:24:56 -0400146 Pool.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_FLOW_ID
147 Pool.Start = DevInfo.FlowIdStart
148 Pool.End = DevInfo.FlowIdEnd
149 Pool.Sharing = openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH
Abhilash S.L8ee90712019-04-29 16:24:22 +0530150 ranges.Pools = append(ranges.Pools, &Pool)
151 // Add to device info
152 DevInfo.Ranges = append(DevInfo.Ranges, &ranges)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400153 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530154
Girish Gowdru0c588b22019-04-23 23:24:56 -0400155 //Create a separate Resource Manager instance for each range. This assumes that
156 // each technology is represented by only a single range
157 var GlobalPONRsrcMgr *ponrmgr.PONResourceManager
158 var err error
159 for _, TechRange := range DevInfo.Ranges {
160 technology := TechRange.Technology
161 log.Debugf("Device info technology %s", technology)
162 Ranges[technology] = TechRange
163 RsrcMgrsByTech[technology], err = ponrmgr.NewPONResourceManager(technology, DeviceType, DeviceID,
164 Backend, ResourceMgr.Host, ResourceMgr.Port)
165 if err != nil {
166 log.Errorf("Failed to create pon resource manager instacnce for technology %s", technology)
167 return nil
168 }
169 //resource_mgrs_by_tech[technology] = resource_mgr
170 if GlobalPONRsrcMgr == nil {
171 GlobalPONRsrcMgr = RsrcMgrsByTech[technology]
172 }
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400173 for _, IntfId := range TechRange.IntfIds {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400174 ResourceMgr.ResourceMgrs[uint32(IntfId)] = RsrcMgrsByTech[technology]
175 }
176 //self.initialize_device_resource_range_and_pool(resource_mgr, global_resource_mgr, arange)
177 InitializeDeviceResourceRangeAndPool(RsrcMgrsByTech[technology], GlobalPONRsrcMgr,
178 TechRange, DevInfo)
179 }
180 // After we have initialized resource ranges, initialize the
181 // resource pools accordingly.
182 for _, PONRMgr := range RsrcMgrsByTech {
183 PONRMgr.InitDeviceResourcePool()
184 }
Abhilash S.L8ee90712019-04-29 16:24:22 +0530185 log.Info("Initialization of resource manager success!")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400186 return &ResourceMgr
Abhilash S.L7f17e402019-03-15 17:40:41 +0530187}
188
189func InitializeDeviceResourceRangeAndPool(PONRMgr *ponrmgr.PONResourceManager, GlobalPONRMgr *ponrmgr.PONResourceManager,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400190 TechRange *openolt.DeviceInfo_DeviceResourceRanges, DevInfo *openolt.DeviceInfo) {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530191
Girish Gowdru0c588b22019-04-23 23:24:56 -0400192 // init the resource range pool according to the sharing type
Abhilash S.L7f17e402019-03-15 17:40:41 +0530193
Girish Gowdru0c588b22019-04-23 23:24:56 -0400194 log.Debugf("Resource range pool init for technology %s", PONRMgr.Technology)
195 //first load from KV profiles
196 status := PONRMgr.InitResourceRangesFromKVStore()
197 if status == false {
198 log.Debugf("Failed to load resource ranges from KV store for tech %s", PONRMgr.Technology)
199 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530200
Girish Gowdru0c588b22019-04-23 23:24:56 -0400201 /*
202 Then apply device specific information. If KV doesn't exist
203 or is broader than the device, the device's informationw ill
204 dictate the range limits
205 */
206 log.Debugf("Using device info to init pon resource ranges for tech", PONRMgr.Technology)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530207
Girish Gowdru0c588b22019-04-23 23:24:56 -0400208 ONUIDStart := DevInfo.OnuIdStart
209 ONUIDEnd := DevInfo.OnuIdEnd
210 ONUIDShared := openolt.DeviceInfo_DeviceResourceRanges_Pool_DEDICATED_PER_INTF
211 ONUIDSharedPoolID := uint32(0)
212 AllocIDStart := DevInfo.AllocIdStart
213 AllocIDEnd := DevInfo.AllocIdEnd
214 AllocIDShared := openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH // TODO EdgeCore/BAL limitation
215 AllocIDSharedPoolID := uint32(0)
216 GEMPortIDStart := DevInfo.GemportIdStart
217 GEMPortIDEnd := DevInfo.GemportIdEnd
218 GEMPortIDShared := openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH // TODO EdgeCore/BAL limitation
219 GEMPortIDSharedPoolID := uint32(0)
220 FlowIDStart := DevInfo.FlowIdStart
221 FlowIDEnd := DevInfo.FlowIdEnd
222 FlowIDShared := openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH // TODO EdgeCore/BAL limitation
223 FlowIDSharedPoolID := uint32(0)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530224
Girish Gowdru0c588b22019-04-23 23:24:56 -0400225 var FirstIntfPoolID uint32
226 var SharedPoolID uint32
Abhilash S.L7f17e402019-03-15 17:40:41 +0530227
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400228 /*
229 * As a zero check is made against SharedPoolID to check whether the resources are shared across all intfs
230 * if resources are shared accross interfaces then SharedPoolID is given a positive number.
231 */
Girish Gowdru0c588b22019-04-23 23:24:56 -0400232 for _, FirstIntfPoolID = range TechRange.IntfIds {
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400233 // skip the intf id 0
234 if FirstIntfPoolID == 0 {
235 continue
236 }
Girish Gowdru0c588b22019-04-23 23:24:56 -0400237 break
238 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530239
Girish Gowdru0c588b22019-04-23 23:24:56 -0400240 for _, RangePool := range TechRange.Pools {
241 if RangePool.Sharing == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH {
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400242 SharedPoolID = FirstIntfPoolID
Girish Gowdru0c588b22019-04-23 23:24:56 -0400243 } else if RangePool.Sharing == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_SAME_TECH {
244 SharedPoolID = FirstIntfPoolID
245 } else {
246 SharedPoolID = 0
247 }
248 if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_ONU_ID {
249 ONUIDStart = RangePool.Start
250 ONUIDEnd = RangePool.End
251 ONUIDShared = RangePool.Sharing
252 ONUIDSharedPoolID = SharedPoolID
253 } else if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_ALLOC_ID {
254 AllocIDStart = RangePool.Start
255 AllocIDEnd = RangePool.End
256 AllocIDShared = RangePool.Sharing
257 AllocIDSharedPoolID = SharedPoolID
258 } else if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_GEMPORT_ID {
259 GEMPortIDStart = RangePool.Start
260 GEMPortIDEnd = RangePool.End
261 GEMPortIDShared = RangePool.Sharing
262 GEMPortIDSharedPoolID = SharedPoolID
263 } else if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_FLOW_ID {
264 FlowIDStart = RangePool.Start
265 FlowIDEnd = RangePool.End
266 FlowIDShared = RangePool.Sharing
267 FlowIDSharedPoolID = SharedPoolID
268 }
269 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530270
Girish Gowdru0c588b22019-04-23 23:24:56 -0400271 log.Debugw("Device info init", log.Fields{"technology": TechRange.Technology,
272 "onu_id_start": ONUIDStart, "onu_id_end": ONUIDEnd, "onu_id_shared_pool_id": ONUIDSharedPoolID,
273 "alloc_id_start": AllocIDStart, "alloc_id_end": AllocIDEnd,
274 "alloc_id_shared_pool_id": AllocIDSharedPoolID,
275 "gemport_id_start": GEMPortIDStart, "gemport_id_end": GEMPortIDEnd,
276 "gemport_id_shared_pool_id": GEMPortIDSharedPoolID,
277 "flow_id_start": FlowIDStart,
278 "flow_id_end_idx": FlowIDEnd,
279 "flow_id_shared_pool_id": FlowIDSharedPoolID,
280 "intf_ids": TechRange.IntfIds,
281 "uni_id_start": 0,
282 "uni_id_end_idx":/*MaxUNIIDperONU()*/ 1})
Abhilash S.L7f17e402019-03-15 17:40:41 +0530283
Girish Gowdru0c588b22019-04-23 23:24:56 -0400284 PONRMgr.InitDefaultPONResourceRanges(ONUIDStart, ONUIDEnd, ONUIDSharedPoolID,
285 AllocIDStart, AllocIDEnd, AllocIDSharedPoolID,
286 GEMPortIDStart, GEMPortIDEnd, GEMPortIDSharedPoolID,
287 FlowIDStart, FlowIDEnd, FlowIDSharedPoolID, 0, 1,
288 DevInfo.PonPorts, TechRange.IntfIds)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530289
Girish Gowdru0c588b22019-04-23 23:24:56 -0400290 // For global sharing, make sure to refresh both local and global resource manager instances' range
Abhilash S.L7f17e402019-03-15 17:40:41 +0530291
Girish Gowdru0c588b22019-04-23 23:24:56 -0400292 if ONUIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH {
293 GlobalPONRMgr.UpdateRanges(ponrmgr.ONU_ID_START_IDX, ONUIDStart, ponrmgr.ONU_ID_END_IDX, ONUIDEnd,
294 "", 0, nil)
295 PONRMgr.UpdateRanges(ponrmgr.ONU_ID_START_IDX, ONUIDStart, ponrmgr.ONU_ID_END_IDX, ONUIDEnd,
296 "", 0, GlobalPONRMgr)
297 }
298 if AllocIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH {
299 GlobalPONRMgr.UpdateRanges(ponrmgr.ALLOC_ID_START_IDX, AllocIDStart, ponrmgr.ALLOC_ID_END_IDX, AllocIDEnd,
300 "", 0, nil)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530301
Girish Gowdru0c588b22019-04-23 23:24:56 -0400302 PONRMgr.UpdateRanges(ponrmgr.ALLOC_ID_START_IDX, AllocIDStart, ponrmgr.ALLOC_ID_END_IDX, AllocIDEnd,
303 "", 0, GlobalPONRMgr)
304 }
305 if GEMPortIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH {
306 GlobalPONRMgr.UpdateRanges(ponrmgr.GEMPORT_ID_START_IDX, GEMPortIDStart, ponrmgr.GEMPORT_ID_END_IDX, GEMPortIDEnd,
307 "", 0, nil)
308 PONRMgr.UpdateRanges(ponrmgr.GEMPORT_ID_START_IDX, GEMPortIDStart, ponrmgr.GEMPORT_ID_END_IDX, GEMPortIDEnd,
309 "", 0, GlobalPONRMgr)
310 }
311 if FlowIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH {
312 GlobalPONRMgr.UpdateRanges(ponrmgr.FLOW_ID_START_IDX, FlowIDStart, ponrmgr.FLOW_ID_END_IDX, FlowIDEnd,
313 "", 0, nil)
314 PONRMgr.UpdateRanges(ponrmgr.FLOW_ID_START_IDX, FlowIDStart, ponrmgr.FLOW_ID_END_IDX, FlowIDEnd,
315 "", 0, GlobalPONRMgr)
316 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530317
Girish Gowdru0c588b22019-04-23 23:24:56 -0400318 // Make sure loaded range fits the platform bit encoding ranges
319 PONRMgr.UpdateRanges(ponrmgr.UNI_ID_START_IDX, 0, ponrmgr.UNI_ID_END_IDX /* TODO =OpenOltPlatform.MAX_UNIS_PER_ONU-1*/, 1, "", 0, nil)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530320}
321
322/* TODO
323def __del__(self):
324 self.log.info("clearing-device-resource-pool")
325 for key, resource_mgr in self.resource_mgrs.iteritems():
326 resource_mgr.clear_device_resource_pool()
327
328 def assert_pon_id_limit(self, pon_intf_id):
329 assert pon_intf_id in self.resource_mgrs
330
331 def assert_onu_id_limit(self, pon_intf_id, onu_id):
332 self.assert_pon_id_limit(pon_intf_id)
333 self.resource_mgrs[pon_intf_id].assert_resource_limits(onu_id, PONResourceManager.ONU_ID)
334
335 @property
336 def max_uni_id_per_onu(self):
337 return 0 #OpenOltPlatform.MAX_UNIS_PER_ONU-1, zero-based indexing Uncomment or override to make default multi-uni
338
339 def assert_uni_id_limit(self, pon_intf_id, onu_id, uni_id):
340 self.assert_onu_id_limit(pon_intf_id, onu_id)
341 self.resource_mgrs[pon_intf_id].assert_resource_limits(uni_id, PONResourceManager.UNI_ID)
342*/
343
344func (RsrcMgr *OpenOltResourceMgr) GetONUID(PONIntfID uint32) (uint32, error) {
345
Girish Gowdru0c588b22019-04-23 23:24:56 -0400346 // Get ONU id for a provided pon interface ID.
Abhilash S.L7f17e402019-03-15 17:40:41 +0530347
Girish Gowdru0c588b22019-04-23 23:24:56 -0400348 ONUID, err := RsrcMgr.ResourceMgrs[PONIntfID].GetResourceID(PONIntfID,
349 ponrmgr.ONU_ID, 1)
350 if err != nil {
351 log.Errorf("Failed to get resource for interface %d for type %s",
352 PONIntfID, ponrmgr.ONU_ID)
353 return ONUID[0], err
354 }
355 if ONUID != nil {
356 RsrcMgr.ResourceMgrs[PONIntfID].InitResourceMap(fmt.Sprintf("%d,%d", PONIntfID, ONUID))
357 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530358
Girish Gowdru0c588b22019-04-23 23:24:56 -0400359 return ONUID[0], err
Abhilash S.L7f17e402019-03-15 17:40:41 +0530360}
361
Abhilash S.L8ee90712019-04-29 16:24:22 +0530362func (RsrcMgr *OpenOltResourceMgr) GetFlowIDInfo(PONIntfID uint32, ONUID uint32, UNIID uint32, FlowID uint32) *[]FlowInfo {
363
364 /*
365 Note: For flows which trap from the NNI and not really associated with any particular
366 ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id.
367 */
368 var flows []FlowInfo
369
370 FlowPath := fmt.Sprintf("%d,%d,%d", PONIntfID, ONUID, UNIID)
371 if err := RsrcMgr.ResourceMgrs[PONIntfID].GetFlowIDInfo(FlowPath, FlowID, &flows); err != nil {
372 log.Errorw("Error while getting flows from KV store", log.Fields{"flowId": FlowID})
373 return nil
374 }
375 if len(flows) == 0 {
376 log.Debugw("No flowInfo found in KV store", log.Fields{"flowPath": FlowPath})
377 return nil
378 }
379 return &flows
380}
381
382func (RsrcMgr *OpenOltResourceMgr) GetCurrentFlowIDsForOnu(PONIntfID uint32, ONUID uint32, UNIID uint32) []uint32 {
383 /*
384 Note: For flows which trap from the NNI and not really associated with any particular
385 ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id.
386 */
387 FlowPath := fmt.Sprintf("%d,%d,%d", PONIntfID, ONUID, UNIID)
388 return RsrcMgr.ResourceMgrs[PONIntfID].GetCurrentFlowIDsForOnu(FlowPath)
389}
390
391func (RsrcMgr *OpenOltResourceMgr) UpdateFlowIDInfo(PONIntfID int32, ONUID int32, UNIID int32,
392 FlowID uint32, FlowData *[]FlowInfo) error {
393
394 /*
395 Note: For flows which trap from the NNI and not really associated with any particular
396 ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id.
397 */
398 FlowPath := fmt.Sprintf("%d,%d,%d", PONIntfID, ONUID, UNIID)
399 return RsrcMgr.ResourceMgrs[uint32(PONIntfID)].UpdateFlowIDInfoForOnu(FlowPath, FlowID, *FlowData)
400}
401
Abhilash S.L7f17e402019-03-15 17:40:41 +0530402func (RsrcMgr *OpenOltResourceMgr) GetFlowID(PONIntfID uint32, ONUID uint32, UNIID uint32,
Abhilash S.L8ee90712019-04-29 16:24:22 +0530403 FlowStoreCookie uint64,
404 FlowCategory string) (uint32, error) {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530405
Girish Gowdru0c588b22019-04-23 23:24:56 -0400406 // Get flow ID for a given pon interface id, onu id and uni id.
Abhilash S.L7f17e402019-03-15 17:40:41 +0530407
Girish Gowdru0c588b22019-04-23 23:24:56 -0400408 var err error
409 FlowPath := fmt.Sprintf("%d,%d,%d", PONIntfID, ONUID, UNIID)
410 FlowIDs := RsrcMgr.ResourceMgrs[PONIntfID].GetCurrentFlowIDsForOnu(FlowPath)
411 if FlowIDs != nil {
Abhilash S.L8ee90712019-04-29 16:24:22 +0530412 log.Debugw("Found flowId(s) for this ONU", log.Fields{"pon": PONIntfID, "ONUID": ONUID, "UNIID": UNIID, "KVpath": FlowPath})
413 for _, flowId := range FlowIDs {
414 FlowInfo := RsrcMgr.GetFlowIDInfo(PONIntfID, ONUID, UNIID, uint32(flowId))
415 if FlowInfo != nil {
Abhilash S.L8ee90712019-04-29 16:24:22 +0530416 for _, Info := range *FlowInfo {
417 if FlowCategory != "" && Info.FlowCategory == FlowCategory {
418 log.Debug("Found flow matching with flow catagory", log.Fields{"flowId": flowId, "FlowCategory": FlowCategory})
419 return flowId, nil
420 }
421 if FlowStoreCookie != 0 && Info.FlowStoreCookie == FlowStoreCookie {
422 log.Debug("Found flow matching with flowStore cookie", log.Fields{"flowId": flowId, "FlowStoreCookie": FlowStoreCookie})
423 return flowId, nil
424 }
425 }
426 }
427 }
Girish Gowdru0c588b22019-04-23 23:24:56 -0400428 }
Abhilash S.L8ee90712019-04-29 16:24:22 +0530429 log.Debug("No matching flows with flow cookie or flow category, allocating new flowid")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400430 FlowIDs, err = RsrcMgr.ResourceMgrs[PONIntfID].GetResourceID(PONIntfID,
431 ponrmgr.FLOW_ID, 1)
432 if err != nil {
433 log.Errorf("Failed to get resource for interface %d for type %s",
434 PONIntfID, ponrmgr.FLOW_ID)
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400435 return uint32(0), err
Girish Gowdru0c588b22019-04-23 23:24:56 -0400436 }
437 if FlowIDs != nil {
438 RsrcMgr.ResourceMgrs[PONIntfID].UpdateFlowIDForOnu(FlowPath, FlowIDs[0], true)
439 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530440
Girish Gowdru0c588b22019-04-23 23:24:56 -0400441 return FlowIDs[0], err
Abhilash S.L7f17e402019-03-15 17:40:41 +0530442}
443
Abhilash S.L8ee90712019-04-29 16:24:22 +0530444func (RsrcMgr *OpenOltResourceMgr) GetAllocID(IntfID uint32, ONUID uint32, UNIID uint32) uint32 {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530445
Girish Gowdru0c588b22019-04-23 23:24:56 -0400446 // Get alloc id for a given pon interface id and onu id.
447 var err error
Abhilash S.L8ee90712019-04-29 16:24:22 +0530448 IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", IntfID, ONUID, UNIID)
449 AllocID := RsrcMgr.ResourceMgrs[IntfID].GetCurrentAllocIDForOnu(IntfOnuIDUniID)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400450 if AllocID != nil {
451 // Since we support only one alloc_id for the ONU at the moment,
452 // return the first alloc_id in the list, if available, for that
453 // ONU.
Abhilash S.L8ee90712019-04-29 16:24:22 +0530454 log.Debugw("Retrived alloc ID from pon resource mgr", log.Fields{"AllocID": AllocID})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400455 return AllocID[0]
456 }
457 AllocID, err = RsrcMgr.ResourceMgrs[IntfID].GetResourceID(IntfID,
458 ponrmgr.ALLOC_ID, 1)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530459
Girish Gowdru0c588b22019-04-23 23:24:56 -0400460 if AllocID == nil || err != nil {
461 log.Error("Failed to allocate alloc id")
462 return 0
463 }
464 // update the resource map on KV store with the list of alloc_id
465 // allocated for the pon_intf_onu_id tuple
Abhilash S.L8ee90712019-04-29 16:24:22 +0530466 err = RsrcMgr.ResourceMgrs[IntfID].UpdateAllocIdsForOnu(IntfOnuIDUniID, AllocID)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400467 if err != nil {
468 log.Error("Failed to update Alloc ID")
469 return 0
470 }
Abhilash S.L8ee90712019-04-29 16:24:22 +0530471 log.Debugw("Allocated new Tcont from pon resource mgr", log.Fields{"AllocID": AllocID})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400472 return AllocID[0]
Abhilash S.L7f17e402019-03-15 17:40:41 +0530473}
474
Abhilash S.L8ee90712019-04-29 16:24:22 +0530475func (RsrcMgr *OpenOltResourceMgr) UpdateAllocIdsForOnu(PONPort uint32, ONUID uint32, UNIID uint32, AllocID []uint32) error {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530476
Girish Gowdru0c588b22019-04-23 23:24:56 -0400477 /* update alloc ids in kv store for a given pon interface id,
478 onu id and uni id.
479 */
Abhilash S.L8ee90712019-04-29 16:24:22 +0530480 IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", PONPort, ONUID, UNIID)
481 return RsrcMgr.ResourceMgrs[PONPort].UpdateAllocIdsForOnu(IntfOnuIDUniID,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400482 AllocID)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530483}
484func (RsrcMgr *OpenOltResourceMgr) GetCurrentGEMPortIDsForOnu(IntfID uint32, ONUID uint32,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400485 UNIID uint32) []uint32 {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530486
Girish Gowdru0c588b22019-04-23 23:24:56 -0400487 /* Get gem ports for given pon interface , onu id and uni id. */
Abhilash S.L7f17e402019-03-15 17:40:41 +0530488
Abhilash S.L8ee90712019-04-29 16:24:22 +0530489 IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", IntfID, ONUID, UNIID)
490 return RsrcMgr.ResourceMgrs[IntfID].GetCurrentGEMPortIDsForOnu(IntfOnuIDUniID)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530491}
492
Abhilash S.L8ee90712019-04-29 16:24:22 +0530493func (RsrcMgr *OpenOltResourceMgr) GetCurrentAllocIDForOnu(IntfID uint32, ONUID uint32, UNIID uint32) uint32 {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530494
Girish Gowdru0c588b22019-04-23 23:24:56 -0400495 /* Get alloc ids for given pon interface and onu id. */
Abhilash S.L7f17e402019-03-15 17:40:41 +0530496
Abhilash S.L8ee90712019-04-29 16:24:22 +0530497 IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", IntfID, ONUID, UNIID)
498 AllocID := RsrcMgr.ResourceMgrs[IntfID].GetCurrentAllocIDForOnu(IntfOnuIDUniID)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400499 if AllocID != nil {
500 // Since we support only one alloc_id for the ONU at the moment,
501 // return the first alloc_id in the list, if available, for that
502 // ONU.
503 return AllocID[0]
504 }
505 return 0
Abhilash S.L7f17e402019-03-15 17:40:41 +0530506}
507
508func (RsrcMgr *OpenOltResourceMgr) UpdateGEMportsPonportToOnuMapOnKVStore(GEMPorts []uint32, PonPort uint32,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400509 ONUID uint32, UNIID uint32) error {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530510
Girish Gowdru0c588b22019-04-23 23:24:56 -0400511 /* Update onu and uni id associated with the gem port to the kv store. */
512 var IntfGEMPortPath string
513 Data := fmt.Sprintf("%d %d", ONUID, UNIID)
514 for _, GEM := range GEMPorts {
515 IntfGEMPortPath = fmt.Sprintf("%d,%d", PonPort, GEM)
516 Val, err := json.Marshal(Data)
517 if err != nil {
518 log.Error("failed to Marshal")
519 return err
520 }
521 // This information is used when packet_indication is received and
522 // we need to derive the ONU Id for which the packet arrived based
523 // on the pon_intf and gemport available in the packet_indication
524 if err = RsrcMgr.KVStore.Put(IntfGEMPortPath, Val); err != nil {
525 log.Errorf("Failed to update resource %s", IntfGEMPortPath)
526 return err
527 }
528 }
529 return nil
Abhilash S.L7f17e402019-03-15 17:40:41 +0530530}
531
Abhilash S.L8ee90712019-04-29 16:24:22 +0530532func (RsrcMgr *OpenOltResourceMgr) GetONUUNIfromPONPortGEMPort(PONPort uint32, GEMPort uint32) (err error, OnuID uint32, UniID uint32) {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530533
Abhilash S.L8ee90712019-04-29 16:24:22 +0530534 var ONUID uint32
535 var UNIID uint32
Girish Gowdru0c588b22019-04-23 23:24:56 -0400536 var Data string
Abhilash S.L8ee90712019-04-29 16:24:22 +0530537
538 /* get the onu and uni id for a given gem port and pon port */
539 IntfGEMPortPath := fmt.Sprintf("%d,%d", PONPort, GEMPort)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400540 Value, err := RsrcMgr.KVStore.Get(IntfGEMPortPath)
541 if err == nil {
542 if Value != nil {
543 Val, _ := kvstore.ToByte(Value.Value)
544 if err = json.Unmarshal(Val, &Data); err != nil {
545 log.Error("Failed to unmarshal")
Abhilash S.L8ee90712019-04-29 16:24:22 +0530546 return err, ONUID, UNIID
Girish Gowdru0c588b22019-04-23 23:24:56 -0400547 }
548 IDs := strings.Split(Data, " ")
Abhilash S.L8ee90712019-04-29 16:24:22 +0530549 for index, val := range IDs {
550 switch index {
551 case 0:
552 if intval, err := strconv.Atoi(val); err == nil {
553 ONUID = uint32(intval)
554 }
555 case 1:
556 if intval, err := strconv.Atoi(val); err == nil {
557 UNIID = uint32(intval)
558 }
559 }
Girish Gowdru0c588b22019-04-23 23:24:56 -0400560 }
561 }
562 }
Abhilash S.L8ee90712019-04-29 16:24:22 +0530563 return err, ONUID, UNIID
Abhilash S.L7f17e402019-03-15 17:40:41 +0530564}
565
566func (RsrcMgr *OpenOltResourceMgr) GetGEMPortID(PONPort uint32, ONUID uint32,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400567 UNIID uint32, NumOfPorts uint32) ([]uint32, error) {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530568
Girish Gowdru0c588b22019-04-23 23:24:56 -0400569 /* Get gem port id for a particular pon port, onu id
570 and uni id.
571 */
Abhilash S.L7f17e402019-03-15 17:40:41 +0530572
Girish Gowdru0c588b22019-04-23 23:24:56 -0400573 var err error
Abhilash S.L8ee90712019-04-29 16:24:22 +0530574 IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", PONPort, ONUID, UNIID)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530575
Abhilash S.L8ee90712019-04-29 16:24:22 +0530576 GEMPortList := RsrcMgr.ResourceMgrs[PONPort].GetCurrentGEMPortIDsForOnu(IntfOnuIDUniID)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400577 if GEMPortList != nil {
578 return GEMPortList, nil
579 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530580
Girish Gowdru0c588b22019-04-23 23:24:56 -0400581 GEMPortList, err = RsrcMgr.ResourceMgrs[PONPort].GetResourceID(PONPort,
582 ponrmgr.GEMPORT_ID, NumOfPorts)
583 if err != nil && GEMPortList == nil {
Abhilash S.L8ee90712019-04-29 16:24:22 +0530584 log.Errorf("Failed to get gem port id for %s", IntfOnuIDUniID)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400585 return nil, err
586 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530587
Girish Gowdru0c588b22019-04-23 23:24:56 -0400588 // update the resource map on KV store with the list of gemport_id
589 // allocated for the pon_intf_onu_id tuple
Abhilash S.L8ee90712019-04-29 16:24:22 +0530590 err = RsrcMgr.ResourceMgrs[PONPort].UpdateGEMPortIDsForOnu(IntfOnuIDUniID,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400591 GEMPortList)
592 if err != nil {
Abhilash S.L8ee90712019-04-29 16:24:22 +0530593 log.Errorf("Failed to update GEM ports to kv store for %s", IntfOnuIDUniID)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400594 return nil, err
595 }
596 RsrcMgr.UpdateGEMportsPonportToOnuMapOnKVStore(GEMPortList, PONPort,
597 ONUID, UNIID)
598 return GEMPortList, err
Abhilash S.L7f17e402019-03-15 17:40:41 +0530599}
600
601func (RsrcMgr *OpenOltResourceMgr) UpdateGEMPortIDsForOnu(PONPort uint32, ONUID uint32,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400602 UNIID uint32, GEMPortList []uint32) error {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530603
Girish Gowdru0c588b22019-04-23 23:24:56 -0400604 /* Update gemport ids on to kv store for a given pon port,
605 onu id and uni id.
606 */
Abhilash S.L8ee90712019-04-29 16:24:22 +0530607 IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", PONPort, ONUID, UNIID)
608 return RsrcMgr.ResourceMgrs[PONPort].UpdateGEMPortIDsForOnu(IntfOnuIDUniID,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400609 GEMPortList)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530610
611}
612func (RsrcMgr *OpenOltResourceMgr) FreeONUID(IntfID uint32, ONUID []uint32) {
613
Girish Gowdru0c588b22019-04-23 23:24:56 -0400614 /* Free onu id for a particular interface.*/
615 RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(IntfID, ponrmgr.ONU_ID, ONUID)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530616
Girish Gowdru0c588b22019-04-23 23:24:56 -0400617 var IntfONUID string
618 for _, onu := range ONUID {
619 IntfONUID = fmt.Sprintf("%d,%d", IntfID, onu)
620 RsrcMgr.ResourceMgrs[IntfID].RemoveResourceMap(IntfONUID)
621 }
622 return
Abhilash S.L7f17e402019-03-15 17:40:41 +0530623}
624
625func (RsrcMgr *OpenOltResourceMgr) FreeFlowID(IntfID uint32, ONUID uint32,
Manjunath Vanarajulu28c3e822019-05-16 11:14:28 -0400626 UNIID uint32, FlowId uint32) {
627 var IntfONUID string
628 var err error
629 IntfONUID = fmt.Sprintf("%d,%d,%d", IntfID, ONUID, UNIID)
630 err = RsrcMgr.ResourceMgrs[IntfID].UpdateFlowIDForOnu(IntfONUID, FlowId, false)
631 if err != nil {
632 log.Error("Failed to Update flow id infor for %s", IntfONUID)
633 }
634 RsrcMgr.ResourceMgrs[IntfID].RemoveFlowIDInfo(IntfONUID, FlowId)
635}
636
637func (RsrcMgr *OpenOltResourceMgr) FreeFlowIDs(IntfID uint32, ONUID uint32,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400638 UNIID uint32, FlowID []uint32) {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530639
Girish Gowdru0c588b22019-04-23 23:24:56 -0400640 /* Free flow id for a given interface, onu id and uni id.*/
Abhilash S.L7f17e402019-03-15 17:40:41 +0530641
Girish Gowdru0c588b22019-04-23 23:24:56 -0400642 RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(IntfID, ponrmgr.FLOW_ID, FlowID)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530643
Abhilash S.L8ee90712019-04-29 16:24:22 +0530644 var IntfOnuIDUniID string
Girish Gowdru0c588b22019-04-23 23:24:56 -0400645 var err error
646 for _, flow := range FlowID {
Abhilash S.L8ee90712019-04-29 16:24:22 +0530647 IntfOnuIDUniID = fmt.Sprintf("%d,%d,%d", IntfID, ONUID, UNIID)
648 err = RsrcMgr.ResourceMgrs[IntfID].UpdateFlowIDForOnu(IntfOnuIDUniID, flow, false)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400649 if err != nil {
Abhilash S.L8ee90712019-04-29 16:24:22 +0530650 log.Error("Failed to Update flow id infor for %s", IntfOnuIDUniID)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400651 }
Abhilash S.L8ee90712019-04-29 16:24:22 +0530652 RsrcMgr.ResourceMgrs[IntfID].RemoveFlowIDInfo(IntfOnuIDUniID, flow)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400653 }
654 return
Abhilash S.L7f17e402019-03-15 17:40:41 +0530655}
656
Abhilash S.L8ee90712019-04-29 16:24:22 +0530657func (RsrcMgr *OpenOltResourceMgr) FreePONResourcesForONU(IntfID uint32, ONUID uint32, UNIID uint32) {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530658
Girish Gowdru0c588b22019-04-23 23:24:56 -0400659 /* Free pon resources for a given pon interface and onu id. */
Abhilash S.L7f17e402019-03-15 17:40:41 +0530660
Girish Gowdru0c588b22019-04-23 23:24:56 -0400661 var ONUIDs []uint32
662 ONUIDs = append(ONUIDs, ONUID)
Abhilash S.L8ee90712019-04-29 16:24:22 +0530663 IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", IntfID, ONUID, UNIID)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530664
Abhilash S.L8ee90712019-04-29 16:24:22 +0530665 AllocIDs := RsrcMgr.ResourceMgrs[IntfID].GetCurrentAllocIDForOnu(IntfOnuIDUniID)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530666
Girish Gowdru0c588b22019-04-23 23:24:56 -0400667 RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(IntfID,
668 ponrmgr.ALLOC_ID,
669 AllocIDs)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530670
Abhilash S.L8ee90712019-04-29 16:24:22 +0530671 GEMPortIDs := RsrcMgr.ResourceMgrs[IntfID].GetCurrentGEMPortIDsForOnu(IntfOnuIDUniID)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400672 RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(IntfID,
673 ponrmgr.GEMPORT_ID,
674 GEMPortIDs)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530675
Abhilash S.L8ee90712019-04-29 16:24:22 +0530676 FlowIDs := RsrcMgr.ResourceMgrs[IntfID].GetCurrentFlowIDsForOnu(IntfOnuIDUniID)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400677 RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(IntfID,
678 ponrmgr.FLOW_ID,
679 FlowIDs)
680 RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(IntfID,
681 ponrmgr.ONU_ID,
682 ONUIDs)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530683
Girish Gowdru0c588b22019-04-23 23:24:56 -0400684 // Clear resource map associated with (pon_intf_id, gemport_id) tuple.
Abhilash S.L8ee90712019-04-29 16:24:22 +0530685 RsrcMgr.ResourceMgrs[IntfID].RemoveResourceMap(IntfOnuIDUniID)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530686
Girish Gowdru0c588b22019-04-23 23:24:56 -0400687 // Clear the ONU Id associated with the (pon_intf_id, gemport_id) tuple.
688 for _, GEM := range GEMPortIDs {
689 RsrcMgr.KVStore.Delete(fmt.Sprintf("%d,%d", IntfID, GEM))
690 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530691}
692
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400693func (RsrcMgr *OpenOltResourceMgr) IsFlowCookieOnKVStore(PONIntfID uint32, ONUID uint32, UNIID uint32,
694 FlowStoreCookie uint64) bool {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530695
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400696 FlowPath := fmt.Sprintf("%d,%d,%d", PONIntfID, ONUID, UNIID)
697 FlowIDs := RsrcMgr.ResourceMgrs[PONIntfID].GetCurrentFlowIDsForOnu(FlowPath)
698 if FlowIDs != nil {
699 log.Debugw("Found flowId(s) for this ONU", log.Fields{"pon": PONIntfID, "ONUID": ONUID, "UNIID": UNIID, "KVpath": FlowPath})
700 for _, flowId := range FlowIDs {
701 FlowInfo := RsrcMgr.GetFlowIDInfo(PONIntfID, ONUID, UNIID, uint32(flowId))
702 if FlowInfo != nil {
703 log.Debugw("Found flows", log.Fields{"flows": *FlowInfo, "flowId": flowId})
704 for _, Info := range *FlowInfo {
705 if Info.FlowStoreCookie == FlowStoreCookie {
706 log.Debug("Found flow matching with flowStore cookie", log.Fields{"flowId": flowId, "FlowStoreCookie": FlowStoreCookie})
707 return true
708 }
709 }
710 }
711 }
712 }
713 return false
714}