Converting Software Image Hash to hex string
Returning image version based on the first 14 bytes of the image file. D
Change-Id: I5ea94be5e841cd1a845e7d523cf0e3666983d4aa
diff --git a/internal/bbsim/devices/onu.go b/internal/bbsim/devices/onu.go
index 84706fd..af135de 100644
--- a/internal/bbsim/devices/onu.go
+++ b/internal/bbsim/devices/onu.go
@@ -127,6 +127,9 @@
ImageSoftwareReceivedSections int
ActiveImageEntityId uint16
CommittedImageEntityId uint16
+ StandbyImageVersion string
+ ActiveImageVersion string
+ CommittedImageVersion string
OmciResponseRate uint8
OmciMsgCounter uint8
@@ -163,10 +166,14 @@
MibDataSync: 0,
ImageSoftwareExpectedSections: 0, // populated during OMCI StartSoftwareDownloadRequest
ImageSoftwareReceivedSections: 0,
- ActiveImageEntityId: 0, // when we start the SoftwareImage with ID 0 is active and committed
- CommittedImageEntityId: 0,
- OmciResponseRate: olt.OmciResponseRate,
- OmciMsgCounter: 0,
+ //TODO this needs reworking, it's always 0 or 1, possibly base all on the version
+ ActiveImageEntityId: 0, // when we start the SoftwareImage with ID 0 is active and committed
+ CommittedImageEntityId: 0,
+ StandbyImageVersion: "BBSM_IMG_00000",
+ ActiveImageVersion: "BBSM_IMG_00001",
+ CommittedImageVersion: "BBSM_IMG_00001",
+ OmciResponseRate: olt.OmciResponseRate,
+ OmciMsgCounter: 0,
}
o.SerialNumber = NewSN(olt.ID, pon.ID, id)
// NOTE this state machine is used to track the operational
@@ -782,7 +789,8 @@
responsePkt, _ = omcilib.CreateMibUploadNextResponse(msg.OmciPkt, msg.OmciMsg, o.MibDataSync, o.MibDb)
case omci.GetRequestType:
onuDown := o.OperState.Current() == "down"
- responsePkt, _ = omcilib.CreateGetResponse(msg.OmciPkt, msg.OmciMsg, o.SerialNumber, o.MibDataSync, o.ActiveImageEntityId, o.CommittedImageEntityId, onuDown)
+ responsePkt, _ = omcilib.CreateGetResponse(msg.OmciPkt, msg.OmciMsg, o.SerialNumber, o.MibDataSync, o.ActiveImageEntityId,
+ o.CommittedImageEntityId, o.StandbyImageVersion, o.ActiveImageVersion, o.CommittedImageVersion, onuDown)
case omci.SetRequestType:
success := true
msgObj, _ := omcilib.ParseSetRequest(msg.OmciPkt)
@@ -1011,6 +1019,10 @@
"SectionNumber": msgObj.SectionNumber,
"SectionData": msgObj.SectionData,
}).Trace("received-download-section-request")
+ //Extracting the first 14 bytes to use as a version for this image.
+ if o.ImageSoftwareReceivedSections == 0 {
+ o.StandbyImageVersion = string(msgObj.SectionData[0:14])
+ }
o.ImageSoftwareReceivedSections++
if o.InternalState.Current() != OnuStateImageDownloadInProgress {
if err := o.InternalState.Event(OnuTxProgressImageDownload); err != nil {
@@ -1101,6 +1113,9 @@
}
if msgObj, err := omcilib.ParseActivateSoftwareRequest(msg.OmciPkt); err == nil {
o.ActiveImageEntityId = msgObj.EntityInstance
+ previousActiveImage := o.ActiveImageVersion
+ o.ActiveImageVersion = o.StandbyImageVersion
+ o.StandbyImageVersion = previousActiveImage
} else {
onuLogger.Errorf("something-went-wrong-while-activating: %s", err)
}
@@ -1134,7 +1149,11 @@
// TODO validate that the image to commit is:
// - active
// - not already committed
+ o.ActiveImageEntityId = msgObj.EntityInstance
o.CommittedImageEntityId = msgObj.EntityInstance
+ //committed becomes standby
+ o.StandbyImageVersion = o.CommittedImageVersion
+ o.CommittedImageVersion = o.ActiveImageVersion
} else {
onuLogger.Errorf("something-went-wrong-while-committing: %s", err)
}