blob: 48594931cc5edd0689adce429b5f7d94371a270c [file] [log] [blame]
Holger Hildebrandtfa074992020-03-27 15:42:06 +00001/*
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 Hildebrandt0f9b88d2020-04-20 13:33:25 +000017//Package adaptercoreonu provides the utility for onu devices, flows and statistics
18package adaptercoreonu
Holger Hildebrandtfa074992020-03-27 15:42:06 +000019
20import (
21 "context"
22 "errors"
23 "fmt"
24 "sync"
25 "time"
26
Girish Gowdra50e56422021-06-01 16:46:04 -070027 conf "github.com/opencord/voltha-lib-go/v5/pkg/config"
dbainbri4d3a0dc2020-12-02 00:33:42 +000028
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +000029 "github.com/golang/protobuf/ptypes"
Girish Gowdra50e56422021-06-01 16:46:04 -070030 "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"
mpagenkoc8bba412021-01-15 15:38:44 +000035 "github.com/opencord/voltha-protos/v4/go/extension"
dbainbri4d3a0dc2020-12-02 00:33:42 +000036 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 Hildebrandtfa074992020-03-27 15:42:06 +000040
Matteo Scandolo761f7512020-11-23 15:52:40 -080041 "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/config"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000042)
43
44//OpenONUAC structure holds the ONU core information
45type OpenONUAC struct {
Himani Chawla6d2ae152020-09-02 13:11:20 +053046 deviceHandlers map[string]*deviceHandler
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +000047 deviceHandlersCreateChan map[string]chan bool //channels for deviceHandler create events
Holger Hildebrandt61b24d02020-11-16 13:36:40 +000048 lockDeviceHandlersMap sync.RWMutex
Holger Hildebrandtfa074992020-03-27 15:42:06 +000049 coreProxy adapterif.CoreProxy
50 adapterProxy adapterif.AdapterProxy
Himani Chawlac07fda02020-12-09 16:21:21 +053051 eventProxy eventif.EventProxy
Holger Hildebrandtfa074992020-03-27 15:42:06 +000052 kafkaICProxy kafka.InterContainerProxy
mpagenkoaf801632020-07-03 10:00:42 +000053 kvClient kvstore.Client
Matteo Scandolof1f39a72020-11-24 12:08:11 -080054 cm *conf.ConfigManager
Holger Hildebrandtfa074992020-03-27 15:42:06 +000055 config *config.AdapterFlags
56 numOnus int
Matteo Scandolo127c59d2021-01-28 11:31:18 -080057 KVStoreAddress string
Holger Hildebrandtfa074992020-03-27 15:42:06 +000058 KVStoreType string
mpagenkoaf801632020-07-03 10:00:42 +000059 KVStoreTimeout time.Duration
Holger Hildebrandt61b24d02020-11-16 13:36:40 +000060 mibTemplatesGenerated map[string]bool
61 lockMibTemplateGenerated sync.RWMutex
Holger Hildebrandtfa074992020-03-27 15:42:06 +000062 exitChannel chan int
63 HeartbeatCheckInterval time.Duration
64 HeartbeatFailReportInterval time.Duration
mpagenkodff5dda2020-08-28 11:52:01 +000065 AcceptIncrementalEvto bool
Holger Hildebrandtfa074992020-03-27 15:42:06 +000066 //GrpcTimeoutInterval time.Duration
Himani Chawlad96df182020-09-28 11:12:02 +053067 pSupportedFsms *OmciDeviceFsms
68 maxTimeoutInterAdapterComm time.Duration
Holger Hildebrandt38985dc2021-02-18 16:25:20 +000069 maxTimeoutReconciling time.Duration
mpagenkoc8bba412021-01-15 15:38:44 +000070 pDownloadManager *adapterDownloadManager
mpagenkoc26d4c02021-05-06 14:27:57 +000071 pFileManager *fileDownloadManager //let coexist 'old and new' DownloadManager as long as 'old' does not get obsolete
Girish Gowdraaf0ad632021-01-27 13:00:01 -080072 metricsEnabled bool
Holger Hildebrandte3677f12021-02-05 14:50:56 +000073 mibAuditInterval time.Duration
Girish Gowdra0b235842021-03-09 13:06:46 -080074 omciTimeout int // in seconds
Himani Chawla075f1642021-03-15 19:23:24 +053075 alarmAuditInterval time.Duration
mpagenkoc26d4c02021-05-06 14:27:57 +000076 dlToOnuTimeout4M time.Duration
Holger Hildebrandtfa074992020-03-27 15:42:06 +000077}
78
79//NewOpenONUAC returns a new instance of OpenONU_AC
80func NewOpenONUAC(ctx context.Context, kafkaICProxy kafka.InterContainerProxy,
81 coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy,
Himani Chawlac07fda02020-12-09 16:21:21 +053082 eventProxy eventif.EventProxy, kvClient kvstore.Client, cfg *config.AdapterFlags, cm *conf.ConfigManager) *OpenONUAC {
Holger Hildebrandtfa074992020-03-27 15:42:06 +000083 var openOnuAc OpenONUAC
84 openOnuAc.exitChannel = make(chan int, 1)
Himani Chawla6d2ae152020-09-02 13:11:20 +053085 openOnuAc.deviceHandlers = make(map[string]*deviceHandler)
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +000086 openOnuAc.deviceHandlersCreateChan = make(map[string]chan bool)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +000087 openOnuAc.lockDeviceHandlersMap = sync.RWMutex{}
Holger Hildebrandtfa074992020-03-27 15:42:06 +000088 openOnuAc.kafkaICProxy = kafkaICProxy
89 openOnuAc.config = cfg
Matteo Scandolof1f39a72020-11-24 12:08:11 -080090 openOnuAc.cm = cm
Holger Hildebrandtfa074992020-03-27 15:42:06 +000091 openOnuAc.numOnus = cfg.OnuNumber
92 openOnuAc.coreProxy = coreProxy
93 openOnuAc.adapterProxy = adapterProxy
94 openOnuAc.eventProxy = eventProxy
mpagenkoaf801632020-07-03 10:00:42 +000095 openOnuAc.kvClient = kvClient
Matteo Scandolo127c59d2021-01-28 11:31:18 -080096 openOnuAc.KVStoreAddress = cfg.KVStoreAddress
Holger Hildebrandtfa074992020-03-27 15:42:06 +000097 openOnuAc.KVStoreType = cfg.KVStoreType
mpagenkoaf801632020-07-03 10:00:42 +000098 openOnuAc.KVStoreTimeout = cfg.KVStoreTimeout
Holger Hildebrandt61b24d02020-11-16 13:36:40 +000099 openOnuAc.mibTemplatesGenerated = make(map[string]bool)
100 openOnuAc.lockMibTemplateGenerated = sync.RWMutex{}
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000101 openOnuAc.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval
102 openOnuAc.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval
mpagenkodff5dda2020-08-28 11:52:01 +0000103 openOnuAc.AcceptIncrementalEvto = cfg.AccIncrEvto
Himani Chawlad96df182020-09-28 11:12:02 +0530104 openOnuAc.maxTimeoutInterAdapterComm = cfg.MaxTimeoutInterAdapterComm
Holger Hildebrandt38985dc2021-02-18 16:25:20 +0000105 openOnuAc.maxTimeoutReconciling = cfg.MaxTimeoutReconciling
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000106 //openOnuAc.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval
Girish Gowdraaf0ad632021-01-27 13:00:01 -0800107 openOnuAc.metricsEnabled = cfg.MetricsEnabled
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000108 openOnuAc.mibAuditInterval = cfg.MibAuditInterval
Girish Gowdra0b235842021-03-09 13:06:46 -0800109 // 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 Chawla075f1642021-03-15 19:23:24 +0530111 openOnuAc.alarmAuditInterval = cfg.AlarmAuditInterval
mpagenkoc26d4c02021-05-06 14:27:57 +0000112 openOnuAc.dlToOnuTimeout4M = cfg.DownloadToOnuTimeout4MB
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000113
114 openOnuAc.pSupportedFsms = &OmciDeviceFsms{
115 "mib-synchronizer": {
116 //mibSyncFsm, // Implements the MIB synchronization state machine
Himani Chawla6d2ae152020-09-02 13:11:20 +0530117 mibDbVolatileDictImpl, // Implements volatile ME MIB database
Himani Chawla4d908332020-08-31 12:30:20 +0530118 //true, // Advertise events on OpenOMCI event bus
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000119 openOnuAc.mibAuditInterval, // Time to wait between MIB audits. 0 to disable audits.
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000120 // 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
mpagenkoc8bba412021-01-15 15:38:44 +0000131 openOnuAc.pDownloadManager = newAdapterDownloadManager(ctx)
mpagenkoc26d4c02021-05-06 14:27:57 +0000132 openOnuAc.pFileManager = newFileDownloadManager(ctx)
133 openOnuAc.pFileManager.SetDownloadTimeout(ctx, cfg.DownloadToAdapterTimeout)
mpagenkoc8bba412021-01-15 15:38:44 +0000134
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000135 return &openOnuAc
136}
137
138//Start starts (logs) the adapter
139func (oo *OpenONUAC) Start(ctx context.Context) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000140 logger.Info(ctx, "starting-openonu-adapter")
mpagenkoc8bba412021-01-15 15:38:44 +0000141
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000142 return nil
143}
144
Himani Chawla6d2ae152020-09-02 13:11:20 +0530145/*
146//stop terminates the session
147func (oo *OpenONUAC) stop(ctx context.Context) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000148 logger.Info(ctx,"stopping-device-manager")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000149 oo.exitChannel <- 1
dbainbri4d3a0dc2020-12-02 00:33:42 +0000150 logger.Info(ctx,"device-manager-stopped")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000151 return nil
152}
Himani Chawla6d2ae152020-09-02 13:11:20 +0530153*/
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000154
Himani Chawla6d2ae152020-09-02 13:11:20 +0530155func (oo *OpenONUAC) addDeviceHandlerToMap(ctx context.Context, agent *deviceHandler) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000156 oo.lockDeviceHandlersMap.Lock()
157 defer oo.lockDeviceHandlersMap.Unlock()
158 if _, exist := oo.deviceHandlers[agent.deviceID]; !exist {
159 oo.deviceHandlers[agent.deviceID] = agent
Himani Chawla6d2ae152020-09-02 13:11:20 +0530160 oo.deviceHandlers[agent.deviceID].start(ctx)
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000161 if _, exist := oo.deviceHandlersCreateChan[agent.deviceID]; exist {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000162 logger.Debugw(ctx, "deviceHandler created - trigger processing of pending ONU_IND_REQUEST", log.Fields{"device-id": agent.deviceID})
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000163 oo.deviceHandlersCreateChan[agent.deviceID] <- true
164 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000165 }
166}
167
Himani Chawla6d2ae152020-09-02 13:11:20 +0530168func (oo *OpenONUAC) deleteDeviceHandlerToMap(agent *deviceHandler) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000169 oo.lockDeviceHandlersMap.Lock()
170 defer oo.lockDeviceHandlersMap.Unlock()
171 delete(oo.deviceHandlers, agent.deviceID)
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000172 delete(oo.deviceHandlersCreateChan, agent.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000173}
174
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000175//getDeviceHandler gets the ONU deviceHandler and may wait until it is created
dbainbri4d3a0dc2020-12-02 00:33:42 +0000176func (oo *OpenONUAC) getDeviceHandler(ctx context.Context, deviceID string, aWait bool) *deviceHandler {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000177 oo.lockDeviceHandlersMap.Lock()
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000178 agent, ok := oo.deviceHandlers[deviceID]
179 if aWait && !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000180 logger.Infow(ctx, "Race condition: deviceHandler not present - wait for creation or timeout",
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000181 log.Fields{"device-id": deviceID})
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000182 if _, exist := oo.deviceHandlersCreateChan[deviceID]; !exist {
183 oo.deviceHandlersCreateChan[deviceID] = make(chan bool, 1)
184 }
Girish Gowdra7407a4d2020-11-12 12:44:53 -0800185 deviceCreateChan := oo.deviceHandlersCreateChan[deviceID]
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000186 //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 ...
dbainbri4d3a0dc2020-12-02 00:33:42 +0000192 logger.Warnw(ctx, "No valid deviceHandler created after max WaitTime", log.Fields{"device-id": deviceID})
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000193 return nil
Girish Gowdra7407a4d2020-11-12 12:44:53 -0800194 case <-deviceCreateChan:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000195 logger.Debugw(ctx, "deviceHandler is ready now - continue", log.Fields{"device-id": deviceID})
Girish Gowdra7407a4d2020-11-12 12:44:53 -0800196 oo.lockDeviceHandlersMap.RLock()
197 defer oo.lockDeviceHandlersMap.RUnlock()
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000198 return oo.deviceHandlers[deviceID]
199 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000200 }
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000201 oo.lockDeviceHandlersMap.Unlock()
202 return agent
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000203}
204
dbainbri4d3a0dc2020-12-02 00:33:42 +0000205func (oo *OpenONUAC) processInterAdapterONUIndReqMessage(ctx context.Context, msg *ic.InterAdapterMessage) error {
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000206 msgBody := msg.GetBody()
207 onuIndication := &oop.OnuIndication{}
208 if err := ptypes.UnmarshalAny(msgBody, onuIndication); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000209 logger.Warnw(ctx, "onu-ind-request-cannot-unmarshal-msg-body", log.Fields{"error": err})
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000210 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 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000224 if handler := oo.getDeviceHandler(ctx, targetDevice, waitForDhInstPresent); handler != nil {
225 logger.Infow(ctx, "onu-ind-request", log.Fields{"device-id": targetDevice,
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000226 "OnuId": onuIndication.GetOnuId(),
227 "AdminState": onuIndication.GetAdminState(), "OperState": onuOperstate,
228 "SNR": onuIndication.GetSerialNumber()})
229
230 if onuOperstate == "up" {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000231 return handler.createInterface(ctx, onuIndication)
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000232 } else if (onuOperstate == "down") || (onuOperstate == "unreachable") {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000233 return handler.updateInterface(ctx, onuIndication)
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000234 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000235 logger.Errorw(ctx, "unknown-onu-ind-request operState", log.Fields{"OnuId": onuIndication.GetOnuId()})
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000236 return fmt.Errorf("invalidOperState: %s, %s", onuOperstate, targetDevice)
237 }
238 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000239 logger.Warnw(ctx, "no handler found for received onu-ind-request", log.Fields{
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000240 "msgToDeviceId": targetDevice})
241 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", targetDevice))
242}
243
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000244// 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
dbainbri4d3a0dc2020-12-02 00:33:42 +0000251func (oo *OpenONUAC) Adopt_device(ctx context.Context, device *voltha.Device) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000252 if device == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000253 logger.Warn(ctx, "voltha-device-is-nil")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000254 return errors.New("nil-device")
255 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000256 logger.Infow(ctx, "adopt-device", log.Fields{"device-id": device.Id})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530257 var handler *deviceHandler
dbainbri4d3a0dc2020-12-02 00:33:42 +0000258 if handler = oo.getDeviceHandler(ctx, device.Id, false); handler == nil {
259 handler := newDeviceHandler(ctx, oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000260 oo.addDeviceHandlerToMap(ctx, handler)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530261 go handler.adoptOrReconcileDevice(ctx, device)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000262 // 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
dbainbri4d3a0dc2020-12-02 00:33:42 +0000269func (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 Campanella6515c582020-10-05 11:25:00 +0200271 return nil, fmt.Errorf("device-handler-not-set %s", device.Id)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000272}
273
274//Get_ofp_port_info returns OFP port information for the given device
mpagenkoaf801632020-07-03 10:00:42 +0000275//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 Hildebrandtfa074992020-03-27 15:42:06 +0000277
278//Process_inter_adapter_message sends messages to a target device (between adapters)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000279func (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 Hildebrandt80129db2020-11-23 10:49:32 +0000281 "msgProxyDeviceId": msg.Header.ProxyDeviceId, "msgToDeviceId": msg.Header.ToDeviceId, "Type": msg.Header.Type})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000282
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000283 if msg.Header.Type == ic.InterAdapterMessageType_ONU_IND_REQUEST {
284 // we have to handle ONU_IND_REQUEST already here - see comments in processInterAdapterONUIndReqMessage()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000285 return oo.processInterAdapterONUIndReqMessage(ctx, msg)
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000286 }
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000287 //ToDeviceId should address a DeviceHandler instance
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000288 targetDevice := msg.Header.ToDeviceId
dbainbri4d3a0dc2020-12-02 00:33:42 +0000289 if handler := oo.getDeviceHandler(ctx, targetDevice, false); handler != nil {
mpagenko1cc3cb42020-07-27 15:24:38 +0000290 /* 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 */
dbainbri4d3a0dc2020-12-02 00:33:42 +0000293 return handler.processInterAdapterMessage(ctx, msg)
mpagenko1cc3cb42020-07-27 15:24:38 +0000294 /* so far the processing has been in background with according commented error treatment restrictions:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000295 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
mpagenko1cc3cb42020-07-27 15:24:38 +0000301 */
Holger Hildebrandt14be2bf2022-01-10 16:04:16 +0000302 } 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 Hildebrandtfa074992020-03-27 15:42:06 +0000311 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000312}
313
Girish Gowdra50e56422021-06-01 16:46:04 -0700314//Process_tech_profile_instance_request not implemented
315func (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 Hildebrandtfa074992020-03-27 15:42:06 +0000320//Adapter_descriptor not implemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000321func (oo *OpenONUAC) Adapter_descriptor(ctx context.Context) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000322 return errors.New("unImplemented")
323}
324
325//Device_types unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000326func (oo *OpenONUAC) Device_types(ctx context.Context) (*voltha.DeviceTypes, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000327 return nil, errors.New("unImplemented")
328}
329
330//Health returns unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000331func (oo *OpenONUAC) Health(ctx context.Context) (*voltha.HealthStatus, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000332 return nil, errors.New("unImplemented")
333}
334
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000335//Reconcile_device is called once when the adapter needs to re-create device - usually on core restart
dbainbri4d3a0dc2020-12-02 00:33:42 +0000336func (oo *OpenONUAC) Reconcile_device(ctx context.Context, device *voltha.Device) error {
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000337 if device == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000338 logger.Warn(ctx, "reconcile-device-voltha-device-is-nil")
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000339 return errors.New("nil-device")
340 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000341 logger.Infow(ctx, "reconcile-device", log.Fields{"device-id": device.Id})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530342 var handler *deviceHandler
dbainbri4d3a0dc2020-12-02 00:33:42 +0000343 if handler = oo.getDeviceHandler(ctx, device.Id, false); handler == nil {
344 handler := newDeviceHandler(ctx, oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000345 oo.addDeviceHandlerToMap(ctx, handler)
346 handler.device = device
Maninderb5187552021-03-23 22:23:42 +0530347 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 Hildebrandtbe523842021-03-10 10:47:18 +0000350 handler.startReconciling(ctx, false)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530351 go handler.adoptOrReconcileDevice(ctx, handler.device)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000352 // reconcilement will be continued after onu-device entry is added
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000353 } else {
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000354 return fmt.Errorf(fmt.Sprintf("device-already-reconciled-or-active-%s", device.Id))
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000355 }
356 return nil
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000357}
358
359//Abandon_device unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000360func (oo *OpenONUAC) Abandon_device(ctx context.Context, device *voltha.Device) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000361 return errors.New("unImplemented")
362}
363
364//Disable_device disables the given device
dbainbri4d3a0dc2020-12-02 00:33:42 +0000365func (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)
ozgecanetsiafce57b12020-05-25 14:39:35 +0300369 return nil
370 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000371 logger.Warnw(ctx, "no handler found for device-disable", log.Fields{"device-id": device.Id})
ozgecanetsiafce57b12020-05-25 14:39:35 +0300372 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000373}
374
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000375//Reenable_device enables the onu device after disable
dbainbri4d3a0dc2020-12-02 00:33:42 +0000376func (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)
ozgecanetsiafce57b12020-05-25 14:39:35 +0300380 return nil
381 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000382 logger.Warnw(ctx, "no handler found for device-reenable", log.Fields{"device-id": device.Id})
ozgecanetsiafce57b12020-05-25 14:39:35 +0300383 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000384}
385
386//Reboot_device reboots the given device
dbainbri4d3a0dc2020-12-02 00:33:42 +0000387func (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 {
mpagenko15ff4a52021-03-02 10:09:20 +0000390 go handler.rebootDevice(ctx, true, device) //reboot request with device checking
ozgecanetsiae11479f2020-07-06 09:44:47 +0300391 return nil
392 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000393 logger.Warnw(ctx, "no handler found for device-reboot", log.Fields{"device-id": device.Id})
Andrey Pozolotin1394a1c2021-06-01 00:54:18 +0300394 return fmt.Errorf("handler-not-found-for-device: %s", device.Id)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000395}
396
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000397//Self_test_device unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000398func (oo *OpenONUAC) Self_test_device(ctx context.Context, device *voltha.Device) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000399 return errors.New("unImplemented")
400}
401
Himani Chawla6d2ae152020-09-02 13:11:20 +0530402// Delete_device deletes the given device
dbainbri4d3a0dc2020-12-02 00:33:42 +0000403func (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 Gowdra0e533642021-03-02 22:02:51 -0800406 var errorsList []error
Holger Hildebrandtff05b682021-03-16 15:02:05 +0000407
408 handler.mutexDeletionInProgressFlag.Lock()
409 handler.deletionInProgress = true
410 handler.mutexDeletionInProgressFlag.Unlock()
411
Holger Hildebrandtddc4fbd2022-02-04 14:10:36 +0000412 if err := handler.resetFsms(ctx, true); err != nil {
Girish Gowdra0e533642021-03-02 22:02:51 -0800413 errorsList = append(errorsList, err)
414 }
Holger Hildebrandtddc4fbd2022-02-04 14:10:36 +0000415
416 if err := handler.deleteDevicePersistencyData(ctx); err != nil {
417 errorsList = append(errorsList, err)
Girish Gowdra6afb56a2021-04-27 17:47:57 -0700418 }
Girish Gowdra0e533642021-03-02 22:02:51 -0800419 if handler.pOnuMetricsMgr != nil {
420 if err := handler.pOnuMetricsMgr.clearAllPmData(ctx); err != nil {
421 errorsList = append(errorsList, err)
422 }
423 }
Girish Gowdra6afb56a2021-04-27 17:47:57 -0700424 select {
425 case handler.pSelfTestHdlr.stopSelfTestModule <- true:
426 logger.Debugw(ctx, "sent stop signal to self test handler module", log.Fields{"device-id": device.Id})
427 default:
428 logger.Warnw(ctx, "self test handler module not waiting on stop signal", log.Fields{"device-id": device.Id})
429 }
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000430 //don't leave any garbage - even in error case
431 oo.deleteDeviceHandlerToMap(handler)
Holger Hildebrandtddc4fbd2022-02-04 14:10:36 +0000432 go handler.PrepareForGarbageCollection(ctx, device.Id)
Girish Gowdra0e533642021-03-02 22:02:51 -0800433 if len(errorsList) > 0 {
434 logger.Errorw(ctx, "one-or-more-error-during-device-delete", log.Fields{"device-id": device.Id})
435 return fmt.Errorf("one-or-more-error-during-device-delete, errors:%v", errorsList)
436 }
437 return nil
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000438 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000439 logger.Warnw(ctx, "no handler found for device-deletion", log.Fields{"device-id": device.Id})
mpagenko2418ab02020-11-12 12:58:06 +0000440 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000441}
442
443//Get_device_details unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000444func (oo *OpenONUAC) Get_device_details(ctx context.Context, device *voltha.Device) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000445 return errors.New("unImplemented")
446}
447
448//Update_flows_bulk returns
dbainbri4d3a0dc2020-12-02 00:33:42 +0000449func (oo *OpenONUAC) Update_flows_bulk(ctx context.Context, device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000450 return errors.New("unImplemented")
451}
452
453//Update_flows_incrementally updates (add/remove) the flows on a given device
dbainbri4d3a0dc2020-12-02 00:33:42 +0000454func (oo *OpenONUAC) Update_flows_incrementally(ctx context.Context, device *voltha.Device,
mpagenkodff5dda2020-08-28 11:52:01 +0000455 flows *openflow_13.FlowChanges, groups *openflow_13.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error {
mpagenkofc4f56e2020-11-04 17:17:49 +0000456
dbainbri4d3a0dc2020-12-02 00:33:42 +0000457 logger.Infow(ctx, "update-flows-incrementally", log.Fields{"device-id": device.Id})
mpagenkofc4f56e2020-11-04 17:17:49 +0000458 //flow config is relayed to handler even if the device might be in some 'inactive' state
459 // let the handler or related FSM's decide, what to do with the modified flow state info
460 // at least the flow-remove must be done in respect to internal data, while OMCI activity might not be needed here
mpagenkodff5dda2020-08-28 11:52:01 +0000461
462 // For now, there is no support for group changes (as in the actual Py-adapter code)
mpagenkofc4f56e2020-11-04 17:17:49 +0000463 // but processing is continued for flowUpdate possibly also set in the request
mpagenkodff5dda2020-08-28 11:52:01 +0000464 if groups.ToAdd != nil && groups.ToAdd.Items != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000465 logger.Warnw(ctx, "Update-flow-incr: group add not supported (ignored)", log.Fields{"device-id": device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000466 }
467 if groups.ToRemove != nil && groups.ToRemove.Items != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000468 logger.Warnw(ctx, "Update-flow-incr: group remove not supported (ignored)", log.Fields{"device-id": device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000469 }
470 if groups.ToUpdate != nil && groups.ToUpdate.Items != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000471 logger.Warnw(ctx, "Update-flow-incr: group update not supported (ignored)", log.Fields{"device-id": device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000472 }
473
dbainbri4d3a0dc2020-12-02 00:33:42 +0000474 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
475 err := handler.FlowUpdateIncremental(ctx, flows, groups, flowMetadata)
mpagenkodff5dda2020-08-28 11:52:01 +0000476 return err
477 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000478 logger.Warnw(ctx, "no handler found for incremental flow update", log.Fields{"device-id": device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000479 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000480}
481
482//Update_pm_config returns PmConfigs nil or error
dbainbri4d3a0dc2020-12-02 00:33:42 +0000483func (oo *OpenONUAC) Update_pm_config(ctx context.Context, device *voltha.Device, pmConfigs *voltha.PmConfigs) error {
Girish Gowdrae09a6202021-01-12 18:10:59 -0800484 logger.Infow(ctx, "update-pm-config", log.Fields{"device-id": device.Id})
485 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
Girish Gowdra5a7c4922021-01-22 18:33:41 -0800486 return handler.updatePmConfig(ctx, pmConfigs)
Girish Gowdrae09a6202021-01-12 18:10:59 -0800487 }
Girish Gowdra5a7c4922021-01-22 18:33:41 -0800488 logger.Warnw(ctx, "no handler found for update-pm-config", log.Fields{"device-id": device.Id})
489 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000490}
491
492//Receive_packet_out sends packet out to the device
dbainbri4d3a0dc2020-12-02 00:33:42 +0000493func (oo *OpenONUAC) Receive_packet_out(ctx context.Context, deviceID string, egressPortNo int, packet *openflow_13.OfpPacketOut) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000494 return errors.New("unImplemented")
495}
496
497//Suppress_event unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000498func (oo *OpenONUAC) Suppress_event(ctx context.Context, filter *voltha.EventFilter) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000499 return errors.New("unImplemented")
500}
501
502//Unsuppress_event unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000503func (oo *OpenONUAC) Unsuppress_event(ctx context.Context, filter *voltha.EventFilter) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000504 return errors.New("unImplemented")
505}
506
Andrea Campanella71e546a2021-02-26 11:09:33 +0100507//Download_image requests downloading some image according to indications as given in request
508//The ImageDownload needs to be called `request`due to library reflection requirements
509func (oo *OpenONUAC) Download_image(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
mpagenko15ff4a52021-03-02 10:09:20 +0000510 if request != nil && (*request).Name != "" {
511 if !oo.pDownloadManager.imageExists(ctx, request) {
512 logger.Debugw(ctx, "start image download", log.Fields{"image-description": request})
513 // Download_image is not supposed to be blocking, anyway let's call the DownloadManager still synchronously to detect 'fast' problems
514 // the download itself is later done in background
515 err := oo.pDownloadManager.startDownload(ctx, request)
516 return request, err
517 }
518 // image already exists
519 logger.Debugw(ctx, "image already downloaded", log.Fields{"image-description": request})
520 return request, nil
mpagenkoc8bba412021-01-15 15:38:44 +0000521 }
mpagenko15ff4a52021-03-02 10:09:20 +0000522 return request, errors.New("invalid image definition")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000523}
524
525//Get_image_download_status unimplemented
Andrea Campanella71e546a2021-02-26 11:09:33 +0100526//The ImageDownload needs to be called `request`due to library reflection requirements
dbainbri4d3a0dc2020-12-02 00:33:42 +0000527func (oo *OpenONUAC) Get_image_download_status(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000528 return nil, errors.New("unImplemented")
529}
530
531//Cancel_image_download unimplemented
Andrea Campanella71e546a2021-02-26 11:09:33 +0100532//The ImageDownload needs to be called `request`due to library reflection requirements
dbainbri4d3a0dc2020-12-02 00:33:42 +0000533func (oo *OpenONUAC) Cancel_image_download(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000534 return nil, errors.New("unImplemented")
535}
536
mpagenko9c225032021-10-15 14:26:49 +0000537//Activate_image_update requests downloading some Onu Software image to the ONU via OMCI
Andrea Campanella71e546a2021-02-26 11:09:33 +0100538// according to indications as given in request and on success activate the image on the ONU
539//The ImageDownload needs to be called `request`due to library reflection requirements
540func (oo *OpenONUAC) Activate_image_update(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
mpagenko15ff4a52021-03-02 10:09:20 +0000541 if request != nil && (*request).Name != "" {
542 if oo.pDownloadManager.imageLocallyDownloaded(ctx, request) {
543 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
544 logger.Debugw(ctx, "image download on omci requested", log.Fields{
545 "image-description": request, "device-id": device.Id})
546 err := handler.doOnuSwUpgrade(ctx, request, oo.pDownloadManager)
547 return request, err
548 }
549 logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": device.Id})
550 return request, fmt.Errorf(fmt.Sprintf("handler-not-found - device-id: %s", device.Id))
mpagenko057889c2021-01-21 16:51:58 +0000551 }
mpagenko15ff4a52021-03-02 10:09:20 +0000552 logger.Debugw(ctx, "image not yet downloaded on activate request", log.Fields{"image-description": request})
553 return request, fmt.Errorf(fmt.Sprintf("image-not-yet-downloaded - device-id: %s", device.Id))
mpagenkoc8bba412021-01-15 15:38:44 +0000554 }
mpagenko15ff4a52021-03-02 10:09:20 +0000555 return request, errors.New("invalid image definition")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000556}
557
558//Revert_image_update unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000559func (oo *OpenONUAC) Revert_image_update(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000560 return nil, errors.New("unImplemented")
561}
562
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000563// Enable_port to Enable PON/NNI interface - seems not to be used/required according to python code
dbainbri4d3a0dc2020-12-02 00:33:42 +0000564func (oo *OpenONUAC) Enable_port(ctx context.Context, deviceID string, port *voltha.Port) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000565 return errors.New("unImplemented")
566}
567
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000568// Disable_port to Disable pon/nni interface - seems not to be used/required according to python code
dbainbri4d3a0dc2020-12-02 00:33:42 +0000569func (oo *OpenONUAC) Disable_port(ctx context.Context, deviceID string, port *voltha.Port) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000570 return errors.New("unImplemented")
571}
572
Himani Chawla6d2ae152020-09-02 13:11:20 +0530573//Child_device_lost - unimplemented
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000574//needed for if update >= 3.1.x
Matteo Scandolo3f2bdc82021-03-18 18:18:22 -0700575func (oo *OpenONUAC) Child_device_lost(ctx context.Context, device *voltha.Device) error {
Matteo Scandolo2e6f1e32020-04-15 11:28:45 -0700576 return errors.New("unImplemented")
577}
578
Himani Chawla6d2ae152020-09-02 13:11:20 +0530579// Start_omci_test unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000580func (oo *OpenONUAC) Start_omci_test(ctx context.Context, device *voltha.Device, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) {
Matteo Scandolo2e6f1e32020-04-15 11:28:45 -0700581 return nil, errors.New("unImplemented")
582}
583
Himani Chawla6d2ae152020-09-02 13:11:20 +0530584// Get_ext_value - unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000585func (oo *OpenONUAC) Get_ext_value(ctx context.Context, deviceID string, device *voltha.Device, valueparam voltha.ValueType_Type) (*voltha.ReturnValues, error) {
Matteo Scandolod132c0e2020-04-24 17:06:25 -0700586 return nil, errors.New("unImplemented")
587}
588
kesavandfdf77632021-01-26 23:40:33 -0500589//Single_get_value_request handles the core request to retrieve uni status
mpagenkoc8bba412021-01-15 15:38:44 +0000590func (oo *OpenONUAC) Single_get_value_request(ctx context.Context, request extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) {
kesavandfdf77632021-01-26 23:40:33 -0500591 logger.Infow(ctx, "Single_get_value_request", log.Fields{"request": request})
592
593 if handler := oo.getDeviceHandler(ctx, request.TargetId, false); handler != nil {
594 switch reqType := request.GetRequest().GetRequest().(type) {
595 case *extension.GetValueRequest_UniInfo:
596 return handler.getUniPortStatus(ctx, reqType.UniInfo), nil
Girish Gowdra6afb56a2021-04-27 17:47:57 -0700597 case *extension.GetValueRequest_OnuOpticalInfo:
598 commChan := make(chan Message)
599 respChan := make(chan extension.SingleGetValueResponse)
600 // Initiate the self test request
601 if err := handler.pSelfTestHdlr.SelfTestRequestStart(ctx, request, commChan, respChan); err != nil {
602 return &extension.SingleGetValueResponse{
603 Response: &extension.GetValueResponse{
604 Status: extension.GetValueResponse_ERROR,
605 ErrReason: extension.GetValueResponse_INTERNAL_ERROR,
606 },
607 }, err
608 }
609 // The timeout handling is already implemented in omci_self_test_handler module
610 resp := <-respChan
611 return &resp, nil
Himani Chawla43f95ff2021-06-03 00:24:12 +0530612 case *extension.GetValueRequest_OnuInfo:
613 return handler.getOnuOMCICounters(ctx, reqType.OnuInfo), nil
kesavandfdf77632021-01-26 23:40:33 -0500614 default:
615 return postUniStatusErrResponse(extension.GetValueResponse_UNSUPPORTED), nil
616
617 }
618 }
619 logger.Errorw(ctx, "Single_get_value_request failed ", log.Fields{"request": request})
620 return postUniStatusErrResponse(extension.GetValueResponse_INVALID_DEVICE_ID), nil
mpagenkoc8bba412021-01-15 15:38:44 +0000621}
622
mpagenko83144272021-04-27 10:06:22 +0000623//if update >= 4.3.0
mpagenkoc26d4c02021-05-06 14:27:57 +0000624// Note: already with the implementation of the 'old' download interface problems were detected when the argument name used here is not the same
625// as defined in the adapter interface file. That sounds strange and the effects were strange as well.
626// The reason for that was never finally investigated.
627// To be on the safe side argument names are left here always as defined in iAdapter.go .
mpagenko83144272021-04-27 10:06:22 +0000628
629// Download_onu_image downloads (and optionally activates and commits) the indicated ONU image to the requested ONU(s)
630// if the image is not yet present on the adapter it has to be automatically downloaded
631func (oo *OpenONUAC) Download_onu_image(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoc26d4c02021-05-06 14:27:57 +0000632 if request != nil && len((*request).DeviceId) > 0 && (*request).Image.Version != "" {
633 loResponse := voltha.DeviceImageResponse{}
634 imageIdentifier := (*request).Image.Version
Holger Hildebrandt33f701d2021-12-22 10:07:58 +0000635 downloadStartDone := false
mpagenkoc26d4c02021-05-06 14:27:57 +0000636 firstDevice := true
637 var vendorID string
mpagenko9c225032021-10-15 14:26:49 +0000638 var onuVolthaDevice *voltha.Device
639 var devErr error
mpagenkoc26d4c02021-05-06 14:27:57 +0000640 for _, pCommonID := range (*request).DeviceId {
mpagenko9c225032021-10-15 14:26:49 +0000641 vendorIDMatch := true
mpagenkoc26d4c02021-05-06 14:27:57 +0000642 loDeviceID := (*pCommonID).Id
mpagenko2f2f2362021-06-07 08:25:22 +0000643 loDeviceImageState := voltha.DeviceImageState{}
644 loDeviceImageState.DeviceId = loDeviceID
645 loImageState := voltha.ImageState{}
646 loDeviceImageState.ImageState = &loImageState
647 loDeviceImageState.ImageState.Version = (*request).Image.Version
mpagenko9c225032021-10-15 14:26:49 +0000648
649 onuVolthaDevice = nil
650 handler := oo.getDeviceHandler(ctx, loDeviceID, false)
651 if handler != nil {
652 onuVolthaDevice, devErr = oo.coreProxy.GetDevice(log.WithSpanFromContext(context.TODO(), ctx),
653 loDeviceID, loDeviceID)
654 } else {
655 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
656 devErr = errors.New("no handler found for device-id")
657 }
658 if devErr != nil || onuVolthaDevice == nil {
659 logger.Warnw(ctx, "Failed to fetch ONU device for image download",
660 log.Fields{"device-id": loDeviceID, "err": devErr})
661 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED
662 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //proto restriction, better option: 'INVALID_DEVICE'
mpagenkoc26d4c02021-05-06 14:27:57 +0000663 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
mpagenkoc26d4c02021-05-06 14:27:57 +0000664 } else {
mpagenko9c225032021-10-15 14:26:49 +0000665 if firstDevice {
666 //start/verify download of the image to the adapter based on first found device only
667 // use the OnuVendor identification from first given device
Holger Hildebrandt33f701d2021-12-22 10:07:58 +0000668 // note: if the request was done for a list of devices on the Voltha interface, rwCore
669 // translates that into a new rpc for each device, hence each device will be the first device in parallel requests!
mpagenko9c225032021-10-15 14:26:49 +0000670 firstDevice = false
671 vendorID = onuVolthaDevice.VendorId
672 imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU
Holger Hildebrandt33f701d2021-12-22 10:07:58 +0000673 logger.Infow(ctx, "download request for file",
674 log.Fields{"device-id": loDeviceID, "image-id": imageIdentifier})
675 // call the StartDownload synchronously to detect 'immediate' download problems
676 // the real download itself is later done in background
677 if fileState, err := oo.pFileManager.StartDownload(ctx, imageIdentifier, (*request).Image.Url); err == nil {
mpagenko9c225032021-10-15 14:26:49 +0000678 // note: If the image (with vendorId+name) has already been downloaded before from some other
Holger Hildebrandt33f701d2021-12-22 10:07:58 +0000679 // valid URL, the current download request is not executed (current code delivers URL error).
680 // If the operators want to ensure that the new URL
mpagenko9c225032021-10-15 14:26:49 +0000681 // is really used, then they first have to use the 'abort' API to remove the existing image!
682 // (abort API can be used also after some successful download to just remove the image from adapter)
Holger Hildebrandt33f701d2021-12-22 10:07:58 +0000683 if fileState == cFileStateDlSucceeded || fileState == cFileStateDlStarted {
684 downloadStartDone = true
685 } //else fileState may also indicate error situation, where the requested image is not ready to be used for other devices
mpagenko9c225032021-10-15 14:26:49 +0000686 }
687 } else {
688 //for all following devices verify the matching vendorID
689 if onuVolthaDevice.VendorId != vendorID {
690 logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored",
691 log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID})
692 vendorIDMatch = false
693 }
694 }
Holger Hildebrandt33f701d2021-12-22 10:07:58 +0000695 if downloadStartDone && vendorIDMatch {
mpagenko9c225032021-10-15 14:26:49 +0000696 // start the ONU download activity for each possible device
Holger Hildebrandt33f701d2021-12-22 10:07:58 +0000697 logger.Infow(ctx, "request image download to ONU on omci ", log.Fields{
mpagenko9c225032021-10-15 14:26:49 +0000698 "image-id": imageIdentifier, "device-id": loDeviceID})
Holger Hildebrandt33f701d2021-12-22 10:07:58 +0000699 // onu upgrade handling called in background without immediate error evaluation here
mpagenko9c225032021-10-15 14:26:49 +0000700 // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others
701 // state/progress/success of the request has to be verified using the Get_onu_image_status() API
702 go handler.onuSwUpgradeAfterDownload(ctx, request, oo.pFileManager, imageIdentifier)
703 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_STARTED
704 loDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR
705 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
706 } else {
707 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED
Holger Hildebrandt33f701d2021-12-22 10:07:58 +0000708 if !downloadStartDone {
709 // based on above fileState more descriptive error codes would be possible, e.g
710 // IMAGE_EXISTS_WITH_DIFFERENT_URL - would require proto buf update
mpagenko9c225032021-10-15 14:26:49 +0000711 loDeviceImageState.ImageState.Reason = voltha.ImageState_INVALID_URL
712 } else { //only logical option is !vendorIDMatch
713 loDeviceImageState.ImageState.Reason = voltha.ImageState_VENDOR_DEVICE_MISMATCH
714 }
715 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
716 }
mpagenkoc26d4c02021-05-06 14:27:57 +0000717 }
mpagenko2f2f2362021-06-07 08:25:22 +0000718 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState)
mpagenko9c225032021-10-15 14:26:49 +0000719 } //for all requested devices
mpagenkoc26d4c02021-05-06 14:27:57 +0000720 pImageResp := &loResponse
721 return pImageResp, nil
722 }
723 return nil, errors.New("invalid image download parameters")
mpagenko83144272021-04-27 10:06:22 +0000724}
725
726// Get_onu_image_status delivers the adapter-related information about the download/activation/commitment
727// status for the requested image
728func (oo *OpenONUAC) Get_onu_image_status(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoaa3afe92021-05-21 16:20:58 +0000729 if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
730 loResponse := voltha.DeviceImageResponse{}
mpagenkoaa3afe92021-05-21 16:20:58 +0000731 imageIdentifier := (*in).Version
mpagenko9c225032021-10-15 14:26:49 +0000732 var vendorIDSet bool
mpagenkoaa3afe92021-05-21 16:20:58 +0000733 firstDevice := true
734 var vendorID string
mpagenko9c225032021-10-15 14:26:49 +0000735 var onuVolthaDevice *voltha.Device
736 var devErr error
mpagenkoaa3afe92021-05-21 16:20:58 +0000737 for _, pCommonID := range (*in).DeviceId {
738 loDeviceID := (*pCommonID).Id
mpagenko9c225032021-10-15 14:26:49 +0000739 pDeviceImageState := &voltha.DeviceImageState{DeviceId: loDeviceID}
740 vendorIDSet = false
741 onuVolthaDevice = nil
742 handler := oo.getDeviceHandler(ctx, loDeviceID, false)
743 if handler != nil {
744 onuVolthaDevice, devErr = oo.coreProxy.GetDevice(log.WithSpanFromContext(context.TODO(), ctx),
745 loDeviceID, loDeviceID)
mpagenkoaa3afe92021-05-21 16:20:58 +0000746 } else {
mpagenko9c225032021-10-15 14:26:49 +0000747 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
748 devErr = errors.New("no handler found for device-id")
749 }
750 if devErr != nil || onuVolthaDevice == nil {
751 logger.Warnw(ctx, "Failed to fetch Onu device to get image status",
752 log.Fields{"device-id": loDeviceID, "err": devErr})
753 pImageState := &voltha.ImageState{
754 Version: (*in).Version,
755 DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //no statement about last activity possible
756 Reason: voltha.ImageState_UNKNOWN_ERROR, //something like "DEVICE_NOT_EXISTS" would be better (proto def)
757 ImageState: voltha.ImageState_IMAGE_UNKNOWN,
758 }
759 pDeviceImageState.ImageState = pImageState
760 } else {
761 if firstDevice {
762 //start/verify download of the image to the adapter based on first found device only
763 // use the OnuVendor identification from first given device
764 firstDevice = false
765 vendorID = onuVolthaDevice.VendorId
766 imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU
767 vendorIDSet = true
768 logger.Debugw(ctx, "status request for image", log.Fields{"image-id": imageIdentifier})
769 } else {
770 //for all following devices verify the matching vendorID
771 if onuVolthaDevice.VendorId != vendorID {
772 logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored",
773 log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID})
774 } else {
775 vendorIDSet = true
776 }
777 }
778 if !vendorIDSet {
779 pImageState := &voltha.ImageState{
780 Version: (*in).Version,
781 DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //can't be sure that download for this device was really tried
782 Reason: voltha.ImageState_VENDOR_DEVICE_MISMATCH,
783 ImageState: voltha.ImageState_IMAGE_UNKNOWN,
784 }
785 pDeviceImageState.ImageState = pImageState
786 } else {
787 logger.Debugw(ctx, "image status request for", log.Fields{
788 "image-id": imageIdentifier, "device-id": loDeviceID})
789 //status request is called synchronously to collect the indications for all concerned devices
790 pDeviceImageState.ImageState = handler.requestOnuSwUpgradeState(ctx, imageIdentifier, (*in).Version)
mpagenkoaa3afe92021-05-21 16:20:58 +0000791 }
792 }
mpagenkoaa3afe92021-05-21 16:20:58 +0000793 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState)
mpagenko9c225032021-10-15 14:26:49 +0000794 } //for all requested devices
mpagenkoaa3afe92021-05-21 16:20:58 +0000795 pImageResp := &loResponse
796 return pImageResp, nil
797 }
798 return nil, errors.New("invalid image status request parameters")
mpagenko83144272021-04-27 10:06:22 +0000799}
800
801// Abort_onu_image_upgrade stops the actual download/activation/commitment process (on next possibly step)
802func (oo *OpenONUAC) Abort_onu_image_upgrade(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoaa3afe92021-05-21 16:20:58 +0000803 if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
804 loResponse := voltha.DeviceImageResponse{}
805 imageIdentifier := (*in).Version
806 firstDevice := true
807 var vendorID string
mpagenko9c225032021-10-15 14:26:49 +0000808 var vendorIDSet bool
809 var onuVolthaDevice *voltha.Device
810 var devErr error
mpagenkoaa3afe92021-05-21 16:20:58 +0000811 for _, pCommonID := range (*in).DeviceId {
812 loDeviceID := (*pCommonID).Id
mpagenkoaa3afe92021-05-21 16:20:58 +0000813 pDeviceImageState := &voltha.DeviceImageState{}
mpagenko2f2f2362021-06-07 08:25:22 +0000814 loImageState := voltha.ImageState{}
815 pDeviceImageState.ImageState = &loImageState
mpagenko9c225032021-10-15 14:26:49 +0000816 vendorIDSet = false
817 onuVolthaDevice = nil
818 handler := oo.getDeviceHandler(ctx, loDeviceID, false)
819 if handler != nil {
820 onuVolthaDevice, devErr = oo.coreProxy.GetDevice(log.WithSpanFromContext(context.TODO(), ctx),
821 loDeviceID, loDeviceID)
mpagenkoaa3afe92021-05-21 16:20:58 +0000822 } else {
mpagenko9c225032021-10-15 14:26:49 +0000823 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
824 devErr = errors.New("no handler found for device-id")
mpagenkoaa3afe92021-05-21 16:20:58 +0000825 }
mpagenko9c225032021-10-15 14:26:49 +0000826 if devErr != nil || onuVolthaDevice == nil {
827 logger.Warnw(ctx, "Failed to fetch Onu device to abort its download",
828 log.Fields{"device-id": loDeviceID, "err": devErr})
mpagenkoaa3afe92021-05-21 16:20:58 +0000829 pDeviceImageState.DeviceId = loDeviceID
830 pDeviceImageState.ImageState.Version = (*in).Version
mpagenko9c225032021-10-15 14:26:49 +0000831 pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
832 pDeviceImageState.ImageState.Reason = voltha.ImageState_CANCELLED_ON_REQUEST //something better could be considered (MissingHandler) - proto
mpagenkoaa3afe92021-05-21 16:20:58 +0000833 pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
mpagenko9c225032021-10-15 14:26:49 +0000834 } else {
835 if firstDevice {
836 //start/verify download of the image to the adapter based on first found device only
837 // use the OnuVendor identification from first given device
838 firstDevice = false
839 vendorID = onuVolthaDevice.VendorId
840 vendorIDSet = true
841 imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU
842 logger.Debugw(ctx, "abort request for file", log.Fields{"image-id": imageIdentifier})
843 } else {
844 //for all following devices verify the matching vendorID
845 if onuVolthaDevice.VendorId != vendorID {
846 logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored",
847 log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID})
848 pDeviceImageState.DeviceId = loDeviceID
849 pDeviceImageState.ImageState.Version = (*in).Version
850 pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
851 pDeviceImageState.ImageState.Reason = voltha.ImageState_VENDOR_DEVICE_MISMATCH
852 pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN
853 } else {
854 vendorIDSet = true
855 }
856 }
857 if vendorIDSet {
858 // cancel the ONU upgrade activity for each possible device
859 logger.Debugw(ctx, "image upgrade abort requested", log.Fields{
860 "image-id": imageIdentifier, "device-id": loDeviceID})
861 //upgrade cancel is called synchronously to collect the imageResponse indications for all concerned devices
862 handler.cancelOnuSwUpgrade(ctx, imageIdentifier, (*in).Version, pDeviceImageState)
863 }
mpagenkoaa3afe92021-05-21 16:20:58 +0000864 }
865 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState)
mpagenko9c225032021-10-15 14:26:49 +0000866 } //for all requested devices
mpagenkoaa3afe92021-05-21 16:20:58 +0000867 if !firstDevice {
868 //if at least one valid device was found cancel also a possibly running download to adapter and remove the image
869 // this is to be done after the upgradeOnu cancel activities in order to not subduct the file for still running processes
870 oo.pFileManager.CancelDownload(ctx, imageIdentifier)
871 }
872 pImageResp := &loResponse
873 return pImageResp, nil
874 }
875 return nil, errors.New("invalid image upgrade abort parameters")
mpagenko83144272021-04-27 10:06:22 +0000876}
877
878// Get_onu_images retrieves the ONU SW image status information via OMCI
879func (oo *OpenONUAC) Get_onu_images(ctx context.Context, deviceID string) (*voltha.OnuImages, error) {
Holger Hildebrandtfb402a62021-05-26 14:40:49 +0000880 logger.Infow(ctx, "Get_onu_images", log.Fields{"device-id": deviceID})
881 if handler := oo.getDeviceHandler(ctx, deviceID, false); handler != nil {
Himani Chawla69992ab2021-07-08 15:13:02 +0530882 images, err := handler.getOnuImages(ctx)
883 if err == nil {
Holger Hildebrandtfb402a62021-05-26 14:40:49 +0000884 return images, nil
885 }
886 return nil, fmt.Errorf(fmt.Sprintf("%s-%s", err, deviceID))
887 }
888 logger.Warnw(ctx, "no handler found for Get_onu_images", log.Fields{"device-id": deviceID})
889 return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", deviceID))
mpagenko83144272021-04-27 10:06:22 +0000890}
891
892// Activate_onu_image initiates the activation of the image for the requested ONU(s)
mpagenkoc26d4c02021-05-06 14:27:57 +0000893// precondition: image downloaded and not yet activated or image refers to current inactive image
mpagenko83144272021-04-27 10:06:22 +0000894func (oo *OpenONUAC) Activate_onu_image(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoc26d4c02021-05-06 14:27:57 +0000895 if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
896 loResponse := voltha.DeviceImageResponse{}
897 imageIdentifier := (*in).Version
898 //let the deviceHandler find the adequate way of requesting the image activation
899 for _, pCommonID := range (*in).DeviceId {
900 loDeviceID := (*pCommonID).Id
mpagenko2f2f2362021-06-07 08:25:22 +0000901 loDeviceImageState := voltha.DeviceImageState{}
902 loDeviceImageState.DeviceId = loDeviceID
903 loImageState := voltha.ImageState{}
904 loDeviceImageState.ImageState = &loImageState
905 loDeviceImageState.ImageState.Version = imageIdentifier
mpagenkoc26d4c02021-05-06 14:27:57 +0000906 //compared to download procedure the vendorID (from device) is secondary here
907 // and only needed in case the upgrade process is based on some ongoing download process (and can be retrieved in deviceHandler if needed)
908 // start image activation activity for each possible device
909 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
910 if handler := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil {
911 logger.Debugw(ctx, "onu image activation requested", log.Fields{
912 "image-id": imageIdentifier, "device-id": loDeviceID})
913 //onu activation handling called in background without immediate error evaluation here
914 // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others
915 // state/progress/success of the request has to be verified using the Get_onu_image_status() API
mpagenko183647c2021-06-08 15:25:04 +0000916 if pImageStates, err := handler.onuSwActivateRequest(ctx, imageIdentifier, (*in).CommitOnSuccess); err != nil {
917 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
918 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR
919 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED
920 } else {
921 loDeviceImageState.ImageState.DownloadState = pImageStates.DownloadState
922 loDeviceImageState.ImageState.Reason = pImageStates.Reason
923 loDeviceImageState.ImageState.ImageState = pImageStates.ImageState
924 }
mpagenkoc26d4c02021-05-06 14:27:57 +0000925 } else {
926 //cannot start SW activation for requested device
927 logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": loDeviceID})
mpagenko183647c2021-06-08 15:25:04 +0000928 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
mpagenkoc26d4c02021-05-06 14:27:57 +0000929 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR
930 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED
mpagenkoc26d4c02021-05-06 14:27:57 +0000931 }
mpagenko2f2f2362021-06-07 08:25:22 +0000932 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState)
mpagenkoc26d4c02021-05-06 14:27:57 +0000933 }
934 pImageResp := &loResponse
935 return pImageResp, nil
936 }
937 return nil, errors.New("invalid image activation parameters")
mpagenko83144272021-04-27 10:06:22 +0000938}
939
940// Commit_onu_image enforces the commitment of the image for the requested ONU(s)
941// precondition: image activated and not yet committed
942func (oo *OpenONUAC) Commit_onu_image(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) {
mpagenkoc26d4c02021-05-06 14:27:57 +0000943 if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" {
944 loResponse := voltha.DeviceImageResponse{}
945 imageIdentifier := (*in).Version
946 //let the deviceHandler find the adequate way of requesting the image activation
947 for _, pCommonID := range (*in).DeviceId {
948 loDeviceID := (*pCommonID).Id
mpagenko2f2f2362021-06-07 08:25:22 +0000949 loDeviceImageState := voltha.DeviceImageState{}
950 loDeviceImageState.DeviceId = loDeviceID
951 loImageState := voltha.ImageState{}
952 loDeviceImageState.ImageState = &loImageState
953 loDeviceImageState.ImageState.Version = imageIdentifier
mpagenkoc26d4c02021-05-06 14:27:57 +0000954 //compared to download procedure the vendorID (from device) is secondary here
955 // and only needed in case the upgrade process is based on some ongoing download process (and can be retrieved in deviceHandler if needed)
956 // start image activation activity for each possible device
957 // assumption here is, that the concerned device was already created (automatic start after device creation not supported)
958 if handler := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil {
959 logger.Debugw(ctx, "onu image commitment requested", log.Fields{
960 "image-id": imageIdentifier, "device-id": loDeviceID})
961 //onu commitment handling called in background without immediate error evaluation here
962 // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others
963 // state/progress/success of the request has to be verified using the Get_onu_image_status() API
mpagenko183647c2021-06-08 15:25:04 +0000964 if pImageStates, err := handler.onuSwCommitRequest(ctx, imageIdentifier); err != nil {
965 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
966 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR
967 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED
968 } else {
969 loDeviceImageState.ImageState.DownloadState = pImageStates.DownloadState
970 loDeviceImageState.ImageState.Reason = pImageStates.Reason
971 loDeviceImageState.ImageState.ImageState = pImageStates.ImageState
972 }
mpagenkoc26d4c02021-05-06 14:27:57 +0000973 } else {
974 //cannot start SW commitment for requested device
975 logger.Warnw(ctx, "no handler found for image commitment", log.Fields{"device-id": loDeviceID})
mpagenko183647c2021-06-08 15:25:04 +0000976 loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
mpagenkoc26d4c02021-05-06 14:27:57 +0000977 loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR
978 loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED
mpagenkoc26d4c02021-05-06 14:27:57 +0000979 }
mpagenko2f2f2362021-06-07 08:25:22 +0000980 loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState)
mpagenkoc26d4c02021-05-06 14:27:57 +0000981 }
982 pImageResp := &loResponse
983 return pImageResp, nil
984 }
985 return nil, errors.New("invalid image commitment parameters")
mpagenko83144272021-04-27 10:06:22 +0000986}
987
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000988// Adapter interface required methods ################ end #########
989// #################################################################