Skip to content

Commit

Permalink
Customizable values for retransmission
Browse files Browse the repository at this point in the history
Close #22
  • Loading branch information
louisroyer committed Jul 16, 2024
1 parent 4cdfccf commit 2ce044a
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 6 deletions.
1 change: 1 addition & 0 deletions pfcp/api/entity_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ type PFCPEntityInterface interface {
GetPFCPSession(localIP string, seid SEID) (PFCPSessionInterface, error)
AddEstablishedPFCPSession(session PFCPSessionInterface) error
PrintPFCPRules()
Options() EntityOptionsInterface
}
12 changes: 12 additions & 0 deletions pfcp/api/entity_options_interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2024 Louis Royer and the go-pfcp-networking contributors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
// SPDX-License-Identifier: MIT
package api

import "time"

type EntityOptionsInterface interface {
MessageRetransmissionN1() int
MessageRetransmissionT1() time.Duration
}
8 changes: 7 additions & 1 deletion pfcp/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ type PFCPEntity struct {
// CP function send them to UP functions
sessionsMap api.SessionsMapInterface
kind string // "CP" or "UP"
options EntityOptions
}

func (e *PFCPEntity) Options() api.EntityOptionsInterface {
return e.options
}

// Add an Established PFCP Session
Expand Down Expand Up @@ -68,7 +73,7 @@ func newDefaultPFCPEntityHandlers() map[pfcputil.MessageType]PFCPMessageHandler
return m
}

func NewPFCPEntity(nodeID string, kind string) PFCPEntity {
func NewPFCPEntity(nodeID string, kind string, options EntityOptions) PFCPEntity {
return PFCPEntity{
nodeID: ie.NewNodeIDHeuristic(nodeID),
recoveryTimeStamp: nil,
Expand All @@ -78,6 +83,7 @@ func NewPFCPEntity(nodeID string, kind string) PFCPEntity {
associationsMap: NewAssociationsMap(),
sessionsMap: NewSessionsMap(),
kind: kind,
options: options,
}
}

Expand Down
7 changes: 5 additions & 2 deletions pfcp/entity_cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ type PFCPEntityCP struct {
}

func NewPFCPEntityCP(nodeID string) *PFCPEntityCP {
e := PFCPEntityCP{PFCPEntity: NewPFCPEntity(nodeID, "CP")}
return &e
return NewPFCPEntityCPWithOptions(nodeID, EntityOptions{})
}

func NewPFCPEntityCPWithOptions(nodeID string, options EntityOptions) *PFCPEntityCP {
return &PFCPEntityCP{PFCPEntity: NewPFCPEntity(nodeID, "CP", options)}
}
47 changes: 47 additions & 0 deletions pfcp/entity_options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2024 Louis Royer and the go-pfcp-networking contributors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
// SPDX-License-Identifier: MIT

package pfcp_networking

import (
"fmt"
"time"

"github.com/nextmn/go-pfcp-networking/pfcputil"
)

type EntityOptions struct {
messageRetransmissionT1 *time.Duration
messageRetransmissionN1 *int
}

func NewEntityOptions(messageRetransmissionT1 *time.Duration, messageRetransmissionN1 *int) (*EntityOptions, error) {
if (messageRetransmissionT1 != nil) && (*messageRetransmissionT1 < 1*time.Microsecond) {
return nil, fmt.Errorf("messageRetransmissionT1 must be strictly greater than zero.")
}
if (messageRetransmissionN1 != nil) && (*messageRetransmissionN1 < 0) {
return nil, fmt.Errorf("messageRetransmissionN1 must be greater than zero")
}
return &EntityOptions{
messageRetransmissionT1: messageRetransmissionT1,
messageRetransmissionN1: messageRetransmissionN1,
}, nil
}

func (eo EntityOptions) MessageRetransmissionT1() time.Duration {
if eo.messageRetransmissionT1 != nil {
return *eo.messageRetransmissionT1
} else {
return pfcputil.MESSAGE_RETRANSMISSION_T1
}
}

func (eo EntityOptions) MessageRetransmissionN1() int {
if eo.messageRetransmissionN1 != nil {
return *eo.messageRetransmissionN1
} else {
return pfcputil.MESSAGE_RETRANSMISSION_N1
}
}
6 changes: 5 additions & 1 deletion pfcp/entity_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ type PFCPEntityUP struct {
}

func NewPFCPEntityUP(nodeID string) *PFCPEntityUP {
e := PFCPEntityUP{PFCPEntity: NewPFCPEntity(nodeID, "UP")}
return NewPFCPEntityUPWithOptions(nodeID, EntityOptions{})
}

func NewPFCPEntityUPWithOptions(nodeID string, options EntityOptions) *PFCPEntityUP {
e := PFCPEntityUP{PFCPEntity: NewPFCPEntity(nodeID, "UP", options)}
err := e.initDefaultHandlers()
if err != nil {
log.Println(err)
Expand Down
4 changes: 2 additions & 2 deletions pfcp/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (peer *PFCPPeer) Send(msg message.Message) (m message.Message, err error) {
return nil, fmt.Errorf("Error on write: %s\n", err)
}

for i := 0; i < pfcputil.MESSAGE_RETRANSMISSION_N1; i++ {
for i := 0; i < peer.LocalEntity().Options().MessageRetransmissionN1(); i++ {
select {
case r := <-ch:
msg, err := message.Parse(r)
Expand All @@ -222,7 +222,7 @@ func (peer *PFCPPeer) Send(msg message.Message) (m message.Message, err error) {
return nil, fmt.Errorf("Unexpected incomming PFCP message type")
}
return msg, nil
case <-time.After(pfcputil.MESSAGE_RETRANSMISSION_T1):
case <-time.After(peer.LocalEntity().Options().MessageRetransmissionT1()):
// retry
_, err = peer.conn.WriteToUDP(b, peer.udpAddr)
if err != nil {
Expand Down

0 comments on commit 2ce044a

Please sign in to comment.