python examples, removed params common local module to avoid confusion, clean things up a bit and added a module doc to help explain the file
This commit is contained in:
parent
7da7ea5d62
commit
d659a5c139
5 changed files with 57 additions and 93 deletions
|
@ -1,14 +1,19 @@
|
|||
import logging
|
||||
import time
|
||||
"""
|
||||
This is a standalone script to run a small WLAN based scenario and will not
|
||||
interact with the GUI.
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
import params
|
||||
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
|
||||
|
||||
NODES = 2
|
||||
|
||||
def example(args):
|
||||
|
||||
def main():
|
||||
# ip generator for example
|
||||
prefixes = IpPrefixes("10.83.0.0/16")
|
||||
|
||||
|
@ -20,13 +25,13 @@ def example(args):
|
|||
session.set_state(EventTypes.CONFIGURATION_STATE)
|
||||
|
||||
# create wlan network node
|
||||
wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN)
|
||||
wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN, _id=100)
|
||||
session.mobility.set_model(wlan, BasicRangeModel)
|
||||
|
||||
# create nodes, must set a position for wlan basic range model
|
||||
options = NodeOptions(model="mdr")
|
||||
options.set_position(0, 0)
|
||||
for _ in range(args.nodes):
|
||||
for _ in range(NODES):
|
||||
node = session.add_node(options=options)
|
||||
interface = prefixes.create_interface(node)
|
||||
session.add_link(node.id, wlan.id, interface_one=interface)
|
||||
|
@ -35,27 +40,17 @@ def example(args):
|
|||
session.instantiate()
|
||||
|
||||
# get nodes for example run
|
||||
first_node = session.get_node(2)
|
||||
last_node = session.get_node(args.nodes + 1)
|
||||
first_node = session.get_node(1)
|
||||
last_node = session.get_node(NODES)
|
||||
address = prefixes.ip4_address(first_node)
|
||||
logging.info("node %s pinging %s", last_node.name, address)
|
||||
output = last_node.cmd(f"ping -c {args.count} {address}")
|
||||
output = last_node.cmd(f"ping -c 3 {address}")
|
||||
logging.info(output)
|
||||
|
||||
# shutdown session
|
||||
coreemu.shutdown()
|
||||
|
||||
|
||||
def main():
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
args = params.parse("wlan")
|
||||
start = time.perf_counter()
|
||||
logging.info(
|
||||
"running wlan example: nodes(%s) ping count(%s)", args.nodes, args.count
|
||||
)
|
||||
example(args)
|
||||
logging.info("elapsed time: %s", time.perf_counter() - start)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue