Skip to content

Commit

Permalink
New error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
louisroyer committed Dec 19, 2024
1 parent efad1a6 commit 6edcdaf
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
4 changes: 3 additions & 1 deletion internal/radio/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ import (
)

var (
ErrNilCtx = errors.New("nil context")
ErrNilCtx = errors.New("nil context")
ErrNilUdpConn = errors.New("nil UDP Connection")
ErrUnknownUE = errors.New("Unknown UE")
)
3 changes: 1 addition & 2 deletions internal/radio/radio.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"net"
"net/http"
"net/netip"
Expand Down Expand Up @@ -61,7 +60,7 @@ func (r *Radio) Write(pkt []byte, srv *net.UDPConn, ue jsonapi.ControlURI) error
ueRan, ok := r.peerMap.Load(ue)
if !ok {
logrus.Trace("Unknown UE")
return fmt.Errorf("Unknown UE")
return ErrUnknownUE
}

_, err := srv.WriteToUDPAddrPort(pkt, ueRan.(netip.AddrPort))
Expand Down
7 changes: 3 additions & 4 deletions internal/radio/radio_daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package radio

import (
"context"
"fmt"
"net"
"net/netip"

Expand Down Expand Up @@ -44,7 +43,7 @@ func NewRadioDaemon(radio *Radio, psMan *session.PduSessionsManager, gnbRanAddr
func (r *RadioDaemon) runUplinkDaemon(ctx context.Context, srv *net.UDPConn) error {
if srv == nil {
logrus.Error("nil server")
return fmt.Errorf("nil srv")
return ErrNilUdpConn
}
for {
select {
Expand All @@ -71,7 +70,7 @@ type DLPkt struct {

func (r *RadioDaemon) WriteDownlink(payload []byte, ue jsonapi.ControlURI) error {
if r.srv == nil {
return fmt.Errorf("nil srv")
return ErrNilUdpConn
}
return r.radio.Write(payload, r.srv, ue)
}
Expand All @@ -93,7 +92,7 @@ func (r *RadioDaemon) Start(ctx context.Context) error {
}).Info("Starting Radio Simulatior")
go func(ctx context.Context, srv *net.UDPConn) error {
if srv == nil {
return fmt.Errorf("nil srv")
return ErrNilUdpConn
}
select {
case <-ctx.Done():
Expand Down
3 changes: 3 additions & 0 deletions internal/session/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ import (

var (
ErrNilCtx = errors.New("nil context")

ErrUnsupportedPDUType = errors.New("Unsupported PDU type")
ErrPduSessionNotFound = errors.New("PDU Session not found")
)
9 changes: 4 additions & 5 deletions internal/session/pdu_sessions_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package session

import (
"context"
"fmt"
"math/rand"
"net"
"net/netip"
Expand Down Expand Up @@ -44,19 +43,19 @@ func NewPduSessionsManager(gtpAddr netip.Addr) *PduSessionsManager {
func (p *PduSessionsManager) WriteUplink(ctx context.Context, pkt []byte) error {
if len(pkt) < 20 {
logrus.Trace("too small to be an ipv4 packet")
return fmt.Errorf("Too small to be an ipv4 packet")
return ErrUnsupportedPDUType
}
if (pkt[0] >> 4) != 4 {
logrus.Trace("not an ipv4 packet")
return fmt.Errorf("Not an ipv4 packet")
return ErrUnsupportedPDUType
}
src := netip.AddrFrom4([4]byte{pkt[12], pkt[13], pkt[14], pkt[15]})
fteid, ok := p.Uplink[src]
if !ok {
logrus.WithFields(logrus.Fields{
"ue": src,
}).Trace("unknown UE")
return fmt.Errorf("Unknown UE")
return ErrPduSessionNotFound
}
gpdu := message.NewHeaderWithExtensionHeaders(0x30, message.MsgTypeTPDU, fteid.Teid, 0, pkt, []*message.ExtensionHeader{}...)
b, err := gpdu.Marshal()
Expand Down Expand Up @@ -94,7 +93,7 @@ func (p *PduSessionsManager) WriteUplink(ctx context.Context, pkt []byte) error
func (p *PduSessionsManager) GetUECtrl(teid uint32) (jsonapi.ControlURI, error) {
ueCtrl, ok := p.Downlink[teid]
if !ok {
return ueCtrl, fmt.Errorf("Unknown UE")
return ueCtrl, ErrPduSessionNotFound
}
return ueCtrl, nil
}
Expand Down

0 comments on commit 6edcdaf

Please sign in to comment.