containernet
Spin up and interact with virtual networks using Containernet and Node.js
npm install containernet
This module is a fork of @mafintosh mininet altered to work with Containernet
Usage
var containernet =var cn =var s1 = cnvar d1 = cnvar d2 = cnd1links1d2links1cnstart {consoleconsole// Test connectivityd1}process
API
var cn = containernet([options])
Create a new containernet instance. Options include
clean: false // if true run mn -c firstsudo: true // use sudo if neededsock: '/tmp/mn.sock' // explictly set the .sock file useddebug: false // set to true to enable debug output
If for some reason your containernet instance stops working
you probably wanna try using clean: true
.
cn.start([callback])
Start the containernet network. Usually you call this after defining your hosts, switches and links.
After the network has fully started start
is emitted.
cn.stop([callback])
Stop the containernet network. You should not call any other methods after this.
After the network has fully stopped stop
is emitted.
cn.switches
Array of all created switches.
cn.hosts
Array of all created hosts.
var sw = cn.createSwitch()
Create a new switch
sw.link(other, [options])
Link the switch with another switch or host. Options include:
bandwidth: 10 // use 10mbit linkdelay: '100ms' // 100ms delayloss: 10 // 10% package losshtb: true // use htb
var host = cn.createHost([options])
Create a new host. Options include
image: 'alpine' // docker image to use for the hostcmd: '/bin/bash' // cmd to run on the newly created container
host.ip
The IP address of the host. Populated after the network is started.
host.mac
The MAC address of the host. Populated after the network is started.
host.link(other, [options])
Link the host with another host or switch.
Takes the same options as sw.link
.
host.exec(cmd, [callback])
Execute a docker exec command and return the stream in the callback.
License
MIT