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
35
daemon/examples/python/peertopeer.py
Normal file
35
daemon/examples/python/peertopeer.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
# required imports
|
||||
from core.emulator.coreemu import CoreEmu
|
||||
from core.emulator.data import IpPrefixes, NodeOptions
|
||||
from core.emulator.enumerations import EventTypes
|
||||
from core.nodes.base import CoreNode
|
||||
|
||||
# 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()
|
||||
|
||||
# must be in configuration state for nodes to start, when using "node_add" below
|
||||
session.set_state(EventTypes.CONFIGURATION_STATE)
|
||||
|
||||
# create nodes
|
||||
options = NodeOptions(x=100, y=100)
|
||||
n1 = session.add_node(CoreNode, options=options)
|
||||
options = NodeOptions(x=300, y=100)
|
||||
n2 = session.add_node(CoreNode, options=options)
|
||||
|
||||
# link nodes together
|
||||
iface1 = ip_prefixes.create_iface(n1)
|
||||
iface2 = ip_prefixes.create_iface(n2)
|
||||
session.add_link(n1.id, n2.id, iface1, iface2)
|
||||
|
||||
# start session
|
||||
session.instantiate()
|
||||
|
||||
# do whatever you like here
|
||||
input("press enter to shutdown")
|
||||
|
||||
# stop session
|
||||
session.shutdown()
|
Loading…
Add table
Add a link
Reference in a new issue