Skip to content

Commit

Permalink
fix up features and add created PDRs in SMF response
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog-spb committed Nov 8, 2023
1 parent 369d6bb commit f95cbee
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
18 changes: 10 additions & 8 deletions cmd/core/pfcp_handlers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package core

import (
"math/big"
"net"
"time"

Expand Down Expand Up @@ -45,6 +44,11 @@ func (handlerMap PfcpHandlerMap) Handle(conn *PfcpConnection, buf []byte, addr *
return nil
}

func setBit(n uint8, pos uint) uint8 {
n |= (1 << pos)
return n
}

// https://www.etsi.org/deliver/etsi_ts/129200_129299/129244/16.04.00_60/ts_129244v160400p.pdf page 95
func HandlePfcpAssociationSetupRequest(conn *PfcpConnection, msg message.Message, addr string) (message.Message, error) {
asreq := msg.(*message.AssociationSetupRequest)
Expand Down Expand Up @@ -87,19 +91,17 @@ func HandlePfcpAssociationSetupRequest(conn *PfcpConnection, msg message.Message
conn.NodeAssociations[addr] = remoteNode
log.Info().Msgf("Saving new association: %+v", remoteNode)

x := big.NewInt(0)
x.SetBit(x, 12, 1)
upFunctionFeaturesIE := ie.New(ie.UPFunctionFeatures, x.Bytes())
featuresOctets := []uint8{}
featuresOctets = append(featuresOctets, setBit(0, 4)) //FTUP
//featuresOctets = append(featuresOctets, 0)
//featuresOctets = append(featuresOctets, setBit(0, 2)) //UEIP
upFunctionFeaturesIE := ie.NewUPFunctionFeatures(featuresOctets...)

// shall send a PFCP Association Setup Response including:
asres := message.NewAssociationSetupResponse(asreq.SequenceNumber,
ie.NewCause(ie.CauseRequestAccepted), // a successful cause
newIeNodeID(conn.nodeId), // its Node ID;
upFunctionFeaturesIE,
//ie.NewUPFunctionFeatures(), // information of all supported optional features in the UP function; We don't support any optional features at the moment
// ... other IEs
// optionally one or more UE IP address Pool Information IE which contains a list of UE IP Address Pool Identities per Network Instance, S-NSSAI and IP version;
// optionally the NF Instance ID of the UPF if available
)

//a := message.
Expand Down
40 changes: 26 additions & 14 deletions cmd/core/pfcp_session_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func HandlePfcpSessionEstablishmentRequest(conn *PfcpConnection, msg message.Mes

printSessionEstablishmentRequest(req)
// #TODO: Implement rollback on error
createdPDRs := []SPDRInfo{}

err = func() error {
mapOperations := conn.mapOperations
for _, far := range req.CreateFAR {
Expand Down Expand Up @@ -86,10 +88,11 @@ func HandlePfcpSessionEstablishmentRequest(conn *PfcpConnection, msg message.Mes
continue
}

spdrInfo := SPDRInfo{}
spdrInfo := SPDRInfo{PdrID: uint32(pdrId)}
if err := extractPDR(pdr, session, &spdrInfo, conn.ipam, req.SEID()); err == nil {
session.PutPDR(uint32(pdrId), spdrInfo)
session.PutPDR(spdrInfo.PdrID, spdrInfo)
applyPDR(spdrInfo, mapOperations)
createdPDRs = append(createdPDRs, spdrInfo)
} else {
log.Printf("Error extracting PDR info: %s", err.Error())
}
Expand All @@ -107,16 +110,25 @@ func HandlePfcpSessionEstablishmentRequest(conn *PfcpConnection, msg message.Mes
association.Sessions[localSEID] = session
conn.NodeAssociations[addr] = association

AdditionalIEs := []*ie.IE{
additionalIEs := []*ie.IE{
ie.NewCause(ie.CauseRequestAccepted),
newIeNodeID(conn.nodeId),
ie.NewFSEID(localSEID, conn.nodeAddrV4, nil),
}

//TODO: add Created PDR IE for each generated TEID/IP
//FIXME: process PDR with allocated UE/TEID only
for _, pdr := range createdPDRs {
if pdr.Ipv4 != nil {
additionalIEs = append(additionalIEs, ie.NewCreatedPDR(ie.NewPDRID(0), ie.NewUEIPAddress(0, pdr.Ipv4.String(), "", 0, 0)))
} else if pdr.Ipv6 != nil {

} else {
additionalIEs = append(additionalIEs, ie.NewCreatedPDR(ie.NewPDRID(0), ie.NewFTEID(0, pdr.Teid, conn.n3Address, nil, 0)))
}
}

// Send SessionEstablishmentResponse
estResp := message.NewSessionEstablishmentResponse(0, 0, remoteSEID.SEID, req.Sequence(), 0, AdditionalIEs...)
estResp := message.NewSessionEstablishmentResponse(0, 0, remoteSEID.SEID, req.Sequence(), 0, additionalIEs...)
PfcpMessageRxErrors.WithLabelValues(msg.MessageTypeName(), causeToString(ie.CauseRequestAccepted)).Inc()
log.Info().Msgf("Session Establishment Request from %s accepted.", addr)
return estResp, nil
Expand Down Expand Up @@ -188,10 +200,10 @@ func extractPDR(pdr *ie.IE, session *Session, spdrInfo *SPDRInfo, ipam *service.
if fteid.HasCh() {
if fteid.HasChID() {
//try to find teid previously allocated
if err, teid := teidCache.GetTEID(fteid.ChooseID); err == nil {
spdrInfo.Teid = teid
return nil
}
// if err, teid := teidCache.GetTEID(fteid.ChooseID); err == nil {
// spdrInfo.Teid = teid
// return nil
// }
}

teid, err := ipam.AllocateTEID(seid)
Expand All @@ -200,9 +212,9 @@ func extractPDR(pdr *ie.IE, session *Session, spdrInfo *SPDRInfo, ipam *service.
return fmt.Errorf("Can't allocate TEID: %s", causeToString(ie.CauseNoResourcesAvailable))
}

if fteid.HasChID() {
teidCache.PutTEID(fteid.ChooseID, teid)
}
// if fteid.HasChID() {
// teidCache.PutTEID(fteid.ChooseID, teid)
// }

spdrInfo.Teid = teid
return nil
Expand Down Expand Up @@ -407,11 +419,11 @@ func HandlePfcpSessionModificationRequest(conn *PfcpConnection, msg message.Mess
continue
}

spdrInfo := SPDRInfo{}
spdrInfo := SPDRInfo{PdrID: uint32(pdrId)}
//if err := extractPDR(pdr, session, &spdrInfo, conn.ipam, req.SEID()); err == nil {
if err := extractPDR(pdr, session, &spdrInfo, conn.ipam, req.SEID()); err == nil {
//if err := extractPDR(pdr, session, &spdrInfo); err == nil {
session.PutPDR(uint32(pdrId), spdrInfo)
session.PutPDR(spdrInfo.PdrID, spdrInfo)
applyPDR(spdrInfo, mapOperations)
} else {
log.Info().Msgf("Error extracting PDR info: %s", err.Error())
Expand Down
1 change: 1 addition & 0 deletions cmd/core/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func NewSession(localSEID uint64, remoteSEID uint64) *Session {
}

type SPDRInfo struct {
PdrID uint32
PdrInfo ebpf.PdrInfo
Teid uint32
Ipv4 net.IP
Expand Down

0 comments on commit f95cbee

Please sign in to comment.