Skip to content

Commit

Permalink
Check if PFCP Agent is up by trying to setup association and use esta…
Browse files Browse the repository at this point in the history
…blished association for all test cases (#552)

* Catch errors coming from function executing Docker command

* Check if PFCP Agent is up by trying to setup association; use established association for all test cases

* Clean test code

* revert changes to docker.go

* Rename to waitForPFCPAssociationSetup

* Decrease timeout to wait for PFCP responses

* Actions: Updated with changes from CI

* Trigger CI

Co-authored-by: Github Actions <actions@github>
  • Loading branch information
Tomasz Osiński and Github Actions committed Mar 10, 2022
1 parent d20aea0 commit ed39080
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 30 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/libp2p/go-reuseport v0.1.0
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/omec-project/pfcpsim v0.0.0-20220224085126-19a69dc4b36c
github.com/omec-project/pfcpsim v0.0.0-20220309084214-9414eb21802a
github.com/p4lang/p4runtime v1.3.0
github.com/prometheus/client_golang v1.11.0
github.com/sirupsen/logrus v1.8.1
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,10 @@ github.com/ncw/swift v1.0.47/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
github.com/omec-project/pfcpsim v0.0.0-20220224085126-19a69dc4b36c h1:HiRMUtwZXNg1ep6XIHNg4Uv/FnqpObW9iTAT0BX3PuA=
github.com/omec-project/pfcpsim v0.0.0-20220224085126-19a69dc4b36c/go.mod h1:VpozJhKRcQ5QRW1sl7RLwwqVi+Od7y+tId8419o6xz4=
github.com/omec-project/pfcpsim v0.0.0-20220309065921-4b91bcc14895 h1:TG4qrTzb1zWfu1utBuaaLgcqSL7foRLKY1VcX/J83Pc=
github.com/omec-project/pfcpsim v0.0.0-20220309065921-4b91bcc14895/go.mod h1:VpozJhKRcQ5QRW1sl7RLwwqVi+Od7y+tId8419o6xz4=
github.com/omec-project/pfcpsim v0.0.0-20220309084214-9414eb21802a h1:5WAZa30IUgeCmlpkTZDjIRw+n/AeYx0NB88PppsxUE0=
github.com/omec-project/pfcpsim v0.0.0-20220309084214-9414eb21802a/go.mod h1:VpozJhKRcQ5QRW1sl7RLwwqVi+Od7y+tId8419o6xz4=
github.com/onsi/ginkgo v0.0.0-20151202141238-7f8ab55aaf3b/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand Down
19 changes: 3 additions & 16 deletions test/integration/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,14 @@ func TestUPFBasedUeIPAllocation(t *testing.T) {
})
}

func TestBasicPFCPAssociation(t *testing.T) {
func TestPFCPHeartbeats(t *testing.T) {
setup(t, ConfigDefault)
defer teardown(t)

err := pfcpClient.SetupAssociation()
require.NoErrorf(t, err, "failed to setup PFCP association")

time.Sleep(time.Second * 10)

// Heartbeats interval is 5 seconds by default.
// If the association is alive after 10 seconds it means that PFCP Agent handles heartbeats properly.
require.True(t, pfcpClient.IsAssociationAlive())
}

Expand Down Expand Up @@ -273,15 +272,9 @@ func TestUEBuffering(t *testing.T) {
},
}

err := pfcpClient.SetupAssociation()
require.NoErrorf(t, err, "failed to setup PFCP association")

testUEAttach(t, fillExpected(&tc))
testUEBuffer(t, fillExpected(&tc))
testUEDetach(t, fillExpected(&tc))

err = pfcpClient.TeardownAssociation()
require.NoErrorf(t, err, "failed to gracefully release PFCP association")
}

func fillExpected(tc *testCase) *testCase {
Expand Down Expand Up @@ -433,15 +426,9 @@ func testUEDetach(t *testing.T, testcase *testCase) {
}

func testUEAttachDetach(t *testing.T, testcase *testCase) {
err := pfcpClient.SetupAssociation()
require.NoErrorf(t, err, "failed to setup PFCP association")

testUEAttach(t, testcase)
testUEDetach(t, testcase)

err = pfcpClient.TeardownAssociation()
require.NoErrorf(t, err, "failed to gracefully release PFCP association")

if isFastpathUP4() {
// clear Applications table
// FIXME: Temporary solution. They should be cleared by pfcpiface, see SDFAB-960
Expand Down
43 changes: 32 additions & 11 deletions test/integration/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,28 @@ func waitForPortOpen(net string, host string, port string) error {
}
}

func waitForPFCPAgentToStart() error {
return waitForPortOpen("udp", "127.0.0.1", "8805")
// waitForPFCPAssociationSetup checks if PFCP Agent is started by trying to create PFCP association.
// It retries every 1.5 seconds (0.5 seconds of interval between tries + 1 seconds that PFCP Client waits for response).
func waitForPFCPAssociationSetup(pfcpClient *pfcpsim.PFCPClient) error {
timeout := time.After(30 * time.Second)
ticker := time.Tick(500 * time.Millisecond)

// Decrease timeout to wait for PFCP responses.
// This decreases time to wait for PFCP Agent to start.
pfcpClient.SetPFCPResponseTimeout(1 * time.Second)

// Keep trying until we're timed out or get a result/error
for {
select {
case <-timeout:
return errors.New("timed out")
case <-ticker:
// each test case requires PFCP Association, so we don't teardown it once we notice it's established.
if err := pfcpClient.SetupAssociation(); err == nil {
return nil
}
}
}
}

func waitForBESSMockToStart() error {
Expand Down Expand Up @@ -256,24 +276,20 @@ func setup(t *testing.T, configType uint32) {
require.NoError(t, err)
providers.RunDockerCommandAttach("pfcpiface",
"/bin/pfcpiface -config /config/upf.json")
if isFastpathUP4() {
// FIXME: remove once we remove sleep in UP4.tryConnect()
time.Sleep(2 * time.Second)
}
case ModeNative:
pfcpAgent = pfcpiface.NewPFCPIface(GetConfig(os.Getenv(EnvFastpath), configType))
go pfcpAgent.Run()
default:
t.Fatal("Unexpected test mode")
}

// wait for PFCP Agent to initialize, blocking
err := waitForPFCPAgentToStart()
require.NoErrorf(t, err, "failed to start PFCP Agent: %v", err)

pfcpClient = pfcpsim.NewPFCPClient("127.0.0.1")
err = pfcpClient.ConnectN4("127.0.0.1")
err := pfcpClient.ConnectN4("127.0.0.1")
require.NoErrorf(t, err, "failed to connect to UPF")

// wait for PFCP Agent to initialize, blocking
err = waitForPFCPAssociationSetup(pfcpClient)
require.NoErrorf(t, err, "failed to start PFCP Agent: %v", err)
}

func teardown(t *testing.T) {
Expand All @@ -288,6 +304,11 @@ func teardown(t *testing.T) {
}
}

if pfcpClient.IsAssociationAlive() {
err := pfcpClient.TeardownAssociation()
require.NoError(t, err)
}

if pfcpClient != nil {
pfcpClient.DisconnectN4()
}
Expand Down

0 comments on commit ed39080

Please sign in to comment.