[netstack3] Update enclosed runner tool
- Enclosed runner uses fuchsia_component instead of relying on
run_test_component.
- Updated README
BUG: NET-2278 #done
Change-Id: Ibc0011d1e4cf899abf60db0759c0a54a052ed1f9
diff --git a/src/connectivity/network/netstack3/tools/enclosed_runner/README.md b/src/connectivity/network/netstack3/tools/enclosed_runner/README.md
index 26506faf..f3f86d6 100644
--- a/src/connectivity/network/netstack3/tools/enclosed_runner/README.md
+++ b/src/connectivity/network/netstack3/tools/enclosed_runner/README.md
@@ -19,7 +19,7 @@
* Now that we can use ethernet `001` for ourselves, we can start `enclosed_runner` giving it
the path to the ethernet device and some fixed IP address:
```
-$ run_test_component fuchsia-pkg://fuchsia.com/netstack3_tools#meta/enclosed_runner.cmx -e /dev/class/ethernet/001 -i 192.168.3.55/24 &
+$ run fuchsia-pkg://fuchsia.com/netstack3_tools#meta/enclosed_runner.cmx -e /dev/class/ethernet/001 -i 192.168.3.55/24 &
```
*Note the `&` at the end* of the command. `enclosed_runner` is using the
`fuchsia.test` facet to make use of `run_test_component`'s environment creation.
@@ -32,12 +32,15 @@
* If you want to start processes that use `netstack3`, like `net_cli` for
example, you can `chrealm` into the realm created for `enclosed_runner`, like:
```
-$ chrealm /hub/r/<env_name>/<koid>
+$ chrealm /hub/r/netstack3-env/<koid>
```
-where `<koid>` and `<env_name>` will both change between different runs. The chrealm command to run will be printed when starting `enclosed_runner`. `chrealm` will drop you into a nested shell
-environment that is mapping the `svc` folder to the enclosed environment where
-`netstack3` is running. You can `CTRL+D` out of `chrealm` to go back to the `sys` realm
-when you're done.
+where `<koid>` will change between different runs. The chrealm command to run will be printed when
+starting `enclosed_runner`.
+`chrealm` will drop you into a nested shell environment that is mapping the `svc` folder to the
+enclosed environment where
+`netstack3` is running. You can `CTRL+D` out of `chrealm` to go back to the `sys` realm when
+you're done.
+
* Because `enclosed_runner` will keep running in the background, you can kill it
(and `netstack3` along with it) with `killall enclosed_runner.cmx`. And,
because `netstack3` is killed along with it, if you re-build of `netstack3`
diff --git a/src/connectivity/network/netstack3/tools/enclosed_runner/src/main.rs b/src/connectivity/network/netstack3/tools/enclosed_runner/src/main.rs
index 1faf4f5..6649b9d 100644
--- a/src/connectivity/network/netstack3/tools/enclosed_runner/src/main.rs
+++ b/src/connectivity/network/netstack3/tools/enclosed_runner/src/main.rs
@@ -9,13 +9,19 @@
use fidl_fuchsia_hardware_ethernet as zx_eth;
use fidl_fuchsia_net as net;
use fidl_fuchsia_net_stack::{self as netstack, StackMarker, StackProxy};
-use fuchsia_component::client;
use fuchsia_async as fasync;
+use fuchsia_component::{
+ client::AppBuilder,
+ server::{NestedEnvironment, ServiceFs},
+};
use fuchsia_zircon as zx;
-use std::fs::{self, File};
+use futures::prelude::*;
+use std::fs::File;
use std::os::unix::io::AsRawFd;
use structopt::StructOpt;
+const NETSTACK_URL: &'static str = "fuchsia-pkg://fuchsia.com/netstack3#meta/netstack3.cmx";
+
#[derive(StructOpt, Debug)]
struct Opt {
/// Path to the ethernet device to add to netstack,
@@ -84,8 +90,8 @@
}
impl Netstack {
- fn new() -> Result<Self, Error> {
- Ok(Self { stack: client::connect_to_service::<StackMarker>()? })
+ fn new(env: &NestedEnvironment) -> Result<Self, Error> {
+ Ok(Self { stack: env.connect_to_service::<StackMarker>()? })
}
async fn add_ethernet(&self, path: String) -> Result<u64, Error> {
@@ -140,7 +146,23 @@
#[fasync::run_singlethreaded]
async fn main() -> Result<(), Error> {
let options = Opt::from_args();
- let stack = Netstack::new()?;
+ // create nested environment for netstack:
+
+ let mut ns_builder = AppBuilder::new(NETSTACK_URL.to_string());
+
+ let mut services = ServiceFs::new_local();
+ services
+ .add_proxy_service_to::<StackMarker, _>(ns_builder.directory_request().unwrap().clone())
+ .add_proxy_service_to::<net::SocketProviderMarker, _>(
+ ns_builder.directory_request().unwrap().clone(),
+ );
+
+ let env = services.create_nested_environment("netstack3-env")?;
+
+ let _netstack = ns_builder.spawn(env.launcher())?;
+ fasync::spawn_local(services.collect());
+
+ let stack = Netstack::new(&env)?;
if let Some(eth_path) = options.ethernet {
// open ethernet device and send to stack.
let id = await!(stack.add_ethernet(eth_path))?;
@@ -153,11 +175,9 @@
}
}
- let env_name = fs::read_to_string("/hub/name")?;
println!("enclosed netstack is running...");
- println!("environment name: {}", env_name);
println!("run:");
- println!("chrealm /hub/r/{}/[koid]", env_name);
+ println!("chrealm /hub/r/netstack3-env/[koid]");
println!("to shell into the tailored environment (you can use tab completions for koid)");
println!("to stop the netstack and this environment, run:");
println!("killall enclosed_runner.cmx");
diff --git a/src/connectivity/network/netstack3/tools/meta/enclosed_runner.cmx b/src/connectivity/network/netstack3/tools/meta/enclosed_runner.cmx
index e79e5ea..714f01f 100644
--- a/src/connectivity/network/netstack3/tools/meta/enclosed_runner.cmx
+++ b/src/connectivity/network/netstack3/tools/meta/enclosed_runner.cmx
@@ -1,12 +1,4 @@
{
- "facets": {
- "fuchsia.test": {
- "injected-services": {
- "fuchsia.net.SocketProvider": "fuchsia-pkg://fuchsia.com/netstack3#meta/netstack3.cmx",
- "fuchsia.net.stack.Stack": "fuchsia-pkg://fuchsia.com/netstack3#meta/netstack3.cmx"
- }
- }
- },
"program": {
"binary": "bin/enclosed_runner"
},
@@ -14,11 +6,9 @@
"dev": [
"class/ethernet"
],
- "features": [
- "shell"
- ],
"services": [
- "fuchsia.net.stack.Stack"
+ "fuchsia.sys.Environment",
+ "fuchsia.sys.Loader"
]
}
}