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