blob: e129c6f470777d39a5309cc96326a855c696f55b [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
dbainbri4d3a0dc2020-12-02 00:33:42 +000027 conf "github.com/opencord/voltha-lib-go/v4/pkg/config"
28
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +000029 "github.com/golang/protobuf/ptypes"
dbainbri4d3a0dc2020-12-02 00:33:42 +000030 "github.com/opencord/voltha-lib-go/v4/pkg/adapters/adapterif"
31 "github.com/opencord/voltha-lib-go/v4/pkg/db/kvstore"
Himani Chawlac07fda02020-12-09 16:21:21 +053032 "github.com/opencord/voltha-lib-go/v4/pkg/events/eventif"
dbainbri4d3a0dc2020-12-02 00:33:42 +000033 "github.com/opencord/voltha-lib-go/v4/pkg/kafka"
34 "github.com/opencord/voltha-lib-go/v4/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
Girish Gowdraaf0ad632021-01-27 13:00:01 -080071 metricsEnabled bool
Holger Hildebrandte3677f12021-02-05 14:50:56 +000072 mibAuditInterval time.Duration
Holger Hildebrandtfa074992020-03-27 15:42:06 +000073}
74
75//NewOpenONUAC returns a new instance of OpenONU_AC
76func NewOpenONUAC(ctx context.Context, kafkaICProxy kafka.InterContainerProxy,
77 coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy,
Himani Chawlac07fda02020-12-09 16:21:21 +053078 eventProxy eventif.EventProxy, kvClient kvstore.Client, cfg *config.AdapterFlags, cm *conf.ConfigManager) *OpenONUAC {
Holger Hildebrandtfa074992020-03-27 15:42:06 +000079 var openOnuAc OpenONUAC
80 openOnuAc.exitChannel = make(chan int, 1)
Himani Chawla6d2ae152020-09-02 13:11:20 +053081 openOnuAc.deviceHandlers = make(map[string]*deviceHandler)
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +000082 openOnuAc.deviceHandlersCreateChan = make(map[string]chan bool)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +000083 openOnuAc.lockDeviceHandlersMap = sync.RWMutex{}
Holger Hildebrandtfa074992020-03-27 15:42:06 +000084 openOnuAc.kafkaICProxy = kafkaICProxy
85 openOnuAc.config = cfg
Matteo Scandolof1f39a72020-11-24 12:08:11 -080086 openOnuAc.cm = cm
Holger Hildebrandtfa074992020-03-27 15:42:06 +000087 openOnuAc.numOnus = cfg.OnuNumber
88 openOnuAc.coreProxy = coreProxy
89 openOnuAc.adapterProxy = adapterProxy
90 openOnuAc.eventProxy = eventProxy
mpagenkoaf801632020-07-03 10:00:42 +000091 openOnuAc.kvClient = kvClient
Matteo Scandolo127c59d2021-01-28 11:31:18 -080092 openOnuAc.KVStoreAddress = cfg.KVStoreAddress
Holger Hildebrandtfa074992020-03-27 15:42:06 +000093 openOnuAc.KVStoreType = cfg.KVStoreType
mpagenkoaf801632020-07-03 10:00:42 +000094 openOnuAc.KVStoreTimeout = cfg.KVStoreTimeout
Holger Hildebrandt61b24d02020-11-16 13:36:40 +000095 openOnuAc.mibTemplatesGenerated = make(map[string]bool)
96 openOnuAc.lockMibTemplateGenerated = sync.RWMutex{}
Holger Hildebrandtfa074992020-03-27 15:42:06 +000097 openOnuAc.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval
98 openOnuAc.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval
mpagenkodff5dda2020-08-28 11:52:01 +000099 openOnuAc.AcceptIncrementalEvto = cfg.AccIncrEvto
Himani Chawlad96df182020-09-28 11:12:02 +0530100 openOnuAc.maxTimeoutInterAdapterComm = cfg.MaxTimeoutInterAdapterComm
Holger Hildebrandt38985dc2021-02-18 16:25:20 +0000101 openOnuAc.maxTimeoutReconciling = cfg.MaxTimeoutReconciling
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000102 //openOnuAc.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval
Girish Gowdraaf0ad632021-01-27 13:00:01 -0800103 openOnuAc.metricsEnabled = cfg.MetricsEnabled
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000104 openOnuAc.mibAuditInterval = cfg.MibAuditInterval
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000105
106 openOnuAc.pSupportedFsms = &OmciDeviceFsms{
107 "mib-synchronizer": {
108 //mibSyncFsm, // Implements the MIB synchronization state machine
Himani Chawla6d2ae152020-09-02 13:11:20 +0530109 mibDbVolatileDictImpl, // Implements volatile ME MIB database
Himani Chawla4d908332020-08-31 12:30:20 +0530110 //true, // Advertise events on OpenOMCI event bus
Holger Hildebrandte3677f12021-02-05 14:50:56 +0000111 openOnuAc.mibAuditInterval, // Time to wait between MIB audits. 0 to disable audits.
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000112 // map[string]func() error{
113 // "mib-upload": onuDeviceEntry.MibUploadTask,
114 // "mib-template": onuDeviceEntry.MibTemplateTask,
115 // "get-mds": onuDeviceEntry.GetMdsTask,
116 // "mib-audit": onuDeviceEntry.GetMdsTask,
117 // "mib-resync": onuDeviceEntry.MibResyncTask,
118 // "mib-reconcile": onuDeviceEntry.MibReconcileTask,
119 // },
120 },
121 }
122
mpagenkoc8bba412021-01-15 15:38:44 +0000123 openOnuAc.pDownloadManager = newAdapterDownloadManager(ctx)
124
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000125 return &openOnuAc
126}
127
128//Start starts (logs) the adapter
129func (oo *OpenONUAC) Start(ctx context.Context) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000130 logger.Info(ctx, "starting-openonu-adapter")
mpagenkoc8bba412021-01-15 15:38:44 +0000131
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000132 return nil
133}
134
Himani Chawla6d2ae152020-09-02 13:11:20 +0530135/*
136//stop terminates the session
137func (oo *OpenONUAC) stop(ctx context.Context) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000138 logger.Info(ctx,"stopping-device-manager")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000139 oo.exitChannel <- 1
dbainbri4d3a0dc2020-12-02 00:33:42 +0000140 logger.Info(ctx,"device-manager-stopped")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000141 return nil
142}
Himani Chawla6d2ae152020-09-02 13:11:20 +0530143*/
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000144
Himani Chawla6d2ae152020-09-02 13:11:20 +0530145func (oo *OpenONUAC) addDeviceHandlerToMap(ctx context.Context, agent *deviceHandler) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000146 oo.lockDeviceHandlersMap.Lock()
147 defer oo.lockDeviceHandlersMap.Unlock()
148 if _, exist := oo.deviceHandlers[agent.deviceID]; !exist {
149 oo.deviceHandlers[agent.deviceID] = agent
Himani Chawla6d2ae152020-09-02 13:11:20 +0530150 oo.deviceHandlers[agent.deviceID].start(ctx)
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000151 if _, exist := oo.deviceHandlersCreateChan[agent.deviceID]; exist {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000152 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 +0000153 oo.deviceHandlersCreateChan[agent.deviceID] <- true
154 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000155 }
156}
157
Himani Chawla6d2ae152020-09-02 13:11:20 +0530158func (oo *OpenONUAC) deleteDeviceHandlerToMap(agent *deviceHandler) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000159 oo.lockDeviceHandlersMap.Lock()
160 defer oo.lockDeviceHandlersMap.Unlock()
161 delete(oo.deviceHandlers, agent.deviceID)
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000162 delete(oo.deviceHandlersCreateChan, agent.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000163}
164
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000165//getDeviceHandler gets the ONU deviceHandler and may wait until it is created
dbainbri4d3a0dc2020-12-02 00:33:42 +0000166func (oo *OpenONUAC) getDeviceHandler(ctx context.Context, deviceID string, aWait bool) *deviceHandler {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000167 oo.lockDeviceHandlersMap.Lock()
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000168 agent, ok := oo.deviceHandlers[deviceID]
169 if aWait && !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000170 logger.Infow(ctx, "Race condition: deviceHandler not present - wait for creation or timeout",
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000171 log.Fields{"device-id": deviceID})
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000172 if _, exist := oo.deviceHandlersCreateChan[deviceID]; !exist {
173 oo.deviceHandlersCreateChan[deviceID] = make(chan bool, 1)
174 }
Girish Gowdra7407a4d2020-11-12 12:44:53 -0800175 deviceCreateChan := oo.deviceHandlersCreateChan[deviceID]
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000176 //keep the read sema short to allow for subsequent write
177 oo.lockDeviceHandlersMap.Unlock()
178 // based on concurrent processing the deviceHandler creation may not yet be finished at his point
179 // so it might be needed to wait here for that event with some timeout
180 select {
181 case <-time.After(1 * time.Second): //timer may be discussed ...
dbainbri4d3a0dc2020-12-02 00:33:42 +0000182 logger.Warnw(ctx, "No valid deviceHandler created after max WaitTime", log.Fields{"device-id": deviceID})
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000183 return nil
Girish Gowdra7407a4d2020-11-12 12:44:53 -0800184 case <-deviceCreateChan:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000185 logger.Debugw(ctx, "deviceHandler is ready now - continue", log.Fields{"device-id": deviceID})
Girish Gowdra7407a4d2020-11-12 12:44:53 -0800186 oo.lockDeviceHandlersMap.RLock()
187 defer oo.lockDeviceHandlersMap.RUnlock()
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000188 return oo.deviceHandlers[deviceID]
189 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000190 }
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000191 oo.lockDeviceHandlersMap.Unlock()
192 return agent
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000193}
194
dbainbri4d3a0dc2020-12-02 00:33:42 +0000195func (oo *OpenONUAC) processInterAdapterONUIndReqMessage(ctx context.Context, msg *ic.InterAdapterMessage) error {
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000196 msgBody := msg.GetBody()
197 onuIndication := &oop.OnuIndication{}
198 if err := ptypes.UnmarshalAny(msgBody, onuIndication); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000199 logger.Warnw(ctx, "onu-ind-request-cannot-unmarshal-msg-body", log.Fields{"error": err})
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000200 return err
201 }
202 //ToDeviceId should address a DeviceHandler instance
203 targetDevice := msg.Header.ToDeviceId
204
205 onuOperstate := onuIndication.GetOperState()
206 waitForDhInstPresent := false
207 if onuOperstate == "up" {
208 //Race condition (relevant in BBSIM-environment only): Due to unsynchronized processing of olt-adapter and rw_core,
209 //ONU_IND_REQUEST msg by olt-adapter could arrive a little bit earlier than rw_core was able to announce the corresponding
210 //ONU by RPC of Adopt_device(). Therefore it could be necessary to wait with processing of ONU_IND_REQUEST until call of
211 //Adopt_device() arrived and DeviceHandler instance was created
212 waitForDhInstPresent = true
213 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000214 if handler := oo.getDeviceHandler(ctx, targetDevice, waitForDhInstPresent); handler != nil {
215 logger.Infow(ctx, "onu-ind-request", log.Fields{"device-id": targetDevice,
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000216 "OnuId": onuIndication.GetOnuId(),
217 "AdminState": onuIndication.GetAdminState(), "OperState": onuOperstate,
218 "SNR": onuIndication.GetSerialNumber()})
219
220 if onuOperstate == "up" {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000221 return handler.createInterface(ctx, onuIndication)
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000222 } else if (onuOperstate == "down") || (onuOperstate == "unreachable") {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000223 return handler.updateInterface(ctx, onuIndication)
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000224 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000225 logger.Errorw(ctx, "unknown-onu-ind-request operState", log.Fields{"OnuId": onuIndication.GetOnuId()})
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000226 return fmt.Errorf("invalidOperState: %s, %s", onuOperstate, targetDevice)
227 }
228 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000229 logger.Warnw(ctx, "no handler found for received onu-ind-request", log.Fields{
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000230 "msgToDeviceId": targetDevice})
231 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", targetDevice))
232}
233
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000234// Adapter interface required methods ############## begin #########
235// #################################################################
236
237// for original content compare: (needs according deviceHandler methods)
238// /voltha-openolt-adapter/adaptercore/openolt.go
239
240// Adopt_device creates a new device handler if not present already and then adopts the device
dbainbri4d3a0dc2020-12-02 00:33:42 +0000241func (oo *OpenONUAC) Adopt_device(ctx context.Context, device *voltha.Device) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000242 if device == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000243 logger.Warn(ctx, "voltha-device-is-nil")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000244 return errors.New("nil-device")
245 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000246 logger.Infow(ctx, "adopt-device", log.Fields{"device-id": device.Id})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530247 var handler *deviceHandler
dbainbri4d3a0dc2020-12-02 00:33:42 +0000248 if handler = oo.getDeviceHandler(ctx, device.Id, false); handler == nil {
249 handler := newDeviceHandler(ctx, oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000250 oo.addDeviceHandlerToMap(ctx, handler)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530251 go handler.adoptOrReconcileDevice(ctx, device)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000252 // Launch the creation of the device topic
253 // go oo.createDeviceTopic(device)
254 }
255 return nil
256}
257
258//Get_ofp_device_info returns OFP information for the given device
dbainbri4d3a0dc2020-12-02 00:33:42 +0000259func (oo *OpenONUAC) Get_ofp_device_info(ctx context.Context, device *voltha.Device) (*ic.SwitchCapability, error) {
260 logger.Errorw(ctx, "device-handler-not-set", log.Fields{"device-id": device.Id})
Andrea Campanella6515c582020-10-05 11:25:00 +0200261 return nil, fmt.Errorf("device-handler-not-set %s", device.Id)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000262}
263
264//Get_ofp_port_info returns OFP port information for the given device
mpagenkoaf801632020-07-03 10:00:42 +0000265//200630: method removed as per [VOL-3202]: OF port info is now to be delivered within UniPort create
266// cmp changes in onu_uni_port.go::CreateVolthaPort()
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000267
268//Process_inter_adapter_message sends messages to a target device (between adapters)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000269func (oo *OpenONUAC) Process_inter_adapter_message(ctx context.Context, msg *ic.InterAdapterMessage) error {
270 logger.Debugw(ctx, "Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id,
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000271 "msgProxyDeviceId": msg.Header.ProxyDeviceId, "msgToDeviceId": msg.Header.ToDeviceId, "Type": msg.Header.Type})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000272
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000273 if msg.Header.Type == ic.InterAdapterMessageType_ONU_IND_REQUEST {
274 // we have to handle ONU_IND_REQUEST already here - see comments in processInterAdapterONUIndReqMessage()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000275 return oo.processInterAdapterONUIndReqMessage(ctx, msg)
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000276 }
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000277 //ToDeviceId should address a DeviceHandler instance
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000278 targetDevice := msg.Header.ToDeviceId
dbainbri4d3a0dc2020-12-02 00:33:42 +0000279 if handler := oo.getDeviceHandler(ctx, targetDevice, false); handler != nil {
mpagenko1cc3cb42020-07-27 15:24:38 +0000280 /* 200724: modification towards synchronous implementation - possible errors within processing shall be
281 * in the accordingly delayed response, some timing effect might result in Techprofile processing for multiple UNI's
282 */
dbainbri4d3a0dc2020-12-02 00:33:42 +0000283 return handler.processInterAdapterMessage(ctx, msg)
mpagenko1cc3cb42020-07-27 15:24:38 +0000284 /* so far the processing has been in background with according commented error treatment restrictions:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000285 go handler.ProcessInterAdapterMessage(msg)
286 // error treatment might be more sophisticated
287 // by now let's just accept the message on 'communication layer'
288 // message content problems have to be evaluated then in the handler
289 // and are by now not reported to the calling party (to force what reaction there?)
290 return nil
mpagenko1cc3cb42020-07-27 15:24:38 +0000291 */
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000292 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000293 logger.Warnw(ctx, "no handler found for received Inter-Proxy-message", log.Fields{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000294 "msgToDeviceId": targetDevice})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000295 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", targetDevice))
296}
297
298//Adapter_descriptor not implemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000299func (oo *OpenONUAC) Adapter_descriptor(ctx context.Context) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000300 return errors.New("unImplemented")
301}
302
303//Device_types unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000304func (oo *OpenONUAC) Device_types(ctx context.Context) (*voltha.DeviceTypes, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000305 return nil, errors.New("unImplemented")
306}
307
308//Health returns unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000309func (oo *OpenONUAC) Health(ctx context.Context) (*voltha.HealthStatus, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000310 return nil, errors.New("unImplemented")
311}
312
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000313//Reconcile_device is called once when the adapter needs to re-create device - usually on core restart
dbainbri4d3a0dc2020-12-02 00:33:42 +0000314func (oo *OpenONUAC) Reconcile_device(ctx context.Context, device *voltha.Device) error {
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000315 if device == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000316 logger.Warn(ctx, "reconcile-device-voltha-device-is-nil")
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000317 return errors.New("nil-device")
318 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000319 logger.Infow(ctx, "reconcile-device", log.Fields{"device-id": device.Id})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530320 var handler *deviceHandler
dbainbri4d3a0dc2020-12-02 00:33:42 +0000321 if handler = oo.getDeviceHandler(ctx, device.Id, false); handler == nil {
322 handler := newDeviceHandler(ctx, oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000323 oo.addDeviceHandlerToMap(ctx, handler)
324 handler.device = device
Holger Hildebrandtf37b3d72021-02-17 10:25:22 +0000325 handler.startReconciling(ctx)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530326 go handler.adoptOrReconcileDevice(ctx, handler.device)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000327 // reconcilement will be continued after onu-device entry is added
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000328 } else {
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000329 return fmt.Errorf(fmt.Sprintf("device-already-reconciled-or-active-%s", device.Id))
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000330 }
331 return nil
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000332}
333
334//Abandon_device unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000335func (oo *OpenONUAC) Abandon_device(ctx context.Context, device *voltha.Device) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000336 return errors.New("unImplemented")
337}
338
339//Disable_device disables the given device
dbainbri4d3a0dc2020-12-02 00:33:42 +0000340func (oo *OpenONUAC) Disable_device(ctx context.Context, device *voltha.Device) error {
341 logger.Infow(ctx, "disable-device", log.Fields{"device-id": device.Id})
342 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
343 go handler.disableDevice(ctx, device)
ozgecanetsiafce57b12020-05-25 14:39:35 +0300344 return nil
345 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000346 logger.Warnw(ctx, "no handler found for device-disable", log.Fields{"device-id": device.Id})
ozgecanetsiafce57b12020-05-25 14:39:35 +0300347 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000348}
349
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000350//Reenable_device enables the onu device after disable
dbainbri4d3a0dc2020-12-02 00:33:42 +0000351func (oo *OpenONUAC) Reenable_device(ctx context.Context, device *voltha.Device) error {
352 logger.Infow(ctx, "reenable-device", log.Fields{"device-id": device.Id})
353 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
354 go handler.reEnableDevice(ctx, device)
ozgecanetsiafce57b12020-05-25 14:39:35 +0300355 return nil
356 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000357 logger.Warnw(ctx, "no handler found for device-reenable", log.Fields{"device-id": device.Id})
ozgecanetsiafce57b12020-05-25 14:39:35 +0300358 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000359}
360
361//Reboot_device reboots the given device
dbainbri4d3a0dc2020-12-02 00:33:42 +0000362func (oo *OpenONUAC) Reboot_device(ctx context.Context, device *voltha.Device) error {
363 logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id})
364 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
365 go handler.rebootDevice(ctx, device)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300366 return nil
367 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000368 logger.Warnw(ctx, "no handler found for device-reboot", log.Fields{"device-id": device.Id})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300369 return fmt.Errorf(fmt.Sprintf("handler-not-found-#{device.Id}"))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000370}
371
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000372//Self_test_device unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000373func (oo *OpenONUAC) Self_test_device(ctx context.Context, device *voltha.Device) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000374 return errors.New("unImplemented")
375}
376
Himani Chawla6d2ae152020-09-02 13:11:20 +0530377// Delete_device deletes the given device
dbainbri4d3a0dc2020-12-02 00:33:42 +0000378func (oo *OpenONUAC) Delete_device(ctx context.Context, device *voltha.Device) error {
379 logger.Infow(ctx, "delete-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber})
380 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
381 err := handler.deleteDevicePersistencyData(ctx)
Girish Gowdrae0140f02021-02-02 16:55:09 -0800382 handler.stopCollector <- true // stop the metric collector routine
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000383 //don't leave any garbage - even in error case
384 oo.deleteDeviceHandlerToMap(handler)
mpagenko2418ab02020-11-12 12:58:06 +0000385 return err
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000386 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000387 logger.Warnw(ctx, "no handler found for device-deletion", log.Fields{"device-id": device.Id})
mpagenko2418ab02020-11-12 12:58:06 +0000388 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000389}
390
391//Get_device_details unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000392func (oo *OpenONUAC) Get_device_details(ctx context.Context, device *voltha.Device) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000393 return errors.New("unImplemented")
394}
395
396//Update_flows_bulk returns
dbainbri4d3a0dc2020-12-02 00:33:42 +0000397func (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 +0000398 return errors.New("unImplemented")
399}
400
401//Update_flows_incrementally updates (add/remove) the flows on a given device
dbainbri4d3a0dc2020-12-02 00:33:42 +0000402func (oo *OpenONUAC) Update_flows_incrementally(ctx context.Context, device *voltha.Device,
mpagenkodff5dda2020-08-28 11:52:01 +0000403 flows *openflow_13.FlowChanges, groups *openflow_13.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error {
mpagenkofc4f56e2020-11-04 17:17:49 +0000404
dbainbri4d3a0dc2020-12-02 00:33:42 +0000405 logger.Infow(ctx, "update-flows-incrementally", log.Fields{"device-id": device.Id})
mpagenkofc4f56e2020-11-04 17:17:49 +0000406 //flow config is relayed to handler even if the device might be in some 'inactive' state
407 // let the handler or related FSM's decide, what to do with the modified flow state info
408 // 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 +0000409
410 // For now, there is no support for group changes (as in the actual Py-adapter code)
mpagenkofc4f56e2020-11-04 17:17:49 +0000411 // but processing is continued for flowUpdate possibly also set in the request
mpagenkodff5dda2020-08-28 11:52:01 +0000412 if groups.ToAdd != nil && groups.ToAdd.Items != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000413 logger.Warnw(ctx, "Update-flow-incr: group add not supported (ignored)", log.Fields{"device-id": device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000414 }
415 if groups.ToRemove != nil && groups.ToRemove.Items != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000416 logger.Warnw(ctx, "Update-flow-incr: group remove not supported (ignored)", log.Fields{"device-id": device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000417 }
418 if groups.ToUpdate != nil && groups.ToUpdate.Items != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000419 logger.Warnw(ctx, "Update-flow-incr: group update not supported (ignored)", log.Fields{"device-id": device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000420 }
421
dbainbri4d3a0dc2020-12-02 00:33:42 +0000422 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
423 err := handler.FlowUpdateIncremental(ctx, flows, groups, flowMetadata)
mpagenkodff5dda2020-08-28 11:52:01 +0000424 return err
425 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000426 logger.Warnw(ctx, "no handler found for incremental flow update", log.Fields{"device-id": device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000427 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000428}
429
430//Update_pm_config returns PmConfigs nil or error
dbainbri4d3a0dc2020-12-02 00:33:42 +0000431func (oo *OpenONUAC) Update_pm_config(ctx context.Context, device *voltha.Device, pmConfigs *voltha.PmConfigs) error {
Girish Gowdrae09a6202021-01-12 18:10:59 -0800432 logger.Infow(ctx, "update-pm-config", log.Fields{"device-id": device.Id})
433 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
Girish Gowdra5a7c4922021-01-22 18:33:41 -0800434 return handler.updatePmConfig(ctx, pmConfigs)
Girish Gowdrae09a6202021-01-12 18:10:59 -0800435 }
Girish Gowdra5a7c4922021-01-22 18:33:41 -0800436 logger.Warnw(ctx, "no handler found for update-pm-config", log.Fields{"device-id": device.Id})
437 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000438}
439
440//Receive_packet_out sends packet out to the device
dbainbri4d3a0dc2020-12-02 00:33:42 +0000441func (oo *OpenONUAC) Receive_packet_out(ctx context.Context, deviceID string, egressPortNo int, packet *openflow_13.OfpPacketOut) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000442 return errors.New("unImplemented")
443}
444
445//Suppress_event unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000446func (oo *OpenONUAC) Suppress_event(ctx context.Context, filter *voltha.EventFilter) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000447 return errors.New("unImplemented")
448}
449
450//Unsuppress_event unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000451func (oo *OpenONUAC) Unsuppress_event(ctx context.Context, filter *voltha.EventFilter) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000452 return errors.New("unImplemented")
453}
454
Andrea Campanella71e546a2021-02-26 11:09:33 +0100455//Download_image requests downloading some image according to indications as given in request
456//The ImageDownload needs to be called `request`due to library reflection requirements
457func (oo *OpenONUAC) Download_image(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
458 if !oo.pDownloadManager.imageExists(ctx, request) {
459 logger.Debugw(ctx, "start image download", log.Fields{"image-description": request})
mpagenkoc8bba412021-01-15 15:38:44 +0000460 // Download_image is not supposed to be blocking, anyway let's call the DownloadManager still synchronously to detect 'fast' problems
461 // the download itself is later done in background
Andrea Campanella71e546a2021-02-26 11:09:33 +0100462 err := oo.pDownloadManager.startDownload(ctx, request)
463 return request, err
mpagenkoc8bba412021-01-15 15:38:44 +0000464 }
465 // image already exists
Andrea Campanella71e546a2021-02-26 11:09:33 +0100466 logger.Debugw(ctx, "image already downloaded", log.Fields{"image-description": request})
467 return request, nil
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000468}
469
470//Get_image_download_status unimplemented
Andrea Campanella71e546a2021-02-26 11:09:33 +0100471//The ImageDownload needs to be called `request`due to library reflection requirements
dbainbri4d3a0dc2020-12-02 00:33:42 +0000472func (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 +0000473 return nil, errors.New("unImplemented")
474}
475
476//Cancel_image_download unimplemented
Andrea Campanella71e546a2021-02-26 11:09:33 +0100477//The ImageDownload needs to be called `request`due to library reflection requirements
dbainbri4d3a0dc2020-12-02 00:33:42 +0000478func (oo *OpenONUAC) Cancel_image_download(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000479 return nil, errors.New("unImplemented")
480}
481
mpagenko057889c2021-01-21 16:51:58 +0000482//Activate_image_update requests downloading some Onu Software image to the INU via OMCI
Andrea Campanella71e546a2021-02-26 11:09:33 +0100483// according to indications as given in request and on success activate the image on the ONU
484//The ImageDownload needs to be called `request`due to library reflection requirements
485func (oo *OpenONUAC) Activate_image_update(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
486 if oo.pDownloadManager.imageLocallyDownloaded(ctx, request) {
mpagenko057889c2021-01-21 16:51:58 +0000487 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
488 logger.Debugw(ctx, "image download on omci requested", log.Fields{
Andrea Campanella71e546a2021-02-26 11:09:33 +0100489 "image-description": request, "device-id": device.Id})
490 err := handler.doOnuSwUpgrade(ctx, request, oo.pDownloadManager)
491 return request, err
mpagenko057889c2021-01-21 16:51:58 +0000492 }
493 logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": device.Id})
Andrea Campanella71e546a2021-02-26 11:09:33 +0100494 return request, fmt.Errorf(fmt.Sprintf("handler-not-found - device-id: %s", device.Id))
mpagenkoc8bba412021-01-15 15:38:44 +0000495 }
Andrea Campanella71e546a2021-02-26 11:09:33 +0100496 logger.Debugw(ctx, "image not yet downloaded on activate request", log.Fields{"image-description": request})
497 return request, fmt.Errorf(fmt.Sprintf("image-not-yet-downloaded - device-id: %s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000498}
499
500//Revert_image_update unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000501func (oo *OpenONUAC) Revert_image_update(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000502 return nil, errors.New("unImplemented")
503}
504
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000505// Enable_port to Enable PON/NNI interface - seems not to be used/required according to python code
dbainbri4d3a0dc2020-12-02 00:33:42 +0000506func (oo *OpenONUAC) Enable_port(ctx context.Context, deviceID string, port *voltha.Port) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000507 return errors.New("unImplemented")
508}
509
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000510// Disable_port to Disable pon/nni interface - seems not to be used/required according to python code
dbainbri4d3a0dc2020-12-02 00:33:42 +0000511func (oo *OpenONUAC) Disable_port(ctx context.Context, deviceID string, port *voltha.Port) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000512 return errors.New("unImplemented")
513}
514
Himani Chawla6d2ae152020-09-02 13:11:20 +0530515//Child_device_lost - unimplemented
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000516//needed for if update >= 3.1.x
dbainbri4d3a0dc2020-12-02 00:33:42 +0000517func (oo *OpenONUAC) Child_device_lost(ctx context.Context, deviceID string, pPortNo uint32, onuID uint32) error {
Matteo Scandolo2e6f1e32020-04-15 11:28:45 -0700518 return errors.New("unImplemented")
519}
520
Himani Chawla6d2ae152020-09-02 13:11:20 +0530521// Start_omci_test unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000522func (oo *OpenONUAC) Start_omci_test(ctx context.Context, device *voltha.Device, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) {
Matteo Scandolo2e6f1e32020-04-15 11:28:45 -0700523 return nil, errors.New("unImplemented")
524}
525
Himani Chawla6d2ae152020-09-02 13:11:20 +0530526// Get_ext_value - unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000527func (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 -0700528 return nil, errors.New("unImplemented")
529}
530
kesavandfdf77632021-01-26 23:40:33 -0500531//Single_get_value_request handles the core request to retrieve uni status
mpagenkoc8bba412021-01-15 15:38:44 +0000532func (oo *OpenONUAC) Single_get_value_request(ctx context.Context, request extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) {
kesavandfdf77632021-01-26 23:40:33 -0500533 logger.Infow(ctx, "Single_get_value_request", log.Fields{"request": request})
534
535 if handler := oo.getDeviceHandler(ctx, request.TargetId, false); handler != nil {
536 switch reqType := request.GetRequest().GetRequest().(type) {
537 case *extension.GetValueRequest_UniInfo:
538 return handler.getUniPortStatus(ctx, reqType.UniInfo), nil
539 default:
540 return postUniStatusErrResponse(extension.GetValueResponse_UNSUPPORTED), nil
541
542 }
543 }
544 logger.Errorw(ctx, "Single_get_value_request failed ", log.Fields{"request": request})
545 return postUniStatusErrResponse(extension.GetValueResponse_INVALID_DEVICE_ID), nil
mpagenkoc8bba412021-01-15 15:38:44 +0000546}
547
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000548// Adapter interface required methods ################ end #########
549// #################################################################