Skip to content

Commit

Permalink
Add interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
louisroyer committed Dec 3, 2024
1 parent b8b7033 commit 61633bb
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
6 changes: 5 additions & 1 deletion config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ slices:
nextmn-lite:
pool: "10.0.0.0/24"
upfs:
- "203.0.113.2" # only the first upf is used for now
- node-id: "203.0.113.2" # only the first upf is used for now
interfaces:
- type: "N3"
addr: "198.51.100.11"


logger:
level: "trace"
28 changes: 23 additions & 5 deletions internal/app/pdu_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"math/rand"
"net/http"
"net/netip"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -86,6 +87,7 @@ type PduSessions struct {

type PduSession struct {
Upf netip.Addr
UpfN3 netip.Addr
UplinkTeid uint32
Gnb netip.Addr
DownlinkTeid uint32
Expand Down Expand Up @@ -143,9 +145,9 @@ func (p *PduSessions) EstablishmentRequest(c *gin.Context) {

upf := p.Slices[ps.Dnn].Upfs[0]
upfTeids := &UpfTeids{}
l, ok := p.UpfMap.Load(upf)
l, ok := p.UpfMap.Load(upf.NodeID)
if !ok {
p.UpfMap.Store(upf, upfTeids)
p.UpfMap.Store(upf.NodeID, upfTeids)
} else {
upfTeids = l.(*UpfTeids)
}
Expand All @@ -170,9 +172,24 @@ func (p *PduSessions) EstablishmentRequest(c *gin.Context) {
}
}
}
var iface netip.Addr
ifacedone := false
for _, i := range upf.Interfaces {
if strings.ToLower(i.Type) == "n3" {
iface = i.Addr
ifacedone = true
break
}
}
if !ifacedone {
logrus.Error("could not find n3 interface on first upf")
c.JSON(http.StatusInternalServerError, jsonapi.MessageWithError{Message: "could not find n3 interface on first upf", Error: nil})
return
}
// allocate uplink teid
pduSession := PduSession{
Upf: upf,
Upf: upf.NodeID,
UpfN3: iface,
UplinkTeid: teid,
}

Expand Down Expand Up @@ -231,14 +248,15 @@ func (p *PduSessions) N2EstablishmentResponse(c *gin.Context) {
"ue": ps.UeInfo.Header.Ue.String(),
"gnb": ps.UeInfo.Header.Gnb.String(),
"ip-addr": ps.UeInfo.Addr,
"gtp-upf": psStruct.Upf,
"upf-pfcp": psStruct.Upf,
"gtp-upf": psStruct.UpfN3,
"gtp-uplink-teid": psStruct.UplinkTeid,
"gtp-downlink-teid": psStruct.DownlinkTeid,
"gtp-gnb": psStruct.Gnb,
"dnn": ps.UeInfo.Header.Dnn,
}).Info("New PDU Session Established")

err := p.pfcp.CreateSession(ps.UeInfo.Addr, psStruct.UplinkTeid, psStruct.DownlinkTeid, psStruct.Upf, psStruct.Gnb, ps.UeInfo.Header.Dnn)
err := p.pfcp.CreateSession(ps.UeInfo.Addr, psStruct.UplinkTeid, psStruct.DownlinkTeid, psStruct.Upf, psStruct.UpfN3, psStruct.Gnb, ps.UeInfo.Header.Dnn)
if err != nil {
logrus.WithError(err).Error("Could not configure PDR/FAR in UPF")
c.JSON(http.StatusInternalServerError, jsonapi.MessageWithError{Message: "could not configure PDR/FAR in UPF", Error: err})
Expand Down
10 changes: 5 additions & 5 deletions internal/app/pfcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,21 @@ func (p *PFCPServer) Start(ctx context.Context) error {
}
for _, slice := range p.slices {
for _, upf := range slice.Upfs {
association, err := p.srv.NewEstablishedPFCPAssociation(ie.NewNodeIDHeuristic(upf.String()))
association, err := p.srv.NewEstablishedPFCPAssociation(ie.NewNodeIDHeuristic(upf.NodeID.String()))
if err != nil {
logrus.WithError(err).WithFields(logrus.Fields{
"upf": upf,
"upf": upf.NodeID,
}).Error("Could not perform PFCP association")
return err
}
p.associations[upf] = association
p.associations[upf.NodeID] = association
}
}
logrus.Info("PFCP Associations complete")
return nil
}

func (p *PFCPServer) CreateSession(ue netip.Addr, uplinkTeid uint32, downlinkTeid uint32, upfI netip.Addr, gNB netip.Addr, slice string) error {
func (p *PFCPServer) CreateSession(ue netip.Addr, uplinkTeid uint32, downlinkTeid uint32, upfI netip.Addr, upfIn3 netip.Addr, gNB netip.Addr, slice string) error {
a, ok := p.associations[upfI]
if !ok {
return fmt.Errorf("Could not create PFCP Session: not associated with UPF")
Expand All @@ -84,7 +84,7 @@ func (p *PFCPServer) CreateSession(ue netip.Addr, uplinkTeid uint32, downlinkTei
ie.NewCreatePDR(ie.NewPDRID(1), ie.NewPrecedence(255),
ie.NewPDI(
ie.NewSourceInterface(ie.SrcInterfaceAccess),
ie.NewFTEID(0x01, uplinkTeid, upfI.AsSlice(), nil, 0), // ipv4: 0x01
ie.NewFTEID(0x01, uplinkTeid, upfIn3.AsSlice(), nil, 0), // ipv4: 0x01
ie.NewNetworkInstance(slice),
ie.NewUEIPAddress(0x02, ue.String(), "", 0, 0), // ipv4: 0x02
),
Expand Down
12 changes: 11 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,15 @@ type Control struct {

type Slice struct {
Pool netip.Prefix `yaml:"pool"`
Upfs []netip.Addr `yaml:"upfs"`
Upfs []Upf `yaml:"upfs"`
}

type Upf struct {
NodeID netip.Addr `yaml:"node-id"`
Interfaces []Interface `yaml:"interfaces"`
}

type Interface struct {
Type string `yaml:"type"`
Addr netip.Addr `yaml:"addr"`
}

0 comments on commit 61633bb

Please sign in to comment.