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

Specify local ip address instead of guessing it #25

Merged
merged 1 commit into from
Jul 16, 2024
Merged
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
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
Loading