docs: pass updating python examples to be the same as grpc examples and remove extra cruft to focus on simpler example code alone
This commit is contained in:
parent
828a68a0cd
commit
2b1b027a11
7 changed files with 438 additions and 290 deletions
|
@ -1,10 +1,4 @@
|
|||
"""
|
||||
This is a standalone script to run a small WLAN based scenario and will not
|
||||
interact with the GUI.
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
# required imports
|
||||
from core.emulator.coreemu import CoreEmu
|
||||
from core.emulator.data import IpPrefixes, NodeOptions
|
||||
from core.emulator.enumerations import EventTypes
|
||||
|
@ -12,47 +6,50 @@ from core.location.mobility import BasicRangeModel
|
|||
from core.nodes.base import CoreNode
|
||||
from core.nodes.network import WlanNode
|
||||
|
||||
NODES = 2
|
||||
# ip nerator for example
|
||||
ip_prefixes = IpPrefixes(ip4_prefix="10.0.0.0/24")
|
||||
|
||||
# create emulator instance for creating sessions and utility methods
|
||||
coreemu = CoreEmu()
|
||||
session = coreemu.create_session()
|
||||
|
||||
def main():
|
||||
# ip generator for example
|
||||
prefixes = IpPrefixes("10.83.0.0/16")
|
||||
# must be in configuration state for nodes to start, when using "node_add" below
|
||||
session.set_state(EventTypes.CONFIGURATION_STATE)
|
||||
|
||||
# create emulator instance for creating sessions and utility methods
|
||||
coreemu = CoreEmu()
|
||||
session = coreemu.create_session()
|
||||
# create wlan
|
||||
options = NodeOptions(x=200, y=200)
|
||||
wlan = session.add_node(WlanNode, options=options)
|
||||
|
||||
# must be in configuration state for nodes to start, when using "node_add" below
|
||||
session.set_state(EventTypes.CONFIGURATION_STATE)
|
||||
# create nodes
|
||||
options = NodeOptions(model="mdr", x=100, y=100)
|
||||
n1 = session.add_node(CoreNode, options=options)
|
||||
options = NodeOptions(model="mdr", x=300, y=100)
|
||||
n2 = session.add_node(CoreNode, options=options)
|
||||
|
||||
# create wlan network node
|
||||
wlan = session.add_node(WlanNode, _id=100)
|
||||
session.mobility.set_model(wlan, BasicRangeModel)
|
||||
# configuring wlan
|
||||
session.mobility.set_model_config(
|
||||
wlan.id,
|
||||
BasicRangeModel.name,
|
||||
{
|
||||
"range": "280",
|
||||
"bandwidth": "55000000",
|
||||
"delay": "6000",
|
||||
"jitter": "5",
|
||||
"error": "5",
|
||||
},
|
||||
)
|
||||
|
||||
# create nodes, must set a position for wlan basic range model
|
||||
options = NodeOptions(model="mdr")
|
||||
options.set_position(0, 0)
|
||||
for _ in range(NODES):
|
||||
node = session.add_node(CoreNode, options=options)
|
||||
interface = prefixes.create_iface(node)
|
||||
session.add_link(node.id, wlan.id, iface1_data=interface)
|
||||
# link nodes to wlan
|
||||
iface1 = ip_prefixes.create_iface(n1)
|
||||
session.add_link(n1.id, wlan.id, iface1)
|
||||
iface1 = ip_prefixes.create_iface(n2)
|
||||
session.add_link(n2.id, wlan.id, iface1)
|
||||
|
||||
# instantiate session
|
||||
session.instantiate()
|
||||
# start session
|
||||
session.instantiate()
|
||||
|
||||
# get nodes for example run
|
||||
first_node = session.get_node(1, CoreNode)
|
||||
last_node = session.get_node(NODES, CoreNode)
|
||||
address = prefixes.ip4_address(first_node.id)
|
||||
logging.info("node %s pinging %s", last_node.name, address)
|
||||
output = last_node.cmd(f"ping -c 3 {address}")
|
||||
logging.info(output)
|
||||
# do whatever you like here
|
||||
input("press enter to shutdown")
|
||||
|
||||
# shutdown session
|
||||
coreemu.shutdown()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
main()
|
||||
# stop session
|
||||
session.shutdown()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue