Commit b8e615f4 authored by 吴洲洋's avatar 吴洲洋

update server.go support new smf

parent b6f4048c
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"n4/pkg/log" "n4/pkg/log"
"n4/pkg/pfcp/ie" "n4/pkg/pfcp/ie"
"n4/pkg/pfcp/message" "n4/pkg/pfcp/message"
"n4/pkg/upf/sql"
"n4/pkg/upf/vpp" "n4/pkg/upf/vpp"
"n4/pkg/vpp/binapi/upf" "n4/pkg/vpp/binapi/upf"
"net" "net"
...@@ -98,6 +99,8 @@ func handleClient(config *conf.Config, conn *net.UDPConn) { ...@@ -98,6 +99,8 @@ func handleClient(config *conf.Config, conn *net.UDPConn) {
func handleMsg(config *conf.Config, msgType uint8, msgContent message.Message) []byte { func handleMsg(config *conf.Config, msgType uint8, msgContent message.Message) []byte {
switch msgType { switch msgType {
case message.MsgTypeAssociationSetupRequest:
return handleAssociationSetupRequest(msgContent)
case message.MsgTypeHeartbeatRequest: case message.MsgTypeHeartbeatRequest:
return handleHeartBeatMsg(msgContent) return handleHeartBeatMsg(msgContent)
case message.MsgTypeSessionEstablishmentRequest: case message.MsgTypeSessionEstablishmentRequest:
...@@ -110,6 +113,27 @@ func handleMsg(config *conf.Config, msgType uint8, msgContent message.Message) [ ...@@ -110,6 +113,27 @@ func handleMsg(config *conf.Config, msgType uint8, msgContent message.Message) [
return nil return nil
} }
func handleAssociationSetupRequest(msgContent message.Message) []byte {
msg, ok := msgContent.(*message.AssociationSetupRequest)
if !ok {
log.Warn("got unexpected message: " + msg.MessageTypeName())
}
smfIP, _ := msg.NodeID.NodeID()
log.Info("Get association request from " + smfIP)
sql.InsertIP(smfIP, sql.ASSOCIATIONTRUE)
nodeID := ie.NewNodeID("192.168.2.216", "", "")
ts := ie.NewRecoveryTimeStamp(time.Now())
cp := ie.NewCPFunctionFeatures(16)
response, err := message.NewAssociationSetupResponse(0, 0, 0, nodeID, ts, cp).Marshal()
if err != nil {
log.Warn("Encapsulate Association Setup Response is failed, info is " + err.Error())
}
return response
}
func handleHeartBeatMsg(msgContent message.Message) []byte { func handleHeartBeatMsg(msgContent message.Message) []byte {
msg, ok := msgContent.(*message.HeartbeatRequest) msg, ok := msgContent.(*message.HeartbeatRequest)
...@@ -137,12 +161,6 @@ func handleHeartBeatMsg(msgContent message.Message) []byte { ...@@ -137,12 +161,6 @@ func handleHeartBeatMsg(msgContent message.Message) []byte {
func handleSessionEstablishmentMsg(config *conf.Config, msgContent message.Message) []byte { func handleSessionEstablishmentMsg(config *conf.Config, msgContent message.Message) []byte {
msg, ok := msgContent.(*message.SessionEstablishmentRequest) msg, ok := msgContent.(*message.SessionEstablishmentRequest)
defer func() {
err := recover()
if err != nil {
log.Error("Panicing %s\n", err)
}
}()
if !ok { if !ok {
log.Warn("got unexpected message: " + msg.MessageTypeName()) log.Warn("got unexpected message: " + msg.MessageTypeName())
...@@ -166,9 +184,9 @@ func handleSessionEstablishmentMsg(config *conf.Config, msgContent message.Messa ...@@ -166,9 +184,9 @@ func handleSessionEstablishmentMsg(config *conf.Config, msgContent message.Messa
sourceInterface, _ := pdiIEs[0].SourceInterface() sourceInterface, _ := pdiIEs[0].SourceInterface()
//fteid, _ := pdiIEs[1].FTEID() //fteid, _ := pdiIEs[1].FTEID()
ueipaddress, _ := pdiIEs[2].UEIPAddress() ueipaddress, _ := pdiIEs[2].UEIPAddress()
farid, _ := createPDR[3].FARID()
createFAR, _ := msg.CreateFAR[0].CreateFAR() createFAR, _ := msg.CreateFAR[0].CreateFAR()
farid, _ := createFAR[0].FARID()
applyAction, _ := createFAR[1].ApplyAction() applyAction, _ := createFAR[1].ApplyAction()
forwardingParameters, _ := createFAR[2].ForwardingParameters() forwardingParameters, _ := createFAR[2].ForwardingParameters()
destinationInterface, _ := forwardingParameters[0].DestinationInterface() destinationInterface, _ := forwardingParameters[0].DestinationInterface()
...@@ -199,7 +217,6 @@ func handleSessionEstablishmentMsg(config *conf.Config, msgContent message.Messa ...@@ -199,7 +217,6 @@ func handleSessionEstablishmentMsg(config *conf.Config, msgContent message.Messa
Flags: 1, Flags: 1,
Teid: ueUpTeid[ueipaddress.IPv4Address.String()], Teid: ueUpTeid[ueipaddress.IPv4Address.String()],
IP: upf.BuptNodeValueIP4(ip4ToUint(config.Gnb)), IP: upf.BuptNodeValueIP4(ip4ToUint(config.Gnb)),
//IP: upf.BuptNodeValueIP4([4]uint8{192, 168, 2, 137}),
}, },
UeAddr: upf.BuptPfcpUeIPAddress{ UeAddr: upf.BuptPfcpUeIPAddress{
Flags: 2, Flags: 2,
...@@ -251,12 +268,6 @@ func handleSessionEstablishmentMsg(config *conf.Config, msgContent message.Messa ...@@ -251,12 +268,6 @@ func handleSessionEstablishmentMsg(config *conf.Config, msgContent message.Messa
func handleSessionModificationMsg(config *conf.Config, msgContent message.Message) []byte { func handleSessionModificationMsg(config *conf.Config, msgContent message.Message) []byte {
msg, ok := msgContent.(*message.SessionModificationRequest) msg, ok := msgContent.(*message.SessionModificationRequest)
defer func() {
err := recover()
if err != nil {
log.Error("Panicing %s\n", err)
}
}()
if !ok { if !ok {
log.Warn("got unexpected message: " + msg.MessageTypeName()) log.Warn("got unexpected message: " + msg.MessageTypeName())
...@@ -269,12 +280,8 @@ func handleSessionModificationMsg(config *conf.Config, msgContent message.Messag ...@@ -269,12 +280,8 @@ func handleSessionModificationMsg(config *conf.Config, msgContent message.Messag
createPDR, _ := msg.CreatePDR[0].CreatePDR() createPDR, _ := msg.CreatePDR[0].CreatePDR()
pdrid, _ := createPDR[0].PacketDetectionRuleID() pdrid, _ := createPDR[0].PacketDetectionRuleID()
//precedence, _ := createPDR[1].Precedence()
pdiIEs, _ := createPDR[2].PDI() pdiIEs, _ := createPDR[2].PDI()
//sourceInterface, _ := pdiIEs[0].SourceInterface()
//fteid, _ := pdiIEs[1].FTEID()
ueipaddress, _ := pdiIEs[1].UEIPAddress() ueipaddress, _ := pdiIEs[1].UEIPAddress()
farid, _ := createPDR[3].FARID()
modReqIP = ueipaddress.IPv4Address.String() modReqIP = ueipaddress.IPv4Address.String()
...@@ -282,9 +289,8 @@ func handleSessionModificationMsg(config *conf.Config, msgContent message.Messag ...@@ -282,9 +289,8 @@ func handleSessionModificationMsg(config *conf.Config, msgContent message.Messag
ueSeid[msg.SEID()] = ueipaddress.IPv4Address.String() ueSeid[msg.SEID()] = ueipaddress.IPv4Address.String()
createFAR, _ := msg.CreateFAR[0].CreateFAR() createFAR, _ := msg.CreateFAR[0].CreateFAR()
//applyAction, _ := createFAR[1].ApplyAction() farid, _ := createFAR[0].FARID()
forwardingParameters, _ := createFAR[2].ForwardingParameters() forwardingParameters, _ := createFAR[2].ForwardingParameters()
//destinationInterface, _ := forwardingParameters[0].DestinationInterface()
outerHeaderCreation, _ := forwardingParameters[1].OuterHeaderCreation() outerHeaderCreation, _ := forwardingParameters[1].OuterHeaderCreation()
ueIP := ueipaddress.IPv4Address.String() ueIP := ueipaddress.IPv4Address.String()
...@@ -292,6 +298,7 @@ func handleSessionModificationMsg(config *conf.Config, msgContent message.Messag ...@@ -292,6 +298,7 @@ func handleSessionModificationMsg(config *conf.Config, msgContent message.Messag
log.Info("SEID:%d", msg.SEID()) log.Info("SEID:%d", msg.SEID())
log.Info("TEID 0x%x", outerHeaderCreation.TEID) log.Info("TEID 0x%x", outerHeaderCreation.TEID)
log.Info("UE IP: %s", ueSeid[msg.SEID()]) log.Info("UE IP: %s", ueSeid[msg.SEID()])
log.Info("PDR ID: %d", pdrid)
log.Info("FAR ID:%d", farid) log.Info("FAR ID:%d", farid)
log.Info("UE IPv4:%s", ueIP) log.Info("UE IPv4:%s", ueIP)
log.Info("GNB GTPU IP:%s", gnbIP) log.Info("GNB GTPU IP:%s", gnbIP)
...@@ -334,7 +341,6 @@ func handleSessionModificationMsg(config *conf.Config, msgContent message.Messag ...@@ -334,7 +341,6 @@ func handleSessionModificationMsg(config *conf.Config, msgContent message.Messag
log.Info("pdrid: %d", farid) log.Info("pdrid: %d", farid)
log.Info("ueip %s:index %d", ueip, updateUeIndex[ueip]) log.Info("ueip %s:index %d", ueip, updateUeIndex[ueip])
log.Info("TEID 0x%x", outerHeaderCreation.TEID) log.Info("TEID 0x%x", outerHeaderCreation.TEID)
log.Info("GNB GTPu: %s", outerHeaderCreation.IPv4Address.String())
req := &upf.UpfSsmReq{ req := &upf.UpfSsmReq{
CpSeid: msg.SEID(), CpSeid: msg.SEID(),
...@@ -350,7 +356,7 @@ func handleSessionModificationMsg(config *conf.Config, msgContent message.Messag ...@@ -350,7 +356,7 @@ func handleSessionModificationMsg(config *conf.Config, msgContent message.Messag
FTeid: upf.BuptPfcpFTeid{ FTeid: upf.BuptPfcpFTeid{
Flags: 1, Flags: 1,
Teid: outerHeaderCreation.TEID, Teid: outerHeaderCreation.TEID,
IP: upf.BuptNodeValueIP4(ip4ToUint(outerHeaderCreation.IPv4Address.String())), IP: upf.BuptNodeValueIP4(ip4ToUint(config.Gnb)),
}, },
UeAddr: upf.BuptPfcpUeIPAddress{ UeAddr: upf.BuptPfcpUeIPAddress{
Flags: 2, Flags: 2,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment