Skip to content

Commit

Permalink
Use gnbId from config.yml as first gNB's ID, Fix #48
Browse files Browse the repository at this point in the history
Signed-off-by: Valentin <[email protected]>
  • Loading branch information
linouxis9 committed Dec 23, 2023
1 parent c105608 commit 09d97e1
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions internal/common/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ func CreateGnbs(count int, cfg config.Config, wg *sync.WaitGroup) map[string]*gn
// gnb[0].n2_ip = 192.168.2.10, gnb[0].n3_ip = 192.168.3.10
// gnb[1].n2_ip = 192.168.2.11, gnb[1].n3_ip = 192.168.3.11
// ...
gnbId := cfg.GNodeB.PlmnList.GnbId
n2Ip := cfg.GNodeB.ControlIF.Ip
n3Ip := cfg.GNodeB.DataIF.Ip
for i := 1; i <= count; i++ {
cfg.GNodeB.PlmnList.GnbId = gnbIdGenerator(i)
cfg.GNodeB.PlmnList.GnbId = gnbId
cfg.GNodeB.ControlIF.Ip = n2Ip
cfg.GNodeB.DataIF.Ip = n3Ip

Expand All @@ -42,6 +43,7 @@ func CreateGnbs(count int, cfg config.Config, wg *sync.WaitGroup) map[string]*gn

// TODO: We could find the interfaces where N2/N3 are
// and check that the generated IPs, still belong to the interfaces' subnet
gnbId = gnbIdGenerator(i, gnbId)
n2Ip, err = IncrementIP(n2Ip, "0.0.0.0/0")
if err != nil {
log.Fatal("[GNB][CONFIG] Error while allocating ip for N2: " + err.Error())
Expand All @@ -50,7 +52,6 @@ func CreateGnbs(count int, cfg config.Config, wg *sync.WaitGroup) map[string]*gn
if err != nil {
log.Fatal("[GNB][CONFIG] Error while allocating ip for N3: " + err.Error())
}

}
return gnbs
}
Expand All @@ -73,19 +74,15 @@ func IncrementIP(origIP, cidr string) (string, error) {
return ip.String(), nil
}

func gnbIdGenerator(i int) string {
func gnbIdGenerator(i int, gnbId string) string {

var base string
switch true {
case i < 10:
base = "00000"
case i < 100:
base = "0000"
case i >= 100:
base = "000"
gnbId_int, err := strconv.Atoi(gnbId)
if err != nil {
log.Fatal("[UE][CONFIG] Given gnbId is invalid")
}
base := gnbId_int + i

gnbId := base + strconv.Itoa(i)
gnbId = fmt.Sprintf("%06d", base)
return gnbId
}

Expand Down Expand Up @@ -115,7 +112,7 @@ func SimulateSingleUE(simConfig UESimulationConfig, wg *sync.WaitGroup) {
ueCfg.Ue.Msin = IncrementMsin(simConfig.UeId, simConfig.Cfg.Ue.Msin)
log.Info("[TESTER] TESTING REGISTRATION USING IMSI ", ueCfg.Ue.Msin, " UE")

ueCfg.GNodeB.PlmnList.GnbId = gnbIdGenerator(simConfig.UeId%numGnb + 1)
ueCfg.GNodeB.PlmnList.GnbId = gnbIdGenerator(simConfig.UeId%numGnb, ueCfg.GNodeB.PlmnList.GnbId)

// Launch a coroutine to handle UE's individual scenario
go func(scenarioChan chan procedures.UeTesterMessage, ueId int) {
Expand Down Expand Up @@ -150,7 +147,7 @@ func SimulateSingleUE(simConfig UESimulationConfig, wg *sync.WaitGroup) {
}
case <-handoverChannel:
if ueRx != nil {
ueRx <- procedures.UeTesterMessage{Type: procedures.Handover, GnbChan: simConfig.Gnbs[gnbIdGenerator((ueId+1)%numGnb+1)].GetInboundChannel()}
ueRx <- procedures.UeTesterMessage{Type: procedures.Handover, GnbChan: simConfig.Gnbs[gnbIdGenerator((ueId+1)%numGnb, ueCfg.GNodeB.PlmnList.GnbId)].GetInboundChannel()}
}
case msg := <-scenarioChan:
if ueRx != nil {
Expand Down

0 comments on commit 09d97e1

Please sign in to comment.