Skip to content

Commit

Permalink
Enable gofumpt
Browse files Browse the repository at this point in the history
  • Loading branch information
gab-arrobo authored and thakurajayL committed Jan 26, 2024
1 parent ef3503e commit b6b41a8
Show file tree
Hide file tree
Showing 39 changed files with 379 additions and 435 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ linters:
# - nakedret
# - gci
- misspell
# - gofumpt
- gofumpt
# - whitespace
# - unconvert
# - predeclared
Expand Down
24 changes: 13 additions & 11 deletions common/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,29 @@ const (
* section 9.7 of 3GPP TS 24.501. This makes it easy to generate events
* corresponding to received NAS messages.
*/
const UE_5GS_MOBILITY_MANAGEMENT_EVENTS EventType = N1_EVENT + 64
const UE_5GS_SESSION_MANAGEMENT_EVENTS EventType = N1_EVENT + 192
const (
UE_5GS_MOBILITY_MANAGEMENT_EVENTS EventType = N1_EVENT + 64
UE_5GS_SESSION_MANAGEMENT_EVENTS EventType = N1_EVENT + 192
)

// 5GS Mobility Management events.
const (
_ EventType = UE_5GS_MOBILITY_MANAGEMENT_EVENTS + iota

REG_REQUEST_EVENT //65
REG_REQUEST_EVENT // 65
REG_ACCEPT_EVENT
REG_COMPLETE_EVENT
REG_REJECT_EVENT
DEREG_REQUEST_UE_ORIG_EVENT
DEREG_ACCEPT_UE_ORIG_EVENT
DEREG_REQUEST_UE_TERM_EVENT
DEREG_ACCEPT_UE_TERM_EVENT //72
DEREG_ACCEPT_UE_TERM_EVENT // 72

SERVICE_REQUEST_EVENT = UE_5GS_MOBILITY_MANAGEMENT_EVENTS + 3 + iota //76
SERVICE_REQUEST_EVENT = UE_5GS_MOBILITY_MANAGEMENT_EVENTS + 3 + iota // 76
SERVICE_REJECT_EVENT
SERVICE_ACCEPT_EVENT //78
SERVICE_ACCEPT_EVENT // 78

AUTH_REQUEST_EVENT = UE_5GS_MOBILITY_MANAGEMENT_EVENTS + 10 + iota //86
AUTH_REQUEST_EVENT = UE_5GS_MOBILITY_MANAGEMENT_EVENTS + 10 + iota // 86
AUTH_RESPONSE_EVENT
AUTH_REJECT_EVENT
AUTH_FAILURE_EVENT
Expand All @@ -111,9 +113,9 @@ const (
ID_RESPONSE_EVENT
SEC_MOD_COMMAND_EVENT
SEC_MOD_COMPLETE_EVENT
SEC_MOD_REJECT_EVENT //95
SEC_MOD_REJECT_EVENT // 95

FIVE_GMM_STATUS_EVENT = UE_5GS_MOBILITY_MANAGEMENT_EVENTS + 14 + iota //86
FIVE_GMM_STATUS_EVENT = UE_5GS_MOBILITY_MANAGEMENT_EVENTS + 14 + iota // 86
NOTIFICATION_EVENT
NOTIFICATION_RESPONSE_EVENT
UL_NAS_TRANSPORT_EVENT
Expand All @@ -124,7 +126,7 @@ const (
const (
_ EventType = UE_5GS_SESSION_MANAGEMENT_EVENTS + iota

PDU_SESS_EST_REQUEST_EVENT //193
PDU_SESS_EST_REQUEST_EVENT // 193
PDU_SESS_EST_ACCEPT_EVENT
PDU_SESS_EST_REJECT_EVENT

Expand All @@ -143,7 +145,7 @@ const (
PDU_SESS_REL_COMMAND_EVENT
PDU_SESS_REL_COMPLETE_EVENT

FIVEGSM_STATUS_EVENT = UE_5GS_SESSION_MANAGEMENT_EVENTS + 6 + iota //214
FIVEGSM_STATUS_EVENT = UE_5GS_SESSION_MANAGEMENT_EVENTS + 6 + iota // 214
)

// Events between GNodeB and AMF (N2)
Expand Down
1 change: 0 additions & 1 deletion factory/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func (c *Config) GetVersion() string {
}

func (c *Config) Validate() (err error) {

if c.Info == nil {
return fmt.Errorf("Info field missing")
}
Expand Down
13 changes: 6 additions & 7 deletions gnbsim.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package main
import (
"fmt"
"net/http"
_ "net/http/pprof" //Using package only for invoking initialization.
_ "net/http/pprof" // Using package only for invoking initialization.
"os"
"os/signal"
"sync"
Expand Down Expand Up @@ -43,7 +43,6 @@ func main() {
}

func action(c *cli.Context) error {

cfg := c.String("cfg")
if cfg == "" {
logger.AppLog.Warnln("No configuration file provided. Using default configuration file:", factory.GNBSIM_DEFAULT_CONFIG_PATH)
Expand All @@ -58,7 +57,7 @@ func action(c *cli.Context) error {

config := factory.AppConfig

//Initiating a server for profiling
// Initiating a server for profiling
if config.Configuration.GoProfile.Enable == true {
go func() {
endpt := fmt.Sprintf(":%v", config.Configuration.GoProfile.Port)
Expand Down Expand Up @@ -108,10 +107,10 @@ func action(c *cli.Context) error {
}()
}

//This configuration enables running the configured profiles
//when gnbsim is started. It is enabled by default. If we want no
//profiles to run and gnbsim to wait for a command, then we
//should disable this config.
// This configuration enables running the configured profiles
// when gnbsim is started. It is enabled by default. If we want no
// profiles to run and gnbsim to wait for a command, then we
// should disable this config.
if config.Configuration.RunConfigProfilesAtStart {
var profileWaitGrp sync.WaitGroup
// start profile and wait for it to finish (success or failure)
Expand Down
12 changes: 8 additions & 4 deletions gnodeb/context/gnbamf.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@ func NewGnbAmf(ip string, port int) *GnbAmf {
gnbAmf := &GnbAmf{}
gnbAmf.AmfIp = ip
gnbAmf.AmfPort = port
gnbAmf.Log = logger.GNodeBLog.WithFields(logrus.Fields{"subcategory": "GnbAmf",
logger.FieldIp: gnbAmf.AmfIp})
gnbAmf.Log = logger.GNodeBLog.WithFields(logrus.Fields{
"subcategory": "GnbAmf",
logger.FieldIp: gnbAmf.AmfIp,
})
return gnbAmf
}

func (amf *GnbAmf) Init() {
amf.Log = logger.GNodeBLog.WithFields(logrus.Fields{"subcategory": "GnbAmf",
logger.FieldIp: amf.AmfIp})
amf.Log = logger.GNodeBLog.WithFields(logrus.Fields{
"subcategory": "GnbAmf",
logger.FieldIp: amf.AmfIp,
})
}

func (amf *GnbAmf) GetIpAddr() string {
Expand Down
6 changes: 4 additions & 2 deletions gnodeb/context/gnbcpue.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ func NewGnbCpUe(ngapId int64, gnb *GNodeB, amf *GnbAmf) *GnbCpUe {
gnbue.Amf = amf
gnbue.Gnb = gnb
gnbue.ReadChan = make(chan common.InterfaceMessage, 5)
gnbue.Log = logger.GNodeBLog.WithFields(logrus.Fields{"subcategory": "GnbCpUe",
logger.FieldGnbUeNgapId: ngapId})
gnbue.Log = logger.GNodeBLog.WithFields(logrus.Fields{
"subcategory": "GnbCpUe",
logger.FieldGnbUeNgapId: ngapId,
})
gnbue.Log.Traceln("Context Created")
return &gnbue
}
Expand Down
6 changes: 3 additions & 3 deletions gnodeb/context/gnbuedao.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/sirupsen/logrus"
)

//TODO: Need to separate out the DAOs
// TODO: Need to separate out the DAOs

// GnbUeDao acts as a Data Access Object that stores and provides access to all
// the GNodeB instances
Expand All @@ -22,8 +22,8 @@ type GnbUeDao struct {

/* logger */
Log *logrus.Entry
//TODO:
//ulTeidGnbUpUeMap sync.Map
// TODO:
// ulTeidGnbUpUeMap sync.Map
// This map will be helpful when gNb receives an ErrorIndication Message
// which will have an UL TEID. In which case gNb can fetch and delete the
// GnbUpUe context corresponding to that UL TEID
Expand Down
6 changes: 4 additions & 2 deletions gnodeb/context/gnbupf.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ type GnbUpf struct {
func NewGnbUpf(ip string) *GnbUpf {
gnbupf := &GnbUpf{}

gnbupf.Log = logger.GNodeBLog.WithFields(logrus.Fields{"subcategory": "GnbUpf",
logger.FieldIp: ip})
gnbupf.Log = logger.GNodeBLog.WithFields(logrus.Fields{
"subcategory": "GnbUpf",
logger.FieldIp: ip,
})

ipPort := net.JoinHostPort(ip, strconv.Itoa(GTP_U_PORT))
addr, err := net.ResolveUDPAddr("udp", ipPort)
Expand Down
6 changes: 4 additions & 2 deletions gnodeb/context/gnbupue.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ func NewGnbUpUe(dlTeid, ulTeid uint32, gnb *GNodeB) *GnbUpUe {
gnbue.ReadUlChan = make(chan common.InterfaceMessage, 10)
gnbue.ReadDlChan = make(chan common.InterfaceMessage, 10)
gnbue.ReadCmdChan = make(chan common.InterfaceMessage, 5)
gnbue.Log = logger.GNodeBLog.WithFields(logrus.Fields{"subcategory": "GnbUpUe",
logger.FieldDlTeid: dlTeid})
gnbue.Log = logger.GNodeBLog.WithFields(logrus.Fields{
"subcategory": "GnbUpUe",
logger.FieldDlTeid: dlTeid,
})
gnbue.Log.Traceln("Context Created")
return &gnbue
}
Expand Down
2 changes: 1 addition & 1 deletion gnodeb/context/gnodeb.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// GNodeB holds the context for a gNodeB. It manages the control plane and
// user plane layer of a gNodeB.
type GNodeB struct {
//TODO IP and port should be the property of transport var
// TODO IP and port should be the property of transport var
GnbN2Ip string `yaml:"n2IpAddr"`
GnbN2Port int `yaml:"n2Port"`
GnbN3Ip string `yaml:"n3IpAddr"`
Expand Down
4 changes: 2 additions & 2 deletions gnodeb/gnodeb.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ func RequestConnection(gnb *gnbctx.GNodeB, uemsg *common.UuMessage) (chan common
defer wg.Done()
gnbcpueworker.Init(gnbUe)
}()
//Channel on which UE can write message to GnbUe and from which GnbUe will
//be reading.
// Channel on which UE can write message to GnbUe and from which GnbUe will
// be reading.
ch := gnbUe.ReadChan
ch <- uemsg
return ch, nil
Expand Down
1 change: 0 additions & 1 deletion gnodeb/ngap/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
)

func GetNGSetupRequest(gnb *gnbctx.GNodeB) ([]byte, error) {

message := ngapTestpacket.BuildNGSetupRequest()

// GlobalRANNodeID
Expand Down
17 changes: 8 additions & 9 deletions gnodeb/transport/cptransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
// Need to check if NGAP may exceed this limit
var MAX_SCTP_PKT_LEN int = 2048

//TODO: Should have a context variable which when cancelled will result in
// TODO: Should have a context variable which when cancelled will result in
// the termination of the ReceiveFromPeer handler

// GnbCpTransport represents the control plane transport of the GNodeB
Expand Down Expand Up @@ -73,13 +73,13 @@ func (cpTprt *GnbCpTransport) ConnectToPeer(peer transportcommon.TransportPeer)
return
}

//TODO Should add timeout
// TODO Should add timeout

// SendToPeer sends an NGAP encoded packet to the specified AMF over the socket
// connection and waits for the response
func (cpTprt *GnbCpTransport) SendToPeerBlock(peer transportcommon.TransportPeer,
pkt []byte) ([]byte, error) {

pkt []byte,
) ([]byte, error) {
err := cpTprt.SendToPeer(peer, pkt)
if err != nil {
cpTprt.Log.Errorln("SendToPeer returned err:", err)
Expand All @@ -104,8 +104,8 @@ func (cpTprt *GnbCpTransport) SendToPeerBlock(peer transportcommon.TransportPeer
// SendToPeer sends an NGAP encoded packet to the specified AMF over the socket
// connection
func (cpTprt *GnbCpTransport) SendToPeer(peer transportcommon.TransportPeer,
pkt []byte) (err error) {

pkt []byte,
) (err error) {
err = cpTprt.CheckTransportParam(peer, pkt)
if err != nil {
return err
Expand Down Expand Up @@ -140,13 +140,12 @@ func (cpTprt *GnbCpTransport) ReceiveFromPeer(peer transportcommon.TransportPeer
if err := amf.Conn.Close(); err != nil && err != syscall.EBADF {
cpTprt.Log.Errorln("Close returned:", err)
}

}()

conn := amf.Conn.(*sctp.SCTPConn)
for {
recvMsg := make([]byte, MAX_SCTP_PKT_LEN)
//TODO Handle notification, info
// TODO Handle notification, info
n, _, _, err := conn.SCTPRead(recvMsg)
if err != nil {
switch err {
Expand All @@ -166,7 +165,7 @@ func (cpTprt *GnbCpTransport) ReceiveFromPeer(peer transportcommon.TransportPeer
}

cpTprt.Log.Infof("Read %v bytes from %v\n", n, amf.GetIpAddr())
//TODO Post to gnbamfworker channel
// TODO Post to gnbamfworker channel
gnbamfworker.HandleMessage(cpTprt.GnbInstance, amf, recvMsg[:n])
}
}
Expand Down
12 changes: 6 additions & 6 deletions gnodeb/transport/uptransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// Need to check if NGAP may exceed this limit
var MAX_UDP_PKT_LEN int = 65507

//TODO: Should have a context variable which when cancelled will result in
// TODO: Should have a context variable which when cancelled will result in
// the termination of the ReceiveFromPeer handler

// GnbUpTransport represents the User Plane transport of the GNodeB
Expand Down Expand Up @@ -65,8 +65,8 @@ func (upTprt *GnbUpTransport) Init() error {

// SendToPeer sends a GTP-U encoded packet to the specified UPF over the socket
func (upTprt *GnbUpTransport) SendToPeer(peer transportcommon.TransportPeer,
pkt []byte) (err error) {

pkt []byte,
) (err error) {
err = upTprt.CheckTransportParam(peer, pkt)
if err != nil {
return err
Expand All @@ -93,7 +93,7 @@ func (upTprt *GnbUpTransport) SendToPeer(peer transportcommon.TransportPeer,
func (upTprt *GnbUpTransport) ReceiveFromPeer(peer transportcommon.TransportPeer) {
for {
recvMsg := make([]byte, MAX_UDP_PKT_LEN)
//TODO Handle notification, info
// TODO Handle notification, info
n, srcAddr, err := upTprt.Conn.ReadFromUDP(recvMsg)
if err != nil {
upTprt.Log.Errorln("ReadFromUDP returned:", err)
Expand All @@ -114,8 +114,8 @@ func (upTprt *GnbUpTransport) ReceiveFromPeer(peer transportcommon.TransportPeer
}

func (upTprt *GnbUpTransport) CheckTransportParam(peer transportcommon.TransportPeer,
pkt []byte) error {

pkt []byte,
) error {
upf := peer.(*gnbctx.GnbUpf)

if upf == nil {
Expand Down
17 changes: 10 additions & 7 deletions gnodeb/worker/gnbamfworker/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ func HandleNgSetupFailure(amf *gnbctx.GnbAmf, pdu *ngapType.NGAPPDU) {
}

func HandleDownlinkNasTransport(gnb *gnbctx.GNodeB, amf *gnbctx.GnbAmf,
pdu *ngapType.NGAPPDU) {

pdu *ngapType.NGAPPDU,
) {
if amf == nil {
amf = new(gnbctx.GnbAmf)
amf.Log.Errorln("ran is nil")
Expand Down Expand Up @@ -258,8 +258,8 @@ func HandleDownlinkNasTransport(gnb *gnbctx.GNodeB, amf *gnbctx.GnbAmf,
}

func HandleInitialContextSetupRequest(gnb *gnbctx.GNodeB, amf *gnbctx.GnbAmf,
pdu *ngapType.NGAPPDU) {

pdu *ngapType.NGAPPDU,
) {
if amf == nil {
amf = new(gnbctx.GnbAmf)
amf.Log.Errorln("ran is nil")
Expand Down Expand Up @@ -311,7 +311,8 @@ func HandleInitialContextSetupRequest(gnb *gnbctx.GNodeB, amf *gnbctx.GnbAmf,

// TODO : Much of the code is repeated in each handler
func HandlePduSessResourceSetupRequest(gnb *gnbctx.GNodeB, amf *gnbctx.GnbAmf,
pdu *ngapType.NGAPPDU) {
pdu *ngapType.NGAPPDU,
) {
if amf == nil {
amf = new(gnbctx.GnbAmf)
amf.Log.Errorln("ran is nil")
Expand Down Expand Up @@ -361,7 +362,8 @@ func HandlePduSessResourceSetupRequest(gnb *gnbctx.GNodeB, amf *gnbctx.GnbAmf,
}

func HandlePduSessResourceReleaseCommand(gnb *gnbctx.GNodeB, amf *gnbctx.GnbAmf,
pdu *ngapType.NGAPPDU) {
pdu *ngapType.NGAPPDU,
) {
if amf == nil {
amf = new(gnbctx.GnbAmf)
amf.Log.Errorln("ran is nil")
Expand Down Expand Up @@ -411,7 +413,8 @@ func HandlePduSessResourceReleaseCommand(gnb *gnbctx.GNodeB, amf *gnbctx.GnbAmf,
}

func HandleUeCtxReleaseCommand(gnb *gnbctx.GNodeB, amf *gnbctx.GnbAmf,
pdu *ngapType.NGAPPDU) {
pdu *ngapType.NGAPPDU,
) {
if amf == nil {
amf = new(gnbctx.GnbAmf)
amf.Log.Errorln("ran is nil")
Expand Down

0 comments on commit b6b41a8

Please sign in to comment.