Packet flow
Hyper-V Switch connections structure
The diagram below shows connections between a host and two containers with vRouter extension loaded to Hyper-V Switch. All interfaces (vhost, virtual, physical) are connected to the Hyper-V Switch and all packets are handled by vRouter.
Packet processing
-
Packets are sent from the host OS to vhost interface, from container to the virtual interface, or received on physical interface.
-
Packets are processed by NDIS and vRouter's
FilterSendNetBufferLists
function is called. It receives a list ofNBLs
(a list of lists of packets, see more here). -
If the switch is not running,
NdisFSendNetBufferListsComplete
function is caled and all packets are dropped. -
NBL
list is split into two lists: one that will be processed by vRouter and second, that requires native forwarding and will be forwarded by Hyper-V Switch. -
Natively-forwarded
NBLs
are passed to NDIS usingNdisFSendNetBufferLists
function. -
NBL
list is split into separateNBLs
. -
If there are no VIFs yet, packets are processed using simple switch logic without using of vRouter logic: they are sent to correct port using
NdisFSendNetBufferLists
function. -
Every
NBL
may contain multiple packets (NBs
). It is represented as aWIN_MULTI_PACKET
- an NDIS-independent wrapper. The system independent dp-core code handles single packet at a time, soWIN_MULTI_PACKET
is converted toPWIN_PACKET_LIST
- a list ofWIN_PACKET
structures which are wrappera aroundNBL
containing singleNB
. For more information about wrappers, please see Windows structures abstraction. -
For every
WIN_PACKET
, aVR_PACKET_WRAPPER
structure is allocated. It contains avr_packet
structure - a packet representation used in dp-core, which is linked in underlyingNBL
. -
The dp-core code requires that all packet headers are in a continuous memory region. On Windows, each
NB
contains a list ofMDLs
which describes multiple memory regions. To avoid a situation when the headers are in different memory regions, new NBL containing continuous memory region is allocated and all data is copied there. -
The packet is sent to dp-core using
vif_rx
function for selectedvif
. -
After processing the packet by dp-core, the
win_if_tx
function is called. The checksums are recalculated or offloaded - depending on checksum type and offload capabilities of the hardware - and the packet if split if it is too large (it is segmented - for TCP packets, or fragmented - for non-TCP packets). After this process the resulting packets are represented asWIN_MULTI_PACKET
. -
The destination port for the packets is selected basing on the
vif
. The packet is passed to NDIS usingNdisFSendNetBufferLists
function. -
After processing the packet by all layers of drivers, NDIS calls
FilterSendNetBufferListsComplete
function. vRouter frees all allocated packets and completes packets allocated by upper-layer drivers.