Mininet Python API Reference Manual
|
A virtual network node is simply a shell in a network namespace. More...
Public Member Functions | |
def | __init__ (self, name, inNamespace=True, **params) |
def | fdToNode (cls, fd) |
Return node corresponding to given file descriptor. More... | |
def | startShell (self, mnopts=None) |
Start a shell process for running commands. | |
def | mountPrivateDirs (self) |
mount private directories | |
def | unmountPrivateDirs (self) |
mount private directories | |
def | cleanup (self) |
Help python collect its garbage. | |
def | read (self, size=1024) |
Buffered read from node, potentially blocking. More... | |
def | readline (self) |
Buffered readline from node, potentially blocking. More... | |
def | write (self, data) |
Write data to node. More... | |
def | terminate (self) |
Send kill signal to Node and clean up after it. | |
def | stop (self, deleteIntfs=False) |
Stop node. More... | |
def | waitReadable (self, timeoutms=None) |
Wait until node's output is readable. More... | |
def | sendCmd (self, *args, **kwargs) |
Send a command, followed by a command to echo a sentinel, and return without waiting for the command to complete. More... | |
def | sendInt (self, intr=chr(3)) |
Interrupt running command. | |
def | monitor (self, timeoutms=None, findPid=True) |
Monitor and return the output of a command. More... | |
def | waitOutput (self, verbose=False, findPid=True) |
Wait for a command to complete. More... | |
def | cmd (self, *args, **kwargs) |
Send a command, wait for output, and return it. More... | |
def | cmdPrint (self, *args) |
Call cmd and printing its output. More... | |
def | popen (self, *args, **kwargs) |
Return a Popen() object in our namespace. More... | |
def | pexec (self, *args, **kwargs) |
Execute a command using popen. More... | |
def | newPort (self) |
Return the next port number to allocate. | |
def | addIntf (self, intf, port=None, moveIntfFn=moveIntf) |
Add an interface. More... | |
def | delIntf (self, intf) |
Remove interface from Node's known interfaces. More... | |
def | defaultIntf (self) |
Return interface for lowest port. | |
def | intf (self, intf=None) |
Return our interface object with given string name, default intf if name is falsy (None, empty string, etc). More... | |
def | connectionsTo (self, node) |
Return [ intf1, intf2... More... | |
def | deleteIntfs (self, checkName=True) |
Delete all of our interfaces. More... | |
def | setARP (self, ip, mac) |
Add an ARP entry. More... | |
def | setHostRoute (self, ip, intf) |
Add route to host. More... | |
def | setDefaultRoute (self, intf=None) |
Set the default route to go through intf. More... | |
def | setMAC (self, mac, intf=None) |
Set the MAC address for an interface. More... | |
def | setIP (self, ip, prefixLen=8, intf=None, **kwargs) |
Set the IP address for an interface. More... | |
def | IP (self, intf=None) |
Return IP address of a node or specific interface. | |
def | MAC (self, intf=None) |
Return MAC address of a node or specific interface. | |
def | intfIsUp (self, intf=None) |
Check if an interface is up. | |
def | setParam (self, results, method, **param) |
Internal. More... | |
def | config (self, mac=None, ip=None, defaultRoute=None, lo='up', **_params) |
Configure Node according to (optional) More... | |
def | configDefault (self, **moreParams) |
Configure with default parameters. | |
def | linkTo (self, node, link=Link) |
(Deprecated) Link to another node replace with Link( node1, node2) | |
def | intfList (self) |
List of our interfaces sorted by port number. | |
def | intfNames (self) |
The names of our interfaces sorted by port number. | |
def | __repr__ (self) |
More informative string representation. | |
def | __str__ (self) |
Abbreviated string representation. | |
def | checkSetup (cls) |
Make sure our class and superclasses are set up. | |
def | setup (cls) |
Make sure our class dependencies are available. | |
Public Attributes | |
name | |
privateDirs | |
inNamespace | |
waitExited | |
params | |
intfs | |
ports | |
nameToIntf | |
waiting | |
readbuf | |
decoder | |
slave | |
shell | |
stdin | |
stdout | |
pid | |
pollOut | |
execed | |
lastCmd | |
lastPid | |
Static Public Attributes | |
int | portBase = 0 |
dictionary | inToNode = {} |
dictionary | outToNode = {} |
bool | isSetup = False |
A virtual network node is simply a shell in a network namespace.
We communicate with it using pipes.
def mininet.node.Node.__init__ | ( | self, | |
name, | |||
inNamespace = True , |
|||
** | params | ||
) |
name | name of node |
inNamespace | in network namespace? |
privateDirs | list of private directory strings or tuples |
params | Node parameters (see config() for details) |
Reimplemented in mininet.node.IVSSwitch, mininet.node.CPULimitedHost, and mininet.node.UserSwitch.
def mininet.node.Node.addIntf | ( | self, | |
intf, | |||
port = None , |
|||
moveIntfFn = moveIntf |
|||
) |
Add an interface.
intf | interface |
port | port number (optional, typically OpenFlow port number) |
moveIntfFn | function to move interface (optional) |
def mininet.node.Node.cmd | ( | self, | |
* | args, | ||
** | kwargs | ||
) |
Send a command, wait for output, and return it.
cmd | string |
def mininet.node.Node.cmdPrint | ( | self, | |
* | args | ||
) |
Call cmd and printing its output.
cmd | string |
def mininet.node.Node.config | ( | self, | |
mac = None , |
|||
ip = None , |
|||
defaultRoute = None , |
|||
lo = 'up' , |
|||
** | _params | ||
) |
Configure Node according to (optional)
parameters | |
mac | MAC address for default interface |
ip | IP address for default interface |
ifconfig | arbitrary interface configuration Subclasses should override this method and call the parent class's config(**params) |
def mininet.node.Node.connectionsTo | ( | self, | |
node | |||
) |
Return [ intf1, intf2...
] for all intfs that connect self to node.
def mininet.node.Node.deleteIntfs | ( | self, | |
checkName = True |
|||
) |
Delete all of our interfaces.
checkName | only delete interfaces that contain our name |
def mininet.node.Node.delIntf | ( | self, | |
intf | |||
) |
Remove interface from Node's known interfaces.
Note | to fully delete interface, call intf.delete() instead |
def mininet.node.Node.fdToNode | ( | cls, | |
fd | |||
) |
Return node corresponding to given file descriptor.
fd | file descriptor |
def mininet.node.Node.intf | ( | self, | |
intf = None |
|||
) |
Return our interface object with given string name, default intf if name is falsy (None, empty string, etc).
or the input intf arg.
Having this fcn return its arg for Intf objects makes it easier to construct functions with flexible input args for interfaces (those that accept both string names and Intf objects).
def mininet.node.Node.monitor | ( | self, | |
timeoutms = None , |
|||
findPid = True |
|||
) |
Monitor and return the output of a command.
Set self.waiting to False if command has completed.
timeoutms | timeout in ms or None to wait indefinitely |
findPid | look for PID from mnexec -p |
def mininet.node.Node.pexec | ( | self, | |
* | args, | ||
** | kwargs | ||
) |
Execute a command using popen.
def mininet.node.Node.popen | ( | self, | |
* | args, | ||
** | kwargs | ||
) |
Return a Popen() object in our namespace.
args | Popen() args, single list, or string |
kwargs | Popen() keyword args |
Reimplemented in mininet.node.CPULimitedHost.
def mininet.node.Node.read | ( | self, | |
size = 1024 |
|||
) |
Buffered read from node, potentially blocking.
size | maximum number of characters to return |
def mininet.node.Node.readline | ( | self | ) |
Buffered readline from node, potentially blocking.
def mininet.node.Node.sendCmd | ( | self, | |
* | args, | ||
** | kwargs | ||
) |
Send a command, followed by a command to echo a sentinel, and return without waiting for the command to complete.
args | command and arguments, or string |
printPid | print command's PID? (False) |
Reimplemented in mininet.node.Switch.
def mininet.node.Node.setARP | ( | self, | |
ip, | |||
mac | |||
) |
Add an ARP entry.
ip | IP address as string |
mac | MAC address as string |
def mininet.node.Node.setDefaultRoute | ( | self, | |
intf = None |
|||
) |
Set the default route to go through intf.
intf | Intf or {dev <intfname> via <gw-ip> ...} |
def mininet.node.Node.setHostRoute | ( | self, | |
ip, | |||
intf | |||
) |
Add route to host.
ip | IP address as dotted decimal |
intf | string, interface name |
def mininet.node.Node.setIP | ( | self, | |
ip, | |||
prefixLen = 8 , |
|||
intf = None , |
|||
** | kwargs | ||
) |
Set the IP address for an interface.
intf | intf or intf name |
ip | IP address as a string |
prefixLen | prefix length, e.g. 8 for /8 or 16M addrs |
kwargs | any additional arguments for intf.setIP |
def mininet.node.Node.setMAC | ( | self, | |
mac, | |||
intf = None |
|||
) |
Set the MAC address for an interface.
intf | intf or intf name |
mac | MAC address as string |
def mininet.node.Node.setParam | ( | self, | |
results, | |||
method, | |||
** | param | ||
) |
Internal.
method | configure a single parameter |
results | dict of results to update |
method | config method name |
param | arg=value (ignore if value=None) value may also be list or dict |
def mininet.node.Node.stop | ( | self, | |
deleteIntfs = False |
|||
) |
Stop node.
deleteIntfs | delete interfaces? (False) |
Reimplemented in mininet.node.IVSSwitch, mininet.node.OVSSwitch, mininet.node.UserSwitch, mininet.node.Switch, and mininet.nodelib.LinuxBridge.
def mininet.node.Node.waitOutput | ( | self, | |
verbose = False , |
|||
findPid = True |
|||
) |
Wait for a command to complete.
Completion is signaled by a sentinel character, ASCII(127) appearing in the output stream. Wait for the sentinel and return the output, including trailing newline.
verbose | print output interactively |
def mininet.node.Node.waitReadable | ( | self, | |
timeoutms = None |
|||
) |
Wait until node's output is readable.
timeoutms | timeout in ms or None to wait indefinitely. |
def mininet.node.Node.write | ( | self, | |
data | |||
) |
Write data to node.
data | string |