cnet's local area network (LAN) segments

As of version 2.0, cnet supports local-area network (LAN) segments, that can closely follow the specifications of IEEE 802.3 Ethernet segments. Each segment consists of two or more Network Interface Cards (NICs) that connect host nodes, routers, or accesspoints to the segment. Large networks may be constructed by joining multiple LAN segments via gateway nodes and WAN links.

cnet provides access to each NIC's address as a field of the standard linkinfo structure. The CnetNICaddr datatype stores each NIC address as an array of LEN_NICADDR (=6) unsigned characters. cnet also provides the functions CNET_parse_nicaddr and CNET_format_nicaddr to convert between character strings and the CnetNICaddr datatype.

cnet checks and warns if two NIC addresses in a topology files are the same, but does not demand their uniqueness. This permits the development of malicious snooping/sniffing "protocols" that use CNET_set_nicaddr to masquerade as other nodes.

Reading and writing data via LAN segments

It is anticiapted that frames written to LT_LAN links will carry the address of their destination Network Interface Card (NIC) near the beginning of the frame. Consider the following example function to write data to a LAN segment:

typedef struct {
    CnetNICaddr    dest;
    CnetNICaddr    src;
    char           type[2];
    char           data[LAN_MAXDATA];

#define LEN_ETHERHEADER (2*sizeof(CnetNICaddr) + 2*sizeof(char))

void write_to_lan(CnetNICaddr dest, int link, char *buf, size_t length)
    ETHERPACKET    packet;
    short int      twobytes;

    memcpy(packet.dest, dest,                   sizeof(CnetNICaddr));
    memcpy(packet.src,  linkinfo[link].nicaddr, sizeof(CnetNICaddr));

    twobytes = length;           // type carries the data's true length
    memcpy(packet.type, &twobytes, 2);
    memcpy(, buf, length);

    length  += LEN_ETHERHEADER;
    if(length < ETH_MINPACKET)   // pad short packets to minimum length
        length = ETH_MINPACKET;
    CHECK( CNET_write_physical(link, (char *)&packet, &length) );

This simplified function assumes that the data's length is not too long for the LAN (<= LAN_MAXDATA (=1500) bytes). The destination's NIC address is first copied to the destination address field, and the address of the local NIC used is copied to the source address field. Notice that because the CnetNICaddr type is actually an array of characters, we do not use the & operator in the calls to memcpy.

The data's true length is copied into the packet's two-byte type field, and the provided data copied to the packet's data. After ensuring that the packet to be written is at least ETH_MINPACKET (=64) bytes long, the packet is written to the link.

Again, cnet does not enforce (nor understand) the use of our ETHERPACKET data type.


cnet's simulation of IEEE 802.3 Ethernets is reasonable, but not perfect. cnet supports a fixed transmission rate of 10Mbps, a slot-time of 52usecs, broadcast addressing, collision detection, jamming, and binary exponential backoff. It does not support sub-microsecond timing, jitter control, nor multicast addressing. Each segment is considered to be a full 2.5km long, and all nodes on a segment are considered to be equally spaced along the segment.

You are not encouraged to use cnet as a tool to design an Ethernet-based network against explicit capacity carrying objectives.

 cnet v3.3.3, written by
 Last modified: Tue Oct 13 1:07PM 2015