Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 1 | /* |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 2 | * Copyright 2020-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 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 | |
praneeth kumar nalmas | 3947c58 | 2023-12-13 15:38:50 +0530 | [diff] [blame] | 17 | // Package devdb provides access to internal device ME DB |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 18 | package devdb |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
Holger Hildebrandt | f3c7a18 | 2021-11-17 13:42:08 +0000 | [diff] [blame] | 22 | "encoding/hex" |
Holger Hildebrandt | 2ff21f1 | 2020-08-13 14:38:02 +0000 | [diff] [blame] | 23 | "fmt" |
| 24 | "reflect" |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 25 | "sort" |
Mahir Gunyel | 7f4483a | 2021-05-06 12:53:43 -0700 | [diff] [blame] | 26 | "sync" |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 27 | |
mpagenko | 836a1fd | 2021-11-01 16:12:42 +0000 | [diff] [blame] | 28 | me "github.com/opencord/omci-lib-go/v2/generated" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 29 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 30 | ) |
| 31 | |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 32 | // MeDbMap type holds MEs that are known to the ONT. |
| 33 | type MeDbMap map[me.ClassID]map[uint16]me.AttributeValueMap |
| 34 | |
| 35 | // UnknownMeAndAttribDbMap type holds MEs that are Unknown to the ONT. |
| 36 | type UnknownMeAndAttribDbMap map[UnknownMeOrAttribName]map[me.ClassID]map[uint16]unknownAttribs |
| 37 | |
| 38 | // OnuMCmnMEDBMap type holds MEs that are classified as Unknown to the ONT. |
| 39 | type OnuMCmnMEDBMap map[string]*OnuCmnMEDB |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 40 | |
Holger Hildebrandt | 3908002 | 2022-03-16 10:03:17 +0000 | [diff] [blame] | 41 | // UnknownMeOrAttribName type to be used for unknown ME and attribute names |
| 42 | type UnknownMeOrAttribName string |
Holger Hildebrandt | f3c7a18 | 2021-11-17 13:42:08 +0000 | [diff] [blame] | 43 | |
Holger Hildebrandt | 3908002 | 2022-03-16 10:03:17 +0000 | [diff] [blame] | 44 | // names for unknown ME and attribute identifiers |
Holger Hildebrandt | f3c7a18 | 2021-11-17 13:42:08 +0000 | [diff] [blame] | 45 | const ( |
| 46 | CUnknownItuG988ManagedEntity = "UnknownItuG988ManagedEntity" |
| 47 | CUnknownVendorSpecificManagedEntity = "UnknownVendorSpecificManagedEntity" |
Holger Hildebrandt | 3908002 | 2022-03-16 10:03:17 +0000 | [diff] [blame] | 48 | CUnknownAttributesManagedEntity = "UnknownAttributesManagedEntity" |
Holger Hildebrandt | f3c7a18 | 2021-11-17 13:42:08 +0000 | [diff] [blame] | 49 | ) |
| 50 | |
Holger Hildebrandt | 3908002 | 2022-03-16 10:03:17 +0000 | [diff] [blame] | 51 | // CStartUnknownMeAttribsInBaseLayerPayload defines start of unknown ME attribs after ClassID, InstanceID and AttribMask |
| 52 | const CStartUnknownMeAttribsInBaseLayerPayload = 6 |
| 53 | |
| 54 | type unknownAttribs struct { |
Holger Hildebrandt | f3c7a18 | 2021-11-17 13:42:08 +0000 | [diff] [blame] | 55 | AttribMask string `json:"AttributeMask"` |
| 56 | AttribBytes string `json:"AttributeBytes"` |
| 57 | } |
Holger Hildebrandt | f3c7a18 | 2021-11-17 13:42:08 +0000 | [diff] [blame] | 58 | |
praneeth kumar nalmas | 3947c58 | 2023-12-13 15:38:50 +0530 | [diff] [blame] | 59 | // OnuDeviceDB structure holds information about ME's |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 60 | type OnuDeviceDB struct { |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 61 | ctx context.Context |
| 62 | deviceID string |
| 63 | CommonMeDb *OnuCmnMEDB // Reference to OnuCmnMEDB |
| 64 | OnuSpecificMeDbLock sync.RWMutex |
| 65 | OnuSpecificMeDb MeDbMap |
| 66 | } |
| 67 | |
| 68 | // MIBUploadStatus represents the status of MIBUpload for a particular ONT. |
| 69 | type MIBUploadStatus int |
| 70 | |
| 71 | // Values for Status of the ONT MIB Upload. |
| 72 | const ( |
| 73 | NotStarted MIBUploadStatus = iota // MIB upload has not started |
| 74 | InProgress // MIB upload is in progress |
| 75 | Failed // MIB upload has failed |
| 76 | Completed // MIB upload is completed |
| 77 | ) |
| 78 | |
| 79 | // OnuCmnMEDB structure holds information about ME's common to ONT possessing same MIB Template. |
| 80 | type OnuCmnMEDB struct { |
| 81 | MeDbLock sync.RWMutex |
| 82 | MeDb MeDbMap |
| 83 | UnknownMeAndAttribDb UnknownMeAndAttribDbMap |
| 84 | MIBUploadStatus MIBUploadStatus |
| 85 | } |
| 86 | |
| 87 | // NewOnuCmnMEDB returns a new instance of OnuCmnMEDB |
| 88 | func NewOnuCmnMEDB(ctx context.Context) *OnuCmnMEDB { |
| 89 | |
| 90 | return &OnuCmnMEDB{ |
| 91 | MeDbLock: sync.RWMutex{}, |
| 92 | MeDb: make(MeDbMap), |
| 93 | UnknownMeAndAttribDb: make(UnknownMeAndAttribDbMap), |
| 94 | MIBUploadStatus: NotStarted, |
| 95 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 96 | } |
| 97 | |
praneeth kumar nalmas | 3947c58 | 2023-12-13 15:38:50 +0530 | [diff] [blame] | 98 | // NewOnuDeviceDB returns a new instance for a specific ONU_Device_Entry |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 99 | func NewOnuDeviceDB(ctx context.Context, aDeviceID string) *OnuDeviceDB { |
| 100 | logger.Debugw(ctx, "Init OnuDeviceDB for:", log.Fields{"device-id": aDeviceID}) |
| 101 | var OnuDeviceDB OnuDeviceDB |
| 102 | OnuDeviceDB.ctx = ctx |
| 103 | OnuDeviceDB.deviceID = aDeviceID |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 104 | OnuDeviceDB.CommonMeDb = nil |
| 105 | OnuDeviceDB.OnuSpecificMeDb = make(MeDbMap) |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 106 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 107 | return &OnuDeviceDB |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 108 | } |
| 109 | |
praneeth kumar nalmas | 3947c58 | 2023-12-13 15:38:50 +0530 | [diff] [blame] | 110 | // PutMe puts an ME instance into internal ONU DB |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 111 | func (OnuDeviceDB *OnuDeviceDB) PutMe(ctx context.Context, meClassID me.ClassID, meEntityID uint16, meAttributes me.AttributeValueMap) { |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 112 | |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 113 | //filter out the OnuData |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 114 | if me.OnuDataClassID == meClassID { |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 115 | return |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 116 | } |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 117 | |
| 118 | // Dereference the MeDb pointer |
| 119 | if OnuDeviceDB.CommonMeDb == nil || OnuDeviceDB.CommonMeDb.MeDb == nil { |
| 120 | logger.Errorw(ctx, "MeDb is nil", log.Fields{"device-id": OnuDeviceDB.deviceID}) |
| 121 | return |
| 122 | } |
| 123 | meDb := OnuDeviceDB.CommonMeDb.MeDb |
| 124 | _, ok := meDb[meClassID] |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 125 | if !ok { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 126 | logger.Debugw(ctx, "meClassID not found - add to db :", log.Fields{"device-id": OnuDeviceDB.deviceID}) |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 127 | meDb[meClassID] = make(map[uint16]me.AttributeValueMap) |
| 128 | meDb[meClassID][meEntityID] = make(me.AttributeValueMap) |
| 129 | meDb[meClassID][meEntityID] = meAttributes |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 130 | } else { |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 131 | meAttribs, ok := meDb[meClassID][meEntityID] |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 132 | if !ok { |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 133 | meDb[meClassID][meEntityID] = make(me.AttributeValueMap) |
| 134 | meDb[meClassID][meEntityID] = meAttributes |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 135 | } else { |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 136 | for k, v := range meAttributes { |
| 137 | meAttribs[k] = v |
| 138 | } |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 139 | meDb[meClassID][meEntityID] = meAttribs |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 140 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 141 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 142 | } |
| 143 | |
praneeth kumar nalmas | 3947c58 | 2023-12-13 15:38:50 +0530 | [diff] [blame] | 144 | // GetMe returns an ME instance from internal ONU DB |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 145 | func (OnuDeviceDB *OnuDeviceDB) GetMe(meClassID me.ClassID, meEntityID uint16) me.AttributeValueMap { |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 146 | OnuDeviceDB.CommonMeDb.MeDbLock.RLock() |
| 147 | defer OnuDeviceDB.CommonMeDb.MeDbLock.RUnlock() |
| 148 | |
| 149 | // Check in the common MeDb |
| 150 | if meAttributes, present := OnuDeviceDB.CommonMeDb.MeDb[meClassID][meEntityID]; present { |
| 151 | return meAttributes |
| 152 | } |
| 153 | |
| 154 | OnuDeviceDB.OnuSpecificMeDbLock.RLock() |
| 155 | defer OnuDeviceDB.OnuSpecificMeDbLock.RUnlock() |
| 156 | |
| 157 | // Check in the ONU-specific MeDb |
| 158 | if meAttributes, present := OnuDeviceDB.OnuSpecificMeDb[meClassID][meEntityID]; present { |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 159 | return meAttributes |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 160 | } |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 161 | return nil |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 162 | } |
| 163 | |
praneeth kumar nalmas | 3947c58 | 2023-12-13 15:38:50 +0530 | [diff] [blame] | 164 | // GetUint32Attrib converts JSON numbers to uint32 |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 165 | func (OnuDeviceDB *OnuDeviceDB) GetUint32Attrib(meAttribute interface{}) (uint32, error) { |
Holger Hildebrandt | 2ff21f1 | 2020-08-13 14:38:02 +0000 | [diff] [blame] | 166 | |
| 167 | switch reflect.TypeOf(meAttribute).Kind() { |
| 168 | case reflect.Float64: |
| 169 | //JSON numbers by default are unmarshaled into values of float64 type if type information is not present |
| 170 | return uint32(meAttribute.(float64)), nil |
| 171 | case reflect.Uint32: |
Girish Gowdra | 09e5f21 | 2021-09-30 16:28:36 -0700 | [diff] [blame] | 172 | return meAttribute.(uint32), nil |
Holger Hildebrandt | 2ff21f1 | 2020-08-13 14:38:02 +0000 | [diff] [blame] | 173 | default: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 174 | return uint32(0), fmt.Errorf(fmt.Sprintf("wrong-interface-type-%v-received-for-device-%s", reflect.TypeOf(meAttribute).Kind(), OnuDeviceDB.deviceID)) |
Holger Hildebrandt | 2ff21f1 | 2020-08-13 14:38:02 +0000 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | |
praneeth kumar nalmas | 3947c58 | 2023-12-13 15:38:50 +0530 | [diff] [blame] | 178 | // GetUint16Attrib converts JSON numbers to uint16 |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 179 | func (OnuDeviceDB *OnuDeviceDB) GetUint16Attrib(meAttribute interface{}) (uint16, error) { |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 180 | |
| 181 | switch reflect.TypeOf(meAttribute).Kind() { |
Girish Gowdra | 09e5f21 | 2021-09-30 16:28:36 -0700 | [diff] [blame] | 182 | case reflect.Float64: |
| 183 | //JSON numbers by default are unmarshaled into values of float64 type if type information is not present |
| 184 | return uint16(meAttribute.(float64)), nil |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 185 | case reflect.Uint16: |
| 186 | return meAttribute.(uint16), nil |
| 187 | default: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 188 | return uint16(0), fmt.Errorf(fmt.Sprintf("wrong-interface-type-%v-received-for-device-%s", reflect.TypeOf(meAttribute).Kind(), OnuDeviceDB.deviceID)) |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 189 | } |
| 190 | } |
Girish Gowdra | 041dcb3 | 2020-11-16 16:54:30 -0800 | [diff] [blame] | 191 | |
praneeth kumar nalmas | 3947c58 | 2023-12-13 15:38:50 +0530 | [diff] [blame] | 192 | // GetSortedInstKeys returns a sorted list of all instances of an ME |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 193 | func (OnuDeviceDB *OnuDeviceDB) GetSortedInstKeys(ctx context.Context, meClassID me.ClassID) []uint16 { |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 194 | |
| 195 | var meInstKeys []uint16 |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 196 | OnuDeviceDB.CommonMeDb.MeDbLock.RLock() |
| 197 | defer OnuDeviceDB.CommonMeDb.MeDbLock.RUnlock() |
| 198 | meDb := OnuDeviceDB.CommonMeDb.MeDb |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 199 | |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 200 | // Check if the class ID exists in the MeDb map |
| 201 | if meInstMap, found := meDb[meClassID]; found { |
| 202 | for k := range meInstMap { |
| 203 | meInstKeys = append(meInstKeys, k) |
| 204 | } |
| 205 | logger.Debugw(ctx, "meInstKeys - input order :", log.Fields{"meInstKeys": meInstKeys}) //TODO: delete the line after test phase! |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 206 | } |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 207 | sort.Slice(meInstKeys, func(i, j int) bool { return meInstKeys[i] < meInstKeys[j] }) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 208 | logger.Debugw(ctx, "meInstKeys - output order :", log.Fields{"meInstKeys": meInstKeys}) //TODO: delete the line after test phase! |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 209 | |
| 210 | // Return the sorted instance keys |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 211 | return meInstKeys |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 212 | } |
| 213 | |
praneeth kumar nalmas | 3947c58 | 2023-12-13 15:38:50 +0530 | [diff] [blame] | 214 | // GetNumberOfInst returns the number of instances of an ME |
Holger Hildebrandt | 5ba6c13 | 2022-10-06 13:53:14 +0000 | [diff] [blame] | 215 | func (OnuDeviceDB *OnuDeviceDB) GetNumberOfInst(meClassID me.ClassID) int { |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 216 | var count int |
| 217 | |
| 218 | OnuDeviceDB.CommonMeDb.MeDbLock.RLock() |
| 219 | defer OnuDeviceDB.CommonMeDb.MeDbLock.RUnlock() |
| 220 | |
| 221 | if meClassMap, found := OnuDeviceDB.CommonMeDb.MeDb[meClassID]; found { |
| 222 | count = len(meClassMap) |
| 223 | } |
| 224 | |
| 225 | OnuDeviceDB.OnuSpecificMeDbLock.RLock() |
| 226 | defer OnuDeviceDB.OnuSpecificMeDbLock.RUnlock() |
| 227 | |
| 228 | if onuSpecificMap, found := OnuDeviceDB.OnuSpecificMeDb[meClassID]; found { |
| 229 | count += len(onuSpecificMap) |
| 230 | } |
| 231 | |
| 232 | return count |
Holger Hildebrandt | 5ba6c13 | 2022-10-06 13:53:14 +0000 | [diff] [blame] | 233 | } |
| 234 | |
praneeth kumar nalmas | 3947c58 | 2023-12-13 15:38:50 +0530 | [diff] [blame] | 235 | // LogMeDb logs content of internal ONU DB |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 236 | func (OnuDeviceDB *OnuDeviceDB) LogMeDb(ctx context.Context) { |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 237 | logger.Debugw(ctx, "Logging ME instances for device:", log.Fields{"device-id": OnuDeviceDB.deviceID}) |
| 238 | |
| 239 | if OnuDeviceDB.CommonMeDb != nil && OnuDeviceDB.CommonMeDb.MeDb != nil { |
| 240 | meDb := OnuDeviceDB.CommonMeDb.MeDb |
| 241 | |
| 242 | for meClassID, meInstMap := range meDb { |
| 243 | for meEntityID, meAttribs := range meInstMap { |
| 244 | logger.Debugw(ctx, "Common ME instance: ", log.Fields{"meClassID": meClassID, "meEntityID": meEntityID, "meAttribs": meAttribs, |
| 245 | "device-id": OnuDeviceDB.deviceID}) |
| 246 | } |
| 247 | } |
| 248 | } else { |
| 249 | logger.Warnw(ctx, "Common MeDb is nil", log.Fields{"device-id": OnuDeviceDB.deviceID}) |
| 250 | } |
| 251 | |
| 252 | // Log ONU-specific ME instances |
| 253 | OnuDeviceDB.OnuSpecificMeDbLock.RLock() |
| 254 | defer OnuDeviceDB.OnuSpecificMeDbLock.RUnlock() |
| 255 | |
| 256 | for meClassID, meInstMap := range OnuDeviceDB.OnuSpecificMeDb { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 257 | for meEntityID, meAttribs := range meInstMap { |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 258 | logger.Debugw(ctx, "ONU Specific ME instance:", log.Fields{ |
| 259 | "meClassID": meClassID, |
| 260 | "meEntityID": meEntityID, |
| 261 | "meAttribs": meAttribs, |
| 262 | "device-id": OnuDeviceDB.deviceID, |
| 263 | }) |
Holger Hildebrandt | f3c7a18 | 2021-11-17 13:42:08 +0000 | [diff] [blame] | 264 | } |
| 265 | } |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 266 | |
Holger Hildebrandt | f3c7a18 | 2021-11-17 13:42:08 +0000 | [diff] [blame] | 267 | } |
| 268 | |
praneeth kumar nalmas | 3947c58 | 2023-12-13 15:38:50 +0530 | [diff] [blame] | 269 | // PutUnknownMeOrAttrib puts an instance with unknown ME or attributes into internal ONU DB |
Holger Hildebrandt | 3908002 | 2022-03-16 10:03:17 +0000 | [diff] [blame] | 270 | func (OnuDeviceDB *OnuDeviceDB) PutUnknownMeOrAttrib(ctx context.Context, aMeName UnknownMeOrAttribName, aMeClassID me.ClassID, aMeEntityID uint16, |
Holger Hildebrandt | f3c7a18 | 2021-11-17 13:42:08 +0000 | [diff] [blame] | 271 | aMeAttributeMask uint16, aMePayload []byte) { |
| 272 | |
Holger Hildebrandt | 3908002 | 2022-03-16 10:03:17 +0000 | [diff] [blame] | 273 | meAttribMaskStr := fmt.Sprintf("0x%04x", aMeAttributeMask) |
| 274 | attribs := unknownAttribs{meAttribMaskStr, hex.EncodeToString(aMePayload)} |
Holger Hildebrandt | f3c7a18 | 2021-11-17 13:42:08 +0000 | [diff] [blame] | 275 | |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 276 | unknownMeDb := OnuDeviceDB.CommonMeDb.UnknownMeAndAttribDb |
| 277 | |
| 278 | _, ok := unknownMeDb[aMeName] |
Holger Hildebrandt | f3c7a18 | 2021-11-17 13:42:08 +0000 | [diff] [blame] | 279 | if !ok { |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 280 | unknownMeDb[aMeName] = make(map[me.ClassID]map[uint16]unknownAttribs) |
| 281 | unknownMeDb[aMeName][aMeClassID] = make(map[uint16]unknownAttribs) |
| 282 | unknownMeDb[aMeName][aMeClassID][aMeEntityID] = attribs |
Holger Hildebrandt | f3c7a18 | 2021-11-17 13:42:08 +0000 | [diff] [blame] | 283 | } else { |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 284 | _, ok := unknownMeDb[aMeName][aMeClassID] |
Holger Hildebrandt | f3c7a18 | 2021-11-17 13:42:08 +0000 | [diff] [blame] | 285 | if !ok { |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 286 | unknownMeDb[aMeName][aMeClassID] = make(map[uint16]unknownAttribs) |
| 287 | unknownMeDb[aMeName][aMeClassID][aMeEntityID] = attribs |
Holger Hildebrandt | f3c7a18 | 2021-11-17 13:42:08 +0000 | [diff] [blame] | 288 | } else { |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 289 | _, ok := unknownMeDb[aMeName][aMeClassID][aMeEntityID] |
Holger Hildebrandt | f3c7a18 | 2021-11-17 13:42:08 +0000 | [diff] [blame] | 290 | if !ok { |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 291 | unknownMeDb[aMeName][aMeClassID][aMeEntityID] = attribs |
Holger Hildebrandt | f3c7a18 | 2021-11-17 13:42:08 +0000 | [diff] [blame] | 292 | } |
Holger Hildebrandt | 9ac0d0f | 2020-05-13 11:22:02 +0000 | [diff] [blame] | 293 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 294 | } |
Holger Hildebrandt | 24d5195 | 2020-05-04 14:03:42 +0000 | [diff] [blame] | 295 | } |
praneeth kumar nalmas | 3947c58 | 2023-12-13 15:38:50 +0530 | [diff] [blame] | 296 | |
| 297 | // DeleteMe deletes an ME instance from internal ONU DB |
| 298 | func (OnuDeviceDB *OnuDeviceDB) DeleteMe(meClassID me.ClassID, meEntityID uint16) { |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame^] | 299 | OnuDeviceDB.CommonMeDb.MeDbLock.Lock() |
| 300 | defer OnuDeviceDB.CommonMeDb.MeDbLock.Unlock() |
| 301 | meDb := OnuDeviceDB.CommonMeDb.MeDb |
| 302 | delete(meDb[meClassID], meEntityID) |
| 303 | |
| 304 | OnuDeviceDB.OnuSpecificMeDbLock.Lock() |
| 305 | defer OnuDeviceDB.OnuSpecificMeDbLock.Unlock() |
| 306 | delete(OnuDeviceDB.OnuSpecificMeDb[meClassID], meEntityID) |
| 307 | } |
| 308 | |
| 309 | // PutOnuSpeficMe puts an ME instance into specifically to the ONU DB maintained per ONU. |
| 310 | func (OnuDeviceDB *OnuDeviceDB) PutOnuSpeficMe(ctx context.Context, meClassID me.ClassID, meEntityID uint16, meAttributes me.AttributeValueMap) { |
| 311 | OnuDeviceDB.OnuSpecificMeDbLock.Lock() |
| 312 | defer OnuDeviceDB.OnuSpecificMeDbLock.Unlock() |
| 313 | //filter out the OnuData |
| 314 | if me.OnuDataClassID == meClassID { |
| 315 | return |
| 316 | } |
| 317 | _, ok := OnuDeviceDB.OnuSpecificMeDb[meClassID] |
| 318 | if !ok { |
| 319 | logger.Debugw(ctx, "meClassID not found - add to db :", log.Fields{"device-id": OnuDeviceDB.deviceID}) |
| 320 | OnuDeviceDB.OnuSpecificMeDb[meClassID] = make(map[uint16]me.AttributeValueMap) |
| 321 | OnuDeviceDB.OnuSpecificMeDb[meClassID][meEntityID] = make(me.AttributeValueMap) |
| 322 | OnuDeviceDB.OnuSpecificMeDb[meClassID][meEntityID] = meAttributes |
| 323 | } else { |
| 324 | meAttribs, ok := OnuDeviceDB.OnuSpecificMeDb[meClassID][meEntityID] |
| 325 | if !ok { |
| 326 | OnuDeviceDB.OnuSpecificMeDb[meClassID][meEntityID] = make(me.AttributeValueMap) |
| 327 | OnuDeviceDB.OnuSpecificMeDb[meClassID][meEntityID] = meAttributes |
| 328 | } else { |
| 329 | for k, v := range meAttributes { |
| 330 | meAttribs[k] = v |
| 331 | } |
| 332 | OnuDeviceDB.OnuSpecificMeDb[meClassID][meEntityID] = meAttribs |
| 333 | } |
| 334 | } |
praneeth kumar nalmas | 3947c58 | 2023-12-13 15:38:50 +0530 | [diff] [blame] | 335 | } |