Skip to content

Commit

Permalink
chore: replace omec-project/pfcp with wmnsk/go-pfcp (#283)
Browse files Browse the repository at this point in the history
* chore: replace omec-project/pfcp with wmnsk/go-pfcp

Signed-off-by: guillaume <[email protected]>

* chore: move setBit to private

Signed-off-by: guillaume <[email protected]>

* chore: replace notice about copied code with copyright

Signed-off-by: guillaume <[email protected]>

* chore: replace notice about copied code with copyright

Signed-off-by: guillaume <[email protected]>

---------

Signed-off-by: guillaume <[email protected]>
  • Loading branch information
gruyaume authored Aug 1, 2024
1 parent e168c19 commit 9298460
Show file tree
Hide file tree
Showing 67 changed files with 4,632 additions and 2,020 deletions.
13 changes: 13 additions & 0 deletions context/apply_action.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2024 Canonical Ltd.
//
// SPDX-License-Identifier: Apache-2.0

package context

type ApplyAction struct {
Dupl bool
Nocp bool
Buff bool
Forw bool
Drop bool
}
14 changes: 9 additions & 5 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"github.com/omec-project/openapi/Nnrf_NFManagement"
"github.com/omec-project/openapi/Nudm_SubscriberDataManagement"
"github.com/omec-project/openapi/models"
"github.com/omec-project/pfcp/pfcpType"
"github.com/omec-project/pfcp/pfcpUdp"
"github.com/omec-project/smf/factory"
"github.com/omec-project/smf/logger"
"github.com/omec-project/smf/metrics"
Expand Down Expand Up @@ -52,7 +50,7 @@ type SMFContext struct {
BindingIPv4 string
RegisterIPv4 string

UPNodeIDs []pfcpType.NodeID
UPNodeIDs []NodeID
Key string
PEM string
KeyLog string
Expand All @@ -78,7 +76,8 @@ type SMFContext struct {
PodIp string

StaticIpInfo *[]factory.StaticIpInfo
CPNodeID pfcpType.NodeID
CPNodeID NodeID
PFCPPort int
UDMProfile models.NfProfile
NrfCacheEvictionInterval time.Duration
SBIPort int
Expand All @@ -100,6 +99,9 @@ func RetrieveDnnInformation(Snssai models.Snssai, dnn string) *SnssaiSmfDnnInfo
}

func AllocateLocalSEID() (uint64, error) {
if smfContext.DrsmCtxts.SeidPool == nil {
return 0, fmt.Errorf("SEID pool is not initialized")
}
seid32, err := smfContext.DrsmCtxts.SeidPool.AllocateInt32ID()
if err != nil {
logger.CtxLog.Errorf("allocate SEID error: %+v", err)
Expand Down Expand Up @@ -193,7 +195,7 @@ func InitSmfContext(config *factory.Config) *SMFContext {

if pfcp := configuration.PFCP; pfcp != nil {
if pfcp.Port == 0 {
pfcp.Port = pfcpUdp.PFCP_PORT
pfcp.Port = factory.DEFAULT_PFCP_PORT
}
pfcpAddrEnv := os.Getenv(pfcp.Addr)
if pfcpAddrEnv != "" {
Expand All @@ -209,6 +211,8 @@ func InitSmfContext(config *factory.Config) *SMFContext {
logger.CtxLog.Warnf("PFCP Parse Addr Fail: %v", err)
}

smfContext.PFCPPort = int(pfcp.Port)

smfContext.CPNodeID.NodeIdType = 0
smfContext.CPNodeID.NodeIdValue = addr.IP.To4()
}
Expand Down
67 changes: 33 additions & 34 deletions context/datapath.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"strconv"

"github.com/omec-project/openapi/models"
"github.com/omec-project/pfcp/pfcpType"
"github.com/omec-project/smf/logger"
"github.com/omec-project/smf/qos"
"github.com/omec-project/smf/util"
Expand Down Expand Up @@ -426,9 +425,9 @@ func (dpNode *DataPathNode) CreatePccRuleQer(smContext *SMContext, qosData strin
tc := qos.GetTcDataFromPolicyDecision(smPolicyDec, tcData)

// Get Flow Status
gateStatus := pfcpType.GateOpen
gateStatus := GateOpen
if tc != nil && tc.FlowStatus == models.FlowStatus_DISABLED {
gateStatus = pfcpType.GateClose
gateStatus = GateClose
}

var flowQER *QER
Expand All @@ -440,13 +439,13 @@ func (dpNode *DataPathNode) CreatePccRuleQer(smContext *SMContext, qosData strin
newQER.QFI.QFI = qos.GetQosFlowIdFromQosId(refQos.QosId)

// Flow Status
newQER.GateStatus = &pfcpType.GateStatus{
newQER.GateStatus = &GateStatus{
ULGate: gateStatus,
DLGate: gateStatus,
}

// Rates
newQER.MBR = &pfcpType.MBR{
newQER.MBR = &MBR{
ULMBR: util.BitRateTokbps(refQos.MaxbrUl),
DLMBR: util.BitRateTokbps(refQos.MaxbrDl),
}
Expand All @@ -471,11 +470,11 @@ func (dpNode *DataPathNode) CreateSessRuleQer(smContext *SMContext) (*QER, error
return nil, err
} else {
newQER.QFI.QFI = qos.GetQosFlowIdFromQosId(defQosData.QosId)
newQER.GateStatus = &pfcpType.GateStatus{
ULGate: pfcpType.GateOpen,
DLGate: pfcpType.GateOpen,
newQER.GateStatus = &GateStatus{
ULGate: GateOpen,
DLGate: GateOpen,
}
newQER.MBR = &pfcpType.MBR{
newQER.MBR = &MBR{
ULMBR: util.BitRateTokbps(sessionRule.AuthSessAmbr.Uplink),
DLMBR: util.BitRateTokbps(sessionRule.AuthSessAmbr.Downlink),
}
Expand All @@ -488,7 +487,7 @@ func (dpNode *DataPathNode) CreateSessRuleQer(smContext *SMContext) (*QER, error

// ActivateUpLinkPdr
func (dpNode *DataPathNode) ActivateUpLinkPdr(smContext *SMContext, defQER *QER, defPrecedence uint32) error {
ueIpAddr := pfcpType.UEIPAddress{}
ueIpAddr := UEIPAddress{}
if dpNode.UPF.IsUpfSupportUeIpAddrAlloc() {
ueIpAddr.CHV4 = true
} else {
Expand Down Expand Up @@ -517,8 +516,8 @@ func (dpNode *DataPathNode) ActivateUpLinkPdr(smContext *SMContext, defQER *QER,
logger.CtxLog.Errorf("activate UpLink PDR[%v] failed %v ", name, err)
return err
} else {
ULPDR.PDI.SourceInterface = pfcpType.SourceInterface{InterfaceValue: pfcpType.SourceInterfaceAccess}
ULPDR.PDI.LocalFTeid = &pfcpType.FTEID{
ULPDR.PDI.SourceInterface = SourceInterface{InterfaceValue: SourceInterfaceAccess}
ULPDR.PDI.LocalFTeid = &FTEID{
V4: true,
Ipv4Address: upIP,
Teid: curULTunnel.TEID,
Expand All @@ -529,28 +528,28 @@ func (dpNode *DataPathNode) ActivateUpLinkPdr(smContext *SMContext, defQER *QER,
ULPDR.PDI.NetworkInstance = util_3gpp.Dnn(smContext.Dnn)
}

ULPDR.OuterHeaderRemoval = &pfcpType.OuterHeaderRemoval{
OuterHeaderRemovalDescription: pfcpType.OuterHeaderRemovalGtpUUdpIpv4,
ULPDR.OuterHeaderRemoval = &OuterHeaderRemoval{
OuterHeaderRemovalDescription: OuterHeaderRemovalGtpUUdpIpv4,
}

ULFAR := ULPDR.FAR
ULFAR.ApplyAction = pfcpType.ApplyAction{
ULFAR.ApplyAction = ApplyAction{
Buff: false,
Drop: false,
Dupl: false,
Forw: true,
Nocp: false,
}
ULFAR.ForwardingParameters = &ForwardingParameters{
DestinationInterface: pfcpType.DestinationInterface{
InterfaceValue: pfcpType.DestinationInterfaceCore,
DestinationInterface: DestinationInterface{
InterfaceValue: DestinationInterfaceCore,
},
NetworkInstance: []byte(smContext.Dnn),
}

if dpNode.IsAnchorUPF() {
ULFAR.ForwardingParameters.
DestinationInterface.InterfaceValue = pfcpType.DestinationInterfaceSgiLanN6Lan
DestinationInterface.InterfaceValue = DestinationInterfaceSgiLanN6Lan
}

if nextULDest := dpNode.Next(); nextULDest != nil {
Expand All @@ -561,8 +560,8 @@ func (dpNode *DataPathNode) ActivateUpLinkPdr(smContext *SMContext, defQER *QER,
logger.CtxLog.Errorf("activate UpLink PDR[%v] failed %v ", name, err)
return err
} else {
ULFAR.ForwardingParameters.OuterHeaderCreation = &pfcpType.OuterHeaderCreation{
OuterHeaderCreationDescription: pfcpType.OuterHeaderCreationGtpUUdpIpv4,
ULFAR.ForwardingParameters.OuterHeaderCreation = &OuterHeaderCreation{
OuterHeaderCreationDescription: OuterHeaderCreationGtpUUdpIpv4,
Ipv4Address: upIP,
Teid: nextULTunnel.TEID,
}
Expand All @@ -578,7 +577,7 @@ func (dpNode *DataPathNode) ActivateDlLinkPdr(smContext *SMContext, defQER *QER,
curDLTunnel := dpNode.DownLinkTunnel

// UPF provided UE ip-addr
ueIpAddr := pfcpType.UEIPAddress{}
ueIpAddr := UEIPAddress{}
if dpNode.UPF.IsUpfSupportUeIpAddrAlloc() {
ueIpAddr.CHV4 = true
} else {
Expand All @@ -598,17 +597,17 @@ func (dpNode *DataPathNode) ActivateDlLinkPdr(smContext *SMContext, defQER *QER,
if dpNode.IsAnchorUPF() {
DLPDR.PDI.UEIPAddress = &ueIpAddr
} else {
DLPDR.OuterHeaderRemoval = &pfcpType.OuterHeaderRemoval{
OuterHeaderRemovalDescription: pfcpType.OuterHeaderRemovalGtpUUdpIpv4,
DLPDR.OuterHeaderRemoval = &OuterHeaderRemoval{
OuterHeaderRemovalDescription: OuterHeaderRemovalGtpUUdpIpv4,
}

iface = DLDestUPF.GetInterface(models.UpInterfaceType_N9, smContext.Dnn)
if upIP, err := iface.IP(smContext.SelectedPDUSessionType); err != nil {
logger.CtxLog.Errorf("activate Downlink PDR[%v] failed %v ", name, err)
return err
} else {
DLPDR.PDI.SourceInterface = pfcpType.SourceInterface{InterfaceValue: pfcpType.SourceInterfaceCore}
DLPDR.PDI.LocalFTeid = &pfcpType.FTEID{
DLPDR.PDI.SourceInterface = SourceInterface{InterfaceValue: SourceInterfaceCore}
DLPDR.PDI.LocalFTeid = &FTEID{
V4: true,
Ipv4Address: upIP,
Teid: curDLTunnel.TEID,
Expand All @@ -626,7 +625,7 @@ func (dpNode *DataPathNode) ActivateDlLinkPdr(smContext *SMContext, defQER *QER,
logger.PduSessLog.Traceln("In DLPDR OuterHeaderCreation")
nextDLTunnel := nextDLDest.DownLinkTunnel

DLFAR.ApplyAction = pfcpType.ApplyAction{
DLFAR.ApplyAction = ApplyAction{
Buff: true,
Drop: false,
Dupl: false,
Expand All @@ -641,9 +640,9 @@ func (dpNode *DataPathNode) ActivateDlLinkPdr(smContext *SMContext, defQER *QER,
return err
} else {
DLFAR.ForwardingParameters = &ForwardingParameters{
DestinationInterface: pfcpType.DestinationInterface{InterfaceValue: pfcpType.DestinationInterfaceAccess},
OuterHeaderCreation: &pfcpType.OuterHeaderCreation{
OuterHeaderCreationDescription: pfcpType.OuterHeaderCreationGtpUUdpIpv4,
DestinationInterface: DestinationInterface{InterfaceValue: DestinationInterfaceAccess},
OuterHeaderCreation: &OuterHeaderCreation{
OuterHeaderCreationDescription: OuterHeaderCreationGtpUUdpIpv4,
Ipv4Address: upIP,
Teid: nextDLTunnel.TEID,
},
Expand All @@ -655,12 +654,12 @@ func (dpNode *DataPathNode) ActivateDlLinkPdr(smContext *SMContext, defQER *QER,
DefaultDLPDR := ANUPF.DownLinkTunnel.PDR["default"] // TODO: Iterate over all PDRs
DLFAR := DefaultDLPDR.FAR
DLFAR.ForwardingParameters = new(ForwardingParameters)
DLFAR.ForwardingParameters.DestinationInterface.InterfaceValue = pfcpType.DestinationInterfaceAccess
DLFAR.ForwardingParameters.DestinationInterface.InterfaceValue = DestinationInterfaceAccess
DLFAR.ForwardingParameters.NetworkInstance = []byte(smContext.Dnn)
DLFAR.ForwardingParameters.OuterHeaderCreation = new(pfcpType.OuterHeaderCreation)
DLFAR.ForwardingParameters.OuterHeaderCreation = new(OuterHeaderCreation)

dlOuterHeaderCreation := DLFAR.ForwardingParameters.OuterHeaderCreation
dlOuterHeaderCreation.OuterHeaderCreationDescription = pfcpType.OuterHeaderCreationGtpUUdpIpv4
dlOuterHeaderCreation.OuterHeaderCreationDescription = OuterHeaderCreationGtpUUdpIpv4
dlOuterHeaderCreation.Teid = smContext.Tunnel.ANInformation.TEID
dlOuterHeaderCreation.Ipv4Address = smContext.Tunnel.ANInformation.IPAddress.To4()
}
Expand Down Expand Up @@ -711,7 +710,7 @@ func (dataPath *DataPath) ActivateTunnelAndPDR(smContext *SMContext, precedence
}
}

ueIpAddr := pfcpType.UEIPAddress{}
ueIpAddr := UEIPAddress{}
if curDataPathNode.UPF.IsUpfSupportUeIpAddrAlloc() {
ueIpAddr.CHV4 = true
} else {
Expand All @@ -722,7 +721,7 @@ func (dataPath *DataPath) ActivateTunnelAndPDR(smContext *SMContext, precedence
if curDataPathNode.DownLinkTunnel != nil {
if curDataPathNode.DownLinkTunnel.SrcEndPoint == nil {
for _, DNDLPDR := range curDataPathNode.DownLinkTunnel.PDR {
DNDLPDR.PDI.SourceInterface = pfcpType.SourceInterface{InterfaceValue: pfcpType.SourceInterfaceCore}
DNDLPDR.PDI.SourceInterface = SourceInterface{InterfaceValue: SourceInterfaceCore}
DNDLPDR.PDI.NetworkInstance = util_3gpp.Dnn(smContext.Dnn)
DNDLPDR.PDI.UEIPAddress = &ueIpAddr
}
Expand Down
19 changes: 5 additions & 14 deletions context/db_uptunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"net"

"github.com/omec-project/pfcp/pfcpType"
"github.com/omec-project/smf/logger"
"github.com/omec-project/util/idgenerator"
"github.com/omec-project/util/mongoapi"
Expand Down Expand Up @@ -63,25 +62,17 @@ type PFCPSessionContextInDB struct {
PDRs map[uint16]*PDR
LocalSEID string
RemoteSEID string
NodeID pfcpType.NodeID
NodeID NodeID
}

type PFCPContextInDB map[string]PFCPSessionContextInDB

func GetNodeIDInDB(nodeID pfcpType.NodeID) (nodeIDInDB NodeIDInDB) {
nodeIDInDB = NodeIDInDB{
NodeIdType: nodeID.NodeIdType,
NodeIdValue: nodeID.NodeIdValue,
}
return nodeIDInDB
func GetNodeIDInDB(nodeID NodeID) NodeIDInDB {
return NodeIDInDB(nodeID)
}

func GetNodeID(nodeIDInDB NodeIDInDB) (nodeID pfcpType.NodeID) {
nodeID = pfcpType.NodeID{
NodeIdType: nodeIDInDB.NodeIdType,
NodeIdValue: nodeIDInDB.NodeIdValue,
}
return nodeID
func GetNodeID(nodeIDInDB NodeIDInDB) NodeID {
return NodeID(nodeIDInDB)
}

func testEq(a, b []byte) bool {
Expand Down
14 changes: 14 additions & 0 deletions context/gate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2024 Canonical Ltd.

package context

const (
GateOpen uint8 = iota
GateClose
)

type GateStatus struct {
ULGate uint8 // 0x00001100
DLGate uint8 // 0x00000011
}
10 changes: 10 additions & 0 deletions context/gbr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 Canonical Ltd.
//
// SPDX-License-Identifier: Apache-2.0

package context

type GBR struct {
ULGBR uint64 // 40-bit data
DLGBR uint64 // 40-bit data
}
24 changes: 24 additions & 0 deletions context/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2024 Canonical Ltd.
//
// SPDX-License-Identifier: Apache-2.0

package context

const (
SourceInterfaceAccess uint8 = iota
SourceInterfaceCore
)

const (
DestinationInterfaceAccess uint8 = iota
DestinationInterfaceCore
DestinationInterfaceSgiLanN6Lan
)

type SourceInterface struct {
InterfaceValue uint8 // 0x00001111
}

type DestinationInterface struct {
InterfaceValue uint8 // 0x00001111
}
10 changes: 10 additions & 0 deletions context/mbr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 Canonical Ltd.
//
// SPDX-License-Identifier: Apache-2.0

package context

type MBR struct {
ULMBR uint64 // 40-bit data
DLMBR uint64 // 40-bit data
}
Loading

0 comments on commit 9298460

Please sign in to comment.