-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(netsim): introduce well-known hosts (#25)
This allows us to further reduce the boilerplate in tests.
- Loading branch information
1 parent
e010401
commit de359da
Showing
6 changed files
with
93 additions
and
68 deletions.
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// | ||
// Well-known host configurations for common internet services | ||
// used in network testing scenarios. | ||
// | ||
|
||
package netsim | ||
|
||
import "net/http" | ||
|
||
// MustNewGoogleDNSStack creates a new stack simulating dns.google. | ||
func (s *Scenario) MustNewGoogleDNSStack() *Stack { | ||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.Write([]byte("Google Public DNS server.\n")) | ||
}) | ||
return s.MustNewStack(&StackConfig{ | ||
DomainNames: []string{ | ||
"dns.google", | ||
"dns.google.com", | ||
}, | ||
Addresses: []string{ | ||
"2001:4860:4860::8888", | ||
"8.8.8.8", | ||
}, | ||
DNSOverUDPHandler: s.DNSHandler(), | ||
HTTPHandler: handler, | ||
HTTPSHandler: handler, | ||
}) | ||
} | ||
|
||
// MustNewExampleComStack creates a new stack simulating www.example.com. | ||
func (s *Scenario) MustNewExampleComStack() *Stack { | ||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.Write([]byte("Example Web Server.\n")) | ||
}) | ||
return s.MustNewStack(&StackConfig{ | ||
DomainNames: []string{ | ||
"www.example.com", | ||
"example.com", | ||
"www.example.org", | ||
"example.org", | ||
}, | ||
Addresses: []string{ | ||
"2606:2800:21f:cb07:6820:80da:af6b:8b2c", | ||
"93.184.216.34", | ||
}, | ||
HTTPHandler: handler, | ||
HTTPSHandler: handler, | ||
}) | ||
} | ||
|
||
// MustNewClientStack creates a new client stack with standard testing configuration. | ||
// | ||
// We use GARR's (Italian Research & Education Network) public addresses | ||
// (193.206.158.22 and 2001:760:0:158::22) as default client addresses. | ||
// These are chosen over documentation ranges (like 192.0.2.0/24) to avoid | ||
// triggering bogon filters in network simulation scenarios, while still | ||
// being associated with a public research institution. | ||
// | ||
// The stack uses Google's public DNS addresses as the default resolvers. | ||
func (s *Scenario) MustNewClientStack() *Stack { | ||
return s.MustNewStack(&StackConfig{ | ||
Addresses: []string{ | ||
"193.206.158.22", | ||
"2001:760:0:158::22", | ||
}, | ||
ClientResolvers: []string{ | ||
"2001:4860:4860::8888", | ||
"8.8.8.8", | ||
}, | ||
}) | ||
} |