Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable configuring PFCP response timeout #52

Merged
merged 2 commits into from
Mar 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions pkg/pfcpsim/pfcpsim.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
const (
PFCPStandardPort = 8805
DefaultHeartbeatPeriod = 5
DefaultResponseTimeout = 5 * time.Second
)

// PFCPClient enables to simulate a client sending PFCP messages towards the UPF.
Expand All @@ -43,12 +44,16 @@ type PFCPClient struct {

localAddr string
conn *net.UDPConn

// responseTimeout timeout to wait for PFCP response (default: 5 seconds)
responseTimeout time.Duration
}

func NewPFCPClient(localAddr string) *PFCPClient {
client := &PFCPClient{
sequenceNumber: 0,
localAddr: localAddr,
sequenceNumber: 0,
localAddr: localAddr,
responseTimeout: DefaultResponseTimeout,
}

client.ctx = context.Background()
Expand All @@ -58,6 +63,10 @@ func NewPFCPClient(localAddr string) *PFCPClient {
return client
}

func (c *PFCPClient) SetPFCPResponseTimeout(timeout time.Duration) {
c.responseTimeout = timeout
}

func (c *PFCPClient) getNextSequenceNumber() uint32 {
c.seqNumLock.Lock()
defer c.seqNumLock.Unlock()
Expand Down Expand Up @@ -158,20 +167,23 @@ func (c *PFCPClient) DisconnectN4() {
c.conn.Close()
}

func (c *PFCPClient) PeekNextHeartbeatResponse(timeout time.Duration) (*message.HeartbeatResponse, error) {
func (c *PFCPClient) PeekNextHeartbeatResponse() (*message.HeartbeatResponse, error) {
select {
case msg := <-c.heartbeatsChan:
return msg, nil
case <-time.After(timeout * time.Second):
case <-time.After(c.responseTimeout):
return nil, NewTimeoutExpiredError()
}
}

func (c *PFCPClient) PeekNextResponse(timeout time.Duration) (message.Message, error) {
// PeekNextResponse can be used to wait for a next PFCP message from a peer.
// It's a blocking operation, which is timed out after c.responseTimeout period (5 seconds by default).
// Use SetPFCPResponseTimeout() to configure a custom timeout.
func (c *PFCPClient) PeekNextResponse() (message.Message, error) {
select {
case msg := <-c.recvChan:
return msg, nil
case <-time.After(timeout * time.Second):
case <-time.After(c.responseTimeout):
return nil, NewTimeoutExpiredError()
}
}
Expand Down Expand Up @@ -281,7 +293,7 @@ func (c *PFCPClient) SendAndRecvHeartbeat() error {
return err
}

_, err = c.PeekNextHeartbeatResponse(5)
_, err = c.PeekNextHeartbeatResponse()
if err != nil {
c.setAssociationStatus(false)
return err
Expand All @@ -300,7 +312,7 @@ func (c *PFCPClient) SetupAssociation() error {
return err
}

resp, err := c.PeekNextResponse(DefaultHeartbeatPeriod)
resp, err := c.PeekNextResponse()
if err != nil {
return err
}
Expand Down Expand Up @@ -338,7 +350,7 @@ func (c *PFCPClient) TeardownAssociation() error {
return err
}

resp, err := c.PeekNextResponse(5)
resp, err := c.PeekNextResponse()
if err != nil {
return err
}
Expand Down Expand Up @@ -368,7 +380,7 @@ func (c *PFCPClient) EstablishSession(pdrs []*ieLib.IE, fars []*ieLib.IE, qers [
return nil, err
}

resp, err := c.PeekNextResponse(5)
resp, err := c.PeekNextResponse()
if err != nil {
return nil, NewTimeoutExpiredError(err)
}
Expand Down Expand Up @@ -405,7 +417,7 @@ func (c *PFCPClient) ModifySession(sess *PFCPSession, pdrs []*ieLib.IE, fars []*
return err
}

resp, err := c.PeekNextResponse(5)
resp, err := c.PeekNextResponse()
if err != nil {
return NewTimeoutExpiredError(err)
}
Expand All @@ -430,7 +442,7 @@ func (c *PFCPClient) DeleteSession(sess *PFCPSession) error {
return err
}

resp, err := c.PeekNextResponse(5)
resp, err := c.PeekNextResponse()
if err != nil {
return err
}
Expand Down