diff --git a/README.md b/README.md index 7937438..c8edbd6 100644 --- a/README.md +++ b/README.md @@ -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() @@ -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) diff --git a/pfcp/entity.go b/pfcp/entity.go index bc9a020..760b661 100644 --- a/pfcp/entity.go +++ b/pfcp/entity.go @@ -20,6 +20,7 @@ import ( type PFCPEntity struct { nodeID *ie.IE + listenAddr string recoveryTimeStamp *ie.IE handlers map[pfcputil.MessageType]PFCPMessageHandler conn *net.UDPConn @@ -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, @@ -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 { diff --git a/pfcp/entity_cp.go b/pfcp/entity_cp.go index 77bddc2..204d44e 100644 --- a/pfcp/entity_cp.go +++ b/pfcp/entity_cp.go @@ -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)} } diff --git a/pfcp/entity_up.go b/pfcp/entity_up.go index 1d2ce13..f05b03f 100644 --- a/pfcp/entity_up.go +++ b/pfcp/entity_up.go @@ -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)