Skip to content

Commit

Permalink
(wip) sync.map string
Browse files Browse the repository at this point in the history
  • Loading branch information
louisroyer committed Jan 9, 2025
1 parent b65a58f commit d2ee57a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion internal/radio/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (r *Radio) Peer(c *gin.Context) {
}

func (r *Radio) HandlePeer(peer n1n2.RadioPeerMsg) {
r.peerMap.Store(peer.Control, peer.Data)
r.peerMap.Store(peer.Control.String(), peer.Data)
logrus.WithFields(logrus.Fields{
"peer-control": peer.Control.String(),
"peer-ran": peer.Data,
Expand Down
12 changes: 6 additions & 6 deletions internal/radio/radio.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

type Radio struct {
Client http.Client
peerMap sync.Map // key: gnb control uri ; value: gnb ran ip address
peerMap sync.Map // key: gnb control uri (string); value: gnb ran ip address
routingTable sync.Map // key: ueIp; value gnb control uri
Tun *tun.TunManager
Control jsonapi.ControlURI
Expand All @@ -50,10 +50,10 @@ func NewRadio(control jsonapi.ControlURI, tunMan *tun.TunManager, data netip.Add

// AddRoute creates a route to the gNB for this PDU session, including configuration of iproute2 interface
func (r *Radio) AddRoute(ueIp netip.Addr, gnb jsonapi.ControlURI) error {
if _, ok := r.peerMap.Load(gnb); !ok {
if _, ok := r.peerMap.Load(gnb.String()); !ok {
return ErrUnknownGnb
}
if _, loaded := r.routingTable.LoadOrStore(ueIp, gnb); loaded {
if _, loaded := r.routingTable.LoadOrStore(ueIp, gnb.String()); loaded {
return ErrPduSessionAlreadyExists
}
return r.Tun.AddIp(ueIp)
Expand All @@ -67,12 +67,12 @@ func (r *Radio) DelRoute(ueIp netip.Addr) error {

// UpdateRoute updates the route to the gNB for this PDU Session
func (r *Radio) UpdateRoute(ueIp netip.Addr, oldGnb jsonapi.ControlURI, newGnb jsonapi.ControlURI) error {
if _, ok := r.peerMap.Load(newGnb); !ok {
if _, ok := r.peerMap.Load(newGnb.String()); !ok {
return ErrUnknownGnb
}
if old, ok := r.routingTable.Load(ueIp); !ok {
return ErrPduSessionNotFound
} else if old != oldGnb {
} else if old.(*jsonapi.ControlURI).String() != oldGnb.String() {
return ErrUnexpectedGnb
}

Expand All @@ -86,7 +86,7 @@ func (r *Radio) Write(pkt []byte, srv *net.UDPConn, ue netip.Addr) error {
logrus.Trace("PDU Session not found for this IP Address")
return ErrPduSessionNotFound
}
gnbRan, ok := r.peerMap.Load(gnb)
gnbRan, ok := r.peerMap.Load(gnb.(string))
if !ok {
logrus.Trace("Unknown gnb")
return ErrUnknownGnb
Expand Down
19 changes: 8 additions & 11 deletions internal/radio/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,24 @@
package radio

import (
"encoding/json"
"net/http"
"net/netip"

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

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

func (r *Radio) Status(c *gin.Context) {
peers := make(map[jsonapi.ControlURI]netip.Addr)
peers := make(map[string]netip.AddrPort)
r.peerMap.Range(func(key, value any) bool {
peers[key.(jsonapi.ControlURI)] = value.(netip.Addr)
peers[key.(string)] = value.(netip.AddrPort)
logrus.WithFields(logrus.Fields{
"key": key.(string),
"value": value.(netip.AddrPort),
}).Trace("Creating radio/status response")
return true
})
j, err := json.Marshal(peers)
if err != nil {
c.JSON(http.StatusInternalServerError, jsonapi.MessageWithError{Message: "could not marshal peers map", Error: err})
return
}

c.Header("Cache-Control", "no-cache")
c.JSON(http.StatusOK, j)
c.JSON(http.StatusOK, peers)
}
4 changes: 2 additions & 2 deletions internal/session/handover-command.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ func (p *PduSessions) HandleHandoverCommand(m n1n2.HandoverCommand) {
// TODO: notify gNB/CP of failure?
logrus.WithError(err).WithFields(logrus.Fields{
"ue-addr": session.Addr,
"source-gnb": m.SourceGnb,
"target-gnb": m.TargetGnb,
"source-gnb": m.SourceGnb.String(),
"target-gnb": m.TargetGnb.String(),
}).Error("Handover failure")
continue
}
Expand Down
3 changes: 2 additions & 1 deletion internal/session/pdu_sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ func (p *PduSessions) DeletePduSession(ueIpAddr netip.Addr) error {
func (p *PduSessions) UpdatePduSession(ueIpAddr netip.Addr, oldGnb jsonapi.ControlURI, newGnb jsonapi.ControlURI) error {
logrus.WithFields(logrus.Fields{
"ue-ip-addr": ueIpAddr,
"new-gnb": newGnb,
"old-gnb": oldGnb.String(),
"new-gnb": newGnb.String(),
}).Info("Updating PDU Session")
return p.radio.UpdateRoute(ueIpAddr, oldGnb, newGnb)
}
Expand Down

0 comments on commit d2ee57a

Please sign in to comment.