Minor fixes & tweaks to improve error handing in preparation for BBSim REST API pull request.
Added comments to reduce golint warnings.
Main contributors: Pragya Arya, Vishesh Prasidh
Change-Id: I6f0b67a39dd0b8da0288306ac4f66098df53b18d
diff --git a/device/device_olt.go b/device/device_olt.go
index 618e668..daffcec 100644
--- a/device/device_olt.go
+++ b/device/device_olt.go
@@ -16,10 +16,14 @@
package device
-import "sync"
+import (
+ "strconv"
+ "sync"
+)
type DeviceState int
+// Device interface provides common methods for OLT and ONU devices
type Device interface {
Initialize()
UpdateIntState(intstate DeviceState)
@@ -32,6 +36,7 @@
Intfid uint32
}
+// Olt structure consists required fields for OLT
type Olt struct {
ID uint32
NumPonIntf uint32
@@ -65,6 +70,7 @@
OLT_ACTIVE // After PacketInDaemon Running
)
+// NewOlt creates and return new Olt object
func NewOlt(oltid uint32, npon uint32, nnni uint32) *Olt {
olt := Olt{}
olt.ID = oltid
@@ -73,6 +79,8 @@
olt.Name = "BBSIM OLT"
olt.InternalState = OLT_INACTIVE
olt.OperState = "up"
+ olt.Manufacture = "BBSIM"
+ olt.SerialNumber = "BBSIMOLT00" + strconv.FormatInt(int64(oltid), 10)
olt.Intfs = make([]intf, olt.NumPonIntf+olt.NumNniIntf)
olt.HeartbeatSignature = oltid
olt.mu = &sync.Mutex{}
@@ -89,6 +97,7 @@
return &olt
}
+// Initialize method initializes NNI and PON ports
func (olt *Olt) Initialize() {
olt.InternalState = OLT_INACTIVE
olt.OperState = "up"
@@ -104,16 +113,19 @@
}
}
+// GetIntState returns internal state of OLT
func (olt *Olt) GetIntState() DeviceState {
olt.mu.Lock()
defer olt.mu.Unlock()
return olt.InternalState
}
+// GetDevkey returns device key of OLT
func (olt *Olt) GetDevkey () Devkey {
return Devkey{ID: olt.ID}
}
+// UpdateIntState method updates OLT internal state
func (olt *Olt) UpdateIntState(intstate DeviceState) {
olt.mu.Lock()
defer olt.mu.Unlock()
diff --git a/device/device_onu.go b/device/device_onu.go
index c8e0c4d..1e1ee88 100644
--- a/device/device_onu.go
+++ b/device/device_onu.go
@@ -29,8 +29,10 @@
ONU_INACTIVE DeviceState = iota //TODO: Each stage name should be more accurate
ONU_ACTIVE
ONU_OMCIACTIVE
+ ONU_FREE
)
+// Onu structure stores information of ONUs
type Onu struct {
InternalState DeviceState
OltID uint32
@@ -42,20 +44,22 @@
mu *sync.Mutex
}
+// NewSN constructs and returns serial number based on the OLT ID, intf ID and ONU ID
func NewSN(oltid uint32, intfid uint32, onuid uint32) []byte {
sn := []byte{0, byte(oltid % 256), byte(intfid), byte(onuid)}
return sn
}
+// NewOnus initializes and returns slice of Onu objects
func NewOnus(oltid uint32, intfid uint32, nonus uint32, nnni uint32) []*Onu {
onus := []*Onu{}
for i := 0; i < int(nonus); i++ {
onu := Onu{}
- onu.InternalState = ONU_INACTIVE
+ onu.InternalState = ONU_FREE
onu.mu = &sync.Mutex{}
onu.IntfID = intfid
onu.OltID = oltid
- onu.OperState = "up"
+ onu.OperState = "down"
onu.SerialNumber = new(openolt.SerialNumber)
onu.SerialNumber.VendorId = []byte("BBSM")
onu.SerialNumber.VendorSpecific = NewSN(oltid, intfid, uint32(i))
@@ -65,11 +69,13 @@
return onus
}
+// Initialize method initializes ONU state to up and ONU_INACTIVE
func (onu *Onu) Initialize() {
onu.OperState = "up"
onu.InternalState = ONU_INACTIVE
}
+// ValidateONU method validate ONU based on the serial number in onuMap
func ValidateONU(targetonu openolt.Onu, regonus map[uint32][]*Onu) bool {
for _, onus := range regonus {
for _, onu := range onus {
@@ -81,13 +87,15 @@
return false
}
+// ValidateSN compares two serial numbers and returns result as true/false
func ValidateSN(sn1 openolt.SerialNumber, sn2 openolt.SerialNumber) bool {
return reflect.DeepEqual(sn1.VendorId, sn2.VendorId) && reflect.DeepEqual(sn1.VendorSpecific, sn2.VendorSpecific)
}
+// UpdateOnusOpStatus method updates ONU oper status
func UpdateOnusOpStatus(ponif uint32, onus []*Onu, opstatus string) {
for _, onu := range onus {
- onu.OperState = "up"
+ onu.OperState = opstatus
logger.WithFields(log.Fields{
"onu": onu.SerialNumber,
"pon_interface": ponif,
@@ -95,16 +103,19 @@
}
}
+// UpdateIntState method updates ONU internal state
func (onu *Onu) UpdateIntState(intstate DeviceState) {
onu.mu.Lock()
defer onu.mu.Unlock()
onu.InternalState = intstate
}
+// GetDevkey returns ONU device key
func (onu *Onu) GetDevkey () Devkey {
return Devkey{ID: onu.OnuID, Intfid:onu.IntfID}
}
+// GetIntState returns ONU internal state
func (onu *Onu) GetIntState() DeviceState {
onu.mu.Lock()
defer onu.mu.Unlock()