Class NetworkService

All Implemented Interfaces:
CtxEventListener, BinaryMsgIfaceFactory, ContextHandleAware, HandleAware, Ready, ReadyAndReadyListener, ReadyListener

public final class NetworkService extends AbstractService implements BinaryMsgIfaceFactory
Service that configures network interfaces on nodes within the device. This typically operates on a networkMgr from the local node, but in some device configurations, may provide access to network configuration of multiple nodes.
Version:
2024-05-23
  • Method Details

    • getInterfaces

      public List<NetworkInterface> getInterfaces() throws IOException
      Return the list of available network interfaces on the current node.
      Throws:
      IOException
    • getInterfaceDetails

      public NetworkInterfaceDetails getInterfaceDetails(String name) throws IOException
      Return the details for the specified network interface on the current node.
      Parameters:
      name - the interface name
      Throws:
      IOException
    • getAllInterfaceDetails

      public List<NetworkInterfaceDetails> getAllInterfaceDetails() throws IOException
      Return the details for all available interfaces.
      Throws:
      IOException
    • watchInterface

      public NetworkInterfaceWatch watchInterface(String name, NetworkInterfaceWatch.Callback callback) throws IOException
      Register for state changes on an interface on the current node. Returns watch object that will receive events and can be used to unwatch.
      Parameters:
      name - name of the interface to monitor
      callback - callback to process network interface events
      Returns:
      watch object that will receive events
      Throws:
      IOException
    • getInterfaceAssociations

      public NetworkInterfaceAssociations getInterfaceAssociations() throws IOException
      Return interface names be category association for the current node.
      Throws:
      IOException
    • enableInterface

      public void enableInterface(String name, boolean enable) throws IOException
      Set the specified interface enabled or not on the current node. This does not change the configuration of the interface, it merely brings it up or down.
      Parameters:
      name - the interface name
      enable - true to enable, false to disable
      Throws:
      IOException
    • isRadioEnabled

      public boolean isRadioEnabled() throws IOException
      Return true if the radio is enabled on this node, false if it is not. This is a global setting and not per-interface. Querying immediately after changing the value may return an incorrect value.
      Throws:
      IOException
    • enableRadio

      public void enableRadio(boolean enable) throws IOException
      Enable / disable the radio on this node. This is a global setting and not per-interface.
      Parameters:
      enable - true to enable, false to disable
      Throws:
      IOException
    • getAccessPoints

      public List<WifiDetails> getAccessPoints(String name) throws IOException
      Return the list of previously detected access points on the specified interface on this node.
      Parameters:
      name - the name of the interface
      Throws:
      IOException
    • scanAccessPoints

      public void scanAccessPoints(String name) throws IOException
      Perform a scan of available wifi access points visible from the specified network interface on this node. Network manager will periodically scan for access points, but this triggers a new scan. This is asynchronous and an interface watcher can be used to detect "access-point-added" events to identify new access points.
      Parameters:
      name - the name of the interface
      Throws:
      IOException
    • ping

      public PingResponse ping(String hostname) throws IOException
      Ping the specified hostname from this node. This will perform three pings and return the results.
      Parameters:
      hostname - the hostname or address to ping
      Returns:
      Statistics for the ping
      Throws:
      IOException
    • ping

      public PingResponse ping(PingRequest request) throws IOException
      Perform a ping from this node using the specified ping settings.
      Parameters:
      request - the settings for the ping operation
      Returns:
      Statistics for the ping
      Throws:
      IOException
    • getInterfaces

      public List<NetworkInterface> getInterfaces(NodeId nodeId) throws IOException
      Return the list of available network interfaces.
      Parameters:
      nodeId - the node to operate on
      Throws:
      IOException
    • getInterfaceDetails

      public NetworkInterfaceDetails getInterfaceDetails(NodeId nodeId, String name) throws IOException
      Return the details for the specified network interface.
      Parameters:
      nodeId - the node to operate on
      name - the interface name
      Throws:
      IOException
    • getAllInterfaceDetails

      public List<NetworkInterfaceDetails> getAllInterfaceDetails(NodeId nodeId) throws IOException
      Return details for all available network interfaces.
      Parameters:
      nodeId - the node to operate on
      Throws:
      IOException
    • watchInterface

      public NetworkInterfaceWatch watchInterface(NodeId nodeId, String name, NetworkInterfaceWatch.Callback callback) throws IOException
      Register for state changes on an interface. Returns watch object that will receive events and can be used to unwatch. A watch on a remote node will survive across reboots of that node and will be re-watched when the node reconnects.
      Parameters:
      nodeId - the node to operate on
      name - name of the interface to monitor
      callback - callback to process network interface events
      Returns:
      watch object that will receive events
      Throws:
      IOException
    • unwatchInterface

      public void unwatchInterface(NetworkInterfaceWatch watch) throws IOException
      Unregister an existing interface watch so it will receive no more events.
      Parameters:
      watch - the watch returned when it was registered
      Throws:
      IOException
    • getInterfaceAssociations

      public NetworkInterfaceAssociations getInterfaceAssociations(NodeId nodeId) throws IOException
      Return interface names be category association.
      Parameters:
      nodeId - the node to operate on
      Throws:
      IOException
    • enableInterface

      public void enableInterface(NodeId nodeId, String name, boolean enable) throws IOException
      Set the specified interface enabled or not. This does not change the configuration of the interface, it merely brings it up or down.
      Parameters:
      nodeId - the node to operate on
      name - the interface name
      enable - true to enable, false to disable
      Throws:
      IOException
    • isRadioEnabled

      public boolean isRadioEnabled(NodeId nodeId) throws IOException
      Return true if the radio is enabled on the specified node, false if it is not. This is a global setting and not per-interface. Querying immediately after changing the value may return an incorrect value.
      Parameters:
      nodeId - the node to operate on
      Throws:
      IOException
    • enableRadio

      public void enableRadio(NodeId nodeId, boolean enable) throws IOException
      Enable / disable the radio on this node. This is a global setting and not per-interface.
      Parameters:
      nodeId - the node to operate on
      enable - true to enable, false to disable
      Throws:
      IOException
    • getAccessPoints

      public List<WifiDetails> getAccessPoints(NodeId nodeId, String name) throws IOException
      Return the list of previously detected access points on the specified interface on the specified node.
      Parameters:
      nodeId - the node to operate on
      name - the name of the interface
      Throws:
      IOException
    • scanAccessPoints

      public void scanAccessPoints(NodeId nodeId, String name) throws IOException
      Perform a scan of available wifi access points visible from the specified network interface on the specified node. Network manager will periodically scan for access points, but this triggers a new scan. This is asynchronous and an interface watcher can be used to detect "access-point-added" events to identify new access points.
      Parameters:
      nodeId - the node to operate on
      name - the name of the interface
      Throws:
      IOException
    • ping

      public PingResponse ping(NodeId nodeId, String hostname) throws IOException
      Ping the specified hostname from the specified node. This will perform three pings and return the results.
      Parameters:
      nodeId - the node to operate on
      hostname - the hostname or address to ping
      Returns:
      Statistics for the ping
      Throws:
      IOException
    • ping

      public PingResponse ping(NodeId nodeId, PingRequest request) throws IOException
      Perform a ping from the specified node using the specified ping settings.
      Parameters:
      nodeId - the node to operate on
      request - the settings for the ping operation
      Returns:
      Statistics for the ping
      Throws:
      IOException
    • getIface

      public BinaryMsgIface getIface(String name, BinaryMsgSession session)
      Description copied from interface: BinaryMsgIfaceFactory
      Given the name of an interface from a BinaryMsgSession, return an instance of BinaryMsgIface or null.
      Specified by:
      getIface in interface BinaryMsgIfaceFactory
      Parameters:
      name - the name of the interface
      session - the session to back the interface
      Returns:
      the iface or null