blob: d6c11aea545cd5c73d8f8da15edb45904489907e [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
using fuchsia.hardware.ethernet;
using zx;
/// Provides emulated latency configuration.
struct LatencyConfig {
/// Average latency, in ms.
uint64 average;
/// Latency standard deviation, in ms.
uint64 std_dev;
// Note: Loss config is a union to be able to provide other models of packet loss.
/// Provides emulated packet loss configuration.
union LossConfig {
/// Rate of packet loss expressed as independent drop probability [0-100].
uint8 random_rate;
/// Provides emulated packet reordering configuration.
struct ReorderConfig {
/// Size of buffer, in packets, to store and forward with randomized order.
uint32 store_buff;
/// Tick/deadline in ms to empty buffer, regardless of full state.
/// 0 will cause buffer to flush only when full (dangerous).
uint64 tick;
/// Used to configure a network with emulated adversity conditions.
table NetworkConfig {
/// Latency configuration.
1: LatencyConfig latency;
/// Packet loss configuration.
2: LossConfig packet_loss;
/// Packet reordering configuration.
3: ReorderConfig reorder;
/// Manages virtual networks.
protocol NetworkManager {
/// Lists emulated networks by name.
ListNetworks() -> (vector<string> nets);
/// Creates a new network with given name and config.
CreateNetwork(string name, NetworkConfig config) -> (zx.status status, Network? net);
/// Gets a handle to a network.
GetNetwork(string name) -> (Network? net);
/// Backing of an emulated endpoint.
enum EndpointBacking {
/// Endpoint backed by ethertap device.
/// Configuration used to create an endpoint.
struct EndpointConfig {
/// Fake ethernet mtu.
uint16 mtu;
/// Fake ethernet mac address, if not provided will be set to randomized local mac,
/// using endpoint name as seed.
fuchsia.hardware.ethernet.MacAddress? mac;
/// Backing type of emulated endpoint.
EndpointBacking backing;
/// Manages virtual endpoints.
protocol EndpointManager {
/// Lists endpoints by name.
ListEndpoints() -> (vector<string> endp);
/// Creates endpoint with given name and config.
CreateEndpoint(string name, EndpointConfig config) -> (zx.status status, Endpoint? endpoint);
/// Gets a handle to an endpoint.
GetEndpoint(string name) -> (Endpoint? endpoint);
/// Fake endpoint can be added to a network to snoop or inject packets.
protocol FakeEndpoint {
/// Write Data packet to network.
Write(vector<uint8> data);
/// Called when network receives a data packet.
-> OnData(vector<uint8> data);
/// Virtual network.
protocol Network {
/// Gets network configuration.
GetConfig() -> (NetworkConfig config);
/// Gets network name.
GetName() -> (string name);
/// Updates network configuration.
SetConfig(NetworkConfig config) -> (zx.status status);
/// Attaches endpoint with given name to network.
AttachEndpoint(string name) -> (zx.status status);
/// Removes endpoint with given name from network.
RemoveEndpoint(string name) -> (zx.status status);
/// Injects a fake endpoint.
CreateFakeEndpoint(request<FakeEndpoint> ep);
/// Simple interface to serve devices over fidl.
protocol DeviceProxy {
/// Fulfills the device request.
ServeDevice(handle<channel> req);
/// Virtual ethernet endpoint.
protocol Endpoint {
// Gets endpoint configuration.
GetConfig() -> (EndpointConfig config);
/// Gets endpoint name.
GetName() -> (string name);
/// Sends link up or down signal
SetLinkUp(bool up) -> ();
/// Opens channel with zircon ethernet device.
GetEthernetDevice() -> (fuchsia.hardware.ethernet.Device device);
/// Gets a proxy to open requests with zircon ethernet device.
GetProxy(request<DeviceProxy> proxy);
/// Convenience struct for creating entire network setups.
struct NetworkSetup {
/// Network name, must be unique in network context.
string name;
/// NetworkConfig to use when creating network.
NetworkConfig config;
/// Collection of endpoints to create and attach to network.
vector<EndpointSetup> endpoints;
/// Convenience struct for creating endpoints along with network setup.
struct EndpointSetup {
/// Endpoint name, must be unique in network context.
string name;
/// Optional endpoint config, if not provided defaults will be used.
/// Default values are: mtu = 1500, backing = ETHERTAP, mac = randomized.
EndpointConfig? config;
/// Start endpoint with link status up.
bool link_up;
/// Handle returned when using NetworkContext.Setup for quick network configuration.
/// Networks and endpoints created by Setup are tied to the lifecycle of the SetupHandle's channel.
protocol SetupHandle {
/// Main entry point to manage virtual networks and endpoints.
protocol NetworkContext {
GetNetworkManager(request<NetworkManager> net_manager);
GetEndpointManager(request<EndpointManager> endp_manager);
/// Creates a collection of networks described by |networks|.
/// |status| is ZX_OK for success
/// |setup_handle| is a resource that references and maintains the lifecycle of
/// the created networks and endpoints.
Setup(vector<NetworkSetup> networks) -> (zx.status status, SetupHandle? setup_handle);