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