blob: 3fde9e064565bfb6316a385c5bd11eeaf989597a [file] [log] [blame]
Abhilash S.L7f17e402019-03-15 17:40:41 +05301/*
Joey Armstrong11f5a572024-01-12 19:11:32 -05002 * Copyright 2019-2024 Open Networking Foundation (ONF) and the ONF Contributors
Abhilash S.L7f17e402019-03-15 17:40:41 +05303
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
Joey Armstrong3f0e2422023-07-05 18:25:41 -040017// Package resourcemanager provides the utility for managing resources
manikkaraj kbf256be2019-03-25 00:13:48 +053018package resourcemanager
Abhilash S.L7f17e402019-03-15 17:40:41 +053019
20import (
npujarec5762e2020-01-01 14:08:48 +053021 "context"
Girish Gowdru0c588b22019-04-23 23:24:56 -040022 "encoding/json"
23 "errors"
24 "fmt"
Girish Gowdraa09aeab2020-09-14 16:30:52 -070025 "strings"
Girish Gowdra38d533d2020-03-30 20:38:51 -070026 "sync"
Neha Sharmacc656962020-04-14 14:26:11 +000027 "time"
Abhilash S.L7f17e402019-03-15 17:40:41 +053028
khenaidoo106c61a2021-08-11 18:05:46 -040029 tp "github.com/opencord/voltha-lib-go/v7/pkg/techprofile"
30
31 "github.com/opencord/voltha-lib-go/v7/pkg/db"
32 "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
33 "github.com/opencord/voltha-lib-go/v7/pkg/log"
34 ponrmgr "github.com/opencord/voltha-lib-go/v7/pkg/ponresourcemanager"
35 ofp "github.com/opencord/voltha-protos/v5/go/openflow_13"
36 "github.com/opencord/voltha-protos/v5/go/openolt"
Abhilash S.L7f17e402019-03-15 17:40:41 +053037)
38
salmansiddiqui7ac62132019-08-22 03:58:50 +000039const (
40 // KvstoreTimeout specifies the time out for KV Store Connection
Neha Sharmacc656962020-04-14 14:26:11 +000041 KvstoreTimeout = 5 * time.Second
Matteo Scandolodfa7a972020-11-06 13:03:40 -080042 // BasePathKvStore - <pathPrefix>/openolt/<device_id>
43 BasePathKvStore = "%s/openolt/{%s}"
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070044 // tpIDPathSuffix - <(pon_id, onu_id, uni_id)>/tp_id
45 tpIDPathSuffix = "{%d,%d,%d}/tp_id"
Gamze Abakafee36392019-10-03 11:17:24 +000046 //MeterIDPathSuffix - <(pon_id, onu_id, uni_id)>/<tp_id>/meter_id/<direction>
47 MeterIDPathSuffix = "{%d,%d,%d}/{%d}/meter_id/{%s}"
Girish Gowdra950326e2021-11-05 12:43:24 -070048
49 // OnuPacketInPathPrefix - path prefix where ONU packet-in vlanID/PCP is stored
Girish Gowdraa09aeab2020-09-14 16:30:52 -070050 //format: onu_packetin/{<intfid>,<onuid>,<logicalport>}
Girish Gowdra950326e2021-11-05 12:43:24 -070051 OnuPacketInPathPrefix = "onu_packetin/{%d,%d,%d}"
52 // OnuPacketInPath path on the kvstore to store packetin gemport,which will be used for packetin, packetout
Girish Gowdraa09aeab2020-09-14 16:30:52 -070053 //format: onu_packetin/{<intfid>,<onuid>,<logicalport>}/{<vlanId>,<priority>}
Girish Gowdra950326e2021-11-05 12:43:24 -070054 OnuPacketInPath = OnuPacketInPathPrefix + "/{%d,%d}"
55
56 //FlowIDsForGemPathPrefix format: flowids_for_gem/<intfid>
57 FlowIDsForGemPathPrefix = "flowids_per_gem/{%d}"
58 //FlowIDsForGem flowids_for_gem/<intfid>/<gemport-id>
59 FlowIDsForGem = FlowIDsForGemPathPrefix + "/{%d}"
60
Esin Karamanccb714b2019-11-29 15:02:06 +000061 //McastQueuesForIntf multicast queues for pon interfaces
62 McastQueuesForIntf = "mcast_qs_for_int"
63 //FlowGroup flow_groups/<flow_group_id>
64 // A group is stored under this path on the KV store after it has been installed to the device.
65 // It should also be deleted after it has been removed from the device accordingly.
66 FlowGroup = "flow_groups/{%d}"
67 //FlowGroupCached flow_groups_cached/<flow_group_id>
68 // When a group add request received, we create the group without setting any members to it since we cannot
69 // set any members to a group until it is associated with a multicast flow. It is a BAL limitation.
70 // When the related multicast flow has been created we perform set members operation for the group.
71 // That is why we need to keep the members of a group until the multicast flow creation request comes.
72 // We preserve the groups under "FlowGroupsCached" directory in the KV store temporarily. Having set members,
73 // we remove the group from the cached group store.
74 FlowGroupCached = "flow_groups_cached/{%d}"
Girish Gowdraa09aeab2020-09-14 16:30:52 -070075
76 //FlowIDPath - Path on the KV store for storing list of Flow IDs for a given subscriber
77 //Format: BasePathKvStore/<(pon_intf_id, onu_id, uni_id)>/flow_ids
78 FlowIDPath = "{%s}/flow_ids"
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070079
Girish Gowdra950326e2021-11-05 12:43:24 -070080 //OnuGemInfoPathPathPrefix format: onu_gem_info/<intfid>
81 OnuGemInfoPathPathPrefix = "onu_gem_info/{%d}"
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070082 //OnuGemInfoPath is path on the kvstore to store onugem info map
Girish Gowdra950326e2021-11-05 12:43:24 -070083 //format: onu_gem_info/<intfid>/<onu_id>
84 OnuGemInfoPath = OnuGemInfoPathPathPrefix + "/{%d}"
yasin saplid0566272021-12-21 09:10:30 +000085
86 // NNI uint32 version of -1 which represents the NNI port
87 NNI = 4294967295
salmansiddiqui7ac62132019-08-22 03:58:50 +000088)
Abhilash S.L7f17e402019-03-15 17:40:41 +053089
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070090// FlowInfo holds the flow information
Abhilash S.L8ee90712019-04-29 16:24:22 +053091type FlowInfo struct {
Girish Gowdraa09aeab2020-09-14 16:30:52 -070092 Flow *openolt.Flow
93 IsSymmtricFlow bool
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +053094}
95
96// OnuGemInfo holds onu information along with gem port list and uni port list
97type OnuGemInfo struct {
98 OnuID uint32
99 SerialNumber string
100 IntfID uint32
101 GemPorts []uint32
102 UniPorts []uint32
103}
104
105// PacketInInfoKey is the key for packet in gemport
106type PacketInInfoKey struct {
107 IntfID uint32
108 OnuID uint32
109 LogicalPort uint32
Esin Karaman7fb80c22020-07-16 14:23:33 +0000110 VlanID uint16
111 Priority uint8
Abhilash S.L8ee90712019-04-29 16:24:22 +0530112}
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700113
Esin Karamanccb714b2019-11-29 15:02:06 +0000114// GroupInfo holds group information
115type GroupInfo struct {
116 GroupID uint32
117 OutPorts []uint32
118}
119
Girish Gowdraa482f272021-03-24 23:04:19 -0700120// MeterInfo store meter information at path <(pon_id, onu_id, uni_id)>/<tp_id>/meter_id/<direction>
121type MeterInfo struct {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700122 RefCnt uint8 // number of flow references for this meter. When RefCnt is 0, the MeterInfo should be deleted.
123 MeterID uint32
Girish Gowdraa482f272021-03-24 23:04:19 -0700124}
125
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700126// OpenOltResourceMgr holds resource related information as provided below for each field
Abhilash S.L7f17e402019-03-15 17:40:41 +0530127type OpenOltResourceMgr struct {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700128 PonIntfID uint32
Neha Sharma3f221ae2020-04-29 19:02:12 +0000129 DeviceID string // OLT device id
130 Address string // Host and port of the kv store to connect to
131 Args string // args
132 KVStore *db.Backend // backend kv store connection handle
133 DeviceType string
134 DevInfo *openolt.DeviceInfo // device information
Girish Gowdru0c588b22019-04-23 23:24:56 -0400135 // array of pon resource managers per interface technology
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700136 PonRsrMgr *ponrmgr.PONResourceManager
Girish Gowdra38d533d2020-03-30 20:38:51 -0700137
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700138 // Local maps used for write-through-cache - start
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700139 allocIDsForOnu map[string][]uint32
140 allocIDsForOnuLock sync.RWMutex
141
142 gemPortIDsForOnu map[string][]uint32
143 gemPortIDsForOnuLock sync.RWMutex
144
145 techProfileIDsForOnu map[string][]uint32
146 techProfileIDsForOnuLock sync.RWMutex
147
148 meterInfoForOnu map[string]*MeterInfo
149 meterInfoForOnuLock sync.RWMutex
150
151 onuGemInfo map[string]*OnuGemInfo
152 onuGemInfoLock sync.RWMutex
153
154 gemPortForPacketInInfo map[string]uint32
155 gemPortForPacketInInfoLock sync.RWMutex
156
157 flowIDsForGem map[uint32][]uint64
158 flowIDsForGemLock sync.RWMutex
159
160 mcastQueueForIntf map[uint32][]uint32
161 mcastQueueForIntfLock sync.RWMutex
162 mcastQueueForIntfLoadedFromKvStore bool
163
164 groupInfo map[string]*GroupInfo
165 groupInfoLock sync.RWMutex
166 // Local maps used for write-through-cache - end
Girish Gowdra4c3d4602021-07-22 16:33:37 -0700167
Girish Gowdra76a1b092021-07-28 10:07:04 -0700168 TechprofileRef tp.TechProfileIf
Abhilash S.L7f17e402019-03-15 17:40:41 +0530169}
170
Neha Sharma96b7bf22020-06-15 10:37:32 +0000171func newKVClient(ctx context.Context, storeType string, address string, timeout time.Duration) (kvstore.Client, error) {
172 logger.Infow(ctx, "kv-store-type", log.Fields{"store": storeType})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400173 switch storeType {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400174 case "etcd":
Neha Sharma96b7bf22020-06-15 10:37:32 +0000175 return kvstore.NewEtcdClient(ctx, address, timeout, log.FatalLevel)
Abhay Kumar9bcfeb22024-07-12 09:14:25 +0530176 case "redis":
177 return kvstore.NewRedisClient(address, timeout, false)
178 case "redis-sentinel":
179 return kvstore.NewRedisClient(address, timeout, true)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400180 }
181 return nil, errors.New("unsupported-kv-store")
Abhilash S.L7f17e402019-03-15 17:40:41 +0530182}
183
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700184// SetKVClient sets the KV client and return a kv backend
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800185func SetKVClient(ctx context.Context, backend string, addr string, DeviceID string, basePathKvStore string) *db.Backend {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400186 // TODO : Make sure direct call to NewBackend is working fine with backend , currently there is some
187 // issue between kv store and backend , core is not calling NewBackend directly
Neha Sharma96b7bf22020-06-15 10:37:32 +0000188 kvClient, err := newKVClient(ctx, backend, addr, KvstoreTimeout)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400189 if err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000190 logger.Fatalw(ctx, "Failed to init KV client\n", log.Fields{"err": err})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400191 return nil
192 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700193 // return db.NewBackend(ctx, backend, addr, KvstoreTimeout, fmt.Sprintf(BasePathKvStore, basePathKvStore, DeviceID))
Matteo Scandolod625b4c2020-04-02 16:16:01 -0700194
sbarbaria8910ba2019-11-05 10:12:23 -0500195 kvbackend := &db.Backend{
Girish Gowdru0c588b22019-04-23 23:24:56 -0400196 Client: kvClient,
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700197 StoreType: backend,
Neha Sharma3f221ae2020-04-29 19:02:12 +0000198 Address: addr,
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700199 Timeout: KvstoreTimeout,
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800200 PathPrefix: fmt.Sprintf(BasePathKvStore, basePathKvStore, DeviceID)}
Abhilash S.L7f17e402019-03-15 17:40:41 +0530201
Girish Gowdru0c588b22019-04-23 23:24:56 -0400202 return kvbackend
Abhilash S.L7f17e402019-03-15 17:40:41 +0530203}
204
Holger Hildebrandt143b5be2023-02-10 08:28:15 +0000205// CloseKVClient closes open KV clients
206func (rsrcMgr *OpenOltResourceMgr) CloseKVClient(ctx context.Context) {
207 if rsrcMgr.KVStore != nil {
208 rsrcMgr.KVStore.Client.Close(ctx)
209 rsrcMgr.KVStore = nil
210 }
211 if rsrcMgr.PonRsrMgr != nil {
212 rsrcMgr.PonRsrMgr.CloseKVClient(ctx)
213 }
214}
215
Gamze Abakafee36392019-10-03 11:17:24 +0000216// NewResourceMgr init a New resource manager instance which in turn instantiates pon resource manager
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700217// instances according to technology. Initializes the default resource ranges for all
218// the resources.
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700219func NewResourceMgr(ctx context.Context, PonIntfID uint32, deviceID string, KVStoreAddress string, kvStoreType string, deviceType string, devInfo *openolt.DeviceInfo, basePathKvStore string) *OpenOltResourceMgr {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400220 var ResourceMgr OpenOltResourceMgr
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700221 logger.Debugf(ctx, "Init new resource manager , ponIf: %v, address: %s, device-id: %s", PonIntfID, KVStoreAddress, deviceID)
222 ResourceMgr.PonIntfID = PonIntfID
Girish Gowdraa09aeab2020-09-14 16:30:52 -0700223 ResourceMgr.DeviceID = deviceID
Neha Sharma3f221ae2020-04-29 19:02:12 +0000224 ResourceMgr.Address = KVStoreAddress
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700225 ResourceMgr.DeviceType = deviceType
226 ResourceMgr.DevInfo = devInfo
Abhilash S.L7f17e402019-03-15 17:40:41 +0530227
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700228 Backend := kvStoreType
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800229 ResourceMgr.KVStore = SetKVClient(ctx, Backend, ResourceMgr.Address, deviceID, basePathKvStore)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400230 if ResourceMgr.KVStore == nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000231 logger.Error(ctx, "Failed to setup KV store")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400232 }
Girish Gowdra38d533d2020-03-30 20:38:51 -0700233
Girish Gowdru0c588b22019-04-23 23:24:56 -0400234 // TODO self.args = registry('main').get_args()
Abhilash S.L7f17e402019-03-15 17:40:41 +0530235
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700236 // Create a separate Resource Manager instance for each range. This assumes that
Girish Gowdru0c588b22019-04-23 23:24:56 -0400237 // each technology is represented by only a single range
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700238 for _, TechRange := range devInfo.Ranges {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700239 for _, intfID := range TechRange.IntfIds {
240 if intfID == PonIntfID {
241 technology := TechRange.Technology
242 logger.Debugf(ctx, "Device info technology %s, intf-id %v", technology, PonIntfID)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000243
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700244 rsrMgr, err := ponrmgr.NewPONResourceManager(ctx, technology, deviceType, deviceID,
245 Backend, ResourceMgr.Address, basePathKvStore)
246 if err != nil {
247 logger.Errorf(ctx, "Failed to create pon resource manager instance for technology %s", technology)
248 return nil
249 }
250 ResourceMgr.PonRsrMgr = rsrMgr
251 // self.initialize_device_resource_range_and_pool(resource_mgr, global_resource_mgr, arange)
252 InitializeDeviceResourceRangeAndPool(ctx, rsrMgr, TechRange, devInfo)
253 if err := ResourceMgr.PonRsrMgr.InitDeviceResourcePoolForIntf(ctx, intfID); err != nil {
254 logger.Fatal(ctx, "failed-to-initialize-device-resource-pool-intf-id-%v-device-id", ResourceMgr.PonIntfID, ResourceMgr.DeviceID)
255 return nil
256 }
257 }
Girish Gowdru0c588b22019-04-23 23:24:56 -0400258 }
Girish Gowdru0c588b22019-04-23 23:24:56 -0400259 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700260
261 ResourceMgr.InitLocalCache()
yasin saplibddc2d72022-02-08 13:10:17 +0000262 if err := ResourceMgr.LoadLocalCacheFromKVStore(ctx); err != nil {
yasin sapli9e4c5092022-02-01 13:52:33 +0000263 logger.Error(ctx, "failed-to-load-local-cache-from-kvstore")
264 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000265 logger.Info(ctx, "Initialization of resource manager success!")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400266 return &ResourceMgr
Abhilash S.L7f17e402019-03-15 17:40:41 +0530267}
268
Joey Armstrong3f0e2422023-07-05 18:25:41 -0400269// InitLocalCache initializes local maps used for write-through-cache
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700270func (rsrcMgr *OpenOltResourceMgr) InitLocalCache() {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700271 rsrcMgr.allocIDsForOnu = make(map[string][]uint32)
272 rsrcMgr.gemPortIDsForOnu = make(map[string][]uint32)
273 rsrcMgr.techProfileIDsForOnu = make(map[string][]uint32)
274 rsrcMgr.meterInfoForOnu = make(map[string]*MeterInfo)
275 rsrcMgr.onuGemInfo = make(map[string]*OnuGemInfo)
276 rsrcMgr.gemPortForPacketInInfo = make(map[string]uint32)
277 rsrcMgr.flowIDsForGem = make(map[uint32][]uint64)
278 rsrcMgr.mcastQueueForIntf = make(map[uint32][]uint32)
279 rsrcMgr.groupInfo = make(map[string]*GroupInfo)
280}
281
Joey Armstrong3f0e2422023-07-05 18:25:41 -0400282// LoadLocalCacheFromKVStore loads local maps
yasin saplibddc2d72022-02-08 13:10:17 +0000283func (rsrcMgr *OpenOltResourceMgr) LoadLocalCacheFromKVStore(ctx context.Context) error {
yasin sapli9e4c5092022-02-01 13:52:33 +0000284
285 //List all the keys for OnuGemInfo
yasin saplibddc2d72022-02-08 13:10:17 +0000286 prefixPath := fmt.Sprintf(OnuGemInfoPathPathPrefix, rsrcMgr.PonIntfID)
yasin sapli9e4c5092022-02-01 13:52:33 +0000287 keys, err := rsrcMgr.KVStore.List(ctx, prefixPath)
288 logger.Debug(ctx, "load-local-cache-from-KV-store-started")
289 if err != nil {
290 logger.Errorf(ctx, "failed-to-list-keys-from-path-%s", prefixPath)
291 return err
292 }
293 for path := range keys {
294 var Val []byte
295 var onugem OnuGemInfo
296 // Get rid of the path prefix
297 stringToBeReplaced := rsrcMgr.KVStore.PathPrefix + "/"
298 replacedWith := ""
299 path = strings.Replace(path, stringToBeReplaced, replacedWith, 1)
300
301 value, err := rsrcMgr.KVStore.Get(ctx, path)
302 if err != nil {
303 logger.Errorw(ctx, "failed-to-get-from-kv-store", log.Fields{"path": path})
304 return err
305 } else if value == nil {
306 logger.Debug(ctx, "no-onugeminfo-for-path", log.Fields{"path": path})
307 continue
308 }
309 if Val, err = kvstore.ToByte(value.Value); err != nil {
310 logger.Error(ctx, "failed-to-covert-to-byte-array")
311 return err
312 }
313 if err = json.Unmarshal(Val, &onugem); err != nil {
314 logger.Error(ctx, "failed-to-unmarshall")
315 return err
316 }
317 logger.Debugw(ctx, "found-onugeminfo-from-path", log.Fields{"path": path, "onuGemInfo": onugem})
318
319 rsrcMgr.onuGemInfoLock.Lock()
320 rsrcMgr.onuGemInfo[path] = &onugem
321 rsrcMgr.onuGemInfoLock.Unlock()
322
323 }
324 logger.Debug(ctx, "load-local-cache-from-KV-store-finished")
325 return nil
326}
327
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700328// InitializeDeviceResourceRangeAndPool initializes the resource range pool according to the sharing type, then apply
329// device specific information. If KV doesn't exist
330// or is broader than the device, the device's information will
331// dictate the range limits
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700332func InitializeDeviceResourceRangeAndPool(ctx context.Context, ponRMgr *ponrmgr.PONResourceManager,
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700333 techRange *openolt.DeviceInfo_DeviceResourceRanges, devInfo *openolt.DeviceInfo) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700334 // var ONUIDShared, AllocIDShared, GEMPortIDShared openolt.DeviceInfo_DeviceResourceRanges_Pool_SharingType
335 var ONUIDStart, ONUIDEnd, AllocIDStart, AllocIDEnd, GEMPortIDStart, GEMPortIDEnd uint32
336 var ONUIDShared, AllocIDShared, GEMPortIDShared, FlowIDShared uint32
337
338 // The below variables are just dummy and needed to pass as arguments to InitDefaultPONResourceRanges function.
339 // The openolt adapter does not need flowIDs to be managed as it is managed on the OLT device
340 // The UNI IDs are dynamically generated by openonu adapter for every discovered UNI.
341 var flowIDDummyStart, flowIDDummyEnd uint32 = 1, 2
342 var uniIDDummyStart, uniIDDummyEnd uint32 = 0, 1
Abhilash S.L7f17e402019-03-15 17:40:41 +0530343
Girish Gowdru0c588b22019-04-23 23:24:56 -0400344 // init the resource range pool according to the sharing type
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700345 logger.Debugw(ctx, "Device info init", log.Fields{"technology": techRange.Technology,
346 "onu_id_start": ONUIDStart, "onu_id_end": ONUIDEnd,
347 "alloc_id_start": AllocIDStart, "alloc_id_end": AllocIDEnd,
348 "gemport_id_start": GEMPortIDStart, "gemport_id_end": GEMPortIDEnd,
349 "intf_ids": techRange.IntfIds,
350 })
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700351 for _, RangePool := range techRange.Pools {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700352 // FIXME: Remove hardcoding
Girish Gowdru0c588b22019-04-23 23:24:56 -0400353 if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_ONU_ID {
354 ONUIDStart = RangePool.Start
355 ONUIDEnd = RangePool.End
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700356 ONUIDShared = uint32(RangePool.Sharing)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400357 } else if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_ALLOC_ID {
358 AllocIDStart = RangePool.Start
359 AllocIDEnd = RangePool.End
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700360 AllocIDShared = uint32(RangePool.Sharing)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400361 } else if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_GEMPORT_ID {
362 GEMPortIDStart = RangePool.Start
363 GEMPortIDEnd = RangePool.End
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700364 GEMPortIDShared = uint32(RangePool.Sharing)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400365 }
366 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530367
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700368 ponRMgr.InitDefaultPONResourceRanges(ctx, ONUIDStart, ONUIDEnd, ONUIDShared,
369 AllocIDStart, AllocIDEnd, AllocIDShared,
370 GEMPortIDStart, GEMPortIDEnd, GEMPortIDShared,
371 flowIDDummyStart, flowIDDummyEnd, FlowIDShared, uniIDDummyStart, uniIDDummyEnd,
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700372 devInfo.PonPorts, techRange.IntfIds)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530373
Abhilash S.L7f17e402019-03-15 17:40:41 +0530374}
375
Devmalya Paul495b94a2019-08-27 19:42:00 -0400376// Delete clears used resources for the particular olt device being deleted
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700377func (rsrcMgr *OpenOltResourceMgr) Delete(ctx context.Context, intfID uint32) error {
378 if err := rsrcMgr.PonRsrMgr.ClearDeviceResourcePoolForIntf(ctx, intfID); err != nil {
379 logger.Debug(ctx, "Failed to clear device resource pool")
380 return err
Devmalya Paul495b94a2019-08-27 19:42:00 -0400381 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000382 logger.Debug(ctx, "Cleared device resource pool")
Devmalya Paul495b94a2019-08-27 19:42:00 -0400383 return nil
384}
Abhilash S.L7f17e402019-03-15 17:40:41 +0530385
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700386// GetONUID returns the available onuID for the given pon-port
yasin saplibddc2d72022-02-08 13:10:17 +0000387func (rsrcMgr *OpenOltResourceMgr) GetONUID(ctx context.Context) (uint32, error) {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400388 // Get ONU id for a provided pon interface ID.
yasin saplibddc2d72022-02-08 13:10:17 +0000389 onuID, err := rsrcMgr.TechprofileRef.GetResourceID(ctx, rsrcMgr.PonIntfID,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400390 ponrmgr.ONU_ID, 1)
391 if err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000392 logger.Errorf(ctx, "Failed to get resource for interface %d for type %s",
yasin saplibddc2d72022-02-08 13:10:17 +0000393 rsrcMgr.PonIntfID, ponrmgr.ONU_ID)
cbabuabf02352019-10-15 13:14:56 +0200394 return 0, err
Girish Gowdru0c588b22019-04-23 23:24:56 -0400395 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700396 if len(onuID) > 0 {
Girish Gowdraa09aeab2020-09-14 16:30:52 -0700397 return onuID[0], err
Girish Gowdru0c588b22019-04-23 23:24:56 -0400398 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530399
Girish Gowdra950326e2021-11-05 12:43:24 -0700400 return 0, fmt.Errorf("no-onu-id-allocated")
Abhilash S.L8ee90712019-04-29 16:24:22 +0530401}
402
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700403// UpdateAllocIdsForOnu updates alloc ids in kv store for a given pon interface id, onu id and uni id
yasin saplibddc2d72022-02-08 13:10:17 +0000404func (rsrcMgr *OpenOltResourceMgr) UpdateAllocIdsForOnu(ctx context.Context, onuID uint32, uniID uint32, allocIDs []uint32) error {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530405
yasin saplibddc2d72022-02-08 13:10:17 +0000406 intfOnuIDuniID := fmt.Sprintf("%d,%d,%d", rsrcMgr.PonIntfID, onuID, uniID)
Gamze Abaka745ccb72021-11-18 11:29:58 +0000407
408 // Note: in case the write to DB fails there could be inconsistent data between cache and db.
409 // Although this is highly unlikely with DB retries in place, this is something we have to deal with in the next release
410 if err := rsrcMgr.PonRsrMgr.UpdateAllocIdsForOnu(ctx, intfOnuIDuniID, allocIDs); err != nil {
411 logger.Errorw(ctx, "Failed to update alloc ids for onu", log.Fields{"err": err})
412 return err
413 }
414
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700415 // update cache
416 rsrcMgr.allocIDsForOnuLock.Lock()
417 rsrcMgr.allocIDsForOnu[intfOnuIDuniID] = allocIDs
418 rsrcMgr.allocIDsForOnuLock.Unlock()
Gamze Abaka745ccb72021-11-18 11:29:58 +0000419 return nil
Abhilash S.L7f17e402019-03-15 17:40:41 +0530420}
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700421
422// GetCurrentGEMPortIDsForOnu returns gem ports for given pon interface , onu id and uni id
yasin saplibddc2d72022-02-08 13:10:17 +0000423func (rsrcMgr *OpenOltResourceMgr) GetCurrentGEMPortIDsForOnu(ctx context.Context, onuID uint32,
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700424 uniID uint32) []uint32 {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530425
yasin saplibddc2d72022-02-08 13:10:17 +0000426 intfOnuIDuniID := fmt.Sprintf("%d,%d,%d", rsrcMgr.PonIntfID, onuID, uniID)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530427
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700428 // fetch from cache
429 rsrcMgr.gemPortIDsForOnuLock.RLock()
430 gemIDs, ok := rsrcMgr.gemPortIDsForOnu[intfOnuIDuniID]
431 rsrcMgr.gemPortIDsForOnuLock.RUnlock()
432 if ok {
433 return gemIDs
434 }
435 /* Get gem ports for given pon interface , onu id and uni id. */
436 gemIDs = rsrcMgr.PonRsrMgr.GetCurrentGEMPortIDsForOnu(ctx, intfOnuIDuniID)
437
438 // update cache
439 rsrcMgr.gemPortIDsForOnuLock.Lock()
440 rsrcMgr.gemPortIDsForOnu[intfOnuIDuniID] = gemIDs
441 rsrcMgr.gemPortIDsForOnuLock.Unlock()
442
443 return gemIDs
Abhilash S.L7f17e402019-03-15 17:40:41 +0530444}
445
Gamze Abakafee36392019-10-03 11:17:24 +0000446// GetCurrentAllocIDsForOnu returns alloc ids for given pon interface and onu id
yasin saplibddc2d72022-02-08 13:10:17 +0000447func (rsrcMgr *OpenOltResourceMgr) GetCurrentAllocIDsForOnu(ctx context.Context, onuID uint32, uniID uint32) []uint32 {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530448
yasin saplibddc2d72022-02-08 13:10:17 +0000449 intfOnuIDuniID := fmt.Sprintf("%d,%d,%d", rsrcMgr.PonIntfID, onuID, uniID)
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700450 // fetch from cache
451 rsrcMgr.allocIDsForOnuLock.RLock()
452 allocIDs, ok := rsrcMgr.allocIDsForOnu[intfOnuIDuniID]
453 rsrcMgr.allocIDsForOnuLock.RUnlock()
454 if ok {
455 return allocIDs
Girish Gowdru0c588b22019-04-23 23:24:56 -0400456 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700457 allocIDs = rsrcMgr.PonRsrMgr.GetCurrentAllocIDForOnu(ctx, intfOnuIDuniID)
458
459 // update cache
460 rsrcMgr.allocIDsForOnuLock.Lock()
461 rsrcMgr.allocIDsForOnu[intfOnuIDuniID] = allocIDs
462 rsrcMgr.allocIDsForOnuLock.Unlock()
463
464 return allocIDs
Gamze Abakafee36392019-10-03 11:17:24 +0000465}
466
467// RemoveAllocIDForOnu removes the alloc id for given pon interface, onu id, uni id and alloc id
yasin saplibddc2d72022-02-08 13:10:17 +0000468func (rsrcMgr *OpenOltResourceMgr) RemoveAllocIDForOnu(ctx context.Context, onuID uint32, uniID uint32, allocID uint32) {
469 allocIDs := rsrcMgr.GetCurrentAllocIDsForOnu(ctx, onuID, uniID)
Gamze Abakafee36392019-10-03 11:17:24 +0000470 for i := 0; i < len(allocIDs); i++ {
471 if allocIDs[i] == allocID {
472 allocIDs = append(allocIDs[:i], allocIDs[i+1:]...)
473 break
474 }
475 }
yasin saplibddc2d72022-02-08 13:10:17 +0000476 err := rsrcMgr.UpdateAllocIdsForOnu(ctx, onuID, uniID, allocIDs)
Gamze Abakafee36392019-10-03 11:17:24 +0000477 if err != nil {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700478 logger.Errorf(ctx, "Failed to Remove Alloc Id For Onu. intfID %d onuID %d uniID %d allocID %d",
yasin saplibddc2d72022-02-08 13:10:17 +0000479 rsrcMgr.PonIntfID, onuID, uniID, allocID)
Gamze Abakafee36392019-10-03 11:17:24 +0000480 }
481}
482
483// RemoveGemPortIDForOnu removes the gem port id for given pon interface, onu id, uni id and gem port id
yasin saplibddc2d72022-02-08 13:10:17 +0000484func (rsrcMgr *OpenOltResourceMgr) RemoveGemPortIDForOnu(ctx context.Context, onuID uint32, uniID uint32, gemPortID uint32) {
485 gemPortIDs := rsrcMgr.GetCurrentGEMPortIDsForOnu(ctx, onuID, uniID)
Gamze Abakafee36392019-10-03 11:17:24 +0000486 for i := 0; i < len(gemPortIDs); i++ {
487 if gemPortIDs[i] == gemPortID {
488 gemPortIDs = append(gemPortIDs[:i], gemPortIDs[i+1:]...)
489 break
490 }
491 }
yasin saplibddc2d72022-02-08 13:10:17 +0000492 err := rsrcMgr.UpdateGEMPortIDsForOnu(ctx, onuID, uniID, gemPortIDs)
Gamze Abakafee36392019-10-03 11:17:24 +0000493 if err != nil {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700494 logger.Errorf(ctx, "Failed to Remove Gem Id For Onu. intfID %d onuID %d uniID %d gemPortId %d",
yasin saplibddc2d72022-02-08 13:10:17 +0000495 rsrcMgr.PonIntfID, onuID, uniID, gemPortID)
Gamze Abakafee36392019-10-03 11:17:24 +0000496 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530497}
498
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700499// UpdateGEMPortIDsForOnu updates gemport ids on to the kv store for a given pon port, onu id and uni id
yasin saplibddc2d72022-02-08 13:10:17 +0000500func (rsrcMgr *OpenOltResourceMgr) UpdateGEMPortIDsForOnu(ctx context.Context, onuID uint32,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700501 uniID uint32, gemIDs []uint32) error {
yasin saplibddc2d72022-02-08 13:10:17 +0000502 intfOnuIDuniID := fmt.Sprintf("%d,%d,%d", rsrcMgr.PonIntfID, onuID, uniID)
Gamze Abaka745ccb72021-11-18 11:29:58 +0000503
504 if err := rsrcMgr.PonRsrMgr.UpdateGEMPortIDsForOnu(ctx, intfOnuIDuniID, gemIDs); err != nil {
505 logger.Errorw(ctx, "Failed to update gem port ids for onu", log.Fields{"err": err})
506 return err
507 }
508
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700509 // update cache
510 rsrcMgr.gemPortIDsForOnuLock.Lock()
511 rsrcMgr.gemPortIDsForOnu[intfOnuIDuniID] = gemIDs
512 rsrcMgr.gemPortIDsForOnuLock.Unlock()
Gamze Abaka745ccb72021-11-18 11:29:58 +0000513 return nil
Abhilash S.L7f17e402019-03-15 17:40:41 +0530514}
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700515
516// FreeonuID releases(make free) onu id for a particular pon-port
yasin saplibddc2d72022-02-08 13:10:17 +0000517func (rsrcMgr *OpenOltResourceMgr) FreeonuID(ctx context.Context, onuID []uint32) {
Girish Gowdrab8f1b5a2021-06-27 20:42:40 -0700518 if len(onuID) == 0 {
519 logger.Info(ctx, "onu id slice is nil, nothing to free")
520 return
521 }
yasin saplibddc2d72022-02-08 13:10:17 +0000522 if err := rsrcMgr.TechprofileRef.FreeResourceID(ctx, rsrcMgr.PonIntfID, ponrmgr.ONU_ID, onuID); err != nil {
Matteo Scandolo84585372021-03-18 14:21:22 -0700523 logger.Errorw(ctx, "error-while-freeing-onu-id", log.Fields{
yasin saplibddc2d72022-02-08 13:10:17 +0000524 "intf-id": rsrcMgr.PonIntfID,
Matteo Scandolo84585372021-03-18 14:21:22 -0700525 "onu-id": onuID,
526 "err": err.Error(),
527 })
Girish Gowdrab8f1b5a2021-06-27 20:42:40 -0700528 } else {
yasin saplibddc2d72022-02-08 13:10:17 +0000529 logger.Infow(ctx, "freed onu id", log.Fields{"intfID": rsrcMgr.PonIntfID, "onuID": onuID})
Matteo Scandolo84585372021-03-18 14:21:22 -0700530 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530531}
532
Gamze Abakafee36392019-10-03 11:17:24 +0000533// FreeAllocID frees AllocID on the PON resource pool and also frees the allocID association
534// for the given OLT device.
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700535// The caller should ensure that this is a blocking call and this operation is serialized for
536// the ONU so as not cause resource corruption since there are no mutexes used here.
Girish Gowdraf3728b12022-02-02 21:46:51 -0800537// Setting freeFromResourcePool to false will not clear it from the resource pool but only
538// clear it for the given pon/onu/uni
yasin saplibddc2d72022-02-08 13:10:17 +0000539func (rsrcMgr *OpenOltResourceMgr) FreeAllocID(ctx context.Context, onuID uint32,
Girish Gowdraf3728b12022-02-02 21:46:51 -0800540 uniID uint32, allocID uint32, freeFromResourcePool bool) {
Girish Gowdrab77ded92020-04-08 11:45:05 -0700541
yasin saplibddc2d72022-02-08 13:10:17 +0000542 rsrcMgr.RemoveAllocIDForOnu(ctx, onuID, uniID, allocID)
Girish Gowdraf3728b12022-02-02 21:46:51 -0800543 if freeFromResourcePool {
544 allocIDs := make([]uint32, 0)
545 allocIDs = append(allocIDs, allocID)
yasin saplibddc2d72022-02-08 13:10:17 +0000546 if err := rsrcMgr.TechprofileRef.FreeResourceID(ctx, rsrcMgr.PonIntfID, ponrmgr.ALLOC_ID, allocIDs); err != nil {
Girish Gowdraf3728b12022-02-02 21:46:51 -0800547 logger.Errorw(ctx, "error-while-freeing-alloc-id", log.Fields{
yasin saplibddc2d72022-02-08 13:10:17 +0000548 "intf-id": rsrcMgr.PonIntfID,
Girish Gowdraf3728b12022-02-02 21:46:51 -0800549 "onu-id": onuID,
550 "err": err.Error(),
551 })
552 }
Matteo Scandolo84585372021-03-18 14:21:22 -0700553 }
Gamze Abakafee36392019-10-03 11:17:24 +0000554}
555
556// FreeGemPortID frees GemPortID on the PON resource pool and also frees the gemPortID association
557// for the given OLT device.
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700558// The caller should ensure that this is a blocking call and this operation is serialized for
559// the ONU so as not cause resource corruption since there are no mutexes used here.
yasin saplibddc2d72022-02-08 13:10:17 +0000560func (rsrcMgr *OpenOltResourceMgr) FreeGemPortID(ctx context.Context, onuID uint32,
Gamze Abakafee36392019-10-03 11:17:24 +0000561 uniID uint32, gemPortID uint32) {
yasin saplibddc2d72022-02-08 13:10:17 +0000562 rsrcMgr.RemoveGemPortIDForOnu(ctx, onuID, uniID, gemPortID)
Girish Gowdrab77ded92020-04-08 11:45:05 -0700563
Gamze Abakafee36392019-10-03 11:17:24 +0000564 gemPortIDs := make([]uint32, 0)
565 gemPortIDs = append(gemPortIDs, gemPortID)
yasin saplibddc2d72022-02-08 13:10:17 +0000566 if err := rsrcMgr.TechprofileRef.FreeResourceID(ctx, rsrcMgr.PonIntfID, ponrmgr.GEMPORT_ID, gemPortIDs); err != nil {
Matteo Scandolo84585372021-03-18 14:21:22 -0700567 logger.Errorw(ctx, "error-while-freeing-gem-port-id", log.Fields{
yasin saplibddc2d72022-02-08 13:10:17 +0000568 "intf-id": rsrcMgr.PonIntfID,
Matteo Scandolo84585372021-03-18 14:21:22 -0700569 "onu-id": onuID,
570 "err": err.Error(),
571 })
572 }
Gamze Abakafee36392019-10-03 11:17:24 +0000573}
574
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700575// FreePONResourcesForONU make the pon resources free for a given pon interface and onu id
yasin saplibddc2d72022-02-08 13:10:17 +0000576func (rsrcMgr *OpenOltResourceMgr) FreePONResourcesForONU(ctx context.Context, onuID uint32, uniID uint32) {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530577
yasin saplibddc2d72022-02-08 13:10:17 +0000578 intfOnuIDuniID := fmt.Sprintf("%d,%d,%d", rsrcMgr.PonIntfID, onuID, uniID)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530579
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700580 AllocIDs := rsrcMgr.PonRsrMgr.GetCurrentAllocIDForOnu(ctx, intfOnuIDuniID)
Matteo Scandolod625b4c2020-04-02 16:16:01 -0700581
yasin saplibddc2d72022-02-08 13:10:17 +0000582 if err := rsrcMgr.TechprofileRef.FreeResourceID(ctx, rsrcMgr.PonIntfID,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400583 ponrmgr.ALLOC_ID,
Matteo Scandolo84585372021-03-18 14:21:22 -0700584 AllocIDs); err != nil {
585 logger.Errorw(ctx, "error-while-freeing-all-alloc-ids-for-onu", log.Fields{
yasin saplibddc2d72022-02-08 13:10:17 +0000586 "intf-id": rsrcMgr.PonIntfID,
Matteo Scandolo84585372021-03-18 14:21:22 -0700587 "onu-id": onuID,
588 "err": err.Error(),
589 })
590 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530591
Gamze Abaka745ccb72021-11-18 11:29:58 +0000592 //update cache
593 rsrcMgr.allocIDsForOnuLock.Lock()
594 delete(rsrcMgr.allocIDsForOnu, intfOnuIDuniID)
595 rsrcMgr.allocIDsForOnuLock.Unlock()
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700596
Gamze Abaka745ccb72021-11-18 11:29:58 +0000597 GEMPortIDs := rsrcMgr.PonRsrMgr.GetCurrentGEMPortIDsForOnu(ctx, intfOnuIDuniID)
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700598
yasin saplibddc2d72022-02-08 13:10:17 +0000599 if err := rsrcMgr.TechprofileRef.FreeResourceID(ctx, rsrcMgr.PonIntfID,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400600 ponrmgr.GEMPORT_ID,
Matteo Scandolo84585372021-03-18 14:21:22 -0700601 GEMPortIDs); err != nil {
602 logger.Errorw(ctx, "error-while-freeing-all-gem-port-ids-for-onu", log.Fields{
yasin saplibddc2d72022-02-08 13:10:17 +0000603 "intf-id": rsrcMgr.PonIntfID,
Matteo Scandolo84585372021-03-18 14:21:22 -0700604 "onu-id": onuID,
605 "err": err.Error(),
606 })
607 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530608
Gamze Abaka745ccb72021-11-18 11:29:58 +0000609 // update cache
610 rsrcMgr.gemPortIDsForOnuLock.Lock()
611 delete(rsrcMgr.gemPortIDsForOnu, intfOnuIDuniID)
612 rsrcMgr.gemPortIDsForOnuLock.Unlock()
613
Girish Gowdru0c588b22019-04-23 23:24:56 -0400614 // Clear resource map associated with (pon_intf_id, gemport_id) tuple.
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700615 rsrcMgr.PonRsrMgr.RemoveResourceMap(ctx, intfOnuIDuniID)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530616}
617
Girish Gowdraa09aeab2020-09-14 16:30:52 -0700618// IsFlowOnKvStore checks if the given flowID is present on the kv store
619// Returns true if the flowID is found, otherwise it returns false
yasin saplibddc2d72022-02-08 13:10:17 +0000620func (rsrcMgr *OpenOltResourceMgr) IsFlowOnKvStore(ctx context.Context, onuID int32, flowID uint64) (bool, error) {
yasin saplid0566272021-12-21 09:10:30 +0000621 var anyError error
Abhilash S.L7f17e402019-03-15 17:40:41 +0530622
yasin saplid0566272021-12-21 09:10:30 +0000623 // In case of nni trap flow
624 if onuID == -1 {
yasin saplibddc2d72022-02-08 13:10:17 +0000625 nniTrapflowIDs, err := rsrcMgr.GetFlowIDsForGem(ctx, NNI)
yasin saplid0566272021-12-21 09:10:30 +0000626 if err != nil {
627 logger.Warnw(ctx, "failed-to-get-nni-trap-flowIDs", log.Fields{"err": err})
628 return false, err
629 }
630 for _, id := range nniTrapflowIDs {
Girish Gowdraa09aeab2020-09-14 16:30:52 -0700631 if flowID == id {
yasin saplid0566272021-12-21 09:10:30 +0000632 return true, nil
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400633 }
634 }
635 }
yasin saplid0566272021-12-21 09:10:30 +0000636
yasin saplibddc2d72022-02-08 13:10:17 +0000637 path := fmt.Sprintf(OnuGemInfoPath, rsrcMgr.PonIntfID, onuID)
yasin saplid0566272021-12-21 09:10:30 +0000638 rsrcMgr.onuGemInfoLock.RLock()
639 val, ok := rsrcMgr.onuGemInfo[path]
640 rsrcMgr.onuGemInfoLock.RUnlock()
641
642 if ok {
643 for _, gem := range val.GemPorts {
yasin saplibddc2d72022-02-08 13:10:17 +0000644 flowIDs, err := rsrcMgr.GetFlowIDsForGem(ctx, gem)
yasin saplid0566272021-12-21 09:10:30 +0000645 if err != nil {
646 anyError = err
647 logger.Warnw(ctx, "failed-to-get-flowIDs-for-gem", log.Fields{"err": err, "onuID": onuID, "gem": gem})
648 } else {
649 for _, id := range flowIDs {
650 if flowID == id {
651 return true, nil
652 }
653 }
654 }
655 }
656 }
657 return false, anyError
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400658}
Manikkaraj kb1d51442019-07-23 10:41:02 -0400659
salmansiddiqui7ac62132019-08-22 03:58:50 +0000660// GetTechProfileIDForOnu fetches Tech-Profile-ID from the KV-Store for the given onu based on the path
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700661// This path is formed as the following: {intfID, onuID, uniID}/tp_id
yasin saplibddc2d72022-02-08 13:10:17 +0000662func (rsrcMgr *OpenOltResourceMgr) GetTechProfileIDForOnu(ctx context.Context, onuID uint32, uniID uint32) []uint32 {
663 Path := fmt.Sprintf(tpIDPathSuffix, rsrcMgr.PonIntfID, onuID, uniID)
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700664 // fetch from cache
665 rsrcMgr.techProfileIDsForOnuLock.RLock()
666 tpIDs, ok := rsrcMgr.techProfileIDsForOnu[Path]
667 rsrcMgr.techProfileIDsForOnuLock.RUnlock()
668 if ok {
669 return tpIDs
670 }
671 Value, err := rsrcMgr.KVStore.Get(ctx, Path)
Manikkaraj kb1d51442019-07-23 10:41:02 -0400672 if err == nil {
673 if Value != nil {
674 Val, err := kvstore.ToByte(Value.Value)
675 if err != nil {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700676 logger.Errorw(ctx, "Failed to convert into byte array", log.Fields{"err": err})
677 return tpIDs
Manikkaraj kb1d51442019-07-23 10:41:02 -0400678 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700679 if err = json.Unmarshal(Val, &tpIDs); err != nil {
680 logger.Error(ctx, "Failed to unmarshal", log.Fields{"err": err})
681 return tpIDs
Manikkaraj kb1d51442019-07-23 10:41:02 -0400682 }
683 }
684 } else {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000685 logger.Errorf(ctx, "Failed to get TP id from kvstore for path %s", Path)
Manikkaraj kb1d51442019-07-23 10:41:02 -0400686 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700687 logger.Debugf(ctx, "Getting TP id %d from path %s", tpIDs, Path)
688
689 // update cache
690 rsrcMgr.techProfileIDsForOnuLock.Lock()
691 rsrcMgr.techProfileIDsForOnu[Path] = tpIDs
692 rsrcMgr.techProfileIDsForOnuLock.Unlock()
693
694 return tpIDs
Manikkaraj kb1d51442019-07-23 10:41:02 -0400695
696}
697
Gamze Abakafee36392019-10-03 11:17:24 +0000698// RemoveTechProfileIDsForOnu deletes all tech profile ids from the KV-Store for the given onu based on the path
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700699// This path is formed as the following: {intfID, onuID, uniID}/tp_id
yasin saplibddc2d72022-02-08 13:10:17 +0000700func (rsrcMgr *OpenOltResourceMgr) RemoveTechProfileIDsForOnu(ctx context.Context, onuID uint32, uniID uint32) error {
701 intfOnuUniID := fmt.Sprintf(tpIDPathSuffix, rsrcMgr.PonIntfID, onuID, uniID)
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700702
703 if err := rsrcMgr.KVStore.Delete(ctx, intfOnuUniID); err != nil {
704 logger.Errorw(ctx, "Failed to delete techprofile id resource in KV store", log.Fields{"path": intfOnuUniID})
Manikkaraj kb1d51442019-07-23 10:41:02 -0400705 return err
706 }
Gamze Abaka745ccb72021-11-18 11:29:58 +0000707
708 // update cache
709 rsrcMgr.techProfileIDsForOnuLock.Lock()
710 delete(rsrcMgr.techProfileIDsForOnu, intfOnuUniID)
711 rsrcMgr.techProfileIDsForOnuLock.Unlock()
Manikkaraj kb1d51442019-07-23 10:41:02 -0400712 return nil
713}
714
Gamze Abakafee36392019-10-03 11:17:24 +0000715// RemoveTechProfileIDForOnu deletes a specific tech profile id from the KV-Store for the given onu based on the path
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700716// This path is formed as the following: {intfID, onuID, uniID}/tp_id
yasin saplibddc2d72022-02-08 13:10:17 +0000717func (rsrcMgr *OpenOltResourceMgr) RemoveTechProfileIDForOnu(ctx context.Context, onuID uint32, uniID uint32, tpID uint32) error {
718 tpIDList := rsrcMgr.GetTechProfileIDForOnu(ctx, onuID, uniID)
Gamze Abakafee36392019-10-03 11:17:24 +0000719 for i, tpIDInList := range tpIDList {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700720 if tpIDInList == tpID {
Gamze Abakafee36392019-10-03 11:17:24 +0000721 tpIDList = append(tpIDList[:i], tpIDList[i+1:]...)
722 }
723 }
yasin saplibddc2d72022-02-08 13:10:17 +0000724 intfOnuUniID := fmt.Sprintf(tpIDPathSuffix, rsrcMgr.PonIntfID, onuID, uniID)
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700725
Gamze Abakafee36392019-10-03 11:17:24 +0000726 Value, err := json.Marshal(tpIDList)
727 if err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000728 logger.Error(ctx, "failed to Marshal")
Gamze Abakafee36392019-10-03 11:17:24 +0000729 return err
730 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700731 if err = rsrcMgr.KVStore.Put(ctx, intfOnuUniID, Value); err != nil {
732 logger.Errorf(ctx, "Failed to update resource %s", intfOnuUniID)
Gamze Abakafee36392019-10-03 11:17:24 +0000733 return err
734 }
Gamze Abaka745ccb72021-11-18 11:29:58 +0000735
736 // update cache
737 rsrcMgr.techProfileIDsForOnuLock.Lock()
738 rsrcMgr.techProfileIDsForOnu[intfOnuUniID] = tpIDList
739 rsrcMgr.techProfileIDsForOnuLock.Unlock()
Gamze Abakafee36392019-10-03 11:17:24 +0000740 return err
741}
742
743// UpdateTechProfileIDForOnu updates (put) already present tech-profile-id for the given onu based on the path
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700744// This path is formed as the following: {intfID, onuID, uniID}/tp_id
yasin saplibddc2d72022-02-08 13:10:17 +0000745func (rsrcMgr *OpenOltResourceMgr) UpdateTechProfileIDForOnu(ctx context.Context, onuID uint32,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700746 uniID uint32, tpID uint32) error {
Manikkaraj kb1d51442019-07-23 10:41:02 -0400747 var Value []byte
748 var err error
749
yasin saplibddc2d72022-02-08 13:10:17 +0000750 intfOnuUniID := fmt.Sprintf(tpIDPathSuffix, rsrcMgr.PonIntfID, onuID, uniID)
Gamze Abakafee36392019-10-03 11:17:24 +0000751
yasin saplibddc2d72022-02-08 13:10:17 +0000752 tpIDList := rsrcMgr.GetTechProfileIDForOnu(ctx, onuID, uniID)
Gamze Abakafee36392019-10-03 11:17:24 +0000753 for _, value := range tpIDList {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700754 if value == tpID {
755 logger.Debugf(ctx, "tpID %d is already in tpIdList for the path %s", tpID, intfOnuUniID)
Gamze Abakafee36392019-10-03 11:17:24 +0000756 return err
757 }
758 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700759 logger.Debugf(ctx, "updating tp id %d on path %s", tpID, intfOnuUniID)
760 tpIDList = append(tpIDList, tpID)
761
Gamze Abakafee36392019-10-03 11:17:24 +0000762 Value, err = json.Marshal(tpIDList)
Manikkaraj kb1d51442019-07-23 10:41:02 -0400763 if err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000764 logger.Error(ctx, "failed to Marshal")
Manikkaraj kb1d51442019-07-23 10:41:02 -0400765 return err
766 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700767 if err = rsrcMgr.KVStore.Put(ctx, intfOnuUniID, Value); err != nil {
768 logger.Errorf(ctx, "Failed to update resource %s", intfOnuUniID)
Manikkaraj kb1d51442019-07-23 10:41:02 -0400769 return err
770 }
Gamze Abaka745ccb72021-11-18 11:29:58 +0000771
772 // update cache
773 rsrcMgr.techProfileIDsForOnuLock.Lock()
774 rsrcMgr.techProfileIDsForOnu[intfOnuUniID] = tpIDList
775 rsrcMgr.techProfileIDsForOnuLock.Unlock()
Manikkaraj kb1d51442019-07-23 10:41:02 -0400776 return err
777}
778
Girish Gowdraa482f272021-03-24 23:04:19 -0700779// StoreMeterInfoForOnu updates the meter id in the KV-Store for the given onu based on the path
Gamze Abakafee36392019-10-03 11:17:24 +0000780// This path is formed as the following: <(pon_id, onu_id, uni_id)>/<tp_id>/meter_id/<direction>
yasin saplibddc2d72022-02-08 13:10:17 +0000781func (rsrcMgr *OpenOltResourceMgr) StoreMeterInfoForOnu(ctx context.Context, Direction string, onuID uint32,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700782 uniID uint32, tpID uint32, meterInfo *MeterInfo) error {
Manikkaraj kb1d51442019-07-23 10:41:02 -0400783 var Value []byte
784 var err error
yasin saplibddc2d72022-02-08 13:10:17 +0000785 intfOnuUniID := fmt.Sprintf(MeterIDPathSuffix, rsrcMgr.PonIntfID, onuID, uniID, tpID, Direction)
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700786
Girish Gowdraa482f272021-03-24 23:04:19 -0700787 Value, err = json.Marshal(*meterInfo)
Manikkaraj kb1d51442019-07-23 10:41:02 -0400788 if err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000789 logger.Error(ctx, "failed to Marshal meter config")
Manikkaraj kb1d51442019-07-23 10:41:02 -0400790 return err
791 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700792 if err = rsrcMgr.KVStore.Put(ctx, intfOnuUniID, Value); err != nil {
793 logger.Errorf(ctx, "Failed to store meter into KV store %s", intfOnuUniID)
Manikkaraj kb1d51442019-07-23 10:41:02 -0400794 return err
795 }
Gamze Abaka745ccb72021-11-18 11:29:58 +0000796
797 // update cache
798 rsrcMgr.meterInfoForOnuLock.Lock()
799 rsrcMgr.meterInfoForOnu[intfOnuUniID] = meterInfo
800 rsrcMgr.meterInfoForOnuLock.Unlock()
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700801 logger.Debugw(ctx, "meter info updated successfully", log.Fields{"path": intfOnuUniID, "meter-info": meterInfo})
Manikkaraj kb1d51442019-07-23 10:41:02 -0400802 return err
803}
804
Girish Gowdraa482f272021-03-24 23:04:19 -0700805// GetMeterInfoForOnu fetches the meter id from the kv store for the given onu based on the path
Gamze Abakafee36392019-10-03 11:17:24 +0000806// This path is formed as the following: <(pon_id, onu_id, uni_id)>/<tp_id>/meter_id/<direction>
yasin saplibddc2d72022-02-08 13:10:17 +0000807func (rsrcMgr *OpenOltResourceMgr) GetMeterInfoForOnu(ctx context.Context, Direction string, onuID uint32,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700808 uniID uint32, tpID uint32) (*MeterInfo, error) {
yasin saplibddc2d72022-02-08 13:10:17 +0000809 Path := fmt.Sprintf(MeterIDPathSuffix, rsrcMgr.PonIntfID, onuID, uniID, tpID, Direction)
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700810
811 // get from cache
812 rsrcMgr.meterInfoForOnuLock.RLock()
813 val, ok := rsrcMgr.meterInfoForOnu[Path]
814 rsrcMgr.meterInfoForOnuLock.RUnlock()
815 if ok {
816 return val, nil
817 }
818
Girish Gowdraa482f272021-03-24 23:04:19 -0700819 var meterInfo MeterInfo
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700820 Value, err := rsrcMgr.KVStore.Get(ctx, Path)
Manikkaraj kb1d51442019-07-23 10:41:02 -0400821 if err == nil {
822 if Value != nil {
Girish Gowdraa482f272021-03-24 23:04:19 -0700823 logger.Debug(ctx, "Found meter info in KV store", log.Fields{"Direction": Direction})
salmansiddiqui7ac62132019-08-22 03:58:50 +0000824 Val, er := kvstore.ToByte(Value.Value)
825 if er != nil {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700826 logger.Errorw(ctx, "Failed to convert into byte array", log.Fields{"err": er})
salmansiddiqui7ac62132019-08-22 03:58:50 +0000827 return nil, er
Manikkaraj kb1d51442019-07-23 10:41:02 -0400828 }
Girish Gowdraa482f272021-03-24 23:04:19 -0700829 if er = json.Unmarshal(Val, &meterInfo); er != nil {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700830 logger.Error(ctx, "Failed to unmarshal meter info", log.Fields{"err": er})
salmansiddiqui7ac62132019-08-22 03:58:50 +0000831 return nil, er
Manikkaraj kb1d51442019-07-23 10:41:02 -0400832 }
833 } else {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000834 logger.Debug(ctx, "meter-does-not-exists-in-KVStore")
Manikkaraj kb1d51442019-07-23 10:41:02 -0400835 return nil, err
836 }
837 } else {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000838 logger.Errorf(ctx, "Failed to get Meter config from kvstore for path %s", Path)
Manikkaraj kb1d51442019-07-23 10:41:02 -0400839
840 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700841 // update cache
842 rsrcMgr.meterInfoForOnuLock.Lock()
843 rsrcMgr.meterInfoForOnu[Path] = &meterInfo
844 rsrcMgr.meterInfoForOnuLock.Unlock()
845
Girish Gowdraa482f272021-03-24 23:04:19 -0700846 return &meterInfo, err
Manikkaraj kb1d51442019-07-23 10:41:02 -0400847}
848
Girish Gowdraa482f272021-03-24 23:04:19 -0700849// HandleMeterInfoRefCntUpdate increments or decrements the reference counter for a given meter.
850// When reference count becomes 0, it clears the meter information from the kv store
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700851func (rsrcMgr *OpenOltResourceMgr) HandleMeterInfoRefCntUpdate(ctx context.Context, Direction string,
yasin saplibddc2d72022-02-08 13:10:17 +0000852 onuID uint32, uniID uint32, tpID uint32, increment bool) error {
853 meterInfo, err := rsrcMgr.GetMeterInfoForOnu(ctx, Direction, onuID, uniID, tpID)
Girish Gowdra82c80982021-03-26 16:22:02 -0700854 if err != nil {
855 return err
856 } else if meterInfo == nil {
857 // If we are increasing the reference count, we expect the meter information to be present on KV store.
858 // But if decrementing the reference count, the meter is possibly already cleared from KV store. Just log warn but do not return error.
859 if increment {
yasin saplibddc2d72022-02-08 13:10:17 +0000860 logger.Errorf(ctx, "error-fetching-meter-info-for-intf-%d-onu-%d-uni-%d-tp-id-%d-direction-%s", rsrcMgr.PonIntfID, onuID, uniID, tpID, Direction)
861 return fmt.Errorf("error-fetching-meter-info-for-intf-%d-onu-%d-uni-%d-tp-id-%d-direction-%s", rsrcMgr.PonIntfID, onuID, uniID, tpID, Direction)
Girish Gowdra82c80982021-03-26 16:22:02 -0700862 }
863 logger.Warnw(ctx, "meter is already cleared",
yasin saplibddc2d72022-02-08 13:10:17 +0000864 log.Fields{"intfID": rsrcMgr.PonIntfID, "onuID": onuID, "uniID": uniID, "direction": Direction, "increment": increment})
Girish Gowdra82c80982021-03-26 16:22:02 -0700865 return nil
Girish Gowdraa482f272021-03-24 23:04:19 -0700866 }
Girish Gowdra82c80982021-03-26 16:22:02 -0700867
Girish Gowdraa482f272021-03-24 23:04:19 -0700868 if increment {
869 meterInfo.RefCnt++
870 } else {
871 meterInfo.RefCnt--
Girish Gowdraa482f272021-03-24 23:04:19 -0700872 }
yasin saplibddc2d72022-02-08 13:10:17 +0000873 if err := rsrcMgr.StoreMeterInfoForOnu(ctx, Direction, onuID, uniID, tpID, meterInfo); err != nil {
Girish Gowdraa482f272021-03-24 23:04:19 -0700874 return err
875 }
876 return nil
877}
878
879// RemoveMeterInfoForOnu deletes the meter id from the kV-Store for the given onu based on the path
Gamze Abakafee36392019-10-03 11:17:24 +0000880// This path is formed as the following: <(pon_id, onu_id, uni_id)>/<tp_id>/meter_id/<direction>
yasin saplibddc2d72022-02-08 13:10:17 +0000881func (rsrcMgr *OpenOltResourceMgr) RemoveMeterInfoForOnu(ctx context.Context, Direction string, onuID uint32,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700882 uniID uint32, tpID uint32) error {
yasin saplibddc2d72022-02-08 13:10:17 +0000883 Path := fmt.Sprintf(MeterIDPathSuffix, rsrcMgr.PonIntfID, onuID, uniID, tpID, Direction)
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700884
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700885 if err := rsrcMgr.KVStore.Delete(ctx, Path); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000886 logger.Errorf(ctx, "Failed to delete meter id %s from kvstore ", Path)
Manikkaraj kb1d51442019-07-23 10:41:02 -0400887 return err
888 }
Gamze Abaka745ccb72021-11-18 11:29:58 +0000889
890 // update cache
891 rsrcMgr.meterInfoForOnuLock.Lock()
892 delete(rsrcMgr.meterInfoForOnu, Path)
893 rsrcMgr.meterInfoForOnuLock.Unlock()
Manikkaraj kb1d51442019-07-23 10:41:02 -0400894 return nil
895}
salmansiddiqui7ac62132019-08-22 03:58:50 +0000896
Joey Armstrong3f0e2422023-07-05 18:25:41 -0400897// AddGemToOnuGemInfo adds gemport to onugem info kvstore and also local cache
yasin saplibddc2d72022-02-08 13:10:17 +0000898func (rsrcMgr *OpenOltResourceMgr) AddGemToOnuGemInfo(ctx context.Context, onuID uint32, gemPort uint32) error {
899 onugem, err := rsrcMgr.GetOnuGemInfo(ctx, onuID)
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700900 if err != nil || onugem == nil || onugem.SerialNumber == "" {
yasin saplibddc2d72022-02-08 13:10:17 +0000901 logger.Errorf(ctx, "failed to get onuifo for intfid %d", rsrcMgr.PonIntfID)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530902 return err
903 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700904 if onugem.OnuID == onuID {
905 for _, gem := range onugem.GemPorts {
906 if gem == gemPort {
907 logger.Debugw(ctx, "Gem already present in onugem info, skpping addition", log.Fields{"gem": gem})
908 return nil
909 }
910 }
911 logger.Debugw(ctx, "Added gem to onugem info", log.Fields{"gem": gemPort})
912 onugem.GemPorts = append(onugem.GemPorts, gemPort)
913 } else {
yasin saplibddc2d72022-02-08 13:10:17 +0000914 logger.Errorw(ctx, "onu id in OnuGemInfo does not match", log.Fields{"onuID": onuID, "ponIf": rsrcMgr.PonIntfID, "onuGemInfoOnuID": onugem.OnuID})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700915 return fmt.Errorf("onu-id-in-OnuGemInfo-does-not-match-%v", onuID)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530916 }
917
yasin saplibddc2d72022-02-08 13:10:17 +0000918 err = rsrcMgr.AddOnuGemInfo(ctx, onuID, *onugem)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530919 if err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000920 logger.Error(ctx, "Failed to add onugem to kv store")
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530921 return err
922 }
923 return err
924}
925
Joey Armstrong3f0e2422023-07-05 18:25:41 -0400926// RemoveGemFromOnuGemInfo removes gemport from onugem info on kvstore and also local cache
yasin saplibddc2d72022-02-08 13:10:17 +0000927func (rsrcMgr *OpenOltResourceMgr) RemoveGemFromOnuGemInfo(ctx context.Context, onuID uint32, gemPort uint32) error {
928 onugem, err := rsrcMgr.GetOnuGemInfo(ctx, onuID)
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700929 if err != nil || onugem == nil || onugem.SerialNumber == "" {
yasin saplibddc2d72022-02-08 13:10:17 +0000930 logger.Errorf(ctx, "failed to get onuifo for intfid %d", rsrcMgr.PonIntfID)
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700931 return err
932 }
933 updated := false
934 if onugem.OnuID == onuID {
935 for i, gem := range onugem.GemPorts {
936 if gem == gemPort {
937 logger.Debugw(ctx, "Gem found, removing from onu gem info", log.Fields{"gem": gem})
938 onugem.GemPorts = append(onugem.GemPorts[:i], onugem.GemPorts[i+1:]...)
939 updated = true
940 break
941 }
942 }
943 } else {
yasin saplibddc2d72022-02-08 13:10:17 +0000944 logger.Errorw(ctx, "onu id in OnuGemInfo does not match", log.Fields{"onuID": onuID, "ponIf": rsrcMgr.PonIntfID, "onuGemInfoOnuID": onugem.OnuID})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700945 return fmt.Errorf("onu-id-in-OnuGemInfo-does-not-match-%v", onuID)
946 }
947 if updated {
yasin saplibddc2d72022-02-08 13:10:17 +0000948 err = rsrcMgr.AddOnuGemInfo(ctx, onuID, *onugem)
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700949 if err != nil {
950 logger.Error(ctx, "Failed to add onugem to kv store")
951 return err
952 }
953 } else {
954 logger.Debugw(ctx, "Gem port not found in onu gem info", log.Fields{"gem": gemPort})
955 }
956 return nil
957}
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530958
Joey Armstrong3f0e2422023-07-05 18:25:41 -0400959// GetOnuGemInfo gets onu gem info from the kvstore per interface
yasin saplibddc2d72022-02-08 13:10:17 +0000960func (rsrcMgr *OpenOltResourceMgr) GetOnuGemInfo(ctx context.Context, onuID uint32) (*OnuGemInfo, error) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700961 var err error
962 var Val []byte
963 var onugem OnuGemInfo
964
yasin saplibddc2d72022-02-08 13:10:17 +0000965 path := fmt.Sprintf(OnuGemInfoPath, rsrcMgr.PonIntfID, onuID)
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700966
967 rsrcMgr.onuGemInfoLock.RLock()
968 val, ok := rsrcMgr.onuGemInfo[path]
969 rsrcMgr.onuGemInfoLock.RUnlock()
970 if ok {
971 return val, nil
972 }
973 value, err := rsrcMgr.KVStore.Get(ctx, path)
974 if err != nil {
975 logger.Errorw(ctx, "Failed to get from kv store", log.Fields{"path": path})
976 return nil, err
977 } else if value == nil {
978 logger.Debug(ctx, "No onuinfo for path", log.Fields{"path": path})
979 return nil, nil // returning nil as this could happen if there are no onus for the interface yet
980 }
981 if Val, err = kvstore.ToByte(value.Value); err != nil {
982 logger.Error(ctx, "Failed to convert to byte array")
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530983 return nil, err
984 }
985
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700986 if err = json.Unmarshal(Val, &onugem); err != nil {
987 logger.Error(ctx, "Failed to unmarshall")
988 return nil, err
989 }
990 logger.Debugw(ctx, "found onugem info from path", log.Fields{"path": path, "onuGemInfo": onugem})
991 rsrcMgr.onuGemInfoLock.Lock()
992 rsrcMgr.onuGemInfo[path] = &onugem
993 rsrcMgr.onuGemInfoLock.Unlock()
994
995 return &onugem, nil
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530996}
997
Joey Armstrong3f0e2422023-07-05 18:25:41 -0400998// AddNewOnuGemInfoToCacheAndKvStore function adds a new onu gem info to cache and kvstore
yasin saplibddc2d72022-02-08 13:10:17 +0000999func (rsrcMgr *OpenOltResourceMgr) AddNewOnuGemInfoToCacheAndKvStore(ctx context.Context, onuID uint32, serialNum string) error {
yasin sapli9e4c5092022-02-01 13:52:33 +00001000
yasin saplibddc2d72022-02-08 13:10:17 +00001001 Path := fmt.Sprintf(OnuGemInfoPath, rsrcMgr.PonIntfID, onuID)
yasin sapli9e4c5092022-02-01 13:52:33 +00001002
1003 rsrcMgr.onuGemInfoLock.Lock()
1004 _, ok := rsrcMgr.onuGemInfo[Path]
1005 rsrcMgr.onuGemInfoLock.Unlock()
1006
1007 // If the ONU already exists in onuGemInfo list, nothing to do
1008 if ok {
1009 logger.Debugw(ctx, "onu-id-already-exists-in-cache", log.Fields{"onuID": onuID, "serialNum": serialNum})
1010 return nil
1011 }
1012
yasin saplibddc2d72022-02-08 13:10:17 +00001013 onuGemInfo := OnuGemInfo{OnuID: onuID, SerialNumber: serialNum, IntfID: rsrcMgr.PonIntfID}
yasin sapli9e4c5092022-02-01 13:52:33 +00001014
yasin saplibddc2d72022-02-08 13:10:17 +00001015 if err := rsrcMgr.AddOnuGemInfo(ctx, onuID, onuGemInfo); err != nil {
yasin sapli9e4c5092022-02-01 13:52:33 +00001016 return err
1017 }
1018 logger.Infow(ctx, "added-onuinfo",
1019 log.Fields{
yasin saplibddc2d72022-02-08 13:10:17 +00001020 "intf-id": rsrcMgr.PonIntfID,
yasin sapli9e4c5092022-02-01 13:52:33 +00001021 "onu-id": onuID,
1022 "serial-num": serialNum,
1023 "onu": onuGemInfo,
1024 "device-id": rsrcMgr.DeviceID})
1025 return nil
1026}
1027
Chaitrashree G S1a55b882020-02-04 17:35:35 -05001028// AddOnuGemInfo adds onu info on to the kvstore per interface
yasin saplibddc2d72022-02-08 13:10:17 +00001029func (rsrcMgr *OpenOltResourceMgr) AddOnuGemInfo(ctx context.Context, onuID uint32, onuGem OnuGemInfo) error {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001030
1031 var Value []byte
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301032 var err error
yasin saplibddc2d72022-02-08 13:10:17 +00001033 Path := fmt.Sprintf(OnuGemInfoPath, rsrcMgr.PonIntfID, onuID)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301034
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001035 Value, err = json.Marshal(onuGem)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301036 if err != nil {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001037 logger.Error(ctx, "failed to Marshal")
1038 return err
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301039 }
1040
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001041 if err = rsrcMgr.KVStore.Put(ctx, Path, Value); err != nil {
1042 logger.Errorf(ctx, "Failed to update resource %s", Path)
1043 return err
1044 }
yasin sapli9e4c5092022-02-01 13:52:33 +00001045 logger.Debugw(ctx, "added onu gem info to store", log.Fields{"onuGemInfo": onuGem, "Path": Path})
Gamze Abaka745ccb72021-11-18 11:29:58 +00001046
1047 //update cache
1048 rsrcMgr.onuGemInfoLock.Lock()
1049 rsrcMgr.onuGemInfo[Path] = &onuGem
1050 rsrcMgr.onuGemInfoLock.Unlock()
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001051 return err
1052}
1053
1054// DelOnuGemInfo deletes the onugem info from kvstore per ONU
yasin saplibddc2d72022-02-08 13:10:17 +00001055func (rsrcMgr *OpenOltResourceMgr) DelOnuGemInfo(ctx context.Context, onuID uint32) error {
1056 path := fmt.Sprintf(OnuGemInfoPath, rsrcMgr.PonIntfID, onuID)
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001057
1058 if err := rsrcMgr.KVStore.Delete(ctx, path); err != nil {
1059 logger.Errorf(ctx, "failed to remove resource %s", path)
1060 return err
1061 }
Gamze Abaka745ccb72021-11-18 11:29:58 +00001062
1063 //update cache
1064 rsrcMgr.onuGemInfoLock.Lock()
1065 logger.Debugw(ctx, "removing onu gem info", log.Fields{"onuGemInfo": rsrcMgr.onuGemInfo[path]})
1066 delete(rsrcMgr.onuGemInfo, path)
1067 rsrcMgr.onuGemInfoLock.Unlock()
Andrea Campanellab83b39d2020-03-30 11:41:16 +02001068 return nil
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301069}
1070
Joey Armstrong3f0e2422023-07-05 18:25:41 -04001071// DeleteAllOnuGemInfoForIntf deletes all the all onu gem info on the given pon interface
yasin saplibddc2d72022-02-08 13:10:17 +00001072func (rsrcMgr *OpenOltResourceMgr) DeleteAllOnuGemInfoForIntf(ctx context.Context) error {
Girish Gowdra950326e2021-11-05 12:43:24 -07001073
yasin saplibddc2d72022-02-08 13:10:17 +00001074 path := fmt.Sprintf(OnuGemInfoPathPathPrefix, rsrcMgr.PonIntfID)
Girish Gowdra950326e2021-11-05 12:43:24 -07001075
yasin saplibddc2d72022-02-08 13:10:17 +00001076 logger.Debugw(ctx, "delete-all-onu-gem-info-for-pon-intf", log.Fields{"intfID": rsrcMgr.PonIntfID})
Girish Gowdra950326e2021-11-05 12:43:24 -07001077 if err := rsrcMgr.KVStore.DeleteWithPrefix(ctx, path); err != nil {
1078 logger.Errorf(ctx, "failed-to-remove-resource-%s", path)
1079 return err
1080 }
1081
1082 // Reset cache. Normally not necessary as the entire device is getting deleted when this API is invoked.
1083 rsrcMgr.onuGemInfoLock.Lock()
1084 rsrcMgr.onuGemInfo = make(map[string]*OnuGemInfo)
1085 rsrcMgr.onuGemInfoLock.Unlock()
1086 return nil
1087}
1088
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301089// AddUniPortToOnuInfo adds uni port to the onuinfo kvstore. check if the uni is already present if not update the kv store.
yasin saplibddc2d72022-02-08 13:10:17 +00001090func (rsrcMgr *OpenOltResourceMgr) AddUniPortToOnuInfo(ctx context.Context, onuID uint32, portNo uint32) {
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301091
yasin saplibddc2d72022-02-08 13:10:17 +00001092 onugem, err := rsrcMgr.GetOnuGemInfo(ctx, onuID)
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001093 if err != nil || onugem == nil || onugem.SerialNumber == "" {
yasin saplibddc2d72022-02-08 13:10:17 +00001094 logger.Warnf(ctx, "failed to get onuifo for intfid %d", rsrcMgr.PonIntfID)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301095 return
1096 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001097
1098 if onugem.OnuID == onuID {
1099 for _, uni := range onugem.UniPorts {
1100 if uni == portNo {
1101 logger.Debugw(ctx, "uni already present in onugem info", log.Fields{"uni": portNo})
1102 return
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301103 }
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301104 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001105 onugem.UniPorts = append(onugem.UniPorts, portNo)
1106 } else {
yasin saplibddc2d72022-02-08 13:10:17 +00001107 logger.Warnw(ctx, "onu id mismatch in onu gem info", log.Fields{"intfID": rsrcMgr.PonIntfID, "onuID": onuID})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001108 return
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301109 }
yasin saplibddc2d72022-02-08 13:10:17 +00001110 err = rsrcMgr.AddOnuGemInfo(ctx, onuID, *onugem)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301111 if err != nil {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001112 logger.Errorw(ctx, "Failed to add uni port in onugem to kv store", log.Fields{"uni": portNo})
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301113 return
1114 }
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301115}
1116
Joey Armstrong3f0e2422023-07-05 18:25:41 -04001117// UpdateGemPortForPktIn updates gemport for pkt in path to kvstore, path being intfid, onuid, portno, vlan id, priority bit
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001118func (rsrcMgr *OpenOltResourceMgr) UpdateGemPortForPktIn(ctx context.Context, pktIn PacketInInfoKey, gemPort uint32) {
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301119
Girish Gowdra950326e2021-11-05 12:43:24 -07001120 path := fmt.Sprintf(OnuPacketInPath, pktIn.IntfID, pktIn.OnuID, pktIn.LogicalPort, pktIn.VlanID, pktIn.Priority)
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001121
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301122 Value, err := json.Marshal(gemPort)
1123 if err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001124 logger.Error(ctx, "Failed to marshal data")
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301125 return
1126 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001127 if err = rsrcMgr.KVStore.Put(ctx, path, Value); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001128 logger.Errorw(ctx, "Failed to put to kvstore", log.Fields{"path": path, "value": gemPort})
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301129 return
1130 }
Gamze Abaka745ccb72021-11-18 11:29:58 +00001131
1132 // update cache
1133 rsrcMgr.gemPortForPacketInInfoLock.Lock()
1134 rsrcMgr.gemPortForPacketInInfo[path] = gemPort
1135 rsrcMgr.gemPortForPacketInInfoLock.Unlock()
Neha Sharma96b7bf22020-06-15 10:37:32 +00001136 logger.Debugw(ctx, "added gem packet in successfully", log.Fields{"path": path, "gem": gemPort})
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301137}
1138
Esin Karaman7fb80c22020-07-16 14:23:33 +00001139// GetGemPortFromOnuPktIn gets the gem port from onu pkt in path, path being intfid, onuid, portno, vlan id, priority bit
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001140func (rsrcMgr *OpenOltResourceMgr) GetGemPortFromOnuPktIn(ctx context.Context, packetInInfoKey PacketInInfoKey) (uint32, error) {
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301141
1142 var Val []byte
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301143
Girish Gowdra950326e2021-11-05 12:43:24 -07001144 path := fmt.Sprintf(OnuPacketInPath, packetInInfoKey.IntfID, packetInInfoKey.OnuID, packetInInfoKey.LogicalPort,
Esin Karaman7fb80c22020-07-16 14:23:33 +00001145 packetInInfoKey.VlanID, packetInInfoKey.Priority)
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001146 // get from cache
1147 rsrcMgr.gemPortForPacketInInfoLock.RLock()
1148 gemPort, ok := rsrcMgr.gemPortForPacketInInfo[path]
1149 rsrcMgr.gemPortForPacketInInfoLock.RUnlock()
1150 if ok {
1151 logger.Debugw(ctx, "found packein gemport from path", log.Fields{"path": path, "gem": gemPort})
1152 return gemPort, nil
1153 }
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301154
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001155 value, err := rsrcMgr.KVStore.Get(ctx, path)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301156 if err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001157 logger.Errorw(ctx, "Failed to get from kv store", log.Fields{"path": path})
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301158 return uint32(0), err
1159 } else if value == nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001160 logger.Debugw(ctx, "No pkt in gem found", log.Fields{"path": path})
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301161 return uint32(0), nil
1162 }
1163
1164 if Val, err = kvstore.ToByte(value.Value); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001165 logger.Error(ctx, "Failed to convert to byte array")
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301166 return uint32(0), err
1167 }
1168 if err = json.Unmarshal(Val, &gemPort); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001169 logger.Error(ctx, "Failed to unmarshall")
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301170 return uint32(0), err
1171 }
Neha Sharma96b7bf22020-06-15 10:37:32 +00001172 logger.Debugw(ctx, "found packein gemport from path", log.Fields{"path": path, "gem": gemPort})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001173 // update cache
1174 rsrcMgr.gemPortForPacketInInfoLock.Lock()
1175 rsrcMgr.gemPortForPacketInInfo[path] = gemPort
1176 rsrcMgr.gemPortForPacketInInfoLock.Unlock()
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301177
1178 return gemPort, nil
1179}
1180
Joey Armstrong3f0e2422023-07-05 18:25:41 -04001181// DeletePacketInGemPortForOnu deletes the packet-in gemport for ONU
yasin saplibddc2d72022-02-08 13:10:17 +00001182func (rsrcMgr *OpenOltResourceMgr) DeletePacketInGemPortForOnu(ctx context.Context, onuID uint32, logicalPort uint32) error {
1183 path := fmt.Sprintf(OnuPacketInPathPrefix, rsrcMgr.PonIntfID, onuID, logicalPort)
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001184 value, err := rsrcMgr.KVStore.List(ctx, path)
Esin Karaman7fb80c22020-07-16 14:23:33 +00001185 if err != nil {
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001186 logger.Errorf(ctx, "failed-to-read-value-from-path-%s", path)
1187 return errors.New("failed-to-read-value-from-path-" + path)
Esin Karaman7fb80c22020-07-16 14:23:33 +00001188 }
Esin Karaman7fb80c22020-07-16 14:23:33 +00001189
Gamze Abaka745ccb72021-11-18 11:29:58 +00001190 logger.Debugw(ctx, "delete-packetin-gem-port", log.Fields{"realPath": path})
1191 if err := rsrcMgr.KVStore.DeleteWithPrefix(ctx, path); err != nil {
1192 logger.Errorf(ctx, "failed-to-remove-resource-%s", path)
1193 return err
1194 }
1195
Esin Karaman7fb80c22020-07-16 14:23:33 +00001196 //remove them one by one
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001197 for key := range value {
serkant.uluderya4f5ed592020-12-17 20:57:59 +03001198 // Remove the PathPrefix from the path on KV key.
Girish Gowdra950326e2021-11-05 12:43:24 -07001199 // gemPortForPacketInInfo cache uses OnuPacketInPath as the key
serkant.uluderya4f5ed592020-12-17 20:57:59 +03001200 stringToBeReplaced := rsrcMgr.KVStore.PathPrefix + "/"
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001201 replacedWith := ""
1202 key = strings.Replace(key, stringToBeReplaced, replacedWith, 1)
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001203 // update cache
1204 rsrcMgr.gemPortForPacketInInfoLock.Lock()
1205 delete(rsrcMgr.gemPortForPacketInInfo, key)
1206 rsrcMgr.gemPortForPacketInInfoLock.Unlock()
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001207
serkant.uluderya4f5ed592020-12-17 20:57:59 +03001208 logger.Debugw(ctx, "removed-key-from-packetin-gem-port-cache", log.Fields{"key": key, "cache-len": len(rsrcMgr.gemPortForPacketInInfo)})
1209 }
1210
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301211 return nil
1212}
1213
Joey Armstrong3f0e2422023-07-05 18:25:41 -04001214// GetFlowIDsForGem gets the list of FlowIDs for the given gemport
yasin saplibddc2d72022-02-08 13:10:17 +00001215func (rsrcMgr *OpenOltResourceMgr) GetFlowIDsForGem(ctx context.Context, gem uint32) ([]uint64, error) {
1216 path := fmt.Sprintf(FlowIDsForGem, rsrcMgr.PonIntfID, gem)
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001217
1218 // get from cache
1219 rsrcMgr.flowIDsForGemLock.RLock()
1220 flowIDs, ok := rsrcMgr.flowIDsForGem[gem]
1221 rsrcMgr.flowIDsForGemLock.RUnlock()
1222 if ok {
1223 return flowIDs, nil
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301224 }
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301225
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001226 value, err := rsrcMgr.KVStore.Get(ctx, path)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301227 if err != nil {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001228 logger.Errorw(ctx, "Failed to get from kv store", log.Fields{"path": path})
1229 return nil, err
yasin saplid0566272021-12-21 09:10:30 +00001230 } else if value == nil || value.Value == nil {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001231 logger.Debug(ctx, "no flow-ids found", log.Fields{"path": path})
1232 return nil, nil
1233 }
1234 Val, err := kvstore.ToByte(value.Value)
1235 if err != nil {
1236 logger.Error(ctx, "Failed to convert to byte array")
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301237 return nil, err
1238 }
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301239
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001240 if err = json.Unmarshal(Val, &flowIDs); err != nil {
1241 logger.Error(ctx, "Failed to unmarshall")
1242 return nil, err
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301243 }
1244
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001245 // update cache
1246 rsrcMgr.flowIDsForGemLock.Lock()
1247 rsrcMgr.flowIDsForGem[gem] = flowIDs
1248 rsrcMgr.flowIDsForGemLock.Unlock()
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301249
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001250 return flowIDs, nil
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301251}
Abhilash Laxmeshwar275c0742019-11-25 16:47:02 +05301252
yasin sapli9e4c5092022-02-01 13:52:33 +00001253// IsGemPortUsedByAnotherFlow returns true if given gem is used by another flow
Girish Gowdrab4c33302022-03-18 15:07:38 -07001254func (rsrcMgr *OpenOltResourceMgr) IsGemPortUsedByAnotherFlow(ctx context.Context, gemPortID uint32, flowID uint64) (bool, error) {
1255 flowIDList, err := rsrcMgr.GetFlowIDsForGem(ctx, gemPortID)
1256 if err != nil {
1257 return false, err
1258 }
yasin sapli9e4c5092022-02-01 13:52:33 +00001259 for _, id := range flowIDList {
1260 if flowID != id {
Girish Gowdrab4c33302022-03-18 15:07:38 -07001261 return true, nil
yasin sapli9e4c5092022-02-01 13:52:33 +00001262 }
1263 }
Girish Gowdrab4c33302022-03-18 15:07:38 -07001264 return false, nil
yasin sapli9e4c5092022-02-01 13:52:33 +00001265}
1266
1267// RegisterFlowIDForGem updates both cache and KV store for flowIDsForGem map
yasin saplibddc2d72022-02-08 13:10:17 +00001268func (rsrcMgr *OpenOltResourceMgr) RegisterFlowIDForGem(ctx context.Context, gemPortID uint32, flowFromCore *ofp.OfpFlowStats) error {
Girish Gowdrab4c33302022-03-18 15:07:38 -07001269 flowIDs, err := rsrcMgr.GetFlowIDsForGem(ctx, gemPortID)
1270 if err != nil {
1271 return err
yasin sapli9e4c5092022-02-01 13:52:33 +00001272 }
Girish Gowdrab4c33302022-03-18 15:07:38 -07001273
1274 flowIDs = appendUnique64bit(flowIDs, flowFromCore.Id)
yasin sapli9e4c5092022-02-01 13:52:33 +00001275 // update the flowids for a gem to the KVstore
yasin saplibddc2d72022-02-08 13:10:17 +00001276 return rsrcMgr.UpdateFlowIDsForGem(ctx, gemPortID, flowIDs)
yasin sapli9e4c5092022-02-01 13:52:33 +00001277}
1278
Joey Armstrong3f0e2422023-07-05 18:25:41 -04001279// UpdateFlowIDsForGem updates flow id per gemport
yasin saplibddc2d72022-02-08 13:10:17 +00001280func (rsrcMgr *OpenOltResourceMgr) UpdateFlowIDsForGem(ctx context.Context, gem uint32, flowIDs []uint64) error {
Abhilash Laxmeshwar275c0742019-11-25 16:47:02 +05301281 var val []byte
yasin saplibddc2d72022-02-08 13:10:17 +00001282 path := fmt.Sprintf(FlowIDsForGem, rsrcMgr.PonIntfID, gem)
Abhilash Laxmeshwar275c0742019-11-25 16:47:02 +05301283
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001284 if flowIDs == nil {
Girish Gowdra950326e2021-11-05 12:43:24 -07001285 if err := rsrcMgr.KVStore.Delete(ctx, path); err != nil {
1286 logger.Errorw(ctx, "Failed to delete from kvstore", log.Fields{"err": err, "path": path})
1287 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001288 return nil
Abhilash Laxmeshwar275c0742019-11-25 16:47:02 +05301289 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001290 val, err := json.Marshal(flowIDs)
Abhilash Laxmeshwar275c0742019-11-25 16:47:02 +05301291 if err != nil {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001292 logger.Error(ctx, "Failed to marshal data", log.Fields{"err": err})
Abhilash Laxmeshwar275c0742019-11-25 16:47:02 +05301293 return err
1294 }
Girish Gowdrab77ded92020-04-08 11:45:05 -07001295
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001296 if err = rsrcMgr.KVStore.Put(ctx, path, val); err != nil {
1297 logger.Errorw(ctx, "Failed to put to kvstore", log.Fields{"err": err, "path": path, "value": val})
Abhilash Laxmeshwar275c0742019-11-25 16:47:02 +05301298 return err
1299 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001300 logger.Debugw(ctx, "added flowid list for gem to kv successfully", log.Fields{"path": path, "flowidlist": flowIDs})
Gamze Abaka745ccb72021-11-18 11:29:58 +00001301
1302 // update cache
1303 rsrcMgr.flowIDsForGemLock.Lock()
1304 rsrcMgr.flowIDsForGem[gem] = flowIDs
1305 rsrcMgr.flowIDsForGemLock.Unlock()
Abhilash Laxmeshwar275c0742019-11-25 16:47:02 +05301306 return nil
1307}
1308
Joey Armstrong3f0e2422023-07-05 18:25:41 -04001309// DeleteFlowIDsForGem deletes the flowID list entry per gem from kvstore.
yasin saplibddc2d72022-02-08 13:10:17 +00001310func (rsrcMgr *OpenOltResourceMgr) DeleteFlowIDsForGem(ctx context.Context, gem uint32) error {
1311 path := fmt.Sprintf(FlowIDsForGem, rsrcMgr.PonIntfID, gem)
Gamze Abaka745ccb72021-11-18 11:29:58 +00001312 if err := rsrcMgr.KVStore.Delete(ctx, path); err != nil {
1313 logger.Errorw(ctx, "Failed to delete from kvstore", log.Fields{"err": err, "path": path})
1314 return err
1315 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001316 // update cache
1317 rsrcMgr.flowIDsForGemLock.Lock()
1318 delete(rsrcMgr.flowIDsForGem, gem)
1319 rsrcMgr.flowIDsForGemLock.Unlock()
Gamze Abaka745ccb72021-11-18 11:29:58 +00001320 return nil
Abhilash Laxmeshwar6d1acb92020-01-17 15:43:03 +05301321}
Esin Karamanccb714b2019-11-29 15:02:06 +00001322
Joey Armstrong3f0e2422023-07-05 18:25:41 -04001323// DeleteAllFlowIDsForGemForIntf deletes all the flow ids associated for all the gems on the given pon interface
yasin saplibddc2d72022-02-08 13:10:17 +00001324func (rsrcMgr *OpenOltResourceMgr) DeleteAllFlowIDsForGemForIntf(ctx context.Context) error {
1325 path := fmt.Sprintf(FlowIDsForGemPathPrefix, rsrcMgr.PonIntfID)
Girish Gowdra950326e2021-11-05 12:43:24 -07001326
yasin saplibddc2d72022-02-08 13:10:17 +00001327 logger.Debugw(ctx, "delete-flow-ids-for-gem-for-pon-intf", log.Fields{"intfID": rsrcMgr.PonIntfID})
Girish Gowdra950326e2021-11-05 12:43:24 -07001328 if err := rsrcMgr.KVStore.DeleteWithPrefix(ctx, path); err != nil {
1329 logger.Errorf(ctx, "failed-to-remove-resource-%s", path)
1330 return err
1331 }
1332
1333 // Reset cache. Normally not necessary as the entire device is getting deleted when this API is invoked.
1334 rsrcMgr.flowIDsForGemLock.Lock()
1335 rsrcMgr.flowIDsForGem = make(map[uint32][]uint64)
1336 rsrcMgr.flowIDsForGemLock.Unlock()
1337 return nil
1338}
1339
Joey Armstrong3f0e2422023-07-05 18:25:41 -04001340// GetMcastQueuePerInterfaceMap gets multicast queue info per pon interface
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001341func (rsrcMgr *OpenOltResourceMgr) GetMcastQueuePerInterfaceMap(ctx context.Context) (map[uint32][]uint32, error) {
Kent Hagermane6ff1012020-07-14 15:07:53 -04001342 path := McastQueuesForIntf
Esin Karamanccb714b2019-11-29 15:02:06 +00001343 var val []byte
1344
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001345 rsrcMgr.mcastQueueForIntfLock.RLock()
1346 if rsrcMgr.mcastQueueForIntfLoadedFromKvStore {
1347 rsrcMgr.mcastQueueForIntfLock.RUnlock()
1348 return rsrcMgr.mcastQueueForIntf, nil
1349 }
1350 rsrcMgr.mcastQueueForIntfLock.RUnlock()
1351
1352 kvPair, err := rsrcMgr.KVStore.Get(ctx, path)
Esin Karamanccb714b2019-11-29 15:02:06 +00001353 if err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001354 logger.Error(ctx, "failed to get data from kv store")
Esin Karamanccb714b2019-11-29 15:02:06 +00001355 return nil, err
1356 }
1357 if kvPair != nil && kvPair.Value != nil {
1358 if val, err = kvstore.ToByte(kvPair.Value); err != nil {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001359 logger.Error(ctx, "Failed to convert to byte array ", log.Fields{"err": err})
Esin Karamanccb714b2019-11-29 15:02:06 +00001360 return nil, err
1361 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001362 rsrcMgr.mcastQueueForIntfLock.Lock()
1363 defer rsrcMgr.mcastQueueForIntfLock.Unlock()
1364 if err = json.Unmarshal(val, &rsrcMgr.mcastQueueForIntf); err != nil {
1365 logger.Error(ctx, "Failed to unmarshall ", log.Fields{"err": err})
Esin Karamanccb714b2019-11-29 15:02:06 +00001366 return nil, err
1367 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001368 rsrcMgr.mcastQueueForIntfLoadedFromKvStore = true
Esin Karamanccb714b2019-11-29 15:02:06 +00001369 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001370 return rsrcMgr.mcastQueueForIntf, nil
Esin Karamanccb714b2019-11-29 15:02:06 +00001371}
1372
Joey Armstrong3f0e2422023-07-05 18:25:41 -04001373// AddMcastQueueForIntf adds multicast queue for pon interface
yasin saplibddc2d72022-02-08 13:10:17 +00001374func (rsrcMgr *OpenOltResourceMgr) AddMcastQueueForIntf(ctx context.Context, gem uint32, servicePriority uint32) error {
Esin Karamanccb714b2019-11-29 15:02:06 +00001375 var val []byte
Kent Hagermane6ff1012020-07-14 15:07:53 -04001376 path := McastQueuesForIntf
Esin Karamanccb714b2019-11-29 15:02:06 +00001377
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001378 // Load local cache from kv store the first time
1379 rsrcMgr.mcastQueueForIntfLock.RLock()
1380 if !rsrcMgr.mcastQueueForIntfLoadedFromKvStore {
1381 rsrcMgr.mcastQueueForIntfLock.RUnlock()
1382 _, err := rsrcMgr.GetMcastQueuePerInterfaceMap(ctx)
1383 if err != nil {
yasin saplibddc2d72022-02-08 13:10:17 +00001384 logger.Errorw(ctx, "Failed to get multicast queue info for interface", log.Fields{"err": err, "intf": rsrcMgr.PonIntfID})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001385 return err
1386 }
1387 } else {
1388 rsrcMgr.mcastQueueForIntfLock.RUnlock()
1389 }
1390
1391 // Update KV store
1392 rsrcMgr.mcastQueueForIntfLock.Lock()
yasin saplibddc2d72022-02-08 13:10:17 +00001393 rsrcMgr.mcastQueueForIntf[rsrcMgr.PonIntfID] = []uint32{gem, servicePriority}
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001394 val, err := json.Marshal(rsrcMgr.mcastQueueForIntf)
Esin Karamanccb714b2019-11-29 15:02:06 +00001395 if err != nil {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001396 rsrcMgr.mcastQueueForIntfLock.Unlock()
1397 logger.Errorw(ctx, "Failed to marshal data", log.Fields{"err": err})
Esin Karamanccb714b2019-11-29 15:02:06 +00001398 return err
1399 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001400 rsrcMgr.mcastQueueForIntfLock.Unlock()
1401
1402 if err = rsrcMgr.KVStore.Put(ctx, path, val); err != nil {
1403 logger.Errorw(ctx, "Failed to put to kvstore", log.Fields{"err": err, "path": path, "value": val})
Esin Karamanccb714b2019-11-29 15:02:06 +00001404 return err
1405 }
yasin saplibddc2d72022-02-08 13:10:17 +00001406 logger.Debugw(ctx, "added multicast queue info to KV store successfully", log.Fields{"path": path, "interfaceId": rsrcMgr.PonIntfID, "gem": gem, "svcPrior": servicePriority})
Esin Karamanccb714b2019-11-29 15:02:06 +00001407 return nil
1408}
1409
Joey Armstrong3f0e2422023-07-05 18:25:41 -04001410// DeleteMcastQueueForIntf deletes multicast queue info for the current pon interface from kvstore
Gustavo Silva41af9122022-10-11 11:05:13 -03001411func (rsrcMgr *OpenOltResourceMgr) DeleteMcastQueueForIntf(ctx context.Context) error {
Girish Gowdraf3728b12022-02-02 21:46:51 -08001412 path := McastQueuesForIntf
1413
1414 if err := rsrcMgr.KVStore.Delete(ctx, path); err != nil {
1415 logger.Errorw(ctx, "Failed to delete multicast queue info from kvstore", log.Fields{"err": err, "interfaceId": rsrcMgr.PonIntfID})
Gustavo Silva41af9122022-10-11 11:05:13 -03001416 return err
Girish Gowdraf3728b12022-02-02 21:46:51 -08001417 }
1418 logger.Debugw(ctx, "deleted multicast queue info from KV store successfully", log.Fields{"interfaceId": rsrcMgr.PonIntfID})
Gustavo Silva41af9122022-10-11 11:05:13 -03001419 return nil
Girish Gowdraf3728b12022-02-02 21:46:51 -08001420}
1421
Joey Armstrong3f0e2422023-07-05 18:25:41 -04001422// AddFlowGroupToKVStore adds flow group into KV store
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001423func (rsrcMgr *OpenOltResourceMgr) AddFlowGroupToKVStore(ctx context.Context, groupEntry *ofp.OfpGroupEntry, cached bool) error {
Esin Karamanccb714b2019-11-29 15:02:06 +00001424 var Value []byte
1425 var err error
1426 var path string
1427 if cached {
1428 path = fmt.Sprintf(FlowGroupCached, groupEntry.Desc.GroupId)
1429 } else {
1430 path = fmt.Sprintf(FlowGroup, groupEntry.Desc.GroupId)
1431 }
1432 //build group info object
1433 var outPorts []uint32
1434 for _, ofBucket := range groupEntry.Desc.Buckets {
1435 for _, ofAction := range ofBucket.Actions {
1436 if ofAction.Type == ofp.OfpActionType_OFPAT_OUTPUT {
1437 outPorts = append(outPorts, ofAction.GetOutput().Port)
1438 }
1439 }
1440 }
1441 groupInfo := GroupInfo{
1442 GroupID: groupEntry.Desc.GroupId,
1443 OutPorts: outPorts,
1444 }
1445
1446 Value, err = json.Marshal(groupInfo)
1447
1448 if err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001449 logger.Error(ctx, "failed to Marshal flow group object")
Esin Karamanccb714b2019-11-29 15:02:06 +00001450 return err
1451 }
1452
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001453 if err = rsrcMgr.KVStore.Put(ctx, path, Value); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001454 logger.Errorf(ctx, "Failed to update resource %s", path)
Esin Karamanccb714b2019-11-29 15:02:06 +00001455 return err
1456 }
Gamze Abaka745ccb72021-11-18 11:29:58 +00001457
1458 // update cache
1459 rsrcMgr.groupInfoLock.Lock()
1460 rsrcMgr.groupInfo[path] = &groupInfo
1461 rsrcMgr.groupInfoLock.Unlock()
Esin Karamanccb714b2019-11-29 15:02:06 +00001462 return nil
1463}
1464
Joey Armstrong3f0e2422023-07-05 18:25:41 -04001465// RemoveFlowGroupFromKVStore removes flow group from KV store
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001466func (rsrcMgr *OpenOltResourceMgr) RemoveFlowGroupFromKVStore(ctx context.Context, groupID uint32, cached bool) error {
Esin Karamanccb714b2019-11-29 15:02:06 +00001467 var path string
1468 if cached {
1469 path = fmt.Sprintf(FlowGroupCached, groupID)
1470 } else {
1471 path = fmt.Sprintf(FlowGroup, groupID)
1472 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001473
1474 if err := rsrcMgr.KVStore.Delete(ctx, path); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001475 logger.Errorf(ctx, "Failed to remove resource %s due to %s", path, err)
Esin Karamand519bbf2020-07-01 11:16:03 +00001476 return err
Esin Karamanccb714b2019-11-29 15:02:06 +00001477 }
Gamze Abaka745ccb72021-11-18 11:29:58 +00001478
1479 // update cache
1480 rsrcMgr.groupInfoLock.Lock()
1481 delete(rsrcMgr.groupInfo, path)
1482 rsrcMgr.groupInfoLock.Unlock()
Esin Karamand519bbf2020-07-01 11:16:03 +00001483 return nil
Esin Karamanccb714b2019-11-29 15:02:06 +00001484}
1485
Joey Armstrong3f0e2422023-07-05 18:25:41 -04001486// GetFlowGroupFromKVStore fetches flow group from the KV store. Returns (false, {} error) if any problem occurs during
1487// fetching the data. Returns (true, groupInfo, nil) if the group is fetched successfully.
Esin Karamanccb714b2019-11-29 15:02:06 +00001488// Returns (false, {}, nil) if the group does not exists in the KV store.
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001489func (rsrcMgr *OpenOltResourceMgr) GetFlowGroupFromKVStore(ctx context.Context, groupID uint32, cached bool) (bool, GroupInfo, error) {
Esin Karamanccb714b2019-11-29 15:02:06 +00001490 var groupInfo GroupInfo
1491 var path string
1492 if cached {
1493 path = fmt.Sprintf(FlowGroupCached, groupID)
1494 } else {
1495 path = fmt.Sprintf(FlowGroup, groupID)
1496 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001497
1498 // read from cache
1499 rsrcMgr.groupInfoLock.RLock()
1500 gi, ok := rsrcMgr.groupInfo[path]
1501 rsrcMgr.groupInfoLock.RUnlock()
1502 if ok {
1503 return true, *gi, nil
1504 }
1505
1506 kvPair, err := rsrcMgr.KVStore.Get(ctx, path)
Esin Karamanccb714b2019-11-29 15:02:06 +00001507 if err != nil {
1508 return false, groupInfo, err
1509 }
1510 if kvPair != nil && kvPair.Value != nil {
1511 Val, err := kvstore.ToByte(kvPair.Value)
1512 if err != nil {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001513 logger.Errorw(ctx, "Failed to convert flow group into byte array", log.Fields{"err": err})
Esin Karamanccb714b2019-11-29 15:02:06 +00001514 return false, groupInfo, err
1515 }
1516 if err = json.Unmarshal(Val, &groupInfo); err != nil {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001517 logger.Errorw(ctx, "Failed to unmarshal", log.Fields{"err": err})
Esin Karamanccb714b2019-11-29 15:02:06 +00001518 return false, groupInfo, err
1519 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001520 // update cache
1521 rsrcMgr.groupInfoLock.Lock()
1522 rsrcMgr.groupInfo[path] = &groupInfo
1523 rsrcMgr.groupInfoLock.Unlock()
1524
Esin Karamanccb714b2019-11-29 15:02:06 +00001525 return true, groupInfo, nil
1526 }
1527 return false, groupInfo, nil
1528}
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001529
yasin sapli9e4c5092022-02-01 13:52:33 +00001530// GetOnuGemInfoList returns all gems in the onuGemInfo map
1531func (rsrcMgr *OpenOltResourceMgr) GetOnuGemInfoList(ctx context.Context) []OnuGemInfo {
1532 var onuGemInfoLst []OnuGemInfo
1533 rsrcMgr.onuGemInfoLock.RLock()
1534 defer rsrcMgr.onuGemInfoLock.RUnlock()
1535 for _, v := range rsrcMgr.onuGemInfo {
1536 onuGemInfoLst = append(onuGemInfoLst, *v)
1537 }
1538 return onuGemInfoLst
1539}
1540
yasin sapli9e4c5092022-02-01 13:52:33 +00001541func appendUnique64bit(slice []uint64, item uint64) []uint64 {
1542 for _, sliceElement := range slice {
1543 if sliceElement == item {
1544 return slice
1545 }
1546 }
1547 return append(slice, item)
1548}