Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
louisroyer committed Dec 10, 2024
1 parent 96f5057 commit 06405f2
Show file tree
Hide file tree
Showing 10 changed files with 260 additions and 215 deletions.
32 changes: 18 additions & 14 deletions internal/app/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
"net/netip"
"time"

"github.com/nextmn/ue-lite/internal/cli"
"github.com/nextmn/ue-lite/internal/radio"
"github.com/nextmn/ue-lite/internal/session"

"github.com/nextmn/json-api/healthcheck"

"github.com/gin-gonic/gin"
Expand All @@ -20,36 +24,36 @@ import (

type HttpServerEntity struct {
srv *http.Server
ps *PduSessions
radio *Radio
cli *Cli
ps *session.PduSessions
radio *radio.Radio
cli *cli.Cli
}

func NewHttpServerEntity(bindAddr netip.AddrPort, radio *Radio, ps *PduSessions) *HttpServerEntity {
cli := NewCli(radio, ps)
func NewHttpServerEntity(bindAddr netip.AddrPort, r *radio.Radio, ps *session.PduSessions) *HttpServerEntity {
c := cli.NewCli(r, ps)
// TODO: gin.SetMode(gin.DebugMode) / gin.SetMode(gin.ReleaseMode) depending on log level
r := gin.Default()
r.GET("/status", Status)
h := gin.Default()
h.GET("/status", Status)

// CLI
r.POST("/cli/radio/peer", cli.RadioPeer)
r.POST("/cli/ps/establish", cli.PsEstablish)
h.POST("/cli/radio/peer", c.RadioPeer)
h.POST("/cli/ps/establish", c.PsEstablish)

// Radio
r.POST("/radio/peer", radio.Peer)
h.POST("/radio/peer", r.Peer)

// Pdu Session
r.POST("/ps/establishment-accept", ps.EstablishmentAccept)
h.POST("/ps/establishment-accept", ps.EstablishmentAccept)

logrus.WithFields(logrus.Fields{"http-addr": bindAddr}).Info("HTTP Server created")
e := HttpServerEntity{
srv: &http.Server{
Addr: bindAddr.String(),
Handler: r,
Handler: h,
},
ps: ps,
radio: radio,
cli: cli,
radio: r,
cli: c,
}
return &e
}
Expand Down
128 changes: 0 additions & 128 deletions internal/app/radio_daemon.go

This file was deleted.

32 changes: 19 additions & 13 deletions internal/app/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,44 @@ import (
"context"

"github.com/nextmn/ue-lite/internal/config"
"github.com/nextmn/ue-lite/internal/radio"
"github.com/nextmn/ue-lite/internal/session"
"github.com/nextmn/ue-lite/internal/tun"
)

type Setup struct {
config *config.UEConfig
httpServerEntity *HttpServerEntity
radioDaemon *RadioDaemon
psMan *PduSessionsManager
tunMan *TunManager
radioDaemon *radio.RadioDaemon
ps *session.PduSessions
tunMan *tun.TunManager
}

func NewSetup(config *config.UEConfig) *Setup {
radio := NewRadio(config.Control.Uri, config.Ran.BindAddr, "go-github-nextmn-ue-lite")
psMan := NewPduSessionsManager(radio)
ps := NewPduSessions(config.Control.Uri, psMan, "go-github-nextmn-ue-lite")
r := radio.NewRadio(config.Control.Uri, config.Ran.BindAddr, "go-github-nextmn-ue-lite")
tunMan := tun.NewTunManager()
psMan := session.NewPduSessionsManager(tunMan)
ps := session.NewPduSessions(config.Control.Uri, psMan, config.Ran.PDUSessions, "go-github-nextmn-ue-lite")
return &Setup{
config: config,
httpServerEntity: NewHttpServerEntity(config.Control.BindAddr, radio, ps),
radioDaemon: NewRadioDaemon(config.Control.Uri, config.Ran.Gnbs, config.Ran.PDUSessions, radio, ps, psMan, config.Ran.BindAddr),
psMan: psMan,
tunMan: NewTunManager(),
httpServerEntity: NewHttpServerEntity(config.Control.BindAddr, r, ps),
radioDaemon: radio.NewRadioDaemon(config.Control.Uri, config.Ran.Gnbs, r, psMan, tunMan, config.Ran.BindAddr),
ps: ps,
tunMan: tunMan,
}
}

func (s *Setup) Init(ctx context.Context) error {
if err := s.httpServerEntity.Start(); err != nil {
return err
}
tun, err := s.tunMan.Start(ctx)
if err != nil {
if err := s.tunMan.Start(ctx); err != nil {
return err
}
if err := s.radioDaemon.Start(ctx, tun); err != nil {
if err := s.radioDaemon.Start(ctx); err != nil {
return err
}
if err := s.ps.Start(ctx); err != nil {
return err
}
return nil
Expand Down
11 changes: 7 additions & 4 deletions internal/app/cli.go → internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@
// found in the LICENSE file.
// SPDX-License-Identifier: MIT

package app
package cli

import (
"net/http"

"github.com/nextmn/json-api/jsonapi"

"github.com/nextmn/ue-lite/internal/radio"
"github.com/nextmn/ue-lite/internal/session"

"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)

type Cli struct {
Radio *Radio
PduSessions *PduSessions
Radio *radio.Radio
PduSessions *session.PduSessions
}

func NewCli(radio *Radio, pduSessions *PduSessions) *Cli {
func NewCli(radio *radio.Radio, pduSessions *session.PduSessions) *Cli {
return &Cli{
Radio: radio,
PduSessions: pduSessions,
Expand Down
2 changes: 1 addition & 1 deletion internal/app/radio.go → internal/radio/radio.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// found in the LICENSE file.
// SPDX-License-Identifier: MIT

package app
package radio

import (
"bytes"
Expand Down
Loading

0 comments on commit 06405f2

Please sign in to comment.