blob: 1a831367a64a9abdc2dedfd2c95292cafe71ee2c [file] [log] [blame]
Holger Hildebrandt9ac0d0f2020-05-13 11:22:02 +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
17//Package adaptercoreonu provides the utility for onu devices, flows and statistics
18package adaptercoreonu
19
20import (
21 "github.com/looplab/fsm"
22
23 //"sync"
24 //"time"
25
26 //"github.com/opencord/voltha-lib-go/v3/pkg/kafka"
27
28 "github.com/opencord/voltha-lib-go/v3/pkg/log"
29 //ic "github.com/opencord/voltha-protos/v3/go/inter_container"
30 //"github.com/opencord/voltha-protos/v3/go/openflow_13"
31 //"github.com/opencord/voltha-protos/v3/go/voltha"
32)
33
34func (onuDeviceEntry *OnuDeviceEntry) enterDLStartingState(e *fsm.Event) {
35 logger.Debugw("MibDownload FSM", log.Fields{"Start downloading OMCI MIB in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
36
37 // start go routine for processing of MibDownload messages
38 go onuDeviceEntry.ProcessMibDownloadMessages()
39}
40
41func (onuDeviceEntry *OnuDeviceEntry) enterDownloadingState(e *fsm.Event) {
42 logger.Debugw("MibDownload FSM", log.Fields{"GAL Ethernet Profile set in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
43 //onuDeviceEntry.PDevOmciCC.sendGalEthernetProfileSet(context.TODO(), ConstDefaultOmciTimeout, true)
44}
45
46func (onuDeviceEntry *OnuDeviceEntry) enterDownloadedState(e *fsm.Event) {
47 logger.Debugw("MibDownload FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
48 onuDeviceEntry.transferSystemEvent(MibDownloadDone)
49}
50
51func (onuDeviceEntry *OnuDeviceEntry) ProcessMibDownloadMessages( /*ctx context.Context*/ ) {
52 logger.Debugw("MibDownload Msg", log.Fields{"Start routine to process OMCI-messages for device-id": onuDeviceEntry.deviceID})
53loop:
54 for {
55 select {
56 // case <-ctx.Done():
57 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID})
58 // break loop
59 case message, ok := <-onuDeviceEntry.pMibDownloadFsm.commChan:
60 if !ok {
61 logger.Info("MibDownload Msg", log.Fields{"Message couldn't be read from channel for device-id": onuDeviceEntry.deviceID})
62 break loop
63 }
64 logger.Debugw("MibDownload Msg", log.Fields{"Received OMCI message for device-id": onuDeviceEntry.deviceID})
65
66 if message.Type != OMCI {
67 logger.Warn("MibDownload Msg", log.Fields{"Unknown message type received for device-id": onuDeviceEntry.deviceID,
68 "message.Type": message.Type})
69 } else {
70 msg, _ := message.Data.(OmciMessage)
71 onuDeviceEntry.handleOmciMibDownloadMessage(msg)
72 }
73 }
74 }
75 logger.Info("MibDownload Msg", log.Fields{"Stop receiving messages for device-id": onuDeviceEntry.deviceID})
76 // TODO: only this action?
77 onuDeviceEntry.pMibDownloadFsm.pFsm.Event("restart")
78}
79
80func (onuDeviceEntry *OnuDeviceEntry) handleOmciMibDownloadMessage(msg OmciMessage) {
81
82 logger.Debugw("Rx OMCI MibDownload Msg", log.Fields{"device-id": onuDeviceEntry.deviceID,
83 "msgType": msg.OmciMsg.MessageType})
84
85 //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ...
86 /*
87 switch msg.OmciMsg.MessageType {
88 case omci.MibResetResponseType:
89 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse)
90 if msgLayer == nil {
91 logger.Error("Omci Msg layer could not be detected")
92 return
93 }
94 msgObj, msgOk := msgLayer.(*omci.MibResetResponse)
95 if !msgOk {
96 logger.Error("Omci Msg layer could not be assigned")
97 return
98 }
99 logger.Debugw("MibResetResponse Data", log.Fields{"data-fields": msgObj})
100 if msgObj.Result != me.Success {
101 logger.Errorw("Omci MibResetResponse Error - strange - what to do?", log.Fields{"Error": msgObj.Result})
102 return
103 }
104 onuDeviceEntry.PDevOmciCC.sendMibUpload(context.TODO(), ConstDefaultOmciTimeout, true)
105 case omci.MibUploadResponseType:
106 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse)
107 if msgLayer == nil {
108 logger.Error("Omci Msg layer could not be detected")
109 return
110 }
111 msgObj, msgOk := msgLayer.(*omci.MibUploadResponse)
112 if !msgOk {
113 logger.Error("Omci Msg layer could not be assigned")
114 return
115 }
116 logger.Debugw("MibUploadResponse Data for:", log.Fields{"deviceId": onuDeviceEntry.deviceID, "data-fields": msgObj})
117 // to be verified / reworked !!!
118 onuDeviceEntry.PDevOmciCC.uploadNoOfCmds = msgObj.NumberOfCommands
119 if onuDeviceEntry.PDevOmciCC.uploadSequNo < onuDeviceEntry.PDevOmciCC.uploadNoOfCmds {
120 onuDeviceEntry.PDevOmciCC.sendMibUploadNext(context.TODO(), ConstDefaultOmciTimeout, true)
121 } else {
122 logger.Error("Invalid number of commands received for:", log.Fields{"deviceId": onuDeviceEntry.deviceID, "uploadNoOfCmds": onuDeviceEntry.PDevOmciCC.uploadNoOfCmds})
123 //TODO right action?
124 onuDeviceEntry.MibSyncFsm.Event("timeout")
125 }
126 case omci.MibUploadNextResponseType:
127 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse)
128 if msgLayer == nil {
129 logger.Error("Omci Msg layer could not be detected")
130 return
131 }
132 msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse)
133 if !msgOk {
134 logger.Error("Omci Msg layer could not be assigned")
135 return
136 }
137 logger.Debugw("MibUploadNextResponse Data for:", log.Fields{"deviceId": onuDeviceEntry.deviceID, "data-fields": msgObj})
138
139 onuDeviceEntry.pOnuDB.StoreMe(msgObj)
140
141 if onuDeviceEntry.PDevOmciCC.uploadSequNo < onuDeviceEntry.PDevOmciCC.uploadNoOfCmds {
142 onuDeviceEntry.PDevOmciCC.sendMibUploadNext(context.TODO(), ConstDefaultOmciTimeout, true)
143 } else {
144 //TODO
145 onuDeviceEntry.MibSyncFsm.Event("success")
146 }
147 }
148 */
149}