From e708703363b5e853dee29d09fbdbddcf9cfd3990 Mon Sep 17 00:00:00 2001 From: Matt Keeter Date: Fri, 27 Mar 2026 20:52:09 +0000 Subject: [PATCH] Get socket parameters from manifest --- cmd/manifest/src/lib.rs | 24 ++++ cmd/rpc/src/lib.rs | 9 +- .../cmd/manifest/manifest.chilly.0.stdout | 3 + ...fest.control_plane_agent.overflow.0.stdout | 7 + .../cmd/manifest/manifest.counters.0.stdout | 8 ++ ...fest.duplicate_HostFlash_hash_REPLY.stdout | 6 + .../manifest/manifest.extern-regions.stdout | 7 + .../manifest.flash-ram-mismatch.0.stdout | 4 + ...mlet-c-dev-image-default-v1.0.2.zip.stdout | 7 + .../cmd/manifest/manifest.host-panic.0.stdout | 8 ++ .../cmd/manifest/manifest.host-panic.1.stdout | 8 ++ .../cmd/manifest/manifest.host-panic.2.stdout | 8 ++ .../cmd/manifest/manifest.host-panic.3.stdout | 8 ++ .../cmd/manifest/manifest.host-panic.4.stdout | 8 ++ .../manifest.idol-returns-an-enum.stdout | 7 + .../tests/cmd/manifest/manifest.igor.0.stdout | 6 + .../manifest/manifest.in_bootloader.0.stdout | 4 + .../cmd/manifest/manifest.ipc-counts.0.stdout | 8 ++ .../manifest/manifest.kernel-panic.0.stdout | 3 + .../manifest/manifest.kernel-panic.1.stdout | 6 + .../cmd/manifest/manifest.kiowa.26.stdout | 3 + .../cmd/manifest/manifest.new-ringbuf.stdout | 7 + .../manifest.nightly-2022-11-01.stdout | 6 + .../manifest/manifest.panic-on-boot.stdout | 6 + ...anifest.sidecar-b-image-default.zip.stdout | 8 ++ .../cmd/manifest/manifest.spoopy.0.stdout | 3 + .../cmd/manifest/manifest.sprot_status.stdout | 6 + .../manifest/manifest.static-tasks.0.stdout | 3 + .../manifest/manifest.static-tasks.1.stdout | 3 + .../cmd/manifest/manifest.task.net.stdout | 6 + .../cmd/manifest/manifest.task.power.stdout | 8 ++ .../cmd/manifest/manifest.u16-ringbuf.stdout | 8 ++ humility-core/src/hubris.rs | 132 ++++++++++++++++++ humility-hiffy/src/lib.rs | 28 +++- humility-net-core/src/lib.rs | 55 +++----- 35 files changed, 389 insertions(+), 42 deletions(-) diff --git a/cmd/manifest/src/lib.rs b/cmd/manifest/src/lib.rs index 61aec019b..5702dfc35 100644 --- a/cmd/manifest/src/lib.rs +++ b/cmd/manifest/src/lib.rs @@ -244,6 +244,30 @@ fn manifestcmd(context: &mut ExecutionContext) -> Result<()> { } } + if !manifest.sockets.is_empty() { + println!( + "{:>12} => {} socket{}", + "sockets", + manifest.sockets.len(), + if manifest.sockets.len() != 1 { "s" } else { "" } + ); + println!( + " {:20} {:5} {:>6} {:>7} {}", + "NAME", "KIND", "PORT", "RXSIZE", "OWNER" + ); + + for socket in &manifest.sockets { + println!( + " {:20} {:5} {:>6} {:>7} {}", + socket.name, + socket.kind, + socket.port, + socket.rx.bytes, + socket.owner.name, + ); + } + } + Ok(()) } diff --git a/cmd/rpc/src/lib.rs b/cmd/rpc/src/lib.rs index d25a43225..6e766d515 100644 --- a/cmd/rpc/src/lib.rs +++ b/cmd/rpc/src/lib.rs @@ -364,7 +364,7 @@ pub struct RpcClient<'a> { hubris: &'a HubrisArchive, socket: UdpSocket, rpc_reply_type: &'a HubrisEnum, - buf: [u8; 1024], // matches buffer size in `task-udprpc` + buf: Vec, // sized to match socket buffer size } impl<'a> RpcClient<'a> { @@ -373,8 +373,8 @@ impl<'a> RpcClient<'a> { ip: ScopedV6Addr, timeout: Duration, ) -> Result { - // Hard-coded socket address, based on Hubris configuration - let target = format!("[{ip}]:998"); + let udprpc = hubris.manifest.get_socket_by_task("udprpc")?; + let target = format!("[{ip}]:{}", udprpc.port); let dest = target.to_socket_addrs()?.collect::>(); let socket = UdpSocket::bind("[::]:0")?; @@ -393,7 +393,8 @@ impl<'a> RpcClient<'a> { .lookup_enum_byname(hubris, "RpcReply")? .ok_or_else(|| anyhow!("can't find RpcReply"))?; - Ok(Self { hubris, socket, rpc_reply_type, buf: [0; 1024] }) + let buf = vec![0u8; udprpc.tx.bytes]; + Ok(Self { hubris, socket, rpc_reply_type, buf }) } pub fn call( diff --git a/humility-bin/tests/cmd/manifest/manifest.chilly.0.stdout b/humility-bin/tests/cmd/manifest/manifest.chilly.0.stdout index d126b1d03..a9b33b30a 100644 --- a/humility-bin/tests/cmd/manifest/manifest.chilly.0.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.chilly.0.stdout @@ -156,3 +156,6 @@ 74 DIMM_G1 i2c id=39 temp 75 DIMM_H0 i2c id=40 temp 76 DIMM_H1 i2c id=41 temp + sockets => 1 socket + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho diff --git a/humility-bin/tests/cmd/manifest/manifest.control_plane_agent.overflow.0.stdout b/humility-bin/tests/cmd/manifest/manifest.control_plane_agent.overflow.0.stdout index c7e01fc9c..41696c705 100644 --- a/humility-bin/tests/cmd/manifest/manifest.control_plane_agent.overflow.0.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.control_plane_agent.overflow.0.stdout @@ -258,3 +258,10 @@ 130 DIMM_H1 i2c id=74 temp 131 M2_A i2c id=75 temp 132 M2_B i2c id=76 temp + sockets => 5 sockets + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho + broadcast udp 997 1024 udpbroadcast + control_plane_agent udp 11111 2048 control_plane_agent + dump_agent udp 11113 1024 dump_agent + inspector udp 23547 512 gimlet_inspector diff --git a/humility-bin/tests/cmd/manifest/manifest.counters.0.stdout b/humility-bin/tests/cmd/manifest/manifest.counters.0.stdout index 09d176e62..85fd128d1 100644 --- a/humility-bin/tests/cmd/manifest/manifest.counters.0.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.counters.0.stdout @@ -259,3 +259,11 @@ 130 DIMM_H1 i2c id=74 temp 131 M2_A i2c id=75 temp 132 M2_B i2c id=76 temp + sockets => 6 sockets + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho + broadcast udp 997 1024 udpbroadcast + control_plane_agent udp 11111 2048 control_plane_agent + dump_agent udp 11113 1024 dump_agent + inspector udp 23547 512 gimlet_inspector + rpc udp 998 1024 udprpc diff --git a/humility-bin/tests/cmd/manifest/manifest.duplicate_HostFlash_hash_REPLY.stdout b/humility-bin/tests/cmd/manifest/manifest.duplicate_HostFlash_hash_REPLY.stdout index d1a91c9fc..1d0140ebd 100644 --- a/humility-bin/tests/cmd/manifest/manifest.duplicate_HostFlash_hash_REPLY.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.duplicate_HostFlash_hash_REPLY.stdout @@ -184,3 +184,9 @@ 74 DIMM_G1 i2c id=61 temp 75 DIMM_H0 i2c id=62 temp 76 DIMM_H1 i2c id=63 temp + sockets => 4 sockets + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho + broadcast udp 997 1024 udpbroadcast + rpc udp 998 1024 udprpc + mgmt_gateway udp 11111 2048 mgmt_gateway diff --git a/humility-bin/tests/cmd/manifest/manifest.extern-regions.stdout b/humility-bin/tests/cmd/manifest/manifest.extern-regions.stdout index d9c2cf9b3..7bcc39f28 100644 --- a/humility-bin/tests/cmd/manifest/manifest.extern-regions.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.extern-regions.stdout @@ -258,3 +258,10 @@ 130 DIMM_G1 i2c id=74 temp 131 DIMM_H0 i2c id=75 temp 132 DIMM_H1 i2c id=76 temp + sockets => 5 sockets + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho + broadcast udp 997 1024 udpbroadcast + rpc udp 998 1024 udprpc + control_plane_agent udp 11111 2048 control_plane_agent + dump_agent udp 11113 1024 dump_agent diff --git a/humility-bin/tests/cmd/manifest/manifest.flash-ram-mismatch.0.stdout b/humility-bin/tests/cmd/manifest/manifest.flash-ram-mismatch.0.stdout index 080d927d4..cc6ba3141 100644 --- a/humility-bin/tests/cmd/manifest/manifest.flash-ram-mismatch.0.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.flash-ram-mismatch.0.stdout @@ -158,3 +158,7 @@ 74 DIMM_G1 i2c id=39 temp 75 DIMM_H0 i2c id=40 temp 76 DIMM_H1 i2c id=41 temp + sockets => 2 sockets + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho + broadcast udp 997 1024 udpbroadcast diff --git a/humility-bin/tests/cmd/manifest/manifest.gimlet-c-dev-image-default-v1.0.2.zip.stdout b/humility-bin/tests/cmd/manifest/manifest.gimlet-c-dev-image-default-v1.0.2.zip.stdout index 588f32aa1..95f2f3cdc 100644 --- a/humility-bin/tests/cmd/manifest/manifest.gimlet-c-dev-image-default-v1.0.2.zip.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.gimlet-c-dev-image-default-v1.0.2.zip.stdout @@ -258,3 +258,10 @@ 130 DIMM_H1 i2c id=74 temp 131 M2_A i2c id=75 temp 132 M2_B i2c id=76 temp + sockets => 5 sockets + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho + broadcast udp 997 1024 udpbroadcast + control_plane_agent udp 11111 2048 control_plane_agent + dump_agent udp 11113 1024 dump_agent + rpc udp 998 1024 udprpc diff --git a/humility-bin/tests/cmd/manifest/manifest.host-panic.0.stdout b/humility-bin/tests/cmd/manifest/manifest.host-panic.0.stdout index ed71c8723..e68029bab 100644 --- a/humility-bin/tests/cmd/manifest/manifest.host-panic.0.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.host-panic.0.stdout @@ -259,3 +259,11 @@ 130 DIMM_H1 i2c id=74 temp 131 M2_A i2c id=75 temp 132 M2_B i2c id=76 temp + sockets => 6 sockets + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho + broadcast udp 997 1024 udpbroadcast + control_plane_agent udp 11111 2048 control_plane_agent + dump_agent udp 11113 1024 dump_agent + inspector udp 23547 512 gimlet_inspector + rpc udp 998 1024 udprpc diff --git a/humility-bin/tests/cmd/manifest/manifest.host-panic.1.stdout b/humility-bin/tests/cmd/manifest/manifest.host-panic.1.stdout index ed71c8723..e68029bab 100644 --- a/humility-bin/tests/cmd/manifest/manifest.host-panic.1.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.host-panic.1.stdout @@ -259,3 +259,11 @@ 130 DIMM_H1 i2c id=74 temp 131 M2_A i2c id=75 temp 132 M2_B i2c id=76 temp + sockets => 6 sockets + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho + broadcast udp 997 1024 udpbroadcast + control_plane_agent udp 11111 2048 control_plane_agent + dump_agent udp 11113 1024 dump_agent + inspector udp 23547 512 gimlet_inspector + rpc udp 998 1024 udprpc diff --git a/humility-bin/tests/cmd/manifest/manifest.host-panic.2.stdout b/humility-bin/tests/cmd/manifest/manifest.host-panic.2.stdout index ed71c8723..e68029bab 100644 --- a/humility-bin/tests/cmd/manifest/manifest.host-panic.2.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.host-panic.2.stdout @@ -259,3 +259,11 @@ 130 DIMM_H1 i2c id=74 temp 131 M2_A i2c id=75 temp 132 M2_B i2c id=76 temp + sockets => 6 sockets + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho + broadcast udp 997 1024 udpbroadcast + control_plane_agent udp 11111 2048 control_plane_agent + dump_agent udp 11113 1024 dump_agent + inspector udp 23547 512 gimlet_inspector + rpc udp 998 1024 udprpc diff --git a/humility-bin/tests/cmd/manifest/manifest.host-panic.3.stdout b/humility-bin/tests/cmd/manifest/manifest.host-panic.3.stdout index 644901130..96ecb9610 100644 --- a/humility-bin/tests/cmd/manifest/manifest.host-panic.3.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.host-panic.3.stdout @@ -259,3 +259,11 @@ 130 DIMM_H1 i2c id=74 temp 131 M2_A i2c id=75 temp 132 M2_B i2c id=76 temp + sockets => 6 sockets + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho + broadcast udp 997 1024 udpbroadcast + control_plane_agent udp 11111 2048 control_plane_agent + dump_agent udp 11113 1024 dump_agent + inspector udp 23547 512 gimlet_inspector + rpc udp 998 1024 udprpc diff --git a/humility-bin/tests/cmd/manifest/manifest.host-panic.4.stdout b/humility-bin/tests/cmd/manifest/manifest.host-panic.4.stdout index 644901130..96ecb9610 100644 --- a/humility-bin/tests/cmd/manifest/manifest.host-panic.4.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.host-panic.4.stdout @@ -259,3 +259,11 @@ 130 DIMM_H1 i2c id=74 temp 131 M2_A i2c id=75 temp 132 M2_B i2c id=76 temp + sockets => 6 sockets + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho + broadcast udp 997 1024 udpbroadcast + control_plane_agent udp 11111 2048 control_plane_agent + dump_agent udp 11113 1024 dump_agent + inspector udp 23547 512 gimlet_inspector + rpc udp 998 1024 udprpc diff --git a/humility-bin/tests/cmd/manifest/manifest.idol-returns-an-enum.stdout b/humility-bin/tests/cmd/manifest/manifest.idol-returns-an-enum.stdout index 324459298..28ec9e400 100644 --- a/humility-bin/tests/cmd/manifest/manifest.idol-returns-an-enum.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.idol-returns-an-enum.stdout @@ -258,3 +258,10 @@ 130 DIMM_G1 i2c id=74 temp 131 DIMM_H0 i2c id=75 temp 132 DIMM_H1 i2c id=76 temp + sockets => 5 sockets + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho + broadcast udp 997 1024 udpbroadcast + rpc udp 998 1024 udprpc + control_plane_agent udp 11111 2048 control_plane_agent + dump_agent udp 11113 1024 dump_agent diff --git a/humility-bin/tests/cmd/manifest/manifest.igor.0.stdout b/humility-bin/tests/cmd/manifest/manifest.igor.0.stdout index b1e25eaa3..4b45a06e5 100644 --- a/humility-bin/tests/cmd/manifest/manifest.igor.0.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.igor.0.stdout @@ -253,3 +253,9 @@ 130 DIMM_G1 i2c id=73 temp 131 DIMM_H0 i2c id=74 temp 132 DIMM_H1 i2c id=75 temp + sockets => 4 sockets + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho + broadcast udp 997 1024 udpbroadcast + rpc udp 998 1024 udprpc + control_plane_agent udp 11111 2048 control_plane_agent diff --git a/humility-bin/tests/cmd/manifest/manifest.in_bootloader.0.stdout b/humility-bin/tests/cmd/manifest/manifest.in_bootloader.0.stdout index bda788bde..80141ca6c 100644 --- a/humility-bin/tests/cmd/manifest/manifest.in_bootloader.0.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.in_bootloader.0.stdout @@ -158,3 +158,7 @@ 74 DIMM_G1 i2c id=39 temp 75 DIMM_H0 i2c id=40 temp 76 DIMM_H1 i2c id=41 temp + sockets => 2 sockets + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho + broadcast udp 997 1024 udpbroadcast diff --git a/humility-bin/tests/cmd/manifest/manifest.ipc-counts.0.stdout b/humility-bin/tests/cmd/manifest/manifest.ipc-counts.0.stdout index 43e129bf7..9e0688f0b 100644 --- a/humility-bin/tests/cmd/manifest/manifest.ipc-counts.0.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.ipc-counts.0.stdout @@ -259,3 +259,11 @@ 130 DIMM_H1 i2c id=74 temp 131 M2_A i2c id=75 temp 132 M2_B i2c id=76 temp + sockets => 6 sockets + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho + broadcast udp 997 1024 udpbroadcast + control_plane_agent udp 11111 2048 control_plane_agent + dump_agent udp 11113 1024 dump_agent + inspector udp 23547 512 gimlet_inspector + rpc udp 998 1024 udprpc diff --git a/humility-bin/tests/cmd/manifest/manifest.kernel-panic.0.stdout b/humility-bin/tests/cmd/manifest/manifest.kernel-panic.0.stdout index f563c166d..89ef5fab9 100644 --- a/humility-bin/tests/cmd/manifest/manifest.kernel-panic.0.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.kernel-panic.0.stdout @@ -27,3 +27,6 @@ i2c buses => 1 controller, 1 bus C PORT MODE NAME DESCRIPTION 2 F init - - + sockets => 1 socket + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho diff --git a/humility-bin/tests/cmd/manifest/manifest.kernel-panic.1.stdout b/humility-bin/tests/cmd/manifest/manifest.kernel-panic.1.stdout index 56187b6f6..40e0f45b9 100644 --- a/humility-bin/tests/cmd/manifest/manifest.kernel-panic.1.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.kernel-panic.1.stdout @@ -254,3 +254,9 @@ 130 DIMM_G1 i2c id=73 temp 131 DIMM_H0 i2c id=74 temp 132 DIMM_H1 i2c id=75 temp + sockets => 4 sockets + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho + broadcast udp 997 1024 udpbroadcast + rpc udp 998 1024 udprpc + control_plane_agent udp 11111 2048 control_plane_agent diff --git a/humility-bin/tests/cmd/manifest/manifest.kiowa.26.stdout b/humility-bin/tests/cmd/manifest/manifest.kiowa.26.stdout index 9d35d2372..a646c9034 100644 --- a/humility-bin/tests/cmd/manifest/manifest.kiowa.26.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.kiowa.26.stdout @@ -25,3 +25,6 @@ i2c buses => 1 controller, 1 bus C PORT MODE NAME DESCRIPTION 2 F init - - + sockets => 1 socket + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho diff --git a/humility-bin/tests/cmd/manifest/manifest.new-ringbuf.stdout b/humility-bin/tests/cmd/manifest/manifest.new-ringbuf.stdout index 388e6a805..1efd94c35 100644 --- a/humility-bin/tests/cmd/manifest/manifest.new-ringbuf.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.new-ringbuf.stdout @@ -153,3 +153,10 @@ 60 V1P8_SYS i2c id=25 current 61 V1P8_SYS i2c id=25 voltage 62 vsc7448 i2c id=26 temp + sockets => 5 sockets + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho + broadcast udp 997 1024 udpbroadcast + rpc udp 998 1024 udprpc + control_plane_agent udp 11111 2048 control_plane_agent + transceivers udp 11112 2048 transceivers diff --git a/humility-bin/tests/cmd/manifest/manifest.nightly-2022-11-01.stdout b/humility-bin/tests/cmd/manifest/manifest.nightly-2022-11-01.stdout index 53ea00cdb..a6cc3c5da 100644 --- a/humility-bin/tests/cmd/manifest/manifest.nightly-2022-11-01.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.nightly-2022-11-01.stdout @@ -254,3 +254,9 @@ 130 DIMM_G1 i2c id=73 temp 131 DIMM_H0 i2c id=74 temp 132 DIMM_H1 i2c id=75 temp + sockets => 4 sockets + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho + broadcast udp 997 1024 udpbroadcast + rpc udp 998 1024 udprpc + control_plane_agent udp 11111 2048 control_plane_agent diff --git a/humility-bin/tests/cmd/manifest/manifest.panic-on-boot.stdout b/humility-bin/tests/cmd/manifest/manifest.panic-on-boot.stdout index 977f9cbe4..8aaa9f994 100644 --- a/humility-bin/tests/cmd/manifest/manifest.panic-on-boot.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.panic-on-boot.stdout @@ -254,3 +254,9 @@ 130 DIMM_G1 i2c id=73 temp 131 DIMM_H0 i2c id=74 temp 132 DIMM_H1 i2c id=75 temp + sockets => 4 sockets + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho + broadcast udp 997 1024 udpbroadcast + rpc udp 998 1024 udprpc + control_plane_agent udp 11111 2048 control_plane_agent diff --git a/humility-bin/tests/cmd/manifest/manifest.sidecar-b-image-default.zip.stdout b/humility-bin/tests/cmd/manifest/manifest.sidecar-b-image-default.zip.stdout index aa3e55c44..2710e3647 100644 --- a/humility-bin/tests/cmd/manifest/manifest.sidecar-b-image-default.zip.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.sidecar-b-image-default.zip.stdout @@ -186,3 +186,11 @@ 94 xcvr29 qsfp temp 95 xcvr30 qsfp temp 96 xcvr31 qsfp temp + sockets => 6 sockets + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho + broadcast udp 997 1024 udpbroadcast + rpc udp 998 1024 udprpc + control_plane_agent udp 11111 2048 control_plane_agent + dump_agent udp 11113 1024 dump_agent + transceivers udp 11112 2048 transceivers diff --git a/humility-bin/tests/cmd/manifest/manifest.spoopy.0.stdout b/humility-bin/tests/cmd/manifest/manifest.spoopy.0.stdout index eb538d7ea..d9a27670a 100644 --- a/humility-bin/tests/cmd/manifest/manifest.spoopy.0.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.spoopy.0.stdout @@ -123,3 +123,6 @@ 58 V12_SYS_A2 i2c id=25 power 59 V12_SYS_A2 i2c id=25 current 60 V12_SYS_A2 i2c id=25 voltage + sockets => 1 socket + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho diff --git a/humility-bin/tests/cmd/manifest/manifest.sprot_status.stdout b/humility-bin/tests/cmd/manifest/manifest.sprot_status.stdout index b7d9e2944..c0d54465a 100644 --- a/humility-bin/tests/cmd/manifest/manifest.sprot_status.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.sprot_status.stdout @@ -254,3 +254,9 @@ 130 DIMM_G1 i2c id=73 temp 131 DIMM_H0 i2c id=74 temp 132 DIMM_H1 i2c id=75 temp + sockets => 4 sockets + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho + broadcast udp 997 1024 udpbroadcast + rpc udp 998 1024 udprpc + control_plane_agent udp 11111 2048 control_plane_agent diff --git a/humility-bin/tests/cmd/manifest/manifest.static-tasks.0.stdout b/humility-bin/tests/cmd/manifest/manifest.static-tasks.0.stdout index db7749f3d..2882da256 100644 --- a/humility-bin/tests/cmd/manifest/manifest.static-tasks.0.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.static-tasks.0.stdout @@ -30,3 +30,6 @@ 2 F init - - 3 C init - - 4 F init - - + sockets => 1 socket + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho diff --git a/humility-bin/tests/cmd/manifest/manifest.static-tasks.1.stdout b/humility-bin/tests/cmd/manifest/manifest.static-tasks.1.stdout index a4ccc85f4..6dbf8b33f 100644 --- a/humility-bin/tests/cmd/manifest/manifest.static-tasks.1.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.static-tasks.1.stdout @@ -30,3 +30,6 @@ 2 F init - - 3 C init - - 4 F init - - + sockets => 1 socket + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho diff --git a/humility-bin/tests/cmd/manifest/manifest.task.net.stdout b/humility-bin/tests/cmd/manifest/manifest.task.net.stdout index f8870dac7..9af66765e 100644 --- a/humility-bin/tests/cmd/manifest/manifest.task.net.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.task.net.stdout @@ -258,3 +258,9 @@ 130 DIMM_G1 i2c id=74 temp 131 DIMM_H0 i2c id=75 temp 132 DIMM_H1 i2c id=76 temp + sockets => 4 sockets + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho + broadcast udp 997 1024 udpbroadcast + rpc udp 998 1024 udprpc + control_plane_agent udp 11111 2048 control_plane_agent diff --git a/humility-bin/tests/cmd/manifest/manifest.task.power.stdout b/humility-bin/tests/cmd/manifest/manifest.task.power.stdout index 832487335..27bbd6cb9 100644 --- a/humility-bin/tests/cmd/manifest/manifest.task.power.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.task.power.stdout @@ -259,3 +259,11 @@ 130 DIMM_H1 i2c id=74 temp 131 M2_A i2c id=75 temp 132 M2_B i2c id=76 temp + sockets => 6 sockets + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho + broadcast udp 997 1024 udpbroadcast + control_plane_agent udp 11111 2048 control_plane_agent + dump_agent udp 11113 1024 dump_agent + inspector udp 23547 512 gimlet_inspector + rpc udp 998 1024 udprpc diff --git a/humility-bin/tests/cmd/manifest/manifest.u16-ringbuf.stdout b/humility-bin/tests/cmd/manifest/manifest.u16-ringbuf.stdout index 6ae71e29e..ce0fb65c7 100644 --- a/humility-bin/tests/cmd/manifest/manifest.u16-ringbuf.stdout +++ b/humility-bin/tests/cmd/manifest/manifest.u16-ringbuf.stdout @@ -259,3 +259,11 @@ 130 DIMM_H1 i2c id=74 temp 131 M2_A i2c id=75 temp 132 M2_B i2c id=76 temp + sockets => 6 sockets + NAME KIND PORT RXSIZE OWNER + echo udp 7 1024 udpecho + broadcast udp 997 1024 udpbroadcast + control_plane_agent udp 11111 2048 control_plane_agent + dump_agent udp 11113 1024 dump_agent + inspector udp 23547 512 gimlet_inspector + rpc udp 998 1024 udprpc diff --git a/humility-core/src/hubris.rs b/humility-core/src/hubris.rs index ae89923c0..651e4ea54 100644 --- a/humility-core/src/hubris.rs +++ b/humility-core/src/hubris.rs @@ -59,9 +59,18 @@ pub struct HubrisManifest { pub i2c_devices: Vec, pub i2c_buses: Vec, pub sensors: Vec, + pub sockets: Vec, pub auxflash: Option, } +impl HubrisManifest { + pub fn get_socket_by_task(&self, task: &str) -> Result<&HubrisSocket> { + self.sockets.iter().find(|s| s.owner.name == task).ok_or_else(|| { + anyhow!("couldn't find socket with owner {:?}", task) + }) + } +} + // // This structure (and the structures that it refers to) contain everything // that we might want to pull out of the config TOML -- which will be a subset @@ -241,10 +250,26 @@ impl HubrisConfigAuxflash { #[derive(Clone, Debug, Deserialize)] struct HubrisConfigConfig { i2c: Option, + net: Option, sensor: Option, auxflash: Option, } +#[derive(Clone, Debug, Deserialize)] +struct HubrisConfigNet { + #[serde(default)] + sockets: IndexMap, +} + +#[derive(Clone, Debug, Deserialize)] +struct HubrisConfigSocket { + kind: String, + owner: HubrisSocketOwner, + port: u16, + tx: HubrisSocketBuffer, + rx: HubrisSocketBuffer, +} + #[derive(Clone, Debug, Deserialize)] pub struct HubrisConfigSensor { devices: Vec, @@ -369,6 +394,92 @@ pub struct HubrisSensor { pub device: HubrisSensorDevice, } +#[derive(Clone, Debug, Serialize)] +pub struct HubrisSocket { + pub name: String, + pub kind: String, + pub owner: HubrisSocketOwner, + pub port: u16, + pub tx: HubrisSocketBuffer, + pub rx: HubrisSocketBuffer, +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct HubrisSocketOwner { + pub name: String, + #[serde(deserialize_with = "deserialize_notification")] + pub notification: HubrisSocketNotification, +} + +#[derive(Copy, Clone, Debug, Deserialize, Serialize)] +pub struct HubrisSocketBuffer { + pub packets: usize, + pub bytes: usize, +} + +use serde::de::{self, Deserializer, Visitor}; + +#[derive(Debug, Clone)] +pub enum HubrisSocketNotification { + Bit(u64), + Named(String), +} + +/// Deserialize a `HubrisSocketNotification` from either a string or integer +fn deserialize_notification<'de, D>( + deserializer: D, +) -> Result +where + D: Deserializer<'de>, +{ + struct NotificationVisitor; + impl<'de> Visitor<'de> for NotificationVisitor { + type Value = HubrisSocketNotification; + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("a string or an integer") + } + + fn visit_u64(self, v: u64) -> Result + where + E: de::Error, + { + Ok(HubrisSocketNotification::Bit(v)) + } + + // Handle the case where the value is an integer + fn visit_i64(self, v: i64) -> Result + where + E: de::Error, + { + match u64::try_from(v) { + Ok(v) => self.visit_u64(v), + Err(_) => Err(E::custom("i64 must be positive")), + } + } + + // Handle the case where the value is a string, and parse it + fn visit_str(self, v: &str) -> Result + where + E: de::Error, + { + Ok(HubrisSocketNotification::Named(v.to_owned())) + } + } + deserializer.deserialize_any(NotificationVisitor) +} + +impl Serialize for HubrisSocketNotification { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + match self { + HubrisSocketNotification::Bit(i) => serializer.serialize_u64(*i), + HubrisSocketNotification::Named(n) => serializer.serialize_str(n), + } + } +} + impl fmt::Display for HubrisSensorKind { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( @@ -1162,6 +1273,20 @@ impl HubrisArchive { if let Some(sensor) = config.sensor.as_ref() { self.load_sensor_config(sensor)?; } + if let Some(net) = config.net.as_ref() { + self.manifest.sockets = net + .sockets + .iter() + .map(|(name, cfg)| HubrisSocket { + name: name.clone(), + kind: cfg.kind.clone(), + owner: cfg.owner.clone(), + port: cfg.port, + tx: cfg.tx, + rx: cfg.rx, + }) + .collect(); + } } Ok(()) @@ -1972,6 +2097,13 @@ impl HubrisArchive { .find(|t| t.iface.as_ref().map(|i| i.name == name).unwrap_or(false)) } + pub fn get_socket_by_iface(&self, iface: &str) -> Result<&HubrisSocket> { + let module = self.lookup_module_by_iface(iface).ok_or_else(|| { + anyhow!("couldn't find task implementing {:?}", iface) + })?; + self.manifest.get_socket_by_task(&module.name) + } + pub fn modules(&self) -> impl Iterator { self.modules.values() } diff --git a/humility-hiffy/src/lib.rs b/humility-hiffy/src/lib.rs index c23769444..f25b9eafb 100644 --- a/humility-hiffy/src/lib.rs +++ b/humility-hiffy/src/lib.rs @@ -442,6 +442,9 @@ impl<'a> HiffyContext<'a> { bail!("can't make non-Idol calls over RPC"); } + // Find the socket that we'll be using to communicate + let udprpc = self.hubris.manifest.get_socket_by_task("udprpc")?; + // Pick values that are much larger than we'd ever see on a machine const HIFFY_TEXT_SIZE: usize = 65536; const HIFFY_RSTACK_SIZE: usize = 65536; @@ -477,6 +480,9 @@ impl<'a> HiffyContext<'a> { hubris: Option>, core: Option>, + /// Socket used for communication + socket: Option, + /// If we receive an RPC result, then record the buffer here results: Vec>, @@ -489,6 +495,7 @@ impl<'a> HiffyContext<'a> { HiffySendWorkspace { hubris: None, core: None, + socket: None, results: vec![], errors: vec![], }); @@ -538,8 +545,7 @@ impl<'a> HiffyContext<'a> { .map_err(|_| Failure::Fault(Fault::BadParameter(2)))?; } - let mut buf = [0u8; 1024]; // matches buffer size in `task-udprpc` - HIFFY_SEND_WORKSPACE.with(|workspace| { + let buf = HIFFY_SEND_WORKSPACE.with(|workspace| { let mut workspace = workspace.borrow_mut(); let (hubris, core) = { // SAFETY: we only ever call this function when the pointers @@ -553,6 +559,9 @@ impl<'a> HiffyContext<'a> { ) } }; + let socket = workspace.socket.as_ref().unwrap(); + + let mut buf = vec![0u8; socket.tx.bytes]; let image_id = hubris.image_id().unwrap(); let header = RpcHeader { @@ -565,6 +574,15 @@ impl<'a> HiffyContext<'a> { let mut packet = header.as_bytes().to_vec(); packet.extend(&payload[0..nbytes as usize]); + if packet.len() > socket.rx.bytes { + let e = anyhow!( + "packet length {} exceeds rx buf size {}", + packet.len(), + socket.rx.bytes, + ); + workspace.errors.push(e); + return Err(Failure::FunctionError(0)); + } // Send the packet out if let Err(e) = core.send(&packet, NetAgent::UdpRpc) { @@ -575,8 +593,9 @@ impl<'a> HiffyContext<'a> { // Try to receive a reply match core.recv(buf.as_mut_slice(), NetAgent::UdpRpc) { Ok(n) => { - workspace.results.push(buf[0..n].to_vec()); - Ok(()) + buf.truncate(n); + workspace.results.push(buf.clone()); + Ok(buf) } Err(e) => { workspace.errors.push(e); @@ -663,6 +682,7 @@ impl<'a> HiffyContext<'a> { .unwrap(), ), + socket: Some(udprpc.clone()), results: vec![], errors: vec![], }; diff --git a/humility-net-core/src/lib.rs b/humility-net-core/src/lib.rs index d9687ea2e..c342357e6 100644 --- a/humility-net-core/src/lib.rs +++ b/humility-net-core/src/lib.rs @@ -15,7 +15,9 @@ use anyhow::{Context, Result, anyhow, bail}; use humility::{ core::{Core, NetAgent}, - hubris::{HubrisArchive, HubrisFlashMap, HubrisRegion, HubrisTask}, + hubris::{ + HubrisArchive, HubrisFlashMap, HubrisRegion, HubrisSocket, HubrisTask, + }, msg, net::ScopedV6Addr, }; @@ -50,45 +52,30 @@ impl NetCore { hubris: &HubrisArchive, timeout: Duration, ) -> Result { - let udprpc_socket = if hubris.lookup_task("udprpc").is_some() { - // See oxidecomputer/oana for standard Hubris UDP ports - let target = format!("[{addr}]:998"); - + let open_socket = |socket: &HubrisSocket| -> Result<_> { + let target = format!("[{addr}]:{}", socket.port); let dest = target.to_socket_addrs()?.collect::>(); - let udprpc_socket = UdpSocket::bind("[::]:0")?; - udprpc_socket.set_read_timeout(Some(timeout))?; - udprpc_socket.connect(&dest[..])?; - Some(udprpc_socket) - } else { - None + let socket = UdpSocket::bind("[::]:0")?; + socket.set_read_timeout(Some(timeout))?; + socket.connect(&dest[..])?; + Ok(socket) }; + let udprpc_socket = hubris + .manifest + .get_socket_by_task("udprpc") + .ok() + .map(open_socket) + .transpose()?; // We'll check to see if there's a dump agent available over UDP, which // means // 1) There's a task implementing the `DumpAgent` interface - // 2) That task has the `net` feature enabled - - // Find the dump agent task name. This is usually `dump_agent`, but - // that's not guaranteed; what *is* guaranteed is that it implements the - // DumpAgent interface. - let dump_agent_task = - hubris.lookup_module_by_iface("DumpAgent").map(|t| t.task); - let has_dump_agent = dump_agent_task - .map(|t| hubris.does_task_have_feature(t, "net").unwrap()) - .unwrap_or(false); - - // - // See oxidecomputer/oana for standard Hubris UDP ports - let dump_agent_socket = if has_dump_agent { - let target = format!("[{addr}]:11113"); - let dest = target.to_socket_addrs()?.collect::>(); - let dump_agent_socket = UdpSocket::bind("[::]:0")?; - dump_agent_socket.set_read_timeout(Some(timeout))?; - dump_agent_socket.connect(&dest[..])?; - Some(dump_agent_socket) - } else { - None - }; + // 2) That task has an associated socket + let dump_agent_socket = hubris + .get_socket_by_iface("DumpAgent") + .ok() + .map(open_socket) + .transpose()?; let mut out = Self { udprpc_socket,