Ethernet Simulation
TEMU provides support for Ethernet bus based devices. To support the development of custom MAC controllers, TEMU provides three generic models.
The MDIOBus
model implements MDIO routing.
As multiple MDIO devices can be connected to the same bus, a bus model is needed.
A GenericPHY
model is implemented to expose the MDIO interface to the MAC models.
The GenericPHY
model can be attached to the EthernetLink
model.
EthernetLink
is responsible for routing EthernetFrames between registered nodes.
It has two routing lists.
Firstly, a list of promiscuous nodes that will receive all messages.
Secondly, a routing map for non-promiscuous nodes.
When the EthernetLink
model receives a frame,
it forwards the frame to all the promiscous nodes.
Then, it routes it to the destination MAC.
The EthernetLink
assumes unique MACs,
thus it will emit a warning in the case of a MAC address collission.
Connecting Devices
An ethernet link must be connected to its attached PHYs.
Connection is done using the connect
command.
ethlink0.connect device=phy0:PHYIface
ethlink0.connect device=phy0:PHYIface
Checksums
Ethernet frames typically have a checksum that is generated and checked by hardware. To optimise the bus model, it is expected that MAC models supports opt in control on checksum generation and checking. This applies to all checksums, including Ethernet frame CRCs and IP header, TCP, UDP checksums. Since the Ethernet link is fully virtual, data cannot normally be corrupted in transit. Thus checksum checking and generation would be a waste of cycles.
There are still several usecases where one want to enable checksums:
-
When viewing capture files with Wireshark, the tool will complain if ethernet CRCs are invalid.
-
When receiving frames in a device which do not have hardware assisted CRC checking.
Thus, normally Ethernet CRC generation and checking will be disabled, while TCP/UDP/IP checksum generation (but not hardware checking) will be enabled.
Auto Negotiation
The ethernet model supports autonegotiation for transfer speed capabilities.
The process is based on issuing an auto-negotiation request to the ethernet link model.
The link will then issue auto-negotiation requests to each attached PHY,
and finally call autonegotiateDone
for all attached PHYs.
Each PHY will be called with the current known capabilities. It should return the same capabilities with potentially some of them cleared.
The actual final capabilities are reported with autonegotiateDone
.
There, a PHY will select the highest priority common mode. Which by the standard is:
-
40GBASE T FD
-
25GBASE T FD
-
10GBASE T FD
-
5GBASE T FD
-
2.5GBASE T FD
-
1000BASE T FD
-
1000BASE T HD
-
100BASE T2 FD
-
100BASE TX FD
-
100BASE T2 HD
-
100BASE T4
-
100BASE TX HD
-
10BASE T FD
-
10BASE T HD
TEMU does not support emulation of 2.5 GBASE and above at this moment. |
Ethernet Frames
Ethernet frames in TEMU are structs containing a flag field, data and an optional preamble.
The data field is a COW buffer which contains the level 2 ethernet frame data.
The preamble will typically be ignored and not set for most MACs.
However if it is set to somthing non-standard,
a device can indicate this by setting the flag TEMU_ETH_NON_STANDARD_PREAMBLE
.
Ethernet Link
Frame Capture
The ethernet link can be instructed to dump all traffic to a PCAPNG file.
Wireshark may flag frames as having invalid CRCs. To avoid this you can enable CRC generation in the MAC, or turn off checking in Wireshark. |
To enable capture execute the enableCapture command ont he ethernet link.
ethlink0.enableCapture file="foo.pcap"
ethernet-link-enable-capture link=ethlink0 file="foo.pcap"
@EthernetLink Reference
EthernetLink Reference
Properties
Name | Type | Description |
---|---|---|
Class |
*void |
Class object |
Component |
*void |
Pointer to component object if part of component |
LoggingFlags |
uint64_t |
Flags for logging info |
Name |
*char |
Object name |
TimeSource |
*void |
Time source object |
Generic PHY
The GenericPHY
is a PHY / MII device which supports both the MDIO interface
and the PHY interface for sending/receiving ethernet frames.
The GenericPHY
device class by default enables support for BASE10, BASE100
and BASE1000 transfers.
To only enable specific speed modes, the constructor accepts arguments:
-
base10:1
-
base100:1
-
base1000:1
If any of these are set, the unset ones will be disabled.
Thus by default a PHY supports all BASE10, BASE100 and BASE1000 modes. By setting the base10 argument, only BASE10 modes will be supported. By setting base10 and base 100 arguments, only BASE10 and BASE100 will be supported.
At present it is not possible to control the support on a lower level.
@GenericPHY Reference
GenericPHY Reference
Properties
Name | Type | Description |
---|---|---|
Class |
*void |
Class object |
Component |
*void |
Pointer to component object if part of component |
LoggingFlags |
uint64_t |
Flags for logging info |
Name |
*char |
Object name |
TimeSource |
*void |
Time source object |
autoNegAdvertisment |
uint16_t |
Auto negotiation advertisment register |
autoNegotiationExpansion |
uint16_t |
Auto negotiation expansion register |
basicModeConfig |
uint16_t |
Basic mode config register |
basicModeStatus |
uint16_t |
Basic mode status register |
ethernetLink |
temu_IfaceRef/ <unknown> |
Ethernet link. |
linkPartnerAbility |
uint16_t |
Link partner ability register |
macDevice |
temu_IfaceRef/ <unknown> |
MAC device. |
phyID |
[uint16_t; 2] |
Physical ID registers |
MDIO Bus
The MDIO bus distributes MDIO control messages and supports routing of them. The MDIO bus use the same interface as an MDIO device. Thus, if only one MDIO device (e.g. GenericPHY) is available no MDIO bus instance is needed.
@MDIOBus Reference
MDIOBus Reference
Properties
Name | Type | Description |
---|---|---|
Class |
*void |
Class object |
Component |
*void |
Pointer to component object if part of component |
LoggingFlags |
uint64_t |
Flags for logging info |
Name |
*char |
Object name |
TimeSource |
*void |
Time source object |
macDevice |
temu_IfaceRef/ <unknown> |
MAC controller. |
phyDevices |
[temu_IfaceRef; 32]/ <unknown> |
MDIO interface of PHYs. |