diff --git a/go.mod b/go.mod index f6e272309..ea8991ec0 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 67931ed16..d91e29252 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/test/integration/basic_test.go b/test/integration/basic_test.go index 664f56cf9..8dada58a8 100644 --- a/test/integration/basic_test.go +++ b/test/integration/basic_test.go @@ -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()) } @@ -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 { @@ -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 diff --git a/test/integration/framework.go b/test/integration/framework.go index 90df97b91..52a39d52a 100644 --- a/test/integration/framework.go +++ b/test/integration/framework.go @@ -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 { @@ -256,10 +276,6 @@ 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() @@ -267,13 +283,13 @@ func setup(t *testing.T, configType uint32) { 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) { @@ -288,6 +304,11 @@ func teardown(t *testing.T) { } } + if pfcpClient.IsAssociationAlive() { + err := pfcpClient.TeardownAssociation() + require.NoError(t, err) + } + if pfcpClient != nil { pfcpClient.DisconnectN4() }