SatCat5
eth_crosslink.cc
1 // Copyright 2024-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 
6 #include <hal_test/eth_crosslink.h>
7 
12 
13 // Workaround to ensure C++11 allocates static constants.
14 // See also: https://stackoverflow.com/questions/8452952/
19 
20 Crosslink::Crosslink(const char* filename, u16 type)
21  : pcap(true)
22  , eth0(&pcap)
23  , eth1(&pcap)
24 {
25  // Crosslink the two interfaces.
26  eth0.connect(&eth1);
27  eth1.connect(&eth0);
28  // Start the PCAP log.
29  pcap.open(satcat5::test::sim_filename(filename, "pcap"), type);
30 }
31 
32 void Crosslink::set_loss_rate(float rate) {
33  eth0.set_loss_rate(rate);
34  eth1.set_loss_rate(rate);
35 }
36 
37 void Crosslink::set_zero_pad(unsigned len) {
38  eth0.set_zero_pad(len);
39  eth1.set_zero_pad(len);
40 }
41 
42 CrosslinkEth::CrosslinkEth(const char* filename)
43  : Crosslink(filename)
44  , net0(MAC0, &eth0, &eth0)
45  , net1(MAC1, &eth1, &eth1)
46 {
47  // Nothing else to initialize
48 }
49 
50 CrosslinkIp::CrosslinkIp(const char* filename)
51  : Crosslink(filename)
52  , net0(MAC0, IP0, &eth0, &eth0, &timer)
53  , net1(MAC1, IP1, &eth1, &eth1, &timer)
54 {
55  // Nothing else to initialize
56 }
57 
58 CrosslinkSpp::CrosslinkSpp(const char* filename)
59  : Crosslink(filename, satcat5::io::LINKTYPE_USER0)
60  , spp0(&eth0, &eth0)
61  , spp1(&eth1, &eth1)
62 {
63  // Nothing else to initialize
64 }
void open(const char *filename, u16 type=LINKTYPE_ETHERNET)
Open the specified file, and optionally specify LinkType.
Definition: file_pcap.cc:285
void set_zero_pad(unsigned len)
Set minimum frame length. Runt frames are zero-padded.
Definition: eth_interface.h:55
void set_loss_rate(float rate)
Set rate for randomized drops of outgoing packets.
void connect(satcat5::test::EthernetInterface *dst)
Crosslink to specified destination object.
std::string sim_filename(const char *pre, const char *ext)
Generate a unique filename for storing unit-test results.
Definition: sim_utils.cc:51
An Ethernet MAC address (with serializable interface).
Definition: eth_header.h:29
IPv4 address is a 32-bit unsigned integer.
Definition: ip_core.h:15