-
Notifications
You must be signed in to change notification settings - Fork 97
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
Test/pfcp #109
Merged
Merged
Test/pfcp #109
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
61c7743
test: build test
ian60509 44ed80c
feat: test file
ming-hsien 1a3afb7
feat: testing file (pfcp build)
ming-hsien 1b252cb
feat: Add pfcp build test file
ming-hsien 50b6807
fix: build_test
ming-hsien fd718a9
feat: udp send pfcp request test
HanHongChen 7f10cc0
fix: linter error
HanHongChen dbf8cc3
fix: linter error
HanHongChen f070ba8
style: remove unless code
HanHongChen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,6 @@ cscope.* | |
# Debug | ||
*.log | ||
*.pcap | ||
|
||
tttt_test.go | ||
tttt.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/free5gc/smf | ||
|
||
go 1.21 | ||
go 1.21.0 | ||
|
||
require ( | ||
github.com/antihax/optional v1.0.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,165 @@ | ||
package handler_test | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"net" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/sirupsen/logrus" | ||
. "github.com/smartystreets/goconvey/convey" | ||
|
||
"github.com/free5gc/pfcp" | ||
"github.com/free5gc/pfcp/pfcpType" | ||
"github.com/free5gc/pfcp/pfcpUdp" | ||
"github.com/free5gc/smf/internal/logger" | ||
"github.com/free5gc/smf/internal/pfcp/handler" | ||
) | ||
|
||
type LogCapture struct { | ||
buffer bytes.Buffer | ||
} | ||
|
||
func (lc *LogCapture) Write(p []byte) (n int, err error) { | ||
return lc.buffer.Write(p) | ||
} | ||
|
||
func (lc *LogCapture) String() string { | ||
return lc.buffer.String() | ||
} | ||
|
||
// func TestHandlePfcpHeartbeatRequest(t *testing.T) { | ||
// } | ||
|
||
func TestHandlePfcpManagementRequest(t *testing.T) { | ||
re := regexp.MustCompile(`(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{9}Z)(.*)`) | ||
Convey("Test log message", t, func() { | ||
remoteAddr := &net.UDPAddr{} | ||
testPfcpReq := &pfcp.Message{} | ||
msg := pfcpUdp.NewMessage(remoteAddr, testPfcpReq) | ||
logCapture := &LogCapture{} | ||
logger.Log.SetOutput(io.MultiWriter(logCapture, logrus.StandardLogger().Out)) | ||
handler.HandlePfcpPfdManagementRequest(msg) | ||
capturedLogs := re.FindStringSubmatch(logCapture.String()) | ||
|
||
logCaptureExp := &LogCapture{} | ||
logger.Log.SetOutput(io.MultiWriter(logCaptureExp)) | ||
logger.PfcpLog.Warnf("PFCP PFD Management Request handling is not implemented") | ||
capturedLogsExp := re.FindStringSubmatch(logCaptureExp.String()) | ||
So(capturedLogs[2], ShouldEqual, capturedLogsExp[2]) | ||
}) | ||
} | ||
|
||
func TestHandlePfcpAssociationSetupRequest(t *testing.T) { | ||
re := regexp.MustCompile(`(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{9}Z)(.*)`) | ||
re2 := regexp.MustCompile(`(.*)\n(.*)`) | ||
Convey("Test if NodeID is Nil", t, func() { | ||
remoteAddr := &net.UDPAddr{ | ||
IP: net.ParseIP("192.168.1.1"), | ||
Port: 12345, | ||
} | ||
|
||
testPfcpReq := &pfcp.Message{ | ||
Header: pfcp.Header{ | ||
Version: 1, | ||
MP: 0, | ||
S: 0, | ||
MessageType: pfcp.PFCP_ASSOCIATION_SETUP_REQUEST, | ||
MessageLength: 9, | ||
SEID: 0, | ||
SequenceNumber: 1, | ||
MessagePriority: 0, | ||
}, | ||
Body: pfcp.PFCPAssociationSetupRequest{ | ||
NodeID: nil, | ||
}, | ||
} | ||
|
||
logCapture := &LogCapture{} | ||
logger.Log.SetOutput(io.MultiWriter(logCapture, logrus.StandardLogger().Out)) | ||
|
||
msg := pfcpUdp.NewMessage(remoteAddr, testPfcpReq) | ||
handler.HandlePfcpAssociationSetupRequest(msg) | ||
capturedLogs := re.FindStringSubmatch(logCapture.String()) | ||
|
||
logCaptureExp := &LogCapture{} | ||
logger.Log.SetOutput(io.MultiWriter(logCaptureExp)) | ||
logger.PfcpLog.Errorln("pfcp association needs NodeID") | ||
logger.PfcpLog.Infof("Handle PFCP Association Setup Request with NodeID") | ||
ExpLogs := re.FindStringSubmatch(logCaptureExp.String()) | ||
fmt.Println(ExpLogs) | ||
if len(capturedLogs) <= 2 || len(ExpLogs) <= 2 { | ||
t.Errorf("The extracted log is not as expected.") | ||
} | ||
So(capturedLogs[2], ShouldEqual, ExpLogs[2]) | ||
}) | ||
Convey("Test if NodeID is NotNil, upf is Nil", t, func() { | ||
remoteAddr := &net.UDPAddr{ | ||
IP: net.ParseIP("192.168.1.1"), | ||
Port: 12345, | ||
} | ||
|
||
testPfcpReq := &pfcp.Message{ | ||
Header: pfcp.Header{ | ||
Version: 1, | ||
MP: 0, | ||
S: 0, | ||
MessageType: pfcp.PFCP_ASSOCIATION_SETUP_REQUEST, | ||
MessageLength: 9, | ||
SEID: 0, | ||
SequenceNumber: 1, | ||
MessagePriority: 0, | ||
}, | ||
Body: pfcp.PFCPAssociationSetupRequest{ | ||
NodeID: &pfcpType.NodeID{ | ||
NodeIdType: pfcpType.NodeIdTypeIpv4Address, | ||
IP: net.ParseIP("192.168.1.1").To4(), | ||
}, | ||
}, | ||
} | ||
|
||
logCapture := &LogCapture{} | ||
logger.Log.SetOutput(io.MultiWriter(logCapture, logrus.StandardLogger().Out)) | ||
|
||
msg := pfcpUdp.NewMessage(remoteAddr, testPfcpReq) | ||
handler.HandlePfcpAssociationSetupRequest(msg) | ||
capturedLogs := re.FindStringSubmatch(re2.FindStringSubmatch(logCapture.String())[1]) | ||
|
||
logCaptureExp := &LogCapture{} | ||
logger.Log.SetOutput(io.MultiWriter(logCaptureExp)) | ||
logger.PfcpLog.Infof("Handle PFCP Association Setup Request with NodeID[%s]", "192.168.1.1") | ||
logger.PfcpLog.Errorf("can't find UPF[%s]", "192.168.1.1") | ||
ExpLogs := re.FindStringSubmatch(re2.FindStringSubmatch(logCaptureExp.String())[1]) | ||
if len(capturedLogs) <= 2 || len(ExpLogs) <= 2 { | ||
t.Errorf("The extracted log is not as expected.") | ||
} | ||
So(capturedLogs[2], ShouldEqual, ExpLogs[2]) | ||
capturedLogs = re.FindStringSubmatch(re2.FindStringSubmatch(logCapture.String())[2]) | ||
ExpLogs = re.FindStringSubmatch(re2.FindStringSubmatch(logCaptureExp.String())[2]) | ||
So(capturedLogs[2], ShouldEqual, ExpLogs[2]) | ||
}) | ||
} | ||
|
||
func TestHandlePfcpAssociationReleaseRequest(t *testing.T) { | ||
func TestHandlePfcpAssociationUpdateRequest(t *testing.T) { | ||
re := regexp.MustCompile(`(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{9}Z)(.*)`) | ||
Convey("Test logger message", t, func() { | ||
remoteAddr := &net.UDPAddr{} | ||
testPfcpReq := &pfcp.Message{} | ||
msg := pfcpUdp.NewMessage(remoteAddr, testPfcpReq) | ||
logCapture := &LogCapture{} | ||
logger.Log.SetOutput(io.MultiWriter(logCapture, logrus.StandardLogger().Out)) | ||
handler.HandlePfcpAssociationUpdateRequest(msg) | ||
capturedLogs := re.FindStringSubmatch(logCapture.String()) | ||
|
||
logCaptureExp := &LogCapture{} | ||
logger.Log.SetOutput(io.MultiWriter(logCaptureExp)) | ||
logger.PfcpLog.Warnf("PFCP Association Update Request handling is not implemented") | ||
capturedLogsExp := re.FindStringSubmatch(logCaptureExp.String()) | ||
So(capturedLogs[2], ShouldEqual, capturedLogsExp[2]) | ||
}) | ||
} | ||
|
||
// func TestHandlePfcpAssociationReleaseRequest(t *testing.T) { | ||
// } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done