Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +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 | fa07499 | 2020-03-27 15:42:06 +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 nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 17 | // Package core provides the utility for onu devices, flows and statistics |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 18 | package core |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
| 22 | "errors" |
| 23 | "fmt" |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 24 | "hash/fnv" |
Holger Hildebrandt | 52f271b | 2022-06-02 09:32:27 +0000 | [diff] [blame] | 25 | "strings" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 26 | "sync" |
| 27 | "time" |
| 28 | |
Praneeth Kumar Nalmas | 77ab2f3 | 2024-04-17 11:14:27 +0530 | [diff] [blame] | 29 | grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry" |
| 30 | "github.com/opencord/voltha-lib-go/v7/pkg/db" |
| 31 | vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc" |
| 32 | codes "google.golang.org/grpc/codes" |
| 33 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 34 | conf "github.com/opencord/voltha-lib-go/v7/pkg/config" |
khenaidoo | f333355 | 2021-12-15 16:52:31 -0500 | [diff] [blame] | 35 | "github.com/opencord/voltha-protos/v5/go/adapter_service" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 36 | "github.com/opencord/voltha-protos/v5/go/common" |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 37 | "github.com/opencord/voltha-protos/v5/go/health" |
| 38 | "github.com/opencord/voltha-protos/v5/go/olt_inter_adapter_service" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 39 | "google.golang.org/grpc" |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 40 | "google.golang.org/grpc/status" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 41 | |
| 42 | "github.com/golang/protobuf/ptypes/empty" |
| 43 | "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore" |
| 44 | "github.com/opencord/voltha-lib-go/v7/pkg/events/eventif" |
| 45 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 46 | ca "github.com/opencord/voltha-protos/v5/go/core_adapter" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 47 | "github.com/opencord/voltha-protos/v5/go/extension" |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 48 | ia "github.com/opencord/voltha-protos/v5/go/inter_adapter" |
| 49 | "github.com/opencord/voltha-protos/v5/go/omci" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 50 | "github.com/opencord/voltha-protos/v5/go/voltha" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 51 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 52 | cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common" |
Matteo Scandolo | 761f751 | 2020-11-23 15:52:40 -0800 | [diff] [blame] | 53 | "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/config" |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame] | 54 | devdb "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/devdb" |
Holger Hildebrandt | 6065220 | 2021-11-02 11:09:36 +0000 | [diff] [blame] | 55 | pmmgr "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/pmmgr" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 56 | "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/swupg" |
| 57 | uniprt "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/uniprt" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 58 | ) |
| 59 | |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 60 | type reachabilityFromRemote struct { |
| 61 | lastKeepAlive time.Time |
| 62 | keepAliveInterval int64 |
| 63 | } |
| 64 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 65 | // OpenONUAC structure holds the ONU core information |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 66 | type OpenONUAC struct { |
Himani Chawla | c07fda0 | 2020-12-09 16:21:21 +0530 | [diff] [blame] | 67 | eventProxy eventif.EventProxy |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 68 | kvClient kvstore.Client |
Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 69 | deviceHandlers map[string]*deviceHandler |
| 70 | deviceHandlersCreateChan map[string]chan bool //channels for deviceHandler create events |
| 71 | coreClient *vgrpc.Client |
| 72 | parentAdapterClients map[string]*vgrpc.Client |
| 73 | reachableFromRemote map[string]*reachabilityFromRemote |
Matteo Scandolo | f1f39a7 | 2020-11-24 12:08:11 -0800 | [diff] [blame] | 74 | cm *conf.ConfigManager |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 75 | config *config.AdapterFlags |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 76 | mibTemplatesGenerated map[string]bool |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 77 | exitChannel chan int |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 78 | pSupportedFsms *cmn.OmciDeviceFsms |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 79 | pDownloadManager *swupg.AdapterDownloadManager |
| 80 | pFileManager *swupg.FileDownloadManager //let coexist 'old and new' DownloadManager as long as 'old' does not get obsolete |
Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 81 | MibDatabaseMap devdb.OnuMCmnMEDBMap |
| 82 | KVStoreAddress string |
| 83 | KVStoreType string |
| 84 | numOnus int |
| 85 | KVStoreTimeout time.Duration |
| 86 | HeartbeatCheckInterval time.Duration |
| 87 | HeartbeatFailReportInterval time.Duration |
| 88 | maxTimeoutInterAdapterComm time.Duration |
| 89 | maxTimeoutReconciling time.Duration |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 90 | mibAuditInterval time.Duration |
| 91 | omciTimeout int // in seconds |
| 92 | alarmAuditInterval time.Duration |
| 93 | dlToOnuTimeout4M time.Duration |
| 94 | rpcTimeout time.Duration |
| 95 | maxConcurrentFlowsPerUni int |
Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 96 | mutexDeviceHandlersMap sync.RWMutex |
| 97 | lockParentAdapterClients sync.RWMutex |
| 98 | lockReachableFromRemote sync.RWMutex |
| 99 | mutexMibTemplateGenerated sync.RWMutex |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame] | 100 | mutexMibDatabaseMap sync.RWMutex |
Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 101 | AcceptIncrementalEvto bool |
| 102 | MetricsEnabled bool |
| 103 | ExtendedOmciSupportEnabled bool |
| 104 | skipOnuConfig bool |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 105 | } |
| 106 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 107 | // NewOpenONUAC returns a new instance of OpenONU_AC |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 108 | func NewOpenONUAC(ctx context.Context, coreClient *vgrpc.Client, eventProxy eventif.EventProxy, |
| 109 | kvClient kvstore.Client, cfg *config.AdapterFlags, cm *conf.ConfigManager) *OpenONUAC { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 110 | var openOnuAc OpenONUAC |
| 111 | openOnuAc.exitChannel = make(chan int, 1) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 112 | openOnuAc.deviceHandlers = make(map[string]*deviceHandler) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 113 | openOnuAc.deviceHandlersCreateChan = make(map[string]chan bool) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 114 | openOnuAc.parentAdapterClients = make(map[string]*vgrpc.Client) |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 115 | openOnuAc.reachableFromRemote = make(map[string]*reachabilityFromRemote) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 116 | openOnuAc.mutexDeviceHandlersMap = sync.RWMutex{} |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 117 | openOnuAc.config = cfg |
Matteo Scandolo | f1f39a7 | 2020-11-24 12:08:11 -0800 | [diff] [blame] | 118 | openOnuAc.cm = cm |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 119 | openOnuAc.coreClient = coreClient |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 120 | openOnuAc.numOnus = cfg.OnuNumber |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 121 | openOnuAc.eventProxy = eventProxy |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 122 | openOnuAc.kvClient = kvClient |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 123 | openOnuAc.KVStoreAddress = cfg.KVStoreAddress |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 124 | openOnuAc.KVStoreType = cfg.KVStoreType |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 125 | openOnuAc.KVStoreTimeout = cfg.KVStoreTimeout |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 126 | openOnuAc.mibTemplatesGenerated = make(map[string]bool) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 127 | openOnuAc.mutexMibTemplateGenerated = sync.RWMutex{} |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 128 | openOnuAc.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval |
| 129 | openOnuAc.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 130 | openOnuAc.AcceptIncrementalEvto = cfg.AccIncrEvto |
Himani Chawla | d96df18 | 2020-09-28 11:12:02 +0530 | [diff] [blame] | 131 | openOnuAc.maxTimeoutInterAdapterComm = cfg.MaxTimeoutInterAdapterComm |
Holger Hildebrandt | 38985dc | 2021-02-18 16:25:20 +0000 | [diff] [blame] | 132 | openOnuAc.maxTimeoutReconciling = cfg.MaxTimeoutReconciling |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 133 | //openOnuAc.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 134 | openOnuAc.MetricsEnabled = cfg.MetricsEnabled |
Holger Hildebrandt | c572e62 | 2022-06-22 09:19:17 +0000 | [diff] [blame] | 135 | openOnuAc.ExtendedOmciSupportEnabled = cfg.ExtendedOmciSupportEnabled |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 136 | openOnuAc.mibAuditInterval = cfg.MibAuditInterval |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 137 | // since consumers of OMCI timeout value everywhere in code is in "int seconds", do this useful conversion |
| 138 | openOnuAc.omciTimeout = int(cfg.OmciTimeout.Seconds()) |
Himani Chawla | 075f164 | 2021-03-15 19:23:24 +0530 | [diff] [blame] | 139 | openOnuAc.alarmAuditInterval = cfg.AlarmAuditInterval |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 140 | openOnuAc.dlToOnuTimeout4M = cfg.DownloadToOnuTimeout4MB |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 141 | openOnuAc.rpcTimeout = cfg.RPCTimeout |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 142 | openOnuAc.maxConcurrentFlowsPerUni = cfg.MaxConcurrentFlowsPerUni |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 143 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 144 | openOnuAc.pSupportedFsms = &cmn.OmciDeviceFsms{ |
Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 145 | "mib-synchronizer": cmn.ActivityDescr{ |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 146 | //mibSyncFsm, // Implements the MIB synchronization state machine |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 147 | DatabaseClass: mibDbVolatileDictImpl, // Implements volatile ME MIB database |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 148 | //true, // Advertise events on OpenOMCI event bus |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 149 | AuditInterval: openOnuAc.mibAuditInterval, // Time to wait between MIB audits. 0 to disable audits. |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 150 | // map[string]func() error{ |
| 151 | // "mib-upload": onuDeviceEntry.MibUploadTask, |
| 152 | // "mib-template": onuDeviceEntry.MibTemplateTask, |
| 153 | // "get-mds": onuDeviceEntry.GetMdsTask, |
| 154 | // "mib-audit": onuDeviceEntry.GetMdsTask, |
| 155 | // "mib-resync": onuDeviceEntry.MibResyncTask, |
| 156 | // "mib-reconcile": onuDeviceEntry.MibReconcileTask, |
| 157 | // }, |
| 158 | }, |
| 159 | } |
| 160 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 161 | openOnuAc.pDownloadManager = swupg.NewAdapterDownloadManager(ctx) |
| 162 | openOnuAc.pFileManager = swupg.NewFileDownloadManager(ctx) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 163 | openOnuAc.pFileManager.SetDownloadTimeout(ctx, cfg.DownloadToAdapterTimeout) |
Praneeth Kumar Nalmas | 77ab2f3 | 2024-04-17 11:14:27 +0530 | [diff] [blame] | 164 | openOnuAc.skipOnuConfig = cfg.SkipOnuConfig |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame] | 165 | openOnuAc.mutexMibDatabaseMap = sync.RWMutex{} |
| 166 | openOnuAc.MibDatabaseMap = make(map[string]*devdb.OnuCmnMEDB) |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 167 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 168 | return &openOnuAc |
| 169 | } |
| 170 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 171 | // Start starts (logs) the adapter |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 172 | func (oo *OpenONUAC) Start(ctx context.Context) error { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 173 | logger.Info(ctx, "starting-openonu-adapter") |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 174 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 175 | return nil |
| 176 | } |
| 177 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 178 | // Stop terminates the session |
khenaidoo | f333355 | 2021-12-15 16:52:31 -0500 | [diff] [blame] | 179 | func (oo *OpenONUAC) Stop(ctx context.Context) error { |
| 180 | logger.Info(ctx, "stopping-device-manager") |
| 181 | close(oo.exitChannel) |
| 182 | oo.stopAllGrpcClients(ctx) |
| 183 | logger.Info(ctx, "device-manager-stopped") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 184 | return nil |
| 185 | } |
| 186 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 187 | func (oo *OpenONUAC) addDeviceHandlerToMap(ctx context.Context, agent *deviceHandler) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 188 | oo.mutexDeviceHandlersMap.Lock() |
| 189 | defer oo.mutexDeviceHandlersMap.Unlock() |
| 190 | if _, exist := oo.deviceHandlers[agent.DeviceID]; !exist { |
| 191 | oo.deviceHandlers[agent.DeviceID] = agent |
| 192 | oo.deviceHandlers[agent.DeviceID].start(ctx) |
| 193 | if _, exist := oo.deviceHandlersCreateChan[agent.DeviceID]; exist { |
| 194 | logger.Debugw(ctx, "deviceHandler created - trigger processing of pending ONU_IND_REQUEST", log.Fields{"device-id": agent.DeviceID}) |
| 195 | oo.deviceHandlersCreateChan[agent.DeviceID] <- true |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 196 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 197 | } |
| 198 | } |
| 199 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 200 | func (oo *OpenONUAC) deleteDeviceHandlerToMap(agent *deviceHandler) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 201 | oo.mutexDeviceHandlersMap.Lock() |
| 202 | defer oo.mutexDeviceHandlersMap.Unlock() |
| 203 | delete(oo.deviceHandlers, agent.DeviceID) |
| 204 | delete(oo.deviceHandlersCreateChan, agent.DeviceID) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 205 | } |
| 206 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 207 | // getDeviceHandler gets the ONU deviceHandler and may wait until it is created |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 208 | func (oo *OpenONUAC) getDeviceHandler(ctx context.Context, deviceID string, aWait bool) (*deviceHandler, error) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 209 | oo.mutexDeviceHandlersMap.Lock() |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 210 | agent, ok := oo.deviceHandlers[deviceID] |
| 211 | if aWait && !ok { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 212 | logger.Infow(ctx, "Race condition: deviceHandler not present - wait for creation or timeout", |
Holger Hildebrandt | 6c1fb0a | 2020-11-25 15:41:01 +0000 | [diff] [blame] | 213 | log.Fields{"device-id": deviceID}) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 214 | if _, exist := oo.deviceHandlersCreateChan[deviceID]; !exist { |
| 215 | oo.deviceHandlersCreateChan[deviceID] = make(chan bool, 1) |
| 216 | } |
Girish Gowdra | 7407a4d | 2020-11-12 12:44:53 -0800 | [diff] [blame] | 217 | deviceCreateChan := oo.deviceHandlersCreateChan[deviceID] |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 218 | //keep the read sema short to allow for subsequent write |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 219 | oo.mutexDeviceHandlersMap.Unlock() |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 220 | // based on concurrent processing the deviceHandler creation may not yet be finished at his point |
| 221 | // so it might be needed to wait here for that event with some timeout |
| 222 | select { |
Akash Soni | 71f4476 | 2024-12-11 16:12:21 +0530 | [diff] [blame] | 223 | case <-time.After(20 * time.Second): //timer may be discussed ... |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 224 | errMsg := fmt.Sprintf("No valid deviceHandler created after max WaitTime for device %s", deviceID) |
| 225 | logger.Warn(ctx, errMsg) |
| 226 | return nil, status.Error(codes.NotFound, errMsg) |
Girish Gowdra | 7407a4d | 2020-11-12 12:44:53 -0800 | [diff] [blame] | 227 | case <-deviceCreateChan: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 228 | logger.Debugw(ctx, "deviceHandler is ready now - continue", log.Fields{"device-id": deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 229 | oo.mutexDeviceHandlersMap.RLock() |
| 230 | defer oo.mutexDeviceHandlersMap.RUnlock() |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 231 | return oo.deviceHandlers[deviceID], nil |
| 232 | case <-ctx.Done(): |
| 233 | errMsg := fmt.Sprintf("context cancelled while waiting for device handler for device %s: %v", deviceID, ctx.Err()) |
| 234 | logger.Warnw(ctx, errMsg, log.Fields{"device-id": deviceID, "context-error": ctx.Err()}) |
| 235 | return nil, errors.New(errMsg) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 236 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 237 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 238 | oo.mutexDeviceHandlersMap.Unlock() |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 239 | return agent, nil |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 240 | } |
| 241 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 242 | // AdoptDevice creates a new device handler if not present already and then adopts the device |
| 243 | func (oo *OpenONUAC) AdoptDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 244 | if device == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 245 | logger.Warn(ctx, "voltha-device-is-nil") |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 246 | return nil, errors.New("nil-device") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 247 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 248 | logger.Infow(ctx, "adopt-device", log.Fields{"device-id": device.Id}) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 249 | var handler *deviceHandler |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 250 | if handler, _ = oo.getDeviceHandler(ctx, device.Id, false); handler == nil { |
| 251 | fsmCtx := log.WithSpanFromContext(context.Background(), ctx) |
| 252 | handler := newDeviceHandler(fsmCtx, oo.coreClient, oo.eventProxy, device, oo) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 253 | oo.addDeviceHandlerToMap(ctx, handler) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 254 | |
| 255 | // Setup the grpc communication with the parent adapter |
| 256 | if err := oo.setupParentInterAdapterClient(ctx, device.ProxyAddress.AdapterEndpoint); err != nil { |
| 257 | // TODO: Cleanup on failure needed |
| 258 | return nil, err |
| 259 | } |
| 260 | |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 261 | go handler.adoptOrReconcileDevice(fsmCtx, device) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 262 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 263 | return &empty.Empty{}, nil |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 264 | } |
| 265 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 266 | // ReconcileDevice is called once when the adapter needs to re-create device - usually on core restart |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 267 | func (oo *OpenONUAC) ReconcileDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 268 | if device == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 269 | logger.Warn(ctx, "reconcile-device-voltha-device-is-nil") |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 270 | return nil, errors.New("nil-device") |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 271 | } |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 272 | logger.Infow(ctx, "reconcile-device", log.Fields{"device-id": device.Id, "parent-id": device.ParentId}) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 273 | var handler *deviceHandler |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 274 | if handler, _ = oo.getDeviceHandler(ctx, device.Id, false); handler == nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 275 | handler := newDeviceHandler(ctx, oo.coreClient, oo.eventProxy, device, oo) |
Praneeth Kumar Nalmas | 77ab2f3 | 2024-04-17 11:14:27 +0530 | [diff] [blame] | 276 | logger.Infow(ctx, "reconciling-device skip-onu-config value ", log.Fields{"device-id": device.Id, "parent-id": device.ParentId, "skip-onu-config": oo.skipOnuConfig}) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 277 | handler.device = device |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 278 | if err := handler.updateDeviceStateInCore(log.WithSpanFromContext(context.Background(), ctx), &ca.DeviceStateFilter{ |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 279 | DeviceId: device.Id, |
| 280 | OperStatus: voltha.OperStatus_RECONCILING, |
| 281 | ConnStatus: device.ConnectStatus, |
| 282 | }); err != nil { |
| 283 | return nil, fmt.Errorf("not able to update device state to reconciling. Err : %s", err.Error()) |
Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 284 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 285 | // Setup the grpc communication with the parent adapter |
| 286 | if err := oo.setupParentInterAdapterClient(ctx, device.ProxyAddress.AdapterEndpoint); err != nil { |
| 287 | // TODO: Cleanup on failure needed |
| 288 | return nil, err |
| 289 | } |
Akash Soni | 931f9b9 | 2024-12-11 18:36:36 +0530 | [diff] [blame] | 290 | // Add device handler to map only if adapter and core connections are up |
| 291 | oo.addDeviceHandlerToMap(ctx, handler) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 292 | handler.StartReconciling(log.WithSpanFromContext(context.Background(), ctx), false) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 293 | go handler.adoptOrReconcileDevice(log.WithSpanFromContext(context.Background(), ctx), handler.device) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 294 | // reconcilement will be continued after onu-device entry is added |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 295 | } else { |
nikesh.krishnan | 9d2bbf7 | 2023-12-11 07:36:57 +0530 | [diff] [blame] | 296 | logger.Warnf(ctx, "device-already-reconciled-or-active", log.Fields{"device-id": device.Id, "parent-id": device.ParentId}) |
| 297 | return &empty.Empty{}, status.Errorf(codes.AlreadyExists, "handler exists: %s", device.Id) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 298 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 299 | return &empty.Empty{}, nil |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 300 | } |
| 301 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 302 | // DisableDevice disables the given device |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 303 | func (oo *OpenONUAC) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 304 | logger.Infow(ctx, "disable-device", log.Fields{"device-id": device.Id}) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 305 | if handler, err := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 306 | go handler.disableDevice(log.WithSpanFromContext(context.Background(), ctx), device) |
| 307 | return &empty.Empty{}, nil |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 308 | } else { |
| 309 | logger.Warnw(ctx, "no handler found for device-disable", log.Fields{"device-id": device.Id}) |
| 310 | return nil, err |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 311 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 312 | } |
| 313 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 314 | // ReEnableDevice enables the onu device after disable |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 315 | func (oo *OpenONUAC) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 316 | logger.Infow(ctx, "reenable-device", log.Fields{"device-id": device.Id}) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 317 | if handler, err := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 318 | go handler.reEnableDevice(log.WithSpanFromContext(context.Background(), ctx), device) |
| 319 | return &empty.Empty{}, nil |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 320 | } else { |
| 321 | logger.Warnw(ctx, "no handler found for device-reenable", log.Fields{"device-id": device.Id}) |
| 322 | return nil, err |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 323 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 324 | } |
| 325 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 326 | // RebootDevice reboots the given device |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 327 | func (oo *OpenONUAC) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 328 | logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id}) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 329 | if handler, err := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 330 | go handler.rebootDevice(log.WithSpanFromContext(context.Background(), ctx), true, device) //reboot request with device checking |
| 331 | return &empty.Empty{}, nil |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 332 | } else { |
| 333 | logger.Warnw(ctx, "no handler found for device-reboot", log.Fields{"device-id": device.Id}) |
| 334 | return nil, err |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 335 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 336 | } |
| 337 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 338 | // DeleteDevice deletes the given device |
| 339 | func (oo *OpenONUAC) DeleteDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 340 | nctx := log.WithSpanFromContext(context.Background(), ctx) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 341 | logger.Infow(ctx, "delete-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber, "ctx": ctx, "nctx": nctx}) |
Holger Hildebrandt | c69f074 | 2021-11-16 13:48:00 +0000 | [diff] [blame] | 342 | |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 343 | if handler, err := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
| 344 | // Acquire read lock to check if deletion is already in progress |
| 345 | handler.mutexDeletionInProgressFlag.RLock() |
| 346 | if handler.deletionInProgress { |
| 347 | // If deletion is already in progress, release the read lock and return |
| 348 | handler.mutexDeletionInProgressFlag.RUnlock() |
| 349 | errMsg := fmt.Sprintf("Device deletion is already in progress %s err: %s", device.Id, err) |
| 350 | logger.Info(ctx, errMsg) |
| 351 | return nil, status.Error(codes.FailedPrecondition, errMsg) |
| 352 | } |
| 353 | // Release read lock before setting the deletion flag |
| 354 | handler.mutexDeletionInProgressFlag.RUnlock() |
Holger Hildebrandt | ff05b68 | 2021-03-16 15:02:05 +0000 | [diff] [blame] | 355 | handler.mutexDeletionInProgressFlag.Lock() |
| 356 | handler.deletionInProgress = true |
| 357 | handler.mutexDeletionInProgressFlag.Unlock() |
| 358 | |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 359 | // Setting the device deletion progress flag will cause the PM FSM to cleanup for GC after FSM moves to NULL state |
nikesh.krishnan | 1249be9 | 2023-11-27 04:20:12 +0530 | [diff] [blame] | 360 | if handler.pOnuMetricsMgr != nil { |
| 361 | handler.pOnuMetricsMgr.SetdeviceDeletionInProgress(true) |
| 362 | } |
praneeth nalmas | f405e96 | 2023-08-07 15:02:03 +0530 | [diff] [blame] | 363 | |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 364 | close(handler.deviceDeleteCommChan) |
| 365 | if resetErr := handler.resetFsms(ctx, true); resetErr != nil { |
| 366 | logger.Errorw(ctx, "failed to reset FSMs for the device", log.Fields{"device-id": device.Id, "err": resetErr}) |
| 367 | handler.mutexDeletionInProgressFlag.Lock() |
| 368 | handler.deletionInProgress = false |
| 369 | handler.mutexDeletionInProgressFlag.Unlock() |
| 370 | return nil, resetErr |
Holger Hildebrandt | 6065220 | 2021-11-02 11:09:36 +0000 | [diff] [blame] | 371 | } |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 372 | for _, uni := range handler.uniEntityMap { |
| 373 | if handler.GetFlowMonitoringIsRunning(uni.UniID) { |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 374 | select { |
| 375 | case handler.stopFlowMonitoringRoutine[uni.UniID] <- true: |
| 376 | logger.Debugw(ctx, "sent stop signal to self flow monitoring routine", log.Fields{"device-id": device.Id, "uni-id": uni.UniID}) |
| 377 | default: |
| 378 | |
| 379 | logger.Warnw(ctx, "stopFlowMonitoringRoutine channel already closed", log.Fields{"device-id": device.Id, "uni-id": uni.UniID}) |
| 380 | } |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 381 | } |
| 382 | } |
Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 383 | //don't leave any garbage in kv-store |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 384 | if forceDeleteErr := oo.forceDeleteDeviceKvData(ctx, device.Id); forceDeleteErr != nil { |
| 385 | logger.Errorw(ctx, "failed to delete ONU data from KV store", log.Fields{"device-id": device.Id, "err": forceDeleteErr}) |
| 386 | return nil, forceDeleteErr |
Holger Hildebrandt | c69f074 | 2021-11-16 13:48:00 +0000 | [diff] [blame] | 387 | } |
Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 388 | oo.deleteDeviceHandlerToMap(handler) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 389 | handler.PrepareForGarbageCollection(ctx, handler.DeviceID) |
Holger Hildebrandt | 6065220 | 2021-11-02 11:09:36 +0000 | [diff] [blame] | 390 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 391 | return &empty.Empty{}, nil |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 392 | } else { |
| 393 | errMsg := fmt.Sprintf("Device Handler not found -%s with error %s", device.Id, err) |
| 394 | logger.Error(ctx, errMsg) |
| 395 | return nil, status.Error(codes.NotFound, errMsg) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 396 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 397 | } |
| 398 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 399 | // UpdateFlowsIncrementally updates (add/remove) the flows on a given device |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 400 | func (oo *OpenONUAC) UpdateFlowsIncrementally(ctx context.Context, incrFlows *ca.IncrementalFlows) (*empty.Empty, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 401 | logger.Infow(ctx, "update-flows-incrementally", log.Fields{"device-id": incrFlows.Device.Id}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 402 | |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 403 | //flow config is relayed to handler even if the device might be in some 'inactive' state |
| 404 | // let the handler or related FSM's decide, what to do with the modified flow state info |
| 405 | // at least the flow-remove must be done in respect to internal data, while OMCI activity might not be needed here |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 406 | |
| 407 | // For now, there is no support for group changes (as in the actual Py-adapter code) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 408 | // but processing is continued for flowUpdate possibly also set in the request |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 409 | if incrFlows.Groups.ToAdd != nil && incrFlows.Groups.ToAdd.Items != nil { |
| 410 | logger.Warnw(ctx, "Update-flow-incr: group add not supported (ignored)", log.Fields{"device-id": incrFlows.Device.Id}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 411 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 412 | if incrFlows.Groups.ToRemove != nil && incrFlows.Groups.ToRemove.Items != nil { |
| 413 | logger.Warnw(ctx, "Update-flow-incr: group remove not supported (ignored)", log.Fields{"device-id": incrFlows.Device.Id}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 414 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 415 | if incrFlows.Groups.ToUpdate != nil && incrFlows.Groups.ToUpdate.Items != nil { |
| 416 | logger.Warnw(ctx, "Update-flow-incr: group update not supported (ignored)", log.Fields{"device-id": incrFlows.Device.Id}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 417 | } |
| 418 | |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 419 | if handler, err := oo.getDeviceHandler(ctx, incrFlows.Device.Id, false); handler != nil { |
| 420 | if flowUpdateErr := handler.FlowUpdateIncremental(log.WithSpanFromContext(context.Background(), ctx), incrFlows.Flows, incrFlows.Groups, incrFlows.FlowMetadata); flowUpdateErr != nil { |
| 421 | return nil, flowUpdateErr |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 422 | } |
| 423 | return &empty.Empty{}, nil |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 424 | } else { |
| 425 | logger.Warnw(ctx, "no handler found for incremental flow update", log.Fields{"device-id": incrFlows.Device.Id}) |
| 426 | return nil, err |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 427 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 428 | } |
| 429 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 430 | // UpdatePmConfig returns PmConfigs nil or error |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 431 | func (oo *OpenONUAC) UpdatePmConfig(ctx context.Context, configs *ca.PmConfigsInfo) (*empty.Empty, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 432 | logger.Infow(ctx, "update-pm-config", log.Fields{"device-id": configs.DeviceId}) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 433 | if handler, err := oo.getDeviceHandler(ctx, configs.DeviceId, false); handler != nil { |
| 434 | if pmConfigErr := handler.updatePmConfig(log.WithSpanFromContext(context.Background(), ctx), configs.PmConfigs); pmConfigErr != nil { |
| 435 | return nil, pmConfigErr |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 436 | } |
| 437 | return &empty.Empty{}, nil |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 438 | } else { |
| 439 | logger.Warnw(ctx, "no handler found for update-pm-config", log.Fields{"device-id": configs.DeviceId}) |
| 440 | return nil, err |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 441 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 442 | } |
| 443 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 444 | // DownloadImage requests downloading some image according to indications as given in request |
| 445 | // The ImageDownload needs to be called `request`due to library reflection requirements |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 446 | func (oo *OpenONUAC) DownloadImage(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 447 | ctx = log.WithSpanFromContext(context.Background(), ctx) |
| 448 | if imageInfo != nil && imageInfo.Image != nil && imageInfo.Image.Name != "" { |
Holger Hildebrandt | 52f271b | 2022-06-02 09:32:27 +0000 | [diff] [blame] | 449 | if strings.Contains(imageInfo.Image.Url, "https:") { |
| 450 | return nil, errors.New("image download via https not supported") |
| 451 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 452 | if !oo.pDownloadManager.ImageExists(ctx, imageInfo.Image) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 453 | logger.Debugw(ctx, "start image download", log.Fields{"image-description": imageInfo.Image}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 454 | // Download_image is not supposed to be blocking, anyway let's call the DownloadManager still synchronously to detect 'fast' problems |
| 455 | // the download itself is later done in background |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 456 | if err := oo.pDownloadManager.StartDownload(ctx, imageInfo.Image); err != nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 457 | return nil, err |
| 458 | } |
| 459 | return imageInfo.Image, nil |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 460 | } |
| 461 | // image already exists |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 462 | logger.Debugw(ctx, "image already downloaded", log.Fields{"image-description": imageInfo.Image}) |
| 463 | return imageInfo.Image, nil |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 464 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 465 | |
| 466 | return nil, errors.New("invalid image definition") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 467 | } |
| 468 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 469 | // ActivateImageUpdate requests downloading some Onu Software image to the ONU via OMCI |
| 470 | // |
| 471 | // according to indications as given in request and on success activate the image on the ONU |
| 472 | // |
| 473 | // The ImageDownload needs to be called `request`due to library reflection requirements |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 474 | func (oo *OpenONUAC) ActivateImageUpdate(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 475 | if imageInfo != nil && imageInfo.Image != nil && imageInfo.Image.Name != "" { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 476 | if oo.pDownloadManager.ImageLocallyDownloaded(ctx, imageInfo.Image) { |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 477 | if handler, err := oo.getDeviceHandler(ctx, imageInfo.Device.Id, false); handler != nil { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 478 | logger.Debugw(ctx, "image download on omci requested", log.Fields{ |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 479 | "image-description": imageInfo.Image, "device-id": imageInfo.Device.Id}) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 480 | if swUpgradeErr := handler.doOnuSwUpgrade(ctx, imageInfo.Image, oo.pDownloadManager); swUpgradeErr != nil { |
| 481 | return nil, swUpgradeErr |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 482 | } |
| 483 | return imageInfo.Image, nil |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 484 | } else { |
| 485 | logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": imageInfo.Device.Id}) |
| 486 | return nil, err |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 487 | } |
mpagenko | 057889c | 2021-01-21 16:51:58 +0000 | [diff] [blame] | 488 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 489 | logger.Debugw(ctx, "image not yet downloaded on activate request", log.Fields{"image-description": imageInfo.Image}) |
Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 490 | return nil, fmt.Errorf("image-not-yet-downloaded - device-id: %s", imageInfo.Device.Id) |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 491 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 492 | return nil, errors.New("invalid image definition") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 493 | } |
| 494 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 495 | // GetSingleValue handles the core request to retrieve uni status |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 496 | func (oo *OpenONUAC) GetSingleValue(ctx context.Context, request *extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) { |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 497 | logger.Infow(ctx, "Single_get_value_request", log.Fields{"request": request}) |
| 498 | |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 499 | if handler, err := oo.getDeviceHandler(ctx, request.TargetId, false); handler != nil { |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 500 | switch reqType := request.GetRequest().GetRequest().(type) { |
| 501 | case *extension.GetValueRequest_UniInfo: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 502 | return handler.GetUniPortStatus(ctx, reqType.UniInfo), nil |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 503 | case *extension.GetValueRequest_OnuOpticalInfo: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 504 | CommChan := make(chan cmn.Message) |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 505 | respChan := make(chan extension.SingleGetValueResponse) |
| 506 | // Initiate the self test request |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 507 | if selfTestErr := handler.pSelfTestHdlr.SelfTestRequestStart(ctx, *request, CommChan, respChan); selfTestErr != nil { |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 508 | return &extension.SingleGetValueResponse{ |
| 509 | Response: &extension.GetValueResponse{ |
| 510 | Status: extension.GetValueResponse_ERROR, |
| 511 | ErrReason: extension.GetValueResponse_INTERNAL_ERROR, |
| 512 | }, |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 513 | }, selfTestErr |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 514 | } |
| 515 | // The timeout handling is already implemented in omci_self_test_handler module |
| 516 | resp := <-respChan |
| 517 | return &resp, nil |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 518 | case *extension.GetValueRequest_OnuInfo: |
| 519 | return handler.getOnuOMCICounters(ctx, reqType.OnuInfo), nil |
Holger Hildebrandt | 66af5ce | 2022-09-07 13:38:02 +0000 | [diff] [blame] | 520 | case *extension.GetValueRequest_OnuOmciStats: |
| 521 | return handler.getOnuOMCIStats(ctx) |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 522 | case *extension.GetValueRequest_OnuActiveAlarms: |
| 523 | resp := handler.getOnuActiveAlarms(ctx) |
| 524 | logger.Infow(ctx, "Received response for on demand active alarms request ", log.Fields{"response": resp}) |
| 525 | return resp, nil |
Akash Reddy Kankanala | c28f0e2 | 2025-06-16 11:00:55 +0530 | [diff] [blame] | 526 | case *extension.GetValueRequest_OnuAllocGemStats: |
| 527 | resp := handler.getONUGEMStatsInfo(ctx) |
| 528 | logger.Infow(ctx, "Received response for on demand active alarms request ", log.Fields{"response": resp}) |
| 529 | return resp, nil |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 530 | default: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 531 | return uniprt.PostUniStatusErrResponse(extension.GetValueResponse_UNSUPPORTED), nil |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 532 | } |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 533 | } else { |
| 534 | logger.Errorw(ctx, "Single_get_value_request failed ", log.Fields{"request": request}) |
| 535 | return uniprt.PostUniStatusErrResponse(extension.GetValueResponse_INVALID_DEVICE_ID), err |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 536 | } |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 537 | } |
| 538 | |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 539 | //if update >= 4.3.0 |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 540 | // Note: already with the implementation of the 'old' download interface problems were detected when the argument name used here is not the same |
| 541 | // as defined in the adapter interface file. That sounds strange and the effects were strange as well. |
| 542 | // The reason for that was never finally investigated. |
| 543 | // To be on the safe side argument names are left here always as defined in iAdapter.go . |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 544 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 545 | // DownloadOnuImage downloads (and optionally activates and commits) the indicated ONU image to the requested ONU(s) |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 546 | // |
| 547 | // if the image is not yet present on the adapter it has to be automatically downloaded |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 548 | func (oo *OpenONUAC) DownloadOnuImage(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 549 | if request != nil && len((*request).DeviceId) > 0 && (*request).Image.Version != "" { |
Holger Hildebrandt | 52f271b | 2022-06-02 09:32:27 +0000 | [diff] [blame] | 550 | if strings.Contains((*request).Image.Url, "https:") { |
| 551 | return nil, errors.New("image download via https not supported") |
| 552 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 553 | loResponse := voltha.DeviceImageResponse{} |
| 554 | imageIdentifier := (*request).Image.Version |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 555 | downloadStartDone := false |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 556 | firstDevice := true |
| 557 | var vendorID string |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 558 | var onuVolthaDevice *voltha.Device |
| 559 | var devErr error |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 560 | for _, pCommonID := range (*request).DeviceId { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 561 | vendorIDMatch := true |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 562 | loDeviceID := (*pCommonID).Id |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 563 | loDeviceImageState := voltha.DeviceImageState{} |
| 564 | loDeviceImageState.DeviceId = loDeviceID |
| 565 | loImageState := voltha.ImageState{} |
| 566 | loDeviceImageState.ImageState = &loImageState |
| 567 | loDeviceImageState.ImageState.Version = (*request).Image.Version |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 568 | |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 569 | onuVolthaDevice = nil |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 570 | handler, err := oo.getDeviceHandler(ctx, loDeviceID, false) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 571 | if handler != nil { |
| 572 | onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID) |
| 573 | } else { |
| 574 | // assumption here is, that the concerned device was already created (automatic start after device creation not supported) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 575 | devErr = err |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 576 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 577 | if devErr != nil || onuVolthaDevice == nil { |
| 578 | logger.Warnw(ctx, "Failed to fetch ONU device for image download", |
| 579 | log.Fields{"device-id": loDeviceID, "err": devErr}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 580 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED |
| 581 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //proto restriction, better option: 'INVALID_DEVICE' |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 582 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 583 | } else { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 584 | if firstDevice { |
| 585 | //start/verify download of the image to the adapter based on first found device only |
| 586 | // use the OnuVendor identification from first given device |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 587 | |
| 588 | // note: if the request was done for a list of devices on the Voltha interface, rwCore |
| 589 | // translates that into a new rpc for each device, hence each device will be the first device in parallel requests! |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 590 | firstDevice = false |
| 591 | vendorID = onuVolthaDevice.VendorId |
| 592 | imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 593 | logger.Infow(ctx, "download request for file", |
| 594 | log.Fields{"device-id": loDeviceID, "image-id": imageIdentifier}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 595 | |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 596 | // call the StartDownload synchronously to detect 'immediate' download problems |
| 597 | // the real download itself is later done in background |
| 598 | if fileState, err := oo.pFileManager.StartDownload(ctx, imageIdentifier, (*request).Image.Url); err == nil { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 599 | // note: If the image (with vendorId+name) has already been downloaded before from some other |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 600 | // valid URL, the current download request is not executed (current code delivers URL error). |
| 601 | // If the operators want to ensure that the new URL |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 602 | // is really used, then they first have to use the 'abort' API to remove the existing image! |
| 603 | // (abort API can be used also after some successful download to just remove the image from adapter) |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 604 | if fileState == swupg.CFileStateDlSucceeded || fileState == swupg.CFileStateDlStarted { |
| 605 | downloadStartDone = true |
| 606 | } //else fileState may also indicate error situation, where the requested image is not ready to be used for other devices |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 607 | } |
| 608 | } else { |
| 609 | //for all following devices verify the matching vendorID |
| 610 | if onuVolthaDevice.VendorId != vendorID { |
| 611 | logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored", |
| 612 | log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID}) |
| 613 | vendorIDMatch = false |
| 614 | } |
| 615 | } |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 616 | if downloadStartDone && vendorIDMatch { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 617 | // start the ONU download activity for each possible device |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 618 | logger.Infow(ctx, "request image download to ONU on omci ", log.Fields{ |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 619 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 620 | //onu upgrade handling called in background without immediate error evaluation here |
| 621 | // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others |
| 622 | // state/progress/success of the request has to be verified using the Get_onu_image_status() API |
| 623 | go handler.onuSwUpgradeAfterDownload(ctx, request, oo.pFileManager, imageIdentifier) |
| 624 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_STARTED |
| 625 | loDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR |
| 626 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 627 | } else { |
| 628 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 629 | if !downloadStartDone { |
| 630 | //based on above fileState more descriptive error codes would be possible, e.g |
| 631 | // IMAGE_EXISTS_WITH_DIFFERENT_URL - would require proto buf update |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 632 | loDeviceImageState.ImageState.Reason = voltha.ImageState_INVALID_URL |
| 633 | } else { //only logical option is !vendorIDMatch |
| 634 | loDeviceImageState.ImageState.Reason = voltha.ImageState_VENDOR_DEVICE_MISMATCH |
| 635 | } |
| 636 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 637 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 638 | } |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 639 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 640 | } //for all requested devices |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 641 | pImageResp := &loResponse |
| 642 | return pImageResp, nil |
| 643 | } |
| 644 | return nil, errors.New("invalid image download parameters") |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 645 | } |
| 646 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 647 | // GetOnuImageStatus delivers the adapter-related information about the download/activation/commitment |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 648 | // |
| 649 | // status for the requested image |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 650 | func (oo *OpenONUAC) GetOnuImageStatus(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 651 | if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" { |
| 652 | loResponse := voltha.DeviceImageResponse{} |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 653 | imageIdentifier := (*in).Version |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 654 | var vendorIDSet bool |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 655 | firstDevice := true |
| 656 | var vendorID string |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 657 | var onuVolthaDevice *voltha.Device |
| 658 | var devErr error |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 659 | for _, pCommonID := range (*in).DeviceId { |
| 660 | loDeviceID := (*pCommonID).Id |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 661 | pDeviceImageState := &voltha.DeviceImageState{DeviceId: loDeviceID} |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 662 | vendorIDSet = false |
| 663 | onuVolthaDevice = nil |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 664 | handler, err := oo.getDeviceHandler(ctx, loDeviceID, false) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 665 | if handler != nil { |
| 666 | onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID) |
| 667 | } else { |
| 668 | // assumption here is, that the concerned device was already created (automatic start after device creation not supported) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 669 | devErr = err |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 670 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 671 | if devErr != nil || onuVolthaDevice == nil { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 672 | logger.Warnw(ctx, "Failed to fetch Onu device to get image status", |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 673 | log.Fields{"device-id": loDeviceID, "err": devErr}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 674 | pImageState := &voltha.ImageState{ |
| 675 | Version: (*in).Version, |
| 676 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //no statement about last activity possible |
| 677 | Reason: voltha.ImageState_UNKNOWN_ERROR, //something like "DEVICE_NOT_EXISTS" would be better (proto def) |
| 678 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 679 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 680 | pDeviceImageState.ImageState = pImageState |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 681 | } else { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 682 | if firstDevice { |
| 683 | //start/verify download of the image to the adapter based on first found device only |
| 684 | // use the OnuVendor identification from first given device |
| 685 | firstDevice = false |
| 686 | vendorID = onuVolthaDevice.VendorId |
| 687 | imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU |
| 688 | vendorIDSet = true |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 689 | logger.Debugw(ctx, "status request for image", log.Fields{"device-id": loDeviceID, "image-id": imageIdentifier}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 690 | } else { |
| 691 | //for all following devices verify the matching vendorID |
| 692 | if onuVolthaDevice.VendorId != vendorID { |
| 693 | logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored", |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 694 | log.Fields{"device-id": loDeviceID, "onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 695 | } else { |
| 696 | vendorIDSet = true |
| 697 | } |
| 698 | } |
| 699 | if !vendorIDSet { |
| 700 | pImageState := &voltha.ImageState{ |
| 701 | Version: (*in).Version, |
| 702 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //can't be sure that download for this device was really tried |
| 703 | Reason: voltha.ImageState_VENDOR_DEVICE_MISMATCH, |
| 704 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
| 705 | } |
| 706 | pDeviceImageState.ImageState = pImageState |
| 707 | } else { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 708 | logger.Debugw(ctx, "image status request for", log.Fields{ |
| 709 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 710 | //status request is called synchronously to collect the indications for all concerned devices |
| 711 | pDeviceImageState.ImageState = handler.requestOnuSwUpgradeState(ctx, imageIdentifier, (*in).Version) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 712 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 713 | } |
| 714 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 715 | } //for all requested devices |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 716 | pImageResp := &loResponse |
| 717 | return pImageResp, nil |
| 718 | } |
| 719 | return nil, errors.New("invalid image status request parameters") |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 720 | } |
| 721 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 722 | // AbortOnuImageUpgrade stops the actual download/activation/commitment process (on next possibly step) |
| 723 | func (oo *OpenONUAC) AbortOnuImageUpgrade(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 724 | if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" { |
| 725 | loResponse := voltha.DeviceImageResponse{} |
| 726 | imageIdentifier := (*in).Version |
| 727 | firstDevice := true |
| 728 | var vendorID string |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 729 | var vendorIDSet bool |
| 730 | var onuVolthaDevice *voltha.Device |
| 731 | var devErr error |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 732 | for _, pCommonID := range (*in).DeviceId { |
| 733 | loDeviceID := (*pCommonID).Id |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 734 | pDeviceImageState := &voltha.DeviceImageState{} |
| 735 | loImageState := voltha.ImageState{} |
| 736 | pDeviceImageState.ImageState = &loImageState |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 737 | vendorIDSet = false |
| 738 | onuVolthaDevice = nil |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 739 | handler, err := oo.getDeviceHandler(ctx, loDeviceID, false) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 740 | if handler != nil { |
| 741 | onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID) |
| 742 | } else { |
| 743 | // assumption here is, that the concerned device was already created (automatic start after device creation not supported) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 744 | devErr = err |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 745 | } |
| 746 | if devErr != nil || onuVolthaDevice == nil { |
| 747 | logger.Warnw(ctx, "Failed to fetch Onu device to abort its download", |
| 748 | log.Fields{"device-id": loDeviceID, "err": devErr}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 749 | pDeviceImageState.DeviceId = loDeviceID |
| 750 | pDeviceImageState.ImageState.Version = (*in).Version |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 751 | pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 752 | pDeviceImageState.ImageState.Reason = voltha.ImageState_CANCELLED_ON_REQUEST //something better could be considered (MissingHandler) - proto |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 753 | pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 754 | } else { |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 755 | if firstDevice { |
| 756 | //start/verify download of the image to the adapter based on first found device only |
| 757 | // use the OnuVendor identification from first given device |
| 758 | firstDevice = false |
| 759 | vendorID = onuVolthaDevice.VendorId |
| 760 | vendorIDSet = true |
| 761 | imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 762 | logger.Debugw(ctx, "abort request for file", log.Fields{"device-id": loDeviceID, "image-id": imageIdentifier}) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 763 | } else { |
| 764 | //for all following devices verify the matching vendorID |
| 765 | if onuVolthaDevice.VendorId != vendorID { |
| 766 | logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored", |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 767 | log.Fields{"device-id": loDeviceID, "onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID}) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 768 | pDeviceImageState.DeviceId = loDeviceID |
| 769 | pDeviceImageState.ImageState.Version = (*in).Version |
| 770 | pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 771 | pDeviceImageState.ImageState.Reason = voltha.ImageState_VENDOR_DEVICE_MISMATCH |
| 772 | pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 773 | } else { |
| 774 | vendorIDSet = true |
| 775 | } |
| 776 | } |
| 777 | if vendorIDSet { |
| 778 | // cancel the ONU upgrade activity for each possible device |
| 779 | logger.Debugw(ctx, "image upgrade abort requested", log.Fields{ |
| 780 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 781 | //upgrade cancel is called synchronously to collect the imageResponse indications for all concerned devices |
| 782 | handler.cancelOnuSwUpgrade(ctx, imageIdentifier, (*in).Version, pDeviceImageState) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 783 | } |
| 784 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 785 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 786 | } //for all requested devices |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 787 | if !firstDevice { |
| 788 | //if at least one valid device was found cancel also a possibly running download to adapter and remove the image |
| 789 | // this is to be done after the upgradeOnu cancel activities in order to not subduct the file for still running processes |
| 790 | oo.pFileManager.CancelDownload(ctx, imageIdentifier) |
| 791 | } |
| 792 | pImageResp := &loResponse |
| 793 | return pImageResp, nil |
| 794 | } |
| 795 | return nil, errors.New("invalid image upgrade abort parameters") |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 796 | } |
| 797 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 798 | // GetOnuImages retrieves the ONU SW image status information via OMCI |
| 799 | func (oo *OpenONUAC) GetOnuImages(ctx context.Context, id *common.ID) (*voltha.OnuImages, error) { |
| 800 | logger.Infow(ctx, "Get_onu_images", log.Fields{"device-id": id.Id}) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 801 | if handler, err := oo.getDeviceHandler(ctx, id.Id, false); handler != nil { |
| 802 | images, getImagesErr := handler.getOnuImages(ctx) |
| 803 | if getImagesErr == nil { |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 804 | return images, nil |
| 805 | } |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 806 | return nil, fmt.Errorf("%s-%s", getImagesErr, id.Id) |
| 807 | } else { |
| 808 | logger.Warnw(ctx, "no handler found for Get_onu_images", log.Fields{"device-id": id.Id}) |
| 809 | return nil, err |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 810 | } |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 811 | } |
| 812 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 813 | // ActivateOnuImage initiates the activation of the image for the requested ONU(s) |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 814 | // |
| 815 | // precondition: image downloaded and not yet activated or image refers to current inactive image |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 816 | func (oo *OpenONUAC) ActivateOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 817 | if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" { |
| 818 | loResponse := voltha.DeviceImageResponse{} |
| 819 | imageIdentifier := (*in).Version |
| 820 | //let the deviceHandler find the adequate way of requesting the image activation |
| 821 | for _, pCommonID := range (*in).DeviceId { |
| 822 | loDeviceID := (*pCommonID).Id |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 823 | loDeviceImageState := voltha.DeviceImageState{} |
| 824 | loDeviceImageState.DeviceId = loDeviceID |
| 825 | loImageState := voltha.ImageState{} |
| 826 | loDeviceImageState.ImageState = &loImageState |
| 827 | loDeviceImageState.ImageState.Version = imageIdentifier |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 828 | //compared to download procedure the vendorID (from device) is secondary here |
| 829 | // and only needed in case the upgrade process is based on some ongoing download process (and can be retrieved in deviceHandler if needed) |
| 830 | // start image activation activity for each possible device |
| 831 | // assumption here is, that the concerned device was already created (automatic start after device creation not supported) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 832 | if handler, _ := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 833 | logger.Debugw(ctx, "onu image activation requested", log.Fields{ |
| 834 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 835 | //onu activation handling called in background without immediate error evaluation here |
| 836 | // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others |
| 837 | // state/progress/success of the request has to be verified using the Get_onu_image_status() API |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 838 | if pImageStates, err := handler.onuSwActivateRequest(ctx, imageIdentifier, (*in).CommitOnSuccess); err != nil { |
| 839 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 840 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR |
| 841 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED |
| 842 | } else { |
| 843 | loDeviceImageState.ImageState.DownloadState = pImageStates.DownloadState |
| 844 | loDeviceImageState.ImageState.Reason = pImageStates.Reason |
| 845 | loDeviceImageState.ImageState.ImageState = pImageStates.ImageState |
| 846 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 847 | } else { |
| 848 | //cannot start SW activation for requested device |
| 849 | logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": loDeviceID}) |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 850 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 851 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR |
| 852 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 853 | } |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 854 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 855 | } |
| 856 | pImageResp := &loResponse |
| 857 | return pImageResp, nil |
| 858 | } |
| 859 | return nil, errors.New("invalid image activation parameters") |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 860 | } |
| 861 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 862 | // CommitOnuImage enforces the commitment of the image for the requested ONU(s) |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 863 | // |
| 864 | // precondition: image activated and not yet committed |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 865 | func (oo *OpenONUAC) CommitOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 866 | if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" { |
| 867 | loResponse := voltha.DeviceImageResponse{} |
| 868 | imageIdentifier := (*in).Version |
| 869 | //let the deviceHandler find the adequate way of requesting the image activation |
| 870 | for _, pCommonID := range (*in).DeviceId { |
| 871 | loDeviceID := (*pCommonID).Id |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 872 | loDeviceImageState := voltha.DeviceImageState{} |
| 873 | loDeviceImageState.DeviceId = loDeviceID |
| 874 | loImageState := voltha.ImageState{} |
| 875 | loDeviceImageState.ImageState = &loImageState |
| 876 | loDeviceImageState.ImageState.Version = imageIdentifier |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 877 | //compared to download procedure the vendorID (from device) is secondary here |
| 878 | // and only needed in case the upgrade process is based on some ongoing download process (and can be retrieved in deviceHandler if needed) |
| 879 | // start image activation activity for each possible device |
| 880 | // assumption here is, that the concerned device was already created (automatic start after device creation not supported) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 881 | if handler, _ := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 882 | logger.Debugw(ctx, "onu image commitment requested", log.Fields{ |
| 883 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 884 | //onu commitment handling called in background without immediate error evaluation here |
| 885 | // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others |
| 886 | // state/progress/success of the request has to be verified using the Get_onu_image_status() API |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 887 | if pImageStates, err := handler.onuSwCommitRequest(ctx, imageIdentifier); err != nil { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 888 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED |
| 889 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //can be multiple reasons here |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 890 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED |
| 891 | } else { |
| 892 | loDeviceImageState.ImageState.DownloadState = pImageStates.DownloadState |
| 893 | loDeviceImageState.ImageState.Reason = pImageStates.Reason |
| 894 | loDeviceImageState.ImageState.ImageState = pImageStates.ImageState |
| 895 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 896 | } else { |
| 897 | //cannot start SW commitment for requested device |
| 898 | logger.Warnw(ctx, "no handler found for image commitment", log.Fields{"device-id": loDeviceID}) |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 899 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 900 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR |
| 901 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 902 | } |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 903 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 904 | } |
| 905 | pImageResp := &loResponse |
| 906 | return pImageResp, nil |
| 907 | } |
| 908 | return nil, errors.New("invalid image commitment parameters") |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 909 | } |
| 910 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 911 | // Adapter interface required methods ################ end ######### |
| 912 | // ################################################################# |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 913 | |
| 914 | /* |
| 915 | * |
| 916 | * ONU inter adapter service |
| 917 | * |
| 918 | */ |
| 919 | |
| 920 | // OnuIndication is part of the ONU Inter-adapter service API. |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 921 | func (oo *OpenONUAC) OnuIndication(ctx context.Context, onuInd *ia.OnuIndicationMessage) (*empty.Empty, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 922 | logger.Debugw(ctx, "onu-indication", log.Fields{"onu-indication": onuInd}) |
| 923 | |
| 924 | if onuInd == nil || onuInd.OnuIndication == nil { |
| 925 | return nil, fmt.Errorf("invalid-onu-indication-%v", onuInd) |
| 926 | } |
| 927 | |
| 928 | onuIndication := onuInd.OnuIndication |
| 929 | onuOperstate := onuIndication.GetOperState() |
| 930 | waitForDhInstPresent := false |
| 931 | if onuOperstate == "up" { |
| 932 | //Race condition (relevant in BBSIM-environment only): Due to unsynchronized processing of olt-adapter and rw_core, |
| 933 | //ONU_IND_REQUEST msg by olt-adapter could arrive a little bit earlier than rw_core was able to announce the corresponding |
| 934 | //ONU by RPC of Adopt_device(). Therefore it could be necessary to wait with processing of ONU_IND_REQUEST until call of |
| 935 | //Adopt_device() arrived and DeviceHandler instance was created |
| 936 | waitForDhInstPresent = true |
| 937 | } |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 938 | if handler, _ := oo.getDeviceHandler(ctx, onuInd.DeviceId, waitForDhInstPresent); handler != nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 939 | logger.Infow(ctx, "onu-ind-request", log.Fields{"device-id": onuInd.DeviceId, |
| 940 | "OnuId": onuIndication.GetOnuId(), |
| 941 | "AdminState": onuIndication.GetAdminState(), "OperState": onuOperstate, |
| 942 | "SNR": onuIndication.GetSerialNumber()}) |
| 943 | |
| 944 | if onuOperstate == "up" { |
| 945 | if err := handler.createInterface(ctx, onuIndication); err != nil { |
| 946 | return nil, err |
| 947 | } |
| 948 | return &empty.Empty{}, nil |
| 949 | } else if (onuOperstate == "down") || (onuOperstate == "unreachable") { |
Holger Hildebrandt | 68854a8 | 2022-09-05 07:00:21 +0000 | [diff] [blame] | 950 | if err := handler.UpdateInterface(ctx); err != nil { |
ozgecanetsia | 76db57a | 2022-02-03 15:32:03 +0300 | [diff] [blame] | 951 | return nil, err |
| 952 | } |
| 953 | return &empty.Empty{}, nil |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 954 | } else { |
| 955 | logger.Errorw(ctx, "unknown-onu-ind-request operState", log.Fields{"OnuId": onuIndication.GetOnuId()}) |
| 956 | return nil, fmt.Errorf("invalidOperState: %s, %s", onuOperstate, onuInd.DeviceId) |
| 957 | } |
| 958 | } |
| 959 | logger.Warnw(ctx, "no handler found for received onu-ind-request", log.Fields{ |
| 960 | "msgToDeviceId": onuInd.DeviceId}) |
Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 961 | return nil, fmt.Errorf("handler-not-found-%s", onuInd.DeviceId) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | // OmciIndication is part of the ONU Inter-adapter service API. |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 965 | func (oo *OpenONUAC) OmciIndication(ctx context.Context, msg *ia.OmciMessage) (*empty.Empty, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 966 | logger.Debugw(ctx, "omci-response", log.Fields{"parent-device-id": msg.ParentDeviceId, "child-device-id": msg.ChildDeviceId}) |
| 967 | |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 968 | if handler, err := oo.getDeviceHandler(ctx, msg.ChildDeviceId, false); handler != nil { |
| 969 | if omciIndErr := handler.handleOMCIIndication(log.WithSpanFromContext(context.Background(), ctx), msg); omciIndErr != nil { |
| 970 | return nil, omciIndErr |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 971 | } |
| 972 | return &empty.Empty{}, nil |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 973 | } else { |
| 974 | return nil, err |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 975 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | // DownloadTechProfile is part of the ONU Inter-adapter service API. |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 979 | func (oo *OpenONUAC) DownloadTechProfile(ctx context.Context, tProfile *ia.TechProfileDownloadMessage) (*empty.Empty, error) { |
nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 980 | logger.Info(ctx, "download-tech-profile", log.Fields{"device-id": tProfile.DeviceId, "uni-id": tProfile.UniId}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 981 | |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 982 | if handler, err := oo.getDeviceHandler(ctx, tProfile.DeviceId, false); handler != nil { |
Praneeth Nalmas | 04600be | 2024-12-08 20:12:32 +0530 | [diff] [blame] | 983 | handler.RLockMutexDeletionInProgressFlag() |
| 984 | if handler.GetDeletionInProgress() { |
| 985 | logger.Warnw(ctx, "Device deletion in progress - avoid processing Tech Profile", log.Fields{"device-id": tProfile.DeviceId}) |
| 986 | |
| 987 | handler.RUnlockMutexDeletionInProgressFlag() |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 988 | return nil, fmt.Errorf("can't proceed, device deletion is in progress-%s", tProfile.DeviceId) |
Praneeth Nalmas | 04600be | 2024-12-08 20:12:32 +0530 | [diff] [blame] | 989 | } |
| 990 | handler.RUnlockMutexDeletionInProgressFlag() |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 991 | if tpDownloadErr := handler.handleTechProfileDownloadRequest(log.WithSpanFromContext(context.Background(), ctx), tProfile); tpDownloadErr != nil { |
| 992 | return nil, tpDownloadErr |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 993 | } |
| 994 | return &empty.Empty{}, nil |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 995 | } else { |
| 996 | return nil, err |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 997 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | // DeleteGemPort is part of the ONU Inter-adapter service API. |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1001 | func (oo *OpenONUAC) DeleteGemPort(ctx context.Context, gPort *ia.DeleteGemPortMessage) (*empty.Empty, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1002 | logger.Debugw(ctx, "delete-gem-port", log.Fields{"device-id": gPort.DeviceId, "uni-id": gPort.UniId}) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 1003 | if handler, _ := oo.getDeviceHandler(ctx, gPort.DeviceId, false); handler != nil { |
nikesh.krishnan | 1249be9 | 2023-11-27 04:20:12 +0530 | [diff] [blame] | 1004 | if handler.GetDeletionInProgress() { |
| 1005 | logger.Error(ctx, "device deletion in progres", log.Fields{"device-id": gPort.DeviceId}) |
| 1006 | return nil, fmt.Errorf("device deletion in progress for device-id: %s", gPort.DeviceId) |
| 1007 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1008 | if err := handler.handleDeleteGemPortRequest(log.WithSpanFromContext(context.Background(), ctx), gPort); err != nil { |
| 1009 | return nil, err |
| 1010 | } |
Holger Hildebrandt | 5b77406 | 2021-11-10 10:24:29 +0000 | [diff] [blame] | 1011 | } else { |
| 1012 | logger.Debugw(ctx, "deviceHandler not found", log.Fields{"device-id": gPort.DeviceId}) |
| 1013 | // delete requests for objects of an already deleted ONU should be acknowledged positively - continue |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1014 | } |
Holger Hildebrandt | 5b77406 | 2021-11-10 10:24:29 +0000 | [diff] [blame] | 1015 | return &empty.Empty{}, nil |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | // DeleteTCont is part of the ONU Inter-adapter service API. |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1019 | func (oo *OpenONUAC) DeleteTCont(ctx context.Context, tConf *ia.DeleteTcontMessage) (*empty.Empty, error) { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1020 | logger.Debugw(ctx, "delete-tcont", log.Fields{"device-id": tConf.DeviceId, "tconf": tConf}) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 1021 | if handler, _ := oo.getDeviceHandler(ctx, tConf.DeviceId, false); handler != nil { |
nikesh.krishnan | 1249be9 | 2023-11-27 04:20:12 +0530 | [diff] [blame] | 1022 | if handler.GetDeletionInProgress() { |
| 1023 | logger.Error(ctx, "device deletion in progres", log.Fields{"device-id": tConf.DeviceId}) |
| 1024 | return nil, fmt.Errorf("device deletion in progress for device-id: %s", tConf.DeviceId) |
| 1025 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1026 | if err := handler.handleDeleteTcontRequest(log.WithSpanFromContext(context.Background(), ctx), tConf); err != nil { |
| 1027 | return nil, err |
| 1028 | } |
Holger Hildebrandt | 5b77406 | 2021-11-10 10:24:29 +0000 | [diff] [blame] | 1029 | } else { |
| 1030 | logger.Debugw(ctx, "deviceHandler not found", log.Fields{"device-id": tConf.DeviceId}) |
| 1031 | // delete requests for objects of an already deleted ONU should be acknowledged positively - continue |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1032 | } |
Holger Hildebrandt | 5b77406 | 2021-11-10 10:24:29 +0000 | [diff] [blame] | 1033 | return &empty.Empty{}, nil |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | /* |
| 1037 | * Parent GRPC clients |
| 1038 | */ |
| 1039 | |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 1040 | func getHash(endpoint, contextInfo string) string { |
| 1041 | strToHash := endpoint + contextInfo |
| 1042 | h := fnv.New128().Sum([]byte(strToHash)) |
| 1043 | return string(h) |
| 1044 | } |
| 1045 | |
Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 1046 | // nolint:unparam |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 1047 | func (oo *OpenONUAC) updateReachabilityFromRemote(ctx context.Context, remote *common.Connection) { |
| 1048 | logger.Debugw(context.Background(), "updating-remote-connection-status", log.Fields{"remote": remote}) |
| 1049 | oo.lockReachableFromRemote.Lock() |
| 1050 | defer oo.lockReachableFromRemote.Unlock() |
| 1051 | endpointHash := getHash(remote.Endpoint, remote.ContextInfo) |
| 1052 | if _, ok := oo.reachableFromRemote[endpointHash]; ok { |
| 1053 | oo.reachableFromRemote[endpointHash].lastKeepAlive = time.Now() |
| 1054 | oo.reachableFromRemote[endpointHash].keepAliveInterval = remote.KeepAliveInterval |
| 1055 | return |
| 1056 | } |
| 1057 | logger.Debugw(context.Background(), "initial-remote-connection", log.Fields{"remote": remote}) |
| 1058 | oo.reachableFromRemote[endpointHash] = &reachabilityFromRemote{lastKeepAlive: time.Now(), keepAliveInterval: remote.KeepAliveInterval} |
| 1059 | } |
| 1060 | |
Akash Soni | 931f9b9 | 2024-12-11 18:36:36 +0530 | [diff] [blame] | 1061 | // func (oo *OpenONUAC) isReachableFromRemote(ctx context.Context, endpoint string, contextInfo string) bool { |
| 1062 | // logger.Debugw(ctx, "checking-remote-reachability", log.Fields{"endpoint": endpoint, "context": contextInfo}) |
| 1063 | // oo.lockReachableFromRemote.RLock() |
| 1064 | // defer oo.lockReachableFromRemote.RUnlock() |
| 1065 | // endpointHash := getHash(endpoint, contextInfo) |
| 1066 | // if _, ok := oo.reachableFromRemote[endpointHash]; ok { |
| 1067 | // logger.Debugw(ctx, "endpoint-exists", log.Fields{"last-keep-alive": time.Since(oo.reachableFromRemote[endpointHash].lastKeepAlive)}) |
| 1068 | // // Assume the connection is down if we did not receive 2 keep alives in succession |
| 1069 | // maxKeepAliveWait := time.Duration(oo.reachableFromRemote[endpointHash].keepAliveInterval * 2) |
| 1070 | // return time.Since(oo.reachableFromRemote[endpointHash].lastKeepAlive) <= maxKeepAliveWait |
| 1071 | // } |
| 1072 | // return false |
| 1073 | // } |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 1074 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1075 | // stopAllGrpcClients stops all grpc clients in use |
khenaidoo | f333355 | 2021-12-15 16:52:31 -0500 | [diff] [blame] | 1076 | func (oo *OpenONUAC) stopAllGrpcClients(ctx context.Context) { |
| 1077 | // Stop the clients that connect to the parent |
| 1078 | oo.lockParentAdapterClients.Lock() |
| 1079 | for key := range oo.parentAdapterClients { |
| 1080 | oo.parentAdapterClients[key].Stop(ctx) |
| 1081 | delete(oo.parentAdapterClients, key) |
| 1082 | } |
| 1083 | oo.lockParentAdapterClients.Unlock() |
| 1084 | |
| 1085 | // Stop core client connection |
| 1086 | oo.coreClient.Stop(ctx) |
| 1087 | } |
| 1088 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1089 | func (oo *OpenONUAC) setupParentInterAdapterClient(ctx context.Context, endpoint string) error { |
| 1090 | logger.Infow(ctx, "setting-parent-adapter-connection", log.Fields{"parent-endpoint": endpoint}) |
| 1091 | oo.lockParentAdapterClients.Lock() |
| 1092 | defer oo.lockParentAdapterClients.Unlock() |
| 1093 | if _, ok := oo.parentAdapterClients[endpoint]; ok { |
| 1094 | return nil |
| 1095 | } |
| 1096 | |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 1097 | childClient, err := vgrpc.NewClient( |
| 1098 | oo.config.AdapterEndpoint, |
| 1099 | endpoint, |
khenaidoo | f333355 | 2021-12-15 16:52:31 -0500 | [diff] [blame] | 1100 | "olt_inter_adapter_service.OltInterAdapterService", |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 1101 | oo.oltAdapterRestarted) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1102 | |
| 1103 | if err != nil { |
| 1104 | return err |
| 1105 | } |
nikesh.krishnan | ce4879a | 2023-08-01 18:36:57 +0530 | [diff] [blame] | 1106 | retryCodes := []codes.Code{ |
| 1107 | codes.Unavailable, // server is currently unavailable |
| 1108 | codes.DeadlineExceeded, // deadline for the operation was exceeded |
| 1109 | } |
| 1110 | backoffCtxOption := grpc_retry.WithBackoff(grpc_retry.BackoffLinearWithJitter(oo.config.PerRPCRetryTimeout, 0.2)) |
| 1111 | grpcRetryOptions := grpc_retry.UnaryClientInterceptor(grpc_retry.WithMax(oo.config.MaxRetries), grpc_retry.WithPerRetryTimeout(oo.config.PerRPCRetryTimeout), grpc_retry.WithCodes(retryCodes...), backoffCtxOption) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1112 | |
| 1113 | oo.parentAdapterClients[endpoint] = childClient |
nikesh.krishnan | ce4879a | 2023-08-01 18:36:57 +0530 | [diff] [blame] | 1114 | go oo.parentAdapterClients[endpoint].Start(log.WithSpanFromContext(context.TODO(), ctx), getOltInterAdapterServiceClientHandler, grpcRetryOptions) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1115 | // Wait until we have a connection to the child adapter. |
| 1116 | // Unlimited retries or until context expires |
| 1117 | subCtx := log.WithSpanFromContext(context.TODO(), ctx) |
| 1118 | backoff := vgrpc.NewBackoff(oo.config.MinBackoffRetryDelay, oo.config.MaxBackoffRetryDelay, 0) |
| 1119 | for { |
| 1120 | client, err := oo.parentAdapterClients[endpoint].GetOltInterAdapterServiceClient() |
| 1121 | if err == nil && client != nil { |
| 1122 | logger.Infow(subCtx, "connected-to-parent-adapter", log.Fields{"parent-endpoint": endpoint}) |
| 1123 | break |
| 1124 | } |
| 1125 | logger.Warnw(subCtx, "connection-to-parent-adapter-not-ready", log.Fields{"error": err, "parent-endpoint": endpoint}) |
| 1126 | // Backoff |
| 1127 | if err = backoff.Backoff(subCtx); err != nil { |
| 1128 | logger.Errorw(subCtx, "received-error-on-backoff", log.Fields{"error": err, "parent-endpoint": endpoint}) |
| 1129 | break |
| 1130 | } |
| 1131 | } |
| 1132 | return nil |
| 1133 | } |
| 1134 | |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1135 | func (oo *OpenONUAC) getParentAdapterServiceClient(endpoint string) (olt_inter_adapter_service.OltInterAdapterServiceClient, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1136 | // First check from cache |
| 1137 | oo.lockParentAdapterClients.RLock() |
| 1138 | if pgClient, ok := oo.parentAdapterClients[endpoint]; ok { |
| 1139 | oo.lockParentAdapterClients.RUnlock() |
| 1140 | return pgClient.GetOltInterAdapterServiceClient() |
| 1141 | } |
| 1142 | oo.lockParentAdapterClients.RUnlock() |
| 1143 | |
| 1144 | // Set the parent connection - can occur on restarts |
| 1145 | ctx, cancel := context.WithTimeout(context.Background(), oo.config.RPCTimeout) |
| 1146 | err := oo.setupParentInterAdapterClient(ctx, endpoint) |
| 1147 | cancel() |
| 1148 | if err != nil { |
| 1149 | return nil, err |
| 1150 | } |
| 1151 | |
| 1152 | // Get the parent client now |
| 1153 | oo.lockParentAdapterClients.RLock() |
| 1154 | defer oo.lockParentAdapterClients.RUnlock() |
| 1155 | if pgClient, ok := oo.parentAdapterClients[endpoint]; ok { |
| 1156 | return pgClient.GetOltInterAdapterServiceClient() |
| 1157 | } |
| 1158 | |
| 1159 | return nil, fmt.Errorf("no-client-for-endpoint-%s", endpoint) |
| 1160 | } |
| 1161 | |
| 1162 | // TODO: Any action the adapter needs to do following an olt adapter restart? |
| 1163 | func (oo *OpenONUAC) oltAdapterRestarted(ctx context.Context, endPoint string) error { |
| 1164 | logger.Errorw(ctx, "olt-adapter-restarted", log.Fields{"endpoint": endPoint}) |
| 1165 | return nil |
| 1166 | } |
| 1167 | |
khenaidoo | f333355 | 2021-12-15 16:52:31 -0500 | [diff] [blame] | 1168 | // getOltInterAdapterServiceClientHandler is used to setup the remote gRPC service |
| 1169 | func getOltInterAdapterServiceClientHandler(ctx context.Context, conn *grpc.ClientConn) interface{} { |
| 1170 | if conn == nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1171 | return nil |
| 1172 | } |
khenaidoo | f333355 | 2021-12-15 16:52:31 -0500 | [diff] [blame] | 1173 | return olt_inter_adapter_service.NewOltInterAdapterServiceClient(conn) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1174 | } |
| 1175 | |
Holger Hildebrandt | c69f074 | 2021-11-16 13:48:00 +0000 | [diff] [blame] | 1176 | func (oo *OpenONUAC) forceDeleteDeviceKvData(ctx context.Context, aDeviceID string) error { |
| 1177 | logger.Debugw(ctx, "force deletion of ONU device specific data in kv store", log.Fields{"device-id": aDeviceID}) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 1178 | |
Girish Gowdra | f10379e | 2022-02-02 21:49:44 -0800 | [diff] [blame] | 1179 | // delete onu persitent data |
Girish Gowdra | e9ff261 | 2022-02-04 11:34:33 -0800 | [diff] [blame] | 1180 | onuBaseKvStorePath := fmt.Sprintf(cmn.CBasePathOnuKVStore, oo.cm.Backend.PathPrefix) |
| 1181 | logger.Debugw(ctx, "SetOnuKVStoreBackend", log.Fields{"IpTarget": oo.KVStoreAddress, "BasePathKvStore": onuBaseKvStorePath, |
| 1182 | "device-id": aDeviceID}) |
| 1183 | onuKvbackend := &db.Backend{ |
| 1184 | Client: oo.kvClient, |
| 1185 | StoreType: oo.KVStoreType, |
| 1186 | Address: oo.KVStoreAddress, |
| 1187 | Timeout: oo.KVStoreTimeout, |
| 1188 | PathPrefix: onuBaseKvStorePath, |
| 1189 | } |
| 1190 | err := onuKvbackend.DeleteWithPrefix(ctx, aDeviceID) |
| 1191 | if err != nil { |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 1192 | errMsg := fmt.Sprintf("unable to delete ONU persistent data at %s, error: %s", cmn.CBasePathOnuKVStore, err) |
| 1193 | logger.Error(ctx, errMsg) |
| 1194 | return status.Error(codes.Internal, errMsg) |
Holger Hildebrandt | c69f074 | 2021-11-16 13:48:00 +0000 | [diff] [blame] | 1195 | } |
Girish Gowdra | f10379e | 2022-02-02 21:49:44 -0800 | [diff] [blame] | 1196 | // delete pm data |
Girish Gowdra | e9ff261 | 2022-02-04 11:34:33 -0800 | [diff] [blame] | 1197 | pmBaseKvStorePath := fmt.Sprintf(pmmgr.CPmKvStorePrefixBase, oo.cm.Backend.PathPrefix) |
| 1198 | logger.Debugw(ctx, "SetPmKVStoreBackend", log.Fields{"IpTarget": oo.KVStoreAddress, "BasePathKvStore": pmBaseKvStorePath, |
| 1199 | "device-id": aDeviceID}) |
Girish Gowdra | f10379e | 2022-02-02 21:49:44 -0800 | [diff] [blame] | 1200 | pmKvbackend := &db.Backend{ |
| 1201 | Client: oo.kvClient, |
| 1202 | StoreType: oo.KVStoreType, |
| 1203 | Address: oo.KVStoreAddress, |
| 1204 | Timeout: oo.KVStoreTimeout, |
Girish Gowdra | e9ff261 | 2022-02-04 11:34:33 -0800 | [diff] [blame] | 1205 | PathPrefix: pmBaseKvStorePath, |
Girish Gowdra | f10379e | 2022-02-02 21:49:44 -0800 | [diff] [blame] | 1206 | } |
Girish Gowdra | e9ff261 | 2022-02-04 11:34:33 -0800 | [diff] [blame] | 1207 | err = pmKvbackend.DeleteWithPrefix(ctx, aDeviceID) |
Girish Gowdra | f10379e | 2022-02-02 21:49:44 -0800 | [diff] [blame] | 1208 | if err != nil { |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 1209 | errMsg := fmt.Sprintf("unable to delete device PM data in KVstore at %s, error: %s", pmmgr.CPmKvStorePrefixBase, err) |
| 1210 | logger.Error(ctx, errMsg) |
| 1211 | return status.Error(codes.Internal, errMsg) |
Girish Gowdra | f10379e | 2022-02-02 21:49:44 -0800 | [diff] [blame] | 1212 | } |
Holger Hildebrandt | c69f074 | 2021-11-16 13:48:00 +0000 | [diff] [blame] | 1213 | return nil |
| 1214 | } |
| 1215 | |
khenaidoo | f333355 | 2021-12-15 16:52:31 -0500 | [diff] [blame] | 1216 | // GetHealthStatus is used by the voltha core to open a streaming connection with the onu adapter. |
| 1217 | func (oo *OpenONUAC) GetHealthStatus(stream adapter_service.AdapterService_GetHealthStatusServer) error { |
| 1218 | ctx := context.Background() |
| 1219 | logger.Debugw(ctx, "receive-stream-connection", log.Fields{"stream": stream}) |
| 1220 | |
| 1221 | if stream == nil { |
| 1222 | return fmt.Errorf("conn-is-nil %v", stream) |
| 1223 | } |
| 1224 | initialRequestTime := time.Now() |
| 1225 | var remoteClient *common.Connection |
| 1226 | var tempClient *common.Connection |
| 1227 | var err error |
| 1228 | loop: |
| 1229 | for { |
| 1230 | tempClient, err = stream.Recv() |
| 1231 | if err != nil { |
| 1232 | logger.Warnw(ctx, "received-stream-error", log.Fields{"remote-client": remoteClient, "error": err}) |
| 1233 | break loop |
| 1234 | } |
| 1235 | // Send a response back |
| 1236 | err = stream.Send(&health.HealthStatus{State: health.HealthStatus_HEALTHY}) |
| 1237 | if err != nil { |
| 1238 | logger.Warnw(ctx, "sending-stream-error", log.Fields{"remote-client": remoteClient, "error": err}) |
| 1239 | break loop |
| 1240 | } |
| 1241 | remoteClient = tempClient |
| 1242 | |
| 1243 | logger.Debugw(ctx, "received-keep-alive", log.Fields{"remote-client": remoteClient}) |
| 1244 | |
| 1245 | select { |
| 1246 | case <-stream.Context().Done(): |
| 1247 | logger.Infow(ctx, "stream-keep-alive-context-done", log.Fields{"remote-client": remoteClient, "error": stream.Context().Err()}) |
| 1248 | break loop |
| 1249 | case <-oo.exitChannel: |
| 1250 | logger.Warnw(ctx, "received-stop", log.Fields{"remote-client": remoteClient, "initial-conn-time": initialRequestTime}) |
| 1251 | break loop |
| 1252 | default: |
| 1253 | } |
| 1254 | } |
| 1255 | logger.Errorw(ctx, "connection-down", log.Fields{"remote-client": remoteClient, "error": err, "initial-conn-time": initialRequestTime}) |
| 1256 | return err |
| 1257 | } |
| 1258 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1259 | /* |
| 1260 | * |
| 1261 | * Unimplemented APIs |
| 1262 | * |
| 1263 | */ |
| 1264 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1265 | // GetOfpDeviceInfo returns OFP information for the given device. Method not implemented as per [VOL-3202]. |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1266 | // OF port info is now to be delivered within UniPort create cmp changes in onu_uni_port.go::CreateVolthaPort() |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1267 | func (oo *OpenONUAC) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ca.SwitchCapability, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1268 | return nil, errors.New("unImplemented") |
| 1269 | } |
| 1270 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1271 | // SimulateAlarm is unimplemented |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1272 | func (oo *OpenONUAC) SimulateAlarm(context.Context, *ca.SimulateAlarmMessage) (*common.OperationResp, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1273 | return nil, errors.New("unImplemented") |
| 1274 | } |
| 1275 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1276 | // SetExtValue is unimplemented |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1277 | func (oo *OpenONUAC) SetExtValue(context.Context, *ca.SetExtValueMessage) (*empty.Empty, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1278 | return nil, errors.New("unImplemented") |
| 1279 | } |
| 1280 | |
Akash Soni | 3c176c6 | 2024-12-04 13:30:43 +0530 | [diff] [blame] | 1281 | // SetSingleValue sets a single value based on the given request and returns the response. |
| 1282 | func (oo *OpenONUAC) SetSingleValue(ctx context.Context, request *extension.SingleSetValueRequest) (*extension.SingleSetValueResponse, error) { |
| 1283 | logger.Infow(ctx, "single_set_value_request", log.Fields{"request": request}) |
| 1284 | |
| 1285 | errResp := func(status extension.SetValueResponse_Status, |
| 1286 | reason extension.SetValueResponse_ErrorReason) *extension.SingleSetValueResponse { |
| 1287 | return &extension.SingleSetValueResponse{ |
| 1288 | Response: &extension.SetValueResponse{ |
| 1289 | Status: status, |
| 1290 | ErrReason: reason, |
| 1291 | }, |
| 1292 | } |
| 1293 | } |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 1294 | if handler, err := oo.getDeviceHandler(ctx, request.TargetId, false); handler != nil { |
Akash Soni | 3c176c6 | 2024-12-04 13:30:43 +0530 | [diff] [blame] | 1295 | switch reqType := request.GetRequest().GetRequest().(type) { |
| 1296 | case *extension.SetValueRequest_AppOffloadOnuConfig: |
| 1297 | return handler.setOnuOffloadStats(ctx, reqType.AppOffloadOnuConfig), nil |
| 1298 | default: |
| 1299 | return errResp(extension.SetValueResponse_ERROR, extension.SetValueResponse_UNSUPPORTED), nil |
| 1300 | } |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame^] | 1301 | } else { |
| 1302 | logger.Errorw(ctx, "Single_set_value_request failed ", log.Fields{"request": request}) |
| 1303 | return errResp(extension.SetValueResponse_ERROR, extension.SetValueResponse_INVALID_DEVICE_ID), err |
Akash Soni | 3c176c6 | 2024-12-04 13:30:43 +0530 | [diff] [blame] | 1304 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1305 | } |
| 1306 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1307 | // StartOmciTest not implemented |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1308 | func (oo *OpenONUAC) StartOmciTest(ctx context.Context, test *ca.OMCITest) (*omci.TestResponse, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1309 | return nil, errors.New("unImplemented") |
| 1310 | } |
| 1311 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1312 | // SuppressEvent unimplemented |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1313 | func (oo *OpenONUAC) SuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) { |
| 1314 | return nil, errors.New("unImplemented") |
| 1315 | } |
| 1316 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1317 | // UnSuppressEvent unimplemented |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1318 | func (oo *OpenONUAC) UnSuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) { |
| 1319 | return nil, errors.New("unImplemented") |
| 1320 | } |
| 1321 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1322 | // GetImageDownloadStatus is unimplemented |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1323 | func (oo *OpenONUAC) GetImageDownloadStatus(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1324 | return nil, errors.New("unImplemented") |
| 1325 | } |
| 1326 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1327 | // CancelImageDownload is unimplemented |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1328 | func (oo *OpenONUAC) CancelImageDownload(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1329 | return nil, errors.New("unImplemented") |
| 1330 | } |
| 1331 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1332 | // RevertImageUpdate is unimplemented |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1333 | func (oo *OpenONUAC) RevertImageUpdate(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1334 | return nil, errors.New("unImplemented") |
| 1335 | } |
| 1336 | |
| 1337 | // UpdateFlowsBulk is unimplemented |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1338 | func (oo *OpenONUAC) UpdateFlowsBulk(ctx context.Context, flows *ca.BulkFlows) (*empty.Empty, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1339 | return nil, errors.New("unImplemented") |
| 1340 | } |
| 1341 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1342 | // SelfTestDevice unimplented |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1343 | func (oo *OpenONUAC) SelfTestDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 1344 | return nil, errors.New("unImplemented") |
| 1345 | } |
| 1346 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1347 | // SendPacketOut sends packet out to the device |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1348 | func (oo *OpenONUAC) SendPacketOut(ctx context.Context, packet *ca.PacketOut) (*empty.Empty, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1349 | return nil, errors.New("unImplemented") |
| 1350 | } |
| 1351 | |
| 1352 | // EnablePort to Enable PON/NNI interface - seems not to be used/required according to python code |
| 1353 | func (oo *OpenONUAC) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { |
| 1354 | return nil, errors.New("unImplemented") |
| 1355 | } |
| 1356 | |
| 1357 | // DisablePort to Disable pon/nni interface - seems not to be used/required according to python code |
| 1358 | func (oo *OpenONUAC) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { |
| 1359 | return nil, errors.New("unImplemented") |
| 1360 | } |
| 1361 | |
| 1362 | // GetExtValue - unimplemented |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1363 | func (oo *OpenONUAC) GetExtValue(ctx context.Context, extInfo *ca.GetExtValueMessage) (*extension.ReturnValues, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1364 | return nil, errors.New("unImplemented") |
| 1365 | } |
| 1366 | |
| 1367 | // ChildDeviceLost - unimplemented |
| 1368 | func (oo *OpenONUAC) ChildDeviceLost(ctx context.Context, childDevice *voltha.Device) (*empty.Empty, error) { |
| 1369 | return nil, errors.New("unImplemented") |
| 1370 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1371 | |
| 1372 | // GetSupportedFsms - TODO: add comment |
| 1373 | func (oo *OpenONUAC) GetSupportedFsms() *cmn.OmciDeviceFsms { |
| 1374 | return oo.pSupportedFsms |
| 1375 | } |
| 1376 | |
| 1377 | // LockMutexMibTemplateGenerated - TODO: add comment |
| 1378 | func (oo *OpenONUAC) LockMutexMibTemplateGenerated() { |
| 1379 | oo.mutexMibTemplateGenerated.Lock() |
| 1380 | } |
| 1381 | |
| 1382 | // UnlockMutexMibTemplateGenerated - TODO: add comment |
| 1383 | func (oo *OpenONUAC) UnlockMutexMibTemplateGenerated() { |
| 1384 | oo.mutexMibTemplateGenerated.Unlock() |
| 1385 | } |
| 1386 | |
| 1387 | // GetMibTemplatesGenerated - TODO: add comment |
| 1388 | func (oo *OpenONUAC) GetMibTemplatesGenerated(mibTemplatePath string) (value bool, exist bool) { |
| 1389 | value, exist = oo.mibTemplatesGenerated[mibTemplatePath] |
| 1390 | return value, exist |
| 1391 | } |
| 1392 | |
| 1393 | // SetMibTemplatesGenerated - TODO: add comment |
| 1394 | func (oo *OpenONUAC) SetMibTemplatesGenerated(mibTemplatePath string, value bool) { |
| 1395 | oo.mibTemplatesGenerated[mibTemplatePath] = value |
| 1396 | } |
| 1397 | |
| 1398 | // RLockMutexDeviceHandlersMap - TODO: add comment |
| 1399 | func (oo *OpenONUAC) RLockMutexDeviceHandlersMap() { |
| 1400 | oo.mutexDeviceHandlersMap.RLock() |
| 1401 | } |
| 1402 | |
| 1403 | // RUnlockMutexDeviceHandlersMap - TODO: add comment |
| 1404 | func (oo *OpenONUAC) RUnlockMutexDeviceHandlersMap() { |
| 1405 | oo.mutexDeviceHandlersMap.RUnlock() |
| 1406 | } |
| 1407 | |
| 1408 | // GetDeviceHandler - TODO: add comment |
| 1409 | func (oo *OpenONUAC) GetDeviceHandler(deviceID string) (value cmn.IdeviceHandler, exist bool) { |
| 1410 | value, exist = oo.deviceHandlers[deviceID] |
| 1411 | return value, exist |
| 1412 | } |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame] | 1413 | |
| 1414 | // GetONUMIBDBMap - Returns the Map corresponding to ONT type and the MIB common Instance. |
| 1415 | func (oo *OpenONUAC) GetONUMIBDBMap() devdb.OnuMCmnMEDBMap { |
| 1416 | return oo.MibDatabaseMap |
| 1417 | } |
| 1418 | |
| 1419 | // RLockMutexMIBDatabaseMap acquires a read lock on the mutex associated with the MIBDatabaseMap. |
| 1420 | func (oo *OpenONUAC) RLockMutexMIBDatabaseMap() { |
| 1421 | oo.mutexMibDatabaseMap.RLock() |
| 1422 | } |
| 1423 | |
| 1424 | // RUnlockMutexMIBDatabaseMap releases the read lock on the mutex associated with the MIBDatabaseMap. |
| 1425 | func (oo *OpenONUAC) RUnlockMutexMIBDatabaseMap() { |
| 1426 | oo.mutexMibDatabaseMap.RUnlock() |
| 1427 | } |
| 1428 | |
| 1429 | // LockMutexMIBDatabaseMap locks the mutex associated with the MIBDatabaseMap. |
| 1430 | // Should be called before any operations that modify or read from the MIBDatabaseMap. |
| 1431 | func (oo *OpenONUAC) LockMutexMIBDatabaseMap() { |
| 1432 | oo.mutexMibDatabaseMap.Lock() |
| 1433 | } |
| 1434 | |
| 1435 | // UnlockMutexMIBDatabaseMap unlocks the mutex associated with the MIBDatabaseMap. |
| 1436 | // Should be called after completing operations that require exclusive access |
| 1437 | // to the MIBDatabaseMap, ensuring the mutex is released for other goroutines. |
| 1438 | func (oo *OpenONUAC) UnlockMutexMIBDatabaseMap() { |
| 1439 | oo.mutexMibDatabaseMap.Unlock() |
| 1440 | } |
| 1441 | |
| 1442 | // CreateEntryAtMibDatabaseMap adds an entry to the MibDatabaseMap if it doesn't exist |
| 1443 | func (oo *OpenONUAC) CreateEntryAtMibDatabaseMap(ctx context.Context, key string) (*devdb.OnuCmnMEDB, error) { |
| 1444 | oo.mutexMibDatabaseMap.Lock() |
| 1445 | defer oo.mutexMibDatabaseMap.Unlock() |
| 1446 | |
| 1447 | // Check if the key already exists |
| 1448 | if mibEntry, exists := oo.MibDatabaseMap[key]; exists { |
| 1449 | logger.Warnw(ctx, "Entry already exists in MIB Database Map", log.Fields{"remote-client": key}) |
| 1450 | return mibEntry, fmt.Errorf("entry already exists for key: %s", key) |
| 1451 | } |
| 1452 | |
| 1453 | value := devdb.NewOnuCmnMEDB(ctx) |
| 1454 | |
| 1455 | logger.Infow(ctx, "Created a new Common MIB Database Entry", log.Fields{"remote-client": key}) |
| 1456 | oo.MibDatabaseMap[key] = value |
| 1457 | |
| 1458 | return value, nil |
| 1459 | } |
| 1460 | |
| 1461 | // FetchEntryFromMibDatabaseMap fetches a references to common ME DB for a MIB Template from the MibDatabaseMap |
| 1462 | // If a valid entry exists returns pointer to cmnDB else returns nil. |
| 1463 | func (oo *OpenONUAC) FetchEntryFromMibDatabaseMap(ctx context.Context, key string) (*devdb.OnuCmnMEDB, bool) { |
| 1464 | oo.mutexMibDatabaseMap.RLock() |
| 1465 | defer oo.mutexMibDatabaseMap.RUnlock() |
| 1466 | value, exists := oo.MibDatabaseMap[key] |
| 1467 | if !exists { |
| 1468 | return nil, false |
| 1469 | } |
| 1470 | return value, true |
| 1471 | |
| 1472 | } |
| 1473 | |
| 1474 | // ResetEntryFromMibDatabaseMap resets the ME values from the Maps. |
| 1475 | func (oo *OpenONUAC) ResetEntryFromMibDatabaseMap(ctx context.Context, key string) { |
| 1476 | oo.mutexMibDatabaseMap.RLock() |
| 1477 | onuCmnMEDB, exists := oo.MibDatabaseMap[key] |
| 1478 | oo.mutexMibDatabaseMap.RUnlock() |
| 1479 | if exists { |
| 1480 | // Lock the MeDbLock to ensure thread-safe operation |
| 1481 | onuCmnMEDB.MeDbLock.Lock() |
| 1482 | defer onuCmnMEDB.MeDbLock.Unlock() |
| 1483 | |
| 1484 | // Reset the MeDb and UnknownMeAndAttribDb maps |
| 1485 | onuCmnMEDB.MeDb = make(devdb.MeDbMap) |
| 1486 | onuCmnMEDB.UnknownMeAndAttribDb = make(devdb.UnknownMeAndAttribDbMap) |
| 1487 | |
| 1488 | } |
| 1489 | } |
| 1490 | |
| 1491 | // DeleteEntryFromMibDatabaseMap deletes an entry from the MibDatabaseMap |
| 1492 | func (oo *OpenONUAC) DeleteEntryFromMibDatabaseMap(key string) { |
| 1493 | oo.mutexMibDatabaseMap.Lock() |
| 1494 | defer oo.mutexMibDatabaseMap.Unlock() |
| 1495 | delete(oo.MibDatabaseMap, key) |
| 1496 | } |