Skip to content

Network Device Plugin

opencode-agent[bot] edited this page May 10, 2026 · 1 revision

Network Device Plugin

Plugin interface for network device drivers that bridges the Plugin system with the network stack.

Overview

The Network Device Plugin (NetPlugin) is a JNode plugin that provides the core networking service infrastructure. It serves as the bridge between the Plugin system, device drivers, and the network protocol stack. The plugin initializes network layer management, registers the network API with the InitialNaming service registry, and starts the packet processing thread.

Key Components

Class/File Location Purpose
NetPlugin net/src/net/org/jnode/net/service/NetPlugin.java Main plugin class extending Plugin, manages network service lifecycle
NetDeviceImpl net/src/net/org/jnode/net/service/NetDeviceImpl.java Wrapper class extending VMNetDevice, bridges JNode Device to Java networking
NetAPIImpl net/src/net/org/jnode/net/service/NetAPIImpl.java Implementation of VMNetAPI, provides device enumeration and address resolution
DefaultNetworkLayerManager net/src/net/org/jnode/net/service/DefaultNetworkLayerManager.java Registry for network protocol layers (IP, ARP, TCP, UDP)

How It Works

Plugin Lifecycle

The NetPlugin extends JNode's Plugin base class and implements the core networking service:

  1. Initialization: During construction, the plugin creates:

    • A DefaultNetworkLayerManager instance that loads network layer extensions
    • A NetAPIImpl instance providing the network API
    • A QueueProcessorThread for asynchronous packet processing
  2. Startup (startPlugin):

    • Binds the NetworkLayerManager to InitialNaming for service discovery
    • Starts the packet processing thread
    • Registers the network API with VMNetUtils
  3. Shutdown (stopPlugin):

    • Unregisters the network API from VMNetUtils
    • Unbinds the NetworkLayerManager from InitialNaming
    • Stops the packet processing thread

Device Abstraction

The NetDeviceImpl class wraps a JNode Device (which implements NetDeviceAPI) and presents it as a VMNetDevice to the standard Java networking API:

public final class NetDeviceImpl extends VMNetDevice {
    private final Device device;
    
    public NetDeviceImpl(Device device) {
        this.device = device;
    }
    
    public String getId() {
        return device.getId();
    }
    
    public Device getDevice() {
        return this.device;
    }
}

Network Layer Management

The DefaultNetworkLayerManager serves as the central registry for protocol layers:

  • Loads network layers from the networkLayers extension point
  • Routes incoming packets to appropriate protocol handlers
  • Manages the packet queue for async processing

Gotchas

  • Packet processing thread: The QueueProcessorThread runs continuously; stopping the plugin requires proper thread termination
  • InitialNaming dependency: Other services depend on the NetworkLayerManager being bound before they can operate
  • Extension point required: The networkLayers extension point must be properly configured for protocol layers to load
  • Device API requirement: Network devices must implement NetDeviceAPI to be recognized by the network stack

Clone this wiki locally