async fn run_netstack_and_get_ipv6_addrs_for_endpoint<N: Netstack>(
    endpoint: &fidl_fuchsia_netemul_network::EndpointProxy,
    launcher: &fidl_fuchsia_sys::LauncherProxy,
    name: String,
) -> Result<Vec<fidl_fuchsia_net::Subnet>> {
    let device =
        DeviceConnection::new(endpoint).await.context("failed to get device connection")?;
    // Launch the netstack service.
    let (dir, dir_server) = fuchsia_zircon::Channel::create()?;
    let (component_controller, component_controller_server) =
        fidl::endpoints::create_proxy::<fidl_fuchsia_sys::ComponentControllerMarker>()
            .context("failed to create launcher proxy")?;
    let () = launcher.create_component(
        &mut fidl_fuchsia_sys::LaunchInfo {
            url: N::URL.to_string(),
            arguments: None,
            out: None,
            err: None,
            directory_request: Some(dir_server),
            flat_namespace: None,
            additional_services: None,
        },
        Some(component_controller_server),
    )?;

    // Connect to the netstack service.
    let (netstack, server) =
        fidl::endpoints::create_proxy::<fidl_fuchsia_netstack::NetstackMarker>()
            .context("failed to create netstack proxy")?;
    let () = fdio::service_connect_at(
        &dir,
        <fidl_fuchsia_netstack::NetstackMarker as fidl::endpoints::DiscoverableService>::SERVICE_NAME,
        server.into_channel(),
    ).context("failed to connect to netstack")?;

    // Add the device and get its interface state from netstack.
    // TODO(48907) Support Network Device. This helper fn should use stack.fidl
    // and be agnostic over interface type.
    let id = netstack
        .add_ethernet_device(
            &name,
            &mut fidl_fuchsia_netstack::InterfaceConfig {
                name: name.to_string(),
                filepath: "/fake/filepath/for_test".to_string(),
                metric: 0,
                ip_address_config: fidl_fuchsia_netstack::IpAddressConfig::Dhcp(true),
            },
            device.expect_ethernet("add_ethernet_device requires an Ethernet endpoint"),
        )
        .await
        .context("failed to add ethernet device")?;
    let interface = netstack
        .get_interfaces2()
        .await
        .context("failed to get interfaces")?
        .into_iter()
        .find(|interface| interface.id == id)
        .ok_or(anyhow::format_err!("failed to find added ethernet device"))?;

    // Kill the netstack.
    //
    // Note, simply dropping `component_controller` would also kill the netstack
    // but we explicitly kill it and wait for the terminated event before
    // proceeding.
    let () = component_controller.kill()?;
    let mut event_stream = component_controller.take_event_stream();
    while let Some(event) = event_stream.next().await {
        match event? {
            fidl_fuchsia_sys::ComponentControllerEvent::OnTerminated { .. } => break,
            fidl_fuchsia_sys::ComponentControllerEvent::OnDirectoryReady {} => {}
        }
    }

    Ok(interface.ipv6addrs)
}
/// Launches a new netstack with the endpoint and returns the IPv6 addresses
/// initially assigned to it.
///
/// If `run_netstack_and_get_ipv6_addrs_for_endpoint` returns successfully, it
/// is guaranteed that the launched netstack has been terminated. Note, if
/// `run_netstack_and_get_ipv6_addrs_for_endpoint` does not return successfully,
/// the launched netstack will still be terminated, but no guarantees are made
/// about when that will happen.
Launches a new netstack with the endpoint and returns the IPv6 addresses
initially assigned to it.

If `run_netstack_and_get_ipv6_addrs_for_endpoint` returns successfully, it
is guaranteed that the launched netstack has been terminated. Note, if
`run_netstack_and_get_ipv6_addrs_for_endpoint` does not return successfully,
the launched netstack will still be terminated, but no guarantees are made
about when that will happen.
Launches a new netstack with the endpoint and returns the IPv6 addresses initially assigned to it . If ` run_netstack_and_get_ipv6_addrs_for_endpoint ` returns successfully it is guaranteed that the launched netstack has been terminated . Note if ` run_netstack_and_get_ipv6_addrs_for_endpoint ` does not return successfully the launched netstack will still be terminated but no guarantees are made about when that will happen .
async fn run_netstack_and_get_ipv6_addrs_for_endpoint<N: Netstack>(
    endpoint: &fidl_fuchsia_netemul_network::EndpointProxy,
    launcher: &fidl_fuchsia_sys::LauncherProxy,
    name: String,
) -> Result<Vec<fidl_fuchsia_net::Subnet>> {
    let device =
        DeviceConnection::new(endpoint).await.context("failed to get device connection")?;
    // Launch the netstack service.
    let (dir, dir_server) = fuchsia_zircon::Channel::create()?;
    let (component_controller, component_controller_server) =
        fidl::endpoints::create_proxy::<fidl_fuchsia_sys::ComponentControllerMarker>()
            .context("failed to create launcher proxy")?;
    let () = launcher.create_component(
        &mut fidl_fuchsia_sys::LaunchInfo {
            url: N::URL.to_string(),
            arguments: None,
            out: None,
            err: None,
            directory_request: Some(dir_server),
            flat_namespace: None,
            additional_services: None,
        },
        Some(component_controller_server),
    )?;
    // Connect to the netstack service.
    let (netstack, server) =
        fidl::endpoints::create_proxy::<fidl_fuchsia_netstack::NetstackMarker>()
            .context("failed to create netstack proxy")?;
    let () = fdio::service_connect_at(
        &dir,
        <fidl_fuchsia_netstack::NetstackMarker as fidl::endpoints::DiscoverableService>::SERVICE_NAME,
        server.into_channel(),
    ).context("failed to connect to netstack")?;
    // Add the device and get its interface state from netstack.
    // TODO(48907) Support Network Device. This helper fn should use stack.fidl
    // and be agnostic over interface type.
    let id = netstack
        .add_ethernet_device(
            &name,
            &mut fidl_fuchsia_netstack::InterfaceConfig {
                name: name.to_string(),
                filepath: "/fake/filepath/for_test".to_string(),
                metric: 0,
                ip_address_config: fidl_fuchsia_netstack::IpAddressConfig::Dhcp(true),
            },
            device.expect_ethernet("add_ethernet_device requires an Ethernet endpoint"),
        )
        .await
        .context("failed to add ethernet device")?;
    let interface = netstack
        .get_interfaces2()
        .await
        .context("failed to get interfaces")?
        .into_iter()
        .find(|interface| interface.id == id)
        .ok_or(anyhow::format_err!("failed to find added ethernet device"))?;
    // Kill the netstack.
    //
    // Note, simply dropping `component_controller` would also kill the netstack
    // but we explicitly kill it and wait for the terminated event before
    // proceeding.
    let () = component_controller.kill()?;
    let mut event_stream = component_controller.take_event_stream();
    while let Some(event) = event_stream.next().await {
        match event? {
            fidl_fuchsia_sys::ComponentControllerEvent::OnTerminated { .. } => break,
            fidl_fuchsia_sys::ComponentControllerEvent::OnDirectoryReady {} => {}
        }
    }
    Ok(interface.ipv6addrs)
}
async fn run_netstack_and_get_ipv6_addrs_for_endpoint < N : Netstack > ( endpoint : & fidl_fuchsia_netemul_network :: EndpointProxy , launcher : & fidl_fuchsia_sys :: LauncherProxy , name : String , ) -> Result < Vec < fidl_fuchsia_net :: Subnet > > { let device = DeviceConnection :: new ( endpoint ) . await . context ( " " ) ? ; // Launch the netstack service. let ( dir , dir_server ) = fuchsia_zircon :: Channel :: create ( ) ? ; let ( component_controller , component_controller_server ) = fidl :: endpoints :: create_proxy :: < fidl_fuchsia_sys :: ComponentControllerMarker > ( ) . context ( " " ) ? ; let ( ) = launcher . create_component ( & mut fidl_fuchsia_sys :: LaunchInfo { url : N :: URL . to_string ( ) , arguments : None , out : None , err : None , directory_request : Some ( dir_server ) , flat_namespace : None , additional_services : None , } , Some ( component_controller_server ) , ) ? ; // Connect to the netstack service. let ( netstack , server ) = fidl :: endpoints :: create_proxy :: < fidl_fuchsia_netstack :: NetstackMarker > ( ) . context ( " " ) ? ; let ( ) = fdio :: service_connect_at ( & dir , < fidl_fuchsia_netstack :: NetstackMarker as fidl :: endpoints :: DiscoverableService > :: SERVICE_NAME , server . into_channel ( ) , ) . context ( " " ) ? ; // Add the device and get its interface state from netstack. // TODO(48907) Support Network Device. This helper fn should use stack.fidl // and be agnostic over interface type. let id = netstack . add_ethernet_device ( & name , & mut fidl_fuchsia_netstack :: InterfaceConfig { name : name . to_string ( ) , filepath : " " . to_string ( ) , metric : 0 , ip_address_config : fidl_fuchsia_netstack :: IpAddressConfig :: Dhcp ( true ) , } , device . expect_ethernet ( " " ) , ) . await . context ( " " ) ? ; let interface = netstack . get_interfaces2 ( ) . await . context ( " " ) ? . into_iter ( ) . find ( | interface | interface . id == id ) . ok_or ( anyhow :: format_err ! ( " " ) ) ? ; // Kill the netstack. // // Note, simply dropping `component_controller` would also kill the netstack // but we explicitly kill it and wait for the terminated event before // proceeding. let ( ) = component_controller . kill ( ) ? ; let mut event_stream = component_controller . take_event_stream ( ) ; while let Some ( event ) = event_stream . next ( ) . await { match event ? { fidl_fuchsia_sys :: ComponentControllerEvent :: OnTerminated { .. } => break , fidl_fuchsia_sys :: ComponentControllerEvent :: OnDirectoryReady { } => { } } } Ok ( interface . ipv6addrs ) }
Launches a new netstack with the endpoint and returns the IPv6 addresses
initially assigned to it.
Launches a new netstack with the endpoint and returns the IPv6 addresses initially assigned to it .
endpoint
&fidl_fuchsia_netemul_network::EndpointProxy
launcher
&fidl_fuchsia_sys::LauncherProxy
name
String
endpoint
&fidl_fuchsia_netemul_network::EndpointProxy
launcher
&fidl_fuchsia_sys::LauncherProxy
name
String