nic_router.run: do not append but concatenate

Makes the script more readable and saves 100 LOC.

Ref #2193
This commit is contained in:
Martin Stein 2017-02-11 03:51:44 +01:00 committed by Christian Helmuth
parent 412c5e5be4
commit d301022fe7
2 changed files with 173 additions and 271 deletions

View File

@ -42,7 +42,7 @@ proc platform_drv_build_components {} {
proc append_platform_drv_build_components {} {
global build_components
append build_components [platform_drv_build_components]
append build_components { } [platform_drv_build_components]
}
proc platform_drv_boot_modules {} {
@ -57,7 +57,7 @@ proc platform_drv_boot_modules {} {
proc append_platform_drv_boot_modules {} {
global boot_modules
append boot_modules $platform_drv_boot_modules
append boot_modules { } [platform_drv_boot_modules]
}

View File

@ -1,41 +1,42 @@
#
# Build
# Build components
#
set tcp_up_to_down_1 1
set tcp_up_to_down_2 1
set tcp_down_to_up_1 1
set udp_down_to_down_1 1
set udp_up_to_down_1 1
set udp_down_to_up_1 1
set use_usb_driver [expr [have_spec omap4] || [have_spec arndale] || [have_spec rpi]]
set use_nic_driver [expr !$use_usb_driver && ![have_spec imx53] && ![have_spec riscv] && ![have_spec odroid_xu] && ![have_spec linux] && ![have_spec wand_quad]]
set nic_driver "nic_drv"
if ($use_usb_driver) {
set nic_driver "usb_drv" }
if {[expr !$use_usb_driver && !$use_nic_driver]} {
puts "\n Run script is not supported on this platform. \n"; exit 0 }
set build_components {
core init drivers/timer drivers/nic server/nic_router server/nic_bridge
test/lwip/http_srv_static test/lwip/http_clnt test/lxip/udp_echo
test/lxip/udp_client
}
proc gpio_drv { } { if {[have_spec rpi] && [have_spec hw]} { return hw_gpio_drv }
if {[have_spec rpi] && [have_spec foc]} { return foc_gpio_drv }
return gpio_drv }
lappend_if $use_usb_driver build_components drivers/usb
lappend_if [have_spec gpio] build_components drivers/gpio
proc enable_test_1 { } { return 1 }
proc enable_test_2 { } { return 1 }
proc enable_test_3 { } { return 1 }
proc enable_test_4 { } { return 1 }
proc enable_test_5 { } { return 1 }
proc enable_test_6 { } { return 1 }
source ${genode_dir}/repos/base/run/platform_drv.inc
append_platform_drv_build_components
build $build_components
proc nic_drv { } {
if {[have_spec omap4] || [have_spec arndale] || [have_spec rpi]} { return usb_drv }
if {!([have_spec imx53] || [have_spec riscv] || [have_spec odroid_xu] || [have_spec linux] || [have_spec wand_quad])} { return nic_drv }
}
proc gpio_drv { } {
if {[have_spec rpi] && [have_spec hw]} { return hw_gpio_drv }
if {[have_spec rpi] && [have_spec foc]} { return foc_gpio_drv }
if {[have_spec gpio]} { return gpio_drv }
}
if {[nic_drv] == ""} {
puts "\n Run script is not supported on this platform. \n"; exit 0 }
proc nic_drv_build { } {
if {[nic_drv] == "nic_drv"} { return drivers/nic }
if {[nic_drv] == "usb_drv"} { return drivers/usb }
}
proc gpio_drv_build { } { if {[gpio_drv] != ""} { return " drivers/gpio" } }
build [string cat {
core init drivers/timer server/nic_router server/nic_bridge
test/lwip/http_srv_static test/lwip/http_clnt test/lxip/udp_echo
test/lxip/udp_client } [nic_drv_build] { } [gpio_drv_build] {
} [platform_drv_build_components]]
create_boot_directory
@ -43,7 +44,119 @@ create_boot_directory
# Generate config
#
append config {
proc gpio_drv_config { } {
if {[have_spec gpio]} { return [string cat {
<start name="} [gpio_drv] {">
<resource name="RAM" quantum="4M"/>
<provides><service name="Gpio"/></provides>
</start>}] }
}
proc nic_drv_config { } {
if {[nic_drv] == "nic_drv"} { return [string cat {
<start name="nic_drv">
<resource name="RAM" quantum="6M"/>
<provides><service name="Nic"/></provides>
</start>}] }
if {[nic_drv] == "usb_drv"} { return [string cat {
<start name="usb_drv">
<resource name="RAM" quantum="12M"/>
<provides>
<service name="Nic"/>
</provides>
<config ehci="yes">
<nic mac="02:00:00:00:01:01" />
</config>
</start>}] }
}
proc client_bin { prot } {
if {$prot == "udp"} { return "test-lxip_udp_client" }
if {$prot == "http"} { return "test-http_clnt" } }
proc server_bin { prot } {
if {$prot == "udp"} { return "test-lxip_udp_echo" }
if {$prot == "http"} { return "test-lwip_httpsrv_static" } }
proc client_config { prot index ip_addr gateway netmask nic srv_port srv_ip } {
return [string cat {
<start name="} $prot {_client_} $index {">
<binary name="} [client_bin $prot] {" />
<resource name="RAM" quantum="2M"/>
<route>
<service name="Nic"> <child name="} $nic {"/> </service>
<any-service> <parent/> <any-child/> </any-service>
</route>
<config server_ip="} $srv_ip {" server_port="} $srv_port {">
<vfs> <dir name="dev"> <log/> </dir> </vfs>
<libc stdout="/dev/log" stderr="/dev/log" ip_addr="} $ip_addr {"
gateway="} $gateway {" netmask="} $netmask {"/>
</config>
</start>}]
}
proc server_config { prot index ip_addr gateway netmask nic port } {
return [string cat {
<start name="} $prot {_server_} $index {">
<binary name="} [server_bin $prot] {" />
<resource name="RAM" quantum="2M"/>
<route>
<service name="Nic"> <child name="} $nic {"/> </service>
<any-service> <parent/> <any-child/> </any-service>
</route>
<config port="} $port {">
<vfs> <dir name="dev"> <log/> </dir> </vfs>
<libc stdout="/dev/log" stderr="/dev/log" ip_addr="} $ip_addr {"
gateway="} $gateway {" netmask="} $netmask {"/>
</config>
</start>}]
}
proc test_1_config { } {
if {[enable_test_1]} { return [string cat {
} [client_config udp 1 10.0.98.55 10.0.98.33 255.255.255.0 nic_router 1337 10.0.98.33] {
} [server_config udp 1 10.0.99.55 10.0.99.33 255.255.255.0 nic_router 1337 ]] }
}
proc test_2_config { } {
if {[enable_test_2]} { return [string cat {
} [client_config udp 2 10.0.2.212 10.0.2.1 255.255.255.0 nic_bridge 1 10.0.2.55] {
} [server_config udp 2 18.17.16.15 18.17.16.14 255.255.0.0 nic_router 1 ]] }
}
proc test_3_config { } {
if {[enable_test_3]} { return [string cat {
} [client_config udp 3 217.13.192.2 217.13.192.1 255.255.192.0 nic_router 65535 10.0.2.213] {
} [server_config udp 3 10.0.2.213 10.0.2.55 255.255.255.0 nic_bridge 65535 ]] }
}
proc test_4_config { } {
if {[enable_test_4]} { return [string cat {
} [client_config http 1 10.0.2.201 10.0.2.1 255.255.255.0 nic_bridge 80 10.0.2.55] {
} [server_config http 1 192.168.1.18 192.168.1.1 255.255.255.0 nic_router 80 ]] }
}
proc test_5_config { } {
if {[enable_test_5]} { return [string cat {
} [client_config http 2 10.0.2.202 10.0.2.1 255.255.255.0 nic_bridge 8080 10.0.2.55] {
} [server_config http 2 192.168.2.72 192.168.2.1 255.255.255.0 nic_router 8080 ]] }
}
proc test_6_config { } {
if {[enable_test_6]} { return [string cat {
} [client_config http 3 100.200.0.128 100.200.0.1 255.255.0.0 nic_router 2345 10.0.2.203] {
} [server_config http 3 10.0.2.203 10.0.2.1 255.255.255.0 nic_bridge 2345 ]] }
}
install_config [string cat {
<config>
<parent-provides>
<service name="ROM"/>
@ -56,37 +169,15 @@ append config {
<service name="CPU"/>
<service name="LOG"/>
</parent-provides>
<default-route>
<any-service> <parent/> <any-child/> </any-service>
</default-route>}
</default-route>
append_if [have_spec gpio] config "
<start name=\"[gpio_drv]\">
<resource name=\"RAM\" quantum=\"4M\"/>
<provides><service name=\"Gpio\"/></provides>
<config/>
</start>"
} [gpio_drv_config] {
} [nic_drv_config] {
} [platform_drv_config] {
append_if $use_usb_driver config {
<start name="usb_drv">
<resource name="RAM" quantum="12M"/>
<provides>
<service name="Nic"/>
</provides>
<config ehci="yes">
<nic mac="02:00:00:00:01:01" />
</config>
</start>}
append_platform_drv_config
append_if $use_nic_driver config {
<start name="nic_drv">
<resource name="RAM" quantum="6M"/>
<provides><service name="Nic"/></provides>
</start>}
append config {
<start name="timer">
<resource name="RAM" quantum="1M"/>
<provides><service name="Timer"/></provides>
@ -144,230 +235,41 @@ append config {
<provides><service name="Nic"/></provides>
<config>
<policy label_prefix="nic_router" ip_addr="10.0.2.55" />
<policy label_prefix="http_client_1" ip_addr="10.0.2.201" />
<policy label_prefix="http_client_2" ip_addr="10.0.2.202" />
<policy label_prefix="http_server_3" ip_addr="10.0.2.203" />
<policy label_prefix="http_client_1" ip_addr="10.0.2.201" />
<policy label_prefix="http_client_2" ip_addr="10.0.2.202" />
<policy label_prefix="http_server_3" ip_addr="10.0.2.203" />
<policy label_prefix="udp_client_2" ip_addr="10.0.2.212" />
<policy label_prefix="udp_server_3" ip_addr="10.0.2.213" />
<policy label_prefix="udp_server_3" ip_addr="10.0.2.213" />
</config>
<route>}
append config "
<service name=\"Nic\"> <child name=\"${nic_driver}\"/> </service>"
append config {
<any-service> <parent/> <any-child/> </any-service>
</route>
</start>}
append_if $udp_down_to_down_1 config {
<start name="udp_client_1">
<binary name="test-lxip_udp_client" />
<resource name="RAM" quantum="2M"/>
<route>
<service name="Nic"> <child name="nic_router"/> </service>
<service name="Nic"> <child name="} [nic_drv] {"/> </service>
<any-service> <parent/> <any-child/> </any-service>
</route>
<config server_ip="10.0.98.33" server_port="1337">
<vfs> <dir name="dev"> <log/> </dir> </vfs>
<libc stdout="/dev/log" stderr="/dev/log" ip_addr="10.0.98.55"
gateway="10.0.98.33" netmask="255.255.255.0"/>
</config>
</start>
<start name="udp_server_1">
<binary name="test-lxip_udp_echo" />
<resource name="RAM" quantum="2M"/>
<route>
<service name="Nic"> <child name="nic_router"/> </service>
<any-service> <parent/> <any-child/> </any-service>
</route>
<config port="1337">
<vfs> <dir name="dev"> <log/> </dir> </vfs>
<libc stdout="/dev/log" stderr="/dev/log" ip_addr="10.0.99.55"
gateway="10.0.99.33" netmask="255.255.255.0"/>
</config>
</start>}
} [test_1_config] {
} [test_2_config] {
} [test_3_config] {
} [test_4_config] {
} [test_5_config] {
} [test_6_config] {
append_if $udp_up_to_down_1 config {
<start name="udp_client_2">
<binary name="test-lxip_udp_client" />
<resource name="RAM" quantum="2M"/>
<route>
<service name="Nic"> <child name="nic_bridge"/> </service>
<any-service> <parent/> <any-child/> </any-service>
</route>
<config server_ip="10.0.2.55" server_port="1">
<vfs> <dir name="dev"> <log/> </dir> </vfs>
<libc stdout="/dev/log" stderr="/dev/log" ip_addr="10.0.2.212"
gateway="10.0.2.1" netmask="255.255.255.0"/>
</config>
</start>
<start name="udp_server_2">
<binary name="test-lxip_udp_echo" />
<resource name="RAM" quantum="2M"/>
<route>
<service name="Nic"> <child name="nic_router"/> </service>
<any-service> <parent/> <any-child/> </any-service>
</route>
<config port="1">
<vfs> <dir name="dev"> <log/> </dir> </vfs>
<libc stdout="/dev/log" stderr="/dev/log" ip_addr="18.17.16.15"
gateway="18.17.16.14" netmask="255.255.0.0"/>
</config>
</start>}
append_if $udp_down_to_up_1 config {
<start name="udp_client_3">
<binary name="test-lxip_udp_client" />
<resource name="RAM" quantum="2M"/>
<route>
<service name="Nic"> <child name="nic_router"/> </service>
<any-service> <parent/> <any-child/> </any-service>
</route>
<config server_ip="10.0.2.213" server_port="65535">
<vfs> <dir name="dev"> <log/> </dir> </vfs>
<libc stdout="/dev/log" stderr="/dev/log" ip_addr="217.13.192.2"
gateway="217.13.192.1" netmask="255.255.192.0"/>
</config>
</start>
<start name="udp_server_3">
<binary name="test-lxip_udp_echo" />
<resource name="RAM" quantum="2M"/>
<route>
<service name="Nic"> <child name="nic_bridge"/> </service>
<any-service> <parent/> <any-child/> </any-service>
</route>
<config port="65535">
<vfs> <dir name="dev"> <log/> </dir> </vfs>
<libc stdout="/dev/log" stderr="/dev/log" ip_addr="10.0.2.213"
gateway="10.0.2.55" netmask="255.255.255.0"/>
</config>
</start>}
append_if $tcp_up_to_down_1 config {
<start name="http_server_1">
<binary name="test-lwip_httpsrv_static"/>
<resource name="RAM" quantum="2M"/>
<route>
<service name="Nic"> <child name="nic_router"/> </service>
<any-service> <parent/> <any-child/> </any-service>
</route>
<config port="80">
<vfs> <dir name="dev"> <log/> </dir> </vfs>
<libc stdout="/dev/log" stderr="/dev/log" ip_addr="192.168.1.18"
netmask="255.255.255.0" gateway="192.168.1.1" />
</config>
</start>
<start name="http_client_1">
<binary name="test-http_clnt"/>
<resource name="RAM" quantum="2M"/>
<route>
<service name="Nic"> <child name="nic_bridge"/> </service>
<any-service> <parent/> <any-child/> </any-service>
</route>
<config server_ip="10.0.2.55" server_port="80">
<vfs> <dir name="dev"> <log/> </dir> </vfs>
<libc stdout="/dev/log" stderr="/dev/log" ip_addr="10.0.2.201"
gateway="10.0.2.1" netmask="255.255.255.0"/>
</config>
</start>}
append_if $tcp_up_to_down_2 config {
<start name="http_server_2">
<binary name="test-lwip_httpsrv_static"/>
<resource name="RAM" quantum="2M"/>
<route>
<service name="Nic"> <child name="nic_router"/> </service>
<any-service> <parent/> <any-child/> </any-service>
</route>
<config port="8080">
<vfs> <dir name="dev"> <log/> </dir> </vfs>
<libc stdout="/dev/log" stderr="/dev/log" ip_addr="192.168.2.72"
netmask="255.255.255.0" gateway="192.168.2.1"/>
</config>
</start>
<start name="http_client_2">
<binary name="test-http_clnt"/>
<resource name="RAM" quantum="2M"/>
<route>
<service name="Nic"> <child name="nic_bridge"/> </service>
<any-service> <parent/> <any-child/> </any-service>
</route>
<config server_ip="10.0.2.55" server_port="8080">
<vfs> <dir name="dev"> <log/> </dir> </vfs>
<libc stdout="/dev/log" stderr="/dev/log" ip_addr="10.0.2.202"
gateway="10.0.2.1" netmask="255.255.255.0"/>
</config>
</start>}
append_if $tcp_down_to_up_1 config {
<start name="http_server_3">
<binary name="test-lwip_httpsrv_static"/>
<resource name="RAM" quantum="2M"/>
<route>
<service name="Nic"> <child name="nic_bridge"/> </service>
<any-service> <parent/> <any-child/> </any-service>
</route>
<config port="2345">
<vfs> <dir name="dev"> <log/> </dir> </vfs>
<libc stdout="/dev/log" stderr="/dev/log" ip_addr="10.0.2.203"
gateway="10.0.2.1" netmask="255.255.255.0"/>
</config>
</start>
<start name="http_client_3">
<binary name="test-http_clnt"/>
<resource name="RAM" quantum="2M"/>
<route>
<service name="Nic"> <child name="nic_router"/> </service>
<any-service> <parent/> <any-child/> </any-service>
</route>
<config server_ip="10.0.2.203" server_port="2345">
<vfs> <dir name="dev"> <log/> </dir> </vfs>
<libc stdout="/dev/log" stderr="/dev/log" ip_addr="100.200.0.128"
netmask="255.255.0.0" gateway="100.200.0.1"/>
</config>
</start>}
append config { </config> }
install_config $config
</config> }]
#
# Boot modules
# Create single image and execute
#
# generic modules
set boot_modules {
build_boot_image [string cat {
core init timer nic_router nic_bridge ld.lib.so libc.lib.so libm.lib.so
libc_resolv.lib.so lwip.lib.so lxip.lib.so test-http_clnt
test-lwip_httpsrv_static test-lxip_udp_echo test-lxip_udp_client
}
} [nic_drv] { } [gpio_drv] { } [platform_drv_boot_modules]]
# platform-specific modules
lappend_if $use_usb_driver boot_modules usb_drv
lappend_if $use_nic_driver boot_modules nic_drv
lappend_if [have_spec gpio] boot_modules [gpio_drv]
proc nic_qemu_args { } {
if {[have_spec x86]} { return "-net nic,model=e1000" }
if {[have_spec lan9118]} { return "-net nic,model=lan9118" } }
append_platform_drv_boot_modules
append qemu_args { -m 256 -nographic -net user -redir udp:5555::1337 } [nic_qemu_args]
build_boot_image $boot_modules
# qemu config
append qemu_args " -m 256 -nographic "
append_if [have_spec x86] qemu_args " -net nic,model=e1000 "
append_if [have_spec lan9118] qemu_args " -net nic,model=lan9118 "
append qemu_args " -net user -redir udp:5555::1337 "
run_genode_until ".*Test done.*\n.*Test done.*\n.*Test done.*\n.*Test done.*\n.*Test done.*\n.*Test done.*\n" 60
run_genode_until {.*Test done.*\n.*Test done.*\n.*Test done.*\n.*Test done.*\n.*Test done.*\n.*Test done.*\n} 60