Skip to content
Merged

Lint #56

Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ctx := context.TODO()
cpNode := NewPFCPEntityCP(SMF_NODE_ID, SMF_IP_ADDR) // node id can be an IP Address or a FQDN
go cpNode.ListenAndServeContext(ctx)
cpNode.WaitReady(ctx)
association, _ := cpNode.NewEstablishedPFCPAssociation(ie.NewNodeIDHeuristic(UPFADDR))
association, _ := cpNode.NewEstablishedPFCPAssociation(ctx, ie.NewNodeIDHeuristic(UPFADDR))
session, _ := a.CreateSession(pdrs, fars)

```
Expand Down
6 changes: 4 additions & 2 deletions pfcp/api/association_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
package api

import (
"context"

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

type SEID = uint64
type PFCPAssociationInterface interface {
PFCPPeerInterface
SetupInitiatedByCP() error
SetupInitiatedByCP(ctx context.Context) error
GetNextSEID() SEID
CreateSession(remoteFseid *ie.IE, pdrs PDRMapInterface, fars FARMapInterface) (session PFCPSessionInterface, err error)
CreateSession(ctx context.Context, remoteFseid *ie.IE, pdrs PDRMapInterface, fars FARMapInterface) (session PFCPSessionInterface, err error)
}
2 changes: 1 addition & 1 deletion pfcp/api/entity_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type PFCPEntityInterface interface {
IsControlPlane() bool
NodeID() *ie.IE
RecoveryTimeStamp() *ie.IE
NewEstablishedPFCPAssociation(nodeID *ie.IE) (association PFCPAssociationInterface, err error)
NewEstablishedPFCPAssociation(ctx context.Context, nodeID *ie.IE) (association PFCPAssociationInterface, err error)
RemovePFCPAssociation(association PFCPAssociationInterface) error
GetPFCPAssociation(nid string) (association PFCPAssociationInterface, err error)
GetPFCPSessions() []PFCPSessionInterface
Expand Down
4 changes: 3 additions & 1 deletion pfcp/api/peer_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
package api

import (
"context"

"github.com/wmnsk/go-pfcp/ie"
"github.com/wmnsk/go-pfcp/message"
)
Expand All @@ -19,5 +21,5 @@ type PFCPPeerInterface interface {
IsUserPlane() bool
IsControlPlane() bool
LocalEntity() PFCPEntityInterface
NewEstablishedPFCPAssociation() (PFCPAssociationInterface, error)
NewEstablishedPFCPAssociation(ctx context.Context) (PFCPAssociationInterface, error)
}
30 changes: 16 additions & 14 deletions pfcp/association.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package pfcp_networking

import (
"context"
"fmt"
"net"
"time"
Expand All @@ -23,14 +24,13 @@ type PFCPAssociation struct {
}

// Create a new PFCPAssociation, this association is already set-up
func newEstablishedPFCPAssociation(peer api.PFCPPeerInterface) (api.PFCPAssociationInterface, error) {
func newEstablishedPFCPAssociation(ctx context.Context, peer api.PFCPPeerInterface) (api.PFCPAssociationInterface, error) {
association := PFCPAssociation{
PFCPPeerInterface: peer,
isSetup: false,
sessionIDPool: NewSessionIDPool(),
}
err := association.SetupInitiatedByCP()
if err != nil {
if err := association.SetupInitiatedByCP(ctx); err != nil {
return nil, err
}
return &association, nil
Expand All @@ -57,14 +57,14 @@ func (association *PFCPAssociation) GetNextSEID() api.SEID {
// clause 6.2.6.3).
// The CP function and the UP function shall support the PFCP Association Setup initiated by the CP function. The CP
// function and the UP function may additionally support the PFCP Association Setup initiated by the UP function.
func (association *PFCPAssociation) SetupInitiatedByCP() error {
func (association *PFCPAssociation) SetupInitiatedByCP(ctx context.Context) error {
if association.isSetup {
return fmt.Errorf("Association is already set up")
return fmt.Errorf("association is already set up")
}
switch {
case association.LocalEntity().IsUserPlane():
association.isSetup = true
go association.heartMonitoring()
go association.heartMonitoring(ctx)
return nil
case association.LocalEntity().IsControlPlane():
sar := message.NewAssociationSetupRequest(0, association.LocalEntity().NodeID(), association.LocalEntity().RecoveryTimeStamp())
Expand All @@ -83,17 +83,17 @@ func (association *PFCPAssociation) SetupInitiatedByCP() error {
}
if cause == ie.CauseRequestAccepted {
association.isSetup = true
go association.heartMonitoring()
go association.heartMonitoring(ctx)
return nil
}
return fmt.Errorf("Association setup request rejected")
return fmt.Errorf("association setup request rejected")
default:
return fmt.Errorf("Local PFCP entity is not a UP function, neither a CP function.")
return fmt.Errorf("local PFCP entity is not a UP function, neither a CP function")
}
}

// Start monitoring heart of a PFCP Association
func (association *PFCPAssociation) heartMonitoring() error {
func (association *PFCPAssociation) heartMonitoring(ctx context.Context) error {
defer association.Close()
checkInterval := 30 * time.Second
for {
Expand All @@ -106,6 +106,8 @@ func (association *PFCPAssociation) heartMonitoring() error {
if err != nil {
return err
}
case <-ctx.Done():
return ctx.Err()
}
}
}
Expand Down Expand Up @@ -141,7 +143,7 @@ func (association *PFCPAssociation) getFSEID(seid api.SEID) (*ie.IE, error) {
ip4, err4 := net.ResolveIPAddr("ip4", nodeID)
ip6, err6 := net.ResolveIPAddr("ip6", nodeID)
if err4 != nil && err6 != nil {
return nil, fmt.Errorf("Cannot resolve NodeID")
return nil, fmt.Errorf("cannot resolve NodeID")
}
switch {
case err4 == nil && err6 == nil:
Expand All @@ -151,14 +153,14 @@ func (association *PFCPAssociation) getFSEID(seid api.SEID) (*ie.IE, error) {
case err4 != nil && err6 == nil:
localFseid = ie.NewFSEID(seid, nil, ip6.IP.To16())
case err4 != nil && err6 != nil:
return nil, fmt.Errorf("Cannot resolve NodeID")
return nil, fmt.Errorf("cannot resolve NodeID")
}
}
return localFseid, nil
}

// remoteFseid can be nil if caller is at CP function side
func (association *PFCPAssociation) CreateSession(remoteFseid *ie.IE, pdrs api.PDRMapInterface, fars api.FARMapInterface) (session api.PFCPSessionInterface, err error) {
func (association *PFCPAssociation) CreateSession(ctx context.Context, remoteFseid *ie.IE, pdrs api.PDRMapInterface, fars api.FARMapInterface) (session api.PFCPSessionInterface, err error) {
// Generation of the F-SEID
localSEID := association.GetNextSEID()
localFseid, err := association.getFSEID(localSEID)
Expand All @@ -176,7 +178,7 @@ func (association *PFCPAssociation) CreateSession(remoteFseid *ie.IE, pdrs api.P
// Safe function to create FSEID
func NewFSEID(seid api.SEID, v4, v6 *net.IPAddr) (*ie.IE, error) {
if v4 == nil && v6 == nil {
return nil, fmt.Errorf("Cannot create FSEID with no IP Address")
return nil, fmt.Errorf("cannot create FSEID with no IP Address")
}
var ip4, ip6 net.IP
if v4 != nil {
Expand Down
4 changes: 2 additions & 2 deletions pfcp/association_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (a *AssociationsMap) Add(association api.PFCPAssociationInterface) error {
}
if _, exists := a.associations[nid]; exists {
// Only one association shall be setup between given pair of CP and UP functions.
return fmt.Errorf("Association already exist.")
return fmt.Errorf("association already exist")
}
a.muAssociations.Lock()
defer a.muAssociations.Unlock()
Expand All @@ -70,7 +70,7 @@ func (a *AssociationsMap) Get(nid string) (association api.PFCPAssociationInterf
if asso, exists := a.associations[nid]; exists {
return asso, nil
}
return nil, fmt.Errorf("Association does not exist.")
return nil, fmt.Errorf("association does not exist")
}

// Update a Association
Expand Down
22 changes: 11 additions & 11 deletions pfcp/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,27 +144,27 @@ func (e *PFCPEntity) GetHandler(t pfcputil.MessageType) (h PFCPMessageHandler, e
if f, exists := e.handlers[t]; exists {
return f, nil
}
return nil, fmt.Errorf("Received unexpected PFCP message type")
return nil, fmt.Errorf("received unexpected PFCP message type")
}

func (e *PFCPEntity) AddHandler(t pfcputil.MessageType, h PFCPMessageHandler) error {
if e.RecoveryTimeStamp() != nil {
return fmt.Errorf("Cannot add handler to already started PFCP Entity")
return fmt.Errorf("cannot add handler to already started PFCP Entity")
}
if !pfcputil.IsMessageTypeRequest(t) {
return fmt.Errorf("Only request messages can have a handler")
return fmt.Errorf("only request messages can have a handler")
}
e.handlers[t] = h
return nil
}

func (e *PFCPEntity) AddHandlers(funcs map[pfcputil.MessageType]PFCPMessageHandler) error {
if e.RecoveryTimeStamp() != nil {
return fmt.Errorf("Cannot add handler to already started PFCP Entity")
return fmt.Errorf("cannot add handler to already started PFCP Entity")
}
for t := range funcs {
if !pfcputil.IsMessageTypeRequest(t) {
return fmt.Errorf("Only request messages can have a handler")
return fmt.Errorf("only request messages can have a handler")
}
}

Expand All @@ -184,22 +184,22 @@ func (e *PFCPEntity) GetPFCPAssociation(nid string) (association api.PFCPAssocia
return e.associationsMap.Get(nid)
}

func (e *PFCPEntity) NewEstablishedPFCPAssociation(nodeID *ie.IE) (association api.PFCPAssociationInterface, err error) {
func (e *PFCPEntity) NewEstablishedPFCPAssociation(ctx context.Context, nodeID *ie.IE) (association api.PFCPAssociationInterface, err error) {
peer, err := newPFCPPeerUP(e, nodeID)
if err != nil {
return nil, err
}
if e.RecoveryTimeStamp() == nil {
return nil, fmt.Errorf("Local PFCP entity is not started")
return nil, fmt.Errorf("local PFCP entity is not started")
}
nid, err := nodeID.NodeID()
if err != nil {
return nil, err
}
if !e.associationsMap.CheckNonExist(nid) {
return nil, fmt.Errorf("Association already exists")
return nil, fmt.Errorf("association already exists")
}
a, err := peer.NewEstablishedPFCPAssociation()
a, err := peer.NewEstablishedPFCPAssociation(ctx)
if err != nil {
return nil, err
}
Expand All @@ -224,7 +224,7 @@ func (e *PFCPEntity) ListenAndServeContext(ctx context.Context) error {
return err
} else {
e.Serve(ctx, conn)
return fmt.Errorf("Server closed")
return fmt.Errorf("server closed")
}
}

Expand All @@ -242,7 +242,7 @@ func (e *PFCPEntity) WaitReady(ctx context.Context) error {
// Always return a non-nil error and close the PFCPConn.
func (e *PFCPEntity) Serve(ctx context.Context, conn *PFCPConn) error {
if conn == nil {
return fmt.Errorf("Conn is nil")
return fmt.Errorf("conn is nil")
}
newconn := &onceClosePfcpConn{PFCPConn: conn}
e.registerPfcpConn(newconn)
Expand Down
6 changes: 3 additions & 3 deletions pfcp/entity_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ func (eo EntityOptions) MessageRetransmissionT1() time.Duration {
return eo.messageRetransmissionT1
}

func (eo EntityOptions) SetMessageRetransmissionT1(messageRetransmissionT1 time.Duration) error {
func (eo *EntityOptions) SetMessageRetransmissionT1(messageRetransmissionT1 time.Duration) error {
if messageRetransmissionT1 < 1*time.Microsecond {
return fmt.Errorf("messageRetransmissionT1 must be strictly greater than zero.")
return fmt.Errorf("messageRetransmissionT1 must be strictly greater than zero")
}
eo.messageRetransmissionT1 = messageRetransmissionT1
return nil
Expand All @@ -47,7 +47,7 @@ func (eo EntityOptions) MessageRetransmissionN1() int {
return eo.messageRetransmissionN1
}

func (eo EntityOptions) SetMessageRetransmissionN1(messageRetransmissionN1 int) error {
func (eo *EntityOptions) SetMessageRetransmissionN1(messageRetransmissionN1 int) error {
if messageRetransmissionN1 < 0 {
return fmt.Errorf("messageRetransmissionN1 must be greater than zero")
}
Expand Down
4 changes: 2 additions & 2 deletions pfcp/far.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (far *FAR) ForwardingParameters() (*ie.IE, error) {
// This IE shall be present when the Apply Action requests
// the packets to be forwarded. It may be present otherwise.
if far.forwardingParameters == nil {
return nil, fmt.Errorf("No forwarding parameters ie")
return nil, fmt.Errorf("no forwarding parameters ie")
}
return far.forwardingParameters, nil

Expand All @@ -64,7 +64,7 @@ func (far *FAR) Update(farUpdate api.FARUpdateInterface) error {
return err
}
if farId != farUpdateId {
return fmt.Errorf("Wrong FAR ID")
return fmt.Errorf("wrong FAR ID")
}

// Update ApplyAction
Expand Down
Loading
Loading