网络仿真框架

Network Emulation Framework

网络仿真框架

Contents

内容

Disclamer

免责声明

This documentation explain the implementation details of Network Emulation Framework. Framework's public APIs are located in:

本文档解释了网络仿真框架的实现细节。框架的公共API位于:

Overview

概述

Network Emulation Framework provides an ability to emulate network behavior between different clients, including a WebRTC PeerConnection client. To configure network behavior, the user can choose different options:

网络仿真框架提供了在不同客户端(包括WebRTC对等连接客户端)之间模拟网络行为的能力。要配置网络行为,用户可以选择不同的选项:

  • Use predefined implementation that can be configured with parameters such as packet loss, bandwidth, delay, etc.
  • 使用预定义的实现,该实现可以使用参数(如数据包丢失、带宽、延迟等)进行配置。
  • Custom implementation
  • 自定义实现

Conceptually the framework provides the ability to define multiple endpoints and routes used to connect them. All network related entities are created and managed by single factory class webrtc::NetworkEmulationManager which is implemented by webrtc::test::NetworkEmulationManagerImpl and can work in two modes:

从概念上讲,该框架提供了定义多个端点和用于连接它们的路由的能力。所有与网络相关的实体都由单个工厂类webrtc::NetworkEmulationManager创建和管理,该类由webrtc::test::NetworkSimulationManagerImpl实现,可以在两种模式下工作:

  • Real time
  • 实时
  • Simulated time
  • 模拟时间

The manager has a dedicated task queue which pipes all packets through all network routes from senders to receivers. This task queue behaviour is determined by webrtc::TimeController, which is based on either in real time or simulated time mode.

管理器有一个专用的任务队列,它通过所有网络路由将所有数据包从发送方传送到接收方。此任务队列行为由webrtc::TimeController决定,它基于实时或模拟时间模式。

The network operates on IP level and supports only UDP for now.

该网络在IP级别上运行,目前仅支持UDP。

Abstractions

抽象

The framework contains the following public abstractions:

该框架包含以下公共抽象:

  • webrtc::NetworkBehaviorInterface - defines how emulated network should behave. It operates on packets metadata level and is responsible for telling which packet at which time have to be delivered to the next receiver.

  • webrtc::NetworkBehaviorInterface-定义模拟网络的行为方式。它在数据包元数据级别上操作,并负责告知在哪个时间必须将哪个数据包传递给下一个接收器。

  • webrtc::EmulatedIpPacket - represents a single packet that can be sent or received via emulated network. It has source and destination address and payload to transfer.

  • webrtc::EmulatedIpPacket-表示可以通过模拟网络发送或接收的单个数据包。它具有要传输的源地址、目标地址和有效载荷。

  • webrtc::EmulatedNetworkReceiverInterface - generic packet receiver interface.

  • webrtc::EmulatedNetworkReceiverInterface-通用数据包接收器接口。

  • webrtc::EmulatedEndpoint - primary user facing abstraction of the framework. It represents a network interface on client's machine. It has its own unique IP address and can be used to send and receive packets.

    EmulatedEndpoint implements EmulatedNetworkReceiverInterface to receive packets from the network and provides an API to send packets to the network and API to bind other EmulatedNetworkReceiverInterface which will be able to receive packets from the endpoint. EmulatedEndpoint interface has the only implementation: webrtc::test::EmulatedEndpointImpl.

  • webrtc::EmulatedEndpoint-面向用户的主要框架抽象。表示客户端机器上的网络接口。有自己唯一的IP地址,可以用来发送和接收数据包。
    EmulatedEndpoint实现EmulatedNetworkReceiverInterface以从网络接收数据包,并提供向网络发送数据包的API和绑定其他能够从端点接收数据包的EmulatedNetworksReceiverInterface的API。EmulatedEndpoint接口只有一个实现:webrtc::test::EmulatedEndpointImpl。

  • webrtc::EmulatedNetworkNode - represents single network in the real world, like a 3G network between peers, or Wi-Fi for one peer and LTE for another. Each EmulatedNetworkNode is a single direction connetion and to form bidirectional connection between endpoints two nodes should be used. Multiple nodes can be joined into chain emulating a network path from one peer to another.

    In public API this class is forward declared and fully accessible only by the framework implementation.

    Internally consist of two parts: LinkEmulation, which is responsible for behavior of current EmulatedNetworkNode and NetworkRouterNode which is responsible for routing packets to the next node or to the endpoint.

  • webrtc::EmulatedNetworkNode-代表现实世界中的单个网络,比如对等端之间的3G网络,或者一个对等端的Wi-Fi和另一个对等端的LTE。每个EmulatedNetworkNode都是单向连接,为了在端点之间形成双向连接,应该使用两个节点。可以将多个节点加入模拟从一个对等端到另一个对等端的网络路径的链中。
    在公共API中,这个类是前向声明的,并且只有框架实现才能完全访问。
    内部由两部分组成:LinkEmulation,负责当前EmulatedNetworkNode的行为;NetworkRouterNode,负责将数据包路由到下一个节点或端点。

  • webrtc::EmulatedRoute - represents single route from one network interface on one device to another network interface on another device.

    In public API this class is forward declared and fully accessible only by the framework implementation.

    It contains start and end endpoint and ordered list of EmulatedNetworkNode which forms the single directional route between those endpoints.

  • webrtc::EmulatedRoute-表示从一个设备上的一个网络接口到另一个设备的另一个网络界面的单一路由。
    在公共API中,这个类是前向声明的,并且只有框架实现才能完全访问。
    它包含起始和结束端点以及EmulatedNetworkNode的有序列表,该列表形成了这些端点之间的单向路由。

The framework has also the following private abstractions:

该框架还具有以下私有抽象:

  • webrtc::test::NetworkRouterNode - an EmulatedNetworkReceiverInterface that can route incoming packets to the next receiver based on internal IP routing table.

  • webrtc::test::NetworkRouterNode-一个仿真的NetworkReceiverInterface,可以根据内部IP路由表将传入的数据包路由到下一个接收器。

  • webrtc::test::LinkEmulation - an EmulatedNetworkReceiverInterface that can emulate network leg behavior via webrtc::NetworkBehaviorInterface interface.

  • webrtc::test::LinkEmulation-一个EmulatedNetworkReceiverInterface,可以通过webrtc::NetworkBehaviorInterface接口模拟网络支路行为。

For integrating with webrtc::PeerConnection there are helper abstractions:

为了与webrtc::PeerConnection集成,有一些助手抽象:

  • webrtc::EmulatedNetworkManagerInterface which is implemented by webrtc::test::EmulatedNetworkManager and provides rtc::Thread and rtc::NetworkManager for WebRTC to use as network thread for PeerConnection and for cricket::BasicPortAllocator.

  • webrtc::EmulatedNetworkManager接口,由webrtc::test::EmulatedNetworkManager实现,并为webrtc提供rtc::Thread和rtc::NetworkManager,用作PeerConnection和cricket::BasicPortAllocator的网络线程。

    Implementation represent framework endpoints as rtc::Network to WebRTC.
  • 实现将框架端点表示为rtc::Network到WebRTC。

Architecture

架构

Let‘s take a look on how framework’s abstractions are connected to each other.

让我们来看看框架的抽象是如何相互连接的。

When the user wants to setup emulated network, first of all, they should create an instance of NetworkEmulationManager using webrtc::CreateNetworkEmulationManager(...) API. Then user should use a manager to create at least one EmulatedEndpoint for each client. After endpoints, the user should create required EmulatedNetworkNodes and with help of manager chain them into EmulatedRoutes conecting desired endpoints.

当用户想要设置模拟网络时,首先,他们应该使用webrtc::CreateNetworkEmulationManager(…)API创建NetworkEmulationManager的实例。然后,用户应该使用管理器为每个客户端创建至少一个EmulatedEndpoint。在端点之后,用户应该创建所需的EmulatedNetworkNodes,并在管理器的帮助下将它们链接到连接所需端点的EmulatedRoutes中。

Here is a visual overview of the emulated network architecture:

以下是模拟网络体系结构的可视化概述:

When network is hooked into PeerConnection it is done through network thread and NetworkManager. In the network thread the custom rtc::SocketServer is provided: webrtc::test::FakeNetworkSocketServer. This custom socket server will construct custom sockets (webrtc::test::FakeNetworkSocket), which internally bind themselves to the required endpoint. All packets processing inside socket have to be done on the PeerConnection‘s network thread. When packet is going from PeerConnection to the network it’s already comming from the network thread and when it's comming from the emulated network switch from the Network Emulation Framework internal task queue and PeerConnection‘s network thread is done inside socket’s OnPacketReceived(...) method.

当网络连接到对等连接时,它是通过网络线程和NetworkManager完成的。在网络线程中,提供了自定义的rtc::SocketServer:webrtc::test::FakeNetworkSocketServer。这个自定义套接字服务器将构造自定义套接字(webrtc::test::FakeNetworkSocket),这些套接字在内部将自己绑定到所需的端点。套接字内的所有数据包处理都必须在对等连接的网络线程上完成。当数据包从对等连接到网络时,它已经从网络线程混合,当它从网络仿真框架内部任务队列的模拟网络交换机混合时,对等连接的网络线程在套接字的OnPacketReceived(…)方法中完成。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值