SEBA-758 send periodic port stats to voltha
SEBA-790 get flow, gemport, and tcont information through API
fix lint errors
Change-Id: I10909e1992eba71d8e54c976ccbcea8778e35539
diff --git a/device/device_olt.go b/device/device_olt.go
index b3dc2c3..719f67b 100644
--- a/device/device_olt.go
+++ b/device/device_olt.go
@@ -21,13 +21,14 @@
"sync"
)
-type DeviceState int
+//State represents the OLT States
+type State int
// Device interface provides common methods for OLT and ONU devices
type Device interface {
Initialize()
- UpdateIntState(intstate DeviceState)
- GetIntState() DeviceState
+ UpdateIntState(intstate State)
+ GetIntState() State
GetDevkey() Devkey
}
@@ -46,10 +47,10 @@
SerialNumber string
Manufacture string
Name string
- InternalState DeviceState
+ InternalState State
OperState string
- NniIntfs []nniIntf
- PonIntfs []ponIntf
+ NniIntfs []Port
+ PonIntfs []Port
HeartbeatSignature uint32
mu *sync.Mutex
}
@@ -68,21 +69,21 @@
NniLosRaised
)
-type ponIntf struct {
+// Port info for NNI and PON ports
+type Port struct {
Type string
IntfID uint32
OperState string
AlarmState AlarmState
+ PortStats PortStats
}
-type nniIntf struct {
- Type string
- IntfID uint32
- OperState string
- AlarmState AlarmState
+// PortStats for NNI and PON ports
+type PortStats struct {
+ Packets uint64
}
-// Constants for port types
+// Constants for Port types
const (
IntfPon = "pon"
IntfNni = "nni"
@@ -96,9 +97,9 @@
// Constants for OLT states
const (
- OLT_INACTIVE DeviceState = iota // OLT/ONUs are not instantiated
- OLT_PREACTIVE // Before PacketInDaemon Running
- OLT_ACTIVE // After PacketInDaemon Running
+ OltInactive State = iota // OLT/ONUs are not instantiated
+ OltPreactive // Before PacketInDaemon Running
+ OltActive // After PacketInDaemon Running
)
// OLTAlarmStateToString is used to get alarm state as string
@@ -116,12 +117,12 @@
olt.NumPonIntf = npon
olt.NumNniIntf = nnni
olt.Name = "BBSIM OLT"
- olt.InternalState = OLT_INACTIVE
+ olt.InternalState = OltInactive
olt.OperState = "up"
olt.Manufacture = "BBSIM"
olt.SerialNumber = "BBSIMOLT00" + strconv.FormatInt(int64(oltid), 10)
- olt.NniIntfs = make([]nniIntf, olt.NumNniIntf)
- olt.PonIntfs = make([]ponIntf, olt.NumPonIntf)
+ olt.NniIntfs = make([]Port, olt.NumNniIntf)
+ olt.PonIntfs = make([]Port, olt.NumPonIntf)
olt.HeartbeatSignature = oltid
olt.mu = &sync.Mutex{}
for i := uint32(0); i < olt.NumNniIntf; i++ {
@@ -141,7 +142,7 @@
// Initialize method initializes NNI and PON ports
func (olt *Olt) Initialize() {
- olt.InternalState = OLT_INACTIVE
+ olt.InternalState = OltInactive
olt.OperState = "up"
for i := uint32(0); i < olt.NumNniIntf; i++ {
olt.NniIntfs[i].IntfID = i
@@ -158,7 +159,7 @@
}
// GetIntState returns internal state of OLT
-func (olt *Olt) GetIntState() DeviceState {
+func (olt *Olt) GetIntState() State {
olt.mu.Lock()
defer olt.mu.Unlock()
return olt.InternalState
@@ -170,7 +171,7 @@
}
// UpdateIntState method updates OLT internal state
-func (olt *Olt) UpdateIntState(intstate DeviceState) {
+func (olt *Olt) UpdateIntState(intstate State) {
olt.mu.Lock()
defer olt.mu.Unlock()
olt.InternalState = intstate
diff --git a/device/device_onu.go b/device/device_onu.go
index aafa793..b0af2c2 100644
--- a/device/device_onu.go
+++ b/device/device_onu.go
@@ -22,43 +22,51 @@
"github.com/opencord/voltha-bbsim/common/logger"
openolt "github.com/opencord/voltha-protos/go/openolt"
+ techprofile "github.com/opencord/voltha-protos/go/tech_profile"
log "github.com/sirupsen/logrus"
)
// Constants for the ONU states
const (
- ONU_INACTIVE DeviceState = iota // TODO: Each stage name should be more accurate
- ONU_ACTIVE
- ONU_OMCIACTIVE
- ONU_AUTHENTICATED
- ONU_LOS_RAISED
- ONU_OMCI_CHANNEL_LOS_RAISED
- ONU_LOS_ON_OLT_PON_LOS // TODO give more suitable and crisp name
- ONU_FREE
+ OnuFree State = iota // TODO: Each stage name should be more accurate
+ OnuInactive
+ OnuLosRaised
+ OnuLosOnOltPonLos
+ OnuOmciChannelLosRaised
+ OnuActive
+ OnuOmciActive
+ OnuAuthenticated
)
// ONUState maps int value of device state to string
-var ONUState = map[DeviceState]string{
- ONU_INACTIVE: "ONU_INACTIVE",
- ONU_ACTIVE: "ONU_ACTIVE",
- ONU_OMCIACTIVE: "ONU_OMCIACTIVE",
- ONU_AUTHENTICATED: "ONU_AUTHENTICATED",
- ONU_LOS_RAISED: "ONU_LOS_RAISED",
- ONU_OMCI_CHANNEL_LOS_RAISED: "ONU_OMCI_CHANNEL_LOS_RAISED",
- ONU_LOS_ON_OLT_PON_LOS: "ONU_LOS_ON_OLT_PON_LOS",
- ONU_FREE: "ONU_FREE",
+var ONUState = map[State]string{
+ OnuFree: "ONU_FREE",
+ OnuInactive: "ONU_INACTIVE",
+ OnuLosRaised: "ONU_LOS_RAISED",
+ OnuLosOnOltPonLos: "ONU_LOS_ON_OLT_PON_LOS",
+ OnuOmciChannelLosRaised: "ONU_OMCI_CHANNEL_LOS_RAISED",
+ OnuActive: "ONU_ACTIVE",
+ OnuOmciActive: "ONU_OMCIACTIVE",
+ OnuAuthenticated: "ONU_AUTHENTICATED",
+}
+
+// FlowKey used for FlowMap key
+type FlowKey struct {
+ FlowID uint32
+ FlowDirection string
}
// Onu structure stores information of ONUs
type Onu struct {
- InternalState DeviceState
+ InternalState State
OltID uint32
IntfID uint32
OperState string
SerialNumber *openolt.SerialNumber
OnuID uint32
- GemportID uint16
- FlowIDs []uint32
+ GemPortMap map[uint32][]uint32 // alloc-id is used as key and corresponding gem-ports are stored in slice
+ Tconts *techprofile.TrafficSchedulers
+ Flows []FlowKey
mu *sync.Mutex
}
@@ -69,11 +77,11 @@
}
// NewOnus initializes and returns slice of Onu objects
-func NewOnus(oltid uint32, intfid uint32, nonus uint32, nnni uint32) []*Onu {
- onus := []*Onu{}
+func NewOnus(oltid uint32, intfid uint32, nonus uint32) []*Onu {
+ var onus []*Onu
for i := 1; i <= int(nonus); i++ {
onu := Onu{}
- onu.InternalState = ONU_FREE // New Onu Initialised with state ONU_FREE
+ onu.InternalState = OnuFree // New Onu Initialised with state ONU_FREE
onu.mu = &sync.Mutex{}
onu.IntfID = intfid
onu.OltID = oltid
@@ -81,7 +89,7 @@
onu.SerialNumber = new(openolt.SerialNumber)
onu.SerialNumber.VendorId = []byte("BBSM")
onu.SerialNumber.VendorSpecific = NewSN(oltid, intfid, uint32(i))
- onu.GemportID = 0
+ onu.GemPortMap = make(map[uint32][]uint32)
onus = append(onus, &onu)
}
return onus
@@ -90,19 +98,7 @@
// 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 {
- if ValidateSN(*targetonu.SerialNumber, *onu.SerialNumber) {
- return true
- }
- }
- }
- return false
+ onu.InternalState = OnuInactive
}
// ValidateSN compares two serial numbers and returns result as true/false
@@ -120,7 +116,7 @@
}
// UpdateIntState method updates ONU internal state
-func (onu *Onu) UpdateIntState(intstate DeviceState) {
+func (onu *Onu) UpdateIntState(intstate State) {
onu.mu.Lock()
defer onu.mu.Unlock()
onu.InternalState = intstate
@@ -132,21 +128,21 @@
}
// GetIntState returns ONU internal state
-func (onu *Onu) GetIntState() DeviceState {
+func (onu *Onu) GetIntState() State {
onu.mu.Lock()
defer onu.mu.Unlock()
return onu.InternalState
}
-// DeleteFlowID method search and delete flowID from the onu flowIDs slice
-func (onu *Onu) DeleteFlowID(flowID uint32) {
- for pos, id := range onu.FlowIDs {
- if id == flowID {
- // delete the flowID by shifting all flowIDs by one
- onu.FlowIDs = append(onu.FlowIDs[:pos], onu.FlowIDs[pos+1:]...)
- t := make([]uint32, len(onu.FlowIDs))
- copy(t, onu.FlowIDs)
- onu.FlowIDs = t
+// DeleteFlow method search and delete flowKey from the onu flows slice
+func (onu *Onu) DeleteFlow(key FlowKey) {
+ for pos, flowKey := range onu.Flows {
+ if flowKey == key {
+ // delete the flowKey by shifting all flowKeys by one
+ onu.Flows = append(onu.Flows[:pos], onu.Flows[pos+1:]...)
+ t := make([]FlowKey, len(onu.Flows))
+ copy(t, onu.Flows)
+ onu.Flows = t
break
}
}
diff --git a/device/utils.go b/device/utils.go
index 7e0eca3..2d4cc28 100644
--- a/device/utils.go
+++ b/device/utils.go
@@ -17,19 +17,17 @@
package device
import (
- "fmt"
-
"github.com/opencord/voltha-bbsim/common/logger"
log "github.com/sirupsen/logrus"
"strconv"
)
+// OnuToSn returns serial number in string format for given ONU
func OnuToSn(onu *Onu) string {
- // FIXME
- // see https://github.com/opencord/voltha/blob/master/voltha/adapters/openolt/openolt_device.py#L929-L943
- return string(onu.SerialNumber.VendorId) + "00000" + fmt.Sprint(onu.IntfID) + "0" + fmt.Sprintf("%x", onu.OnuID-1)
+ return string(onu.SerialNumber.VendorId) + ConvB2S(onu.SerialNumber.VendorSpecific)
}
+// LoggerWithOnu method logs ONU fields
func LoggerWithOnu(onu *Onu) *log.Entry {
if onu == nil {
@@ -39,12 +37,13 @@
return logger.GetLogger().WithFields(log.Fields{
"serial_number": OnuToSn(onu),
- "interfaceId": onu.IntfID,
- "onuId": onu.OnuID,
- "oltId": onu.OltID,
+ "interfaceID": onu.IntfID,
+ "onuID": onu.OnuID,
+ "oltID": onu.OltID,
})
}
+// ConvB2S converts byte array to string
func ConvB2S(b []byte) string {
s := ""
for _, i := range b {