Network Devices

Network devices are the building blocks of a computer network, and each type works at a different layer of the OSI model. This page covers the functions and characteristics of the main devices and the role each of them plays in a network.

Overview of Network Devices

1. Device Classification

Network devices can be classified by the layer of the OSI model in which they operate:

  • Physical layer devices: repeaters, hubs
  • Data link layer devices: bridges, switches
  • Network layer devices: routers
  • Multi-layer devices: gateways

2. Device Functions

Every network device has its own specific function:

  • Signal processing: amplifies, regenerates, and converts signals
  • Data forwarding: forwards data between networks
  • Address resolution: resolves and converts network addresses
  • Protocol conversion: converts between different protocols

Physical Layer Devices

1. Repeater

Description

A repeater is a network device that operates at the physical layer. It amplifies and regenerates signals in order to extend the transmission distance of a network.

Main Functions

  • Signal amplification: amplifies an attenuated signal
  • Signal regeneration: regenerates the digital signal
  • Distance extension: extends the transmission distance of the network
  • Signal shaping: improves signal quality

How It Works

// Repeater structure
typedef struct {
    uint8_t input_port;        // Input port
    uint8_t output_port;       // Output port
    uint32_t signal_strength;  // Signal strength
    uint8_t signal_quality;    // Signal quality
    uint8_t status;            // Device status
} Repeater;

// Repeater functions
typedef struct {
    int (*amplify_signal)(uint8_t* input_signal, uint8_t* output_signal, size_t length);
    int (*regenerate_signal)(uint8_t* input_signal, uint8_t* output_signal, size_t length);
    int (*check_signal_quality)(uint8_t* signal, size_t length);
    int (*get_device_status)(void);
} RepeaterInterface;

// Repeater implementation
typedef struct {
    Repeater device;
    RepeaterInterface interface;
    char device_name[64];
    uint32_t packets_processed;
    uint32_t errors_detected;
} RepeaterImpl;

Characteristics

  • Simplicity: a simple structure with a single function
  • Transparency: transparent to the protocols above
  • Limitation: cannot isolate collision domains
  • Use case: extending the transmission distance of a network

2. Hub

Description

A hub is a multi-port repeater. It connects several network devices and produces a star topology.

Main Functions

  • Multi-port connection: connects several network devices
  • Signal broadcast: broadcasts the signal to every port
  • Collision detection: detects collisions on the network
  • Network extension: extends the size of the network

How It Works

// Hub structure
typedef struct {
    uint8_t port_count;        // Number of ports
    uint8_t active_ports[16];  // Active ports
    uint32_t broadcast_count;   // Broadcast count
    uint32_t collision_count;   // Collision count
    uint8_t hub_type;          // Hub type
} Hub;

// Hub functions
typedef struct {
    int (*broadcast_signal)(uint8_t* signal, size_t length);
    int (*detect_collision)(uint8_t port_id);
    int (*get_port_status)(uint8_t port_id);
    int (*set_port_status)(uint8_t port_id, uint8_t status);
} HubInterface;

// Hub implementation
typedef struct {
    Hub device;
    HubInterface interface;
    char hub_name[64];
    uint32_t total_packets;
    uint32_t total_collisions;
} HubImpl;

Characteristics

  • Shared medium: all ports share the transmission medium
  • Collision domain: the whole hub is one collision domain
  • Broadcast domain: the whole hub is one broadcast domain
  • Performance limit: performance degrades as more devices are attached

1. Bridge

Description

A bridge is a network device that operates at the data link layer. It connects different network segments and forwards and filters frames.

Main Functions

  • Frame forwarding: forwards frames between different segments
  • Frame filtering: filters frames according to the MAC address
  • Collision domain isolation: isolates separate collision domains
  • Learning: learns the mapping from MAC address to port

How It Works

// Bridge structure
typedef struct {
    uint8_t port_count;        // Number of ports
    uint8_t mac_table[256][6]; // MAC address table
    uint8_t port_mapping[256]; // Port mapping
    uint32_t learning_timeout; // Learning timeout
    uint8_t bridge_type;       // Bridge type
} Bridge;

// Bridge functions
typedef struct {
    int (*forward_frame)(const uint8_t* frame, size_t length, uint8_t src_port);
    int (*filter_frame)(const uint8_t* frame, size_t length, uint8_t dest_port);
    int (*learn_mac)(const uint8_t* mac_addr, uint8_t port_id);
    int (*get_mac_table)(uint8_t* mac_table, size_t* table_size);
} BridgeInterface;

// Bridge implementation
typedef struct {
    Bridge device;
    BridgeInterface interface;
    char bridge_name[64];
    uint32_t frames_forwarded;
    uint32_t frames_filtered;
} BridgeImpl;

Characteristics

  • Intelligent forwarding: forwards frames according to the MAC address
  • Collision domain isolation: isolates separate collision domains
  • Learning: learns MAC addresses automatically
  • Filtering: discards frames that are not needed

2. Switch

Description

A switch is a multi-port bridge that processes several frames at the same time, which gives it higher network performance.

Main Functions

  • Parallel processing: processes several frames at the same time
  • Full-duplex communication: supports full-duplex communication
  • VLAN support: supports virtual LANs
  • QoS support: supports quality of service

How It Works

// Switch structure
typedef struct {
    uint8_t port_count;        // Number of ports
    uint8_t vlan_count;        // Number of VLANs
    uint8_t mac_table[1024][6]; // MAC address table
    uint8_t vlan_table[1024];  // VLAN table
    uint32_t buffer_size;      // Buffer size
    uint8_t switch_type;       // Switch type
} Switch;

// Switch functions
typedef struct {
    int (*process_frame)(const uint8_t* frame, size_t length, uint8_t src_port);
    int (*forward_frame)(const uint8_t* frame, size_t length, uint8_t dest_port);
    int (*create_vlan)(uint16_t vlan_id, const char* vlan_name);
    int (*add_port_to_vlan)(uint8_t port_id, uint16_t vlan_id);
    int (*set_qos)(uint8_t port_id, uint8_t qos_level);
} SwitchInterface;

// Switch implementation
typedef struct {
    Switch device;
    SwitchInterface interface;
    char switch_name[64];
    uint32_t total_frames;
    uint32_t broadcast_frames;
    uint32_t unicast_frames;
} SwitchImpl;

Characteristics

  • High performance: supports parallel processing
  • Intelligent forwarding: forwards frames according to the MAC address
  • VLAN support: supports virtual LANs
  • Management: offers a rich set of management features

Network Layer Devices

1. Router

Description

A router is a device that operates at the network layer. It connects different networks and routes and forwards packets.

Main Functions

  • Routing: selects the best path for a packet
  • Packet forwarding: forwards packets between networks
  • Address translation: performs network address translation
  • Protocol conversion: converts between different protocols

How It Works

// Router structure
typedef struct {
    uint8_t interface_count;   // Number of interfaces
    uint32_t routing_table[256][4]; // Routing table
    uint8_t interface_status[16]; // Interface status
    uint32_t packet_count;    // Packet count
    uint8_t router_type;      // Router type
} Router;

// Router functions
typedef struct {
    int (*route_packet)(const uint8_t* packet, size_t length, uint32_t dest_ip);
    int (*forward_packet)(const uint8_t* packet, size_t length, uint8_t interface_id);
    int (*add_route)(uint32_t network, uint32_t mask, uint32_t next_hop);
    int (*remove_route)(uint32_t network, uint32_t mask);
    int (*get_routing_table)(uint32_t* table, size_t* table_size);
} RouterInterface;

// Router implementation
typedef struct {
    Router device;
    RouterInterface interface;
    char router_name[64];
    uint32_t packets_routed;
    uint32_t packets_dropped;
    uint32_t routing_errors;
} RouterImpl;

Characteristics

  • Network isolation: isolates separate networks
  • Routing: provides route selection
  • Protocol support: supports many network protocols
  • Security: provides network security functions

Multi-Layer Devices

1. Gateway

Description

A gateway is a device that operates at several layers. It connects networks of different types and performs protocol conversion.

Main Functions

  • Protocol conversion: converts between different protocols
  • Data format conversion: converts the data format
  • Address translation: performs address translation
  • Security control: provides security control functions

How It Works

// Gateway structure
typedef struct {
    uint8_t protocol_count;    // Number of protocols
    uint8_t supported_protocols[16]; // Supported protocols
    uint32_t conversion_table[256]; // Conversion table
    uint8_t security_level;    // Security level
    uint8_t gateway_type;      // Gateway type
} Gateway;

// Gateway functions
typedef struct {
    int (*convert_protocol)(const uint8_t* data, size_t length, uint8_t src_protocol, uint8_t dest_protocol);
    int (*convert_format)(const uint8_t* data, size_t length, uint8_t src_format, uint8_t dest_format);
    int (*convert_address)(uint32_t src_addr, uint32_t* dest_addr, uint8_t addr_type);
    int (*apply_security)(const uint8_t* data, size_t length, uint8_t security_level);
} GatewayInterface;

// Gateway implementation
typedef struct {
    Gateway device;
    GatewayInterface interface;
    char gateway_name[64];
    uint32_t packets_converted;
    uint32_t security_violations;
    uint32_t conversion_errors;
} GatewayImpl;

Characteristics

  • Protocol conversion: supports conversion between many protocols
  • Format conversion: supports data format conversion
  • Security control: provides security control functions
  • Complex functionality: the function set is complex and the cost is high

Where Devices Sit in the OSI Model

1. Layer Correspondence

DeviceOSI LayerMain FunctionTypical Use
RepeaterPhysical LayerSignal amplification and regenerationExtending the network distance
HubPhysical LayerMulti-port signal broadcastStar topology connections
BridgeData Link LayerFrame forwarding and filteringConnecting different segments
SwitchData Link LayerIntelligent frame forwardingCore device of a LAN
RouterNetwork LayerPacket routing and forwardingConnecting different networks
GatewayMultiple LayersProtocol and format conversionConnecting heterogeneous networks

2. Factors in Choosing a Device

Performance Requirements

  • Transmission rate: choose a device with a rate that matches the needs of the network
  • Processing capacity: choose a device whose processing capacity matches the size of the network
  • Scalability: take future expansion into account

Functional Requirements

  • Protocol support: make sure the device supports the network protocols in use
  • Management features: choose a device with the management features the deployment needs
  • Security features: choose a device with the security features the deployment needs

Cost Factors

  • Purchase cost: take the acquisition cost into account
  • Maintenance cost: take the cost of maintaining and operating the device into account
  • Upgrade cost: take the cost of future upgrades into account

Example Device Configuration

1. Switch Configuration

// Switch configuration structure
typedef struct {
    char hostname[64];         // Hostname
    uint8_t management_ip[4];  // Management IP address
    uint16_t vlan_config[16];  // VLAN configuration
    uint8_t port_config[16];   // Port configuration
    uint8_t qos_config[16];    // QoS configuration
} SwitchConfig;

// Switch configuration function
int configure_switch(SwitchImpl* switch_dev, const SwitchConfig* config) {
    // Set the hostname
    strcpy(switch_dev->device_name, config->hostname);

    // Set the management IP
    memcpy(switch_dev->device.management_ip, config->management_ip, 4);

    // Configure the VLANs
    for (int i = 0; i < 16; i++) {
        if (config->vlan_config[i] != 0) {
            switch_dev->interface.create_vlan(config->vlan_config[i], "VLAN");
        }
    }

    // Configure the ports
    for (int i = 0; i < 16; i++) {
        if (config->port_config[i] != 0) {
            switch_dev->interface.set_qos(i, config->port_config[i]);
        }
    }

    return 0;
}

2. Router Configuration

// Router configuration structure
typedef struct {
    char hostname[64];         // Hostname
    uint8_t interface_ips[16][4]; // Interface IP addresses
    uint32_t routes[64][3];    // Route configuration
    uint8_t routing_protocol;  // Routing protocol
} RouterConfig;

// Router configuration function
int configure_router(RouterImpl* router_dev, const RouterConfig* config) {
    // Set the hostname
    strcpy(router_dev->device_name, config->hostname);

    // Configure the interface IP addresses
    for (int i = 0; i < 16; i++) {
        if (config->interface_ips[i][0] != 0) {
            // Configure the interface IP address
            configure_interface_ip(router_dev, i, config->interface_ips[i]);
        }
    }

    // Configure the routes
    for (int i = 0; i < 64; i++) {
        if (config->routes[i][0] != 0) {
            router_dev->interface.add_route(
                config->routes[i][0],  // Network address
                config->routes[i][1],  // Subnet mask
                config->routes[i][2]   // Next hop
            );
        }
    }

    return 0;
}

Found an issue with this content?

Tell us what could be improved.