VOL-1358 BBSim - Improve the mediator component
This update is for triggering the test activation per-ONU.
Each OLT/ONU instance's state update is notified to the mediator.
Change-Id: Ia702c0081720d4f1cee10929077b97cc0661c375
diff --git a/device/device_olt.go b/device/device_olt.go
index 41df918..618e668 100644
--- a/device/device_olt.go
+++ b/device/device_olt.go
@@ -16,7 +16,21 @@
package device
-type oltState int
+import "sync"
+
+type DeviceState int
+
+type Device interface {
+ Initialize()
+ UpdateIntState(intstate DeviceState)
+ GetIntState() DeviceState
+ GetDevkey() Devkey
+}
+
+type Devkey struct {
+ ID uint32
+ Intfid uint32
+}
type Olt struct {
ID uint32
@@ -26,10 +40,11 @@
SerialNumber string
Manufacture string
Name string
- InternalState *oltState
+ InternalState DeviceState
OperState string
Intfs []intf
HeartbeatSignature uint32
+ mu *sync.Mutex
}
type intf struct {
@@ -38,11 +53,16 @@
OperState string
}
+/* OltState
+OLT_INACTIVE -> OLT_PREACTIVE -> ACTIVE
+ (ActivateOLT) (Enable)
+ <- <-
+*/
+
const (
- PRE_ENABLE oltState = iota
- OLT_UP
- PONIF_UP
- ONU_DISCOVERED
+ OLT_INACTIVE DeviceState = iota // OLT/ONUs are not instantiated
+ OLT_PREACTIVE // Before PacketInDaemon Running
+ OLT_ACTIVE // After PacketInDaemon Running
)
func NewOlt(oltid uint32, npon uint32, nnni uint32) *Olt {
@@ -51,11 +71,11 @@
olt.NumPonIntf = npon
olt.NumNniIntf = nnni
olt.Name = "BBSIM OLT"
- olt.InternalState = new(oltState)
- *olt.InternalState = PRE_ENABLE
+ olt.InternalState = OLT_INACTIVE
olt.OperState = "up"
olt.Intfs = make([]intf, olt.NumPonIntf+olt.NumNniIntf)
olt.HeartbeatSignature = oltid
+ olt.mu = &sync.Mutex{}
for i := uint32(0); i < olt.NumNniIntf; i++ {
olt.Intfs[i].IntfID = i
olt.Intfs[i].OperState = "up"
@@ -69,8 +89,8 @@
return &olt
}
-func (olt *Olt) InitializeStatus() {
- *olt.InternalState = PRE_ENABLE
+func (olt *Olt) Initialize() {
+ olt.InternalState = OLT_INACTIVE
olt.OperState = "up"
for i := uint32(0); i < olt.NumNniIntf; i++ {
olt.Intfs[i].IntfID = i
@@ -83,3 +103,19 @@
olt.Intfs[i].Type = "pon"
}
}
+
+func (olt *Olt) GetIntState() DeviceState {
+ olt.mu.Lock()
+ defer olt.mu.Unlock()
+ return olt.InternalState
+}
+
+func (olt *Olt) GetDevkey () Devkey {
+ return Devkey{ID: olt.ID}
+}
+
+func (olt *Olt) UpdateIntState(intstate DeviceState) {
+ olt.mu.Lock()
+ defer olt.mu.Unlock()
+ olt.InternalState = intstate
+}
\ No newline at end of file
diff --git a/device/device_onu.go b/device/device_onu.go
index 24f2cbf..c1a7aad 100644
--- a/device/device_onu.go
+++ b/device/device_onu.go
@@ -25,15 +25,13 @@
log "github.com/sirupsen/logrus"
)
-type onuState int
-
const (
- ONU_PRE_ACTIVATED onuState = iota
- ONU_ACTIVATED
+ ONU_PREACTIVATED DeviceState = iota
+ ONU_ACTIVE
)
type Onu struct {
- InternalState *onuState
+ InternalState DeviceState
OltID uint32
IntfID uint32
OperState string
@@ -51,8 +49,7 @@
onus := []*Onu{}
for i := 0; i < int(nonus); i++ {
onu := Onu{}
- onu.InternalState = new(onuState)
- *onu.InternalState = ONU_PRE_ACTIVATED
+ onu.InternalState = ONU_PREACTIVATED
onu.mu = &sync.Mutex{}
onu.IntfID = intfid
onu.OltID = oltid
@@ -65,9 +62,9 @@
return onus
}
-func (onu *Onu) InitializeStatus() {
+func (onu *Onu) Initialize() {
onu.OperState = "up"
- *onu.InternalState = ONU_PRE_ACTIVATED
+ onu.InternalState = ONU_PREACTIVATED
}
func ValidateONU(targetonu openolt.Onu, regonus map[uint32][]*Onu) bool {
@@ -95,14 +92,18 @@
}
}
-func (onu *Onu) UpdateIntStatus(intstatus onuState) {
+func (onu *Onu) UpdateIntState(intstate DeviceState) {
onu.mu.Lock()
defer onu.mu.Unlock()
- *onu.InternalState = intstatus
+ onu.InternalState = intstate
}
-func (onu *Onu) GetIntStatus() onuState {
+func (onu *Onu) GetDevkey () Devkey {
+ return Devkey{ID: onu.OnuID, Intfid:onu.IntfID}
+}
+
+func (onu *Onu) GetIntState() DeviceState {
onu.mu.Lock()
defer onu.mu.Unlock()
- return *onu.InternalState
+ return onu.InternalState
}