Skip to content

Commit

Permalink
update go-pfcp to latest (based on v0.0.22)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-ywliu committed Oct 9, 2023
1 parent b192a9a commit 78a6a67
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 47 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ require (
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.8.1
github.com/urfave/cli v1.22.5
github.com/wmnsk/go-pfcp v0.0.17-0.20221027122420-36112307f93a
github.com/wmnsk/go-pfcp v0.0.23-0.20231009074152-d5a9c1f47114
gopkg.in/yaml.v2 v2.4.0
)
14 changes: 6 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
Expand Down Expand Up @@ -77,8 +77,8 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJ
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY=
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pascaldekloe/goe v0.1.1 h1:Ah6WQ56rZONR3RW3qWa2NCZ6JAVvSpUcoLBaOmYFt9Q=
github.com/pascaldekloe/goe v0.1.1/go.mod h1:KSyfaxQOh0HZPjDP1FL/kFtbqYqrALJTaMafFUIccqU=
github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU=
github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
Expand Down Expand Up @@ -117,8 +117,8 @@ github.com/ugorji/go/codec v1.2.9 h1:rmenucSohSTiyL09Y+l2OCk+FrMxGMzho2+tjr5ticU
github.com/ugorji/go/codec v1.2.9/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU=
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/wmnsk/go-pfcp v0.0.17-0.20221027122420-36112307f93a h1:skrc17l2Yv6poWnvr800TsWFrnsi0pJ+3RnmlhZvyPw=
github.com/wmnsk/go-pfcp v0.0.17-0.20221027122420-36112307f93a/go.mod h1:GdZzvBajb3sNUP8ohAhXcVgzuckLPe/fVBJlzJSIqXs=
github.com/wmnsk/go-pfcp v0.0.23-0.20231009074152-d5a9c1f47114 h1:8y4Hd1l92YQajB5s53suWTTbRRClaZWyDyYm9fl1RX0=
github.com/wmnsk/go-pfcp v0.0.23-0.20231009074152-d5a9c1f47114/go.mod h1:C93sXfS7NGT9niMpb6K+pf/2GQTMBPFqZ5K2fmAtoA8=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs=
github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM=
Expand Down Expand Up @@ -174,8 +174,6 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
Expand Down
2 changes: 1 addition & 1 deletion internal/forwarder/buffnetlink/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (h *testHandler) NotifySessReport(sr report.SessReport) {
for _, rep := range sr.Reports {
switch r := rep.(type) {
case report.DLDReport:
if r.Action&report.BUFF != 0 && len(r.BufPkt) > 0 {
if r.Action&report.APPLY_ACT_BUFF != 0 && len(r.BufPkt) > 0 {
q, ok := s[r.PDRID]
if !ok {
qlen := 10
Expand Down
34 changes: 19 additions & 15 deletions internal/forwarder/gtp5g.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,14 +626,18 @@ func (g *Gtp5g) CreateFAR(lSeid uint64, req *ie.IE) error {
}
farid = uint64(v)
case ie.ApplyAction:
v, err := i.ApplyAction()
b, err := i.ApplyAction()
if err != nil {
return err
}
var act report.ApplyAction
err = act.Unmarshal(b)
if err != nil {
return err
}
v = SwitchU16Endian(v)
attrs = append(attrs, nl.Attr{
Type: gtp5gnl.FAR_APPLY_ACTION,
Value: nl.AttrU16(v),
Value: nl.AttrU16(act.Flags),
})
case ie.ForwardingParameters:
xs, err := i.ForwardingParameters()
Expand Down Expand Up @@ -666,10 +670,6 @@ func (g *Gtp5g) CreateFAR(lSeid uint64, req *ie.IE) error {
return gtp5gnl.CreateFAROID(g.client, g.link.link, oid, attrs)
}

func SwitchU16Endian(i uint16) uint16 {
return (i >> 8) | (i << 8)
}

func (g *Gtp5g) UpdateFAR(lSeid uint64, req *ie.IE) error {
var farid uint64
var attrs []nl.Attr
Expand All @@ -687,16 +687,20 @@ func (g *Gtp5g) UpdateFAR(lSeid uint64, req *ie.IE) error {
}
farid = uint64(v)
case ie.ApplyAction:
v, err := i.ApplyAction()
b, err := i.ApplyAction()
if err != nil {
return err
}
var act report.ApplyAction
err = act.Unmarshal(b)
if err != nil {
return err
}
v = SwitchU16Endian(v)
attrs = append(attrs, nl.Attr{
Type: gtp5gnl.FAR_APPLY_ACTION,
Value: nl.AttrU16(v),
Value: nl.AttrU16(act.Flags),
})
g.applyAction(lSeid, int(farid), v)
g.applyAction(lSeid, int(farid), act)
case ie.UpdateForwardingParameters:
xs, err := i.UpdateForwardingParameters()
if err != nil {
Expand Down Expand Up @@ -1565,18 +1569,18 @@ func (g *Gtp5g) HandleReport(handler report.Handler) {
g.ps.Handle(handler, g.psQueryURR)
}

func (g *Gtp5g) applyAction(lSeid uint64, farid int, action uint16) {
func (g *Gtp5g) applyAction(lSeid uint64, farid int, action report.ApplyAction) {
oid := gtp5gnl.OID{lSeid, uint64(farid)}
far, err := gtp5gnl.GetFAROID(g.client, g.link.link, oid)
if err != nil {
g.log.Errorf("applyAction err: %+v", err)
return
}
if far.Action&report.BUFF == 0 {
if far.Action&report.APPLY_ACT_BUFF == 0 {
return
}
switch {
case action&report.DROP != 0:
case action.DROP():
// BUFF -> DROP
for _, pdrid := range far.PDRIDs {
for {
Expand All @@ -1586,7 +1590,7 @@ func (g *Gtp5g) applyAction(lSeid uint64, farid int, action uint16) {
}
}
}
case action&report.FORW != 0:
case action.FORW():
// BUFF -> FORW
for _, pdrid := range far.PDRIDs {
oid := gtp5gnl.OID{lSeid, uint64(pdrid)}
Expand Down
6 changes: 3 additions & 3 deletions internal/forwarder/gtp5g_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestGtp5g_CreateRules(t *testing.T) {
t.Run("create rules", func(t *testing.T) {
far := ie.NewCreateFAR(
ie.NewFARID(2),
ie.NewApplyAction(SwitchU16Endian(0x2)),
ie.NewApplyAction(0x2),
ie.NewForwardingParameters(
ie.NewDestinationInterface(ie.DstInterfaceSGiLANN6LAN),
ie.NewNetworkInstance("internet"),
Expand All @@ -70,7 +70,7 @@ func TestGtp5g_CreateRules(t *testing.T) {

far = ie.NewCreateFAR(
ie.NewFARID(4),
ie.NewApplyAction(SwitchU16Endian(0x2)),
ie.NewApplyAction(0x2),
)

err = g.CreateFAR(lSeid, far)
Expand Down Expand Up @@ -206,7 +206,7 @@ func TestGtp5g_CreateRules(t *testing.T) {

far := ie.NewUpdateFAR(
ie.NewFARID(4),
ie.NewApplyAction(SwitchU16Endian(0x2)),
ie.NewApplyAction(0x2),
ie.NewUpdateForwardingParameters(
ie.NewDestinationInterface(ie.DstInterfaceAccess),
ie.NewNetworkInstance("internet"),
Expand Down
4 changes: 2 additions & 2 deletions internal/pfcp/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ func (s *PfcpServer) ServeReport(sr *report.SessReport) {
switch r := rpt.(type) {
case report.DLDReport:
s.log.Debugf("ServeReport: SEID(%#x), type(%s)", sr.SEID, r.Type())
if r.Action&report.BUFF != 0 && len(r.BufPkt) > 0 {
if r.Action&report.APPLY_ACT_BUFF != 0 && len(r.BufPkt) > 0 {
sess.Push(r.PDRID, r.BufPkt)
}
if r.Action&report.NOCP == 0 {
if r.Action&report.APPLY_ACT_NOCP == 0 {
return
}
err := s.serveDLDReport(laddr, sr.SEID, r.PDRID)
Expand Down
95 changes: 82 additions & 13 deletions internal/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,21 +471,90 @@ func (m *DurationMeasure) IE() *ie.IE {

// Apply Action IE bits definition
const (
DROP = 1 << iota
FORW
BUFF
NOCP
DUPL
IPMA
IPMD
DFRT
EDRT
BDPN
DDPN
FSSM
MBSU
APPLY_ACT_DROP = 1 << iota
APPLY_ACT_FORW
APPLY_ACT_BUFF
APPLY_ACT_NOCP
APPLY_ACT_DUPL
APPLY_ACT_IPMA
APPLY_ACT_IPMD
APPLY_ACT_DFRT
APPLY_ACT_EDRT
APPLY_ACT_BDPN
APPLY_ACT_DDPN
APPLY_ACT_FSSM
APPLY_ACT_MBSU
)

type ApplyAction struct {
Flags uint16
}

func (a *ApplyAction) Unmarshal(b []byte) error {
var v []byte
if len(b) < 1 {
return errors.Errorf("ApplyAction Unmarshal: less than 1 bytes")
} else if len(b) < 2 {
// slice len might be 1 or 2; enlarge slice to 2 bytes at least
v = make([]byte, len(b)+1)
copy(v, b)
}
a.Flags = binary.LittleEndian.Uint16(v)
return nil
}

func (a *ApplyAction) DROP() bool {
return a.Flags&APPLY_ACT_DROP != 0
}

func (a *ApplyAction) FORW() bool {
return a.Flags&APPLY_ACT_FORW != 0
}

func (a *ApplyAction) BUFF() bool {
return a.Flags&APPLY_ACT_BUFF != 0
}

func (a *ApplyAction) NOCP() bool {
return a.Flags&APPLY_ACT_NOCP != 0
}

func (a *ApplyAction) DUPL() bool {
return a.Flags&APPLY_ACT_DUPL != 0
}

func (a *ApplyAction) IPMA() bool {
return a.Flags&APPLY_ACT_IPMA != 0
}

func (a *ApplyAction) IPMD() bool {
return a.Flags&APPLY_ACT_IPMD != 0
}

func (a *ApplyAction) DFRT() bool {
return a.Flags&APPLY_ACT_DFRT != 0
}

func (a *ApplyAction) EDRT() bool {
return a.Flags&APPLY_ACT_EDRT != 0
}

func (a *ApplyAction) BDPN() bool {
return a.Flags&APPLY_ACT_BDPN != 0
}

func (a *ApplyAction) DDPN() bool {
return a.Flags&APPLY_ACT_DDPN != 0
}

func (a *ApplyAction) FSSM() bool {
return a.Flags&APPLY_ACT_FSSM != 0
}

func (a *ApplyAction) MBSU() bool {
return a.Flags&APPLY_ACT_MBSU != 0
}

type SessReport struct {
SEID uint64
Reports []Report
Expand Down
6 changes: 2 additions & 4 deletions testtools/upftest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (

"github.com/wmnsk/go-pfcp/ie"
"github.com/wmnsk/go-pfcp/message"

"github.com/free5gc/go-upf/internal/forwarder"
)

func main() {
Expand Down Expand Up @@ -118,15 +116,15 @@ func main() {
),
ie.NewCreateFAR(
ie.NewFARID(1),
ie.NewApplyAction(forwarder.SwitchU16Endian(2) /* 2: FORW(Forward) */),
ie.NewApplyAction(2), // 2: FORW(Forward)
ie.NewForwardingParameters(
ie.NewDestinationInterface(ie.DstInterfaceSGiLANN6LAN),
ie.NewNetworkInstance("internet"),
),
),
ie.NewCreateFAR(
ie.NewFARID(2),
ie.NewApplyAction(forwarder.SwitchU16Endian(2) /* 2: FORW(Forward) */),
ie.NewApplyAction(2), // 2: FORW(Forward)
ie.NewForwardingParameters(
ie.NewDestinationInterface(ie.DstInterfaceAccess),
ie.NewNetworkInstance("internet"),
Expand Down

0 comments on commit 78a6a67

Please sign in to comment.