blob: 58b1771c0dd6a029511e1dbbb0484272b96b9755 [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"
35 ic "github.com/opencord/voltha-protos/v4/go/inter_container"
36 "github.com/opencord/voltha-protos/v4/go/openflow_13"
37 oop "github.com/opencord/voltha-protos/v4/go/openolt"
38 "github.com/opencord/voltha-protos/v4/go/voltha"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000039
Matteo Scandolo761f7512020-11-23 15:52:40 -080040 "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/config"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000041)
42
43//OpenONUAC structure holds the ONU core information
44type OpenONUAC struct {
Himani Chawla6d2ae152020-09-02 13:11:20 +053045 deviceHandlers map[string]*deviceHandler
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +000046 deviceHandlersCreateChan map[string]chan bool //channels for deviceHandler create events
Holger Hildebrandt61b24d02020-11-16 13:36:40 +000047 lockDeviceHandlersMap sync.RWMutex
Holger Hildebrandtfa074992020-03-27 15:42:06 +000048 coreProxy adapterif.CoreProxy
49 adapterProxy adapterif.AdapterProxy
Himani Chawlac07fda02020-12-09 16:21:21 +053050 eventProxy eventif.EventProxy
Holger Hildebrandtfa074992020-03-27 15:42:06 +000051 kafkaICProxy kafka.InterContainerProxy
mpagenkoaf801632020-07-03 10:00:42 +000052 kvClient kvstore.Client
Matteo Scandolof1f39a72020-11-24 12:08:11 -080053 cm *conf.ConfigManager
Holger Hildebrandtfa074992020-03-27 15:42:06 +000054 config *config.AdapterFlags
55 numOnus int
56 KVStoreHost string
57 KVStorePort int
58 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 Hildebrandtfa074992020-03-27 15:42:06 +000069}
70
71//NewOpenONUAC returns a new instance of OpenONU_AC
72func NewOpenONUAC(ctx context.Context, kafkaICProxy kafka.InterContainerProxy,
73 coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy,
Himani Chawlac07fda02020-12-09 16:21:21 +053074 eventProxy eventif.EventProxy, kvClient kvstore.Client, cfg *config.AdapterFlags, cm *conf.ConfigManager) *OpenONUAC {
Holger Hildebrandtfa074992020-03-27 15:42:06 +000075 var openOnuAc OpenONUAC
76 openOnuAc.exitChannel = make(chan int, 1)
Himani Chawla6d2ae152020-09-02 13:11:20 +053077 openOnuAc.deviceHandlers = make(map[string]*deviceHandler)
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +000078 openOnuAc.deviceHandlersCreateChan = make(map[string]chan bool)
Holger Hildebrandt61b24d02020-11-16 13:36:40 +000079 openOnuAc.lockDeviceHandlersMap = sync.RWMutex{}
Holger Hildebrandtfa074992020-03-27 15:42:06 +000080 openOnuAc.kafkaICProxy = kafkaICProxy
81 openOnuAc.config = cfg
Matteo Scandolof1f39a72020-11-24 12:08:11 -080082 openOnuAc.cm = cm
Holger Hildebrandtfa074992020-03-27 15:42:06 +000083 openOnuAc.numOnus = cfg.OnuNumber
84 openOnuAc.coreProxy = coreProxy
85 openOnuAc.adapterProxy = adapterProxy
86 openOnuAc.eventProxy = eventProxy
mpagenkoaf801632020-07-03 10:00:42 +000087 openOnuAc.kvClient = kvClient
Holger Hildebrandtfa074992020-03-27 15:42:06 +000088 openOnuAc.KVStoreHost = cfg.KVStoreHost
89 openOnuAc.KVStorePort = cfg.KVStorePort
90 openOnuAc.KVStoreType = cfg.KVStoreType
mpagenkoaf801632020-07-03 10:00:42 +000091 openOnuAc.KVStoreTimeout = cfg.KVStoreTimeout
Holger Hildebrandt61b24d02020-11-16 13:36:40 +000092 openOnuAc.mibTemplatesGenerated = make(map[string]bool)
93 openOnuAc.lockMibTemplateGenerated = sync.RWMutex{}
Holger Hildebrandtfa074992020-03-27 15:42:06 +000094 openOnuAc.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval
95 openOnuAc.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval
mpagenkodff5dda2020-08-28 11:52:01 +000096 openOnuAc.AcceptIncrementalEvto = cfg.AccIncrEvto
Himani Chawlad96df182020-09-28 11:12:02 +053097 openOnuAc.maxTimeoutInterAdapterComm = cfg.MaxTimeoutInterAdapterComm
Holger Hildebrandtfa074992020-03-27 15:42:06 +000098 //openOnuAc.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000099
100 openOnuAc.pSupportedFsms = &OmciDeviceFsms{
101 "mib-synchronizer": {
102 //mibSyncFsm, // Implements the MIB synchronization state machine
Himani Chawla6d2ae152020-09-02 13:11:20 +0530103 mibDbVolatileDictImpl, // Implements volatile ME MIB database
Himani Chawla4d908332020-08-31 12:30:20 +0530104 //true, // Advertise events on OpenOMCI event bus
105 cMibAuditDelayImpl, // Time to wait between MIB audits. 0 to disable audits.
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000106 // map[string]func() error{
107 // "mib-upload": onuDeviceEntry.MibUploadTask,
108 // "mib-template": onuDeviceEntry.MibTemplateTask,
109 // "get-mds": onuDeviceEntry.GetMdsTask,
110 // "mib-audit": onuDeviceEntry.GetMdsTask,
111 // "mib-resync": onuDeviceEntry.MibResyncTask,
112 // "mib-reconcile": onuDeviceEntry.MibReconcileTask,
113 // },
114 },
115 }
116
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000117 return &openOnuAc
118}
119
120//Start starts (logs) the adapter
121func (oo *OpenONUAC) Start(ctx context.Context) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000122 logger.Info(ctx, "starting-openonu-adapter")
123 logger.Info(ctx, "openonu-adapter-started")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000124 return nil
125}
126
Himani Chawla6d2ae152020-09-02 13:11:20 +0530127/*
128//stop terminates the session
129func (oo *OpenONUAC) stop(ctx context.Context) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000130 logger.Info(ctx,"stopping-device-manager")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000131 oo.exitChannel <- 1
dbainbri4d3a0dc2020-12-02 00:33:42 +0000132 logger.Info(ctx,"device-manager-stopped")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000133 return nil
134}
Himani Chawla6d2ae152020-09-02 13:11:20 +0530135*/
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000136
Himani Chawla6d2ae152020-09-02 13:11:20 +0530137func (oo *OpenONUAC) addDeviceHandlerToMap(ctx context.Context, agent *deviceHandler) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000138 oo.lockDeviceHandlersMap.Lock()
139 defer oo.lockDeviceHandlersMap.Unlock()
140 if _, exist := oo.deviceHandlers[agent.deviceID]; !exist {
141 oo.deviceHandlers[agent.deviceID] = agent
Himani Chawla6d2ae152020-09-02 13:11:20 +0530142 oo.deviceHandlers[agent.deviceID].start(ctx)
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000143 if _, exist := oo.deviceHandlersCreateChan[agent.deviceID]; exist {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000144 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 +0000145 oo.deviceHandlersCreateChan[agent.deviceID] <- true
146 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000147 }
148}
149
Himani Chawla6d2ae152020-09-02 13:11:20 +0530150func (oo *OpenONUAC) deleteDeviceHandlerToMap(agent *deviceHandler) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000151 oo.lockDeviceHandlersMap.Lock()
152 defer oo.lockDeviceHandlersMap.Unlock()
153 delete(oo.deviceHandlers, agent.deviceID)
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000154 delete(oo.deviceHandlersCreateChan, agent.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000155}
156
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000157//getDeviceHandler gets the ONU deviceHandler and may wait until it is created
dbainbri4d3a0dc2020-12-02 00:33:42 +0000158func (oo *OpenONUAC) getDeviceHandler(ctx context.Context, deviceID string, aWait bool) *deviceHandler {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000159 oo.lockDeviceHandlersMap.Lock()
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000160 agent, ok := oo.deviceHandlers[deviceID]
161 if aWait && !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000162 logger.Infow(ctx, "Race condition: deviceHandler not present - wait for creation or timeout",
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000163 log.Fields{"device-id": deviceID})
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000164 if _, exist := oo.deviceHandlersCreateChan[deviceID]; !exist {
165 oo.deviceHandlersCreateChan[deviceID] = make(chan bool, 1)
166 }
Girish Gowdra7407a4d2020-11-12 12:44:53 -0800167 deviceCreateChan := oo.deviceHandlersCreateChan[deviceID]
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000168 //keep the read sema short to allow for subsequent write
169 oo.lockDeviceHandlersMap.Unlock()
170 // based on concurrent processing the deviceHandler creation may not yet be finished at his point
171 // so it might be needed to wait here for that event with some timeout
172 select {
173 case <-time.After(1 * time.Second): //timer may be discussed ...
dbainbri4d3a0dc2020-12-02 00:33:42 +0000174 logger.Warnw(ctx, "No valid deviceHandler created after max WaitTime", log.Fields{"device-id": deviceID})
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000175 return nil
Girish Gowdra7407a4d2020-11-12 12:44:53 -0800176 case <-deviceCreateChan:
dbainbri4d3a0dc2020-12-02 00:33:42 +0000177 logger.Debugw(ctx, "deviceHandler is ready now - continue", log.Fields{"device-id": deviceID})
Girish Gowdra7407a4d2020-11-12 12:44:53 -0800178 oo.lockDeviceHandlersMap.RLock()
179 defer oo.lockDeviceHandlersMap.RUnlock()
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000180 return oo.deviceHandlers[deviceID]
181 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000182 }
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000183 oo.lockDeviceHandlersMap.Unlock()
184 return agent
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000185}
186
dbainbri4d3a0dc2020-12-02 00:33:42 +0000187func (oo *OpenONUAC) processInterAdapterONUIndReqMessage(ctx context.Context, msg *ic.InterAdapterMessage) error {
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000188 msgBody := msg.GetBody()
189 onuIndication := &oop.OnuIndication{}
190 if err := ptypes.UnmarshalAny(msgBody, onuIndication); err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000191 logger.Warnw(ctx, "onu-ind-request-cannot-unmarshal-msg-body", log.Fields{"error": err})
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000192 return err
193 }
194 //ToDeviceId should address a DeviceHandler instance
195 targetDevice := msg.Header.ToDeviceId
196
197 onuOperstate := onuIndication.GetOperState()
198 waitForDhInstPresent := false
199 if onuOperstate == "up" {
200 //Race condition (relevant in BBSIM-environment only): Due to unsynchronized processing of olt-adapter and rw_core,
201 //ONU_IND_REQUEST msg by olt-adapter could arrive a little bit earlier than rw_core was able to announce the corresponding
202 //ONU by RPC of Adopt_device(). Therefore it could be necessary to wait with processing of ONU_IND_REQUEST until call of
203 //Adopt_device() arrived and DeviceHandler instance was created
204 waitForDhInstPresent = true
205 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000206 if handler := oo.getDeviceHandler(ctx, targetDevice, waitForDhInstPresent); handler != nil {
207 logger.Infow(ctx, "onu-ind-request", log.Fields{"device-id": targetDevice,
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000208 "OnuId": onuIndication.GetOnuId(),
209 "AdminState": onuIndication.GetAdminState(), "OperState": onuOperstate,
210 "SNR": onuIndication.GetSerialNumber()})
211
212 if onuOperstate == "up" {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000213 return handler.createInterface(ctx, onuIndication)
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000214 } else if (onuOperstate == "down") || (onuOperstate == "unreachable") {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000215 return handler.updateInterface(ctx, onuIndication)
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000216 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000217 logger.Errorw(ctx, "unknown-onu-ind-request operState", log.Fields{"OnuId": onuIndication.GetOnuId()})
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000218 return fmt.Errorf("invalidOperState: %s, %s", onuOperstate, targetDevice)
219 }
220 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000221 logger.Warnw(ctx, "no handler found for received onu-ind-request", log.Fields{
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000222 "msgToDeviceId": targetDevice})
223 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", targetDevice))
224}
225
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000226// Adapter interface required methods ############## begin #########
227// #################################################################
228
229// for original content compare: (needs according deviceHandler methods)
230// /voltha-openolt-adapter/adaptercore/openolt.go
231
232// Adopt_device creates a new device handler if not present already and then adopts the device
dbainbri4d3a0dc2020-12-02 00:33:42 +0000233func (oo *OpenONUAC) Adopt_device(ctx context.Context, device *voltha.Device) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000234 if device == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000235 logger.Warn(ctx, "voltha-device-is-nil")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000236 return errors.New("nil-device")
237 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000238 logger.Infow(ctx, "adopt-device", log.Fields{"device-id": device.Id})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530239 var handler *deviceHandler
dbainbri4d3a0dc2020-12-02 00:33:42 +0000240 if handler = oo.getDeviceHandler(ctx, device.Id, false); handler == nil {
241 handler := newDeviceHandler(ctx, oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000242 oo.addDeviceHandlerToMap(ctx, handler)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530243 go handler.adoptOrReconcileDevice(ctx, device)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000244 // Launch the creation of the device topic
245 // go oo.createDeviceTopic(device)
246 }
247 return nil
248}
249
250//Get_ofp_device_info returns OFP information for the given device
dbainbri4d3a0dc2020-12-02 00:33:42 +0000251func (oo *OpenONUAC) Get_ofp_device_info(ctx context.Context, device *voltha.Device) (*ic.SwitchCapability, error) {
252 logger.Errorw(ctx, "device-handler-not-set", log.Fields{"device-id": device.Id})
Andrea Campanella6515c582020-10-05 11:25:00 +0200253 return nil, fmt.Errorf("device-handler-not-set %s", device.Id)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000254}
255
256//Get_ofp_port_info returns OFP port information for the given device
mpagenkoaf801632020-07-03 10:00:42 +0000257//200630: method removed as per [VOL-3202]: OF port info is now to be delivered within UniPort create
258// cmp changes in onu_uni_port.go::CreateVolthaPort()
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000259
260//Process_inter_adapter_message sends messages to a target device (between adapters)
dbainbri4d3a0dc2020-12-02 00:33:42 +0000261func (oo *OpenONUAC) Process_inter_adapter_message(ctx context.Context, msg *ic.InterAdapterMessage) error {
262 logger.Debugw(ctx, "Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id,
Holger Hildebrandt80129db2020-11-23 10:49:32 +0000263 "msgProxyDeviceId": msg.Header.ProxyDeviceId, "msgToDeviceId": msg.Header.ToDeviceId, "Type": msg.Header.Type})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000264
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000265 if msg.Header.Type == ic.InterAdapterMessageType_ONU_IND_REQUEST {
266 // we have to handle ONU_IND_REQUEST already here - see comments in processInterAdapterONUIndReqMessage()
dbainbri4d3a0dc2020-12-02 00:33:42 +0000267 return oo.processInterAdapterONUIndReqMessage(ctx, msg)
Holger Hildebrandt6c1fb0a2020-11-25 15:41:01 +0000268 }
Holger Hildebrandtf07b44a2020-11-10 13:07:54 +0000269 //ToDeviceId should address a DeviceHandler instance
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000270 targetDevice := msg.Header.ToDeviceId
dbainbri4d3a0dc2020-12-02 00:33:42 +0000271 if handler := oo.getDeviceHandler(ctx, targetDevice, false); handler != nil {
mpagenko1cc3cb42020-07-27 15:24:38 +0000272 /* 200724: modification towards synchronous implementation - possible errors within processing shall be
273 * in the accordingly delayed response, some timing effect might result in Techprofile processing for multiple UNI's
274 */
dbainbri4d3a0dc2020-12-02 00:33:42 +0000275 return handler.processInterAdapterMessage(ctx, msg)
mpagenko1cc3cb42020-07-27 15:24:38 +0000276 /* so far the processing has been in background with according commented error treatment restrictions:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000277 go handler.ProcessInterAdapterMessage(msg)
278 // error treatment might be more sophisticated
279 // by now let's just accept the message on 'communication layer'
280 // message content problems have to be evaluated then in the handler
281 // and are by now not reported to the calling party (to force what reaction there?)
282 return nil
mpagenko1cc3cb42020-07-27 15:24:38 +0000283 */
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000284 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000285 logger.Warnw(ctx, "no handler found for received Inter-Proxy-message", log.Fields{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000286 "msgToDeviceId": targetDevice})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000287 return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", targetDevice))
288}
289
290//Adapter_descriptor not implemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000291func (oo *OpenONUAC) Adapter_descriptor(ctx context.Context) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000292 return errors.New("unImplemented")
293}
294
295//Device_types unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000296func (oo *OpenONUAC) Device_types(ctx context.Context) (*voltha.DeviceTypes, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000297 return nil, errors.New("unImplemented")
298}
299
300//Health returns unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000301func (oo *OpenONUAC) Health(ctx context.Context) (*voltha.HealthStatus, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000302 return nil, errors.New("unImplemented")
303}
304
Holger Hildebrandt9ca8b132020-08-07 14:45:03 +0000305//Reconcile_device is called once when the adapter needs to re-create device - usually on core restart
dbainbri4d3a0dc2020-12-02 00:33:42 +0000306func (oo *OpenONUAC) Reconcile_device(ctx context.Context, device *voltha.Device) error {
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000307 if device == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000308 logger.Warn(ctx, "reconcile-device-voltha-device-is-nil")
Holger Hildebrandtf41a1602020-08-19 09:52:50 +0000309 return errors.New("nil-device")
310 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000311 logger.Infow(ctx, "reconcile-device", log.Fields{"device-id": device.Id})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530312 var handler *deviceHandler
dbainbri4d3a0dc2020-12-02 00:33:42 +0000313 if handler = oo.getDeviceHandler(ctx, device.Id, false); handler == nil {
314 handler := newDeviceHandler(ctx, 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
dbainbri4d3a0dc2020-12-02 00:33:42 +0000327func (oo *OpenONUAC) Abandon_device(ctx context.Context, device *voltha.Device) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000328 return errors.New("unImplemented")
329}
330
331//Disable_device disables the given device
dbainbri4d3a0dc2020-12-02 00:33:42 +0000332func (oo *OpenONUAC) Disable_device(ctx context.Context, device *voltha.Device) error {
333 logger.Infow(ctx, "disable-device", log.Fields{"device-id": device.Id})
334 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
335 go handler.disableDevice(ctx, device)
ozgecanetsiafce57b12020-05-25 14:39:35 +0300336 return nil
337 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000338 logger.Warnw(ctx, "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
dbainbri4d3a0dc2020-12-02 00:33:42 +0000343func (oo *OpenONUAC) Reenable_device(ctx context.Context, device *voltha.Device) error {
344 logger.Infow(ctx, "reenable-device", log.Fields{"device-id": device.Id})
345 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
346 go handler.reEnableDevice(ctx, device)
ozgecanetsiafce57b12020-05-25 14:39:35 +0300347 return nil
348 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000349 logger.Warnw(ctx, "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
dbainbri4d3a0dc2020-12-02 00:33:42 +0000354func (oo *OpenONUAC) Reboot_device(ctx context.Context, device *voltha.Device) error {
355 logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id})
356 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
357 go handler.rebootDevice(ctx, device)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300358 return nil
359 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000360 logger.Warnw(ctx, "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
dbainbri4d3a0dc2020-12-02 00:33:42 +0000365func (oo *OpenONUAC) Self_test_device(ctx context.Context, device *voltha.Device) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000366 return errors.New("unImplemented")
367}
368
Himani Chawla6d2ae152020-09-02 13:11:20 +0530369// Delete_device deletes the given device
dbainbri4d3a0dc2020-12-02 00:33:42 +0000370func (oo *OpenONUAC) Delete_device(ctx context.Context, device *voltha.Device) error {
371 logger.Infow(ctx, "delete-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber})
372 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
373 err := handler.deleteDevicePersistencyData(ctx)
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 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000378 logger.Warnw(ctx, "no handler found for device-deletion", log.Fields{"device-id": device.Id})
mpagenko2418ab02020-11-12 12:58:06 +0000379 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
dbainbri4d3a0dc2020-12-02 00:33:42 +0000383func (oo *OpenONUAC) Get_device_details(ctx context.Context, device *voltha.Device) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000384 return errors.New("unImplemented")
385}
386
387//Update_flows_bulk returns
dbainbri4d3a0dc2020-12-02 00:33:42 +0000388func (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 +0000389 return errors.New("unImplemented")
390}
391
392//Update_flows_incrementally updates (add/remove) the flows on a given device
dbainbri4d3a0dc2020-12-02 00:33:42 +0000393func (oo *OpenONUAC) Update_flows_incrementally(ctx context.Context, device *voltha.Device,
mpagenkodff5dda2020-08-28 11:52:01 +0000394 flows *openflow_13.FlowChanges, groups *openflow_13.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error {
mpagenkofc4f56e2020-11-04 17:17:49 +0000395
dbainbri4d3a0dc2020-12-02 00:33:42 +0000396 logger.Infow(ctx, "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 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000404 logger.Warnw(ctx, "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 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000407 logger.Warnw(ctx, "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 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000410 logger.Warnw(ctx, "Update-flow-incr: group update not supported (ignored)", log.Fields{"device-id": device.Id})
mpagenkodff5dda2020-08-28 11:52:01 +0000411 }
412
dbainbri4d3a0dc2020-12-02 00:33:42 +0000413 if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil {
414 err := handler.FlowUpdateIncremental(ctx, flows, groups, flowMetadata)
mpagenkodff5dda2020-08-28 11:52:01 +0000415 return err
416 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000417 logger.Warnw(ctx, "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
dbainbri4d3a0dc2020-12-02 00:33:42 +0000422func (oo *OpenONUAC) Update_pm_config(ctx context.Context, device *voltha.Device, pmConfigs *voltha.PmConfigs) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000423 return errors.New("unImplemented")
424}
425
426//Receive_packet_out sends packet out to the device
dbainbri4d3a0dc2020-12-02 00:33:42 +0000427func (oo *OpenONUAC) Receive_packet_out(ctx context.Context, deviceID string, egressPortNo int, packet *openflow_13.OfpPacketOut) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000428 return errors.New("unImplemented")
429}
430
431//Suppress_event unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000432func (oo *OpenONUAC) Suppress_event(ctx context.Context, filter *voltha.EventFilter) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000433 return errors.New("unImplemented")
434}
435
436//Unsuppress_event unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000437func (oo *OpenONUAC) Unsuppress_event(ctx context.Context, filter *voltha.EventFilter) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000438 return errors.New("unImplemented")
439}
440
441//Download_image unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000442func (oo *OpenONUAC) Download_image(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000443 return nil, errors.New("unImplemented")
444}
445
446//Get_image_download_status unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000447func (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 +0000448 return nil, errors.New("unImplemented")
449}
450
451//Cancel_image_download unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000452func (oo *OpenONUAC) Cancel_image_download(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000453 return nil, errors.New("unImplemented")
454}
455
456//Activate_image_update unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000457func (oo *OpenONUAC) Activate_image_update(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000458 return nil, errors.New("unImplemented")
459}
460
461//Revert_image_update unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000462func (oo *OpenONUAC) Revert_image_update(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000463 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
dbainbri4d3a0dc2020-12-02 00:33:42 +0000467func (oo *OpenONUAC) Enable_port(ctx context.Context, deviceID string, port *voltha.Port) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000468 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
dbainbri4d3a0dc2020-12-02 00:33:42 +0000472func (oo *OpenONUAC) Disable_port(ctx context.Context, deviceID string, port *voltha.Port) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000473 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
dbainbri4d3a0dc2020-12-02 00:33:42 +0000478func (oo *OpenONUAC) Child_device_lost(ctx context.Context, deviceID string, pPortNo uint32, onuID uint32) error {
Matteo Scandolo2e6f1e32020-04-15 11:28:45 -0700479 return errors.New("unImplemented")
480}
481
Himani Chawla6d2ae152020-09-02 13:11:20 +0530482// Start_omci_test unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000483func (oo *OpenONUAC) Start_omci_test(ctx context.Context, device *voltha.Device, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) {
Matteo Scandolo2e6f1e32020-04-15 11:28:45 -0700484 return nil, errors.New("unImplemented")
485}
486
Himani Chawla6d2ae152020-09-02 13:11:20 +0530487// Get_ext_value - unimplemented
dbainbri4d3a0dc2020-12-02 00:33:42 +0000488func (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 -0700489 return nil, errors.New("unImplemented")
490}
491
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000492// Adapter interface required methods ################ end #########
493// #################################################################