Skip to content

Commit

Permalink
add test for old and new br configuration with(out) shim dispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiSubira committed Jan 3, 2024
1 parent 0ee169c commit a4d776f
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 20 deletions.
9 changes: 9 additions & 0 deletions acceptance/old_new_br/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("//acceptance/common:topogen.bzl", "topogen_test")

topogen_test(
name = "test",
src = "test.py",
args = ["--executable=end2end_integration:$(location //tools/end2end_integration)"],
data = ["//tools/end2end_integration"],
topo = "//acceptance/old_new_br/testdata:topology.topo",
)
55 changes: 55 additions & 0 deletions acceptance/old_new_br/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env python3

# Copyright 2023 ETH Zurich

import time

from acceptance.common import base
from acceptance.common import scion
# from plumbum import local


class Test(base.TestTopogen):
"""
Constructs a simple test topology with one core, four leaf ASes.
Each of them will run a different mix between BR that will replicate
the old behaviour (i.e., they will send traffic to its own AS to the
endhost default port) and routers with the new behaviour (i.e., they
will rewrite the underlay UDP/IP destination port with the UDP/SCION
port).
AS 1-ff00:0:1 is core.
AS 1-ff00:0:2, 1-ff00:0:3
We use the shortnames AS1, AS2, etc. for the ASes above.
AS1 contains a BR with the port rewriting configuration to the default
range. It also includes a shim dispatcher.
AS2 contains a BR with a configuration that reassembles the old
behaviour, i.e., sending all traffic to default endhost port 30041.
It also includes a shim dispatcher.
AS3 contains a BR with the port rewriting configuration to the default
range. It does not include the shim dispatcher.
"""

def setup_prepare(self):
super().setup_prepare()

br_as_2_id = "br1-ff00_0_2-1"

br_as_2_file = self.artifacts / "gen" / "ASff00_0_2" \
/ ("%s.toml" % br_as_2_id)
scion.update_toml({"router.endhost_start_port": 0}, [br_as_2_file])
scion.update_toml({"router.endhost_end_port": 0}, [br_as_2_file])

def setup_start(self):
super().setup_start()
time.sleep(10) # Give applications time to download configurations

def _run(self):
ping_test = self.get_executable("end2end_integration")
ping_test["-d", "-outDir", self.artifacts].run_fg()


if __name__ == "__main__":
base.main(Test)
3 changes: 3 additions & 0 deletions acceptance/old_new_br/testdata/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports_files([
"topology.topo",
])
15 changes: 15 additions & 0 deletions acceptance/old_new_br/testdata/topology.topo
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--- # Gateway Topology
ASes:
"1-ff00:0:1":
core: true
voting: true
authoritative: true
issuing: true
"1-ff00:0:2":
cert_issuer: 1-ff00:0:1
"1-ff00:0:3":
cert_issuer: 1-ff00:0:1
test_dispatcher: False
links:
- {a: "1-ff00:0:1#2", b: "1-ff00:0:2#1", linkAtoB: CHILD}
- {a: "1-ff00:0:1#3", b: "1-ff00:0:3#1", linkAtoB: CHILD}
8 changes: 8 additions & 0 deletions router/cmd/router/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ func realMain(ctx context.Context) error {
if err := iaCtx.Configure(); err != nil {
return serrors.WrapStr("configuring dataplane", err)
}
startPort, endPort := controlConfig.Topo.PortRange()
if globalCfg.Router.EndhostStartPort != nil &&
globalCfg.Router.EndhostEndPort != nil {
startPort = uint16(*globalCfg.Router.EndhostStartPort)
endPort = uint16(*globalCfg.Router.EndhostEndPort)
}
dp.DataPlane.SetPortRange(startPort, endPort)
log.Debug("Endhost port range configuration", "startPort", startPort, "endPort", endPort)
statusPages := service.StatusPages{
"info": service.NewInfoStatusPage(),
"config": service.NewConfigStatusPage(globalCfg),
Expand Down
34 changes: 28 additions & 6 deletions router/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ type Config struct {
}

type RouterConfig struct {
ReceiveBufferSize int `toml:"receive_buffer_size,omitempty"`
SendBufferSize int `toml:"send_buffer_size,omitempty"`
NumProcessors int `toml:"num_processors,omitempty"`
NumSlowPathProcessors int `toml:"num_slow_processors,omitempty"`
BatchSize int `toml:"batch_size,omitempty"`
ReceiveBufferSize int `toml:"receive_buffer_size,omitempty"`
SendBufferSize int `toml:"send_buffer_size,omitempty"`
NumProcessors int `toml:"num_processors,omitempty"`
NumSlowPathProcessors int `toml:"num_slow_processors,omitempty"`
BatchSize int `toml:"batch_size,omitempty"`
EndhostStartPort *int `toml:"endhost_start_port,omitempty"`
EndhostEndPort *int `toml:"endhost_end_port,omitempty"`
}

func (cfg *RouterConfig) ConfigName() string {
Expand All @@ -66,7 +68,27 @@ func (cfg *RouterConfig) Validate() error {
if cfg.NumSlowPathProcessors < 1 {
return serrors.New("Provided router config is invalid. NumSlowPathProcessors < 1")
}

if cfg.EndhostStartPort != nil {
if cfg.EndhostEndPort == nil {
return serrors.New("Provided router config is invalid. " +
"EndHostEndPort is nil; EndHostStartPort isn't")
}
if *cfg.EndhostStartPort < 0 {
return serrors.New("Provided router config is invalid. EndHostStartPort < 0")
}
if *cfg.EndhostEndPort >= (1 << 16) {
return serrors.New("Provided router config is invalid. EndHostEndPort > 2**16 -1")
}
if *cfg.EndhostStartPort > *cfg.EndhostEndPort {
return serrors.New("Provided router config is invalid. " +
"EndHostStartPort > EndhostEndPort")
}
} else {
if cfg.EndhostEndPort != nil {
return serrors.New("Provided router config is invalid. " +
"EndHostStartPort is nil; EndHostEndPort isn't")
}
}
return nil
}

Expand Down
7 changes: 0 additions & 7 deletions router/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,6 @@ func (c *Connector) SetKey(ia addr.IA, index int, key []byte) error {
return c.DataPlane.SetKey(key)
}

func (c *Connector) SetPortRange(start, end uint16) {
c.mtx.Lock()
defer c.mtx.Unlock()
log.Debug("Setting endhost port range", "start:", start, "end", end)
c.DataPlane.SetPortRange(start, end)
}

func (c *Connector) ListInternalInterfaces() ([]control.InternalInterface, error) {
c.mtx.Lock()
defer c.mtx.Unlock()
Expand Down
3 changes: 0 additions & 3 deletions router/control/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ type Dataplane interface {
AddSvc(ia addr.IA, svc addr.SVC, a *net.UDPAddr) error
DelSvc(ia addr.IA, svc addr.SVC, a *net.UDPAddr) error
SetKey(ia addr.IA, index int, key []byte) error
SetPortRange(start, end uint16)
}

// LinkInfo contains the information about a link between an internal and
Expand Down Expand Up @@ -126,8 +125,6 @@ func ConfigDataplane(dp Dataplane, cfg *Config) error {
return err
}
}
// Set endhost port range
dp.SetPortRange(cfg.Topo.PortRange())

// Add internal interfaces
if cfg.BR != nil {
Expand Down
5 changes: 3 additions & 2 deletions tools/topology/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,9 @@ def _dispatcher_conf(self, topo_id, topo, base):
},
},
}
keys = (list(topo.get("control_service", {})) +
["tester_%s" % topo_id.file_fmt()])
keys = list(topo.get("control_service", {}))
if topo.get("test_dispatcher"):
keys.append("tester_%s" % topo_id.file_fmt())
for disp_id in keys:
entry = copy.deepcopy(base_entry)
net_key = disp_id
Expand Down
11 changes: 9 additions & 2 deletions tools/topology/docker_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def _test_conf(self, topo_id):
entry = {
'image': docker_image(self.args, 'tester'),
'container_name': 'tester_%s' % topo_id.file_fmt(),
'depends_on': ['scion_disp_%s' % name],
'privileged': True,
'entrypoint': 'sh tester.sh',
'environment': {},
Expand All @@ -87,12 +86,20 @@ def _test_conf(self, topo_id):
self.output_base + '/gen:' + cntr_base + '/gen:rw',
self.output_base + '/gen-certs:' + cntr_base + '/gen-certs:rw'
],
'network_mode': 'service:scion_disp_%s' % name,
}
net = self.args.networks[name][0]
ipv = 'ipv4'
if ipv not in net:
ipv = 'ipv6'
ip = str(net[ipv])
if 'scion_disp_%s' % name in self.dc_conf['services']:
entry['depends_on'] = ['scion_disp_%s' % name]
entry.update({'network_mode': 'service:scion_disp_%s' % name})
else:
entry['networks'] = {}
entry['networks'][self.args.bridges[net['net']]] = {
'%s_address' % ipv: ip
}
disp_net = self.args.networks[name][0]
entry['environment']['SCION_LOCAL_ADDR'] = str(disp_net[ipv])
sciond_net = self.args.networks['sd%s' % topo_id.file_fmt()][0]
Expand Down
1 change: 1 addition & 0 deletions tools/topology/topo.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ def _generate_as_topo(self, topo_id, as_conf):
'attributes': attributes,
'isd_as': str(topo_id),
'mtu': mtu,
'test_dispatcher': as_conf.get('test_dispatcher', True),
'endhost_start_port': as_conf.get('endhost_start_port', self.args.endhost_start_port),
'endhost_end_port': as_conf.get('endhost_end_port', self.args.endhost_end_port),
}
Expand Down

0 comments on commit a4d776f

Please sign in to comment.