Git Product home page Git Product logo

ethernet's Introduction

Ethernet

Manages ethernet on Nerves based embedded systems, with optional Celluose integration.

Features

  • DHCP, including timeouts and re-acquisition
  • IP4LL/AIPA automatic ethernet address configuration
  • Easy callback-based notification of device state changes

Usage

{:ok, eth0} = Ethernet.start_link interface: "eth0", hostname: "happy"

Options are specified by a keyword list, as follows:

keyword type description
interface string interface to configure (eg "eth0", "en2", "lo0", etc)
hostname string hostname to pass to dhcp server during dhcp request

Config options may be specified by a keyword list for configuration in a config.exs file using the :static_config key. Required keys of list are:

keyword type description
ip string IP address to configure to (e.g. "192.168.15.100")
mask string Subnet Mask to use (e.g. "255.255.255.0")
router string IP address of router (e.g. "192.168.15.1")
config :ethernet, static_config: [
    ip: "192.168.1.10",
    mask: "255.255.0.0",
    router: "192.168.1.1"
    ]

Notifications

Ethernet implements an event manager which provides information about changes in the status of the interface.

For instance, imagine you wanted to implement a handler that wrote the new network configuration to standard output everytime it changed. You could implement it like this:

defmodule NetworkStateInspectionHandler
  use GenEvent
  def handle_event(:if_changed, new_config) do
    IO.write "New configuration: #{inspect new_config}"
  end
end

And then, you could start the interface and add the handler like this..

{:ok, eth0} = Ethernet.start_link interface: "eth0", hostname: "happy"
GenEvent.add_handler(eth0, NetworkStateInspectionHandler, [])

Static IP Configuration Storage

Ethernet is capable of storing static configuration values, provided a module is implemented following the Ethernet.Storage Behaviour. It is up to the implementer to determine how this should be accomplished. An example of using cellulose/persistent_storage project is provided in the /examples directory.

To utilize your module just specify it in your config:

config :ethernet, storage: EthernetPersistentStorage

Or when you start Ethernet just pass it with the key :storage:

Ethernet.start storage: EthernetPersistentStorage

Areas For Improvement

  • needs a lot better AIPA/IP4LL address negotiation

Examples

    # Start Ethernet using dhcp and calling back to AIPA/ipv4ll

    #config.exs
    config :ethernet, interface: "eth2", hostname: "bbb"

    # starting...
    iex> Ethernet.start

    # Start Ethernet with static configuration

    #config.exs
    config :ethernet, interface: "eth2", hostname: "bbb", static_config: [
      ip: "192.168.1.100", mask: "255.255.255.0", router: "192.168.1.1"
    ]

    # starting...
    iex> Ethernet.start

Contributing

We appreciate any contribution to Cellulose Projects, so check out our CONTRIBUTING.md guide for more information. We usually keep a list of features and bugs in the issue tracker.

ethernet's People

Contributors

ghitchens avatar captchrisd avatar

Stargazers

 avatar Sandy Taylor avatar Richard.L avatar  avatar Kevin Old avatar Cody Krieger avatar

Watchers

Frank Hunleth avatar  avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.