WIP [VOL-3024] - MIB download - provide basic omci configuration to ONU
[VOL-3035] - Store all ME
Change-Id: Ic7393d9dd08131c17d9e4dc7cfb6d2e31bc28044
Signed-off-by: Holger Hildebrandt <holger.hildebrandt@adtran.com>
diff --git a/VERSION b/VERSION
index 05471f1..385281e 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.7-dev
+0.1.9-dev
diff --git a/internal/pkg/onuadaptercore/device_handler.go b/internal/pkg/onuadaptercore/device_handler.go
index 1744406..e3f74e9 100644
--- a/internal/pkg/onuadaptercore/device_handler.go
+++ b/internal/pkg/onuadaptercore/device_handler.go
@@ -30,6 +30,7 @@
"github.com/gogo/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"github.com/looplab/fsm"
+ me "github.com/opencord/omci-lib-go/generated"
"github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif"
"github.com/opencord/voltha-lib-go/v3/pkg/log"
vc "github.com/opencord/voltha-protos/v3/go/common"
@@ -730,53 +731,57 @@
// PM related heartbeat??? !!!TODO....
//self._heartbeat.enabled = True
- //example how to call FSM - transition up to state "uploading"
- if dh.GetOnuDeviceEntry().MibSyncFsm.Is("disabled") {
-
- if err := dh.GetOnuDeviceEntry().MibSyncFsm.Event("start"); err != nil {
- logger.Errorw("MibSyncFsm: Can't go to state starting", log.Fields{"err": err})
- return errors.New("Can't go to state starting")
- } else {
- logger.Debug("MibSyncFsm", log.Fields{"state": string(dh.GetOnuDeviceEntry().MibSyncFsm.Current())})
- //Determine ONU status and start/re-start MIB Synchronization tasks
- //Determine if this ONU has ever synchronized
- if true { //TODO: insert valid check
- if err := dh.GetOnuDeviceEntry().MibSyncFsm.Event("load_mib_template"); err != nil {
- logger.Errorw("MibSyncFsm: Can't go to state loading_mib_template", log.Fields{"err": err})
- return errors.New("Can't go to state loading_mib_template")
+ //call MibUploadFSM - transition up to state "in_sync"
+ pMibUlFsm := dh.GetOnuDeviceEntry().pMibUploadFsm.pFsm
+ if pMibUlFsm != nil {
+ if pMibUlFsm.Is("disabled") {
+ if err := pMibUlFsm.Event("start"); err != nil {
+ logger.Errorw("MibSyncFsm: Can't go to state starting", log.Fields{"err": err})
+ return errors.New("Can't go to state starting")
+ } else {
+ logger.Debug("MibSyncFsm", log.Fields{"state": string(pMibUlFsm.Current())})
+ //Determine ONU status and start/re-start MIB Synchronization tasks
+ //Determine if this ONU has ever synchronized
+ if true { //TODO: insert valid check
+ if err := pMibUlFsm.Event("load_mib_template"); err != nil {
+ logger.Errorw("MibSyncFsm: Can't go to state loading_mib_template", log.Fields{"err": err})
+ return errors.New("Can't go to state loading_mib_template")
+ } else {
+ logger.Debug("MibSyncFsm", log.Fields{"state": string(pMibUlFsm.Current())})
+ //Find and load a mib template. If not found proceed with mib_upload
+ // callbacks to be handled:
+ // Event("success")
+ // Event("timeout")
+ //no mib template found
+ if true { //TODO: insert valid check
+ if err := pMibUlFsm.Event("upload_mib"); err != nil {
+ logger.Errorw("MibSyncFsm: Can't go to state uploading", log.Fields{"err": err})
+ return errors.New("Can't go to state uploading")
+ } else {
+ logger.Debug("state of MibSyncFsm", log.Fields{"state": string(pMibUlFsm.Current())})
+ //Begin full MIB data upload, starting with a MIB RESET
+ // callbacks to be handled:
+ // success: e.Event("success")
+ // failure: e.Event("timeout")
+ }
+ }
+ }
} else {
- logger.Debug("MibSyncFsm", log.Fields{"state": string(dh.GetOnuDeviceEntry().MibSyncFsm.Current())})
- //Find and load a mib template. If not found proceed with mib_upload
+ pMibUlFsm.Event("examine_mds")
+ logger.Debug("state of MibSyncFsm", log.Fields{"state": string(pMibUlFsm.Current())})
+ //Examine the MIB Data Sync
// callbacks to be handled:
// Event("success")
// Event("timeout")
- //no mib template found
- if true { //TODO: insert valid check
- if err := dh.GetOnuDeviceEntry().MibSyncFsm.Event("upload_mib"); err != nil {
- logger.Errorw("MibSyncFsm: Can't go to state uploading", log.Fields{"err": err})
- return errors.New("Can't go to state uploading")
- } else {
- logger.Debug("state of MibSyncFsm", log.Fields{"state": string(dh.GetOnuDeviceEntry().MibSyncFsm.Current())})
- //Begin full MIB data upload, starting with a MIB RESET
- // callbacks to be handled:
- // success: e.Event("success")
- // failure: e.Event("timeout")
- }
- }
+ // Event("mismatch")
}
- } else {
- dh.GetOnuDeviceEntry().MibSyncFsm.Event("examine_mds")
- logger.Debug("state of MibSyncFsm", log.Fields{"state": string(dh.GetOnuDeviceEntry().MibSyncFsm.Current())})
- //Examine the MIB Data Sync
- // callbacks to be handled:
- // Event("success")
- // Event("timeout")
- // Event("mismatch")
}
+ } else {
+ logger.Errorw("wrong state of MibSyncFsm - want: disabled", log.Fields{"have": string(pMibUlFsm.Current())})
+ return errors.New("wrong state of MibSyncFsm")
}
} else {
- logger.Errorw("wrong state of MibSyncFsm - want: disabled", log.Fields{"have": string(dh.GetOnuDeviceEntry().MibSyncFsm.Current())})
- return errors.New("wrong state of MibSyncFsm")
+ logger.Errorw("MibSyncFsm invalid - cannot be executed!!", log.Fields{"deviceID": dh.deviceID})
}
return nil
}
@@ -794,44 +799,50 @@
logger.Errorw("error-DeviceReasonUpdate to 'mibsync-complete'", log.Fields{"deviceID": dh.deviceID, "error": err})
}
- for i := uint16(0); i < dh.GetOnuDeviceEntry().pOnuDB.unigMeCount; i++ {
- mgmtEntityId, _ := dh.GetOnuDeviceEntry().pOnuDB.unigMe[i].GetAttribute("ManagedEntityId")
- logger.Debugw("Add UNI port for stored UniG instance:", log.Fields{"deviceId": dh.GetOnuDeviceEntry().deviceID, "UnigMe EntityID": mgmtEntityId})
- dh.addUniPort(mgmtEntityId.(uint16), i, UniPPTP)
- }
-
- // fixed assumption about PPTP/UNI-G ONU-config
- // to be replaced by DB parsing of MibUpload data TODO!!!
- // parameters are: InstanceNo, running UniNo, type
- // dh.addUniPort(257, 0, UniPPTP)
- // dh.addUniPort(258, 1, UniPPTP)
- // dh.addUniPort(259, 2, UniPPTP)
- // dh.addUniPort(260, 3, UniPPTP)
-
- // start the MibDownload (assumed here to be done via some FSM again - open //TODO!!!)
- /* the mib-download code may look something like that:
- if err := dh.GetOnuDeviceEntry().MibDownloadFsm.Event("start"); err != nil {
- logger.Errorw("MibDownloadFsm: Can't go to state starting", log.Fields{"err": err})
- return errors.New("Can't go to state starting")
- } else {
- logger.Debug("MibDownloadFsm", log.Fields{"state": string(dh.GetOnuDeviceEntry().MibDownloadFsm.Current())})
- //Determine ONU status and start/re-start MIB MibDownloadFsm
- //Determine if this ONU has ever synchronized
- if true { //TODO: insert valid check
- if err := dh.GetOnuDeviceEntry().MibSyncFsm.Event("download_mib"); err != nil {
- logger.Errorw("MibDownloadFsm: Can't go to state 'download_mib'", log.Fields{"err": err})
- return errors.New("Can't go to state 'download_mib'")
- } else {
- //some further processing ???
- logger.Debug("state of MibDownloadFsm", log.Fields{"state": string(dh.GetOnuDeviceEntry().MibDownloadFsm.Current())})
- //some further processing ???
- }
+ unigMap, ok := dh.GetOnuDeviceEntry().pOnuDB.meDb[me.UniGClassID]
+ unigInstKeys := dh.GetOnuDeviceEntry().pOnuDB.GetSortedInstKeys(unigMap)
+ if ok {
+ i := uint16(0)
+ for _, mgmtEntityId := range unigInstKeys {
+ logger.Debugw("Add UNI port for stored UniG instance:", log.Fields{"deviceId": dh.GetOnuDeviceEntry().deviceID, "UnigMe EntityID": mgmtEntityId})
+ dh.addUniPort(mgmtEntityId, i, UniPPTP)
+ i++
}
+ } else {
+ logger.Warnw("No UniG instances found!", log.Fields{"deviceId": dh.GetOnuDeviceEntry().deviceID})
}
- but by now we shortcut the download here and immediately fake the ONU-active state to get the state indication on ONUS!!!:
- */
- //shortcut code to fake download-done!!!:
+
+ /* real Mib download procedure could look somthing like this:
+ ***** but for the moment the FSM is still limited (sending no OMCI) *****
+ ***** thus never reaches 'downloaded' state *****
+ */
+ pMibDlFsm := dh.GetOnuDeviceEntry().pMibDownloadFsm.pFsm
+ if pMibDlFsm != nil {
+ if pMibDlFsm.Is("disabled") {
+ if err := pMibDlFsm.Event("start"); err != nil {
+ logger.Errorw("MibDownloadFsm: Can't go to state starting", log.Fields{"err": err})
+ // maybe try a FSM restart and then again ... - TODO!!!
+ } else {
+ logger.Debug("MibDownloadFsm", log.Fields{"state": string(pMibDlFsm.Current())})
+ // maybe use more specific states here for the specific download steps ...
+ if err := pMibDlFsm.Event("download_mib"); err != nil {
+ logger.Errorw("MibDownloadFsm: Can't go to state downloading", log.Fields{"err": err})
+ } else {
+ logger.Debug("state of MibDownloadFsm", log.Fields{"state": string(pMibDlFsm.Current())})
+ //Begin MIB data download
+ }
+ }
+ } else {
+ logger.Errorw("wrong state of MibDownloadFsm - want: disabled", log.Fields{"have": string(pMibDlFsm.Current())})
+ }
+ /***** Mib download started */
+ } else {
+ logger.Errorw("MibDownloadFsm invalid - cannot be executed!!", log.Fields{"deviceID": dh.deviceID})
+ }
+
+ //shortcut code to fake download-done!!!: TODO!!! to be removed with complete DL FSM
go dh.GetOnuDeviceEntry().transferSystemEvent(MibDownloadDone)
+
} else if dev_Event == MibDownloadDone {
logger.Debugw("MibDownloadDone event: update dev state to 'Oper.Active'", log.Fields{"deviceID": dh.deviceID})
//initiate DevStateUpdate
diff --git a/internal/pkg/onuadaptercore/mib_download.go b/internal/pkg/onuadaptercore/mib_download.go
new file mode 100644
index 0000000..1a83136
--- /dev/null
+++ b/internal/pkg/onuadaptercore/mib_download.go
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2020-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//Package adaptercoreonu provides the utility for onu devices, flows and statistics
+package adaptercoreonu
+
+import (
+ "github.com/looplab/fsm"
+
+ //"sync"
+ //"time"
+
+ //"github.com/opencord/voltha-lib-go/v3/pkg/kafka"
+
+ "github.com/opencord/voltha-lib-go/v3/pkg/log"
+ //ic "github.com/opencord/voltha-protos/v3/go/inter_container"
+ //"github.com/opencord/voltha-protos/v3/go/openflow_13"
+ //"github.com/opencord/voltha-protos/v3/go/voltha"
+)
+
+func (onuDeviceEntry *OnuDeviceEntry) enterDLStartingState(e *fsm.Event) {
+ logger.Debugw("MibDownload FSM", log.Fields{"Start downloading OMCI MIB in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
+
+ // start go routine for processing of MibDownload messages
+ go onuDeviceEntry.ProcessMibDownloadMessages()
+}
+
+func (onuDeviceEntry *OnuDeviceEntry) enterDownloadingState(e *fsm.Event) {
+ logger.Debugw("MibDownload FSM", log.Fields{"GAL Ethernet Profile set in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
+ //onuDeviceEntry.PDevOmciCC.sendGalEthernetProfileSet(context.TODO(), ConstDefaultOmciTimeout, true)
+}
+
+func (onuDeviceEntry *OnuDeviceEntry) enterDownloadedState(e *fsm.Event) {
+ logger.Debugw("MibDownload FSM", log.Fields{"send notification to core in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
+ onuDeviceEntry.transferSystemEvent(MibDownloadDone)
+}
+
+func (onuDeviceEntry *OnuDeviceEntry) ProcessMibDownloadMessages( /*ctx context.Context*/ ) {
+ logger.Debugw("MibDownload Msg", log.Fields{"Start routine to process OMCI-messages for device-id": onuDeviceEntry.deviceID})
+loop:
+ for {
+ select {
+ // case <-ctx.Done():
+ // logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID})
+ // break loop
+ case message, ok := <-onuDeviceEntry.pMibDownloadFsm.commChan:
+ if !ok {
+ logger.Info("MibDownload Msg", log.Fields{"Message couldn't be read from channel for device-id": onuDeviceEntry.deviceID})
+ break loop
+ }
+ logger.Debugw("MibDownload Msg", log.Fields{"Received OMCI message for device-id": onuDeviceEntry.deviceID})
+
+ if message.Type != OMCI {
+ logger.Warn("MibDownload Msg", log.Fields{"Unknown message type received for device-id": onuDeviceEntry.deviceID,
+ "message.Type": message.Type})
+ } else {
+ msg, _ := message.Data.(OmciMessage)
+ onuDeviceEntry.handleOmciMibDownloadMessage(msg)
+ }
+ }
+ }
+ logger.Info("MibDownload Msg", log.Fields{"Stop receiving messages for device-id": onuDeviceEntry.deviceID})
+ // TODO: only this action?
+ onuDeviceEntry.pMibDownloadFsm.pFsm.Event("restart")
+}
+
+func (onuDeviceEntry *OnuDeviceEntry) handleOmciMibDownloadMessage(msg OmciMessage) {
+
+ logger.Debugw("Rx OMCI MibDownload Msg", log.Fields{"device-id": onuDeviceEntry.deviceID,
+ "msgType": msg.OmciMsg.MessageType})
+
+ //further analysis could be done here based on msg.OmciMsg.Payload, e.g. verification of error code ...
+ /*
+ switch msg.OmciMsg.MessageType {
+ case omci.MibResetResponseType:
+ msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibResetResponse)
+ if msgLayer == nil {
+ logger.Error("Omci Msg layer could not be detected")
+ return
+ }
+ msgObj, msgOk := msgLayer.(*omci.MibResetResponse)
+ if !msgOk {
+ logger.Error("Omci Msg layer could not be assigned")
+ return
+ }
+ logger.Debugw("MibResetResponse Data", log.Fields{"data-fields": msgObj})
+ if msgObj.Result != me.Success {
+ logger.Errorw("Omci MibResetResponse Error - strange - what to do?", log.Fields{"Error": msgObj.Result})
+ return
+ }
+ onuDeviceEntry.PDevOmciCC.sendMibUpload(context.TODO(), ConstDefaultOmciTimeout, true)
+ case omci.MibUploadResponseType:
+ msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadResponse)
+ if msgLayer == nil {
+ logger.Error("Omci Msg layer could not be detected")
+ return
+ }
+ msgObj, msgOk := msgLayer.(*omci.MibUploadResponse)
+ if !msgOk {
+ logger.Error("Omci Msg layer could not be assigned")
+ return
+ }
+ logger.Debugw("MibUploadResponse Data for:", log.Fields{"deviceId": onuDeviceEntry.deviceID, "data-fields": msgObj})
+ // to be verified / reworked !!!
+ onuDeviceEntry.PDevOmciCC.uploadNoOfCmds = msgObj.NumberOfCommands
+ if onuDeviceEntry.PDevOmciCC.uploadSequNo < onuDeviceEntry.PDevOmciCC.uploadNoOfCmds {
+ onuDeviceEntry.PDevOmciCC.sendMibUploadNext(context.TODO(), ConstDefaultOmciTimeout, true)
+ } else {
+ logger.Error("Invalid number of commands received for:", log.Fields{"deviceId": onuDeviceEntry.deviceID, "uploadNoOfCmds": onuDeviceEntry.PDevOmciCC.uploadNoOfCmds})
+ //TODO right action?
+ onuDeviceEntry.MibSyncFsm.Event("timeout")
+ }
+ case omci.MibUploadNextResponseType:
+ msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse)
+ if msgLayer == nil {
+ logger.Error("Omci Msg layer could not be detected")
+ return
+ }
+ msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse)
+ if !msgOk {
+ logger.Error("Omci Msg layer could not be assigned")
+ return
+ }
+ logger.Debugw("MibUploadNextResponse Data for:", log.Fields{"deviceId": onuDeviceEntry.deviceID, "data-fields": msgObj})
+
+ onuDeviceEntry.pOnuDB.StoreMe(msgObj)
+
+ if onuDeviceEntry.PDevOmciCC.uploadSequNo < onuDeviceEntry.PDevOmciCC.uploadNoOfCmds {
+ onuDeviceEntry.PDevOmciCC.sendMibUploadNext(context.TODO(), ConstDefaultOmciTimeout, true)
+ } else {
+ //TODO
+ onuDeviceEntry.MibSyncFsm.Event("success")
+ }
+ }
+ */
+}
diff --git a/internal/pkg/onuadaptercore/mib_sync.go b/internal/pkg/onuadaptercore/mib_sync.go
index ba4c429..d15ae03 100644
--- a/internal/pkg/onuadaptercore/mib_sync.go
+++ b/internal/pkg/onuadaptercore/mib_sync.go
@@ -35,17 +35,11 @@
//"github.com/opencord/voltha-protos/v3/go/voltha"
)
-func (onuDeviceEntry *OnuDeviceEntry) logStateChange(e *fsm.Event) {
- 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})
-}
-
func (onuDeviceEntry *OnuDeviceEntry) enterStartingState(e *fsm.Event) {
logger.Debugw("MibSync FSM", log.Fields{"Start processing MibSync-msgs in State": e.FSM.Current(), "device-id": onuDeviceEntry.deviceID})
onuDeviceEntry.pOnuDB = NewOnuDeviceDB(context.TODO(), onuDeviceEntry)
- // create channel and start go routine for processing of MibSync messages
- onuDeviceEntry.MibSyncChan = make(chan Message, 2048)
go onuDeviceEntry.ProcessMibSyncMessages()
}
@@ -92,7 +86,7 @@
// case <-ctx.Done():
// logger.Info("MibSync Msg", log.Fields{"Message handling canceled via context for device-id": onuDeviceEntry.deviceID})
// break loop
- case message, ok := <-onuDeviceEntry.MibSyncChan:
+ case message, ok := <-onuDeviceEntry.pMibUploadFsm.commChan:
if !ok {
logger.Info("MibSync Msg", log.Fields{"Message couldn't be read from channel for device-id": onuDeviceEntry.deviceID})
break loop
@@ -113,7 +107,7 @@
}
logger.Info("MibSync Msg", log.Fields{"Stopped handling of MibSyncChan for device-id": onuDeviceEntry.deviceID})
// TODO: only this action?
- onuDeviceEntry.MibSyncFsm.Event("stop")
+ onuDeviceEntry.pMibUploadFsm.pFsm.Event("stop")
}
func (onuDeviceEntry *OnuDeviceEntry) handleTestMsg(msg TestMessage) {
@@ -122,8 +116,8 @@
switch msg.TestMessageVal {
case AnyTriggerForMibSyncUploadMib:
- onuDeviceEntry.MibSyncFsm.Event("upload_mib")
- logger.Debugw("MibSync Msg", log.Fields{"state": string(onuDeviceEntry.MibSyncFsm.Current())})
+ onuDeviceEntry.pMibUploadFsm.pFsm.Event("upload_mib")
+ logger.Debugw("MibSync Msg", log.Fields{"state": string(onuDeviceEntry.pMibUploadFsm.pFsm.Current())})
default:
logger.Warn("MibSync Msg", log.Fields{"Unknown message type received for device-id": onuDeviceEntry.deviceID, "msg.TestMessageVal": msg.TestMessageVal})
}
@@ -172,7 +166,7 @@
} else {
logger.Error("Invalid number of commands received for:", log.Fields{"deviceId": onuDeviceEntry.deviceID, "uploadNoOfCmds": onuDeviceEntry.PDevOmciCC.uploadNoOfCmds})
//TODO right action?
- onuDeviceEntry.MibSyncFsm.Event("timeout")
+ onuDeviceEntry.pMibUploadFsm.pFsm.Event("timeout")
}
case omci.MibUploadNextResponseType:
msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeMibUploadNextResponse)
@@ -193,7 +187,8 @@
onuDeviceEntry.PDevOmciCC.sendMibUploadNext(context.TODO(), ConstDefaultOmciTimeout, true)
} else {
//TODO
- onuDeviceEntry.MibSyncFsm.Event("success")
+ onuDeviceEntry.pOnuDB.LogMeDb()
+ onuDeviceEntry.pMibUploadFsm.pFsm.Event("success")
}
}
}
diff --git a/internal/pkg/onuadaptercore/omci_cc.go b/internal/pkg/onuadaptercore/omci_cc.go
index 0d40873..c712b1d 100644
--- a/internal/pkg/onuadaptercore/omci_cc.go
+++ b/internal/pkg/onuadaptercore/omci_cc.go
@@ -531,7 +531,7 @@
},
}
//logger.Debugw("Message to be sent into channel:", log.Fields{"mibSyncMsg": mibSyncMsg})
- (*oo.pOnuDeviceEntry).MibSyncChan <- mibSyncMsg
+ (*oo.pOnuDeviceEntry).pMibUploadFsm.commChan <- mibSyncMsg
return nil
}
diff --git a/internal/pkg/onuadaptercore/onu_device_db.go b/internal/pkg/onuadaptercore/onu_device_db.go
index 2729747..0b985d6 100644
--- a/internal/pkg/onuadaptercore/onu_device_db.go
+++ b/internal/pkg/onuadaptercore/onu_device_db.go
@@ -19,23 +19,20 @@
import (
"context"
- "errors"
+ "sort"
"github.com/opencord/omci-lib-go"
me "github.com/opencord/omci-lib-go/generated"
"github.com/opencord/voltha-lib-go/v3/pkg/log"
)
+type MeDbMap map[me.ClassID]map[uint16]me.AttributeValueMap
+
//OnuDeviceDB structure holds information about known ME's
type OnuDeviceDB struct {
- ctx context.Context
- pOnuDeviceEntry *OnuDeviceEntry
- unigMeCount uint16
- unigMe []*me.ManagedEntity
- pptpEthUniMeCount uint16
- pptpEthUniMe []*me.ManagedEntity
- AnigMe *me.ManagedEntity
- VeipMe *me.ManagedEntity
+ ctx context.Context
+ pOnuDeviceEntry *OnuDeviceEntry
+ meDb MeDbMap
}
//OnuDeviceDB returns a new instance for a specific ONU_Device_Entry
@@ -44,91 +41,64 @@
var onuDeviceDB OnuDeviceDB
onuDeviceDB.ctx = ctx
onuDeviceDB.pOnuDeviceEntry = a_pOnuDeviceEntry
- onuDeviceDB.unigMeCount = 0
- onuDeviceDB.unigMe = make([]*me.ManagedEntity, 4, MaxUnisPerOnu)
- onuDeviceDB.pptpEthUniMeCount = 0
- onuDeviceDB.pptpEthUniMe = make([]*me.ManagedEntity, 4, MaxUnisPerOnu)
- onuDeviceDB.AnigMe = nil
- onuDeviceDB.VeipMe = nil
+ onuDeviceDB.meDb = make(MeDbMap)
+
return &onuDeviceDB
}
-func (onuDeviceDB *OnuDeviceDB) UnigAdd(meParamData me.ParamData) error {
- var omciErr me.OmciErrors
- onuDeviceDB.unigMe[onuDeviceDB.unigMeCount], omciErr = me.NewUniG(meParamData)
- if omciErr.StatusCode() != me.Success {
- logger.Errorw("UniG could not be parsed for:", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID})
- return errors.New("UniG could not be parsed")
+func (onuDeviceDB *OnuDeviceDB) StoreMe(a_pMibUpResp *omci.MibUploadNextResponse) {
+
+ meClassId := a_pMibUpResp.ReportedME.GetClassID()
+ meEntityId := a_pMibUpResp.ReportedME.GetEntityID()
+ meAttributes := a_pMibUpResp.ReportedME.GetAttributeValueMap()
+
+ //filter out the OnuData
+ if me.OnuDataClassID == meClassId {
+ return
}
- logger.Debugw("UniG instance stored for:", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID,
- "UnigMe ": onuDeviceDB.unigMe[onuDeviceDB.unigMeCount], "unigMeCount": onuDeviceDB.unigMeCount})
- if onuDeviceDB.unigMeCount < MaxUnisPerOnu {
- onuDeviceDB.unigMeCount++
+
+ logger.Debugw("Search for key data :", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID, "meClassId": meClassId, "meEntityId": meEntityId})
+ meInstMap, ok := onuDeviceDB.meDb[meClassId]
+ if !ok {
+ logger.Debugw("meClassId not found - add to db :", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID})
+ meInstMap = make(map[uint16]me.AttributeValueMap)
+ onuDeviceDB.meDb[meClassId] = meInstMap
+ onuDeviceDB.meDb[meClassId][meEntityId] = meAttributes
} else {
- logger.Errorw("Max number of UniGs exceeded for:", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID})
- return errors.New("Max number of UniGs exceeded")
+ meAttribs, ok := onuDeviceDB.meDb[meClassId][meEntityId]
+ if !ok {
+ logger.Debugw("meEntityId not found - add to db :", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID})
+ onuDeviceDB.meDb[meClassId][meEntityId] = meAttributes
+ } else {
+ logger.Debugw("ME-Instance exists already: merge attribute data :", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID, "meAttribs": meAttribs})
+
+ for k, v := range meAttributes {
+ meAttribs[k] = v
+ }
+ onuDeviceDB.meDb[meClassId][meEntityId] = meAttribs
+ logger.Debugw("ME-Instance updated :", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID, "meAttribs": meAttribs})
+ }
}
- return nil
}
-func (onuDeviceDB *OnuDeviceDB) PptpEthUniAdd(meParamData me.ParamData) error {
- var omciErr me.OmciErrors
- onuDeviceDB.pptpEthUniMe[onuDeviceDB.pptpEthUniMeCount], omciErr = me.NewPhysicalPathTerminationPointEthernetUni(meParamData)
- if omciErr.StatusCode() != me.Success {
- logger.Errorw("pptpEthUni could not be parsed for:", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID})
- return errors.New("pptpEthUni could not be parsed")
+func (onuDeviceDB *OnuDeviceDB) GetSortedInstKeys(meInstMap map[uint16]me.AttributeValueMap) []uint16 {
+
+ var meInstKeys []uint16
+
+ for k := range meInstMap {
+ meInstKeys = append(meInstKeys, k)
}
- logger.Debugw("pptpEthUni instance stored for:", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID,
- "pptpEthUniMe ": onuDeviceDB.pptpEthUniMe[onuDeviceDB.pptpEthUniMeCount], "pptpEthUniMeCount": onuDeviceDB.pptpEthUniMeCount})
- if onuDeviceDB.pptpEthUniMeCount < MaxUnisPerOnu {
- onuDeviceDB.pptpEthUniMeCount++
- } else {
- logger.Errorw("Max number of pptpEthUnis exceeded for:", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID})
- return errors.New("Max number of pptpEthUnis exceeded")
- }
- return nil
+ logger.Debugw("meInstKeys - input order :", log.Fields{"meInstKeys": meInstKeys}) //TODO: delete the line after test phase!
+ sort.Slice(meInstKeys, func(i, j int) bool { return meInstKeys[i] < meInstKeys[j] })
+ logger.Debugw("meInstKeys - output order :", log.Fields{"meInstKeys": meInstKeys}) //TODO: delete the line after test phase!
+ return meInstKeys
}
-func (onuDeviceDB *OnuDeviceDB) AnigAdd(meParamData me.ParamData) error {
- var omciErr me.OmciErrors
- onuDeviceDB.AnigMe, omciErr = me.NewAniG(meParamData)
- if omciErr.StatusCode() != me.Success {
- logger.Errorw("AniG could not be parsed for:", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID})
- return errors.New("AniG could not be parsed")
+func (onuDeviceDB *OnuDeviceDB) LogMeDb() {
+ logger.Debugw("ME instances stored for :", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID})
+ for meClassId, meInstMap := range onuDeviceDB.meDb {
+ for meEntityId, meAttribs := range meInstMap {
+ logger.Debugw("ME instance: ", log.Fields{"meClassId": meClassId, "meEntityId": meEntityId, "meAttribs": meAttribs, "deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID})
+ }
}
- logger.Debugw("AniG instance stored for:", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID, "AnigMe ": onuDeviceDB.AnigMe})
- return nil
-}
-
-func (onuDeviceDB *OnuDeviceDB) VeipAdd(meParamData me.ParamData) error {
- var omciErr me.OmciErrors
- onuDeviceDB.VeipMe, omciErr = me.NewVirtualEthernetInterfacePoint(meParamData)
- if omciErr.StatusCode() != me.Success {
- logger.Errorw("VEIP could not be parsed for:", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID})
- return errors.New("VEIP could not be parsed")
- }
- logger.Debugw("VEIP instance stored for:", log.Fields{"deviceId": onuDeviceDB.pOnuDeviceEntry.deviceID, "VeipMe ": onuDeviceDB.VeipMe})
- return nil
-}
-
-func (onuDeviceDB *OnuDeviceDB) StoreMe(a_pMibUpResp *omci.MibUploadNextResponse) error {
-
- meParamData := me.ParamData{
- EntityID: a_pMibUpResp.ReportedME.GetEntityID(),
- Attributes: a_pMibUpResp.ReportedME.GetAttributeValueMap(),
- }
-
- switch a_pMibUpResp.ReportedME.GetClassID() {
- case me.UniGClassID:
- onuDeviceDB.UnigAdd(meParamData)
- case me.PhysicalPathTerminationPointEthernetUniClassID:
- onuDeviceDB.PptpEthUniAdd(meParamData)
- case me.AniGClassID:
- onuDeviceDB.AnigAdd(meParamData)
- case me.VirtualEthernetInterfacePointClassID:
- onuDeviceDB.VeipAdd(meParamData)
- default:
- //ME won't be stored currently
- }
- return nil
}
diff --git a/internal/pkg/onuadaptercore/onu_device_entry.go b/internal/pkg/onuadaptercore/onu_device_entry.go
index 25c7c20..62b86c0 100644
--- a/internal/pkg/onuadaptercore/onu_device_entry.go
+++ b/internal/pkg/onuadaptercore/onu_device_entry.go
@@ -54,6 +54,28 @@
}
type OmciDeviceFsms map[string]activityDescr
+type AdapterFsm struct {
+ fsmName string
+ deviceID string
+ commChan chan Message
+ pFsm *fsm.FSM
+}
+
+func NewAdapterFsm(a_name string, a_deviceID string, a_commChannel chan Message) *AdapterFsm {
+ aFsm := &AdapterFsm{
+ fsmName: a_name,
+ deviceID: a_deviceID,
+ commChan: a_commChannel,
+ }
+ return aFsm
+}
+
+//Start starts (logs) the omci agent
+func (oo *AdapterFsm) logFsmStateChange(e *fsm.Event) {
+ logger.Debugw("FSM state change", log.Fields{"device-id": oo.deviceID, "FSM name": oo.fsmName,
+ "event name": string(e.Event), "src state": string(e.Src), "dst state": string(e.Dst)})
+}
+
//OntDeviceEntry structure holds information about the attached FSM'as and their communication
type OnuDeviceEntry struct {
deviceID string
@@ -66,10 +88,18 @@
//lockDeviceEntries sync.RWMutex
mibDbClass func() error
supportedFsms OmciDeviceFsms
- MibSyncFsm *fsm.FSM
- MibSyncChan chan Message
devState OnuDeviceEvent
+ // for mibUpload
mibAuditDelay uint16
+ //MibSyncFsm *fsm.FSM
+ //MibSyncChan chan Message
+ pMibUploadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later
+ // for mibDownload
+ //MibDownloadFsm *fsm.FSM
+ //MibDownloadChan chan Message
+ pMibDownloadFsm *AdapterFsm //could be handled dynamically and more general as pAdapterFsm - perhaps later
+ //remark: general usage of pAdapterFsm would require generalization of commChan usage and internal event setting
+ // within the FSM event procedures
}
//OnuDeviceEntry returns a new instance of a OnuDeviceEntry
@@ -119,8 +149,10 @@
onuDeviceEntry.mibAuditDelay = onuDeviceEntry.supportedFsms["mib-synchronizer"].auditDelay
logger.Debugw("MibAudit is set to", log.Fields{"Delay": onuDeviceEntry.mibAuditDelay})
- // Omci related Mib sync state machine
- onuDeviceEntry.MibSyncFsm = fsm.NewFSM(
+ // Omci related Mib upload sync state machine
+ mibUploadChan := make(chan Message, 2048)
+ onuDeviceEntry.pMibUploadFsm = NewAdapterFsm("MibUpload", device_id, mibUploadChan)
+ onuDeviceEntry.pMibUploadFsm.pFsm = fsm.NewFSM(
"disabled",
fsm.Events{
@@ -154,7 +186,7 @@
},
fsm.Callbacks{
- "enter_state": func(e *fsm.Event) { onuDeviceEntry.logStateChange(e) },
+ "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibDownloadFsm.logFsmStateChange(e) },
"enter_starting": func(e *fsm.Event) { onuDeviceEntry.enterStartingState(e) },
"enter_loading_mib_template": func(e *fsm.Event) { onuDeviceEntry.enterLoadingMibTemplateState(e) },
"enter_uploading": func(e *fsm.Event) { onuDeviceEntry.enterUploadingState(e) },
@@ -165,6 +197,35 @@
"enter_in_sync": func(e *fsm.Event) { onuDeviceEntry.enterInSyncState(e) },
},
)
+ // Omci related Mib download state machine
+ mibDownloadChan := make(chan Message, 2048)
+ onuDeviceEntry.pMibDownloadFsm = NewAdapterFsm("MibDownload", device_id, mibDownloadChan)
+ onuDeviceEntry.pMibDownloadFsm.pFsm = fsm.NewFSM(
+ "disabled",
+ fsm.Events{
+
+ {Name: "start", Src: []string{"disabled"}, Dst: "starting"},
+
+ {Name: "download_mib", Src: []string{"starting"}, Dst: "downloading"},
+
+ {Name: "success", Src: []string{"downloading"}, Dst: "downloaded"},
+
+ {Name: "timeout", Src: []string{"downloading"}, Dst: "starting"},
+
+ {Name: "restart", Src: []string{"starting", "downloading", "downloaded"}, Dst: "disabled"},
+ },
+
+ fsm.Callbacks{
+ "enter_state": func(e *fsm.Event) { onuDeviceEntry.pMibDownloadFsm.logFsmStateChange(e) },
+ "enter_starting": func(e *fsm.Event) { onuDeviceEntry.enterDLStartingState(e) },
+ "enter_downloading": func(e *fsm.Event) { onuDeviceEntry.enterDownloadingState(e) },
+ "enter_downloaded": func(e *fsm.Event) { onuDeviceEntry.enterDownloadedState(e) },
+ },
+ )
+ if onuDeviceEntry.pMibDownloadFsm == nil || onuDeviceEntry.pMibDownloadFsm.pFsm == nil {
+ logger.Error("MibDownloadFsm could not be instantiated!!")
+ // some specifc error treatment - or waiting for crash ???
+ }
// Alarm Synchronization Database
//self._alarm_db = None