基类
即 mininet.node.Node, 表示一个基本的虚拟网络节点,是所有的网络节点的父类。
实现上其实就是在网络名字空间中的一个shell进程,可以通过各种管道进行通信。该类是模块中其他类的根本,其它类都是直接或间接继承。
节点包括名称、是否在网络名字空间、接口、端口等可能的属性。
init
params: Node parameters (see config() for details)"""
# Make sure class actually works
self.checkSetup()
self.name = name
self.inNamespace = inNamespace
# Stash configuration parameters for future reference
self.params = params
self.intfs = {} # dict of port numbers to interfaces
self.ports = {} # dict of interfaces to port numbers
# replace with Port objects, eventually ?
self.nameToIntf = {} # dict of interface names to Intfs
# Make pylint happy
( self.shell, self.execed, self.pid, self.stdin, self.stdout,
self.lastPid, self.lastCmd, self.pollOut ) = (
None, None, None, None, None, None, None, None )
self.waiting = False
self.readbuf = ''
# Start command interpreter shell
self.startShell()初始化函数主要进行参数的初始化,之后通过调用 startShell() 启动一个 shell进程(该进程默认关闭描述符,并从 tty 上分离开来),等待接受传入的命令。句柄被发送给 self.shell 上。
addIntf
添加一个接口(比如 <Intf h1-eth0> )到节点上,如果给定了 port(比如 0 ),则建立端口到接口的映射关系。这个映射关系通过 self.intfs 和 self.ports 两个字典来分别维护。
cmd
该函数能在节点所在的进程shell上执行输入的命令。
config
配置 MAC,IP 或 default Route 信息。
connectionsTo
返回所有从自身连接到给定节点的接口,即 [ intf1, intf2... ]。
Last updated
Was this helpful?