removed rtype and param typing from doc strings to help avoid maintaining duplicate information provided by type hints
This commit is contained in:
parent
9d89877b20
commit
f4ddf310a8
32 changed files with 1091 additions and 1357 deletions
|
@ -45,11 +45,11 @@ class NodeBase:
|
|||
"""
|
||||
Creates a NodeBase instance.
|
||||
|
||||
:param core.emulator.session.Session session: CORE session object
|
||||
:param int _id: id
|
||||
:param str name: object name
|
||||
:param bool start: start value
|
||||
:param core.emulator.distributed.DistributedServer server: remote server node
|
||||
:param session: CORE session object
|
||||
:param _id: id
|
||||
:param name: object name
|
||||
:param start: start value
|
||||
:param server: remote server node
|
||||
will run on, default is None for localhost
|
||||
"""
|
||||
|
||||
|
@ -102,14 +102,13 @@ class NodeBase:
|
|||
"""
|
||||
Runs a command on the host system or distributed server.
|
||||
|
||||
:param str args: command to run
|
||||
:param dict env: environment to run command with
|
||||
:param str cwd: directory to run command in
|
||||
:param bool wait: True to wait for status, False otherwise
|
||||
:param bool shell: True to use shell, False otherwise
|
||||
:param args: command to run
|
||||
:param env: environment to run command with
|
||||
:param cwd: directory to run command in
|
||||
:param wait: True to wait for status, False otherwise
|
||||
:param shell: True to use shell, False otherwise
|
||||
:return: combined stdout and stderr
|
||||
:rtype: str
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
if self.server is None:
|
||||
return utils.cmd(args, env, cwd, wait, shell)
|
||||
|
@ -120,12 +119,11 @@ class NodeBase:
|
|||
"""
|
||||
Set the (x,y,z) position of the object.
|
||||
|
||||
:param float x: x position
|
||||
:param float y: y position
|
||||
:param float z: z position
|
||||
:param x: x position
|
||||
:param y: y position
|
||||
:param z: z position
|
||||
:return: True if position changed, False otherwise
|
||||
:rtype: bool
|
||||
"""
|
||||
"""
|
||||
return self.position.set(x=x, y=y, z=z)
|
||||
|
||||
def getposition(self) -> Tuple[float, float, float]:
|
||||
|
@ -133,28 +131,25 @@ class NodeBase:
|
|||
Return an (x,y,z) tuple representing this object's position.
|
||||
|
||||
:return: x,y,z position tuple
|
||||
:rtype: tuple
|
||||
"""
|
||||
"""
|
||||
return self.position.get()
|
||||
|
||||
def ifname(self, ifindex: int) -> str:
|
||||
"""
|
||||
Retrieve interface name for index.
|
||||
|
||||
:param int ifindex: interface index
|
||||
:param ifindex: interface index
|
||||
:return: interface name
|
||||
:rtype: str
|
||||
"""
|
||||
"""
|
||||
return self._netif[ifindex].name
|
||||
|
||||
def netifs(self, sort: bool = False) -> List[CoreInterface]:
|
||||
"""
|
||||
Retrieve network interfaces, sorted if desired.
|
||||
|
||||
:param bool sort: boolean used to determine if interfaces should be sorted
|
||||
:param sort: boolean used to determine if interfaces should be sorted
|
||||
:return: network interfaces
|
||||
:rtype: list[core.nodes.interfaces.CoreInterface]
|
||||
"""
|
||||
"""
|
||||
if sort:
|
||||
return [self._netif[x] for x in sorted(self._netif)]
|
||||
else:
|
||||
|
@ -165,18 +160,16 @@ class NodeBase:
|
|||
Return the attached interface count.
|
||||
|
||||
:return: number of network interfaces
|
||||
:rtype: int
|
||||
"""
|
||||
"""
|
||||
return len(self._netif)
|
||||
|
||||
def getifindex(self, netif: CoreInterface) -> int:
|
||||
"""
|
||||
Retrieve index for an interface.
|
||||
|
||||
:param core.nodes.interface.CoreInterface netif: interface to get index for
|
||||
:param netif: interface to get index for
|
||||
:return: interface index if found, -1 otherwise
|
||||
:rtype: int
|
||||
"""
|
||||
"""
|
||||
for ifindex in self._netif:
|
||||
if self._netif[ifindex] is netif:
|
||||
return ifindex
|
||||
|
@ -187,8 +180,7 @@ class NodeBase:
|
|||
Create a new interface index.
|
||||
|
||||
:return: interface index
|
||||
:rtype: int
|
||||
"""
|
||||
"""
|
||||
while self.ifindex in self._netif:
|
||||
self.ifindex += 1
|
||||
ifindex = self.ifindex
|
||||
|
@ -207,13 +199,12 @@ class NodeBase:
|
|||
Build a data object for this node.
|
||||
|
||||
:param message_type: purpose for the data object we are creating
|
||||
:param str lat: latitude
|
||||
:param str lon: longitude
|
||||
:param str alt: altitude
|
||||
:param str source: source of node data
|
||||
:param lat: latitude
|
||||
:param lon: longitude
|
||||
:param alt: altitude
|
||||
:param source: source of node data
|
||||
:return: node data object
|
||||
:rtype: core.emulator.data.NodeData
|
||||
"""
|
||||
"""
|
||||
if self.apitype is None:
|
||||
return None
|
||||
|
||||
|
@ -257,8 +248,7 @@ class NodeBase:
|
|||
|
||||
:param flags: message flags
|
||||
:return: list of link data
|
||||
:rtype: list[core.data.LinkData]
|
||||
"""
|
||||
"""
|
||||
return []
|
||||
|
||||
|
||||
|
@ -278,11 +268,11 @@ class CoreNodeBase(NodeBase):
|
|||
"""
|
||||
Create a CoreNodeBase instance.
|
||||
|
||||
:param core.emulator.session.Session session: CORE session object
|
||||
:param int _id: object id
|
||||
:param str name: object name
|
||||
:param bool start: boolean for starting
|
||||
:param core.emulator.distributed.DistributedServer server: remote server node
|
||||
:param session: CORE session object
|
||||
:param _id: object id
|
||||
:param name: object name
|
||||
:param start: boolean for starting
|
||||
:param server: remote server node
|
||||
will run on, default is None for localhost
|
||||
"""
|
||||
super().__init__(session, _id, name, start, server)
|
||||
|
@ -320,8 +310,8 @@ class CoreNodeBase(NodeBase):
|
|||
"""
|
||||
Add network interface to node and set the network interface index if successful.
|
||||
|
||||
:param core.nodes.interface.CoreInterface netif: network interface to add
|
||||
:param int ifindex: interface index
|
||||
:param netif: network interface to add
|
||||
:param ifindex: interface index
|
||||
:return: nothing
|
||||
"""
|
||||
if ifindex in self._netif:
|
||||
|
@ -333,7 +323,7 @@ class CoreNodeBase(NodeBase):
|
|||
"""
|
||||
Delete a network interface
|
||||
|
||||
:param int ifindex: interface index to delete
|
||||
:param ifindex: interface index to delete
|
||||
:return: nothing
|
||||
"""
|
||||
if ifindex not in self._netif:
|
||||
|
@ -346,10 +336,9 @@ class CoreNodeBase(NodeBase):
|
|||
"""
|
||||
Retrieve network interface.
|
||||
|
||||
:param int ifindex: index of interface to retrieve
|
||||
:param ifindex: index of interface to retrieve
|
||||
:return: network interface, or None if not found
|
||||
:rtype: core.nodes.interface.CoreInterface
|
||||
"""
|
||||
"""
|
||||
if ifindex in self._netif:
|
||||
return self._netif[ifindex]
|
||||
else:
|
||||
|
@ -359,8 +348,8 @@ class CoreNodeBase(NodeBase):
|
|||
"""
|
||||
Attach a network.
|
||||
|
||||
:param int ifindex: interface of index to attach
|
||||
:param core.nodes.base.CoreNetworkBase net: network to attach
|
||||
:param ifindex: interface of index to attach
|
||||
:param net: network to attach
|
||||
:return: nothing
|
||||
"""
|
||||
if ifindex not in self._netif:
|
||||
|
@ -371,7 +360,7 @@ class CoreNodeBase(NodeBase):
|
|||
"""
|
||||
Detach network interface.
|
||||
|
||||
:param int ifindex: interface index to detach
|
||||
:param ifindex: interface index to detach
|
||||
:return: nothing
|
||||
"""
|
||||
if ifindex not in self._netif:
|
||||
|
@ -403,8 +392,7 @@ class CoreNodeBase(NodeBase):
|
|||
:param obj: object to get common network with
|
||||
:param want_ctrl: flag set to determine if control network are wanted
|
||||
:return: tuples of common networks
|
||||
:rtype: list
|
||||
"""
|
||||
"""
|
||||
common = []
|
||||
for netif1 in self.netifs():
|
||||
if not want_ctrl and hasattr(netif1, "control"):
|
||||
|
@ -418,12 +406,11 @@ class CoreNodeBase(NodeBase):
|
|||
"""
|
||||
Runs a command within a node container.
|
||||
|
||||
:param str args: command to run
|
||||
:param bool wait: True to wait for status, False otherwise
|
||||
:param bool shell: True to use shell, False otherwise
|
||||
:param args: command to run
|
||||
:param wait: True to wait for status, False otherwise
|
||||
:param shell: True to use shell, False otherwise
|
||||
:return: combined stdout and stderr
|
||||
:rtype: str
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
@ -431,7 +418,7 @@ class CoreNodeBase(NodeBase):
|
|||
"""
|
||||
Create a terminal command string.
|
||||
|
||||
:param str sh: shell to execute command in
|
||||
:param sh: shell to execute command in
|
||||
:return: str
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
@ -458,13 +445,13 @@ class CoreNode(CoreNodeBase):
|
|||
"""
|
||||
Create a CoreNode instance.
|
||||
|
||||
:param core.emulator.session.Session session: core session instance
|
||||
:param int _id: object id
|
||||
:param str name: object name
|
||||
:param str nodedir: node directory
|
||||
:param str bootsh: boot shell to use
|
||||
:param bool start: start flag
|
||||
:param core.emulator.distributed.DistributedServer server: remote server node
|
||||
:param session: core session instance
|
||||
:param _id: object id
|
||||
:param name: object name
|
||||
:param nodedir: node directory
|
||||
:param bootsh: boot shell to use
|
||||
:param start: start flag
|
||||
:param server: remote server node
|
||||
will run on, default is None for localhost
|
||||
"""
|
||||
super().__init__(session, _id, name, start, server)
|
||||
|
@ -490,7 +477,7 @@ class CoreNode(CoreNodeBase):
|
|||
Create node network client for running network commands within the nodes
|
||||
container.
|
||||
|
||||
:param bool use_ovs: True for OVS bridges, False for Linux bridges
|
||||
:param use_ovs: True for OVS bridges, False for Linux bridges
|
||||
:return: node network client
|
||||
"""
|
||||
return get_net_client(use_ovs, self.cmd)
|
||||
|
@ -500,8 +487,7 @@ class CoreNode(CoreNodeBase):
|
|||
Check if the node is alive.
|
||||
|
||||
:return: True if node is alive, False otherwise
|
||||
:rtype: bool
|
||||
"""
|
||||
"""
|
||||
try:
|
||||
self.host_cmd(f"kill -0 {self.pid}")
|
||||
except CoreCommandError:
|
||||
|
@ -601,12 +587,11 @@ class CoreNode(CoreNodeBase):
|
|||
Runs a command that is used to configure and setup the network within a
|
||||
node.
|
||||
|
||||
:param str args: command to run
|
||||
:param bool wait: True to wait for status, False otherwise
|
||||
:param bool shell: True to use shell, False otherwise
|
||||
:param args: command to run
|
||||
:param wait: True to wait for status, False otherwise
|
||||
:param shell: True to use shell, False otherwise
|
||||
:return: combined stdout and stderr
|
||||
:rtype: str
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
if self.server is None:
|
||||
return self.client.check_cmd(args, wait=wait, shell=shell)
|
||||
|
@ -618,7 +603,7 @@ class CoreNode(CoreNodeBase):
|
|||
"""
|
||||
Create a terminal command string.
|
||||
|
||||
:param str sh: shell to execute command in
|
||||
:param sh: shell to execute command in
|
||||
:return: str
|
||||
"""
|
||||
terminal = self.client.create_cmd(sh)
|
||||
|
@ -631,7 +616,7 @@ class CoreNode(CoreNodeBase):
|
|||
"""
|
||||
Create a private directory.
|
||||
|
||||
:param str path: path to create
|
||||
:param path: path to create
|
||||
:return: nothing
|
||||
"""
|
||||
if path[0] != "/":
|
||||
|
@ -646,8 +631,8 @@ class CoreNode(CoreNodeBase):
|
|||
"""
|
||||
Create and mount a directory.
|
||||
|
||||
:param str source: source directory to mount
|
||||
:param str target: target directory to create
|
||||
:param source: source directory to mount
|
||||
:param target: target directory to create
|
||||
:return: nothing
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
|
@ -662,8 +647,7 @@ class CoreNode(CoreNodeBase):
|
|||
Retrieve a new interface index.
|
||||
|
||||
:return: new interface index
|
||||
:rtype: int
|
||||
"""
|
||||
"""
|
||||
with self.lock:
|
||||
return super().newifindex()
|
||||
|
||||
|
@ -671,8 +655,8 @@ class CoreNode(CoreNodeBase):
|
|||
"""
|
||||
Create a new interface.
|
||||
|
||||
:param int ifindex: index for the new interface
|
||||
:param str ifname: name for the new interface
|
||||
:param ifindex: index for the new interface
|
||||
:param ifname: name for the new interface
|
||||
:return: nothing
|
||||
"""
|
||||
with self.lock:
|
||||
|
@ -728,11 +712,10 @@ class CoreNode(CoreNodeBase):
|
|||
"""
|
||||
Create a new tunnel tap.
|
||||
|
||||
:param int ifindex: interface index
|
||||
:param str ifname: interface name
|
||||
:param ifindex: interface index
|
||||
:param ifname: interface name
|
||||
:return: interface index
|
||||
:rtype: int
|
||||
"""
|
||||
"""
|
||||
with self.lock:
|
||||
if ifindex is None:
|
||||
ifindex = self.newifindex()
|
||||
|
@ -758,8 +741,8 @@ class CoreNode(CoreNodeBase):
|
|||
"""
|
||||
Set hardware addres for an interface.
|
||||
|
||||
:param int ifindex: index of interface to set hardware address for
|
||||
:param str addr: hardware address to set
|
||||
:param ifindex: index of interface to set hardware address for
|
||||
:param addr: hardware address to set
|
||||
:return: nothing
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
|
@ -773,8 +756,8 @@ class CoreNode(CoreNodeBase):
|
|||
"""
|
||||
Add interface address.
|
||||
|
||||
:param int ifindex: index of interface to add address to
|
||||
:param str addr: address to add to interface
|
||||
:param ifindex: index of interface to add address to
|
||||
:param addr: address to add to interface
|
||||
:return: nothing
|
||||
"""
|
||||
addr = utils.validate_ip(addr)
|
||||
|
@ -791,8 +774,8 @@ class CoreNode(CoreNodeBase):
|
|||
"""
|
||||
Delete address from an interface.
|
||||
|
||||
:param int ifindex: index of interface to delete address from
|
||||
:param str addr: address to delete from interface
|
||||
:param ifindex: index of interface to delete address from
|
||||
:param addr: address to delete from interface
|
||||
:return: nothing
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
|
@ -810,7 +793,7 @@ class CoreNode(CoreNodeBase):
|
|||
"""
|
||||
Bring an interface up.
|
||||
|
||||
:param int ifindex: index of interface to bring up
|
||||
:param ifindex: index of interface to bring up
|
||||
:return: nothing
|
||||
"""
|
||||
if self.up:
|
||||
|
@ -828,14 +811,13 @@ class CoreNode(CoreNodeBase):
|
|||
"""
|
||||
Create a new network interface.
|
||||
|
||||
:param core.nodes.base.CoreNetworkBase net: network to associate with
|
||||
:param list addrlist: addresses to add on the interface
|
||||
:param str hwaddr: hardware address to set for interface
|
||||
:param int ifindex: index of interface to create
|
||||
:param str ifname: name for interface
|
||||
:param net: network to associate with
|
||||
:param addrlist: addresses to add on the interface
|
||||
:param hwaddr: hardware address to set for interface
|
||||
:param ifindex: index of interface to create
|
||||
:param ifname: name for interface
|
||||
:return: interface index
|
||||
:rtype: int
|
||||
"""
|
||||
"""
|
||||
if not addrlist:
|
||||
addrlist = []
|
||||
|
||||
|
@ -872,8 +854,8 @@ class CoreNode(CoreNodeBase):
|
|||
"""
|
||||
Add a file.
|
||||
|
||||
:param str srcname: source file name
|
||||
:param str filename: file name to add
|
||||
:param srcname: source file name
|
||||
:param filename: file name to add
|
||||
:return: nothing
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
|
@ -891,7 +873,7 @@ class CoreNode(CoreNodeBase):
|
|||
"""
|
||||
Return the name of a node"s file on the host filesystem.
|
||||
|
||||
:param str filename: host file name
|
||||
:param filename: host file name
|
||||
:return: path to file
|
||||
"""
|
||||
dirname, basename = os.path.split(filename)
|
||||
|
@ -907,9 +889,9 @@ class CoreNode(CoreNodeBase):
|
|||
"""
|
||||
Create a node file with a given mode.
|
||||
|
||||
:param str filename: name of file to create
|
||||
:param str contents: contents of file
|
||||
:param int mode: mode for file
|
||||
:param filename: name of file to create
|
||||
:param contents: contents of file
|
||||
:param mode: mode for file
|
||||
:return: nothing
|
||||
"""
|
||||
hostfilename = self.hostfilename(filename)
|
||||
|
@ -933,9 +915,9 @@ class CoreNode(CoreNodeBase):
|
|||
Copy a file to a node, following symlinks and preserving metadata.
|
||||
Change file mode if specified.
|
||||
|
||||
:param str filename: file name to copy file to
|
||||
:param str srcfilename: file to copy
|
||||
:param int mode: mode to copy to
|
||||
:param filename: file name to copy file to
|
||||
:param srcfilename: file to copy
|
||||
:param mode: mode to copy to
|
||||
:return: nothing
|
||||
"""
|
||||
hostfilename = self.hostfilename(filename)
|
||||
|
@ -969,11 +951,11 @@ class CoreNetworkBase(NodeBase):
|
|||
"""
|
||||
Create a CoreNetworkBase instance.
|
||||
|
||||
:param core.emulator.session.Session session: CORE session object
|
||||
:param int _id: object id
|
||||
:param str name: object name
|
||||
:param bool start: should object start
|
||||
:param core.emulator.distributed.DistributedServer server: remote server node
|
||||
:param session: CORE session object
|
||||
:param _id: object id
|
||||
:param name: object name
|
||||
:param start: should object start
|
||||
:param server: remote server node
|
||||
will run on, default is None for localhost
|
||||
"""
|
||||
super().__init__(session, _id, name, start, server)
|
||||
|
@ -1000,20 +982,18 @@ class CoreNetworkBase(NodeBase):
|
|||
"""
|
||||
Link network to another.
|
||||
|
||||
:param core.nodes.base.CoreNetworkBase net: network to link with
|
||||
:param net: network to link with
|
||||
:return: created interface
|
||||
:rtype: core.nodes.interface.Veth
|
||||
"""
|
||||
"""
|
||||
pass
|
||||
|
||||
def getlinknetif(self, net: "CoreNetworkBase") -> CoreInterface:
|
||||
"""
|
||||
Return the interface of that links this net with another net.
|
||||
|
||||
:param core.nodes.base.CoreNetworkBase net: interface to get link for
|
||||
:param net: interface to get link for
|
||||
:return: interface the provided network is linked to
|
||||
:rtype: core.nodes.interface.CoreInterface
|
||||
"""
|
||||
"""
|
||||
for netif in self.netifs():
|
||||
if hasattr(netif, "othernet") and netif.othernet == net:
|
||||
return netif
|
||||
|
@ -1023,7 +1003,7 @@ class CoreNetworkBase(NodeBase):
|
|||
"""
|
||||
Attach network interface.
|
||||
|
||||
:param core.nodes.interface.CoreInterface netif: network interface to attach
|
||||
:param netif: network interface to attach
|
||||
:return: nothing
|
||||
"""
|
||||
i = self.newifindex()
|
||||
|
@ -1036,7 +1016,7 @@ class CoreNetworkBase(NodeBase):
|
|||
"""
|
||||
Detach network interface.
|
||||
|
||||
:param core.nodes.interface.CoreInterface netif: network interface to detach
|
||||
:param netif: network interface to detach
|
||||
:return: nothing
|
||||
"""
|
||||
del self._netif[netif.netifi]
|
||||
|
@ -1049,10 +1029,9 @@ class CoreNetworkBase(NodeBase):
|
|||
Build link data objects for this network. Each link object describes a link
|
||||
between this network and a node.
|
||||
|
||||
:param int flags: message type
|
||||
:param flags: message type
|
||||
:return: list of link data
|
||||
:rtype: list[core.data.LinkData]
|
||||
"""
|
||||
"""
|
||||
all_links = []
|
||||
|
||||
# build a link message from this network node to each node having a
|
||||
|
@ -1159,12 +1138,11 @@ class Position:
|
|||
"""
|
||||
Returns True if the position has actually changed.
|
||||
|
||||
:param float x: x position
|
||||
:param float y: y position
|
||||
:param float z: z position
|
||||
:param x: x position
|
||||
:param y: y position
|
||||
:param z: z position
|
||||
:return: True if position changed, False otherwise
|
||||
:rtype: bool
|
||||
"""
|
||||
"""
|
||||
if self.x == x and self.y == y and self.z == z:
|
||||
return False
|
||||
self.x = x
|
||||
|
@ -1177,6 +1155,5 @@ class Position:
|
|||
Retrieve x,y,z position.
|
||||
|
||||
:return: x,y,z position tuple
|
||||
:rtype: tuple
|
||||
"""
|
||||
"""
|
||||
return self.x, self.y, self.z
|
||||
|
|
|
@ -17,8 +17,8 @@ class VnodeClient:
|
|||
"""
|
||||
Create a VnodeClient instance.
|
||||
|
||||
:param str name: name for client
|
||||
:param str ctrlchnlname: control channel name
|
||||
:param name: name for client
|
||||
:param ctrlchnlname: control channel name
|
||||
"""
|
||||
self.name = name
|
||||
self.ctrlchnlname = ctrlchnlname
|
||||
|
@ -38,8 +38,7 @@ class VnodeClient:
|
|||
Check if node is connected or not.
|
||||
|
||||
:return: True if connected, False otherwise
|
||||
:rtype: bool
|
||||
"""
|
||||
"""
|
||||
return True
|
||||
|
||||
def close(self) -> None:
|
||||
|
@ -57,12 +56,11 @@ class VnodeClient:
|
|||
"""
|
||||
Run command and return exit status and combined stdout and stderr.
|
||||
|
||||
:param str args: command to run
|
||||
:param bool wait: True to wait for command status, False otherwise
|
||||
:param bool shell: True to use shell, False otherwise
|
||||
:param args: command to run
|
||||
:param wait: True to wait for command status, False otherwise
|
||||
:param shell: True to use shell, False otherwise
|
||||
:return: combined stdout and stderr
|
||||
:rtype: str
|
||||
:raises core.CoreCommandError: when there is a non-zero exit status
|
||||
:raises core.CoreCommandError: when there is a non-zero exit status
|
||||
"""
|
||||
self._verify_connection()
|
||||
args = self.create_cmd(args)
|
||||
|
|
|
@ -88,15 +88,15 @@ class DockerNode(CoreNode):
|
|||
"""
|
||||
Create a DockerNode instance.
|
||||
|
||||
:param core.emulator.session.Session session: core session instance
|
||||
:param int _id: object id
|
||||
:param str name: object name
|
||||
:param str nodedir: node directory
|
||||
:param str bootsh: boot shell to use
|
||||
:param bool start: start flag
|
||||
:param core.emulator.distributed.DistributedServer server: remote server node
|
||||
:param session: core session instance
|
||||
:param _id: object id
|
||||
:param name: object name
|
||||
:param nodedir: node directory
|
||||
:param bootsh: boot shell to use
|
||||
:param start: start flag
|
||||
:param server: remote server node
|
||||
will run on, default is None for localhost
|
||||
:param str image: image to start container with
|
||||
:param image: image to start container with
|
||||
"""
|
||||
if image is None:
|
||||
image = "ubuntu"
|
||||
|
@ -108,7 +108,7 @@ class DockerNode(CoreNode):
|
|||
Create node network client for running network commands within the nodes
|
||||
container.
|
||||
|
||||
:param bool use_ovs: True for OVS bridges, False for Linux bridges
|
||||
:param use_ovs: True for OVS bridges, False for Linux bridges
|
||||
:return:node network client
|
||||
"""
|
||||
return get_net_client(use_ovs, self.nsenter_cmd)
|
||||
|
@ -118,8 +118,7 @@ class DockerNode(CoreNode):
|
|||
Check if the node is alive.
|
||||
|
||||
:return: True if node is alive, False otherwise
|
||||
:rtype: bool
|
||||
"""
|
||||
"""
|
||||
return self.client.is_alive()
|
||||
|
||||
def startup(self) -> None:
|
||||
|
@ -165,7 +164,7 @@ class DockerNode(CoreNode):
|
|||
"""
|
||||
Create a terminal command string.
|
||||
|
||||
:param str sh: shell to execute command in
|
||||
:param sh: shell to execute command in
|
||||
:return: str
|
||||
"""
|
||||
return f"docker exec -it {self.name} bash"
|
||||
|
@ -174,7 +173,7 @@ class DockerNode(CoreNode):
|
|||
"""
|
||||
Create a private directory.
|
||||
|
||||
:param str path: path to create
|
||||
:param path: path to create
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("creating node dir: %s", path)
|
||||
|
@ -185,8 +184,8 @@ class DockerNode(CoreNode):
|
|||
"""
|
||||
Create and mount a directory.
|
||||
|
||||
:param str source: source directory to mount
|
||||
:param str target: target directory to create
|
||||
:param source: source directory to mount
|
||||
:param target: target directory to create
|
||||
:return: nothing
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
|
@ -197,9 +196,9 @@ class DockerNode(CoreNode):
|
|||
"""
|
||||
Create a node file with a given mode.
|
||||
|
||||
:param str filename: name of file to create
|
||||
:param filename: name of file to create
|
||||
:param contents: contents of file
|
||||
:param int mode: mode for file
|
||||
:param mode: mode for file
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("nodefile filename(%s) mode(%s)", filename, mode)
|
||||
|
@ -226,9 +225,9 @@ class DockerNode(CoreNode):
|
|||
Copy a file to a node, following symlinks and preserving metadata.
|
||||
Change file mode if specified.
|
||||
|
||||
:param str filename: file name to copy file to
|
||||
:param str srcfilename: file to copy
|
||||
:param int mode: mode to copy to
|
||||
:param filename: file name to copy file to
|
||||
:param srcfilename: file to copy
|
||||
:param mode: mode to copy to
|
||||
:return: nothing
|
||||
"""
|
||||
logging.info(
|
||||
|
|
|
@ -32,11 +32,11 @@ class CoreInterface:
|
|||
"""
|
||||
Creates a CoreInterface instance.
|
||||
|
||||
:param core.emulator.session.Session session: core session instance
|
||||
:param core.nodes.base.CoreNode node: node for interface
|
||||
:param str name: interface name
|
||||
:param int mtu: mtu value
|
||||
:param core.emulator.distributed.DistributedServer server: remote server node
|
||||
:param session: core session instance
|
||||
:param node: node for interface
|
||||
:param name: interface name
|
||||
:param mtu: mtu value
|
||||
:param server: remote server node
|
||||
will run on, default is None for localhost
|
||||
"""
|
||||
self.session = session
|
||||
|
@ -74,14 +74,13 @@ class CoreInterface:
|
|||
"""
|
||||
Runs a command on the host system or distributed server.
|
||||
|
||||
:param str args: command to run
|
||||
:param dict env: environment to run command with
|
||||
:param str cwd: directory to run command in
|
||||
:param bool wait: True to wait for status, False otherwise
|
||||
:param bool shell: True to use shell, False otherwise
|
||||
:param args: command to run
|
||||
:param env: environment to run command with
|
||||
:param cwd: directory to run command in
|
||||
:param wait: True to wait for status, False otherwise
|
||||
:param shell: True to use shell, False otherwise
|
||||
:return: combined stdout and stderr
|
||||
:rtype: str
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
if self.server is None:
|
||||
return utils.cmd(args, env, cwd, wait, shell)
|
||||
|
@ -108,7 +107,7 @@ class CoreInterface:
|
|||
"""
|
||||
Attach network.
|
||||
|
||||
:param core.nodes.base.CoreNetworkBase net: network to attach
|
||||
:param net: network to attach
|
||||
:return: nothing
|
||||
"""
|
||||
if self.net:
|
||||
|
@ -131,7 +130,7 @@ class CoreInterface:
|
|||
"""
|
||||
Add address.
|
||||
|
||||
:param str addr: address to add
|
||||
:param addr: address to add
|
||||
:return: nothing
|
||||
"""
|
||||
addr = utils.validate_ip(addr)
|
||||
|
@ -141,7 +140,7 @@ class CoreInterface:
|
|||
"""
|
||||
Delete address.
|
||||
|
||||
:param str addr: address to delete
|
||||
:param addr: address to delete
|
||||
:return: nothing
|
||||
"""
|
||||
self.addrlist.remove(addr)
|
||||
|
@ -150,7 +149,7 @@ class CoreInterface:
|
|||
"""
|
||||
Set hardware address.
|
||||
|
||||
:param str addr: hardware address to set to.
|
||||
:param addr: hardware address to set to.
|
||||
:return: nothing
|
||||
"""
|
||||
if addr is not None:
|
||||
|
@ -201,7 +200,7 @@ class CoreInterface:
|
|||
intialize it. This is for supporting separate upstream/downstream
|
||||
parameters when two layer-2 nodes are linked together.
|
||||
|
||||
:param str name: name of parameter to swap
|
||||
:param name: name of parameter to swap
|
||||
:return: nothing
|
||||
"""
|
||||
tmp = self._params
|
||||
|
@ -227,8 +226,7 @@ class CoreInterface:
|
|||
|
||||
:param other: other interface
|
||||
:return: true if less than, false otherwise
|
||||
:rtype: bool
|
||||
"""
|
||||
"""
|
||||
return id(self) < id(other)
|
||||
|
||||
|
||||
|
@ -250,14 +248,14 @@ class Veth(CoreInterface):
|
|||
"""
|
||||
Creates a VEth instance.
|
||||
|
||||
:param core.emulator.session.Session session: core session instance
|
||||
:param core.nodes.base.CoreNode node: related core node
|
||||
:param str name: interface name
|
||||
:param str localname: interface local name
|
||||
:param int mtu: interface mtu
|
||||
:param core.emulator.distributed.DistributedServer server: remote server node
|
||||
:param session: core session instance
|
||||
:param node: related core node
|
||||
:param name: interface name
|
||||
:param localname: interface local name
|
||||
:param mtu: interface mtu
|
||||
:param server: remote server node
|
||||
will run on, default is None for localhost
|
||||
:param bool start: start flag
|
||||
:param start: start flag
|
||||
:raises CoreCommandError: when there is a command exception
|
||||
"""
|
||||
# note that net arg is ignored
|
||||
|
@ -320,14 +318,14 @@ class TunTap(CoreInterface):
|
|||
"""
|
||||
Create a TunTap instance.
|
||||
|
||||
:param core.emulator.session.Session session: core session instance
|
||||
:param core.nodes.base.CoreNode node: related core node
|
||||
:param str name: interface name
|
||||
:param str localname: local interface name
|
||||
:param int mtu: interface mtu
|
||||
:param core.emulator.distributed.DistributedServer server: remote server node
|
||||
:param session: core session instance
|
||||
:param node: related core node
|
||||
:param name: interface name
|
||||
:param localname: local interface name
|
||||
:param mtu: interface mtu
|
||||
:param server: remote server node
|
||||
will run on, default is None for localhost
|
||||
:param bool start: start flag
|
||||
:param start: start flag
|
||||
"""
|
||||
super().__init__(session, node, name, mtu, server)
|
||||
self.localname = localname
|
||||
|
@ -373,11 +371,10 @@ class TunTap(CoreInterface):
|
|||
Wait for func() to return zero with exponential backoff.
|
||||
|
||||
:param func: function to wait for a result of zero
|
||||
:param int attempts: number of attempts to wait for a zero result
|
||||
:param float maxretrydelay: maximum retry delay
|
||||
:param attempts: number of attempts to wait for a zero result
|
||||
:param maxretrydelay: maximum retry delay
|
||||
:return: True if wait succeeded, False otherwise
|
||||
:rtype: bool
|
||||
"""
|
||||
"""
|
||||
delay = 0.01
|
||||
result = False
|
||||
for i in range(1, attempts + 1):
|
||||
|
@ -405,8 +402,7 @@ class TunTap(CoreInterface):
|
|||
appear right away waits
|
||||
|
||||
:return: wait for device local response
|
||||
:rtype: int
|
||||
"""
|
||||
"""
|
||||
logging.debug("waiting for device local: %s", self.localname)
|
||||
|
||||
def localdevexists():
|
||||
|
@ -500,17 +496,17 @@ class GreTap(CoreInterface):
|
|||
"""
|
||||
Creates a GreTap instance.
|
||||
|
||||
:param core.nodes.base.CoreNode node: related core node
|
||||
:param str name: interface name
|
||||
:param core.emulator.session.Session session: core session instance
|
||||
:param int mtu: interface mtu
|
||||
:param str remoteip: remote address
|
||||
:param int _id: object id
|
||||
:param str localip: local address
|
||||
:param int ttl: ttl value
|
||||
:param int key: gre tap key
|
||||
:param bool start: start flag
|
||||
:param core.emulator.distributed.DistributedServer server: remote server node
|
||||
:param node: related core node
|
||||
:param name: interface name
|
||||
:param session: core session instance
|
||||
:param mtu: interface mtu
|
||||
:param remoteip: remote address
|
||||
:param _id: object id
|
||||
:param localip: local address
|
||||
:param ttl: ttl value
|
||||
:param key: gre tap key
|
||||
:param start: start flag
|
||||
:param server: remote server node
|
||||
will run on, default is None for localhost
|
||||
:raises CoreCommandError: when there is a command exception
|
||||
"""
|
||||
|
@ -564,6 +560,5 @@ class GreTap(CoreInterface):
|
|||
|
||||
:param flags: link flags
|
||||
:return: link data
|
||||
:rtype: list[core.emulator.data.LinkData]
|
||||
"""
|
||||
"""
|
||||
return []
|
||||
|
|
|
@ -82,15 +82,15 @@ class LxcNode(CoreNode):
|
|||
"""
|
||||
Create a LxcNode instance.
|
||||
|
||||
:param core.emulator.session.Session session: core session instance
|
||||
:param int _id: object id
|
||||
:param str name: object name
|
||||
:param str nodedir: node directory
|
||||
:param str bootsh: boot shell to use
|
||||
:param bool start: start flag
|
||||
:param core.emulator.distributed.DistributedServer server: remote server node
|
||||
:param session: core session instance
|
||||
:param _id: object id
|
||||
:param name: object name
|
||||
:param nodedir: node directory
|
||||
:param bootsh: boot shell to use
|
||||
:param start: start flag
|
||||
:param server: remote server node
|
||||
will run on, default is None for localhost
|
||||
:param str image: image to start container with
|
||||
:param image: image to start container with
|
||||
"""
|
||||
if image is None:
|
||||
image = "ubuntu"
|
||||
|
@ -102,8 +102,7 @@ class LxcNode(CoreNode):
|
|||
Check if the node is alive.
|
||||
|
||||
:return: True if node is alive, False otherwise
|
||||
:rtype: bool
|
||||
"""
|
||||
"""
|
||||
return self.client.is_alive()
|
||||
|
||||
def startup(self) -> None:
|
||||
|
@ -139,7 +138,7 @@ class LxcNode(CoreNode):
|
|||
"""
|
||||
Create a terminal command string.
|
||||
|
||||
:param str sh: shell to execute command in
|
||||
:param sh: shell to execute command in
|
||||
:return: str
|
||||
"""
|
||||
return f"lxc exec {self.name} -- {sh}"
|
||||
|
@ -148,7 +147,7 @@ class LxcNode(CoreNode):
|
|||
"""
|
||||
Create a private directory.
|
||||
|
||||
:param str path: path to create
|
||||
:param path: path to create
|
||||
:return: nothing
|
||||
"""
|
||||
logging.info("creating node dir: %s", path)
|
||||
|
@ -159,8 +158,8 @@ class LxcNode(CoreNode):
|
|||
"""
|
||||
Create and mount a directory.
|
||||
|
||||
:param str source: source directory to mount
|
||||
:param str target: target directory to create
|
||||
:param source: source directory to mount
|
||||
:param target: target directory to create
|
||||
:return: nothing
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
|
@ -171,9 +170,9 @@ class LxcNode(CoreNode):
|
|||
"""
|
||||
Create a node file with a given mode.
|
||||
|
||||
:param str filename: name of file to create
|
||||
:param filename: name of file to create
|
||||
:param contents: contents of file
|
||||
:param int mode: mode for file
|
||||
:param mode: mode for file
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("nodefile filename(%s) mode(%s)", filename, mode)
|
||||
|
@ -199,9 +198,9 @@ class LxcNode(CoreNode):
|
|||
Copy a file to a node, following symlinks and preserving metadata.
|
||||
Change file mode if specified.
|
||||
|
||||
:param str filename: file name to copy file to
|
||||
:param str srcfilename: file to copy
|
||||
:param int mode: mode to copy to
|
||||
:param filename: file name to copy file to
|
||||
:param srcfilename: file to copy
|
||||
:param mode: mode to copy to
|
||||
:return: nothing
|
||||
"""
|
||||
logging.info(
|
||||
|
|
|
@ -24,7 +24,7 @@ class LinuxNetClient:
|
|||
"""
|
||||
Set network hostname.
|
||||
|
||||
:param str name: name for hostname
|
||||
:param name: name for hostname
|
||||
:return: nothing
|
||||
"""
|
||||
self.run(f"hostname {name}")
|
||||
|
@ -33,8 +33,8 @@ class LinuxNetClient:
|
|||
"""
|
||||
Create a new route for a device.
|
||||
|
||||
:param str route: route to create
|
||||
:param str device: device to add route to
|
||||
:param route: route to create
|
||||
:param device: device to add route to
|
||||
:return: nothing
|
||||
"""
|
||||
self.run(f"{IP_BIN} route add {route} dev {device}")
|
||||
|
@ -43,7 +43,7 @@ class LinuxNetClient:
|
|||
"""
|
||||
Bring a device up.
|
||||
|
||||
:param str device: device to bring up
|
||||
:param device: device to bring up
|
||||
:return: nothing
|
||||
"""
|
||||
self.run(f"{IP_BIN} link set {device} up")
|
||||
|
@ -52,7 +52,7 @@ class LinuxNetClient:
|
|||
"""
|
||||
Bring a device down.
|
||||
|
||||
:param str device: device to bring down
|
||||
:param device: device to bring down
|
||||
:return: nothing
|
||||
"""
|
||||
self.run(f"{IP_BIN} link set {device} down")
|
||||
|
@ -61,8 +61,8 @@ class LinuxNetClient:
|
|||
"""
|
||||
Set a device name.
|
||||
|
||||
:param str device: device to set name for
|
||||
:param str name: name to set
|
||||
:param device: device to set name for
|
||||
:param name: name to set
|
||||
:return: nothing
|
||||
"""
|
||||
self.run(f"{IP_BIN} link set {device} name {name}")
|
||||
|
@ -71,38 +71,35 @@ class LinuxNetClient:
|
|||
"""
|
||||
Show information for a device.
|
||||
|
||||
:param str device: device to get information for
|
||||
:param device: device to get information for
|
||||
:return: device information
|
||||
:rtype: str
|
||||
"""
|
||||
"""
|
||||
return self.run(f"{IP_BIN} link show {device}")
|
||||
|
||||
def get_mac(self, device: str) -> str:
|
||||
"""
|
||||
Retrieve MAC address for a given device.
|
||||
|
||||
:param str device: device to get mac for
|
||||
:param device: device to get mac for
|
||||
:return: MAC address
|
||||
:rtype: str
|
||||
"""
|
||||
"""
|
||||
return self.run(f"cat /sys/class/net/{device}/address")
|
||||
|
||||
def get_ifindex(self, device: str) -> str:
|
||||
"""
|
||||
Retrieve ifindex for a given device.
|
||||
|
||||
:param str device: device to get ifindex for
|
||||
:param device: device to get ifindex for
|
||||
:return: ifindex
|
||||
:rtype: str
|
||||
"""
|
||||
"""
|
||||
return self.run(f"cat /sys/class/net/{device}/ifindex")
|
||||
|
||||
def device_ns(self, device: str, namespace: str) -> None:
|
||||
"""
|
||||
Set netns for a device.
|
||||
|
||||
:param str device: device to setns for
|
||||
:param str namespace: namespace to set device to
|
||||
:param device: device to setns for
|
||||
:param namespace: namespace to set device to
|
||||
:return: nothing
|
||||
"""
|
||||
self.run(f"{IP_BIN} link set {device} netns {namespace}")
|
||||
|
@ -111,7 +108,7 @@ class LinuxNetClient:
|
|||
"""
|
||||
Flush device addresses.
|
||||
|
||||
:param str device: device to flush
|
||||
:param device: device to flush
|
||||
:return: nothing
|
||||
"""
|
||||
self.run(
|
||||
|
@ -123,8 +120,8 @@ class LinuxNetClient:
|
|||
"""
|
||||
Set MAC address for a device.
|
||||
|
||||
:param str device: device to set mac for
|
||||
:param str mac: mac to set
|
||||
:param device: device to set mac for
|
||||
:param mac: mac to set
|
||||
:return: nothing
|
||||
"""
|
||||
self.run(f"{IP_BIN} link set dev {device} address {mac}")
|
||||
|
@ -133,7 +130,7 @@ class LinuxNetClient:
|
|||
"""
|
||||
Delete device.
|
||||
|
||||
:param str device: device to delete
|
||||
:param device: device to delete
|
||||
:return: nothing
|
||||
"""
|
||||
self.run(f"{IP_BIN} link delete {device}")
|
||||
|
@ -142,7 +139,7 @@ class LinuxNetClient:
|
|||
"""
|
||||
Remove traffic control settings for a device.
|
||||
|
||||
:param str device: device to remove tc
|
||||
:param device: device to remove tc
|
||||
:return: nothing
|
||||
"""
|
||||
self.run(f"{TC_BIN} qdisc delete dev {device} root")
|
||||
|
@ -151,7 +148,7 @@ class LinuxNetClient:
|
|||
"""
|
||||
Turns interface checksums off.
|
||||
|
||||
:param str interface_name: interface to update
|
||||
:param interface_name: interface to update
|
||||
:return: nothing
|
||||
"""
|
||||
self.run(f"{ETHTOOL_BIN} -K {interface_name} rx off tx off")
|
||||
|
@ -160,9 +157,9 @@ class LinuxNetClient:
|
|||
"""
|
||||
Create address for a device.
|
||||
|
||||
:param str device: device to add address to
|
||||
:param str address: address to add
|
||||
:param str broadcast: broadcast address to use, default is None
|
||||
:param device: device to add address to
|
||||
:param address: address to add
|
||||
:param broadcast: broadcast address to use, default is None
|
||||
:return: nothing
|
||||
"""
|
||||
if broadcast is not None:
|
||||
|
@ -176,8 +173,8 @@ class LinuxNetClient:
|
|||
"""
|
||||
Delete an address from a device.
|
||||
|
||||
:param str device: targeted device
|
||||
:param str address: address to remove
|
||||
:param device: targeted device
|
||||
:param address: address to remove
|
||||
:return: nothing
|
||||
"""
|
||||
self.run(f"{IP_BIN} address delete {address} dev {device}")
|
||||
|
@ -186,8 +183,8 @@ class LinuxNetClient:
|
|||
"""
|
||||
Create a veth pair.
|
||||
|
||||
:param str name: veth name
|
||||
:param str peer: peer name
|
||||
:param name: veth name
|
||||
:param peer: peer name
|
||||
:return: nothing
|
||||
"""
|
||||
self.run(f"{IP_BIN} link add name {name} type veth peer name {peer}")
|
||||
|
@ -198,11 +195,11 @@ class LinuxNetClient:
|
|||
"""
|
||||
Create a GRE tap on a device.
|
||||
|
||||
:param str device: device to add tap to
|
||||
:param str address: address to add tap for
|
||||
:param str local: local address to tie to
|
||||
:param int ttl: time to live value
|
||||
:param int key: key for tap
|
||||
:param device: device to add tap to
|
||||
:param address: address to add tap for
|
||||
:param local: local address to tie to
|
||||
:param ttl: time to live value
|
||||
:param key: key for tap
|
||||
:return: nothing
|
||||
"""
|
||||
cmd = f"{IP_BIN} link add {device} type gretap remote {address}"
|
||||
|
@ -218,7 +215,7 @@ class LinuxNetClient:
|
|||
"""
|
||||
Create a Linux bridge and bring it up.
|
||||
|
||||
:param str name: bridge name
|
||||
:param name: bridge name
|
||||
:return: nothing
|
||||
"""
|
||||
self.run(f"{IP_BIN} link add name {name} type bridge")
|
||||
|
@ -231,7 +228,7 @@ class LinuxNetClient:
|
|||
"""
|
||||
Bring down and delete a Linux bridge.
|
||||
|
||||
:param str name: bridge name
|
||||
:param name: bridge name
|
||||
:return: nothing
|
||||
"""
|
||||
self.device_down(name)
|
||||
|
@ -241,8 +238,8 @@ class LinuxNetClient:
|
|||
"""
|
||||
Create an interface associated with a Linux bridge.
|
||||
|
||||
:param str bridge_name: bridge name
|
||||
:param str interface_name: interface name
|
||||
:param bridge_name: bridge name
|
||||
:param interface_name: interface name
|
||||
:return: nothing
|
||||
"""
|
||||
self.run(f"{IP_BIN} link set dev {interface_name} master {bridge_name}")
|
||||
|
@ -252,8 +249,8 @@ class LinuxNetClient:
|
|||
"""
|
||||
Delete an interface associated with a Linux bridge.
|
||||
|
||||
:param str bridge_name: bridge name
|
||||
:param str interface_name: interface name
|
||||
:param bridge_name: bridge name
|
||||
:param interface_name: interface name
|
||||
:return: nothing
|
||||
"""
|
||||
self.run(f"{IP_BIN} link set dev {interface_name} nomaster")
|
||||
|
@ -282,7 +279,7 @@ class LinuxNetClient:
|
|||
"""
|
||||
Disable mac learning for a Linux bridge.
|
||||
|
||||
:param str name: bridge name
|
||||
:param name: bridge name
|
||||
:return: nothing
|
||||
"""
|
||||
self.run(f"{IP_BIN} link set {name} type bridge ageing_time 0")
|
||||
|
@ -297,7 +294,7 @@ class OvsNetClient(LinuxNetClient):
|
|||
"""
|
||||
Create a OVS bridge and bring it up.
|
||||
|
||||
:param str name: bridge name
|
||||
:param name: bridge name
|
||||
:return: nothing
|
||||
"""
|
||||
self.run(f"{OVS_BIN} add-br {name}")
|
||||
|
@ -310,7 +307,7 @@ class OvsNetClient(LinuxNetClient):
|
|||
"""
|
||||
Bring down and delete a OVS bridge.
|
||||
|
||||
:param str name: bridge name
|
||||
:param name: bridge name
|
||||
:return: nothing
|
||||
"""
|
||||
self.device_down(name)
|
||||
|
@ -320,8 +317,8 @@ class OvsNetClient(LinuxNetClient):
|
|||
"""
|
||||
Create an interface associated with a network bridge.
|
||||
|
||||
:param str bridge_name: bridge name
|
||||
:param str interface_name: interface name
|
||||
:param bridge_name: bridge name
|
||||
:param interface_name: interface name
|
||||
:return: nothing
|
||||
"""
|
||||
self.run(f"{OVS_BIN} add-port {bridge_name} {interface_name}")
|
||||
|
@ -331,8 +328,8 @@ class OvsNetClient(LinuxNetClient):
|
|||
"""
|
||||
Delete an interface associated with a OVS bridge.
|
||||
|
||||
:param str bridge_name: bridge name
|
||||
:param str interface_name: interface name
|
||||
:param bridge_name: bridge name
|
||||
:param interface_name: interface name
|
||||
:return: nothing
|
||||
"""
|
||||
self.run(f"{OVS_BIN} del-port {bridge_name} {interface_name}")
|
||||
|
@ -356,7 +353,7 @@ class OvsNetClient(LinuxNetClient):
|
|||
"""
|
||||
Disable mac learning for a OVS bridge.
|
||||
|
||||
:param str name: bridge name
|
||||
:param name: bridge name
|
||||
:return: nothing
|
||||
"""
|
||||
self.run(f"{OVS_BIN} set bridge {name} other_config:mac-aging-time=0")
|
||||
|
@ -366,8 +363,8 @@ def get_net_client(use_ovs: bool, run: Callable[..., str]) -> LinuxNetClient:
|
|||
"""
|
||||
Retrieve desired net client for running network commands.
|
||||
|
||||
:param bool use_ovs: True for OVS bridges, False for Linux bridges
|
||||
:param func run: function used to run net client commands
|
||||
:param use_ovs: True for OVS bridges, False for Linux bridges
|
||||
:param run: function used to run net client commands
|
||||
:return: net client class
|
||||
"""
|
||||
if use_ovs:
|
||||
|
|
|
@ -100,10 +100,9 @@ class EbtablesQueue:
|
|||
"""
|
||||
Helper for building ebtables atomic file command list.
|
||||
|
||||
:param str cmd: ebtable command
|
||||
:param cmd: ebtable command
|
||||
:return: ebtable atomic command
|
||||
:rtype: str
|
||||
"""
|
||||
"""
|
||||
return f"{EBTABLES_BIN} --atomic-file {self.atomic_file} {cmd}"
|
||||
|
||||
def lastupdate(self, wlan: "CoreNetwork") -> float:
|
||||
|
@ -112,8 +111,7 @@ class EbtablesQueue:
|
|||
|
||||
:param wlan: wlan entity
|
||||
:return: elpased time
|
||||
:rtype: float
|
||||
"""
|
||||
"""
|
||||
try:
|
||||
elapsed = time.monotonic() - self.last_update_time[wlan]
|
||||
except KeyError:
|
||||
|
@ -243,8 +241,8 @@ def ebtablescmds(call: Callable[..., str], cmds: List[str]) -> None:
|
|||
"""
|
||||
Run ebtable commands.
|
||||
|
||||
:param func call: function to call commands
|
||||
:param list cmds: commands to call
|
||||
:param call: function to call commands
|
||||
:param cmds: commands to call
|
||||
:return: nothing
|
||||
"""
|
||||
with ebtables_lock:
|
||||
|
@ -271,11 +269,11 @@ class CoreNetwork(CoreNetworkBase):
|
|||
"""
|
||||
Creates a LxBrNet instance.
|
||||
|
||||
:param core.session.Session session: core session instance
|
||||
:param int _id: object id
|
||||
:param str name: object name
|
||||
:param bool start: start flag
|
||||
:param core.emulator.distributed.DistributedServer server: remote server node
|
||||
:param session: core session instance
|
||||
:param _id: object id
|
||||
:param name: object name
|
||||
:param start: start flag
|
||||
:param server: remote server node
|
||||
will run on, default is None for localhost
|
||||
:param policy: network policy
|
||||
"""
|
||||
|
@ -305,14 +303,13 @@ class CoreNetwork(CoreNetworkBase):
|
|||
Runs a command that is used to configure and setup the network on the host
|
||||
system and all configured distributed servers.
|
||||
|
||||
:param str args: command to run
|
||||
:param dict env: environment to run command with
|
||||
:param str cwd: directory to run command in
|
||||
:param bool wait: True to wait for status, False otherwise
|
||||
:param bool shell: True to use shell, False otherwise
|
||||
:param args: command to run
|
||||
:param env: environment to run command with
|
||||
:param cwd: directory to run command in
|
||||
:param wait: True to wait for status, False otherwise
|
||||
:param shell: True to use shell, False otherwise
|
||||
:return: combined stdout and stderr
|
||||
:rtype: str
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
logging.debug("network node(%s) cmd", self.name)
|
||||
output = utils.cmd(args, env, cwd, wait, shell)
|
||||
|
@ -365,7 +362,7 @@ class CoreNetwork(CoreNetworkBase):
|
|||
"""
|
||||
Attach a network interface.
|
||||
|
||||
:param core.nodes.interface.CoreInterface netif: network interface to attach
|
||||
:param netif: network interface to attach
|
||||
:return: nothing
|
||||
"""
|
||||
if self.up:
|
||||
|
@ -376,7 +373,7 @@ class CoreNetwork(CoreNetworkBase):
|
|||
"""
|
||||
Detach a network interface.
|
||||
|
||||
:param core.nodes.interface.Veth netif: network interface to detach
|
||||
:param netif: network interface to detach
|
||||
:return: nothing
|
||||
"""
|
||||
if self.up:
|
||||
|
@ -387,11 +384,10 @@ class CoreNetwork(CoreNetworkBase):
|
|||
"""
|
||||
Determine if the provided network interfaces are linked.
|
||||
|
||||
:param core.nodes.interface.CoreInterface netif1: interface one
|
||||
:param core.nodes.interface.CoreInterface netif2: interface two
|
||||
:param netif1: interface one
|
||||
:param netif2: interface two
|
||||
:return: True if interfaces are linked, False otherwise
|
||||
:rtype: bool
|
||||
"""
|
||||
"""
|
||||
# check if the network interfaces are attached to this network
|
||||
if self._netif[netif1.netifi] != netif1:
|
||||
raise ValueError(f"inconsistency for netif {netif1.name}")
|
||||
|
@ -417,8 +413,8 @@ class CoreNetwork(CoreNetworkBase):
|
|||
Unlink two interfaces, resulting in adding or removing ebtables
|
||||
filtering rules.
|
||||
|
||||
:param core.nodes.interface.CoreInterface netif1: interface one
|
||||
:param core.nodes.interface.CoreInterface netif2: interface two
|
||||
:param netif1: interface one
|
||||
:param netif2: interface two
|
||||
:return: nothing
|
||||
"""
|
||||
with self._linked_lock:
|
||||
|
@ -433,8 +429,8 @@ class CoreNetwork(CoreNetworkBase):
|
|||
Link two interfaces together, resulting in adding or removing
|
||||
ebtables filtering rules.
|
||||
|
||||
:param core.nodes.interface.CoreInterface netif1: interface one
|
||||
:param core.nodes.interface.CoreInterface netif2: interface two
|
||||
:param netif1: interface one
|
||||
:param netif2: interface two
|
||||
:return: nothing
|
||||
"""
|
||||
with self._linked_lock:
|
||||
|
@ -458,13 +454,13 @@ class CoreNetwork(CoreNetworkBase):
|
|||
"""
|
||||
Configure link parameters by applying tc queuing disciplines on the interface.
|
||||
|
||||
:param core.nodes.interface.CoreInterface netif: interface one
|
||||
:param netif: interface one
|
||||
:param bw: bandwidth to set to
|
||||
:param delay: packet delay to set to
|
||||
:param loss: packet loss to set to
|
||||
:param duplicate: duplicate percentage to set to
|
||||
:param jitter: jitter to set to
|
||||
:param core.netns.vif.Veth netif2: interface two
|
||||
:param netif2: interface two
|
||||
:param devname: device name
|
||||
:return: nothing
|
||||
"""
|
||||
|
@ -546,10 +542,9 @@ class CoreNetwork(CoreNetworkBase):
|
|||
Link this bridge with another by creating a veth pair and installing
|
||||
each device into each bridge.
|
||||
|
||||
:param core.nodes.base.CoreNetworkBase net: network to link with
|
||||
:param net: network to link with
|
||||
:return: created interface
|
||||
:rtype: core.nodes.interface.CoreInterface
|
||||
"""
|
||||
"""
|
||||
sessionid = self.session.short_session_id()
|
||||
try:
|
||||
_id = f"{self.id:x}"
|
||||
|
@ -587,10 +582,9 @@ class CoreNetwork(CoreNetworkBase):
|
|||
Return the interface of that links this net with another net
|
||||
(that were linked using linknet()).
|
||||
|
||||
:param core.nodes.base.CoreNetworkBase net: interface to get link for
|
||||
:param net: interface to get link for
|
||||
:return: interface the provided network is linked to
|
||||
:rtype: core.nodes.interface.CoreInterface
|
||||
"""
|
||||
"""
|
||||
for netif in self.netifs():
|
||||
if hasattr(netif, "othernet") and netif.othernet == net:
|
||||
return netif
|
||||
|
@ -600,7 +594,7 @@ class CoreNetwork(CoreNetworkBase):
|
|||
"""
|
||||
Set addresses on the bridge.
|
||||
|
||||
:param list[str] addrlist: address list
|
||||
:param addrlist: address list
|
||||
:return: nothing
|
||||
"""
|
||||
if not self.up:
|
||||
|
@ -632,16 +626,16 @@ class GreTapBridge(CoreNetwork):
|
|||
"""
|
||||
Create a GreTapBridge instance.
|
||||
|
||||
:param core.emulator.session.Session session: core session instance
|
||||
:param str remoteip: remote address
|
||||
:param int _id: object id
|
||||
:param str name: object name
|
||||
:param session: core session instance
|
||||
:param remoteip: remote address
|
||||
:param _id: object id
|
||||
:param name: object name
|
||||
:param policy: network policy
|
||||
:param str localip: local address
|
||||
:param localip: local address
|
||||
:param ttl: ttl value
|
||||
:param key: gre tap key
|
||||
:param bool start: start flag
|
||||
:param core.emulator.distributed.DistributedServer server: remote server node
|
||||
:param start: start flag
|
||||
:param server: remote server node
|
||||
will run on, default is None for localhost
|
||||
"""
|
||||
CoreNetwork.__init__(self, session, _id, name, False, server, policy)
|
||||
|
@ -696,7 +690,7 @@ class GreTapBridge(CoreNetwork):
|
|||
The 1st address in the provided list is remoteip, 2nd optionally
|
||||
specifies localip.
|
||||
|
||||
:param list addrlist: address list
|
||||
:param addrlist: address list
|
||||
:return: nothing
|
||||
"""
|
||||
if self.gretap:
|
||||
|
@ -756,16 +750,16 @@ class CtrlNet(CoreNetwork):
|
|||
"""
|
||||
Creates a CtrlNet instance.
|
||||
|
||||
:param core.emulator.session.Session session: core session instance
|
||||
:param int _id: node id
|
||||
:param str name: node namee
|
||||
:param session: core session instance
|
||||
:param _id: node id
|
||||
:param name: node namee
|
||||
:param prefix: control network ipv4 prefix
|
||||
:param hostid: host id
|
||||
:param bool start: start flag
|
||||
:param core.emulator.distributed.DistributedServer server: remote server node
|
||||
:param start: start flag
|
||||
:param server: remote server node
|
||||
will run on, default is None for localhost
|
||||
:param str assign_address: assigned address
|
||||
:param str updown_script: updown script
|
||||
:param assign_address: assigned address
|
||||
:param updown_script: updown script
|
||||
:param serverintf: server interface
|
||||
:return:
|
||||
"""
|
||||
|
@ -780,7 +774,7 @@ class CtrlNet(CoreNetwork):
|
|||
"""
|
||||
Add addresses used for created control networks,
|
||||
|
||||
:param int index: starting address index
|
||||
:param index: starting address index
|
||||
:return: nothing
|
||||
"""
|
||||
use_ovs = self.session.options.get_config("ovs") == "True"
|
||||
|
@ -861,8 +855,7 @@ class CtrlNet(CoreNetwork):
|
|||
|
||||
:param flags: message flags
|
||||
:return: list of link data
|
||||
:rtype: list[core.data.LinkData]
|
||||
"""
|
||||
"""
|
||||
return []
|
||||
|
||||
|
||||
|
@ -877,7 +870,7 @@ class PtpNet(CoreNetwork):
|
|||
"""
|
||||
Attach a network interface, but limit attachment to two interfaces.
|
||||
|
||||
:param core.nodes.interface.CoreInterface netif: network interface
|
||||
:param netif: network interface
|
||||
:return: nothing
|
||||
"""
|
||||
if len(self._netif) >= 2:
|
||||
|
@ -899,13 +892,12 @@ class PtpNet(CoreNetwork):
|
|||
built using a link message instead.
|
||||
|
||||
:param message_type: purpose for the data object we are creating
|
||||
:param float lat: latitude
|
||||
:param float lon: longitude
|
||||
:param float alt: altitude
|
||||
:param str source: source of node data
|
||||
:param lat: latitude
|
||||
:param lon: longitude
|
||||
:param alt: altitude
|
||||
:param source: source of node data
|
||||
:return: node data object
|
||||
:rtype: core.emulator.data.NodeData
|
||||
"""
|
||||
"""
|
||||
return None
|
||||
|
||||
def all_link_data(self, flags: int) -> List[LinkData]:
|
||||
|
@ -915,8 +907,7 @@ class PtpNet(CoreNetwork):
|
|||
|
||||
:param flags: message flags
|
||||
:return: list of link data
|
||||
:rtype: list[core.emulator.data.LinkData]
|
||||
"""
|
||||
"""
|
||||
|
||||
all_links = []
|
||||
|
||||
|
@ -1057,11 +1048,11 @@ class WlanNode(CoreNetwork):
|
|||
"""
|
||||
Create a WlanNode instance.
|
||||
|
||||
:param core.session.Session session: core session instance
|
||||
:param int _id: node id
|
||||
:param str name: node name
|
||||
:param bool start: start flag
|
||||
:param core.emulator.distributed.DistributedServer server: remote server node
|
||||
:param session: core session instance
|
||||
:param _id: node id
|
||||
:param name: node name
|
||||
:param start: start flag
|
||||
:param server: remote server node
|
||||
will run on, default is None for localhost
|
||||
:param policy: wlan policy
|
||||
"""
|
||||
|
@ -1083,7 +1074,7 @@ class WlanNode(CoreNetwork):
|
|||
"""
|
||||
Attach a network interface.
|
||||
|
||||
:param core.nodes.interface.CoreInterface netif: network interface
|
||||
:param netif: network interface
|
||||
:return: nothing
|
||||
"""
|
||||
super().attach(netif)
|
||||
|
@ -1099,8 +1090,8 @@ class WlanNode(CoreNetwork):
|
|||
"""
|
||||
Sets the mobility and wireless model.
|
||||
|
||||
:param core.location.mobility.WirelessModel.cls model: wireless model to set to
|
||||
:param dict config: configuration for model being set
|
||||
:param model: wireless model to set to
|
||||
:param config: configuration for model being set
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("node(%s) setting model: %s", self.name, model.name)
|
||||
|
@ -1139,8 +1130,7 @@ class WlanNode(CoreNetwork):
|
|||
|
||||
:param flags: message flags
|
||||
:return: list of link data
|
||||
:rtype: list[core.emulator.data.LinkData]
|
||||
"""
|
||||
"""
|
||||
all_links = super().all_link_data(flags)
|
||||
if self.model:
|
||||
all_links.extend(self.model.all_link_data(flags))
|
||||
|
|
|
@ -62,7 +62,7 @@ class PhysicalNode(CoreNodeBase):
|
|||
"""
|
||||
Create a terminal command string.
|
||||
|
||||
:param str sh: shell to execute command in
|
||||
:param sh: shell to execute command in
|
||||
:return: str
|
||||
"""
|
||||
return sh
|
||||
|
@ -71,8 +71,8 @@ class PhysicalNode(CoreNodeBase):
|
|||
"""
|
||||
Set hardware address for an interface.
|
||||
|
||||
:param int ifindex: index of interface to set hardware address for
|
||||
:param str addr: hardware address to set
|
||||
:param ifindex: index of interface to set hardware address for
|
||||
:param addr: hardware address to set
|
||||
:return: nothing
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
|
@ -86,8 +86,8 @@ class PhysicalNode(CoreNodeBase):
|
|||
"""
|
||||
Add an address to an interface.
|
||||
|
||||
:param int ifindex: index of interface to add address to
|
||||
:param str addr: address to add
|
||||
:param ifindex: index of interface to add address to
|
||||
:param addr: address to add
|
||||
:return: nothing
|
||||
"""
|
||||
addr = utils.validate_ip(addr)
|
||||
|
@ -100,8 +100,8 @@ class PhysicalNode(CoreNodeBase):
|
|||
"""
|
||||
Delete an address from an interface.
|
||||
|
||||
:param int ifindex: index of interface to delete
|
||||
:param str addr: address to delete
|
||||
:param ifindex: index of interface to delete
|
||||
:param addr: address to delete
|
||||
:return: nothing
|
||||
"""
|
||||
interface = self._netif[ifindex]
|
||||
|
@ -279,12 +279,12 @@ class Rj45Node(CoreNodeBase, CoreInterface):
|
|||
"""
|
||||
Create an RJ45Node instance.
|
||||
|
||||
:param core.emulator.session.Session session: core session instance
|
||||
:param int _id: node id
|
||||
:param str name: node name
|
||||
:param session: core session instance
|
||||
:param _id: node id
|
||||
:param name: node name
|
||||
:param mtu: rj45 mtu
|
||||
:param bool start: start flag
|
||||
:param core.emulator.distributed.DistributedServer server: remote server node
|
||||
:param start: start flag
|
||||
:param server: remote server node
|
||||
will run on, default is None for localhost
|
||||
"""
|
||||
CoreNodeBase.__init__(self, session, _id, name, start, server)
|
||||
|
@ -339,7 +339,7 @@ class Rj45Node(CoreNodeBase, CoreInterface):
|
|||
"""
|
||||
Attach a network.
|
||||
|
||||
:param core.nodes.base.CoreNetworkBase net: network to attach
|
||||
:param net: network to attach
|
||||
:return: nothing
|
||||
"""
|
||||
CoreInterface.attachnet(self, net)
|
||||
|
@ -367,14 +367,13 @@ class Rj45Node(CoreNodeBase, CoreInterface):
|
|||
represents an interface, we do not create another object here,
|
||||
but attach ourselves to the given network.
|
||||
|
||||
:param core.nodes.base.CoreNetworkBase net: new network instance
|
||||
:param list[str] addrlist: address list
|
||||
:param str hwaddr: hardware address
|
||||
:param int ifindex: interface index
|
||||
:param str ifname: interface name
|
||||
:param net: new network instance
|
||||
:param addrlist: address list
|
||||
:param hwaddr: hardware address
|
||||
:param ifindex: interface index
|
||||
:param ifname: interface name
|
||||
:return: interface index
|
||||
:rtype: int
|
||||
:raises ValueError: when an interface has already been created, one max
|
||||
:raises ValueError: when an interface has already been created, one max
|
||||
"""
|
||||
with self.lock:
|
||||
if ifindex is None:
|
||||
|
@ -401,7 +400,7 @@ class Rj45Node(CoreNodeBase, CoreInterface):
|
|||
"""
|
||||
Delete a network interface.
|
||||
|
||||
:param int ifindex: interface index to delete
|
||||
:param ifindex: interface index to delete
|
||||
:return: nothing
|
||||
"""
|
||||
if ifindex is None:
|
||||
|
@ -422,11 +421,10 @@ class Rj45Node(CoreNodeBase, CoreInterface):
|
|||
return self here. This keeps the RJ45Node compatible with
|
||||
real nodes.
|
||||
|
||||
:param int ifindex: interface index to retrieve
|
||||
:param ifindex: interface index to retrieve
|
||||
:param net: network to retrieve
|
||||
:return: a network interface
|
||||
:rtype: core.nodes.interface,CoreInterface
|
||||
"""
|
||||
"""
|
||||
if net is not None and net == self.net:
|
||||
return self
|
||||
|
||||
|
@ -442,11 +440,10 @@ class Rj45Node(CoreNodeBase, CoreInterface):
|
|||
"""
|
||||
Retrieve network interface index.
|
||||
|
||||
:param core.nodes.interface.CoreInterface netif: network interface to retrieve
|
||||
:param netif: network interface to retrieve
|
||||
index for
|
||||
:return: interface index, None otherwise
|
||||
:rtype: int
|
||||
"""
|
||||
"""
|
||||
if netif != self:
|
||||
return None
|
||||
return self.ifindex
|
||||
|
@ -455,7 +452,7 @@ class Rj45Node(CoreNodeBase, CoreInterface):
|
|||
"""
|
||||
Add address to to network interface.
|
||||
|
||||
:param str addr: address to add
|
||||
:param addr: address to add
|
||||
:return: nothing
|
||||
:raises CoreCommandError: when there is a command exception
|
||||
"""
|
||||
|
@ -468,7 +465,7 @@ class Rj45Node(CoreNodeBase, CoreInterface):
|
|||
"""
|
||||
Delete address from network interface.
|
||||
|
||||
:param str addr: address to delete
|
||||
:param addr: address to delete
|
||||
:return: nothing
|
||||
:raises CoreCommandError: when there is a command exception
|
||||
"""
|
||||
|
@ -525,12 +522,11 @@ class Rj45Node(CoreNodeBase, CoreInterface):
|
|||
"""
|
||||
Uses setposition from both parent classes.
|
||||
|
||||
:param float x: x position
|
||||
:param float y: y position
|
||||
:param float z: z position
|
||||
:param x: x position
|
||||
:param y: y position
|
||||
:param z: z position
|
||||
:return: True if position changed, False otherwise
|
||||
:rtype: bool
|
||||
"""
|
||||
"""
|
||||
result = CoreNodeBase.setposition(self, x, y, z)
|
||||
CoreInterface.setposition(self, x, y, z)
|
||||
return result
|
||||
|
@ -539,7 +535,7 @@ class Rj45Node(CoreNodeBase, CoreInterface):
|
|||
"""
|
||||
Create a terminal command string.
|
||||
|
||||
:param str sh: shell to execute command in
|
||||
:param sh: shell to execute command in
|
||||
:return: str
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue