cnet v4.0.4 | |
home topology files command‑line options the core API FAQ download and install |
cnet's Physical LayerThe Physical Layer attempts to deliver data frames between nodes. Frames are delivered along any combination of wide-area-networking (WAN), local-area-networking (LAN), or wireless-local-area-networking (WLAN) links. Each physical link is numbered within each node from 1 to its total number of links. As a special case, link 0 represents a loopback link, and is provided to simply copy a frame immediately from a node's output to input. In general, the Physical Layer will randomly corrupt and drop data frames on all WAN, LAN, or WLAN links, but not on the loopback link or Ethernet segments.
When your protocols wish to transmit a data frame along a link,
they write that frame to the Physical Layer.
On calling the
char myframe[ MAX_MESSAGE_SIZE + MY_OVERHEAD ];
size_t length;
... // prepare frame contents for transmission
length = ... ;
result = CNET_write_physical(1, myframe, &length);
When cnet informs the destination node that a frame has arrived,
the handler for
Of course,
in a simple network with just one WAN connection or one Ethernet segment,
all frames will be transmitted and will arrive on link number
As an aid to debugging protocols,
the function
char myframe[ MAX_MESSAGE_SIZE + MY_OVERHEAD ];
size_t length;
int link;
length = sizeof(myframe);
result = CNET_read_physical(&link, myframe, &length);
... // process frame contents
To provide some sense of realism,
frames (or packets) written to Ethernet links are expected to carry the
address of their destination Network Interface Card (NIC) at the very
beginning of the frame.
cnet provides the data type
cnet interprets the leading Consider the following example function, used to write data to an Ethernet segment:
typedef struct {
CnetNICaddr dest;
CnetNICaddr src;
char type[2];
char data[ETH_MAXDATA];
} ETHERPACKET;
#define LEN_ETHERHEADER (sizeof(ETHERPACKET) - ETH_MAXDATA)
static void write_to_ethernet(CnetNICaddr dest, int link, char *buf, size_t len)
{
ETHERPACKET packet;
short int twobytes;
memcpy(packet.dest, dest, sizeof(CnetNICaddr));
memcpy(packet.src, linkinfo[link].nicaddr, sizeof(CnetNICaddr));
twobytes = len; // type carries the data's true length
memcpy(packet.type, &twobytes, 2);
memcpy(packet.data, buf, len);
len += LEN_ETHERHEADER;
if(len < ETH_MINPACKET) // pad short packets to minimum length
len = ETH_MINPACKET;
CHECK(CNET_write_physical(link, (char *)&packet, &len));
......
}
This function assumes that the data's length is not too long for Ethernet
(
The data's true length is copied into the packet's two-byte
Again, cnet does not enforce (nor understand) the use of
our
Two additional Physical Layer functions are provided to assist in the
debugging of multi-layered protocols.
|