Adding delay between ONU operations
Change-Id: I3442325e3b4ad9d0fe77b0182f16d3db42e5f0a1
diff --git a/core/core_server.go b/core/core_server.go
index 8b52e49..76c219f 100644
--- a/core/core_server.go
+++ b/core/core_server.go
@@ -17,6 +17,12 @@
package core
import (
+ "errors"
+ "log"
+ "strconv"
+ "sync"
+ "time"
+
"gerrit.opencord.org/voltha-bbsim/device"
"gerrit.opencord.org/voltha-bbsim/protos"
"gerrit.opencord.org/voltha-bbsim/setup"
@@ -24,11 +30,6 @@
"github.com/google/gopacket/layers"
"github.com/google/gopacket/pcap"
"google.golang.org/grpc"
- "errors"
- "log"
- "strconv"
- "sync"
- "time"
)
type Mode int
@@ -50,6 +51,7 @@
AAAWait int
DhcpWait int
DhcpServerIP string
+ Delay int
gRPCserver *grpc.Server
VethEnv []string
TestFlag bool
@@ -63,7 +65,7 @@
Pkt gopacket.Packet
}
-func (s *Server)Initialize(){
+func (s *Server) Initialize() {
s.VethEnv = []string{}
s.Endchan = make(chan int)
s.TestFlag = false
@@ -71,7 +73,7 @@
s.Ioinfos = []*Ioinfo{}
}
-func Create(oltid uint32, npon uint32, nonus uint32, aaawait int, dhcpwait int, ip string, g *grpc.Server, mode Mode, e chan int) *Server {
+func Create(oltid uint32, npon uint32, nonus uint32, aaawait int, dhcpwait int, ip string, delay int, g *grpc.Server, mode Mode, e chan int) *Server {
s := new(Server)
s.Olt = device.CreateOlt(oltid, npon, 1)
nnni := s.Olt.NumNniIntf
@@ -81,6 +83,7 @@
s.DhcpWait = dhcpwait
s.DhcpServerIP = ip
s.gRPCserver = g
+ s.Delay = delay
s.Mode = mode
s.Endchan = e
s.VethEnv = []string{}
@@ -92,11 +95,11 @@
//TODO: To be fixed
s.CtagMap = make(map[string]uint32)
- for i := 0; i < MAX_ONUS_PER_PON; i ++ {
+ for i := 0; i < MAX_ONUS_PER_PON; i++ {
oltid := s.Olt.ID
intfid := uint32(1)
sn := convB2S(device.CreateSN(oltid, intfid, uint32(i)))
- s.CtagMap[sn] = uint32(900 + i) // This is hard coded for BBWF
+ s.CtagMap[sn] = uint32(900 + i) // This is hard coded for BBWF
}
return s
}
@@ -148,7 +151,7 @@
}
for intfid, _ := range s.Onumap {
- sendOnuInd(stream, s.Onumap[intfid])
+ sendOnuInd(stream, s.Onumap[intfid], s.Delay)
log.Printf("OLT id:%d sent ONUInd.\n", olt.ID)
}
@@ -168,7 +171,7 @@
errchan := make(chan error)
go func() {
- <- errchan
+ <-errchan
close(s.Endchan)
}()
@@ -222,7 +225,7 @@
return nil
}
-func createIoinfos(oltid uint32, vethenv []string, onumap map[uint32][]*device.Onu)([]*Ioinfo, []string, error){
+func createIoinfos(oltid uint32, vethenv []string, onumap map[uint32][]*device.Onu) ([]*Ioinfo, []string, error) {
ioinfos := []*Ioinfo{}
var err error
for intfid, _ := range onumap {
@@ -309,7 +312,7 @@
//C-TAG
onu, _ := s.getOnuByID(onuid)
sn := convB2S(onu.SerialNumber.VendorSpecific)
- if ctag, ok := s.CtagMap[sn]; ok == true{
+ if ctag, ok := s.CtagMap[sn]; ok == true {
tagpkt, err := PushVLAN(pkt, uint16(ctag))
if err != nil {
log.Println("Error happend in C-tag tagging")
@@ -373,14 +376,14 @@
univeths = append(univeths, info.name)
}
- for {
+ for {
select {
case <-s.Endchan:
log.Println("exeAAATest thread receives close !")
return nil
- case <- time.After(time.Second * time.Duration(s.AAAWait)):
+ case <-time.After(time.Second * time.Duration(s.AAAWait)):
log.Println("exeAAATest Start")
- err = setup.ActivateWPASups(univeths)
+ err = setup.ActivateWPASups(univeths, s.Delay)
if err != nil {
return err
}
@@ -416,14 +419,14 @@
univeths = append(univeths, info.name)
}
- for {
+ for {
select {
case <-s.Endchan:
log.Println("exeDHCPTest thread receives close !")
return nil
- case <- time.After(time.Second * time.Duration(s.DhcpWait)):
+ case <-time.After(time.Second * time.Duration(s.DhcpWait)):
log.Println("exeDHCPTest Start")
- err = setup.ActivateDHCPClients(univeths)
+ err = setup.ActivateDHCPClients(univeths, s.Delay)
if err != nil {
return err
}
@@ -479,7 +482,7 @@
return nil
}
-func (s *Server)IsAllOnuActive(regonus map[uint32][]*device.Onu) bool {
+func (s *Server) IsAllOnuActive(regonus map[uint32][]*device.Onu) bool {
for _, onus := range regonus {
for _, onu := range onus {
if onu.GetIntStatus() != device.ONU_ACTIVATED {
@@ -543,7 +546,7 @@
}
func killProcesses(pnames []string) error {
- for _, pname := range pnames {
+ for _, pname := range pnames {
setup.KillProcess(pname)
}
return nil
@@ -584,7 +587,7 @@
func convB2S(b []byte) string {
s := ""
for _, i := range b {
- s = s + strconv. FormatInt(int64(i/16), 16) + strconv. FormatInt(int64(i%16), 16)
+ s = s + strconv.FormatInt(int64(i/16), 16) + strconv.FormatInt(int64(i%16), 16)
}
return s
-}
\ No newline at end of file
+}
diff --git a/core/openolt_service.go b/core/openolt_service.go
index dbb7644..a0d00bf 100644
--- a/core/openolt_service.go
+++ b/core/openolt_service.go
@@ -17,9 +17,11 @@
package core
import (
- "gerrit.opencord.org/voltha-bbsim/protos"
- "gerrit.opencord.org/voltha-bbsim/device"
"log"
+ "time"
+
+ "gerrit.opencord.org/voltha-bbsim/device"
+ "gerrit.opencord.org/voltha-bbsim/protos"
)
func sendOltIndUp(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error {
@@ -43,7 +45,7 @@
func sendIntfInd(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error {
for i := uint32(0); i < olt.NumPonIntf+olt.NumNniIntf; i++ {
intf := olt.Intfs[i]
- if intf.Type == "pon"{ // There is no need to send IntfInd for NNI
+ if intf.Type == "pon" { // There is no need to send IntfInd for NNI
data := &openolt.Indication_IntfInd{&openolt.IntfIndication{IntfId: intf.IntfID, OperState: intf.OperState}}
if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
log.Printf("Failed to send Intf [id: %d] indication : %v\n", i, err)
@@ -80,8 +82,9 @@
return nil
}
-func sendOnuInd(stream openolt.Openolt_EnableIndicationServer, onus []*device.Onu) error {
+func sendOnuInd(stream openolt.Openolt_EnableIndicationServer, onus []*device.Onu, delay int) error {
for i, onu := range onus {
+ time.Sleep(time.Duration(delay) * time.Second)
data := &openolt.Indication_OnuInd{&openolt.OnuIndication{IntfId: onu.IntfID, OnuId: onu.OnuID, OperState: "up", AdminState: "up", SerialNumber: onu.SerialNumber}}
log.Printf("sendONUInd Onuid: %d\n", i)
if err := stream.Send(&openolt.Indication{Data: data}); err != nil {