VOL-1355 BBSim - Support per-ONU control (and remove UNI veths and chhange NNI's veth name)
(UNI veths in BBSim is no longer necessary because DHCP/EAPOL are emulated inside BBSim)
Change-Id: I19aba9fc90dd673c247e70b75130ffd58903f18b
diff --git a/core/mediator.go b/core/mediator.go
index aea0e71..002ce6d 100644
--- a/core/mediator.go
+++ b/core/mediator.go
@@ -84,16 +84,10 @@
return o
}
-type handler struct {
- dst device.DeviceState
- src device.DeviceState
- method func(s *Server) error
-}
-
type mediator struct {
- opt *option
- server *Server
- tester *Tester
+ opt *option
+ server *Server
+ testmanager *TestManager
}
func NewMediator(o *option) *mediator {
@@ -122,12 +116,11 @@
return
}()
- tester := NewTester(opt)
+ tm := NewTestManager(opt)
m.server = server
- m.tester = tester
-
+ m.testmanager = tm
go func() {
- m.Mediate(server)
+ m.Mediate()
}()
c := make(chan os.Signal, 1)
@@ -141,8 +134,8 @@
wg.Add(1)
fmt.Println("SIGINT", sig)
close(c)
- server.Stop() //Non-blocking
- tester.Stop(server) //Non-blocking
+ server.Stop() //Non-blocking
+ tm.Stop() //Non-blocking
return
}
}()
@@ -150,7 +143,7 @@
logger.Debug("Reach to the end line")
}
-func (m *mediator) Mediate(s *Server) {
+func (m *mediator) Mediate() {
defer logger.Debug("Mediate Done")
for sr := range m.server.stateRepCh {
next := sr.next
@@ -158,35 +151,42 @@
dev := sr.device
if reflect.TypeOf(dev) == reflect.TypeOf(&device.Olt{}){
logger.Debug("Received OLT Device %v Current: %d Next: %d", dev, current, next)
- if err := transitOlt(s, current, next, m.tester, m.opt); err != nil {
+ if err := transitOlt(current, next, m.testmanager, m.opt); err != nil {
logger.Error("%v", err)
}
} else if reflect.TypeOf(dev) == reflect.TypeOf(&device.Onu{}) {
logger.Debug("Received ONU Device %v Current: %d Next: %d", dev, current, next)
key := dev.GetDevkey()
- if err := transitOnu(s, key, current, next, m.tester, m.opt); err != nil {
+ if err := transitOnu(key, current, next, m.testmanager, m.opt); err != nil {
logger.Error("%v", err)
}
}
}
}
-func transitOlt (s *Server, current device.DeviceState, next device.DeviceState, tester *Tester, o *option) error {
+func transitOlt (current device.DeviceState, next device.DeviceState, tm *TestManager, o *option) error {
+ logger.Debug("trnsitOlt called current:%d , next:%d", current, next)
if current == device.OLT_PREACTIVE && next == device.OLT_ACTIVE {
-
+ tm.Start()
+ activateDHCPServer("nni_north0", o.dhcpservip)
} else if current == device.OLT_ACTIVE && next == device.OLT_PREACTIVE{
- tester.Stop(s)
+ tm.Stop()
}
return nil
}
-func transitOnu (s *Server, key device.Devkey, current device.DeviceState, next device.DeviceState, tester *Tester, o *option) error {
+func transitOnu (key device.Devkey, current device.DeviceState, next device.DeviceState, tm *TestManager, o *option) error {
+ logger.Debug("trnsitOnu called with key:%s, current:%d , next:%d", key, current, next)
if current == device.ONU_ACTIVE && next == device.ONU_OMCIACTIVE {
- if s.isAllOnuOmciActive(){ //TODO: This should be per-ONU control, not by cheking All ONU's status
- tester.Start(s)
+ t := tm.CreateTester(o, key)
+ if err := tm.StartTester(key, t); err != nil {
+ logger.Error("Cannot Start Executer error:%v", err)
}
} else if (current == device.ONU_OMCIACTIVE || current == device.ONU_ACTIVE) &&
next == device.ONU_INACTIVE {
+ if err := tm.StopTester(key); err != nil {
+ logger.Error("Cannot Start Executer error:%v", err)
+ }
}
return nil
}