Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 17 | //Package core provides the utility for onu devices, flows and statistics |
| 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 | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 25 | "sync" |
| 26 | "time" |
| 27 | |
Holger Hildebrandt | 6065220 | 2021-11-02 11:09:36 +0000 | [diff] [blame] | 28 | "github.com/opencord/voltha-lib-go/v7/pkg/db" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 29 | vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc" |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 30 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 31 | conf "github.com/opencord/voltha-lib-go/v7/pkg/config" |
| 32 | "github.com/opencord/voltha-protos/v5/go/common" |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 33 | "github.com/opencord/voltha-protos/v5/go/health" |
| 34 | "github.com/opencord/voltha-protos/v5/go/olt_inter_adapter_service" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 35 | "google.golang.org/grpc" |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 36 | "google.golang.org/grpc/codes" |
| 37 | "google.golang.org/grpc/status" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 38 | |
| 39 | "github.com/golang/protobuf/ptypes/empty" |
| 40 | "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore" |
| 41 | "github.com/opencord/voltha-lib-go/v7/pkg/events/eventif" |
| 42 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 43 | ca "github.com/opencord/voltha-protos/v5/go/core_adapter" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 44 | "github.com/opencord/voltha-protos/v5/go/extension" |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 45 | ia "github.com/opencord/voltha-protos/v5/go/inter_adapter" |
| 46 | "github.com/opencord/voltha-protos/v5/go/omci" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 47 | "github.com/opencord/voltha-protos/v5/go/voltha" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 48 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 49 | cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common" |
Matteo Scandolo | 761f751 | 2020-11-23 15:52:40 -0800 | [diff] [blame] | 50 | "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/config" |
Holger Hildebrandt | 6065220 | 2021-11-02 11:09:36 +0000 | [diff] [blame] | 51 | pmmgr "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/pmmgr" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 52 | "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/swupg" |
| 53 | uniprt "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/uniprt" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 54 | ) |
| 55 | |
Holger Hildebrandt | 6065220 | 2021-11-02 11:09:36 +0000 | [diff] [blame] | 56 | var onuKvStorePathPrefixes = []string{cmn.CBasePathOnuKVStore, pmmgr.CPmKvStorePrefixBase} |
| 57 | |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 58 | type reachabilityFromRemote struct { |
| 59 | lastKeepAlive time.Time |
| 60 | keepAliveInterval int64 |
| 61 | } |
| 62 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 63 | //OpenONUAC structure holds the ONU core information |
| 64 | type OpenONUAC struct { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 65 | deviceHandlers map[string]*deviceHandler |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 66 | deviceHandlersCreateChan map[string]chan bool //channels for deviceHandler create events |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 67 | mutexDeviceHandlersMap sync.RWMutex |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 68 | coreClient *vgrpc.Client |
| 69 | parentAdapterClients map[string]*vgrpc.Client |
| 70 | lockParentAdapterClients sync.RWMutex |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 71 | reachableFromRemote map[string]*reachabilityFromRemote |
| 72 | lockReachableFromRemote sync.RWMutex |
Himani Chawla | c07fda0 | 2020-12-09 16:21:21 +0530 | [diff] [blame] | 73 | eventProxy eventif.EventProxy |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 74 | kvClient kvstore.Client |
Matteo Scandolo | f1f39a7 | 2020-11-24 12:08:11 -0800 | [diff] [blame] | 75 | cm *conf.ConfigManager |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 76 | config *config.AdapterFlags |
| 77 | numOnus int |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 78 | KVStoreAddress string |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 79 | KVStoreType string |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 80 | KVStoreTimeout time.Duration |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 81 | mibTemplatesGenerated map[string]bool |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 82 | mutexMibTemplateGenerated sync.RWMutex |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 83 | exitChannel chan int |
| 84 | HeartbeatCheckInterval time.Duration |
| 85 | HeartbeatFailReportInterval time.Duration |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 86 | AcceptIncrementalEvto bool |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 87 | pSupportedFsms *cmn.OmciDeviceFsms |
| 88 | maxTimeoutInterAdapterComm time.Duration |
| 89 | maxTimeoutReconciling time.Duration |
| 90 | pDownloadManager *swupg.AdapterDownloadManager |
| 91 | pFileManager *swupg.FileDownloadManager //let coexist 'old and new' DownloadManager as long as 'old' does not get obsolete |
| 92 | MetricsEnabled bool |
| 93 | mibAuditInterval time.Duration |
| 94 | omciTimeout int // in seconds |
| 95 | alarmAuditInterval time.Duration |
| 96 | dlToOnuTimeout4M time.Duration |
| 97 | rpcTimeout time.Duration |
| 98 | maxConcurrentFlowsPerUni int |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | //NewOpenONUAC returns a new instance of OpenONU_AC |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 102 | func NewOpenONUAC(ctx context.Context, coreClient *vgrpc.Client, eventProxy eventif.EventProxy, |
| 103 | kvClient kvstore.Client, cfg *config.AdapterFlags, cm *conf.ConfigManager) *OpenONUAC { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 104 | var openOnuAc OpenONUAC |
| 105 | openOnuAc.exitChannel = make(chan int, 1) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 106 | openOnuAc.deviceHandlers = make(map[string]*deviceHandler) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 107 | openOnuAc.deviceHandlersCreateChan = make(map[string]chan bool) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 108 | openOnuAc.parentAdapterClients = make(map[string]*vgrpc.Client) |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 109 | openOnuAc.reachableFromRemote = make(map[string]*reachabilityFromRemote) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 110 | openOnuAc.mutexDeviceHandlersMap = sync.RWMutex{} |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 111 | openOnuAc.config = cfg |
Matteo Scandolo | f1f39a7 | 2020-11-24 12:08:11 -0800 | [diff] [blame] | 112 | openOnuAc.cm = cm |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 113 | openOnuAc.coreClient = coreClient |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 114 | openOnuAc.numOnus = cfg.OnuNumber |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 115 | openOnuAc.eventProxy = eventProxy |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 116 | openOnuAc.kvClient = kvClient |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 117 | openOnuAc.KVStoreAddress = cfg.KVStoreAddress |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 118 | openOnuAc.KVStoreType = cfg.KVStoreType |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 119 | openOnuAc.KVStoreTimeout = cfg.KVStoreTimeout |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 120 | openOnuAc.mibTemplatesGenerated = make(map[string]bool) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 121 | openOnuAc.mutexMibTemplateGenerated = sync.RWMutex{} |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 122 | openOnuAc.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval |
| 123 | openOnuAc.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 124 | openOnuAc.AcceptIncrementalEvto = cfg.AccIncrEvto |
Himani Chawla | d96df18 | 2020-09-28 11:12:02 +0530 | [diff] [blame] | 125 | openOnuAc.maxTimeoutInterAdapterComm = cfg.MaxTimeoutInterAdapterComm |
Holger Hildebrandt | 38985dc | 2021-02-18 16:25:20 +0000 | [diff] [blame] | 126 | openOnuAc.maxTimeoutReconciling = cfg.MaxTimeoutReconciling |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 127 | //openOnuAc.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 128 | openOnuAc.MetricsEnabled = cfg.MetricsEnabled |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 129 | openOnuAc.mibAuditInterval = cfg.MibAuditInterval |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 130 | // since consumers of OMCI timeout value everywhere in code is in "int seconds", do this useful conversion |
| 131 | openOnuAc.omciTimeout = int(cfg.OmciTimeout.Seconds()) |
Himani Chawla | 075f164 | 2021-03-15 19:23:24 +0530 | [diff] [blame] | 132 | openOnuAc.alarmAuditInterval = cfg.AlarmAuditInterval |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 133 | openOnuAc.dlToOnuTimeout4M = cfg.DownloadToOnuTimeout4MB |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 134 | openOnuAc.rpcTimeout = cfg.RPCTimeout |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 135 | openOnuAc.maxConcurrentFlowsPerUni = cfg.MaxConcurrentFlowsPerUni |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 136 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 137 | openOnuAc.pSupportedFsms = &cmn.OmciDeviceFsms{ |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 138 | "mib-synchronizer": { |
| 139 | //mibSyncFsm, // Implements the MIB synchronization state machine |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 140 | DatabaseClass: mibDbVolatileDictImpl, // Implements volatile ME MIB database |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 141 | //true, // Advertise events on OpenOMCI event bus |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 142 | 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] | 143 | // map[string]func() error{ |
| 144 | // "mib-upload": onuDeviceEntry.MibUploadTask, |
| 145 | // "mib-template": onuDeviceEntry.MibTemplateTask, |
| 146 | // "get-mds": onuDeviceEntry.GetMdsTask, |
| 147 | // "mib-audit": onuDeviceEntry.GetMdsTask, |
| 148 | // "mib-resync": onuDeviceEntry.MibResyncTask, |
| 149 | // "mib-reconcile": onuDeviceEntry.MibReconcileTask, |
| 150 | // }, |
| 151 | }, |
| 152 | } |
| 153 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 154 | openOnuAc.pDownloadManager = swupg.NewAdapterDownloadManager(ctx) |
| 155 | openOnuAc.pFileManager = swupg.NewFileDownloadManager(ctx) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 156 | openOnuAc.pFileManager.SetDownloadTimeout(ctx, cfg.DownloadToAdapterTimeout) |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 157 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 158 | return &openOnuAc |
| 159 | } |
| 160 | |
| 161 | //Start starts (logs) the adapter |
| 162 | func (oo *OpenONUAC) Start(ctx context.Context) error { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 163 | logger.Info(ctx, "starting-openonu-adapter") |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 164 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 165 | return nil |
| 166 | } |
| 167 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 168 | /* |
| 169 | //stop terminates the session |
| 170 | func (oo *OpenONUAC) stop(ctx context.Context) error { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 171 | logger.Info(ctx,"stopping-device-manager") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 172 | oo.exitChannel <- 1 |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 173 | logger.Info(ctx,"device-manager-stopped") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 174 | return nil |
| 175 | } |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 176 | */ |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 177 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 178 | func (oo *OpenONUAC) addDeviceHandlerToMap(ctx context.Context, agent *deviceHandler) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 179 | oo.mutexDeviceHandlersMap.Lock() |
| 180 | defer oo.mutexDeviceHandlersMap.Unlock() |
| 181 | if _, exist := oo.deviceHandlers[agent.DeviceID]; !exist { |
| 182 | oo.deviceHandlers[agent.DeviceID] = agent |
| 183 | oo.deviceHandlers[agent.DeviceID].start(ctx) |
| 184 | if _, exist := oo.deviceHandlersCreateChan[agent.DeviceID]; exist { |
| 185 | logger.Debugw(ctx, "deviceHandler created - trigger processing of pending ONU_IND_REQUEST", log.Fields{"device-id": agent.DeviceID}) |
| 186 | oo.deviceHandlersCreateChan[agent.DeviceID] <- true |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 187 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 191 | func (oo *OpenONUAC) deleteDeviceHandlerToMap(agent *deviceHandler) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 192 | oo.mutexDeviceHandlersMap.Lock() |
| 193 | defer oo.mutexDeviceHandlersMap.Unlock() |
| 194 | delete(oo.deviceHandlers, agent.DeviceID) |
| 195 | delete(oo.deviceHandlersCreateChan, agent.DeviceID) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 196 | } |
| 197 | |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 198 | //getDeviceHandler gets the ONU deviceHandler and may wait until it is created |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 199 | func (oo *OpenONUAC) getDeviceHandler(ctx context.Context, deviceID string, aWait bool) *deviceHandler { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 200 | oo.mutexDeviceHandlersMap.Lock() |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 201 | agent, ok := oo.deviceHandlers[deviceID] |
| 202 | if aWait && !ok { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 203 | 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] | 204 | log.Fields{"device-id": deviceID}) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 205 | if _, exist := oo.deviceHandlersCreateChan[deviceID]; !exist { |
| 206 | oo.deviceHandlersCreateChan[deviceID] = make(chan bool, 1) |
| 207 | } |
Girish Gowdra | 7407a4d | 2020-11-12 12:44:53 -0800 | [diff] [blame] | 208 | deviceCreateChan := oo.deviceHandlersCreateChan[deviceID] |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 209 | //keep the read sema short to allow for subsequent write |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 210 | oo.mutexDeviceHandlersMap.Unlock() |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 211 | // based on concurrent processing the deviceHandler creation may not yet be finished at his point |
| 212 | // so it might be needed to wait here for that event with some timeout |
| 213 | select { |
| 214 | case <-time.After(1 * time.Second): //timer may be discussed ... |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 215 | logger.Warnw(ctx, "No valid deviceHandler created after max WaitTime", log.Fields{"device-id": deviceID}) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 216 | return nil |
Girish Gowdra | 7407a4d | 2020-11-12 12:44:53 -0800 | [diff] [blame] | 217 | case <-deviceCreateChan: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 218 | 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] | 219 | oo.mutexDeviceHandlersMap.RLock() |
| 220 | defer oo.mutexDeviceHandlersMap.RUnlock() |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 221 | return oo.deviceHandlers[deviceID] |
| 222 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 223 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 224 | oo.mutexDeviceHandlersMap.Unlock() |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 225 | return agent |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 226 | } |
| 227 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 228 | // GetHealthStatus is used as a service readiness validation as a grpc connection |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 229 | func (oo *OpenONUAC) GetHealthStatus(ctx context.Context, clientConn *common.Connection) (*health.HealthStatus, error) { |
| 230 | // Update the remote reachability |
| 231 | oo.updateReachabilityFromRemote(ctx, clientConn) |
| 232 | |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 233 | return &health.HealthStatus{State: health.HealthStatus_HEALTHY}, nil |
Holger Hildebrandt | 6c1fb0a | 2020-11-25 15:41:01 +0000 | [diff] [blame] | 234 | } |
| 235 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 236 | // AdoptDevice creates a new device handler if not present already and then adopts the device |
| 237 | 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] | 238 | if device == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 239 | logger.Warn(ctx, "voltha-device-is-nil") |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 240 | return nil, errors.New("nil-device") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 241 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 242 | logger.Infow(ctx, "adopt-device", log.Fields{"device-id": device.Id}) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 243 | var handler *deviceHandler |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 244 | if handler = oo.getDeviceHandler(ctx, device.Id, false); handler == nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 245 | handler := newDeviceHandler(ctx, oo.coreClient, oo.eventProxy, device, oo) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 246 | oo.addDeviceHandlerToMap(ctx, handler) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 247 | |
| 248 | // Setup the grpc communication with the parent adapter |
| 249 | if err := oo.setupParentInterAdapterClient(ctx, device.ProxyAddress.AdapterEndpoint); err != nil { |
| 250 | // TODO: Cleanup on failure needed |
| 251 | return nil, err |
| 252 | } |
| 253 | |
| 254 | go handler.adoptOrReconcileDevice(log.WithSpanFromContext(context.Background(), ctx), device) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 255 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 256 | return &empty.Empty{}, nil |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 257 | } |
| 258 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 259 | //ReconcileDevice is called once when the adapter needs to re-create device - usually on core restart |
| 260 | 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] | 261 | if device == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 262 | logger.Warn(ctx, "reconcile-device-voltha-device-is-nil") |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 263 | return nil, errors.New("nil-device") |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 264 | } |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 265 | logger.Infow(ctx, "reconcile-device", log.Fields{"device-id": device.Id, "parent-id": device.ParentId}) |
| 266 | |
| 267 | // Check whether the grpc client in the adapter of the parent device can reach us yet |
| 268 | if !oo.isReachableFromRemote(device.ProxyAddress.AdapterEndpoint, device.ParentId) { |
| 269 | return nil, status.Errorf(codes.Unavailable, "adapter-not-reachable-from-parent-%s", device.ProxyAddress.AdapterEndpoint) |
| 270 | } |
| 271 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 272 | var handler *deviceHandler |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 273 | if handler = oo.getDeviceHandler(ctx, device.Id, false); handler == nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 274 | handler := newDeviceHandler(ctx, oo.coreClient, oo.eventProxy, device, oo) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 275 | oo.addDeviceHandlerToMap(ctx, handler) |
| 276 | handler.device = device |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 277 | if err := handler.updateDeviceStateInCore(log.WithSpanFromContext(context.Background(), ctx), &ca.DeviceStateFilter{ |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 278 | DeviceId: device.Id, |
| 279 | OperStatus: voltha.OperStatus_RECONCILING, |
| 280 | ConnStatus: device.ConnectStatus, |
| 281 | }); err != nil { |
| 282 | 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] | 283 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 284 | // Setup the grpc communication with the parent adapter |
| 285 | if err := oo.setupParentInterAdapterClient(ctx, device.ProxyAddress.AdapterEndpoint); err != nil { |
| 286 | // TODO: Cleanup on failure needed |
| 287 | return nil, err |
| 288 | } |
| 289 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 290 | handler.StartReconciling(log.WithSpanFromContext(context.Background(), ctx), false) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 291 | go handler.adoptOrReconcileDevice(log.WithSpanFromContext(context.Background(), ctx), handler.device) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 292 | // reconcilement will be continued after onu-device entry is added |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 293 | } else { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 294 | return nil, fmt.Errorf(fmt.Sprintf("device-already-reconciled-or-active-%s", device.Id)) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 295 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 296 | return &empty.Empty{}, nil |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 297 | } |
| 298 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 299 | //DisableDevice disables the given device |
| 300 | func (oo *OpenONUAC) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 301 | logger.Infow(ctx, "disable-device", log.Fields{"device-id": device.Id}) |
| 302 | if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 303 | go handler.disableDevice(log.WithSpanFromContext(context.Background(), ctx), device) |
| 304 | return &empty.Empty{}, nil |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 305 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 306 | logger.Warnw(ctx, "no handler found for device-disable", log.Fields{"device-id": device.Id}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 307 | return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id)) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 308 | } |
| 309 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 310 | //ReEnableDevice enables the onu device after disable |
| 311 | func (oo *OpenONUAC) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 312 | logger.Infow(ctx, "reenable-device", log.Fields{"device-id": device.Id}) |
| 313 | if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 314 | go handler.reEnableDevice(log.WithSpanFromContext(context.Background(), ctx), device) |
| 315 | return &empty.Empty{}, nil |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 316 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 317 | logger.Warnw(ctx, "no handler found for device-reenable", log.Fields{"device-id": device.Id}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 318 | return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id)) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 319 | } |
| 320 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 321 | //RebootDevice reboots the given device |
| 322 | func (oo *OpenONUAC) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 323 | logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id}) |
| 324 | if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 325 | go handler.rebootDevice(log.WithSpanFromContext(context.Background(), ctx), true, device) //reboot request with device checking |
| 326 | return &empty.Empty{}, nil |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 327 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 328 | logger.Warnw(ctx, "no handler found for device-reboot", log.Fields{"device-id": device.Id}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 329 | return nil, fmt.Errorf("handler-not-found-for-device: %s", device.Id) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 330 | } |
| 331 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 332 | // DeleteDevice deletes the given device |
| 333 | func (oo *OpenONUAC) DeleteDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 334 | nctx := log.WithSpanFromContext(context.Background(), ctx) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 335 | 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] | 336 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 337 | if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 338 | var errorsList []error |
Holger Hildebrandt | ff05b68 | 2021-03-16 15:02:05 +0000 | [diff] [blame] | 339 | |
| 340 | handler.mutexDeletionInProgressFlag.Lock() |
| 341 | handler.deletionInProgress = true |
| 342 | handler.mutexDeletionInProgressFlag.Unlock() |
| 343 | |
Holger Hildebrandt | 6065220 | 2021-11-02 11:09:36 +0000 | [diff] [blame] | 344 | if err := handler.resetFsms(ctx, true); err != nil { |
| 345 | errorsList = append(errorsList, err) |
| 346 | } |
Holger Hildebrandt | c69f074 | 2021-11-16 13:48:00 +0000 | [diff] [blame] | 347 | forceKvDelete := false |
| 348 | |
Holger Hildebrandt | 6065220 | 2021-11-02 11:09:36 +0000 | [diff] [blame] | 349 | // Clear PM data on the KV store |
| 350 | if handler.pOnuMetricsMgr != nil { |
| 351 | if err := handler.pOnuMetricsMgr.ClearAllPmData(ctx); err != nil { |
| 352 | errorsList = append(errorsList, err) |
Holger Hildebrandt | c69f074 | 2021-11-16 13:48:00 +0000 | [diff] [blame] | 353 | forceKvDelete = true |
Holger Hildebrandt | 6065220 | 2021-11-02 11:09:36 +0000 | [diff] [blame] | 354 | } |
Holger Hildebrandt | c69f074 | 2021-11-16 13:48:00 +0000 | [diff] [blame] | 355 | } else { |
| 356 | forceKvDelete = true |
| 357 | } |
| 358 | if err := handler.deleteDevicePersistencyData(ctx); err != nil { |
| 359 | errorsList = append(errorsList, err) |
| 360 | forceKvDelete = true |
Girish Gowdra | 10123c0 | 2021-08-30 11:52:06 -0700 | [diff] [blame] | 361 | } |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 362 | for _, uni := range handler.uniEntityMap { |
| 363 | if handler.GetFlowMonitoringIsRunning(uni.UniID) { |
| 364 | handler.stopFlowMonitoringRoutine[uni.UniID] <- true |
| 365 | logger.Debugw(ctx, "sent stop signal to self flow monitoring routine", log.Fields{"device-id": device.Id}) |
| 366 | } |
| 367 | } |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 368 | //don't leave any garbage - even in error case |
| 369 | oo.deleteDeviceHandlerToMap(handler) |
Holger Hildebrandt | c69f074 | 2021-11-16 13:48:00 +0000 | [diff] [blame] | 370 | if forceKvDelete { |
| 371 | if err := oo.forceDeleteDeviceKvData(ctx, device.Id); err != nil { |
| 372 | errorsList = append(errorsList, err) |
| 373 | } |
| 374 | } |
Holger Hildebrandt | 6065220 | 2021-11-02 11:09:36 +0000 | [diff] [blame] | 375 | |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 376 | if len(errorsList) > 0 { |
| 377 | logger.Errorw(ctx, "one-or-more-error-during-device-delete", log.Fields{"device-id": device.Id}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 378 | return nil, fmt.Errorf("one-or-more-error-during-device-delete, errors:%v", errorsList) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 379 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 380 | return &empty.Empty{}, nil |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 381 | } |
Holger Hildebrandt | 6065220 | 2021-11-02 11:09:36 +0000 | [diff] [blame] | 382 | logger.Infow(ctx, "no handler found for device-deletion - trying to delete remaining data in the kv-store ", log.Fields{"device-id": device.Id}) |
| 383 | |
Holger Hildebrandt | c69f074 | 2021-11-16 13:48:00 +0000 | [diff] [blame] | 384 | if err := oo.forceDeleteDeviceKvData(ctx, device.Id); err != nil { |
| 385 | return nil, err |
Holger Hildebrandt | 6065220 | 2021-11-02 11:09:36 +0000 | [diff] [blame] | 386 | } |
| 387 | return &empty.Empty{}, nil |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 388 | } |
| 389 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 390 | //UpdateFlowsIncrementally updates (add/remove) the flows on a given device |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 391 | func (oo *OpenONUAC) UpdateFlowsIncrementally(ctx context.Context, incrFlows *ca.IncrementalFlows) (*empty.Empty, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 392 | 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] | 393 | |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 394 | //flow config is relayed to handler even if the device might be in some 'inactive' state |
| 395 | // let the handler or related FSM's decide, what to do with the modified flow state info |
| 396 | // 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] | 397 | |
| 398 | // 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] | 399 | // but processing is continued for flowUpdate possibly also set in the request |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 400 | if incrFlows.Groups.ToAdd != nil && incrFlows.Groups.ToAdd.Items != nil { |
| 401 | 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] | 402 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 403 | if incrFlows.Groups.ToRemove != nil && incrFlows.Groups.ToRemove.Items != nil { |
| 404 | 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] | 405 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 406 | if incrFlows.Groups.ToUpdate != nil && incrFlows.Groups.ToUpdate.Items != nil { |
| 407 | 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] | 408 | } |
| 409 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 410 | if handler := oo.getDeviceHandler(ctx, incrFlows.Device.Id, false); handler != nil { |
| 411 | if err := handler.FlowUpdateIncremental(log.WithSpanFromContext(context.Background(), ctx), incrFlows.Flows, incrFlows.Groups, incrFlows.FlowMetadata); err != nil { |
| 412 | return nil, err |
| 413 | } |
| 414 | return &empty.Empty{}, nil |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 415 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 416 | logger.Warnw(ctx, "no handler found for incremental flow update", log.Fields{"device-id": incrFlows.Device.Id}) |
| 417 | return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", incrFlows.Device.Id)) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 418 | } |
| 419 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 420 | //UpdatePmConfig returns PmConfigs nil or error |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 421 | func (oo *OpenONUAC) UpdatePmConfig(ctx context.Context, configs *ca.PmConfigsInfo) (*empty.Empty, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 422 | logger.Infow(ctx, "update-pm-config", log.Fields{"device-id": configs.DeviceId}) |
| 423 | if handler := oo.getDeviceHandler(ctx, configs.DeviceId, false); handler != nil { |
| 424 | if err := handler.updatePmConfig(log.WithSpanFromContext(context.Background(), ctx), configs.PmConfigs); err != nil { |
| 425 | return nil, err |
| 426 | } |
| 427 | return &empty.Empty{}, nil |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 428 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 429 | logger.Warnw(ctx, "no handler found for update-pm-config", log.Fields{"device-id": configs.DeviceId}) |
| 430 | return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", configs.DeviceId)) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 431 | } |
| 432 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 433 | //DownloadImage requests downloading some image according to indications as given in request |
Andrea Campanella | 71e546a | 2021-02-26 11:09:33 +0100 | [diff] [blame] | 434 | //The ImageDownload needs to be called `request`due to library reflection requirements |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 435 | func (oo *OpenONUAC) DownloadImage(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 436 | ctx = log.WithSpanFromContext(context.Background(), ctx) |
| 437 | if imageInfo != nil && imageInfo.Image != nil && imageInfo.Image.Name != "" { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 438 | if !oo.pDownloadManager.ImageExists(ctx, imageInfo.Image) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 439 | logger.Debugw(ctx, "start image download", log.Fields{"image-description": imageInfo.Image}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 440 | // Download_image is not supposed to be blocking, anyway let's call the DownloadManager still synchronously to detect 'fast' problems |
| 441 | // the download itself is later done in background |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 442 | if err := oo.pDownloadManager.StartDownload(ctx, imageInfo.Image); err != nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 443 | return nil, err |
| 444 | } |
| 445 | return imageInfo.Image, nil |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 446 | } |
| 447 | // image already exists |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 448 | logger.Debugw(ctx, "image already downloaded", log.Fields{"image-description": imageInfo.Image}) |
| 449 | return imageInfo.Image, nil |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 450 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 451 | |
| 452 | return nil, errors.New("invalid image definition") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 453 | } |
| 454 | |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 455 | //ActivateImageUpdate requests downloading some Onu Software image to the ONU via OMCI |
Andrea Campanella | 71e546a | 2021-02-26 11:09:33 +0100 | [diff] [blame] | 456 | // according to indications as given in request and on success activate the image on the ONU |
| 457 | //The ImageDownload needs to be called `request`due to library reflection requirements |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 458 | func (oo *OpenONUAC) ActivateImageUpdate(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 459 | if imageInfo != nil && imageInfo.Image != nil && imageInfo.Image.Name != "" { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 460 | if oo.pDownloadManager.ImageLocallyDownloaded(ctx, imageInfo.Image) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 461 | if handler := oo.getDeviceHandler(ctx, imageInfo.Device.Id, false); handler != nil { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 462 | logger.Debugw(ctx, "image download on omci requested", log.Fields{ |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 463 | "image-description": imageInfo.Image, "device-id": imageInfo.Device.Id}) |
| 464 | if err := handler.doOnuSwUpgrade(ctx, imageInfo.Image, oo.pDownloadManager); err != nil { |
| 465 | return nil, err |
| 466 | } |
| 467 | return imageInfo.Image, nil |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 468 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 469 | logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": imageInfo.Device.Id}) |
| 470 | return nil, fmt.Errorf(fmt.Sprintf("handler-not-found - device-id: %s", imageInfo.Device.Id)) |
mpagenko | 057889c | 2021-01-21 16:51:58 +0000 | [diff] [blame] | 471 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 472 | logger.Debugw(ctx, "image not yet downloaded on activate request", log.Fields{"image-description": imageInfo.Image}) |
| 473 | return nil, fmt.Errorf(fmt.Sprintf("image-not-yet-downloaded - device-id: %s", imageInfo.Device.Id)) |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 474 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 475 | return nil, errors.New("invalid image definition") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 476 | } |
| 477 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 478 | //GetSingleValue handles the core request to retrieve uni status |
| 479 | func (oo *OpenONUAC) GetSingleValue(ctx context.Context, request *extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) { |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 480 | logger.Infow(ctx, "Single_get_value_request", log.Fields{"request": request}) |
| 481 | |
| 482 | if handler := oo.getDeviceHandler(ctx, request.TargetId, false); handler != nil { |
| 483 | switch reqType := request.GetRequest().GetRequest().(type) { |
| 484 | case *extension.GetValueRequest_UniInfo: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 485 | return handler.GetUniPortStatus(ctx, reqType.UniInfo), nil |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 486 | case *extension.GetValueRequest_OnuOpticalInfo: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 487 | CommChan := make(chan cmn.Message) |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 488 | respChan := make(chan extension.SingleGetValueResponse) |
| 489 | // Initiate the self test request |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 490 | if err := handler.pSelfTestHdlr.SelfTestRequestStart(ctx, *request, CommChan, respChan); err != nil { |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 491 | return &extension.SingleGetValueResponse{ |
| 492 | Response: &extension.GetValueResponse{ |
| 493 | Status: extension.GetValueResponse_ERROR, |
| 494 | ErrReason: extension.GetValueResponse_INTERNAL_ERROR, |
| 495 | }, |
| 496 | }, err |
| 497 | } |
| 498 | // The timeout handling is already implemented in omci_self_test_handler module |
| 499 | resp := <-respChan |
| 500 | return &resp, nil |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 501 | case *extension.GetValueRequest_OnuInfo: |
| 502 | return handler.getOnuOMCICounters(ctx, reqType.OnuInfo), nil |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 503 | default: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 504 | return uniprt.PostUniStatusErrResponse(extension.GetValueResponse_UNSUPPORTED), nil |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 505 | |
| 506 | } |
| 507 | } |
| 508 | logger.Errorw(ctx, "Single_get_value_request failed ", log.Fields{"request": request}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 509 | return uniprt.PostUniStatusErrResponse(extension.GetValueResponse_INVALID_DEVICE_ID), nil |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 510 | } |
| 511 | |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 512 | //if update >= 4.3.0 |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 513 | // Note: already with the implementation of the 'old' download interface problems were detected when the argument name used here is not the same |
| 514 | // as defined in the adapter interface file. That sounds strange and the effects were strange as well. |
| 515 | // The reason for that was never finally investigated. |
| 516 | // 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] | 517 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 518 | // DownloadOnuImage downloads (and optionally activates and commits) the indicated ONU image to the requested ONU(s) |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 519 | // 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] | 520 | func (oo *OpenONUAC) DownloadOnuImage(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 521 | if request != nil && len((*request).DeviceId) > 0 && (*request).Image.Version != "" { |
| 522 | loResponse := voltha.DeviceImageResponse{} |
| 523 | imageIdentifier := (*request).Image.Version |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 524 | downloadStartDone := false |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 525 | firstDevice := true |
| 526 | var vendorID string |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 527 | var onuVolthaDevice *voltha.Device |
| 528 | var devErr error |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 529 | for _, pCommonID := range (*request).DeviceId { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 530 | vendorIDMatch := true |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 531 | loDeviceID := (*pCommonID).Id |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 532 | loDeviceImageState := voltha.DeviceImageState{} |
| 533 | loDeviceImageState.DeviceId = loDeviceID |
| 534 | loImageState := voltha.ImageState{} |
| 535 | loDeviceImageState.ImageState = &loImageState |
| 536 | loDeviceImageState.ImageState.Version = (*request).Image.Version |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 537 | |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 538 | onuVolthaDevice = nil |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 539 | handler := oo.getDeviceHandler(ctx, loDeviceID, false) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 540 | if handler != nil { |
| 541 | onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID) |
| 542 | } else { |
| 543 | // assumption here is, that the concerned device was already created (automatic start after device creation not supported) |
| 544 | devErr = errors.New("no handler found for device-id") |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 545 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 546 | if devErr != nil || onuVolthaDevice == nil { |
| 547 | logger.Warnw(ctx, "Failed to fetch ONU device for image download", |
| 548 | log.Fields{"device-id": loDeviceID, "err": devErr}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 549 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED |
| 550 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //proto restriction, better option: 'INVALID_DEVICE' |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 551 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 552 | } else { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 553 | if firstDevice { |
| 554 | //start/verify download of the image to the adapter based on first found device only |
| 555 | // use the OnuVendor identification from first given device |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 556 | |
| 557 | // note: if the request was done for a list of devices on the Voltha interface, rwCore |
| 558 | // 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] | 559 | firstDevice = false |
| 560 | vendorID = onuVolthaDevice.VendorId |
| 561 | imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 562 | logger.Infow(ctx, "download request for file", |
| 563 | log.Fields{"device-id": loDeviceID, "image-id": imageIdentifier}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 564 | |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 565 | // call the StartDownload synchronously to detect 'immediate' download problems |
| 566 | // the real download itself is later done in background |
| 567 | if fileState, err := oo.pFileManager.StartDownload(ctx, imageIdentifier, (*request).Image.Url); err == nil { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 568 | // 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] | 569 | // valid URL, the current download request is not executed (current code delivers URL error). |
| 570 | // If the operators want to ensure that the new URL |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 571 | // is really used, then they first have to use the 'abort' API to remove the existing image! |
| 572 | // (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] | 573 | if fileState == swupg.CFileStateDlSucceeded || fileState == swupg.CFileStateDlStarted { |
| 574 | downloadStartDone = true |
| 575 | } //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] | 576 | } |
| 577 | } else { |
| 578 | //for all following devices verify the matching vendorID |
| 579 | if onuVolthaDevice.VendorId != vendorID { |
| 580 | logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored", |
| 581 | log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID}) |
| 582 | vendorIDMatch = false |
| 583 | } |
| 584 | } |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 585 | if downloadStartDone && vendorIDMatch { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 586 | // start the ONU download activity for each possible device |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 587 | logger.Infow(ctx, "request image download to ONU on omci ", log.Fields{ |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 588 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 589 | //onu upgrade handling called in background without immediate error evaluation here |
| 590 | // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others |
| 591 | // state/progress/success of the request has to be verified using the Get_onu_image_status() API |
| 592 | go handler.onuSwUpgradeAfterDownload(ctx, request, oo.pFileManager, imageIdentifier) |
| 593 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_STARTED |
| 594 | loDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR |
| 595 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 596 | } else { |
| 597 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 598 | if !downloadStartDone { |
| 599 | //based on above fileState more descriptive error codes would be possible, e.g |
| 600 | // IMAGE_EXISTS_WITH_DIFFERENT_URL - would require proto buf update |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 601 | loDeviceImageState.ImageState.Reason = voltha.ImageState_INVALID_URL |
| 602 | } else { //only logical option is !vendorIDMatch |
| 603 | loDeviceImageState.ImageState.Reason = voltha.ImageState_VENDOR_DEVICE_MISMATCH |
| 604 | } |
| 605 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 606 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 607 | } |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 608 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 609 | } //for all requested devices |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 610 | pImageResp := &loResponse |
| 611 | return pImageResp, nil |
| 612 | } |
| 613 | return nil, errors.New("invalid image download parameters") |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 614 | } |
| 615 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 616 | // GetOnuImageStatus delivers the adapter-related information about the download/activation/commitment |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 617 | // status for the requested image |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 618 | func (oo *OpenONUAC) GetOnuImageStatus(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 619 | if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" { |
| 620 | loResponse := voltha.DeviceImageResponse{} |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 621 | imageIdentifier := (*in).Version |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 622 | var vendorIDSet bool |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 623 | firstDevice := true |
| 624 | var vendorID string |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 625 | var onuVolthaDevice *voltha.Device |
| 626 | var devErr error |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 627 | for _, pCommonID := range (*in).DeviceId { |
| 628 | loDeviceID := (*pCommonID).Id |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 629 | pDeviceImageState := &voltha.DeviceImageState{DeviceId: loDeviceID} |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 630 | vendorIDSet = false |
| 631 | onuVolthaDevice = nil |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 632 | handler := oo.getDeviceHandler(ctx, loDeviceID, false) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 633 | if handler != nil { |
| 634 | onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID) |
| 635 | } else { |
| 636 | // assumption here is, that the concerned device was already created (automatic start after device creation not supported) |
| 637 | devErr = errors.New("no handler found for device-id") |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 638 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 639 | if devErr != nil || onuVolthaDevice == nil { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 640 | logger.Warnw(ctx, "Failed to fetch Onu device to get image status", |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 641 | log.Fields{"device-id": loDeviceID, "err": devErr}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 642 | pImageState := &voltha.ImageState{ |
| 643 | Version: (*in).Version, |
| 644 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //no statement about last activity possible |
| 645 | Reason: voltha.ImageState_UNKNOWN_ERROR, //something like "DEVICE_NOT_EXISTS" would be better (proto def) |
| 646 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 647 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 648 | pDeviceImageState.ImageState = pImageState |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 649 | } else { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 650 | if firstDevice { |
| 651 | //start/verify download of the image to the adapter based on first found device only |
| 652 | // use the OnuVendor identification from first given device |
| 653 | firstDevice = false |
| 654 | vendorID = onuVolthaDevice.VendorId |
| 655 | imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU |
| 656 | vendorIDSet = true |
| 657 | logger.Debugw(ctx, "status request for image", log.Fields{"image-id": imageIdentifier}) |
| 658 | } else { |
| 659 | //for all following devices verify the matching vendorID |
| 660 | if onuVolthaDevice.VendorId != vendorID { |
| 661 | logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored", |
| 662 | log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID}) |
| 663 | } else { |
| 664 | vendorIDSet = true |
| 665 | } |
| 666 | } |
| 667 | if !vendorIDSet { |
| 668 | pImageState := &voltha.ImageState{ |
| 669 | Version: (*in).Version, |
| 670 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //can't be sure that download for this device was really tried |
| 671 | Reason: voltha.ImageState_VENDOR_DEVICE_MISMATCH, |
| 672 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
| 673 | } |
| 674 | pDeviceImageState.ImageState = pImageState |
| 675 | } else { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 676 | logger.Debugw(ctx, "image status request for", log.Fields{ |
| 677 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 678 | //status request is called synchronously to collect the indications for all concerned devices |
| 679 | pDeviceImageState.ImageState = handler.requestOnuSwUpgradeState(ctx, imageIdentifier, (*in).Version) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 680 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 681 | } |
| 682 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 683 | } //for all requested devices |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 684 | pImageResp := &loResponse |
| 685 | return pImageResp, nil |
| 686 | } |
| 687 | return nil, errors.New("invalid image status request parameters") |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 688 | } |
| 689 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 690 | // AbortOnuImageUpgrade stops the actual download/activation/commitment process (on next possibly step) |
| 691 | func (oo *OpenONUAC) AbortOnuImageUpgrade(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 692 | if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" { |
| 693 | loResponse := voltha.DeviceImageResponse{} |
| 694 | imageIdentifier := (*in).Version |
| 695 | firstDevice := true |
| 696 | var vendorID string |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 697 | var vendorIDSet bool |
| 698 | var onuVolthaDevice *voltha.Device |
| 699 | var devErr error |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 700 | for _, pCommonID := range (*in).DeviceId { |
| 701 | loDeviceID := (*pCommonID).Id |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 702 | pDeviceImageState := &voltha.DeviceImageState{} |
| 703 | loImageState := voltha.ImageState{} |
| 704 | pDeviceImageState.ImageState = &loImageState |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 705 | vendorIDSet = false |
| 706 | onuVolthaDevice = nil |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 707 | handler := oo.getDeviceHandler(ctx, loDeviceID, false) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 708 | if handler != nil { |
| 709 | onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID) |
| 710 | } else { |
| 711 | // assumption here is, that the concerned device was already created (automatic start after device creation not supported) |
| 712 | devErr = errors.New("no handler found for device-id") |
| 713 | } |
| 714 | if devErr != nil || onuVolthaDevice == nil { |
| 715 | logger.Warnw(ctx, "Failed to fetch Onu device to abort its download", |
| 716 | log.Fields{"device-id": loDeviceID, "err": devErr}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 717 | pDeviceImageState.DeviceId = loDeviceID |
| 718 | pDeviceImageState.ImageState.Version = (*in).Version |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 719 | pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 720 | 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] | 721 | pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 722 | } else { |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 723 | if firstDevice { |
| 724 | //start/verify download of the image to the adapter based on first found device only |
| 725 | // use the OnuVendor identification from first given device |
| 726 | firstDevice = false |
| 727 | vendorID = onuVolthaDevice.VendorId |
| 728 | vendorIDSet = true |
| 729 | imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU |
| 730 | logger.Debugw(ctx, "abort request for file", log.Fields{"image-id": imageIdentifier}) |
| 731 | } else { |
| 732 | //for all following devices verify the matching vendorID |
| 733 | if onuVolthaDevice.VendorId != vendorID { |
| 734 | logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored", |
| 735 | log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID}) |
| 736 | pDeviceImageState.DeviceId = loDeviceID |
| 737 | pDeviceImageState.ImageState.Version = (*in).Version |
| 738 | pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 739 | pDeviceImageState.ImageState.Reason = voltha.ImageState_VENDOR_DEVICE_MISMATCH |
| 740 | pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 741 | } else { |
| 742 | vendorIDSet = true |
| 743 | } |
| 744 | } |
| 745 | if vendorIDSet { |
| 746 | // cancel the ONU upgrade activity for each possible device |
| 747 | logger.Debugw(ctx, "image upgrade abort requested", log.Fields{ |
| 748 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 749 | //upgrade cancel is called synchronously to collect the imageResponse indications for all concerned devices |
| 750 | handler.cancelOnuSwUpgrade(ctx, imageIdentifier, (*in).Version, pDeviceImageState) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 751 | } |
| 752 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 753 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 754 | } //for all requested devices |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 755 | if !firstDevice { |
| 756 | //if at least one valid device was found cancel also a possibly running download to adapter and remove the image |
| 757 | // this is to be done after the upgradeOnu cancel activities in order to not subduct the file for still running processes |
| 758 | oo.pFileManager.CancelDownload(ctx, imageIdentifier) |
| 759 | } |
| 760 | pImageResp := &loResponse |
| 761 | return pImageResp, nil |
| 762 | } |
| 763 | return nil, errors.New("invalid image upgrade abort parameters") |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 764 | } |
| 765 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 766 | // GetOnuImages retrieves the ONU SW image status information via OMCI |
| 767 | func (oo *OpenONUAC) GetOnuImages(ctx context.Context, id *common.ID) (*voltha.OnuImages, error) { |
| 768 | logger.Infow(ctx, "Get_onu_images", log.Fields{"device-id": id.Id}) |
| 769 | if handler := oo.getDeviceHandler(ctx, id.Id, false); handler != nil { |
Himani Chawla | 69992ab | 2021-07-08 15:13:02 +0530 | [diff] [blame] | 770 | images, err := handler.getOnuImages(ctx) |
| 771 | if err == nil { |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 772 | return images, nil |
| 773 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 774 | return nil, fmt.Errorf(fmt.Sprintf("%s-%s", err, id.Id)) |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 775 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 776 | logger.Warnw(ctx, "no handler found for Get_onu_images", log.Fields{"device-id": id.Id}) |
| 777 | return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", id.Id)) |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 778 | } |
| 779 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 780 | // ActivateOnuImage initiates the activation of the image for the requested ONU(s) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 781 | // 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] | 782 | func (oo *OpenONUAC) ActivateOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 783 | if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" { |
| 784 | loResponse := voltha.DeviceImageResponse{} |
| 785 | imageIdentifier := (*in).Version |
| 786 | //let the deviceHandler find the adequate way of requesting the image activation |
| 787 | for _, pCommonID := range (*in).DeviceId { |
| 788 | loDeviceID := (*pCommonID).Id |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 789 | loDeviceImageState := voltha.DeviceImageState{} |
| 790 | loDeviceImageState.DeviceId = loDeviceID |
| 791 | loImageState := voltha.ImageState{} |
| 792 | loDeviceImageState.ImageState = &loImageState |
| 793 | loDeviceImageState.ImageState.Version = imageIdentifier |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 794 | //compared to download procedure the vendorID (from device) is secondary here |
| 795 | // and only needed in case the upgrade process is based on some ongoing download process (and can be retrieved in deviceHandler if needed) |
| 796 | // start image activation activity for each possible device |
| 797 | // assumption here is, that the concerned device was already created (automatic start after device creation not supported) |
| 798 | if handler := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil { |
| 799 | logger.Debugw(ctx, "onu image activation requested", log.Fields{ |
| 800 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 801 | //onu activation handling called in background without immediate error evaluation here |
| 802 | // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others |
| 803 | // 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] | 804 | if pImageStates, err := handler.onuSwActivateRequest(ctx, imageIdentifier, (*in).CommitOnSuccess); err != nil { |
| 805 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 806 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR |
| 807 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED |
| 808 | } else { |
| 809 | loDeviceImageState.ImageState.DownloadState = pImageStates.DownloadState |
| 810 | loDeviceImageState.ImageState.Reason = pImageStates.Reason |
| 811 | loDeviceImageState.ImageState.ImageState = pImageStates.ImageState |
| 812 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 813 | } else { |
| 814 | //cannot start SW activation for requested device |
| 815 | 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] | 816 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 817 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR |
| 818 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 819 | } |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 820 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 821 | } |
| 822 | pImageResp := &loResponse |
| 823 | return pImageResp, nil |
| 824 | } |
| 825 | return nil, errors.New("invalid image activation parameters") |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 826 | } |
| 827 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 828 | // CommitOnuImage enforces the commitment of the image for the requested ONU(s) |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 829 | // precondition: image activated and not yet committed |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 830 | func (oo *OpenONUAC) CommitOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 831 | if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" { |
| 832 | loResponse := voltha.DeviceImageResponse{} |
| 833 | imageIdentifier := (*in).Version |
| 834 | //let the deviceHandler find the adequate way of requesting the image activation |
| 835 | for _, pCommonID := range (*in).DeviceId { |
| 836 | loDeviceID := (*pCommonID).Id |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 837 | loDeviceImageState := voltha.DeviceImageState{} |
| 838 | loDeviceImageState.DeviceId = loDeviceID |
| 839 | loImageState := voltha.ImageState{} |
| 840 | loDeviceImageState.ImageState = &loImageState |
| 841 | loDeviceImageState.ImageState.Version = imageIdentifier |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 842 | //compared to download procedure the vendorID (from device) is secondary here |
| 843 | // and only needed in case the upgrade process is based on some ongoing download process (and can be retrieved in deviceHandler if needed) |
| 844 | // start image activation activity for each possible device |
| 845 | // assumption here is, that the concerned device was already created (automatic start after device creation not supported) |
| 846 | if handler := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil { |
| 847 | logger.Debugw(ctx, "onu image commitment requested", log.Fields{ |
| 848 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 849 | //onu commitment handling called in background without immediate error evaluation here |
| 850 | // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others |
| 851 | // 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] | 852 | if pImageStates, err := handler.onuSwCommitRequest(ctx, imageIdentifier); err != nil { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 853 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED |
| 854 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //can be multiple reasons here |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 855 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED |
| 856 | } else { |
| 857 | loDeviceImageState.ImageState.DownloadState = pImageStates.DownloadState |
| 858 | loDeviceImageState.ImageState.Reason = pImageStates.Reason |
| 859 | loDeviceImageState.ImageState.ImageState = pImageStates.ImageState |
| 860 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 861 | } else { |
| 862 | //cannot start SW commitment for requested device |
| 863 | 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] | 864 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 865 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR |
| 866 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 867 | } |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 868 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 869 | } |
| 870 | pImageResp := &loResponse |
| 871 | return pImageResp, nil |
| 872 | } |
| 873 | return nil, errors.New("invalid image commitment parameters") |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 874 | } |
| 875 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 876 | // Adapter interface required methods ################ end ######### |
| 877 | // ################################################################# |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 878 | |
| 879 | /* |
| 880 | * |
| 881 | * ONU inter adapter service |
| 882 | * |
| 883 | */ |
| 884 | |
| 885 | // OnuIndication is part of the ONU Inter-adapter service API. |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 886 | func (oo *OpenONUAC) OnuIndication(ctx context.Context, onuInd *ia.OnuIndicationMessage) (*empty.Empty, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 887 | logger.Debugw(ctx, "onu-indication", log.Fields{"onu-indication": onuInd}) |
| 888 | |
| 889 | if onuInd == nil || onuInd.OnuIndication == nil { |
| 890 | return nil, fmt.Errorf("invalid-onu-indication-%v", onuInd) |
| 891 | } |
| 892 | |
| 893 | onuIndication := onuInd.OnuIndication |
| 894 | onuOperstate := onuIndication.GetOperState() |
| 895 | waitForDhInstPresent := false |
| 896 | if onuOperstate == "up" { |
| 897 | //Race condition (relevant in BBSIM-environment only): Due to unsynchronized processing of olt-adapter and rw_core, |
| 898 | //ONU_IND_REQUEST msg by olt-adapter could arrive a little bit earlier than rw_core was able to announce the corresponding |
| 899 | //ONU by RPC of Adopt_device(). Therefore it could be necessary to wait with processing of ONU_IND_REQUEST until call of |
| 900 | //Adopt_device() arrived and DeviceHandler instance was created |
| 901 | waitForDhInstPresent = true |
| 902 | } |
| 903 | if handler := oo.getDeviceHandler(ctx, onuInd.DeviceId, waitForDhInstPresent); handler != nil { |
| 904 | logger.Infow(ctx, "onu-ind-request", log.Fields{"device-id": onuInd.DeviceId, |
| 905 | "OnuId": onuIndication.GetOnuId(), |
| 906 | "AdminState": onuIndication.GetAdminState(), "OperState": onuOperstate, |
| 907 | "SNR": onuIndication.GetSerialNumber()}) |
| 908 | |
| 909 | if onuOperstate == "up" { |
| 910 | if err := handler.createInterface(ctx, onuIndication); err != nil { |
| 911 | return nil, err |
| 912 | } |
| 913 | return &empty.Empty{}, nil |
| 914 | } else if (onuOperstate == "down") || (onuOperstate == "unreachable") { |
| 915 | return nil, handler.updateInterface(ctx, onuIndication) |
| 916 | } else { |
| 917 | logger.Errorw(ctx, "unknown-onu-ind-request operState", log.Fields{"OnuId": onuIndication.GetOnuId()}) |
| 918 | return nil, fmt.Errorf("invalidOperState: %s, %s", onuOperstate, onuInd.DeviceId) |
| 919 | } |
| 920 | } |
| 921 | logger.Warnw(ctx, "no handler found for received onu-ind-request", log.Fields{ |
| 922 | "msgToDeviceId": onuInd.DeviceId}) |
| 923 | return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", onuInd.DeviceId)) |
| 924 | } |
| 925 | |
| 926 | // OmciIndication is part of the ONU Inter-adapter service API. |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 927 | func (oo *OpenONUAC) OmciIndication(ctx context.Context, msg *ia.OmciMessage) (*empty.Empty, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 928 | logger.Debugw(ctx, "omci-response", log.Fields{"parent-device-id": msg.ParentDeviceId, "child-device-id": msg.ChildDeviceId}) |
| 929 | |
| 930 | if handler := oo.getDeviceHandler(ctx, msg.ChildDeviceId, false); handler != nil { |
| 931 | if err := handler.handleOMCIIndication(log.WithSpanFromContext(context.Background(), ctx), msg); err != nil { |
| 932 | return nil, err |
| 933 | } |
| 934 | return &empty.Empty{}, nil |
| 935 | } |
| 936 | return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", msg.ChildDeviceId)) |
| 937 | } |
| 938 | |
| 939 | // DownloadTechProfile is part of the ONU Inter-adapter service API. |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 940 | func (oo *OpenONUAC) DownloadTechProfile(ctx context.Context, tProfile *ia.TechProfileDownloadMessage) (*empty.Empty, error) { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 941 | logger.Debugw(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] | 942 | |
| 943 | if handler := oo.getDeviceHandler(ctx, tProfile.DeviceId, false); handler != nil { |
| 944 | if err := handler.handleTechProfileDownloadRequest(log.WithSpanFromContext(context.Background(), ctx), tProfile); err != nil { |
| 945 | return nil, err |
| 946 | } |
| 947 | return &empty.Empty{}, nil |
| 948 | } |
| 949 | return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", tProfile.DeviceId)) |
| 950 | } |
| 951 | |
| 952 | // DeleteGemPort is part of the ONU Inter-adapter service API. |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 953 | func (oo *OpenONUAC) DeleteGemPort(ctx context.Context, gPort *ia.DeleteGemPortMessage) (*empty.Empty, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 954 | logger.Debugw(ctx, "delete-gem-port", log.Fields{"device-id": gPort.DeviceId, "uni-id": gPort.UniId}) |
| 955 | |
| 956 | if handler := oo.getDeviceHandler(ctx, gPort.DeviceId, false); handler != nil { |
| 957 | if err := handler.handleDeleteGemPortRequest(log.WithSpanFromContext(context.Background(), ctx), gPort); err != nil { |
| 958 | return nil, err |
| 959 | } |
Holger Hildebrandt | 5b77406 | 2021-11-10 10:24:29 +0000 | [diff] [blame] | 960 | } else { |
| 961 | logger.Debugw(ctx, "deviceHandler not found", log.Fields{"device-id": gPort.DeviceId}) |
| 962 | // 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] | 963 | } |
Holger Hildebrandt | 5b77406 | 2021-11-10 10:24:29 +0000 | [diff] [blame] | 964 | return &empty.Empty{}, nil |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | // DeleteTCont is part of the ONU Inter-adapter service API. |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 968 | 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] | 969 | logger.Debugw(ctx, "delete-tcont", log.Fields{"device-id": tConf.DeviceId, "tconf": tConf}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 970 | |
| 971 | if handler := oo.getDeviceHandler(ctx, tConf.DeviceId, false); handler != nil { |
| 972 | if err := handler.handleDeleteTcontRequest(log.WithSpanFromContext(context.Background(), ctx), tConf); err != nil { |
| 973 | return nil, err |
| 974 | } |
Holger Hildebrandt | 5b77406 | 2021-11-10 10:24:29 +0000 | [diff] [blame] | 975 | } else { |
| 976 | logger.Debugw(ctx, "deviceHandler not found", log.Fields{"device-id": tConf.DeviceId}) |
| 977 | // 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] | 978 | } |
Holger Hildebrandt | 5b77406 | 2021-11-10 10:24:29 +0000 | [diff] [blame] | 979 | return &empty.Empty{}, nil |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | /* |
| 983 | * Parent GRPC clients |
| 984 | */ |
| 985 | |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 986 | func getHash(endpoint, contextInfo string) string { |
| 987 | strToHash := endpoint + contextInfo |
| 988 | h := fnv.New128().Sum([]byte(strToHash)) |
| 989 | return string(h) |
| 990 | } |
| 991 | |
| 992 | func (oo *OpenONUAC) updateReachabilityFromRemote(ctx context.Context, remote *common.Connection) { |
| 993 | logger.Debugw(context.Background(), "updating-remote-connection-status", log.Fields{"remote": remote}) |
| 994 | oo.lockReachableFromRemote.Lock() |
| 995 | defer oo.lockReachableFromRemote.Unlock() |
| 996 | endpointHash := getHash(remote.Endpoint, remote.ContextInfo) |
| 997 | if _, ok := oo.reachableFromRemote[endpointHash]; ok { |
| 998 | oo.reachableFromRemote[endpointHash].lastKeepAlive = time.Now() |
| 999 | oo.reachableFromRemote[endpointHash].keepAliveInterval = remote.KeepAliveInterval |
| 1000 | return |
| 1001 | } |
| 1002 | logger.Debugw(context.Background(), "initial-remote-connection", log.Fields{"remote": remote}) |
| 1003 | oo.reachableFromRemote[endpointHash] = &reachabilityFromRemote{lastKeepAlive: time.Now(), keepAliveInterval: remote.KeepAliveInterval} |
| 1004 | } |
| 1005 | |
| 1006 | func (oo *OpenONUAC) isReachableFromRemote(endpoint string, contextInfo string) bool { |
| 1007 | oo.lockReachableFromRemote.RLock() |
| 1008 | defer oo.lockReachableFromRemote.RUnlock() |
| 1009 | endpointHash := getHash(endpoint, contextInfo) |
| 1010 | if _, ok := oo.reachableFromRemote[endpointHash]; ok { |
| 1011 | // Assume the connection is down if we did not receive 2 keep alives in succession |
| 1012 | maxKeepAliveWait := time.Duration(oo.reachableFromRemote[endpointHash].keepAliveInterval * 2) |
| 1013 | return time.Since(oo.reachableFromRemote[endpointHash].lastKeepAlive) <= maxKeepAliveWait |
| 1014 | } |
| 1015 | return false |
| 1016 | } |
| 1017 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1018 | func (oo *OpenONUAC) setupParentInterAdapterClient(ctx context.Context, endpoint string) error { |
| 1019 | logger.Infow(ctx, "setting-parent-adapter-connection", log.Fields{"parent-endpoint": endpoint}) |
| 1020 | oo.lockParentAdapterClients.Lock() |
| 1021 | defer oo.lockParentAdapterClients.Unlock() |
| 1022 | if _, ok := oo.parentAdapterClients[endpoint]; ok { |
| 1023 | return nil |
| 1024 | } |
| 1025 | |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 1026 | childClient, err := vgrpc.NewClient( |
| 1027 | oo.config.AdapterEndpoint, |
| 1028 | endpoint, |
| 1029 | oo.oltAdapterRestarted) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1030 | |
| 1031 | if err != nil { |
| 1032 | return err |
| 1033 | } |
| 1034 | |
| 1035 | oo.parentAdapterClients[endpoint] = childClient |
| 1036 | |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 1037 | go oo.parentAdapterClients[endpoint].Start(log.WithSpanFromContext(context.TODO(), ctx), setAndTestOltInterAdapterServiceHandler) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1038 | |
| 1039 | // Wait until we have a connection to the child adapter. |
| 1040 | // Unlimited retries or until context expires |
| 1041 | subCtx := log.WithSpanFromContext(context.TODO(), ctx) |
| 1042 | backoff := vgrpc.NewBackoff(oo.config.MinBackoffRetryDelay, oo.config.MaxBackoffRetryDelay, 0) |
| 1043 | for { |
| 1044 | client, err := oo.parentAdapterClients[endpoint].GetOltInterAdapterServiceClient() |
| 1045 | if err == nil && client != nil { |
| 1046 | logger.Infow(subCtx, "connected-to-parent-adapter", log.Fields{"parent-endpoint": endpoint}) |
| 1047 | break |
| 1048 | } |
| 1049 | logger.Warnw(subCtx, "connection-to-parent-adapter-not-ready", log.Fields{"error": err, "parent-endpoint": endpoint}) |
| 1050 | // Backoff |
| 1051 | if err = backoff.Backoff(subCtx); err != nil { |
| 1052 | logger.Errorw(subCtx, "received-error-on-backoff", log.Fields{"error": err, "parent-endpoint": endpoint}) |
| 1053 | break |
| 1054 | } |
| 1055 | } |
| 1056 | return nil |
| 1057 | } |
| 1058 | |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1059 | func (oo *OpenONUAC) getParentAdapterServiceClient(endpoint string) (olt_inter_adapter_service.OltInterAdapterServiceClient, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1060 | // First check from cache |
| 1061 | oo.lockParentAdapterClients.RLock() |
| 1062 | if pgClient, ok := oo.parentAdapterClients[endpoint]; ok { |
| 1063 | oo.lockParentAdapterClients.RUnlock() |
| 1064 | return pgClient.GetOltInterAdapterServiceClient() |
| 1065 | } |
| 1066 | oo.lockParentAdapterClients.RUnlock() |
| 1067 | |
| 1068 | // Set the parent connection - can occur on restarts |
| 1069 | ctx, cancel := context.WithTimeout(context.Background(), oo.config.RPCTimeout) |
| 1070 | err := oo.setupParentInterAdapterClient(ctx, endpoint) |
| 1071 | cancel() |
| 1072 | if err != nil { |
| 1073 | return nil, err |
| 1074 | } |
| 1075 | |
| 1076 | // Get the parent client now |
| 1077 | oo.lockParentAdapterClients.RLock() |
| 1078 | defer oo.lockParentAdapterClients.RUnlock() |
| 1079 | if pgClient, ok := oo.parentAdapterClients[endpoint]; ok { |
| 1080 | return pgClient.GetOltInterAdapterServiceClient() |
| 1081 | } |
| 1082 | |
| 1083 | return nil, fmt.Errorf("no-client-for-endpoint-%s", endpoint) |
| 1084 | } |
| 1085 | |
| 1086 | // TODO: Any action the adapter needs to do following an olt adapter restart? |
| 1087 | func (oo *OpenONUAC) oltAdapterRestarted(ctx context.Context, endPoint string) error { |
| 1088 | logger.Errorw(ctx, "olt-adapter-restarted", log.Fields{"endpoint": endPoint}) |
| 1089 | return nil |
| 1090 | } |
| 1091 | |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 1092 | // setAndTestOltInterAdapterServiceHandler is used to test whether the remote gRPC service is up |
| 1093 | func setAndTestOltInterAdapterServiceHandler(ctx context.Context, conn *grpc.ClientConn, clientConn *common.Connection) interface{} { |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1094 | svc := olt_inter_adapter_service.NewOltInterAdapterServiceClient(conn) |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 1095 | if h, err := svc.GetHealthStatus(ctx, clientConn); err != nil || h.State != health.HealthStatus_HEALTHY { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1096 | return nil |
| 1097 | } |
| 1098 | return svc |
| 1099 | } |
| 1100 | |
Holger Hildebrandt | c69f074 | 2021-11-16 13:48:00 +0000 | [diff] [blame] | 1101 | func (oo *OpenONUAC) forceDeleteDeviceKvData(ctx context.Context, aDeviceID string) error { |
| 1102 | logger.Debugw(ctx, "force deletion of ONU device specific data in kv store", log.Fields{"device-id": aDeviceID}) |
| 1103 | |
| 1104 | for i := range onuKvStorePathPrefixes { |
| 1105 | baseKvStorePath := fmt.Sprintf(onuKvStorePathPrefixes[i], oo.cm.Backend.PathPrefix) |
| 1106 | logger.Debugw(ctx, "SetKVStoreBackend", log.Fields{"IpTarget": oo.KVStoreAddress, "BasePathKvStore": baseKvStorePath, |
| 1107 | "device-id": aDeviceID}) |
| 1108 | kvbackend := &db.Backend{ |
| 1109 | Client: oo.kvClient, |
| 1110 | StoreType: oo.KVStoreType, |
| 1111 | Address: oo.KVStoreAddress, |
| 1112 | Timeout: oo.KVStoreTimeout, |
| 1113 | PathPrefix: baseKvStorePath} |
| 1114 | |
| 1115 | if kvbackend == nil { |
| 1116 | logger.Errorw(ctx, "Can't access onuKVStore - no backend connection to service", log.Fields{"service": baseKvStorePath, "device-id": aDeviceID}) |
| 1117 | return fmt.Errorf("can-not-access-onuKVStore-no-backend-connection-to-service") |
| 1118 | } |
| 1119 | err := kvbackend.DeleteWithPrefix(ctx, aDeviceID) |
| 1120 | if err != nil { |
| 1121 | logger.Errorw(ctx, "unable to delete in KVstore", log.Fields{"service": baseKvStorePath, "device-id": aDeviceID, "err": err}) |
| 1122 | return fmt.Errorf("unable-to-delete-in-KVstore") |
| 1123 | } |
| 1124 | } |
| 1125 | return nil |
| 1126 | } |
| 1127 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1128 | /* |
| 1129 | * |
| 1130 | * Unimplemented APIs |
| 1131 | * |
| 1132 | */ |
| 1133 | |
| 1134 | //GetOfpDeviceInfo returns OFP information for the given device. Method not implemented as per [VOL-3202]. |
| 1135 | // OF port info is now to be delivered within UniPort create cmp changes in onu_uni_port.go::CreateVolthaPort() |
| 1136 | // |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1137 | func (oo *OpenONUAC) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ca.SwitchCapability, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1138 | return nil, errors.New("unImplemented") |
| 1139 | } |
| 1140 | |
| 1141 | //SimulateAlarm is unimplemented |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1142 | func (oo *OpenONUAC) SimulateAlarm(context.Context, *ca.SimulateAlarmMessage) (*common.OperationResp, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1143 | return nil, errors.New("unImplemented") |
| 1144 | } |
| 1145 | |
| 1146 | //SetExtValue is unimplemented |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1147 | func (oo *OpenONUAC) SetExtValue(context.Context, *ca.SetExtValueMessage) (*empty.Empty, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1148 | return nil, errors.New("unImplemented") |
| 1149 | } |
| 1150 | |
| 1151 | //SetSingleValue is unimplemented |
| 1152 | func (oo *OpenONUAC) SetSingleValue(context.Context, *extension.SingleSetValueRequest) (*extension.SingleSetValueResponse, error) { |
| 1153 | return nil, errors.New("unImplemented") |
| 1154 | } |
| 1155 | |
| 1156 | //StartOmciTest not implemented |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1157 | func (oo *OpenONUAC) StartOmciTest(ctx context.Context, test *ca.OMCITest) (*omci.TestResponse, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1158 | return nil, errors.New("unImplemented") |
| 1159 | } |
| 1160 | |
| 1161 | //SuppressEvent unimplemented |
| 1162 | func (oo *OpenONUAC) SuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) { |
| 1163 | return nil, errors.New("unImplemented") |
| 1164 | } |
| 1165 | |
| 1166 | //UnSuppressEvent unimplemented |
| 1167 | func (oo *OpenONUAC) UnSuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) { |
| 1168 | return nil, errors.New("unImplemented") |
| 1169 | } |
| 1170 | |
| 1171 | //GetImageDownloadStatus is unimplemented |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1172 | func (oo *OpenONUAC) GetImageDownloadStatus(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1173 | return nil, errors.New("unImplemented") |
| 1174 | } |
| 1175 | |
| 1176 | //CancelImageDownload is unimplemented |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1177 | func (oo *OpenONUAC) CancelImageDownload(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1178 | return nil, errors.New("unImplemented") |
| 1179 | } |
| 1180 | |
| 1181 | //RevertImageUpdate is unimplemented |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1182 | func (oo *OpenONUAC) RevertImageUpdate(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1183 | return nil, errors.New("unImplemented") |
| 1184 | } |
| 1185 | |
| 1186 | // UpdateFlowsBulk is unimplemented |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1187 | func (oo *OpenONUAC) UpdateFlowsBulk(ctx context.Context, flows *ca.BulkFlows) (*empty.Empty, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1188 | return nil, errors.New("unImplemented") |
| 1189 | } |
| 1190 | |
| 1191 | //SelfTestDevice unimplented |
| 1192 | func (oo *OpenONUAC) SelfTestDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 1193 | return nil, errors.New("unImplemented") |
| 1194 | } |
| 1195 | |
| 1196 | //SendPacketOut sends packet out to the device |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1197 | func (oo *OpenONUAC) SendPacketOut(ctx context.Context, packet *ca.PacketOut) (*empty.Empty, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1198 | return nil, errors.New("unImplemented") |
| 1199 | } |
| 1200 | |
| 1201 | // EnablePort to Enable PON/NNI interface - seems not to be used/required according to python code |
| 1202 | func (oo *OpenONUAC) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { |
| 1203 | return nil, errors.New("unImplemented") |
| 1204 | } |
| 1205 | |
| 1206 | // DisablePort to Disable pon/nni interface - seems not to be used/required according to python code |
| 1207 | func (oo *OpenONUAC) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { |
| 1208 | return nil, errors.New("unImplemented") |
| 1209 | } |
| 1210 | |
| 1211 | // GetExtValue - unimplemented |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1212 | func (oo *OpenONUAC) GetExtValue(ctx context.Context, extInfo *ca.GetExtValueMessage) (*extension.ReturnValues, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1213 | return nil, errors.New("unImplemented") |
| 1214 | } |
| 1215 | |
| 1216 | // ChildDeviceLost - unimplemented |
| 1217 | func (oo *OpenONUAC) ChildDeviceLost(ctx context.Context, childDevice *voltha.Device) (*empty.Empty, error) { |
| 1218 | return nil, errors.New("unImplemented") |
| 1219 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1220 | |
| 1221 | // GetSupportedFsms - TODO: add comment |
| 1222 | func (oo *OpenONUAC) GetSupportedFsms() *cmn.OmciDeviceFsms { |
| 1223 | return oo.pSupportedFsms |
| 1224 | } |
| 1225 | |
| 1226 | // LockMutexMibTemplateGenerated - TODO: add comment |
| 1227 | func (oo *OpenONUAC) LockMutexMibTemplateGenerated() { |
| 1228 | oo.mutexMibTemplateGenerated.Lock() |
| 1229 | } |
| 1230 | |
| 1231 | // UnlockMutexMibTemplateGenerated - TODO: add comment |
| 1232 | func (oo *OpenONUAC) UnlockMutexMibTemplateGenerated() { |
| 1233 | oo.mutexMibTemplateGenerated.Unlock() |
| 1234 | } |
| 1235 | |
| 1236 | // GetMibTemplatesGenerated - TODO: add comment |
| 1237 | func (oo *OpenONUAC) GetMibTemplatesGenerated(mibTemplatePath string) (value bool, exist bool) { |
| 1238 | value, exist = oo.mibTemplatesGenerated[mibTemplatePath] |
| 1239 | return value, exist |
| 1240 | } |
| 1241 | |
| 1242 | // SetMibTemplatesGenerated - TODO: add comment |
| 1243 | func (oo *OpenONUAC) SetMibTemplatesGenerated(mibTemplatePath string, value bool) { |
| 1244 | oo.mibTemplatesGenerated[mibTemplatePath] = value |
| 1245 | } |
| 1246 | |
| 1247 | // RLockMutexDeviceHandlersMap - TODO: add comment |
| 1248 | func (oo *OpenONUAC) RLockMutexDeviceHandlersMap() { |
| 1249 | oo.mutexDeviceHandlersMap.RLock() |
| 1250 | } |
| 1251 | |
| 1252 | // RUnlockMutexDeviceHandlersMap - TODO: add comment |
| 1253 | func (oo *OpenONUAC) RUnlockMutexDeviceHandlersMap() { |
| 1254 | oo.mutexDeviceHandlersMap.RUnlock() |
| 1255 | } |
| 1256 | |
| 1257 | // GetDeviceHandler - TODO: add comment |
| 1258 | func (oo *OpenONUAC) GetDeviceHandler(deviceID string) (value cmn.IdeviceHandler, exist bool) { |
| 1259 | value, exist = oo.deviceHandlers[deviceID] |
| 1260 | return value, exist |
| 1261 | } |