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 68f0f80 commit bbe3e25
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
8 changes: 7 additions & 1 deletion internal/radio/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@ import (
)

var (
ErrNilCtx = errors.New("nil context")
ErrNilCtx = errors.New("nil context")
ErrNilTunIface = errors.New("nil TUN interface")
ErrNilUdpConn = errors.New("nil UDP Connection")
ErrUnknownGnb = errors.New("Unknown gNB")

ErrUnsupportedPDUType = errors.New("Unsupported PDU Type")
ErrMalformedPDU = errors.New("Malformed PDU")
)
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 @@ -47,7 +46,7 @@ func (r *Radio) Write(pkt []byte, srv *net.UDPConn, gnb jsonapi.ControlURI) erro
gnbRan, ok := r.peerMap.Load(gnb)
if !ok {
logrus.Trace("Unknown gnb")
return fmt.Errorf("Unknown gnb")
return ErrUnknownGnb
}

_, err := srv.WriteToUDPAddrPort(pkt, gnbRan.(netip.AddrPort))
Expand Down
17 changes: 8 additions & 9 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 @@ -45,10 +44,10 @@ func NewRadioDaemon(control jsonapi.ControlURI, gnbs []jsonapi.ControlURI, radio

func (r *RadioDaemon) runDownlinkDaemon(ctx context.Context, srv *net.UDPConn, ifacetun *water.Interface) error {
if srv == nil {
return fmt.Errorf("nil srv")
return ErrNilUdpConn
}
if ifacetun == nil {
return fmt.Errorf("nil tun iface")
return ErrNilTunIface
}
for {
select {
Expand All @@ -68,10 +67,10 @@ func (r *RadioDaemon) runDownlinkDaemon(ctx context.Context, srv *net.UDPConn, i

func (r *RadioDaemon) runUplinkDaemon(ctx context.Context, srv *net.UDPConn, ifacetun *water.Interface) error {
if srv == nil {
return fmt.Errorf("nil srv")
return ErrNilUdpConn
}
if ifacetun == nil {
return fmt.Errorf("nil tun iface")
return ErrNilTunIface
}
for {
select {
Expand All @@ -86,11 +85,11 @@ func (r *RadioDaemon) runUplinkDaemon(ctx context.Context, srv *net.UDPConn, ifa

// get UE IP Address
if !waterutil.IsIPv4(buf[:n]) {
return fmt.Errorf("not an IPv4 packet")
return ErrUnsupportedPDUType
}
src, ok := netip.AddrFromSlice(waterutil.IPv4Source(buf[:n]).To4())
if !ok {
return fmt.Errorf("error while retrieving ip addr")
return ErrMalformedPDU
}

// get gNB linked to UE
Expand All @@ -102,7 +101,7 @@ func (r *RadioDaemon) runUplinkDaemon(ctx context.Context, srv *net.UDPConn, ifa
logrus.WithFields(
logrus.Fields{
"ip-addr": src,
}).Trace("packet forwarded")
}).Trace("Packet forwarded")
}
}
}
Expand All @@ -128,7 +127,7 @@ func (r *RadioDaemon) Start(ctx context.Context) error {
}
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: 2 additions & 1 deletion internal/session/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ import (
)

var (
ErrNilCtx = errors.New("nil context")
ErrNilCtx = errors.New("nil context")
ErrPduSessionNotFound = errors.New("No PDU Session found for this IP Address")
)
3 changes: 1 addition & 2 deletions internal/session/pdu_sessions_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package session

import (
"fmt"
"net/netip"
"sync"

Expand Down Expand Up @@ -39,7 +38,7 @@ func (p *PduSessionsManager) LinkedGnb(src netip.Addr) (jsonapi.ControlURI, erro
logrus.Fields{
"ip-addr": src,
}).Trace("no pdu session found for this ip address")
return jsonapi.ControlURI{}, fmt.Errorf("no pdu session found for this ip address")
return jsonapi.ControlURI{}, ErrPduSessionNotFound
}
return gnb, nil

Expand Down

0 comments on commit bbe3e25

Please sign in to comment.