blob: ba4c42906acdef47e31d121b2cf8a853d295db93 [file] [log] [blame]
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +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 "context"
22 "errors"
23
24 "github.com/looplab/fsm"
25
26 //"sync"
27 //"time"
28
29 //"github.com/opencord/voltha-lib-go/v3/pkg/kafka"
30 "github.com/opencord/omci-lib-go"
31 me "github.com/opencord/omci-lib-go/generated"
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"
35 //"github.com/opencord/voltha-protos/v3/go/voltha"
36)
37
38func (onuDeviceEntry *OnuDeviceEntry) logStateChange(e *fsm.Event) {
39 logger.Debugw("MibSync FSM", log.Fields{"event name": string(e.Event), "src state": string(e.Src), "dst state": string(e.Dst), "device-id": onuDeviceEntry.deviceID})
40}
41
42func (onuDeviceEntry *OnuDeviceEntry) enterStartingState(e *fsm.Event) {
43 logger.Debugw("MibSync FSM", log.Fields{"Start processing MibSync-msgs in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
44
Holger Hildebrandt24d51952020-05-04 14:03:42 +000045 onuDeviceEntry.pOnuDB = NewOnuDeviceDB(context.TODO(), onuDeviceEntry)
46
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000047 // create channel and start go routine for processing of MibSync messages
48 onuDeviceEntry.MibSyncChan = make(chan Message, 2048)
49 go onuDeviceEntry.ProcessMibSyncMessages()
50}
51
52func (onuDeviceEntry *OnuDeviceEntry) enterLoadingMibTemplateState(e *fsm.Event) {
53 logger.Debugw("MibSync FSM", log.Fields{"Start MibTemplate processing in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
54 logger.Debug("function not implemented yet")
55}
56
57func (onuDeviceEntry *OnuDeviceEntry) enterUploadingState(e *fsm.Event) {
58 logger.Debugw("MibSync FSM", log.Fields{"send mibReset in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
59 onuDeviceEntry.PDevOmciCC.sendMibReset(context.TODO(), ConstDefaultOmciTimeout, true)
60}
61
62func (onuDeviceEntry *OnuDeviceEntry) enterInSyncState(e *fsm.Event) {
63 logger.Debugw("MibSync FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
64 onuDeviceEntry.transferSystemEvent(MibDatabaseSync)
65}
66
67func (onuDeviceEntry *OnuDeviceEntry) enterExaminingMdsState(e *fsm.Event) {
68 logger.Debugw("MibSync FSM", log.Fields{"Start GetMds processing in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
69 logger.Debug("function not implemented yet")
70}
71
72func (onuDeviceEntry *OnuDeviceEntry) enterResynchronizingState(e *fsm.Event) {
73 logger.Debugw("MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
74 logger.Debug("function not implemented yet")
75}
76
77func (onuDeviceEntry *OnuDeviceEntry) enterAuditingState(e *fsm.Event) {
78 logger.Debugw("MibSync FSM", log.Fields{"Start MibResync processing in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
79 logger.Debug("function not implemented yet")
80}
81
82func (onuDeviceEntry *OnuDeviceEntry) enterOutOfSyncState(e *fsm.Event) {
83 logger.Debugw("MibSync FSM", log.Fields{"Start MibReconcile processing in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
84 logger.Debug("function not implemented yet")
85}
86
87func (onuDeviceEntry *OnuDeviceEntry) ProcessMibSyncMessages( /*ctx context.Context*/ ) {
88 logger.Debugw("MibSync Msg", log.Fields{"Start routine to process OMCI-messages for device-id": onuDeviceEntry.deviceID})
89loop:
90 for {
91 select {
92 // case <-ctx.Done():
93 // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID})
94 // break loop
95 case message, ok := <-onuDeviceEntry.MibSyncChan:
96 if !ok {
97 logger.Info("MibSync Msg", log.Fields{"Message couldn't be read from channel for device-id": onuDeviceEntry.deviceID})
98 break loop
99 }
100 logger.Debugw("MibSync Msg", log.Fields{"Received message on ONU MibSyncChan for device-id": onuDeviceEntry.deviceID})
101
102 switch message.Type {
103 case TestMsg:
104 msg, _ := message.Data.(TestMessage)
105 onuDeviceEntry.handleTestMsg(msg)
106 case OMCI:
107 msg, _ := message.Data.(OmciMessage)
108 onuDeviceEntry.handleOmciMessage(msg)
109 default:
110 logger.Warn("MibSync Msg", log.Fields{"Unknown message type received for device-id": onuDeviceEntry.deviceID, "message.Type": message.Type})
111 }
112 }
113 }
114 logger.Info("MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": onuDeviceEntry.deviceID})
115 // TODO: only this action?
116 onuDeviceEntry.MibSyncFsm.Event("stop")
117}
118
119func (onuDeviceEntry *OnuDeviceEntry) handleTestMsg(msg TestMessage) {
120
121 logger.Debugw("MibSync Msg", log.Fields{"TestMessage received for device-id": onuDeviceEntry.deviceID, "msg.TestMessageVal": msg.TestMessageVal})
122
123 switch msg.TestMessageVal {
124 case AnyTriggerForMibSyncUploadMib:
125 onuDeviceEntry.MibSyncFsm.Event("upload_mib")
126 logger.Debugw("MibSync Msg", log.Fields{"state": string(onuDeviceEntry.MibSyncFsm.Current())})
127 default:
128 logger.Warn("MibSync Msg", log.Fields{"Unknown message type received for device-id": onuDeviceEntry.deviceID, "msg.TestMessageVal": msg.TestMessageVal})
129 }
130}
131
132func (onuDeviceEntry *OnuDeviceEntry) handleOmciMessage(msg OmciMessage) {
133
134 logger.Debugw("MibSync Msg", log.Fields{"OmciMessage received for device-id": onuDeviceEntry.deviceID,
135 "msgType": msg.OmciMsg.MessageType})
136
137 //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ...
138 switch msg.OmciMsg.MessageType {
139 case omci.MibResetResponseType:
140 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse)
141 if msgLayer == nil {
142 logger.Error("Omci Msg layer could not be detected")
143 return
144 }
145 msgObj, msgOk := msgLayer.(*omci.MibResetResponse)
146 if !msgOk {
147 logger.Error("Omci Msg layer could not be assigned")
148 return
149 }
150 logger.Debugw("MibResetResponse Data", log.Fields{"data-fields": msgObj})
151 if msgObj.Result != me.Success {
152 logger.Errorw("Omci MibResetResponse Error - strange - what to do?", log.Fields{"Error": msgObj.Result})
153 return
154 }
155 onuDeviceEntry.PDevOmciCC.sendMibUpload(context.TODO(), ConstDefaultOmciTimeout, true)
156 case omci.MibUploadResponseType:
157 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse)
158 if msgLayer == nil {
159 logger.Error("Omci Msg layer could not be detected")
160 return
161 }
162 msgObj, msgOk := msgLayer.(*omci.MibUploadResponse)
163 if !msgOk {
164 logger.Error("Omci Msg layer could not be assigned")
165 return
166 }
Holger Hildebrandt24d51952020-05-04 14:03:42 +0000167 logger.Debugw("MibUploadResponse Data for:", log.Fields{"deviceId": onuDeviceEntry.deviceID, "data-fields": msgObj})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000168 /* to be verified / reworked !!! */
169 onuDeviceEntry.PDevOmciCC.uploadNoOfCmds = msgObj.NumberOfCommands
170 if onuDeviceEntry.PDevOmciCC.uploadSequNo < onuDeviceEntry.PDevOmciCC.uploadNoOfCmds {
171 onuDeviceEntry.PDevOmciCC.sendMibUploadNext(context.TODO(), ConstDefaultOmciTimeout, true)
172 } else {
Holger Hildebrandt24d51952020-05-04 14:03:42 +0000173 logger.Error("Invalid number of commands received for:", log.Fields{"deviceId": onuDeviceEntry.deviceID, "uploadNoOfCmds": onuDeviceEntry.PDevOmciCC.uploadNoOfCmds})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000174 //TODO right action?
175 onuDeviceEntry.MibSyncFsm.Event("timeout")
176 }
177 case omci.MibUploadNextResponseType:
178 msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse)
179 if msgLayer == nil {
180 logger.Error("Omci Msg layer could not be detected")
181 return
182 }
183 msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse)
184 if !msgOk {
185 logger.Error("Omci Msg layer could not be assigned")
186 return
187 }
Holger Hildebrandt24d51952020-05-04 14:03:42 +0000188 logger.Debugw("MibUploadNextResponse Data for:", log.Fields{"deviceId": onuDeviceEntry.deviceID, "data-fields": msgObj})
189
190 onuDeviceEntry.pOnuDB.StoreMe(msgObj)
191
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000192 if onuDeviceEntry.PDevOmciCC.uploadSequNo < onuDeviceEntry.PDevOmciCC.uploadNoOfCmds {
193 onuDeviceEntry.PDevOmciCC.sendMibUploadNext(context.TODO(), ConstDefaultOmciTimeout, true)
194 } else {
195 //TODO
196 onuDeviceEntry.MibSyncFsm.Event("success")
197 }
198 }
199}
200
201func (onuDeviceEntry *OnuDeviceEntry) MibDbVolatileDict() error {
202 logger.Debug("MibVolatileDict- running from default Entry code")
203 return errors.New("not_implemented")
204}
205
206// func (onuDeviceEntry *OnuDeviceEntry) MibTemplateTask() error {
207// return errors.New("not_implemented")
208// }
209// func (onuDeviceEntry *OnuDeviceEntry) MibUploadTask() error {
210// return errors.New("not_implemented")
211// }
212// func (onuDeviceEntry *OnuDeviceEntry) GetMdsTask() error {
213// return errors.New("not_implemented")
214// }
215// func (onuDeviceEntry *OnuDeviceEntry) MibResyncTask() error {
216// return errors.New("not_implemented")
217// }
218// func (onuDeviceEntry *OnuDeviceEntry) MibReconcileTask() error {
219// return errors.New("not_implemented")
220// }