blob: 16ef7d74c77ef3f4842ec1c960a3ee313eff7f03 [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"
Matteo Scandolof1f39a72020-11-24 12:08:11 -080024 conf "github.com/opencord/voltha-lib-go/v3/pkg/config"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000025 "sync"
26 "time"
27
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +000028 "github.com/golang/protobuf/ptypes"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000029 "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif"
mpagenkoaf801632020-07-03 10:00:42 +000030 "github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000031 "github.com/opencord/voltha-lib-go/v3/pkg/kafka"
32 "github.com/opencord/voltha-lib-go/v3/pkg/log"
33 ic "github.com/opencord/voltha-protos/v3/go/inter_container"
34 "github.com/opencord/voltha-protos/v3/go/openflow_13"
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +000035 oop "github.com/opencord/voltha-protos/v3/go/openolt"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000036 "github.com/opencord/voltha-protos/v3/go/voltha"
37
Matteo Scandolo761f7512020-11-23 15:52:40 -080038 "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/config"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000039)
40
41//OpenONUAC structure holds the ONU core information
42type OpenONUAC struct {
Himani Chawla6d2ae152020-09-02 13:11:20 +053043 deviceHandlers map[string]*deviceHandler
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +000044 deviceHandlersCreateChan map[string]chan bool //channels for deviceHandler create events
Holger Hildebrandt61b24d02020-11-16 13:36:40 +000045 lockDeviceHandlersMap sync.RWMutex
Holger Hildebrandtfa074992020-03-27 15:42:06 +000046 coreProxy adapterif.CoreProxy
47 adapterProxy adapterif.AdapterProxy
48 eventProxy adapterif.EventProxy
49 kafkaICProxy kafka.InterContainerProxy
mpagenkoaf801632020-07-03 10:00:42 +000050 kvClient kvstore.Client
Matteo Scandolof1f39a72020-11-24 12:08:11 -080051 cm *conf.ConfigManager
Holger Hildebrandtfa074992020-03-27 15:42:06 +000052 config *config.AdapterFlags
53 numOnus int
54 KVStoreHost string
55 KVStorePort int
56 KVStoreType string
mpagenkoaf801632020-07-03 10:00:42 +000057 KVStoreTimeout time.Duration
Holger Hildebrandt61b24d02020-11-16 13:36:40 +000058 mibTemplatesGenerated map[string]bool
59 lockMibTemplateGenerated sync.RWMutex
Holger Hildebrandtfa074992020-03-27 15:42:06 +000060 exitChannel chan int
61 HeartbeatCheckInterval time.Duration
62 HeartbeatFailReportInterval time.Duration
mpagenkodff5dda2020-08-28 11:52:01 +000063 AcceptIncrementalEvto bool
Holger Hildebrandtfa074992020-03-27 15:42:06 +000064 //GrpcTimeoutInterval time.Duration
Himani Chawlad96df182020-09-28 11:12:02 +053065 pSupportedFsms *OmciDeviceFsms
66 maxTimeoutInterAdapterComm time.Duration
Holger Hildebrandtfa074992020-03-27 15:42:06 +000067}
68
69//NewOpenONUAC returns a new instance of OpenONU_AC
70func NewOpenONUAC(ctx context.Context, kafkaICProxy kafka.InterContainerProxy,
71 coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy,
Matteo Scandolof1f39a72020-11-24 12:08:11 -080072 eventProxy adapterif.EventProxy, kvClient kvstore.Client, cfg *config.AdapterFlags, cm *conf.ConfigManager) *OpenONUAC {
Holger Hildebrandtfa074992020-03-27 15:42:06 +000073 var openOnuAc OpenONUAC
74 openOnuAc.exitChannel = make(chan int, 1)
Himani Chawla6d2ae152020-09-02 13:11:20 +053075 openOnuAc.deviceHandlers = make(map[string]*deviceHandler)
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +000076 openOnuAc.deviceHandlersCreateChan = make(map[string]chan bool)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +000077 openOnuAc.lockDeviceHandlersMap = sync.RWMutex{}
Holger Hildebrandtfa074992020-03-27 15:42:06 +000078 openOnuAc.kafkaICProxy = kafkaICProxy
79 openOnuAc.config = cfg
Matteo Scandolof1f39a72020-11-24 12:08:11 -080080 openOnuAc.cm = cm
Holger Hildebrandtfa074992020-03-27 15:42:06 +000081 openOnuAc.numOnus = cfg.OnuNumber
82 openOnuAc.coreProxy = coreProxy
83 openOnuAc.adapterProxy = adapterProxy
84 openOnuAc.eventProxy = eventProxy
mpagenkoaf801632020-07-03 10:00:42 +000085 openOnuAc.kvClient = kvClient
Holger Hildebrandtfa074992020-03-27 15:42:06 +000086 openOnuAc.KVStoreHost = cfg.KVStoreHost
87 openOnuAc.KVStorePort = cfg.KVStorePort
88 openOnuAc.KVStoreType = cfg.KVStoreType
mpagenkoaf801632020-07-03 10:00:42 +000089 openOnuAc.KVStoreTimeout = cfg.KVStoreTimeout
Holger Hildebrandt61b24d02020-11-16 13:36:40 +000090 openOnuAc.mibTemplatesGenerated = make(map[string]bool)
91 openOnuAc.lockMibTemplateGenerated = sync.RWMutex{}
Holger Hildebrandtfa074992020-03-27 15:42:06 +000092 openOnuAc.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval
93 openOnuAc.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval
mpagenkodff5dda2020-08-28 11:52:01 +000094 openOnuAc.AcceptIncrementalEvto = cfg.AccIncrEvto
Himani Chawlad96df182020-09-28 11:12:02 +053095 openOnuAc.maxTimeoutInterAdapterComm = cfg.MaxTimeoutInterAdapterComm
Holger Hildebrandtfa074992020-03-27 15:42:06 +000096 //openOnuAc.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000097
98 openOnuAc.pSupportedFsms = &OmciDeviceFsms{
99 "mib-synchronizer": {
100 //mibSyncFsm, // Implements the MIB synchronization state machine
Himani Chawla6d2ae152020-09-02 13:11:20 +0530101 mibDbVolatileDictImpl, // Implements volatile ME MIB database
Himani Chawla4d908332020-08-31 12:30:20 +0530102 //true, // Advertise events on OpenOMCI event bus
103 cMibAuditDelayImpl, // Time to wait between MIB audits. 0 to disable audits.
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000104 // map[string]func() error{
105 // "mib-upload": onuDeviceEntry.MibUploadTask,
106 // "mib-template": onuDeviceEntry.MibTemplateTask,
107 // "get-mds": onuDeviceEntry.GetMdsTask,
108 // "mib-audit": onuDeviceEntry.GetMdsTask,
109 // "mib-resync": onuDeviceEntry.MibResyncTask,
110 // "mib-reconcile": onuDeviceEntry.MibReconcileTask,
111 // },
112 },
113 }
114
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000115 return &openOnuAc
116}
117
118//Start starts (logs) the adapter
119func (oo *OpenONUAC) Start(ctx context.Context) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000120 logger.Info("starting-openonu-adapter")
121 logger.Info("openonu-adapter-started")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000122 return nil
123}
124
Himani Chawla6d2ae152020-09-02 13:11:20 +0530125/*
126//stop terminates the session
127func (oo *OpenONUAC) stop(ctx context.Context) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000128 logger.Info("stopping-device-manager")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000129 oo.exitChannel <- 1
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000130 logger.Info("device-manager-stopped")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000131 return nil
132}
Himani Chawla6d2ae152020-09-02 13:11:20 +0530133*/
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000134
Himani Chawla6d2ae152020-09-02 13:11:20 +0530135func (oo *OpenONUAC) addDeviceHandlerToMap(ctx context.Context, agent *deviceHandler) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000136 oo.lockDeviceHandlersMap.Lock()
137 defer oo.lockDeviceHandlersMap.Unlock()
138 if _, exist := oo.deviceHandlers[agent.deviceID]; !exist {
139 oo.deviceHandlers[agent.deviceID] = agent
Himani Chawla6d2ae152020-09-02 13:11:20 +0530140 oo.deviceHandlers[agent.deviceID].start(ctx)
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000141 if _, exist := oo.deviceHandlersCreateChan[agent.deviceID]; exist {
142 logger.Debugw("deviceHandler created - trigger processing of pending ONU_IND_REQUEST", log.Fields{"device-id": agent.deviceID})
143 oo.deviceHandlersCreateChan[agent.deviceID] <- true
144 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000145 }
146}
147
Himani Chawla6d2ae152020-09-02 13:11:20 +0530148func (oo *OpenONUAC) deleteDeviceHandlerToMap(agent *deviceHandler) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000149 oo.lockDeviceHandlersMap.Lock()
150 defer oo.lockDeviceHandlersMap.Unlock()
151 delete(oo.deviceHandlers, agent.deviceID)
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000152 delete(oo.deviceHandlersCreateChan, agent.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000153}
154
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000155//getDeviceHandler gets the ONU deviceHandler and may wait until it is created
156func (oo *OpenONUAC) getDeviceHandler(deviceID string, aWait bool) *deviceHandler {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000157 oo.lockDeviceHandlersMap.Lock()
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000158 agent, ok := oo.deviceHandlers[deviceID]
159 if aWait && !ok {
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000160 logger.Infow("Race condition: deviceHandler not present - wait for creation or timeout",
161 log.Fields{"device-id": deviceID})
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000162 if _, exist := oo.deviceHandlersCreateChan[deviceID]; !exist {
163 oo.deviceHandlersCreateChan[deviceID] = make(chan bool, 1)
164 }
Girish Gowdra7407a4d2020-11-12 12:44:53 -0800165 deviceCreateChan := oo.deviceHandlersCreateChan[deviceID]
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000166 //keep the read sema short to allow for subsequent write
167 oo.lockDeviceHandlersMap.Unlock()
168 // based on concurrent processing the deviceHandler creation may not yet be finished at his point
169 // so it might be needed to wait here for that event with some timeout
170 select {
171 case <-time.After(1 * time.Second): //timer may be discussed ...
172 logger.Warnw("No valid deviceHandler created after max WaitTime", log.Fields{"device-id": deviceID})
173 return nil
Girish Gowdra7407a4d2020-11-12 12:44:53 -0800174 case <-deviceCreateChan:
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000175 logger.Debugw("deviceHandler is ready now - continue", log.Fields{"device-id": deviceID})
Girish Gowdra7407a4d2020-11-12 12:44:53 -0800176 oo.lockDeviceHandlersMap.RLock()
177 defer oo.lockDeviceHandlersMap.RUnlock()
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000178 return oo.deviceHandlers[deviceID]
179 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000180 }
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000181 oo.lockDeviceHandlersMap.Unlock()
182 return agent
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000183}
184
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000185func (oo *OpenONUAC) processInterAdapterONUIndReqMessage(msg *ic.InterAdapterMessage) error {
186 msgBody := msg.GetBody()
187 onuIndication := &oop.OnuIndication{}
188 if err := ptypes.UnmarshalAny(msgBody, onuIndication); err != nil {
189 logger.Warnw("onu-ind-request-cannot-unmarshal-msg-body", log.Fields{"error": err})
190 return err
191 }
192 //ToDeviceId should address a DeviceHandler instance
193 targetDevice := msg.Header.ToDeviceId
194
195 onuOperstate := onuIndication.GetOperState()
196 waitForDhInstPresent := false
197 if onuOperstate == "up" {
198 //Race condition (relevant in BBSIM-environment only): Due to unsynchronized processing of olt-adapter and rw_core,
199 //ONU_IND_REQUEST msg by olt-adapter could arrive a little bit earlier than rw_core was able to announce the corresponding
200 //ONU by RPC of Adopt_device(). Therefore it could be necessary to wait with processing of ONU_IND_REQUEST until call of
201 //Adopt_device() arrived and DeviceHandler instance was created
202 waitForDhInstPresent = true
203 }
204 if handler := oo.getDeviceHandler(targetDevice, waitForDhInstPresent); handler != nil {
205 logger.Infow("onu-ind-request", log.Fields{"device-id": targetDevice,
206 "OnuId": onuIndication.GetOnuId(),
207 "AdminState": onuIndication.GetAdminState(), "OperState": onuOperstate,
208 "SNR": onuIndication.GetSerialNumber()})
209
210 if onuOperstate == "up" {
211 return handler.createInterface(onuIndication)
212 } else if (onuOperstate == "down") || (onuOperstate == "unreachable") {
213 return handler.updateInterface(onuIndication)
214 } else {
215 logger.Errorw("unknown-onu-ind-request operState", log.Fields{"OnuId": onuIndication.GetOnuId()})
216 return fmt.Errorf("invalidOperState: %s, %s", onuOperstate, targetDevice)
217 }
218 }
219 logger.Warnw("no handler found for received onu-ind-request", log.Fields{
220 "msgToDeviceId": targetDevice})
221 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", targetDevice))
222}
223
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000224// Adapter interface required methods ############## begin #########
225// #################################################################
226
227// for original content compare: (needs according deviceHandler methods)
228// /voltha-openolt-adapter/adaptercore/openolt.go
229
230// Adopt_device creates a new device handler if not present already and then adopts the device
231func (oo *OpenONUAC) Adopt_device(device *voltha.Device) error {
232 if device == nil {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000233 logger.Warn("voltha-device-is-nil")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000234 return errors.New("nil-device")
235 }
236 ctx := context.Background()
divyadesai4d299552020-08-18 07:13:49 +0000237 logger.Infow("adopt-device", log.Fields{"device-id": device.Id})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530238 var handler *deviceHandler
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000239 if handler = oo.getDeviceHandler(device.Id, false); handler == nil {
Himani Chawla6d2ae152020-09-02 13:11:20 +0530240 handler := newDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000241 oo.addDeviceHandlerToMap(ctx, handler)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530242 go handler.adoptOrReconcileDevice(ctx, device)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000243 // Launch the creation of the device topic
244 // go oo.createDeviceTopic(device)
245 }
246 return nil
247}
248
249//Get_ofp_device_info returns OFP information for the given device
250func (oo *OpenONUAC) Get_ofp_device_info(device *voltha.Device) (*ic.SwitchCapability, error) {
divyadesai4d299552020-08-18 07:13:49 +0000251 logger.Errorw("device-handler-not-set", log.Fields{"device-id": device.Id})
Andrea Campanella6515c582020-10-05 11:25:00 +0200252 return nil, fmt.Errorf("device-handler-not-set %s", device.Id)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000253}
254
255//Get_ofp_port_info returns OFP port information for the given device
mpagenkoaf801632020-07-03 10:00:42 +0000256//200630: method removed as per [VOL-3202]: OF port info is now to be delivered within UniPort create
257// cmp changes in onu_uni_port.go::CreateVolthaPort()
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000258
259//Process_inter_adapter_message sends messages to a target device (between adapters)
260func (oo *OpenONUAC) Process_inter_adapter_message(msg *ic.InterAdapterMessage) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000261 logger.Debugw("Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id,
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000262 "msgProxyDeviceId": msg.Header.ProxyDeviceId, "msgToDeviceId": msg.Header.ToDeviceId, "Type": msg.Header.Type})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000263
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000264 if msg.Header.Type == ic.InterAdapterMessageType_ONU_IND_REQUEST {
265 // we have to handle ONU_IND_REQUEST already here - see comments in processInterAdapterONUIndReqMessage()
266 return oo.processInterAdapterONUIndReqMessage(msg)
267 }
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000268 //ToDeviceId should address a DeviceHandler instance
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000269 targetDevice := msg.Header.ToDeviceId
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000270 if handler := oo.getDeviceHandler(targetDevice, false); handler != nil {
mpagenko1cc3cb42020-07-27 15:24:38 +0000271 /* 200724: modification towards synchronous implementation - possible errors within processing shall be
272 * in the accordingly delayed response, some timing effect might result in Techprofile processing for multiple UNI's
273 */
Himani Chawla6d2ae152020-09-02 13:11:20 +0530274 return handler.processInterAdapterMessage(msg)
mpagenko1cc3cb42020-07-27 15:24:38 +0000275 /* so far the processing has been in background with according commented error treatment restrictions:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000276 go handler.ProcessInterAdapterMessage(msg)
277 // error treatment might be more sophisticated
278 // by now let's just accept the message on 'communication layer'
279 // message content problems have to be evaluated then in the handler
280 // and are by now not reported to the calling party (to force what reaction there?)
281 return nil
mpagenko1cc3cb42020-07-27 15:24:38 +0000282 */
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000283 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000284 logger.Warnw("no handler found for received Inter-Proxy-message", log.Fields{
285 "msgToDeviceId": targetDevice})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000286 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", targetDevice))
287}
288
289//Adapter_descriptor not implemented
290func (oo *OpenONUAC) Adapter_descriptor() error {
291 return errors.New("unImplemented")
292}
293
294//Device_types unimplemented
295func (oo *OpenONUAC) Device_types() (*voltha.DeviceTypes, error) {
296 return nil, errors.New("unImplemented")
297}
298
299//Health returns unimplemented
300func (oo *OpenONUAC) Health() (*voltha.HealthStatus, error) {
301 return nil, errors.New("unImplemented")
302}
303
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000304//Reconcile_device is called once when the adapter needs to re-create device - usually on core restart
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000305func (oo *OpenONUAC) Reconcile_device(device *voltha.Device) error {
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000306 if device == nil {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000307 logger.Warn("reconcile-device-voltha-device-is-nil")
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000308 return errors.New("nil-device")
309 }
310 ctx := context.Background()
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000311 logger.Infow("reconcile-device", log.Fields{"device-id": device.Id})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530312 var handler *deviceHandler
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000313 if handler = oo.getDeviceHandler(device.Id, false); handler == nil {
Himani Chawla6d2ae152020-09-02 13:11:20 +0530314 handler := newDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000315 oo.addDeviceHandlerToMap(ctx, handler)
316 handler.device = device
317 handler.reconciling = true
Himani Chawla6d2ae152020-09-02 13:11:20 +0530318 go handler.adoptOrReconcileDevice(ctx, handler.device)
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000319 // reconcilement will be continued after onu-device entry is added
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000320 } else {
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000321 return fmt.Errorf(fmt.Sprintf("device-already-reconciled-or-active-%s", device.Id))
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000322 }
323 return nil
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000324}
325
326//Abandon_device unimplemented
327func (oo *OpenONUAC) Abandon_device(device *voltha.Device) error {
328 return errors.New("unImplemented")
329}
330
331//Disable_device disables the given device
332func (oo *OpenONUAC) Disable_device(device *voltha.Device) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000333 logger.Infow("disable-device", log.Fields{"device-id": device.Id})
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000334 if handler := oo.getDeviceHandler(device.Id, false); handler != nil {
Himani Chawla6d2ae152020-09-02 13:11:20 +0530335 go handler.disableDevice(device)
ozgecanetsiafce57b12020-05-25 14:39:35 +0300336 return nil
337 }
divyadesai4d299552020-08-18 07:13:49 +0000338 logger.Warnw("no handler found for device-disable", log.Fields{"device-id": device.Id})
ozgecanetsiafce57b12020-05-25 14:39:35 +0300339 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000340}
341
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000342//Reenable_device enables the onu device after disable
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000343func (oo *OpenONUAC) Reenable_device(device *voltha.Device) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000344 logger.Infow("reenable-device", log.Fields{"device-id": device.Id})
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000345 if handler := oo.getDeviceHandler(device.Id, false); handler != nil {
Himani Chawla6d2ae152020-09-02 13:11:20 +0530346 go handler.reEnableDevice(device)
ozgecanetsiafce57b12020-05-25 14:39:35 +0300347 return nil
348 }
divyadesai4d299552020-08-18 07:13:49 +0000349 logger.Warnw("no handler found for device-reenable", log.Fields{"device-id": device.Id})
ozgecanetsiafce57b12020-05-25 14:39:35 +0300350 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000351}
352
353//Reboot_device reboots the given device
354func (oo *OpenONUAC) Reboot_device(device *voltha.Device) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000355 logger.Infow("reboot-device", log.Fields{"device-id": device.Id})
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000356 if handler := oo.getDeviceHandler(device.Id, false); handler != nil {
Himani Chawla6d2ae152020-09-02 13:11:20 +0530357 go handler.rebootDevice(device)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300358 return nil
359 }
divyadesai4d299552020-08-18 07:13:49 +0000360 logger.Warnw("no handler found for device-reboot", log.Fields{"device-id": device.Id})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300361 return fmt.Errorf(fmt.Sprintf("handler-not-found-#{device.Id}"))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000362}
363
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000364//Self_test_device unimplemented
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000365func (oo *OpenONUAC) Self_test_device(device *voltha.Device) error {
366 return errors.New("unImplemented")
367}
368
Himani Chawla6d2ae152020-09-02 13:11:20 +0530369// Delete_device deletes the given device
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000370func (oo *OpenONUAC) Delete_device(device *voltha.Device) error {
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000371 logger.Infow("delete-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber})
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000372 if handler := oo.getDeviceHandler(device.Id, false); handler != nil {
mpagenko2418ab02020-11-12 12:58:06 +0000373 err := handler.deleteDevicePersistencyData()
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000374 //don't leave any garbage - even in error case
375 oo.deleteDeviceHandlerToMap(handler)
mpagenko2418ab02020-11-12 12:58:06 +0000376 return err
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000377 }
mpagenko2418ab02020-11-12 12:58:06 +0000378 logger.Warnw("no handler found for device-deletion", log.Fields{"device-id": device.Id})
379 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000380}
381
382//Get_device_details unimplemented
383func (oo *OpenONUAC) Get_device_details(device *voltha.Device) error {
384 return errors.New("unImplemented")
385}
386
387//Update_flows_bulk returns
388func (oo *OpenONUAC) Update_flows_bulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata) error {
389 return errors.New("unImplemented")
390}
391
392//Update_flows_incrementally updates (add/remove) the flows on a given device
mpagenkodff5dda2020-08-28 11:52:01 +0000393func (oo *OpenONUAC) Update_flows_incrementally(device *voltha.Device,
394 flows *openflow_13.FlowChanges, groups *openflow_13.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error {
mpagenkofc4f56e2020-11-04 17:17:49 +0000395
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000396 logger.Infow("update-flows-incrementally", log.Fields{"device-id": device.Id})
mpagenkofc4f56e2020-11-04 17:17:49 +0000397 //flow config is relayed to handler even if the device might be in some 'inactive' state
398 // let the handler or related FSM's decide, what to do with the modified flow state info
399 // 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 +0000400
401 // For now, there is no support for group changes (as in the actual Py-adapter code)
mpagenkofc4f56e2020-11-04 17:17:49 +0000402 // but processing is continued for flowUpdate possibly also set in the request
mpagenkodff5dda2020-08-28 11:52:01 +0000403 if groups.ToAdd != nil && groups.ToAdd.Items != nil {
mpagenkofc4f56e2020-11-04 17:17:49 +0000404 logger.Warnw("Update-flow-incr: group add not supported (ignored)", log.Fields{"device-id": device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000405 }
406 if groups.ToRemove != nil && groups.ToRemove.Items != nil {
mpagenkofc4f56e2020-11-04 17:17:49 +0000407 logger.Warnw("Update-flow-incr: group remove not supported (ignored)", log.Fields{"device-id": device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000408 }
409 if groups.ToUpdate != nil && groups.ToUpdate.Items != nil {
mpagenkofc4f56e2020-11-04 17:17:49 +0000410 logger.Warnw("Update-flow-incr: group update not supported (ignored)", log.Fields{"device-id": device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000411 }
412
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000413 if handler := oo.getDeviceHandler(device.Id, false); handler != nil {
mpagenkodff5dda2020-08-28 11:52:01 +0000414 err := handler.FlowUpdateIncremental(flows, groups, flowMetadata)
415 return err
416 }
mpagenkofc4f56e2020-11-04 17:17:49 +0000417 logger.Warnw("no handler found for incremental flow update", log.Fields{"device-id": device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000418 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000419}
420
421//Update_pm_config returns PmConfigs nil or error
422func (oo *OpenONUAC) Update_pm_config(device *voltha.Device, pmConfigs *voltha.PmConfigs) error {
423 return errors.New("unImplemented")
424}
425
426//Receive_packet_out sends packet out to the device
427func (oo *OpenONUAC) Receive_packet_out(deviceID string, egressPortNo int, packet *openflow_13.OfpPacketOut) error {
428 return errors.New("unImplemented")
429}
430
431//Suppress_event unimplemented
432func (oo *OpenONUAC) Suppress_event(filter *voltha.EventFilter) error {
433 return errors.New("unImplemented")
434}
435
436//Unsuppress_event unimplemented
437func (oo *OpenONUAC) Unsuppress_event(filter *voltha.EventFilter) error {
438 return errors.New("unImplemented")
439}
440
441//Download_image unimplemented
442func (oo *OpenONUAC) Download_image(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
443 return nil, errors.New("unImplemented")
444}
445
446//Get_image_download_status unimplemented
447func (oo *OpenONUAC) Get_image_download_status(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
448 return nil, errors.New("unImplemented")
449}
450
451//Cancel_image_download unimplemented
452func (oo *OpenONUAC) Cancel_image_download(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
453 return nil, errors.New("unImplemented")
454}
455
456//Activate_image_update unimplemented
457func (oo *OpenONUAC) Activate_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
458 return nil, errors.New("unImplemented")
459}
460
461//Revert_image_update unimplemented
462func (oo *OpenONUAC) Revert_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
463 return nil, errors.New("unImplemented")
464}
465
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000466// Enable_port to Enable PON/NNI interface - seems not to be used/required according to python code
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000467func (oo *OpenONUAC) Enable_port(deviceID string, port *voltha.Port) error {
468 return errors.New("unImplemented")
469}
470
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000471// Disable_port to Disable pon/nni interface - seems not to be used/required according to python code
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000472func (oo *OpenONUAC) Disable_port(deviceID string, port *voltha.Port) error {
473 return errors.New("unImplemented")
474}
475
Himani Chawla6d2ae152020-09-02 13:11:20 +0530476//Child_device_lost - unimplemented
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000477//needed for if update >= 3.1.x
Matteo Scandolo2e6f1e32020-04-15 11:28:45 -0700478func (oo *OpenONUAC) Child_device_lost(deviceID string, pPortNo uint32, onuID uint32) error {
479 return errors.New("unImplemented")
480}
481
Himani Chawla6d2ae152020-09-02 13:11:20 +0530482// Start_omci_test unimplemented
Matteo Scandolo2e6f1e32020-04-15 11:28:45 -0700483func (oo *OpenONUAC) Start_omci_test(device *voltha.Device, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) {
484 return nil, errors.New("unImplemented")
485}
486
Himani Chawla6d2ae152020-09-02 13:11:20 +0530487// Get_ext_value - unimplemented
Matteo Scandolod132c0e2020-04-24 17:06:25 -0700488func (oo *OpenONUAC) Get_ext_value(deviceID string, device *voltha.Device, valueparam voltha.ValueType_Type) (*voltha.ReturnValues, error) {
489 return nil, errors.New("unImplemented")
490}
491
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000492// Adapter interface required methods ################ end #########
493// #################################################################