SEBA-651 DHCP emulation triggered by DHCP flow install
Change-Id: Ibaeab5ee6daf19ee1d9214ce48363fba6c71fd27
diff --git a/core/tester.go b/core/tester.go
index 2349fae..4d1118e 100644
--- a/core/tester.go
+++ b/core/tester.go
@@ -20,32 +20,25 @@
"context"
"os/exec"
"gerrit.opencord.org/voltha-bbsim/common/logger"
- "golang.org/x/sync/errgroup"
"time"
"strconv"
"gerrit.opencord.org/voltha-bbsim/device"
"fmt"
)
-const (
- DEFAULT Mode = iota
- AAA
- BOTH
-)
-
-type Mode int
-
type TestManager struct {
DhcpServerIP string
Pid []int
- testers map[device.Devkey]*Tester
+ testers map[string]map[device.Devkey]*Tester
ctx context.Context
cancel context.CancelFunc
}
type Tester struct {
+ Type string
Key device.Devkey
- Mode Mode
+ Testfunc func(device.Devkey) error
+ Waitsec int
ctx context.Context
cancel context.CancelFunc
}
@@ -56,11 +49,13 @@
return t
}
-func (*TestManager) CreateTester(opt *option, key device.Devkey) *Tester{
+func (*TestManager) CreateTester(testtype string, opt *option, key device.Devkey, fn func(device.Devkey) error, waitsec int) *Tester{
logger.Debug("CreateTester() called")
t := new(Tester)
- t.Mode = opt.Mode
+ t.Type = testtype
t.Key = key
+ t.Testfunc = fn
+ t.Waitsec = waitsec
return t
}
@@ -69,7 +64,9 @@
ctx, cancel := context.WithCancel(context.Background())
tm.ctx = ctx
tm.cancel = cancel
- tm.testers = map[device.Devkey]*Tester{}
+ tm.testers = make(map[string]map[device.Devkey]*Tester)
+ tm.testers["AAA"] = map[device.Devkey]*Tester{}
+ tm.testers["DHCP"] = map[device.Devkey]*Tester{}
logger.Info("TestManager start")
return nil
}
@@ -83,67 +80,50 @@
return nil
}
-func (tm *TestManager) StartTester (key device.Devkey, t *Tester) error {
- logger.Debug("StartTester called with key:%v", key)
- if t.Mode == DEFAULT {
- _, child := errgroup.WithContext(tm.ctx)
- child, cancel := context.WithCancel(child)
- t.ctx = child
- t.cancel = cancel
- } else if t.Mode == AAA || t.Mode == BOTH {
- eg, child := errgroup.WithContext(tm.ctx)
- child, cancel := context.WithCancel(child)
- t.ctx = child
- t.cancel = cancel
- eg.Go(func() error {
- err := activateWPASupplicant(key)
- if err != nil {
- return err
- }
- return nil
- })
+func (tm *TestManager) StartTester (t *Tester) error {
+ testtype := t.Type
+ key := t.Key
+ waitsec := t.Waitsec
- if t.Mode == BOTH {
- waitForDHCP := 3
- eg.Go(func() error {
- tick := time.NewTicker(time.Second)
- counter := 0
- defer func() {
- tick.Stop()
- logger.Debug("exeDHCPTest Done")
- }()
+ logger.Debug("StartTester type:%s called with key:%v", testtype, key)
+ child, cancel := context.WithCancel(tm.ctx)
+ t.ctx = child
+ t.cancel = cancel
+ go func() error {
+ tick := time.NewTicker(time.Second)
+ counter := 0
+ defer func() {
+ tick.Stop()
+ logger.Debug("Tester type:%s with key %v Done", testtype, key)
+ }()
- L:
- for counter < waitForDHCP {
- select{
- case <-tick.C:
- counter ++
- if counter == waitForDHCP { // TODO: This should be fixed
- break L
- }
- case <-child.Done():
- return nil
- }
+ L:
+ for counter < waitsec {
+ select{
+ case <-tick.C:
+ counter ++
+ if counter == waitsec { // TODO: This should be fixed
+ break L
}
- err := activateDHCPClient(key)
- if err != nil {
- return err
- }
+ case <-child.Done():
return nil
- })
+ }
}
- if err := eg.Wait(); err != nil {
+ err := t.Testfunc(key)
+ if err != nil {
return err
}
- }
- tm.testers[key] = t
+ return nil
+ }()
+
+ tm.testers[testtype][key] = t
return nil
}
-func (tm *TestManager) StopTester (key device.Devkey) error {
- ts := tm.testers[key]
+func (tm *TestManager) StopTester (testtype string, key device.Devkey) error {
+ ts := tm.testers[testtype][key]
ts.cancel()
- delete(tm.testers, key)
+ delete(tm.testers[testtype], key)
return nil
}