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 | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 17 | //Package adaptercoreonu provides the utility for onu devices, flows and statistics |
| 18 | package adaptercoreonu |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
| 22 | "errors" |
| 23 | "fmt" |
| 24 | "sync" |
| 25 | "time" |
| 26 | |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 27 | conf "github.com/opencord/voltha-lib-go/v5/pkg/config" |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 28 | |
Holger Hildebrandt | 6c1fb0a | 2020-11-25 15:41:01 +0000 | [diff] [blame] | 29 | "github.com/golang/protobuf/ptypes" |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 30 | "github.com/opencord/voltha-lib-go/v5/pkg/adapters/adapterif" |
| 31 | "github.com/opencord/voltha-lib-go/v5/pkg/db/kvstore" |
| 32 | "github.com/opencord/voltha-lib-go/v5/pkg/events/eventif" |
| 33 | "github.com/opencord/voltha-lib-go/v5/pkg/kafka" |
| 34 | "github.com/opencord/voltha-lib-go/v5/pkg/log" |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 35 | "github.com/opencord/voltha-protos/v4/go/extension" |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 36 | ic "github.com/opencord/voltha-protos/v4/go/inter_container" |
| 37 | "github.com/opencord/voltha-protos/v4/go/openflow_13" |
| 38 | oop "github.com/opencord/voltha-protos/v4/go/openolt" |
| 39 | "github.com/opencord/voltha-protos/v4/go/voltha" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 40 | |
Matteo Scandolo | 761f751 | 2020-11-23 15:52:40 -0800 | [diff] [blame] | 41 | "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/config" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 42 | ) |
| 43 | |
| 44 | //OpenONUAC structure holds the ONU core information |
| 45 | type OpenONUAC struct { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 46 | deviceHandlers map[string]*deviceHandler |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 47 | deviceHandlersCreateChan map[string]chan bool //channels for deviceHandler create events |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 48 | lockDeviceHandlersMap sync.RWMutex |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 49 | coreProxy adapterif.CoreProxy |
| 50 | adapterProxy adapterif.AdapterProxy |
Himani Chawla | c07fda0 | 2020-12-09 16:21:21 +0530 | [diff] [blame] | 51 | eventProxy eventif.EventProxy |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 52 | kafkaICProxy kafka.InterContainerProxy |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 53 | kvClient kvstore.Client |
Matteo Scandolo | f1f39a7 | 2020-11-24 12:08:11 -0800 | [diff] [blame] | 54 | cm *conf.ConfigManager |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 55 | config *config.AdapterFlags |
| 56 | numOnus int |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 57 | KVStoreAddress string |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 58 | KVStoreType string |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 59 | KVStoreTimeout time.Duration |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 60 | mibTemplatesGenerated map[string]bool |
| 61 | lockMibTemplateGenerated sync.RWMutex |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 62 | exitChannel chan int |
| 63 | HeartbeatCheckInterval time.Duration |
| 64 | HeartbeatFailReportInterval time.Duration |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 65 | AcceptIncrementalEvto bool |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 66 | //GrpcTimeoutInterval time.Duration |
Himani Chawla | d96df18 | 2020-09-28 11:12:02 +0530 | [diff] [blame] | 67 | pSupportedFsms *OmciDeviceFsms |
| 68 | maxTimeoutInterAdapterComm time.Duration |
Holger Hildebrandt | 38985dc | 2021-02-18 16:25:20 +0000 | [diff] [blame] | 69 | maxTimeoutReconciling time.Duration |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 70 | pDownloadManager *adapterDownloadManager |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 71 | pFileManager *fileDownloadManager //let coexist 'old and new' DownloadManager as long as 'old' does not get obsolete |
Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 72 | metricsEnabled bool |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 73 | mibAuditInterval time.Duration |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 74 | omciTimeout int // in seconds |
Himani Chawla | 075f164 | 2021-03-15 19:23:24 +0530 | [diff] [blame] | 75 | alarmAuditInterval time.Duration |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 76 | dlToOnuTimeout4M time.Duration |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | //NewOpenONUAC returns a new instance of OpenONU_AC |
| 80 | func NewOpenONUAC(ctx context.Context, kafkaICProxy kafka.InterContainerProxy, |
| 81 | coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy, |
Himani Chawla | c07fda0 | 2020-12-09 16:21:21 +0530 | [diff] [blame] | 82 | eventProxy eventif.EventProxy, kvClient kvstore.Client, cfg *config.AdapterFlags, cm *conf.ConfigManager) *OpenONUAC { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 83 | var openOnuAc OpenONUAC |
| 84 | openOnuAc.exitChannel = make(chan int, 1) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 85 | openOnuAc.deviceHandlers = make(map[string]*deviceHandler) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 86 | openOnuAc.deviceHandlersCreateChan = make(map[string]chan bool) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 87 | openOnuAc.lockDeviceHandlersMap = sync.RWMutex{} |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 88 | openOnuAc.kafkaICProxy = kafkaICProxy |
| 89 | openOnuAc.config = cfg |
Matteo Scandolo | f1f39a7 | 2020-11-24 12:08:11 -0800 | [diff] [blame] | 90 | openOnuAc.cm = cm |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 91 | openOnuAc.numOnus = cfg.OnuNumber |
| 92 | openOnuAc.coreProxy = coreProxy |
| 93 | openOnuAc.adapterProxy = adapterProxy |
| 94 | openOnuAc.eventProxy = eventProxy |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 95 | openOnuAc.kvClient = kvClient |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 96 | openOnuAc.KVStoreAddress = cfg.KVStoreAddress |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 97 | openOnuAc.KVStoreType = cfg.KVStoreType |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 98 | openOnuAc.KVStoreTimeout = cfg.KVStoreTimeout |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 99 | openOnuAc.mibTemplatesGenerated = make(map[string]bool) |
| 100 | openOnuAc.lockMibTemplateGenerated = sync.RWMutex{} |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 101 | openOnuAc.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval |
| 102 | openOnuAc.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 103 | openOnuAc.AcceptIncrementalEvto = cfg.AccIncrEvto |
Himani Chawla | d96df18 | 2020-09-28 11:12:02 +0530 | [diff] [blame] | 104 | openOnuAc.maxTimeoutInterAdapterComm = cfg.MaxTimeoutInterAdapterComm |
Holger Hildebrandt | 38985dc | 2021-02-18 16:25:20 +0000 | [diff] [blame] | 105 | openOnuAc.maxTimeoutReconciling = cfg.MaxTimeoutReconciling |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 106 | //openOnuAc.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval |
Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 107 | openOnuAc.metricsEnabled = cfg.MetricsEnabled |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 108 | openOnuAc.mibAuditInterval = cfg.MibAuditInterval |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 109 | // since consumers of OMCI timeout value everywhere in code is in "int seconds", do this useful conversion |
| 110 | openOnuAc.omciTimeout = int(cfg.OmciTimeout.Seconds()) |
Himani Chawla | 075f164 | 2021-03-15 19:23:24 +0530 | [diff] [blame] | 111 | openOnuAc.alarmAuditInterval = cfg.AlarmAuditInterval |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 112 | openOnuAc.dlToOnuTimeout4M = cfg.DownloadToOnuTimeout4MB |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 113 | |
| 114 | openOnuAc.pSupportedFsms = &OmciDeviceFsms{ |
| 115 | "mib-synchronizer": { |
| 116 | //mibSyncFsm, // Implements the MIB synchronization state machine |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 117 | mibDbVolatileDictImpl, // Implements volatile ME MIB database |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 118 | //true, // Advertise events on OpenOMCI event bus |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 119 | openOnuAc.mibAuditInterval, // Time to wait between MIB audits. 0 to disable audits. |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 120 | // map[string]func() error{ |
| 121 | // "mib-upload": onuDeviceEntry.MibUploadTask, |
| 122 | // "mib-template": onuDeviceEntry.MibTemplateTask, |
| 123 | // "get-mds": onuDeviceEntry.GetMdsTask, |
| 124 | // "mib-audit": onuDeviceEntry.GetMdsTask, |
| 125 | // "mib-resync": onuDeviceEntry.MibResyncTask, |
| 126 | // "mib-reconcile": onuDeviceEntry.MibReconcileTask, |
| 127 | // }, |
| 128 | }, |
| 129 | } |
| 130 | |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 131 | openOnuAc.pDownloadManager = newAdapterDownloadManager(ctx) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 132 | openOnuAc.pFileManager = newFileDownloadManager(ctx) |
| 133 | openOnuAc.pFileManager.SetDownloadTimeout(ctx, cfg.DownloadToAdapterTimeout) |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 134 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 135 | return &openOnuAc |
| 136 | } |
| 137 | |
| 138 | //Start starts (logs) the adapter |
| 139 | func (oo *OpenONUAC) Start(ctx context.Context) error { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 140 | logger.Info(ctx, "starting-openonu-adapter") |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 141 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 142 | return nil |
| 143 | } |
| 144 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 145 | /* |
| 146 | //stop terminates the session |
| 147 | func (oo *OpenONUAC) stop(ctx context.Context) error { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 148 | logger.Info(ctx,"stopping-device-manager") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 149 | oo.exitChannel <- 1 |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 150 | logger.Info(ctx,"device-manager-stopped") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 151 | return nil |
| 152 | } |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 153 | */ |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 154 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 155 | func (oo *OpenONUAC) addDeviceHandlerToMap(ctx context.Context, agent *deviceHandler) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 156 | oo.lockDeviceHandlersMap.Lock() |
| 157 | defer oo.lockDeviceHandlersMap.Unlock() |
| 158 | if _, exist := oo.deviceHandlers[agent.deviceID]; !exist { |
| 159 | oo.deviceHandlers[agent.deviceID] = agent |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 160 | oo.deviceHandlers[agent.deviceID].start(ctx) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 161 | if _, exist := oo.deviceHandlersCreateChan[agent.deviceID]; exist { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 162 | logger.Debugw(ctx, "deviceHandler created - trigger processing of pending ONU_IND_REQUEST", log.Fields{"device-id": agent.deviceID}) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 163 | oo.deviceHandlersCreateChan[agent.deviceID] <- true |
| 164 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 168 | func (oo *OpenONUAC) deleteDeviceHandlerToMap(agent *deviceHandler) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 169 | oo.lockDeviceHandlersMap.Lock() |
| 170 | defer oo.lockDeviceHandlersMap.Unlock() |
| 171 | delete(oo.deviceHandlers, agent.deviceID) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 172 | delete(oo.deviceHandlersCreateChan, agent.deviceID) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 175 | //getDeviceHandler gets the ONU deviceHandler and may wait until it is created |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 176 | func (oo *OpenONUAC) getDeviceHandler(ctx context.Context, deviceID string, aWait bool) *deviceHandler { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 177 | oo.lockDeviceHandlersMap.Lock() |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 178 | agent, ok := oo.deviceHandlers[deviceID] |
| 179 | if aWait && !ok { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 180 | 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] | 181 | log.Fields{"device-id": deviceID}) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 182 | if _, exist := oo.deviceHandlersCreateChan[deviceID]; !exist { |
| 183 | oo.deviceHandlersCreateChan[deviceID] = make(chan bool, 1) |
| 184 | } |
Girish Gowdra | 7407a4d | 2020-11-12 12:44:53 -0800 | [diff] [blame] | 185 | deviceCreateChan := oo.deviceHandlersCreateChan[deviceID] |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 186 | //keep the read sema short to allow for subsequent write |
| 187 | oo.lockDeviceHandlersMap.Unlock() |
| 188 | // based on concurrent processing the deviceHandler creation may not yet be finished at his point |
| 189 | // so it might be needed to wait here for that event with some timeout |
| 190 | select { |
| 191 | case <-time.After(1 * time.Second): //timer may be discussed ... |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 192 | 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] | 193 | return nil |
Girish Gowdra | 7407a4d | 2020-11-12 12:44:53 -0800 | [diff] [blame] | 194 | case <-deviceCreateChan: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 195 | logger.Debugw(ctx, "deviceHandler is ready now - continue", log.Fields{"device-id": deviceID}) |
Girish Gowdra | 7407a4d | 2020-11-12 12:44:53 -0800 | [diff] [blame] | 196 | oo.lockDeviceHandlersMap.RLock() |
| 197 | defer oo.lockDeviceHandlersMap.RUnlock() |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 198 | return oo.deviceHandlers[deviceID] |
| 199 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 200 | } |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 201 | oo.lockDeviceHandlersMap.Unlock() |
| 202 | return agent |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 203 | } |
| 204 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 205 | func (oo *OpenONUAC) processInterAdapterONUIndReqMessage(ctx context.Context, msg *ic.InterAdapterMessage) error { |
Holger Hildebrandt | 6c1fb0a | 2020-11-25 15:41:01 +0000 | [diff] [blame] | 206 | msgBody := msg.GetBody() |
| 207 | onuIndication := &oop.OnuIndication{} |
| 208 | if err := ptypes.UnmarshalAny(msgBody, onuIndication); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 209 | logger.Warnw(ctx, "onu-ind-request-cannot-unmarshal-msg-body", log.Fields{"error": err}) |
Holger Hildebrandt | 6c1fb0a | 2020-11-25 15:41:01 +0000 | [diff] [blame] | 210 | return err |
| 211 | } |
| 212 | //ToDeviceId should address a DeviceHandler instance |
| 213 | targetDevice := msg.Header.ToDeviceId |
| 214 | |
| 215 | onuOperstate := onuIndication.GetOperState() |
| 216 | waitForDhInstPresent := false |
| 217 | if onuOperstate == "up" { |
| 218 | //Race condition (relevant in BBSIM-environment only): Due to unsynchronized processing of olt-adapter and rw_core, |
| 219 | //ONU_IND_REQUEST msg by olt-adapter could arrive a little bit earlier than rw_core was able to announce the corresponding |
| 220 | //ONU by RPC of Adopt_device(). Therefore it could be necessary to wait with processing of ONU_IND_REQUEST until call of |
| 221 | //Adopt_device() arrived and DeviceHandler instance was created |
| 222 | waitForDhInstPresent = true |
| 223 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 224 | if handler := oo.getDeviceHandler(ctx, targetDevice, waitForDhInstPresent); handler != nil { |
| 225 | logger.Infow(ctx, "onu-ind-request", log.Fields{"device-id": targetDevice, |
Holger Hildebrandt | 6c1fb0a | 2020-11-25 15:41:01 +0000 | [diff] [blame] | 226 | "OnuId": onuIndication.GetOnuId(), |
| 227 | "AdminState": onuIndication.GetAdminState(), "OperState": onuOperstate, |
| 228 | "SNR": onuIndication.GetSerialNumber()}) |
| 229 | |
| 230 | if onuOperstate == "up" { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 231 | return handler.createInterface(ctx, onuIndication) |
Holger Hildebrandt | 6c1fb0a | 2020-11-25 15:41:01 +0000 | [diff] [blame] | 232 | } else if (onuOperstate == "down") || (onuOperstate == "unreachable") { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 233 | return handler.updateInterface(ctx, onuIndication) |
Holger Hildebrandt | 6c1fb0a | 2020-11-25 15:41:01 +0000 | [diff] [blame] | 234 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 235 | logger.Errorw(ctx, "unknown-onu-ind-request operState", log.Fields{"OnuId": onuIndication.GetOnuId()}) |
Holger Hildebrandt | 6c1fb0a | 2020-11-25 15:41:01 +0000 | [diff] [blame] | 236 | return fmt.Errorf("invalidOperState: %s, %s", onuOperstate, targetDevice) |
| 237 | } |
| 238 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 239 | logger.Warnw(ctx, "no handler found for received onu-ind-request", log.Fields{ |
Holger Hildebrandt | 6c1fb0a | 2020-11-25 15:41:01 +0000 | [diff] [blame] | 240 | "msgToDeviceId": targetDevice}) |
| 241 | return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", targetDevice)) |
| 242 | } |
| 243 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 244 | // Adapter interface required methods ############## begin ######### |
| 245 | // ################################################################# |
| 246 | |
| 247 | // for original content compare: (needs according deviceHandler methods) |
| 248 | // /voltha-openolt-adapter/adaptercore/openolt.go |
| 249 | |
| 250 | // Adopt_device creates a new device handler if not present already and then adopts the device |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 251 | func (oo *OpenONUAC) Adopt_device(ctx context.Context, device *voltha.Device) error { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 252 | if device == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 253 | logger.Warn(ctx, "voltha-device-is-nil") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 254 | return errors.New("nil-device") |
| 255 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 256 | logger.Infow(ctx, "adopt-device", log.Fields{"device-id": device.Id}) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 257 | var handler *deviceHandler |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 258 | if handler = oo.getDeviceHandler(ctx, device.Id, false); handler == nil { |
| 259 | handler := newDeviceHandler(ctx, oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 260 | oo.addDeviceHandlerToMap(ctx, handler) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 261 | go handler.adoptOrReconcileDevice(ctx, device) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 262 | // Launch the creation of the device topic |
| 263 | // go oo.createDeviceTopic(device) |
| 264 | } |
| 265 | return nil |
| 266 | } |
| 267 | |
| 268 | //Get_ofp_device_info returns OFP information for the given device |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 269 | func (oo *OpenONUAC) Get_ofp_device_info(ctx context.Context, device *voltha.Device) (*ic.SwitchCapability, error) { |
| 270 | logger.Errorw(ctx, "device-handler-not-set", log.Fields{"device-id": device.Id}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 271 | return nil, fmt.Errorf("device-handler-not-set %s", device.Id) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | //Get_ofp_port_info returns OFP port information for the given device |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 275 | //200630: method removed as per [VOL-3202]: OF port info is now to be delivered within UniPort create |
| 276 | // cmp changes in onu_uni_port.go::CreateVolthaPort() |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 277 | |
| 278 | //Process_inter_adapter_message sends messages to a target device (between adapters) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 279 | func (oo *OpenONUAC) Process_inter_adapter_message(ctx context.Context, msg *ic.InterAdapterMessage) error { |
| 280 | logger.Debugw(ctx, "Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id, |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 281 | "msgProxyDeviceId": msg.Header.ProxyDeviceId, "msgToDeviceId": msg.Header.ToDeviceId, "Type": msg.Header.Type}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 282 | |
Holger Hildebrandt | 6c1fb0a | 2020-11-25 15:41:01 +0000 | [diff] [blame] | 283 | if msg.Header.Type == ic.InterAdapterMessageType_ONU_IND_REQUEST { |
| 284 | // we have to handle ONU_IND_REQUEST already here - see comments in processInterAdapterONUIndReqMessage() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 285 | return oo.processInterAdapterONUIndReqMessage(ctx, msg) |
Holger Hildebrandt | 6c1fb0a | 2020-11-25 15:41:01 +0000 | [diff] [blame] | 286 | } |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 287 | //ToDeviceId should address a DeviceHandler instance |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 288 | targetDevice := msg.Header.ToDeviceId |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 289 | if handler := oo.getDeviceHandler(ctx, targetDevice, false); handler != nil { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 290 | /* 200724: modification towards synchronous implementation - possible errors within processing shall be |
| 291 | * in the accordingly delayed response, some timing effect might result in Techprofile processing for multiple UNI's |
| 292 | */ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 293 | return handler.processInterAdapterMessage(ctx, msg) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 294 | /* so far the processing has been in background with according commented error treatment restrictions: |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 295 | go handler.ProcessInterAdapterMessage(msg) |
| 296 | // error treatment might be more sophisticated |
| 297 | // by now let's just accept the message on 'communication layer' |
| 298 | // message content problems have to be evaluated then in the handler |
| 299 | // and are by now not reported to the calling party (to force what reaction there?) |
| 300 | return nil |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 301 | */ |
Holger Hildebrandt | 14be2bf | 2022-01-10 16:04:16 +0000 | [diff] [blame] | 302 | } else if msg.Header.Type == ic.InterAdapterMessageType_DELETE_GEM_PORT_REQUEST || |
| 303 | msg.Header.Type == ic.InterAdapterMessageType_DELETE_TCONT_REQUEST { |
| 304 | // delete requests for objects of an already deleted ONU should be acknowledged positively - continue |
| 305 | logger.Debugw(ctx, "deviceHandler not found for delete request - continue", log.Fields{"device-id": targetDevice}) |
| 306 | return nil |
| 307 | } else { |
| 308 | logger.Warnw(ctx, "no handler found for received Inter-Proxy-message", log.Fields{ |
| 309 | "msgToDeviceId": targetDevice}) |
| 310 | return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", targetDevice)) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 311 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 312 | } |
| 313 | |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 314 | //Process_tech_profile_instance_request not implemented |
| 315 | func (oo *OpenONUAC) Process_tech_profile_instance_request(ctx context.Context, msg *ic.InterAdapterTechProfileInstanceRequestMessage) *ic.InterAdapterTechProfileDownloadMessage { |
| 316 | logger.Error(ctx, "unImplemented") |
| 317 | return nil |
| 318 | } |
| 319 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 320 | //Adapter_descriptor not implemented |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 321 | func (oo *OpenONUAC) Adapter_descriptor(ctx context.Context) error { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 322 | return errors.New("unImplemented") |
| 323 | } |
| 324 | |
| 325 | //Device_types unimplemented |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 326 | func (oo *OpenONUAC) Device_types(ctx context.Context) (*voltha.DeviceTypes, error) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 327 | return nil, errors.New("unImplemented") |
| 328 | } |
| 329 | |
| 330 | //Health returns unimplemented |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 331 | func (oo *OpenONUAC) Health(ctx context.Context) (*voltha.HealthStatus, error) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 332 | return nil, errors.New("unImplemented") |
| 333 | } |
| 334 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 335 | //Reconcile_device is called once when the adapter needs to re-create device - usually on core restart |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 336 | func (oo *OpenONUAC) Reconcile_device(ctx context.Context, device *voltha.Device) error { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 337 | if device == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 338 | logger.Warn(ctx, "reconcile-device-voltha-device-is-nil") |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 339 | return errors.New("nil-device") |
| 340 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 341 | logger.Infow(ctx, "reconcile-device", log.Fields{"device-id": device.Id}) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 342 | var handler *deviceHandler |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 343 | if handler = oo.getDeviceHandler(ctx, device.Id, false); handler == nil { |
| 344 | handler := newDeviceHandler(ctx, oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 345 | oo.addDeviceHandlerToMap(ctx, handler) |
| 346 | handler.device = device |
Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 347 | if err := handler.coreProxy.DeviceStateUpdate(ctx, device.Id, device.ConnectStatus, voltha.OperStatus_RECONCILING); err != nil { |
| 348 | return fmt.Errorf("not able to update device state to reconciling. Err : %s", err.Error()) |
| 349 | } |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 350 | handler.startReconciling(ctx, false) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 351 | go handler.adoptOrReconcileDevice(ctx, handler.device) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 352 | // reconcilement will be continued after onu-device entry is added |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 353 | } else { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 354 | return fmt.Errorf(fmt.Sprintf("device-already-reconciled-or-active-%s", device.Id)) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 355 | } |
| 356 | return nil |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | //Abandon_device unimplemented |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 360 | func (oo *OpenONUAC) Abandon_device(ctx context.Context, device *voltha.Device) error { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 361 | return errors.New("unImplemented") |
| 362 | } |
| 363 | |
| 364 | //Disable_device disables the given device |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 365 | func (oo *OpenONUAC) Disable_device(ctx context.Context, device *voltha.Device) error { |
| 366 | logger.Infow(ctx, "disable-device", log.Fields{"device-id": device.Id}) |
| 367 | if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
| 368 | go handler.disableDevice(ctx, device) |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 369 | return nil |
| 370 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 371 | logger.Warnw(ctx, "no handler found for device-disable", log.Fields{"device-id": device.Id}) |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 372 | return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id)) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 373 | } |
| 374 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 375 | //Reenable_device enables the onu device after disable |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 376 | func (oo *OpenONUAC) Reenable_device(ctx context.Context, device *voltha.Device) error { |
| 377 | logger.Infow(ctx, "reenable-device", log.Fields{"device-id": device.Id}) |
| 378 | if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
| 379 | go handler.reEnableDevice(ctx, device) |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 380 | return nil |
| 381 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 382 | logger.Warnw(ctx, "no handler found for device-reenable", log.Fields{"device-id": device.Id}) |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 383 | return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id)) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | //Reboot_device reboots the given device |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 387 | func (oo *OpenONUAC) Reboot_device(ctx context.Context, device *voltha.Device) error { |
| 388 | logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id}) |
| 389 | if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 390 | go handler.rebootDevice(ctx, true, device) //reboot request with device checking |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 391 | return nil |
| 392 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 393 | logger.Warnw(ctx, "no handler found for device-reboot", log.Fields{"device-id": device.Id}) |
Andrey Pozolotin | 1394a1c | 2021-06-01 00:54:18 +0300 | [diff] [blame] | 394 | return fmt.Errorf("handler-not-found-for-device: %s", device.Id) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 397 | //Self_test_device unimplemented |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 398 | func (oo *OpenONUAC) Self_test_device(ctx context.Context, device *voltha.Device) error { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 399 | return errors.New("unImplemented") |
| 400 | } |
| 401 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 402 | // Delete_device deletes the given device |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 403 | func (oo *OpenONUAC) Delete_device(ctx context.Context, device *voltha.Device) error { |
| 404 | logger.Infow(ctx, "delete-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber}) |
| 405 | if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 406 | var errorsList []error |
Holger Hildebrandt | ff05b68 | 2021-03-16 15:02:05 +0000 | [diff] [blame] | 407 | |
| 408 | handler.mutexDeletionInProgressFlag.Lock() |
| 409 | handler.deletionInProgress = true |
| 410 | handler.mutexDeletionInProgressFlag.Unlock() |
| 411 | |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 412 | if err := handler.deleteDevicePersistencyData(ctx); err != nil { |
| 413 | errorsList = append(errorsList, err) |
| 414 | } |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 415 | select { |
| 416 | case handler.stopCollector <- true: // stop the metric collector routine |
| 417 | logger.Debugw(ctx, "sent stop signal to metric collector routine", log.Fields{"device-id": device.Id}) |
| 418 | default: |
| 419 | logger.Warnw(ctx, "metric collector routine not waiting on stop signal", log.Fields{"device-id": device.Id}) |
| 420 | } |
| 421 | select { |
| 422 | case handler.stopAlarmManager <- true: //stop the alarm manager. |
| 423 | logger.Debugw(ctx, "sent stop signal to alarm manager", log.Fields{"device-id": device.Id}) |
| 424 | default: |
| 425 | logger.Warnw(ctx, "alarm manager not waiting on stop signal", log.Fields{"device-id": device.Id}) |
| 426 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 427 | if handler.pOnuMetricsMgr != nil { |
| 428 | if err := handler.pOnuMetricsMgr.clearAllPmData(ctx); err != nil { |
| 429 | errorsList = append(errorsList, err) |
| 430 | } |
| 431 | } |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 432 | select { |
| 433 | case handler.pSelfTestHdlr.stopSelfTestModule <- true: |
| 434 | logger.Debugw(ctx, "sent stop signal to self test handler module", log.Fields{"device-id": device.Id}) |
| 435 | default: |
| 436 | logger.Warnw(ctx, "self test handler module not waiting on stop signal", log.Fields{"device-id": device.Id}) |
| 437 | } |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 438 | //don't leave any garbage - even in error case |
| 439 | oo.deleteDeviceHandlerToMap(handler) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 440 | if len(errorsList) > 0 { |
| 441 | logger.Errorw(ctx, "one-or-more-error-during-device-delete", log.Fields{"device-id": device.Id}) |
| 442 | return fmt.Errorf("one-or-more-error-during-device-delete, errors:%v", errorsList) |
| 443 | } |
| 444 | return nil |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 445 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 446 | logger.Warnw(ctx, "no handler found for device-deletion", log.Fields{"device-id": device.Id}) |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 447 | return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id)) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | //Get_device_details unimplemented |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 451 | func (oo *OpenONUAC) Get_device_details(ctx context.Context, device *voltha.Device) error { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 452 | return errors.New("unImplemented") |
| 453 | } |
| 454 | |
| 455 | //Update_flows_bulk returns |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 456 | func (oo *OpenONUAC) Update_flows_bulk(ctx context.Context, device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata) error { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 457 | return errors.New("unImplemented") |
| 458 | } |
| 459 | |
| 460 | //Update_flows_incrementally updates (add/remove) the flows on a given device |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 461 | func (oo *OpenONUAC) Update_flows_incrementally(ctx context.Context, device *voltha.Device, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 462 | flows *openflow_13.FlowChanges, groups *openflow_13.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 463 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 464 | logger.Infow(ctx, "update-flows-incrementally", log.Fields{"device-id": device.Id}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 465 | //flow config is relayed to handler even if the device might be in some 'inactive' state |
| 466 | // let the handler or related FSM's decide, what to do with the modified flow state info |
| 467 | // 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] | 468 | |
| 469 | // 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] | 470 | // but processing is continued for flowUpdate possibly also set in the request |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 471 | if groups.ToAdd != nil && groups.ToAdd.Items != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 472 | logger.Warnw(ctx, "Update-flow-incr: group add not supported (ignored)", log.Fields{"device-id": device.Id}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 473 | } |
| 474 | if groups.ToRemove != nil && groups.ToRemove.Items != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 475 | logger.Warnw(ctx, "Update-flow-incr: group remove not supported (ignored)", log.Fields{"device-id": device.Id}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 476 | } |
| 477 | if groups.ToUpdate != nil && groups.ToUpdate.Items != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 478 | logger.Warnw(ctx, "Update-flow-incr: group update not supported (ignored)", log.Fields{"device-id": device.Id}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 479 | } |
| 480 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 481 | if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
| 482 | err := handler.FlowUpdateIncremental(ctx, flows, groups, flowMetadata) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 483 | return err |
| 484 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 485 | logger.Warnw(ctx, "no handler found for incremental flow update", log.Fields{"device-id": device.Id}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 486 | return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id)) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | //Update_pm_config returns PmConfigs nil or error |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 490 | func (oo *OpenONUAC) Update_pm_config(ctx context.Context, device *voltha.Device, pmConfigs *voltha.PmConfigs) error { |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 491 | logger.Infow(ctx, "update-pm-config", log.Fields{"device-id": device.Id}) |
| 492 | if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 493 | return handler.updatePmConfig(ctx, pmConfigs) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 494 | } |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 495 | logger.Warnw(ctx, "no handler found for update-pm-config", log.Fields{"device-id": device.Id}) |
| 496 | return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id)) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | //Receive_packet_out sends packet out to the device |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 500 | func (oo *OpenONUAC) Receive_packet_out(ctx context.Context, deviceID string, egressPortNo int, packet *openflow_13.OfpPacketOut) error { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 501 | return errors.New("unImplemented") |
| 502 | } |
| 503 | |
| 504 | //Suppress_event unimplemented |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 505 | func (oo *OpenONUAC) Suppress_event(ctx context.Context, filter *voltha.EventFilter) error { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 506 | return errors.New("unImplemented") |
| 507 | } |
| 508 | |
| 509 | //Unsuppress_event unimplemented |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 510 | func (oo *OpenONUAC) Unsuppress_event(ctx context.Context, filter *voltha.EventFilter) error { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 511 | return errors.New("unImplemented") |
| 512 | } |
| 513 | |
Andrea Campanella | 71e546a | 2021-02-26 11:09:33 +0100 | [diff] [blame] | 514 | //Download_image requests downloading some image according to indications as given in request |
| 515 | //The ImageDownload needs to be called `request`due to library reflection requirements |
| 516 | func (oo *OpenONUAC) Download_image(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 517 | if request != nil && (*request).Name != "" { |
| 518 | if !oo.pDownloadManager.imageExists(ctx, request) { |
| 519 | logger.Debugw(ctx, "start image download", log.Fields{"image-description": request}) |
| 520 | // Download_image is not supposed to be blocking, anyway let's call the DownloadManager still synchronously to detect 'fast' problems |
| 521 | // the download itself is later done in background |
| 522 | err := oo.pDownloadManager.startDownload(ctx, request) |
| 523 | return request, err |
| 524 | } |
| 525 | // image already exists |
| 526 | logger.Debugw(ctx, "image already downloaded", log.Fields{"image-description": request}) |
| 527 | return request, nil |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 528 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 529 | return request, errors.New("invalid image definition") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | //Get_image_download_status unimplemented |
Andrea Campanella | 71e546a | 2021-02-26 11:09:33 +0100 | [diff] [blame] | 533 | //The ImageDownload needs to be called `request`due to library reflection requirements |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 534 | func (oo *OpenONUAC) Get_image_download_status(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 535 | return nil, errors.New("unImplemented") |
| 536 | } |
| 537 | |
| 538 | //Cancel_image_download unimplemented |
Andrea Campanella | 71e546a | 2021-02-26 11:09:33 +0100 | [diff] [blame] | 539 | //The ImageDownload needs to be called `request`due to library reflection requirements |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 540 | func (oo *OpenONUAC) Cancel_image_download(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 541 | return nil, errors.New("unImplemented") |
| 542 | } |
| 543 | |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 544 | //Activate_image_update requests downloading some Onu Software image to the ONU via OMCI |
Andrea Campanella | 71e546a | 2021-02-26 11:09:33 +0100 | [diff] [blame] | 545 | // according to indications as given in request and on success activate the image on the ONU |
| 546 | //The ImageDownload needs to be called `request`due to library reflection requirements |
| 547 | func (oo *OpenONUAC) Activate_image_update(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 548 | if request != nil && (*request).Name != "" { |
| 549 | if oo.pDownloadManager.imageLocallyDownloaded(ctx, request) { |
| 550 | if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
| 551 | logger.Debugw(ctx, "image download on omci requested", log.Fields{ |
| 552 | "image-description": request, "device-id": device.Id}) |
| 553 | err := handler.doOnuSwUpgrade(ctx, request, oo.pDownloadManager) |
| 554 | return request, err |
| 555 | } |
| 556 | logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": device.Id}) |
| 557 | return request, fmt.Errorf(fmt.Sprintf("handler-not-found - device-id: %s", device.Id)) |
mpagenko | 057889c | 2021-01-21 16:51:58 +0000 | [diff] [blame] | 558 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 559 | logger.Debugw(ctx, "image not yet downloaded on activate request", log.Fields{"image-description": request}) |
| 560 | return request, fmt.Errorf(fmt.Sprintf("image-not-yet-downloaded - device-id: %s", device.Id)) |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 561 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 562 | return request, errors.New("invalid image definition") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | //Revert_image_update unimplemented |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 566 | func (oo *OpenONUAC) Revert_image_update(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 567 | return nil, errors.New("unImplemented") |
| 568 | } |
| 569 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 570 | // Enable_port to Enable PON/NNI interface - seems not to be used/required according to python code |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 571 | func (oo *OpenONUAC) Enable_port(ctx context.Context, deviceID string, port *voltha.Port) error { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 572 | return errors.New("unImplemented") |
| 573 | } |
| 574 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 575 | // Disable_port to Disable pon/nni interface - seems not to be used/required according to python code |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 576 | func (oo *OpenONUAC) Disable_port(ctx context.Context, deviceID string, port *voltha.Port) error { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 577 | return errors.New("unImplemented") |
| 578 | } |
| 579 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 580 | //Child_device_lost - unimplemented |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 581 | //needed for if update >= 3.1.x |
Matteo Scandolo | 3f2bdc8 | 2021-03-18 18:18:22 -0700 | [diff] [blame] | 582 | func (oo *OpenONUAC) Child_device_lost(ctx context.Context, device *voltha.Device) error { |
Matteo Scandolo | 2e6f1e3 | 2020-04-15 11:28:45 -0700 | [diff] [blame] | 583 | return errors.New("unImplemented") |
| 584 | } |
| 585 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 586 | // Start_omci_test unimplemented |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 587 | func (oo *OpenONUAC) Start_omci_test(ctx context.Context, device *voltha.Device, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) { |
Matteo Scandolo | 2e6f1e3 | 2020-04-15 11:28:45 -0700 | [diff] [blame] | 588 | return nil, errors.New("unImplemented") |
| 589 | } |
| 590 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 591 | // Get_ext_value - unimplemented |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 592 | func (oo *OpenONUAC) Get_ext_value(ctx context.Context, deviceID string, device *voltha.Device, valueparam voltha.ValueType_Type) (*voltha.ReturnValues, error) { |
Matteo Scandolo | d132c0e | 2020-04-24 17:06:25 -0700 | [diff] [blame] | 593 | return nil, errors.New("unImplemented") |
| 594 | } |
| 595 | |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 596 | //Single_get_value_request handles the core request to retrieve uni status |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 597 | func (oo *OpenONUAC) Single_get_value_request(ctx context.Context, request extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) { |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 598 | logger.Infow(ctx, "Single_get_value_request", log.Fields{"request": request}) |
| 599 | |
| 600 | if handler := oo.getDeviceHandler(ctx, request.TargetId, false); handler != nil { |
| 601 | switch reqType := request.GetRequest().GetRequest().(type) { |
| 602 | case *extension.GetValueRequest_UniInfo: |
| 603 | return handler.getUniPortStatus(ctx, reqType.UniInfo), nil |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 604 | case *extension.GetValueRequest_OnuOpticalInfo: |
| 605 | commChan := make(chan Message) |
| 606 | respChan := make(chan extension.SingleGetValueResponse) |
| 607 | // Initiate the self test request |
| 608 | if err := handler.pSelfTestHdlr.SelfTestRequestStart(ctx, request, commChan, respChan); err != nil { |
| 609 | return &extension.SingleGetValueResponse{ |
| 610 | Response: &extension.GetValueResponse{ |
| 611 | Status: extension.GetValueResponse_ERROR, |
| 612 | ErrReason: extension.GetValueResponse_INTERNAL_ERROR, |
| 613 | }, |
| 614 | }, err |
| 615 | } |
| 616 | // The timeout handling is already implemented in omci_self_test_handler module |
| 617 | resp := <-respChan |
| 618 | return &resp, nil |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 619 | case *extension.GetValueRequest_OnuInfo: |
| 620 | return handler.getOnuOMCICounters(ctx, reqType.OnuInfo), nil |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 621 | default: |
| 622 | return postUniStatusErrResponse(extension.GetValueResponse_UNSUPPORTED), nil |
| 623 | |
| 624 | } |
| 625 | } |
| 626 | logger.Errorw(ctx, "Single_get_value_request failed ", log.Fields{"request": request}) |
| 627 | return postUniStatusErrResponse(extension.GetValueResponse_INVALID_DEVICE_ID), nil |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 628 | } |
| 629 | |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 630 | //if update >= 4.3.0 |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 631 | // Note: already with the implementation of the 'old' download interface problems were detected when the argument name used here is not the same |
| 632 | // as defined in the adapter interface file. That sounds strange and the effects were strange as well. |
| 633 | // The reason for that was never finally investigated. |
| 634 | // 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] | 635 | |
| 636 | // Download_onu_image downloads (and optionally activates and commits) the indicated ONU image to the requested ONU(s) |
| 637 | // if the image is not yet present on the adapter it has to be automatically downloaded |
| 638 | func (oo *OpenONUAC) Download_onu_image(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 639 | if request != nil && len((*request).DeviceId) > 0 && (*request).Image.Version != "" { |
| 640 | loResponse := voltha.DeviceImageResponse{} |
| 641 | imageIdentifier := (*request).Image.Version |
Holger Hildebrandt | 33f701d | 2021-12-22 10:07:58 +0000 | [diff] [blame] | 642 | downloadStartDone := false |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 643 | firstDevice := true |
| 644 | var vendorID string |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 645 | var onuVolthaDevice *voltha.Device |
| 646 | var devErr error |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 647 | for _, pCommonID := range (*request).DeviceId { |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 648 | vendorIDMatch := true |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 649 | loDeviceID := (*pCommonID).Id |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 650 | loDeviceImageState := voltha.DeviceImageState{} |
| 651 | loDeviceImageState.DeviceId = loDeviceID |
| 652 | loImageState := voltha.ImageState{} |
| 653 | loDeviceImageState.ImageState = &loImageState |
| 654 | loDeviceImageState.ImageState.Version = (*request).Image.Version |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 655 | |
| 656 | onuVolthaDevice = nil |
| 657 | handler := oo.getDeviceHandler(ctx, loDeviceID, false) |
| 658 | if handler != nil { |
| 659 | onuVolthaDevice, devErr = oo.coreProxy.GetDevice(log.WithSpanFromContext(context.TODO(), ctx), |
| 660 | loDeviceID, loDeviceID) |
| 661 | } else { |
| 662 | // assumption here is, that the concerned device was already created (automatic start after device creation not supported) |
| 663 | devErr = errors.New("no handler found for device-id") |
| 664 | } |
| 665 | if devErr != nil || onuVolthaDevice == nil { |
| 666 | logger.Warnw(ctx, "Failed to fetch ONU device for image download", |
| 667 | log.Fields{"device-id": loDeviceID, "err": devErr}) |
| 668 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED |
| 669 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //proto restriction, better option: 'INVALID_DEVICE' |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 670 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 671 | } else { |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 672 | if firstDevice { |
| 673 | //start/verify download of the image to the adapter based on first found device only |
| 674 | // use the OnuVendor identification from first given device |
Holger Hildebrandt | 33f701d | 2021-12-22 10:07:58 +0000 | [diff] [blame] | 675 | // note: if the request was done for a list of devices on the Voltha interface, rwCore |
| 676 | // translates that into a new rpc for each device, hence each device will be the first device in parallel requests! |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 677 | firstDevice = false |
| 678 | vendorID = onuVolthaDevice.VendorId |
| 679 | imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU |
Holger Hildebrandt | 33f701d | 2021-12-22 10:07:58 +0000 | [diff] [blame] | 680 | logger.Infow(ctx, "download request for file", |
| 681 | log.Fields{"device-id": loDeviceID, "image-id": imageIdentifier}) |
| 682 | // call the StartDownload synchronously to detect 'immediate' download problems |
| 683 | // the real download itself is later done in background |
| 684 | if fileState, err := oo.pFileManager.StartDownload(ctx, imageIdentifier, (*request).Image.Url); err == nil { |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 685 | // note: If the image (with vendorId+name) has already been downloaded before from some other |
Holger Hildebrandt | 33f701d | 2021-12-22 10:07:58 +0000 | [diff] [blame] | 686 | // valid URL, the current download request is not executed (current code delivers URL error). |
| 687 | // If the operators want to ensure that the new URL |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 688 | // is really used, then they first have to use the 'abort' API to remove the existing image! |
| 689 | // (abort API can be used also after some successful download to just remove the image from adapter) |
Holger Hildebrandt | 33f701d | 2021-12-22 10:07:58 +0000 | [diff] [blame] | 690 | if fileState == cFileStateDlSucceeded || fileState == cFileStateDlStarted { |
| 691 | downloadStartDone = true |
| 692 | } //else fileState may also indicate error situation, where the requested image is not ready to be used for other devices |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 693 | } |
| 694 | } else { |
| 695 | //for all following devices verify the matching vendorID |
| 696 | if onuVolthaDevice.VendorId != vendorID { |
| 697 | logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored", |
| 698 | log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID}) |
| 699 | vendorIDMatch = false |
| 700 | } |
| 701 | } |
Holger Hildebrandt | 33f701d | 2021-12-22 10:07:58 +0000 | [diff] [blame] | 702 | if downloadStartDone && vendorIDMatch { |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 703 | // start the ONU download activity for each possible device |
Holger Hildebrandt | 33f701d | 2021-12-22 10:07:58 +0000 | [diff] [blame] | 704 | logger.Infow(ctx, "request image download to ONU on omci ", log.Fields{ |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 705 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
Holger Hildebrandt | 33f701d | 2021-12-22 10:07:58 +0000 | [diff] [blame] | 706 | // onu upgrade handling called in background without immediate error evaluation here |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 707 | // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others |
| 708 | // state/progress/success of the request has to be verified using the Get_onu_image_status() API |
| 709 | go handler.onuSwUpgradeAfterDownload(ctx, request, oo.pFileManager, imageIdentifier) |
| 710 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_STARTED |
| 711 | loDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR |
| 712 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 713 | } else { |
| 714 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED |
Holger Hildebrandt | 33f701d | 2021-12-22 10:07:58 +0000 | [diff] [blame] | 715 | if !downloadStartDone { |
| 716 | // based on above fileState more descriptive error codes would be possible, e.g |
| 717 | // IMAGE_EXISTS_WITH_DIFFERENT_URL - would require proto buf update |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 718 | loDeviceImageState.ImageState.Reason = voltha.ImageState_INVALID_URL |
| 719 | } else { //only logical option is !vendorIDMatch |
| 720 | loDeviceImageState.ImageState.Reason = voltha.ImageState_VENDOR_DEVICE_MISMATCH |
| 721 | } |
| 722 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 723 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 724 | } |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 725 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState) |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 726 | } //for all requested devices |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 727 | pImageResp := &loResponse |
| 728 | return pImageResp, nil |
| 729 | } |
| 730 | return nil, errors.New("invalid image download parameters") |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | // Get_onu_image_status delivers the adapter-related information about the download/activation/commitment |
| 734 | // status for the requested image |
| 735 | func (oo *OpenONUAC) Get_onu_image_status(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 736 | if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" { |
| 737 | loResponse := voltha.DeviceImageResponse{} |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 738 | imageIdentifier := (*in).Version |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 739 | var vendorIDSet bool |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 740 | firstDevice := true |
| 741 | var vendorID string |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 742 | var onuVolthaDevice *voltha.Device |
| 743 | var devErr error |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 744 | for _, pCommonID := range (*in).DeviceId { |
| 745 | loDeviceID := (*pCommonID).Id |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 746 | pDeviceImageState := &voltha.DeviceImageState{DeviceId: loDeviceID} |
| 747 | vendorIDSet = false |
| 748 | onuVolthaDevice = nil |
| 749 | handler := oo.getDeviceHandler(ctx, loDeviceID, false) |
| 750 | if handler != nil { |
| 751 | onuVolthaDevice, devErr = oo.coreProxy.GetDevice(log.WithSpanFromContext(context.TODO(), ctx), |
| 752 | loDeviceID, loDeviceID) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 753 | } else { |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 754 | // assumption here is, that the concerned device was already created (automatic start after device creation not supported) |
| 755 | devErr = errors.New("no handler found for device-id") |
| 756 | } |
| 757 | if devErr != nil || onuVolthaDevice == nil { |
| 758 | logger.Warnw(ctx, "Failed to fetch Onu device to get image status", |
| 759 | log.Fields{"device-id": loDeviceID, "err": devErr}) |
| 760 | pImageState := &voltha.ImageState{ |
| 761 | Version: (*in).Version, |
| 762 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //no statement about last activity possible |
| 763 | Reason: voltha.ImageState_UNKNOWN_ERROR, //something like "DEVICE_NOT_EXISTS" would be better (proto def) |
| 764 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
| 765 | } |
| 766 | pDeviceImageState.ImageState = pImageState |
| 767 | } else { |
| 768 | if firstDevice { |
| 769 | //start/verify download of the image to the adapter based on first found device only |
| 770 | // use the OnuVendor identification from first given device |
| 771 | firstDevice = false |
| 772 | vendorID = onuVolthaDevice.VendorId |
| 773 | imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU |
| 774 | vendorIDSet = true |
| 775 | logger.Debugw(ctx, "status request for image", log.Fields{"image-id": imageIdentifier}) |
| 776 | } else { |
| 777 | //for all following devices verify the matching vendorID |
| 778 | if onuVolthaDevice.VendorId != vendorID { |
| 779 | logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored", |
| 780 | log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID}) |
| 781 | } else { |
| 782 | vendorIDSet = true |
| 783 | } |
| 784 | } |
| 785 | if !vendorIDSet { |
| 786 | pImageState := &voltha.ImageState{ |
| 787 | Version: (*in).Version, |
| 788 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //can't be sure that download for this device was really tried |
| 789 | Reason: voltha.ImageState_VENDOR_DEVICE_MISMATCH, |
| 790 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
| 791 | } |
| 792 | pDeviceImageState.ImageState = pImageState |
| 793 | } else { |
| 794 | logger.Debugw(ctx, "image status request for", log.Fields{ |
| 795 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 796 | //status request is called synchronously to collect the indications for all concerned devices |
| 797 | pDeviceImageState.ImageState = handler.requestOnuSwUpgradeState(ctx, imageIdentifier, (*in).Version) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 798 | } |
| 799 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 800 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState) |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 801 | } //for all requested devices |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 802 | pImageResp := &loResponse |
| 803 | return pImageResp, nil |
| 804 | } |
| 805 | return nil, errors.New("invalid image status request parameters") |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | // Abort_onu_image_upgrade stops the actual download/activation/commitment process (on next possibly step) |
| 809 | func (oo *OpenONUAC) Abort_onu_image_upgrade(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 810 | if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" { |
| 811 | loResponse := voltha.DeviceImageResponse{} |
| 812 | imageIdentifier := (*in).Version |
| 813 | firstDevice := true |
| 814 | var vendorID string |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 815 | var vendorIDSet bool |
| 816 | var onuVolthaDevice *voltha.Device |
| 817 | var devErr error |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 818 | for _, pCommonID := range (*in).DeviceId { |
| 819 | loDeviceID := (*pCommonID).Id |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 820 | pDeviceImageState := &voltha.DeviceImageState{} |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 821 | loImageState := voltha.ImageState{} |
| 822 | pDeviceImageState.ImageState = &loImageState |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 823 | vendorIDSet = false |
| 824 | onuVolthaDevice = nil |
| 825 | handler := oo.getDeviceHandler(ctx, loDeviceID, false) |
| 826 | if handler != nil { |
| 827 | onuVolthaDevice, devErr = oo.coreProxy.GetDevice(log.WithSpanFromContext(context.TODO(), ctx), |
| 828 | loDeviceID, loDeviceID) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 829 | } else { |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 830 | // assumption here is, that the concerned device was already created (automatic start after device creation not supported) |
| 831 | devErr = errors.New("no handler found for device-id") |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 832 | } |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 833 | if devErr != nil || onuVolthaDevice == nil { |
| 834 | logger.Warnw(ctx, "Failed to fetch Onu device to abort its download", |
| 835 | log.Fields{"device-id": loDeviceID, "err": devErr}) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 836 | pDeviceImageState.DeviceId = loDeviceID |
| 837 | pDeviceImageState.ImageState.Version = (*in).Version |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 838 | pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 839 | pDeviceImageState.ImageState.Reason = voltha.ImageState_CANCELLED_ON_REQUEST //something better could be considered (MissingHandler) - proto |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 840 | pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 841 | } else { |
| 842 | if firstDevice { |
| 843 | //start/verify download of the image to the adapter based on first found device only |
| 844 | // use the OnuVendor identification from first given device |
| 845 | firstDevice = false |
| 846 | vendorID = onuVolthaDevice.VendorId |
| 847 | vendorIDSet = true |
| 848 | imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU |
| 849 | logger.Debugw(ctx, "abort request for file", log.Fields{"image-id": imageIdentifier}) |
| 850 | } else { |
| 851 | //for all following devices verify the matching vendorID |
| 852 | if onuVolthaDevice.VendorId != vendorID { |
| 853 | logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored", |
| 854 | log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID}) |
| 855 | pDeviceImageState.DeviceId = loDeviceID |
| 856 | pDeviceImageState.ImageState.Version = (*in).Version |
| 857 | pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 858 | pDeviceImageState.ImageState.Reason = voltha.ImageState_VENDOR_DEVICE_MISMATCH |
| 859 | pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 860 | } else { |
| 861 | vendorIDSet = true |
| 862 | } |
| 863 | } |
| 864 | if vendorIDSet { |
| 865 | // cancel the ONU upgrade activity for each possible device |
| 866 | logger.Debugw(ctx, "image upgrade abort requested", log.Fields{ |
| 867 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 868 | //upgrade cancel is called synchronously to collect the imageResponse indications for all concerned devices |
| 869 | handler.cancelOnuSwUpgrade(ctx, imageIdentifier, (*in).Version, pDeviceImageState) |
| 870 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 871 | } |
| 872 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState) |
mpagenko | 9c22503 | 2021-10-15 14:26:49 +0000 | [diff] [blame] | 873 | } //for all requested devices |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 874 | if !firstDevice { |
| 875 | //if at least one valid device was found cancel also a possibly running download to adapter and remove the image |
| 876 | // this is to be done after the upgradeOnu cancel activities in order to not subduct the file for still running processes |
| 877 | oo.pFileManager.CancelDownload(ctx, imageIdentifier) |
| 878 | } |
| 879 | pImageResp := &loResponse |
| 880 | return pImageResp, nil |
| 881 | } |
| 882 | return nil, errors.New("invalid image upgrade abort parameters") |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | // Get_onu_images retrieves the ONU SW image status information via OMCI |
| 886 | func (oo *OpenONUAC) Get_onu_images(ctx context.Context, deviceID string) (*voltha.OnuImages, error) { |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 887 | logger.Infow(ctx, "Get_onu_images", log.Fields{"device-id": deviceID}) |
| 888 | if handler := oo.getDeviceHandler(ctx, deviceID, false); handler != nil { |
Himani Chawla | 69992ab | 2021-07-08 15:13:02 +0530 | [diff] [blame] | 889 | images, err := handler.getOnuImages(ctx) |
| 890 | if err == nil { |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 891 | return images, nil |
| 892 | } |
| 893 | return nil, fmt.Errorf(fmt.Sprintf("%s-%s", err, deviceID)) |
| 894 | } |
| 895 | logger.Warnw(ctx, "no handler found for Get_onu_images", log.Fields{"device-id": deviceID}) |
| 896 | return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", deviceID)) |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | // Activate_onu_image initiates the activation of the image for the requested ONU(s) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 900 | // precondition: image downloaded and not yet activated or image refers to current inactive image |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 901 | func (oo *OpenONUAC) Activate_onu_image(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 902 | if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" { |
| 903 | loResponse := voltha.DeviceImageResponse{} |
| 904 | imageIdentifier := (*in).Version |
| 905 | //let the deviceHandler find the adequate way of requesting the image activation |
| 906 | for _, pCommonID := range (*in).DeviceId { |
| 907 | loDeviceID := (*pCommonID).Id |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 908 | loDeviceImageState := voltha.DeviceImageState{} |
| 909 | loDeviceImageState.DeviceId = loDeviceID |
| 910 | loImageState := voltha.ImageState{} |
| 911 | loDeviceImageState.ImageState = &loImageState |
| 912 | loDeviceImageState.ImageState.Version = imageIdentifier |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 913 | //compared to download procedure the vendorID (from device) is secondary here |
| 914 | // and only needed in case the upgrade process is based on some ongoing download process (and can be retrieved in deviceHandler if needed) |
| 915 | // start image activation activity for each possible device |
| 916 | // assumption here is, that the concerned device was already created (automatic start after device creation not supported) |
| 917 | if handler := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil { |
| 918 | logger.Debugw(ctx, "onu image activation requested", log.Fields{ |
| 919 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 920 | //onu activation handling called in background without immediate error evaluation here |
| 921 | // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others |
| 922 | // 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] | 923 | if pImageStates, err := handler.onuSwActivateRequest(ctx, imageIdentifier, (*in).CommitOnSuccess); err != nil { |
| 924 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 925 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR |
| 926 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED |
| 927 | } else { |
| 928 | loDeviceImageState.ImageState.DownloadState = pImageStates.DownloadState |
| 929 | loDeviceImageState.ImageState.Reason = pImageStates.Reason |
| 930 | loDeviceImageState.ImageState.ImageState = pImageStates.ImageState |
| 931 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 932 | } else { |
| 933 | //cannot start SW activation for requested device |
| 934 | 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] | 935 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 936 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR |
| 937 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 938 | } |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 939 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 940 | } |
| 941 | pImageResp := &loResponse |
| 942 | return pImageResp, nil |
| 943 | } |
| 944 | return nil, errors.New("invalid image activation parameters") |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | // Commit_onu_image enforces the commitment of the image for the requested ONU(s) |
| 948 | // precondition: image activated and not yet committed |
| 949 | func (oo *OpenONUAC) Commit_onu_image(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 950 | if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" { |
| 951 | loResponse := voltha.DeviceImageResponse{} |
| 952 | imageIdentifier := (*in).Version |
| 953 | //let the deviceHandler find the adequate way of requesting the image activation |
| 954 | for _, pCommonID := range (*in).DeviceId { |
| 955 | loDeviceID := (*pCommonID).Id |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 956 | loDeviceImageState := voltha.DeviceImageState{} |
| 957 | loDeviceImageState.DeviceId = loDeviceID |
| 958 | loImageState := voltha.ImageState{} |
| 959 | loDeviceImageState.ImageState = &loImageState |
| 960 | loDeviceImageState.ImageState.Version = imageIdentifier |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 961 | //compared to download procedure the vendorID (from device) is secondary here |
| 962 | // and only needed in case the upgrade process is based on some ongoing download process (and can be retrieved in deviceHandler if needed) |
| 963 | // start image activation activity for each possible device |
| 964 | // assumption here is, that the concerned device was already created (automatic start after device creation not supported) |
| 965 | if handler := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil { |
| 966 | logger.Debugw(ctx, "onu image commitment requested", log.Fields{ |
| 967 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 968 | //onu commitment handling called in background without immediate error evaluation here |
| 969 | // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others |
| 970 | // 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] | 971 | if pImageStates, err := handler.onuSwCommitRequest(ctx, imageIdentifier); err != nil { |
| 972 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 973 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR |
| 974 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED |
| 975 | } else { |
| 976 | loDeviceImageState.ImageState.DownloadState = pImageStates.DownloadState |
| 977 | loDeviceImageState.ImageState.Reason = pImageStates.Reason |
| 978 | loDeviceImageState.ImageState.ImageState = pImageStates.ImageState |
| 979 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 980 | } else { |
| 981 | //cannot start SW commitment for requested device |
| 982 | 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] | 983 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 984 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR |
| 985 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 986 | } |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 987 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 988 | } |
| 989 | pImageResp := &loResponse |
| 990 | return pImageResp, nil |
| 991 | } |
| 992 | return nil, errors.New("invalid image commitment parameters") |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 993 | } |
| 994 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 995 | // Adapter interface required methods ################ end ######### |
| 996 | // ################################################################# |