Skip to content

Commit

Permalink
Specify local ip address instead of guessing it
Browse files Browse the repository at this point in the history
  • Loading branch information
louisroyer committed Jul 16, 2024
1 parent 2ce044a commit a83c2e4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
### UPF

```golang
upNode := NewPFCPEntityUP(UPFADDR)
upNode := NewPFCPEntityUP(UPF_NODE_ID, UPF_IP_ADDR) // node id can be an IP Address or a FQDN
upNode.Start()
// Access list of associations
associations := upNode.GetPFCPAssociations()
Expand All @@ -21,7 +21,7 @@ sessions := upNode.GetPFCPSessions()
### SMF

```golang
cpNode := NewPFCPEntityCP(SMFADDR)
cpNode := NewPFCPEntityCP(SMF_NODE_ID, SMF_IP_ADDR) // node id can be an IP Address or a FQDN
cpNode.Start()
association, _ := cpNode.NewEstablishedPFCPAssociation(ie.NewNodeIDHeuristic(UPFADDR))
session, _ := a.CreateSession(pdrs, fars)
Expand Down
11 changes: 5 additions & 6 deletions pfcp/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

type PFCPEntity struct {
nodeID *ie.IE
listenAddr string
recoveryTimeStamp *ie.IE
handlers map[pfcputil.MessageType]PFCPMessageHandler
conn *net.UDPConn
Expand Down Expand Up @@ -73,9 +74,10 @@ func newDefaultPFCPEntityHandlers() map[pfcputil.MessageType]PFCPMessageHandler
return m
}

func NewPFCPEntity(nodeID string, kind string, options EntityOptions) PFCPEntity {
func NewPFCPEntity(nodeID string, listenAddr string, kind string, options EntityOptions) PFCPEntity {
return PFCPEntity{
nodeID: ie.NewNodeIDHeuristic(nodeID),
listenAddr: listenAddr,
recoveryTimeStamp: nil,
handlers: newDefaultPFCPEntityHandlers(),
conn: nil,
Expand All @@ -89,11 +91,8 @@ func NewPFCPEntity(nodeID string, kind string, options EntityOptions) PFCPEntity

func (e *PFCPEntity) listen() error {
e.recoveryTimeStamp = ie.NewRecoveryTimeStamp(time.Now())
// TODO: if NodeID is a FQDN, we can expose multiple ip addresses
ipAddr, err := e.NodeID().NodeID()
if err != nil {
return err
}
// TODO: listen on multiple ip addresses (ipv4 + ipv6)
ipAddr := e.listenAddr
udpAddr := pfcputil.CreateUDPAddr(ipAddr, pfcputil.PFCP_PORT)
laddr, err := net.ResolveUDPAddr("udp", udpAddr)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pfcp/entity_cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ type PFCPEntityCP struct {
PFCPEntity
}

func NewPFCPEntityCP(nodeID string) *PFCPEntityCP {
return NewPFCPEntityCPWithOptions(nodeID, EntityOptions{})
func NewPFCPEntityCP(nodeID string, listenAddr string) *PFCPEntityCP {
return NewPFCPEntityCPWithOptions(nodeID, listenAddr, EntityOptions{})
}

func NewPFCPEntityCPWithOptions(nodeID string, options EntityOptions) *PFCPEntityCP {
return &PFCPEntityCP{PFCPEntity: NewPFCPEntity(nodeID, "CP", options)}
func NewPFCPEntityCPWithOptions(nodeID string, listenAddr string, options EntityOptions) *PFCPEntityCP {
return &PFCPEntityCP{PFCPEntity: NewPFCPEntity(nodeID, listenAddr, "CP", options)}
}
8 changes: 4 additions & 4 deletions pfcp/entity_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ type PFCPEntityUP struct {
PFCPEntity
}

func NewPFCPEntityUP(nodeID string) *PFCPEntityUP {
return NewPFCPEntityUPWithOptions(nodeID, EntityOptions{})
func NewPFCPEntityUP(nodeID string, listenAddr string) *PFCPEntityUP {
return NewPFCPEntityUPWithOptions(nodeID, listenAddr, EntityOptions{})
}

func NewPFCPEntityUPWithOptions(nodeID string, options EntityOptions) *PFCPEntityUP {
e := PFCPEntityUP{PFCPEntity: NewPFCPEntity(nodeID, "UP", options)}
func NewPFCPEntityUPWithOptions(nodeID string, listenAddr string, options EntityOptions) *PFCPEntityUP {
e := PFCPEntityUP{PFCPEntity: NewPFCPEntity(nodeID, listenAddr, "UP", options)}
err := e.initDefaultHandlers()
if err != nil {
log.Println(err)
Expand Down

0 comments on commit a83c2e4

Please sign in to comment.