/
association.go
78 lines (68 loc) · 1.76 KB
/
association.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package pfcp
import (
"net"
"github.com/wmnsk/go-pfcp/ie"
"github.com/wmnsk/go-pfcp/message"
)
func (s *PfcpServer) handleAssociationSetupRequest(
req *message.AssociationSetupRequest,
addr net.Addr,
) {
s.log.Infoln("handleAssociationSetupRequest")
if req.NodeID == nil {
s.log.Errorln("not found NodeID")
return
}
rnodeid, err := req.NodeID.NodeID()
if err != nil {
s.log.Errorln(err)
return
}
s.log.Debugf("remote nodeid: %v\n", rnodeid)
// deleting the existing PFCP association and associated PFCP sessions,
// if a PFCP association was already established for the Node ID
// received in the request, regardless of the Recovery Timestamp
// received in the request.
if node, ok := s.rnodes[rnodeid]; ok {
s.log.Infof("delete node: %#+v\n", node)
node.Reset()
delete(s.rnodes, rnodeid)
}
node := s.NewNode(rnodeid, addr, s.driver)
s.rnodes[rnodeid] = node
rsp := message.NewAssociationSetupResponse(
req.Header.SequenceNumber,
newIeNodeID(s.nodeID),
ie.NewCause(ie.CauseRequestAccepted),
ie.NewRecoveryTimeStamp(s.recoveryTime),
// TODO:
// ie.NewUPFunctionFeatures(),
)
err = s.sendRspTo(rsp, addr)
if err != nil {
s.log.Errorln(err)
return
}
}
func (s *PfcpServer) handleAssociationUpdateRequest(
req *message.AssociationUpdateRequest,
addr net.Addr,
) {
s.log.Infoln("handleAssociationUpdateRequest not supported")
}
func (s *PfcpServer) handleAssociationReleaseRequest(
req *message.AssociationReleaseRequest,
addr net.Addr,
) {
s.log.Infoln("handleAssociationReleaseRequest not supported")
}
func newIeNodeID(nodeID string) *ie.IE {
ip := net.ParseIP(nodeID)
if ip != nil {
if ip.To4() != nil {
return ie.NewNodeID(nodeID, "", "")
}
return ie.NewNodeID("", nodeID, "")
}
return ie.NewNodeID("", "", nodeID)
}