-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupfadapter.go
72 lines (61 loc) · 1.92 KB
/
upfadapter.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
// SPDX-FileCopyrightText: 2022-present Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package main
import (
"encoding/json"
"io"
"net/http"
"github.com/omec-project/upfadapter/config"
"github.com/omec-project/upfadapter/logger"
"github.com/omec-project/upfadapter/pfcp"
"github.com/omec-project/upfadapter/pfcp/udp"
"github.com/wmnsk/go-pfcp/message"
)
// Handler for SMF initiated msgs
func handler(w http.ResponseWriter, req *http.Request) {
reqBody, err := io.ReadAll(req.Body)
if err != nil {
logger.AppLog.Errorf("server: could not read request body: %s", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
}
var udpPodMsg config.UdpPodPfcpMsg
err = json.Unmarshal(reqBody, &udpPodMsg)
if err != nil {
logger.AppLog.Errorln("error unmarshalling pfcp msg")
return
}
pfcpMessage, err := message.Parse(udpPodMsg.Msg.Body)
if err != nil {
logger.AppLog.Errorln("error parsing pfcp msg")
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
logger.AppLog.Debugf("received msg type [%v], upf nodeId [%s], smfIp [%v], msg [%v]",
pfcpMessage.MessageType(), udpPodMsg.UpNodeID.NodeIdValue, udpPodMsg.SmfIp, udpPodMsg.Msg)
pfcpJsonRsp, err := pfcp.ForwardPfcpMsgToUpf(pfcpMessage, udpPodMsg.UpNodeID)
if err != nil {
logger.AppLog.Errorf("error forwarding pfcp msg to UPF: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
_, err = w.Write(pfcpJsonRsp)
if err != nil {
logger.AppLog.Errorf("error writing pfcp msg: %v", err)
}
logger.AppLog.Debugf("response sent for %v", pfcpMessage.MessageType())
}
// UDP handler for pfcp msg from UPF
func init() {
go udp.Run(pfcp.Dispatch)
}
// Handler for msgs from SMF
func main() {
http.HandleFunc("/", handler)
err := http.ListenAndServe(":8090", nil)
if err != nil {
logger.AppLog.Errorf("error listening TCP connection: %v", err)
}
}