-
Notifications
You must be signed in to change notification settings - Fork 16
feat(ipv6): add IPv6 address family detection and nvme-cli IPv6 fixes #276
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
Merged
Merged
Changes from all commits
Commits
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 hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package initiator | ||
|
|
||
| import ( | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestGetIPAndPortFromControllerAddressIPv6(t *testing.T) { | ||
| testCases := []struct { | ||
| name string | ||
| address string | ||
| expectedIP string | ||
| expectedPort string | ||
| }{ | ||
| {"IPv6 space-separated", "traddr=fd00::1 trsvcid=20001", "fd00::1", "20001"}, | ||
| {"IPv6 comma-separated", "traddr=fd00::1,trsvcid=20001", "fd00::1", "20001"}, | ||
| {"IPv6 loopback", "traddr=::1 trsvcid=4420", "::1", "4420"}, | ||
| {"IPv4 space-separated", "traddr=10.42.2.18 trsvcid=20006", "10.42.2.18", "20006"}, | ||
| {"IPv4 comma-separated", "traddr=10.42.2.18,trsvcid=20006", "10.42.2.18", "20006"}, | ||
| } | ||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| gotIP, gotPort := GetIPAndPortFromControllerAddress(tc.address) | ||
| if gotIP != tc.expectedIP { | ||
| t.Errorf("GetIPAndPortFromControllerAddress(%q) IP = %q, want %q", tc.address, gotIP, tc.expectedIP) | ||
| } | ||
| if gotPort != tc.expectedPort { | ||
| t.Errorf("GetIPAndPortFromControllerAddress(%q) Port = %q, want %q", tc.address, gotPort, tc.expectedPort) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package client | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| spdktypes "github.com/longhorn/go-spdk-helper/pkg/spdk/types" | ||
| ) | ||
|
|
||
| func TestDetectAddressFamily(t *testing.T) { | ||
| testCases := []struct { | ||
| name string | ||
| ip string | ||
| expected spdktypes.NvmeAddressFamily | ||
| }{ | ||
| {"IPv4", "192.168.1.1", spdktypes.NvmeAddressFamilyIPv4}, | ||
| {"IPv6", "fd00::1", spdktypes.NvmeAddressFamilyIPv6}, | ||
| {"bracketed IPv6", "[fd00::1]", spdktypes.NvmeAddressFamilyIPv6}, | ||
| {"IPv6 loopback", "::1", spdktypes.NvmeAddressFamilyIPv6}, | ||
| {"empty", "", spdktypes.NvmeAddressFamilyIPv4}, | ||
| {"malformed", "not-an-ip", spdktypes.NvmeAddressFamilyIPv4}, | ||
| {"IPv4-mapped v6", "::ffff:10.0.0.1", spdktypes.NvmeAddressFamilyIPv4}, | ||
|
COLDTURNIP marked this conversation as resolved.
|
||
| {"bracketed IPv4-mapped v6", "[::ffff:10.0.0.1]", spdktypes.NvmeAddressFamilyIPv4}, | ||
| } | ||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| got := DetectAddressFamily(tc.ip) | ||
| if got != tc.expected { | ||
| t.Errorf("DetectAddressFamily(%q) = %q, want %q", tc.ip, got, tc.expected) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package util | ||
|
|
||
| import ( | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestNormalizeNvmeAddr(t *testing.T) { | ||
| testCases := []struct { | ||
| name string | ||
| input string | ||
| expected string | ||
| }{ | ||
| {"bare IPv6", "::1", "::1"}, | ||
| {"bracketed IPv6", "[::1]", "::1"}, | ||
| {"IPv4", "10.0.0.1", "10.0.0.1"}, | ||
| {"bracketed fd00", "[fd00::1]", "fd00::1"}, | ||
| {"empty", "", ""}, | ||
| {"single bracket", "[", "["}, | ||
| } | ||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| got := NormalizeNvmeAddr(tc.input) | ||
| if got != tc.expected { | ||
| t.Errorf("NormalizeNvmeAddr(%q) = %q, want %q", tc.input, got, tc.expected) | ||
| } | ||
| }) | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.