Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
bassosimone committed Sep 20, 2023
1 parent a2fe00d commit 4823e82
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 42 deletions.
4 changes: 2 additions & 2 deletions cmd/calibrate/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ func newTopologyPPP(
dnsConfig *netem.DNSConfig,
) (topologyCloser, *netem.UNetStack, *netem.UNetStack) {
// create a PPP topology
topology := netem.Must1(netem.NewPPPTopology(
topology := netem.MustNewPPPTopology(
clientAddress,
serverAddress,
log.Log,
clientLink,
))
)

// create DNS server using the server stack
_ = netem.Must1(netem.NewDNSServer(log.Log, topology.Server, serverAddress, dnsConfig))
Expand Down
30 changes: 6 additions & 24 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,12 @@ func TestLinkLatency(t *testing.T) {

// create a point-to-point topology, which consists of a single
// [Link] connecting two userspace network stacks.
topology, err := netem.NewPPPTopology(
topology := netem.MustNewPPPTopology(
"10.0.0.2",
"10.0.0.1",
log.Log,
lc,
)
if err != nil {
t.Fatal(err)
}
defer topology.Close()

// connect N times and estimate the RTT by sending a SYN and measuring
Expand Down Expand Up @@ -106,15 +103,12 @@ func TestLinkPLR(t *testing.T) {

// create a point-to-point topology, which consists of a single
// [Link] connecting two userspace network stacks.
topology, err := netem.NewPPPTopology(
topology := netem.MustNewPPPTopology(
"10.0.0.2",
"10.0.0.1",
log.Log,
lc,
)
if err != nil {
t.Fatal(err)
}
defer topology.Close()

// make sure we have a deadline bound context
Expand Down Expand Up @@ -381,15 +375,12 @@ func TestLinkPCAP(t *testing.T) {

// create a point-to-point topology, which consists of a single
// [Link] connecting two userspace network stacks.
topology, err := netem.NewPPPTopology(
topology := netem.MustNewPPPTopology(
"10.0.0.2",
"10.0.0.1",
log.Log,
lc,
)
if err != nil {
t.Fatal(err)
}

// connect N times and estimate the RTT by sending a SYN and measuring
// the time required to get back the RST|ACK segment.
Expand Down Expand Up @@ -507,15 +498,12 @@ func TestDPITCPThrottleForSNI(t *testing.T) {

// create a point-to-point topology, which consists of a single
// [Link] connecting two userspace network stacks.
topology, err := netem.NewPPPTopology(
topology := netem.MustNewPPPTopology(
"10.0.0.2",
"10.0.0.1",
log.Log,
lc,
)
if err != nil {
t.Fatal(err)
}
defer topology.Close()

// make sure we have a deadline bound context
Expand Down Expand Up @@ -1283,15 +1271,12 @@ func TestDPITCPDropForSNI(t *testing.T) {

// create a point-to-point topology, which consists of a single
// [Link] connecting two userspace network stacks.
topology, err := netem.NewPPPTopology(
topology := netem.MustNewPPPTopology(
"10.0.0.2",
"10.0.0.1",
log.Log,
lc,
)
if err != nil {
t.Fatal(err)
}
defer topology.Close()

// make sure we have a deadline bound context
Expand Down Expand Up @@ -1448,15 +1433,12 @@ func TestDPITCPDropForEndpoint(t *testing.T) {

// create a point-to-point topology, which consists of a single
// [Link] connecting two userspace network stacks.
topology, err := netem.NewPPPTopology(
topology := netem.MustNewPPPTopology(
"10.0.0.2",
"10.0.0.1",
log.Log,
lc,
)
if err != nil {
t.Fatal(err)
}
defer topology.Close()

// make sure we have a deadline bound context
Expand Down
25 changes: 9 additions & 16 deletions topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type PPPTopology struct {
link *Link
}

// NewPPPTopology creates a [PPPTopology]. Use the Close method to
// shutdown the link created by this topology.
// MustNewPPPTopology creates a [PPPTopology]. Use the Close method
// to shutdown the link created by this topology.
//
// Arguments:
//
Expand All @@ -42,40 +42,33 @@ type PPPTopology struct {
// - MTU is the MTU to use (1500 is a good MTU value);
//
// - lc describes the link characteristics.
func NewPPPTopology(
func MustNewPPPTopology(
clientAddress string,
serverAddress string,
logger Logger,
lc *LinkConfig,
) (*PPPTopology, error) {
) *PPPTopology {
// create configuration for the CA
CA := MustNewCA()

// create the client TCP/IP userspace stack
const MTU = 1500
client, err := NewUNetStack(
client := Must1(NewUNetStack(
logger,
MTU,
clientAddress,
CA,
serverAddress,
)
if err != nil {
return nil, err
}
))

// create the server TCP/IP userspace stack
server, err := NewUNetStack(
server := Must1(NewUNetStack(
logger,
MTU,
serverAddress,
CA,
"0.0.0.0",
)
if err != nil {
client.Close()
return nil, err
}
))

// connect the two stacks using a link
link := NewLink(logger, client, server, lc)
Expand All @@ -86,7 +79,7 @@ func NewPPPTopology(
closeOnce: sync.Once{},
link: link,
}
return t, nil
return t
}

// Close closes all the hosts and links allocated by the topology
Expand Down

0 comments on commit 4823e82

Please sign in to comment.