daemon/grpc/gui: further updates for a new working wireless node, added grpc support for control and additions to gui for creation
This commit is contained in:
parent
e4a6ecf3c2
commit
84acb82c18
19 changed files with 399 additions and 90 deletions
29
daemon/examples/grpc/wireless.py
Normal file
29
daemon/examples/grpc/wireless.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
from core.api.grpc import client
|
||||
from core.api.grpc.wrappers import NodeType, Position
|
||||
|
||||
# interface helper
|
||||
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
||||
|
||||
# create grpc client and connect
|
||||
core = client.CoreGrpcClient()
|
||||
core.connect()
|
||||
|
||||
# add session
|
||||
session = core.create_session()
|
||||
|
||||
# create nodes
|
||||
position = Position(x=200, y=200)
|
||||
wlan = session.add_node(1, _type=NodeType.WIRELESS, position=position)
|
||||
position = Position(x=100, y=100)
|
||||
node1 = session.add_node(2, model="mdr", position=position)
|
||||
position = Position(x=300, y=100)
|
||||
node2 = session.add_node(3, model="mdr", position=position)
|
||||
|
||||
# create links
|
||||
iface1 = iface_helper.create_iface(node1.id, 0)
|
||||
session.add_link(node1=node1, node2=wlan, iface1=iface1)
|
||||
iface1 = iface_helper.create_iface(node2.id, 0)
|
||||
session.add_link(node1=node2, node2=wlan, iface1=iface1)
|
||||
|
||||
# start session
|
||||
core.start_session(session)
|
46
daemon/examples/python/wireless.py
Normal file
46
daemon/examples/python/wireless.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
# required imports
|
||||
import logging
|
||||
|
||||
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
|
||||
from core.nodes.network import WlanNode
|
||||
|
||||
# enable info logging
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
# 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
|
||||
session.set_state(EventTypes.CONFIGURATION_STATE)
|
||||
|
||||
# create wireless
|
||||
options = NodeOptions(x=200, y=200)
|
||||
wireless = session.add_node(WlanNode, options=options)
|
||||
|
||||
# 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)
|
||||
|
||||
# link nodes to wireless
|
||||
iface1 = ip_prefixes.create_iface(n1)
|
||||
session.add_link(n1.id, wireless.id, iface1)
|
||||
iface1 = ip_prefixes.create_iface(n2)
|
||||
session.add_link(n2.id, wireless.id, iface1)
|
||||
|
||||
# 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