updated link config to work distributed, added crude locking for fabric
This commit is contained in:
parent
859f473ba9
commit
a4b6b8be51
5 changed files with 79 additions and 12 deletions
|
@ -1,7 +1,10 @@
|
|||
import logging
|
||||
import threading
|
||||
|
||||
from core.errors import CoreCommandError
|
||||
|
||||
LOCK = threading.Lock()
|
||||
|
||||
|
||||
def remote_cmd(server, cmd, env=None):
|
||||
"""
|
||||
|
@ -16,12 +19,18 @@ def remote_cmd(server, cmd, env=None):
|
|||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
logging.info("remote cmd server(%s): %s", server, cmd)
|
||||
if env is None:
|
||||
result = server.run(cmd, hide=False)
|
||||
else:
|
||||
result = server.run(cmd, hide=False, env=env, replace_env=True)
|
||||
with LOCK:
|
||||
if env is None:
|
||||
result = server.run(cmd, hide=False)
|
||||
else:
|
||||
result = server.run(cmd, hide=False, env=env, replace_env=True)
|
||||
if result.exited:
|
||||
raise CoreCommandError(
|
||||
result.exited, result.command, result.stdout, result.stderr
|
||||
)
|
||||
return result.stdout.strip()
|
||||
|
||||
|
||||
def remote_put(server, source, destination):
|
||||
with LOCK:
|
||||
server.put(source, destination)
|
||||
|
|
|
@ -961,7 +961,7 @@ class CoreNode(CoreNodeBase):
|
|||
self.client.check_cmd(["sync"])
|
||||
else:
|
||||
self.net_cmd(["mkdir", "-p", directory])
|
||||
self.server.put(srcname, filename)
|
||||
distributed.remote_put(self.server, srcname, filename)
|
||||
|
||||
def hostfilename(self, filename):
|
||||
"""
|
||||
|
@ -1001,7 +1001,7 @@ class CoreNode(CoreNodeBase):
|
|||
temp.write(contents.encode("utf-8"))
|
||||
temp.close()
|
||||
self.net_cmd(["mkdir", "-m", "%o" % 0o755, "-p", dirname])
|
||||
self.server.put(temp.name, hostfilename)
|
||||
distributed.remote_put(self.server, temp.name, hostfilename)
|
||||
self.net_cmd(["chmod", "%o" % mode, hostfilename])
|
||||
logging.debug(
|
||||
"node(%s) added file: %s; mode: 0%o", self.name, hostfilename, mode
|
||||
|
@ -1023,7 +1023,7 @@ class CoreNode(CoreNodeBase):
|
|||
if mode is not None:
|
||||
os.chmod(hostfilename, mode)
|
||||
else:
|
||||
self.server.put(srcfilename, hostfilename)
|
||||
distributed.remote_put(self.server, srcfilename, hostfilename)
|
||||
if mode is not None:
|
||||
self.net_cmd(["chmod", "%o" % mode, hostfilename])
|
||||
logging.info(
|
||||
|
|
|
@ -525,14 +525,14 @@ class CoreNetwork(CoreNetworkBase):
|
|||
logging.debug(
|
||||
"linkconfig: %s" % ([tc + parent + ["handle", "1:"] + tbf],)
|
||||
)
|
||||
utils.check_cmd(tc + parent + ["handle", "1:"] + tbf)
|
||||
netif.net_cmd(tc + parent + ["handle", "1:"] + tbf)
|
||||
netif.setparam("has_tbf", True)
|
||||
changed = True
|
||||
elif netif.getparam("has_tbf") and bw <= 0:
|
||||
tcd = [] + tc
|
||||
tcd[2] = "delete"
|
||||
if self.up:
|
||||
utils.check_cmd(tcd + parent)
|
||||
netif.net_cmd(tcd + parent)
|
||||
netif.setparam("has_tbf", False)
|
||||
# removing the parent removes the child
|
||||
netif.setparam("has_netem", False)
|
||||
|
@ -575,14 +575,14 @@ class CoreNetwork(CoreNetworkBase):
|
|||
tc[2] = "delete"
|
||||
if self.up:
|
||||
logging.debug("linkconfig: %s" % ([tc + parent + ["handle", "10:"]],))
|
||||
utils.check_cmd(tc + parent + ["handle", "10:"])
|
||||
netif.net_cmd(tc + parent + ["handle", "10:"])
|
||||
netif.setparam("has_netem", False)
|
||||
elif len(netem) > 1:
|
||||
if self.up:
|
||||
logging.debug(
|
||||
"linkconfig: %s" % ([tc + parent + ["handle", "10:"] + netem],)
|
||||
)
|
||||
utils.check_cmd(tc + parent + ["handle", "10:"] + netem)
|
||||
netif.net_cmd(tc + parent + ["handle", "10:"] + netem)
|
||||
netif.setparam("has_netem", True)
|
||||
|
||||
def linknet(self, net):
|
||||
|
|
|
@ -25,8 +25,8 @@ def main():
|
|||
session.set_state(EventTypes.CONFIGURATION_STATE)
|
||||
|
||||
# create local node, switch, and remote nodes
|
||||
node_one = session.add_node()
|
||||
options = NodeOptions()
|
||||
node_one = session.add_node(node_options=options)
|
||||
options.emulation_server = remote
|
||||
node_two = session.add_node(node_options=options)
|
||||
|
||||
|
|
58
daemon/examples/python/distributed_wlan.py
Normal file
58
daemon/examples/python/distributed_wlan.py
Normal file
|
@ -0,0 +1,58 @@
|
|||
import logging
|
||||
import pdb
|
||||
import sys
|
||||
|
||||
from core.emulator.coreemu import CoreEmu
|
||||
from core.emulator.emudata import IpPrefixes, NodeOptions
|
||||
from core.emulator.enumerations import EventTypes, NodeTypes
|
||||
from core.location.mobility import BasicRangeModel
|
||||
|
||||
|
||||
def main():
|
||||
# ip generator for example
|
||||
prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16")
|
||||
|
||||
# create emulator instance for creating sessions and utility methods
|
||||
coreemu = CoreEmu()
|
||||
session = coreemu.create_session()
|
||||
|
||||
# set controlnet
|
||||
# session.options.set_config("controlnet", "172.16.0.0/24")
|
||||
|
||||
# initialize distributed
|
||||
address = sys.argv[1]
|
||||
remote = sys.argv[2]
|
||||
session.address = address
|
||||
session.add_distributed(remote)
|
||||
|
||||
# must be in configuration state for nodes to start, when using "node_add" below
|
||||
session.set_state(EventTypes.CONFIGURATION_STATE)
|
||||
|
||||
# create local node, switch, and remote nodes
|
||||
options = NodeOptions()
|
||||
options.set_position(0, 0)
|
||||
options.emulation_server = remote
|
||||
node_one = session.add_node(node_options=options)
|
||||
wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN)
|
||||
session.mobility.set_model(wlan, BasicRangeModel)
|
||||
node_two = session.add_node(node_options=options)
|
||||
|
||||
# create node interfaces and link
|
||||
interface_one = prefixes.create_interface(node_one)
|
||||
interface_two = prefixes.create_interface(node_two)
|
||||
session.add_link(node_one.id, wlan.id, interface_one=interface_one)
|
||||
session.add_link(node_two.id, wlan.id, interface_one=interface_two)
|
||||
|
||||
# instantiate session
|
||||
session.instantiate()
|
||||
|
||||
# pause script for verification
|
||||
pdb.set_trace()
|
||||
|
||||
# shutdown session
|
||||
coreemu.shutdown()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
main()
|
Loading…
Reference in a new issue