docs: pass on improving and providing doc based examples for common basic use cases, fixed issue with grpc defaulting session refscale to a very large number
This commit is contained in:
parent
9ea1915f48
commit
828a68a0cd
8 changed files with 478 additions and 208 deletions
|
@ -112,7 +112,7 @@ from core.emulator.session import NT, Session
|
||||||
from core.errors import CoreCommandError, CoreError
|
from core.errors import CoreCommandError, CoreError
|
||||||
from core.location.mobility import BasicRangeModel, Ns2ScriptedMobility
|
from core.location.mobility import BasicRangeModel, Ns2ScriptedMobility
|
||||||
from core.nodes.base import CoreNode, NodeBase
|
from core.nodes.base import CoreNode, NodeBase
|
||||||
from core.nodes.network import PtpNet, WlanNode
|
from core.nodes.network import CtrlNet, PtpNet, WlanNode
|
||||||
from core.services.coreservices import ServiceManager
|
from core.services.coreservices import ServiceManager
|
||||||
|
|
||||||
_ONE_DAY_IN_SECONDS: int = 60 * 60 * 24
|
_ONE_DAY_IN_SECONDS: int = 60 * 60 * 24
|
||||||
|
@ -335,7 +335,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
session = self.coreemu.create_session(request.session_id)
|
session = self.coreemu.create_session(request.session_id)
|
||||||
session.set_state(EventTypes.DEFINITION_STATE)
|
session.set_state(EventTypes.DEFINITION_STATE)
|
||||||
session.location.setrefgeo(47.57917, -122.13232, 2.0)
|
session.location.setrefgeo(47.57917, -122.13232, 2.0)
|
||||||
session.location.refscale = 150000.0
|
session.location.refscale = 150.0
|
||||||
return core_pb2.CreateSessionResponse(
|
return core_pb2.CreateSessionResponse(
|
||||||
session_id=session.id, state=session.state.value
|
session_id=session.id, state=session.state.value
|
||||||
)
|
)
|
||||||
|
@ -556,7 +556,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
nodes = []
|
nodes = []
|
||||||
for _id in session.nodes:
|
for _id in session.nodes:
|
||||||
node = session.nodes[_id]
|
node = session.nodes[_id]
|
||||||
if not isinstance(node, PtpNet):
|
if not isinstance(node, (PtpNet, CtrlNet)):
|
||||||
node_proto = grpcutils.get_node_proto(session, node)
|
node_proto = grpcutils.get_node_proto(session, node)
|
||||||
nodes.append(node_proto)
|
nodes.append(node_proto)
|
||||||
node_links = get_links(node)
|
node_links = get_links(node)
|
||||||
|
|
|
@ -1,74 +1,51 @@
|
||||||
"""
|
# required imports
|
||||||
Example using gRPC API to create a simple EMANE 80211 network.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from core.api.grpc import client
|
from core.api.grpc import client
|
||||||
from core.api.grpc.core_pb2 import Node, NodeType, Position, SessionState
|
from core.api.grpc.core_pb2 import Node, NodeType, Position, SessionState
|
||||||
from core.emane.ieee80211abg import EmaneIeee80211abgModel
|
from core.emane.ieee80211abg import EmaneIeee80211abgModel
|
||||||
|
|
||||||
|
# interface helper
|
||||||
|
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
||||||
|
|
||||||
def log_event(event):
|
# create grpc client and connect
|
||||||
logging.info("event: %s", event)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
# helper to create interface addresses
|
|
||||||
interface_helper = client.InterfaceHelper(ip4_prefix="10.83.0.0/24")
|
|
||||||
|
|
||||||
# create grpc client and start connection context, which auto closes connection
|
|
||||||
core = client.CoreGrpcClient()
|
core = client.CoreGrpcClient()
|
||||||
with core.context_connect():
|
core.connect()
|
||||||
# create session
|
|
||||||
response = core.create_session()
|
|
||||||
logging.info("created session: %s", response)
|
|
||||||
|
|
||||||
# handle events session may broadcast
|
# create session and get id
|
||||||
|
response = core.create_session()
|
||||||
session_id = response.session_id
|
session_id = response.session_id
|
||||||
core.events(session_id, log_event)
|
|
||||||
|
|
||||||
# change session state to configuration so that nodes get started when added
|
# change session state to configuration so that nodes get started when added
|
||||||
response = core.set_session_state(session_id, SessionState.CONFIGURATION)
|
core.set_session_state(session_id, SessionState.CONFIGURATION)
|
||||||
logging.info("set session state: %s", response)
|
|
||||||
|
|
||||||
# create emane node
|
# create emane node
|
||||||
position = Position(x=200, y=200)
|
position = Position(x=200, y=200)
|
||||||
emane = Node(type=NodeType.EMANE, position=position)
|
emane = Node(type=NodeType.EMANE, position=position, emane=EmaneIeee80211abgModel.name)
|
||||||
response = core.add_node(session_id, emane)
|
response = core.add_node(session_id, emane)
|
||||||
logging.info("created emane: %s", response)
|
|
||||||
emane_id = response.node_id
|
emane_id = response.node_id
|
||||||
|
|
||||||
# an emane model must be configured for use, by the emane node
|
|
||||||
core.set_emane_model_config(session_id, emane_id, EmaneIeee80211abgModel.name)
|
|
||||||
|
|
||||||
# create node one
|
# create node one
|
||||||
position = Position(x=100, y=100)
|
position = Position(x=100, y=100)
|
||||||
node1 = Node(type=NodeType.DEFAULT, position=position)
|
n1 = Node(type=NodeType.DEFAULT, position=position, model="mdr")
|
||||||
response = core.add_node(session_id, node1)
|
response = core.add_node(session_id, n1)
|
||||||
logging.info("created node: %s", response)
|
n1_id = response.node_id
|
||||||
node1_id = response.node_id
|
|
||||||
|
|
||||||
# create node two
|
# create node two
|
||||||
position = Position(x=300, y=100)
|
position = Position(x=300, y=100)
|
||||||
node2 = Node(type=NodeType.DEFAULT, position=position)
|
n2 = Node(type=NodeType.DEFAULT, position=position, model="mdr")
|
||||||
response = core.add_node(session_id, node2)
|
response = core.add_node(session_id, n2)
|
||||||
logging.info("created node: %s", response)
|
n2_id = response.node_id
|
||||||
node2_id = response.node_id
|
|
||||||
|
|
||||||
# links nodes to switch
|
# configure general emane settings
|
||||||
interface1 = interface_helper.create_iface(node1_id, 0)
|
core.set_emane_config(session_id, {"eventservicettl": "2"})
|
||||||
response = core.add_link(session_id, node1_id, emane_id, interface1)
|
|
||||||
logging.info("created link: %s", response)
|
|
||||||
interface1 = interface_helper.create_iface(node2_id, 0)
|
|
||||||
response = core.add_link(session_id, node2_id, emane_id, interface1)
|
|
||||||
logging.info("created link: %s", response)
|
|
||||||
|
|
||||||
# change session state
|
# configure emane model settings
|
||||||
response = core.set_session_state(session_id, SessionState.INSTANTIATION)
|
# using a dict mapping currently support values as strings
|
||||||
logging.info("set session state: %s", response)
|
core.set_emane_model_config(
|
||||||
|
session_id, emane_id, EmaneIeee80211abgModel.name, {"unicastrate": "3"}
|
||||||
|
)
|
||||||
|
|
||||||
|
# links nodes to emane
|
||||||
if __name__ == "__main__":
|
iface1 = iface_helper.create_iface(n1_id, 0)
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
core.add_link(session_id, n1_id, emane_id, iface1)
|
||||||
main()
|
iface1 = iface_helper.create_iface(n2_id, 0)
|
||||||
|
core.add_link(session_id, n2_id, emane_id, iface1)
|
||||||
|
|
36
daemon/examples/grpc/peertopeer.py
Normal file
36
daemon/examples/grpc/peertopeer.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
from core.api.grpc import client
|
||||||
|
from core.api.grpc.core_pb2 import Node, NodeType, Position, SessionState
|
||||||
|
|
||||||
|
# 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()
|
||||||
|
|
||||||
|
# create session and get id
|
||||||
|
response = core.create_session()
|
||||||
|
session_id = response.session_id
|
||||||
|
|
||||||
|
# change session state to configuration so that nodes get started when added
|
||||||
|
core.set_session_state(session_id, SessionState.CONFIGURATION)
|
||||||
|
|
||||||
|
# create node one
|
||||||
|
position = Position(x=100, y=100)
|
||||||
|
n1 = Node(type=NodeType.DEFAULT, position=position, model="PC")
|
||||||
|
response = core.add_node(session_id, n1)
|
||||||
|
n1_id = response.node_id
|
||||||
|
|
||||||
|
# create node two
|
||||||
|
position = Position(x=300, y=100)
|
||||||
|
n2 = Node(type=NodeType.DEFAULT, position=position, model="PC")
|
||||||
|
response = core.add_node(session_id, n2)
|
||||||
|
n2_id = response.node_id
|
||||||
|
|
||||||
|
# links nodes together
|
||||||
|
iface1 = iface_helper.create_iface(n1_id, 0)
|
||||||
|
iface2 = iface_helper.create_iface(n2_id, 0)
|
||||||
|
core.add_link(session_id, n1_id, n2_id, iface1, iface2)
|
||||||
|
|
||||||
|
# change session state
|
||||||
|
core.set_session_state(session_id, SessionState.INSTANTIATION)
|
|
@ -1,70 +1,44 @@
|
||||||
"""
|
# required imports
|
||||||
Example using gRPC API to create a simple switch network.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from core.api.grpc import client
|
from core.api.grpc import client
|
||||||
from core.api.grpc.core_pb2 import Node, NodeType, Position, SessionState
|
from core.api.grpc.core_pb2 import Node, NodeType, Position, SessionState
|
||||||
|
|
||||||
|
# interface helper
|
||||||
|
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
||||||
|
|
||||||
def log_event(event):
|
# create grpc client and connect
|
||||||
logging.info("event: %s", event)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
# helper to create interface addresses
|
|
||||||
interface_helper = client.InterfaceHelper(ip4_prefix="10.83.0.0/24")
|
|
||||||
|
|
||||||
# create grpc client and start connection context, which auto closes connection
|
|
||||||
core = client.CoreGrpcClient()
|
core = client.CoreGrpcClient()
|
||||||
with core.context_connect():
|
core.connect()
|
||||||
# create session
|
|
||||||
response = core.create_session()
|
|
||||||
logging.info("created session: %s", response)
|
|
||||||
|
|
||||||
# handle events session may broadcast
|
# create session and get id
|
||||||
|
response = core.create_session()
|
||||||
session_id = response.session_id
|
session_id = response.session_id
|
||||||
core.events(session_id, log_event)
|
|
||||||
|
|
||||||
# change session state to configuration so that nodes get started when added
|
# change session state to configuration so that nodes get started when added
|
||||||
response = core.set_session_state(session_id, SessionState.CONFIGURATION)
|
core.set_session_state(session_id, SessionState.CONFIGURATION)
|
||||||
logging.info("set session state: %s", response)
|
|
||||||
|
|
||||||
# create switch node
|
# create switch node
|
||||||
position = Position(x=200, y=200)
|
position = Position(x=200, y=200)
|
||||||
switch = Node(type=NodeType.SWITCH, position=position)
|
switch = Node(type=NodeType.SWITCH, position=position)
|
||||||
response = core.add_node(session_id, switch)
|
response = core.add_node(session_id, switch)
|
||||||
logging.info("created switch: %s", response)
|
|
||||||
switch_id = response.node_id
|
switch_id = response.node_id
|
||||||
|
|
||||||
# create node one
|
# create node one
|
||||||
position = Position(x=100, y=100)
|
position = Position(x=100, y=100)
|
||||||
node1 = Node(type=NodeType.DEFAULT, position=position, model="PC")
|
n1 = Node(type=NodeType.DEFAULT, position=position, model="PC")
|
||||||
response = core.add_node(session_id, node1)
|
response = core.add_node(session_id, n1)
|
||||||
logging.info("created node: %s", response)
|
n1_id = response.node_id
|
||||||
node1_id = response.node_id
|
|
||||||
|
|
||||||
# create node two
|
# create node two
|
||||||
position = Position(x=300, y=100)
|
position = Position(x=300, y=100)
|
||||||
node2 = Node(type=NodeType.DEFAULT, position=position, model="PC")
|
n2 = Node(type=NodeType.DEFAULT, position=position, model="PC")
|
||||||
response = core.add_node(session_id, node2)
|
response = core.add_node(session_id, n2)
|
||||||
logging.info("created node: %s", response)
|
n2_id = response.node_id
|
||||||
node2_id = response.node_id
|
|
||||||
|
|
||||||
# links nodes to switch
|
# links nodes to switch
|
||||||
interface1 = interface_helper.create_iface(node1_id, 0)
|
iface1 = iface_helper.create_iface(n1_id, 0)
|
||||||
response = core.add_link(session_id, node1_id, switch_id, interface1)
|
core.add_link(session_id, n1_id, switch_id, iface1)
|
||||||
logging.info("created link: %s", response)
|
iface1 = iface_helper.create_iface(n2_id, 0)
|
||||||
interface1 = interface_helper.create_iface(node2_id, 0)
|
core.add_link(session_id, n2_id, switch_id, iface1)
|
||||||
response = core.add_link(session_id, node2_id, switch_id, interface1)
|
|
||||||
logging.info("created link: %s", response)
|
|
||||||
|
|
||||||
# change session state
|
# change session state
|
||||||
response = core.set_session_state(session_id, SessionState.INSTANTIATION)
|
core.set_session_state(session_id, SessionState.INSTANTIATION)
|
||||||
logging.info("set session state: %s", response)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
|
||||||
main()
|
|
||||||
|
|
|
@ -1,82 +1,58 @@
|
||||||
"""
|
# required imports
|
||||||
Example using gRPC API to create a simple wlan network.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from core.api.grpc import client
|
from core.api.grpc import client
|
||||||
from core.api.grpc.core_pb2 import Node, NodeType, Position, SessionState
|
from core.api.grpc.core_pb2 import Node, NodeType, Position, SessionState
|
||||||
|
|
||||||
|
# interface helper
|
||||||
|
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
||||||
|
|
||||||
def log_event(event):
|
# create grpc client and connect
|
||||||
logging.info("event: %s", event)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
# helper to create interface addresses
|
|
||||||
interface_helper = client.InterfaceHelper(ip4_prefix="10.83.0.0/24")
|
|
||||||
|
|
||||||
# create grpc client and start connection context, which auto closes connection
|
|
||||||
core = client.CoreGrpcClient()
|
core = client.CoreGrpcClient()
|
||||||
with core.context_connect():
|
core.connect()
|
||||||
# create session
|
|
||||||
response = core.create_session()
|
|
||||||
logging.info("created session: %s", response)
|
|
||||||
|
|
||||||
# handle events session may broadcast
|
# create session and get id
|
||||||
|
response = core.create_session()
|
||||||
session_id = response.session_id
|
session_id = response.session_id
|
||||||
core.events(session_id, log_event)
|
|
||||||
|
|
||||||
# change session state to configuration so that nodes get started when added
|
# change session state to configuration so that nodes get started when added
|
||||||
response = core.set_session_state(session_id, SessionState.CONFIGURATION)
|
core.set_session_state(session_id, SessionState.CONFIGURATION)
|
||||||
logging.info("set session state: %s", response)
|
|
||||||
|
|
||||||
# create wlan node
|
# create wlan node
|
||||||
position = Position(x=200, y=200)
|
position = Position(x=200, y=200)
|
||||||
wlan = Node(type=NodeType.WIRELESS_LAN, position=position)
|
wlan = Node(type=NodeType.WIRELESS_LAN, position=position)
|
||||||
response = core.add_node(session_id, wlan)
|
response = core.add_node(session_id, wlan)
|
||||||
logging.info("created wlan: %s", response)
|
|
||||||
wlan_id = response.node_id
|
wlan_id = response.node_id
|
||||||
|
|
||||||
# change/configure wlan if desired
|
|
||||||
# NOTE: error = loss, and named this way for legacy purposes for now
|
|
||||||
config = {
|
|
||||||
"bandwidth": "54000000",
|
|
||||||
"range": "500",
|
|
||||||
"jitter": "0",
|
|
||||||
"delay": "5000",
|
|
||||||
"error": "0",
|
|
||||||
}
|
|
||||||
response = core.set_wlan_config(session_id, wlan_id, config)
|
|
||||||
logging.info("set wlan config: %s", response)
|
|
||||||
|
|
||||||
# create node one
|
# create node one
|
||||||
position = Position(x=100, y=100)
|
position = Position(x=100, y=100)
|
||||||
node1 = Node(type=NodeType.DEFAULT, position=position)
|
n1 = Node(type=NodeType.DEFAULT, position=position, model="mdr")
|
||||||
response = core.add_node(session_id, node1)
|
response = core.add_node(session_id, n1)
|
||||||
logging.info("created node: %s", response)
|
n1_id = response.node_id
|
||||||
node1_id = response.node_id
|
|
||||||
|
|
||||||
# create node two
|
# create node two
|
||||||
position = Position(x=300, y=100)
|
position = Position(x=300, y=100)
|
||||||
node2 = Node(type=NodeType.DEFAULT, position=position)
|
n2 = Node(type=NodeType.DEFAULT, position=position, model="mdr")
|
||||||
response = core.add_node(session_id, node2)
|
response = core.add_node(session_id, n2)
|
||||||
logging.info("created node: %s", response)
|
n2_id = response.node_id
|
||||||
node2_id = response.node_id
|
|
||||||
|
|
||||||
# links nodes to switch
|
# configure wlan using a dict mapping currently
|
||||||
interface1 = interface_helper.create_iface(node1_id, 0)
|
# support values as strings
|
||||||
response = core.add_link(session_id, node1_id, wlan_id, interface1)
|
core.set_wlan_config(
|
||||||
logging.info("created link: %s", response)
|
session_id,
|
||||||
interface1 = interface_helper.create_iface(node2_id, 0)
|
wlan_id,
|
||||||
response = core.add_link(session_id, node2_id, wlan_id, interface1)
|
{
|
||||||
logging.info("created link: %s", response)
|
"range": "280",
|
||||||
|
"bandwidth": "55000000",
|
||||||
|
"delay": "6000",
|
||||||
|
"jitter": "5",
|
||||||
|
"error": "5",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
# links nodes to wlan
|
||||||
|
iface1 = iface_helper.create_iface(n1_id, 0)
|
||||||
|
core.add_link(session_id, n1_id, wlan_id, iface1)
|
||||||
|
iface1 = iface_helper.create_iface(n2_id, 0)
|
||||||
|
core.add_link(session_id, n2_id, wlan_id, iface1)
|
||||||
|
|
||||||
# change session state
|
# change session state
|
||||||
response = core.set_session_state(session_id, SessionState.INSTANTIATION)
|
core.set_session_state(session_id, SessionState.INSTANTIATION)
|
||||||
logging.info("set session state: %s", response)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
|
||||||
main()
|
|
||||||
|
|
330
docs/grpc.md
330
docs/grpc.md
|
@ -1,16 +1,15 @@
|
||||||
# Using the gRPC API
|
# gRPC API
|
||||||
|
|
||||||
[gRPC](https://grpc.io/) is the main API for interfacing with CORE and used by
|
* Table of Contents
|
||||||
the python GUI for driving all functionality.
|
{:toc}
|
||||||
|
|
||||||
Currently we are providing a python client that wraps the generated files for
|
[gRPC](https://grpc.io/) is a client/server API for interfacing with CORE
|
||||||
leveraging the API, but proto files noted below can also be leveraged to generate
|
and used by the python GUI for driving all functionality. It is dependent
|
||||||
bindings for other languages as well.
|
on having a running `core-daemon` instance to be leveraged.
|
||||||
|
|
||||||
## HTTP Proxy
|
A python client can be created from the raw generated grpc files included
|
||||||
|
with CORE or one can leverage a provided gRPC client that helps encapsulate
|
||||||
Since gRPC is HTTP2 based, proxy configurations can cause issue. You can either
|
some of the functionality to try and help make things easier.
|
||||||
properly account for this issue or clear out your proxy when running if needed.
|
|
||||||
|
|
||||||
## Python Client
|
## Python Client
|
||||||
|
|
||||||
|
@ -18,6 +17,12 @@ A python client wrapper is provided at
|
||||||
[CoreGrpcClient](https://github.com/coreemu/core/blob/master/daemon/core/api/grpc/client.py)
|
[CoreGrpcClient](https://github.com/coreemu/core/blob/master/daemon/core/api/grpc/client.py)
|
||||||
to help provide some conveniences when using the API.
|
to help provide some conveniences when using the API.
|
||||||
|
|
||||||
|
### Client HTTP Proxy
|
||||||
|
|
||||||
|
Since gRPC is HTTP2 based, proxy configurations can cause issues. By default
|
||||||
|
the client disables proxy support to avoid issues when a proxy is present.
|
||||||
|
You can enable and properly account for this issue when needed.
|
||||||
|
|
||||||
## Proto Files
|
## Proto Files
|
||||||
|
|
||||||
Proto files are used to define the API and protobuf messages that are used for
|
Proto files are used to define the API and protobuf messages that are used for
|
||||||
|
@ -30,7 +35,310 @@ what is going on and response message values that would be returned.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
Example usage of this API can be found
|
### Node Models
|
||||||
|
|
||||||
|
When creating nodes of type `NodeType.DEFAULT` these are the default models
|
||||||
|
and the services they map to.
|
||||||
|
|
||||||
|
* mdr
|
||||||
|
* zebra, OSPFv3MDR, IPForward
|
||||||
|
* PC
|
||||||
|
* DefaultRoute
|
||||||
|
* router
|
||||||
|
* zebra, OSPFv2, OSPFv3, IPForward
|
||||||
|
* host
|
||||||
|
* DefaultRoute, SSH
|
||||||
|
|
||||||
|
### Interface Helper
|
||||||
|
|
||||||
|
There is an interface helper class that can be leveraged for convenience
|
||||||
|
when creating interface data for nodes. Alternatively one can manually create
|
||||||
|
a `core.api.grpc.core_pb2.Interface` class instead with appropriate information.
|
||||||
|
|
||||||
|
Manually creating gRPC interface data:
|
||||||
|
```python
|
||||||
|
from core.api.grpc import core_pb2
|
||||||
|
# id is optional and will set to the next available id
|
||||||
|
# name is optional and will default to eth<id>
|
||||||
|
# mac is optional and will result in a randomly generated mac
|
||||||
|
iface_data = core_pb2.Interface(
|
||||||
|
id=0,
|
||||||
|
name="eth0",
|
||||||
|
ip4="10.0.0.1",
|
||||||
|
ip4_mask=24,
|
||||||
|
ip6="2001::",
|
||||||
|
ip6_mask=64,
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
Leveraging the interface helper class:
|
||||||
|
```python
|
||||||
|
from core.api.grpc import client
|
||||||
|
|
||||||
|
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
||||||
|
# node_id is used to get an ip4/ip6 address indexed from within the above prefixes
|
||||||
|
# face_id is required and used exactly for that
|
||||||
|
# name is optional and would default to eth<id>
|
||||||
|
# mac is optional and will result in a randomly generated mac
|
||||||
|
iface_data = iface_helper.create_iface(
|
||||||
|
node_id=1, iface_id=0, name="eth0", mac="00:00:00:00:aa:00"
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Listening to Events
|
||||||
|
|
||||||
|
TBD
|
||||||
|
|
||||||
|
### Configuring Links
|
||||||
|
|
||||||
|
TBD
|
||||||
|
|
||||||
|
### Peer to Peer Example
|
||||||
|
```python
|
||||||
|
# required imports
|
||||||
|
from core.api.grpc import client
|
||||||
|
from core.api.grpc.core_pb2 import Node, NodeType, Position, SessionState
|
||||||
|
|
||||||
|
# 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()
|
||||||
|
|
||||||
|
# create session and get id
|
||||||
|
response = core.create_session()
|
||||||
|
session_id = response.session_id
|
||||||
|
|
||||||
|
# change session state to configuration so that nodes get started when added
|
||||||
|
core.set_session_state(session_id, SessionState.CONFIGURATION)
|
||||||
|
|
||||||
|
# create node one
|
||||||
|
position = Position(x=100, y=100)
|
||||||
|
n1 = Node(type=NodeType.DEFAULT, position=position, model="PC")
|
||||||
|
response = core.add_node(session_id, n1)
|
||||||
|
n1_id = response.node_id
|
||||||
|
|
||||||
|
# create node two
|
||||||
|
position = Position(x=300, y=100)
|
||||||
|
n2 = Node(type=NodeType.DEFAULT, position=position, model="PC")
|
||||||
|
response = core.add_node(session_id, n2)
|
||||||
|
n2_id = response.node_id
|
||||||
|
|
||||||
|
# links nodes together
|
||||||
|
iface1 = iface_helper.create_iface(n1_id, 0)
|
||||||
|
iface2 = iface_helper.create_iface(n2_id, 0)
|
||||||
|
core.add_link(session_id, n1_id, n2_id, iface1, iface2)
|
||||||
|
|
||||||
|
# change session state
|
||||||
|
core.set_session_state(session_id, SessionState.INSTANTIATION)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Switch/Hub Example
|
||||||
|
```python
|
||||||
|
# required imports
|
||||||
|
from core.api.grpc import client
|
||||||
|
from core.api.grpc.core_pb2 import Node, NodeType, Position, SessionState
|
||||||
|
|
||||||
|
# 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()
|
||||||
|
|
||||||
|
# create session and get id
|
||||||
|
response = core.create_session()
|
||||||
|
session_id = response.session_id
|
||||||
|
|
||||||
|
# change session state to configuration so that nodes get started when added
|
||||||
|
core.set_session_state(session_id, SessionState.CONFIGURATION)
|
||||||
|
|
||||||
|
# create switch node
|
||||||
|
position = Position(x=200, y=200)
|
||||||
|
switch = Node(type=NodeType.SWITCH, position=position)
|
||||||
|
response = core.add_node(session_id, switch)
|
||||||
|
switch_id = response.node_id
|
||||||
|
|
||||||
|
# create node one
|
||||||
|
position = Position(x=100, y=100)
|
||||||
|
n1 = Node(type=NodeType.DEFAULT, position=position, model="PC")
|
||||||
|
response = core.add_node(session_id, n1)
|
||||||
|
n1_id = response.node_id
|
||||||
|
|
||||||
|
# create node two
|
||||||
|
position = Position(x=300, y=100)
|
||||||
|
n2 = Node(type=NodeType.DEFAULT, position=position, model="PC")
|
||||||
|
response = core.add_node(session_id, n2)
|
||||||
|
n2_id = response.node_id
|
||||||
|
|
||||||
|
# links nodes to switch
|
||||||
|
iface1 = iface_helper.create_iface(n1_id, 0)
|
||||||
|
core.add_link(session_id, n1_id, switch_id, iface1)
|
||||||
|
iface1 = iface_helper.create_iface(n2_id, 0)
|
||||||
|
core.add_link(session_id, n2_id, switch_id, iface1)
|
||||||
|
|
||||||
|
# change session state
|
||||||
|
core.set_session_state(session_id, SessionState.INSTANTIATION)
|
||||||
|
```
|
||||||
|
|
||||||
|
### WLAN Example
|
||||||
|
```python
|
||||||
|
# required imports
|
||||||
|
from core.api.grpc import client
|
||||||
|
from core.api.grpc.core_pb2 import Node, NodeType, Position, SessionState
|
||||||
|
|
||||||
|
# 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()
|
||||||
|
|
||||||
|
# create session and get id
|
||||||
|
response = core.create_session()
|
||||||
|
session_id = response.session_id
|
||||||
|
|
||||||
|
# change session state to configuration so that nodes get started when added
|
||||||
|
core.set_session_state(session_id, SessionState.CONFIGURATION)
|
||||||
|
|
||||||
|
# create wlan node
|
||||||
|
position = Position(x=200, y=200)
|
||||||
|
wlan = Node(type=NodeType.WIRELESS_LAN, position=position)
|
||||||
|
response = core.add_node(session_id, wlan)
|
||||||
|
wlan_id = response.node_id
|
||||||
|
|
||||||
|
# create node one
|
||||||
|
position = Position(x=100, y=100)
|
||||||
|
n1 = Node(type=NodeType.DEFAULT, position=position, model="mdr")
|
||||||
|
response = core.add_node(session_id, n1)
|
||||||
|
n1_id = response.node_id
|
||||||
|
|
||||||
|
# create node two
|
||||||
|
position = Position(x=300, y=100)
|
||||||
|
n2 = Node(type=NodeType.DEFAULT, position=position, model="mdr")
|
||||||
|
response = core.add_node(session_id, n2)
|
||||||
|
n2_id = response.node_id
|
||||||
|
|
||||||
|
# configure wlan using a dict mapping currently
|
||||||
|
# support values as strings
|
||||||
|
core.set_wlan_config(session_id, wlan_id, {
|
||||||
|
"range": "280",
|
||||||
|
"bandwidth": "55000000",
|
||||||
|
"delay": "6000",
|
||||||
|
"jitter": "5",
|
||||||
|
"error": "5",
|
||||||
|
})
|
||||||
|
|
||||||
|
# links nodes to wlan
|
||||||
|
iface1 = iface_helper.create_iface(n1_id, 0)
|
||||||
|
core.add_link(session_id, n1_id, wlan_id, iface1)
|
||||||
|
iface1 = iface_helper.create_iface(n2_id, 0)
|
||||||
|
core.add_link(session_id, n2_id, wlan_id, iface1)
|
||||||
|
|
||||||
|
# change session state
|
||||||
|
core.set_session_state(session_id, SessionState.INSTANTIATION)
|
||||||
|
```
|
||||||
|
|
||||||
|
### EMANE Example
|
||||||
|
|
||||||
|
For EMANE you can import and use one of the existing models and
|
||||||
|
use its name for configuration.
|
||||||
|
|
||||||
|
Current models:
|
||||||
|
* core.emane.ieee80211abg.EmaneIeee80211abgModel
|
||||||
|
* core.emane.rfpipe.EmaneRfPipeModel
|
||||||
|
* core.emane.tdma.EmaneTdmaModel
|
||||||
|
* core.emane.bypass.EmaneBypassModel
|
||||||
|
|
||||||
|
Their configurations options are driven dynamically from parsed EMANE manifest files
|
||||||
|
from the installed version of EMANE.
|
||||||
|
|
||||||
|
Options and their purpose can be found at the [EMANE Wiki](https://github.com/adjacentlink/emane/wiki).
|
||||||
|
|
||||||
|
If configuring EMANE global settings or model mac/phy specific settings, any value not provided
|
||||||
|
will use the defaults. When no configuration is used, the defaults are used.
|
||||||
|
|
||||||
|
```python
|
||||||
|
# required imports
|
||||||
|
from core.api.grpc import client
|
||||||
|
from core.api.grpc.core_pb2 import Node, NodeType, Position, SessionState
|
||||||
|
from core.emane.ieee80211abg import EmaneIeee80211abgModel
|
||||||
|
|
||||||
|
# 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()
|
||||||
|
|
||||||
|
# create session and get id
|
||||||
|
response = core.create_session()
|
||||||
|
session_id = response.session_id
|
||||||
|
|
||||||
|
# change session state to configuration so that nodes get started when added
|
||||||
|
core.set_session_state(session_id, SessionState.CONFIGURATION)
|
||||||
|
|
||||||
|
# create emane node
|
||||||
|
position = Position(x=200, y=200)
|
||||||
|
emane = Node(type=NodeType.EMANE, position=position, emane=EmaneIeee80211abgModel.name)
|
||||||
|
response = core.add_node(session_id, emane)
|
||||||
|
emane_id = response.node_id
|
||||||
|
|
||||||
|
# create node one
|
||||||
|
position = Position(x=100, y=100)
|
||||||
|
n1 = Node(type=NodeType.DEFAULT, position=position, model="mdr")
|
||||||
|
response = core.add_node(session_id, n1)
|
||||||
|
n1_id = response.node_id
|
||||||
|
|
||||||
|
# create node two
|
||||||
|
position = Position(x=300, y=100)
|
||||||
|
n2 = Node(type=NodeType.DEFAULT, position=position, model="mdr")
|
||||||
|
response = core.add_node(session_id, n2)
|
||||||
|
n2_id = response.node_id
|
||||||
|
|
||||||
|
# configure general emane settings
|
||||||
|
core.set_emane_config(session_id, {
|
||||||
|
"eventservicettl": "2"
|
||||||
|
})
|
||||||
|
|
||||||
|
# configure emane model settings
|
||||||
|
# using a dict mapping currently support values as strings
|
||||||
|
core.set_emane_model_config(session_id, emane_id, EmaneIeee80211abgModel.name, {
|
||||||
|
"unicastrate": "3",
|
||||||
|
})
|
||||||
|
|
||||||
|
# links nodes to emane
|
||||||
|
iface1 = iface_helper.create_iface(n1_id, 0)
|
||||||
|
core.add_link(session_id, n1_id, emane_id, iface1)
|
||||||
|
iface1 = iface_helper.create_iface(n2_id, 0)
|
||||||
|
core.add_link(session_id, n2_id, emane_id, iface1)
|
||||||
|
|
||||||
|
# change session state
|
||||||
|
core.set_session_state(session_id, SessionState.INSTANTIATION)
|
||||||
|
```
|
||||||
|
|
||||||
|
EMANE Model Configuration:
|
||||||
|
```python
|
||||||
|
# emane network specific config
|
||||||
|
core.set_emane_model_config(session_id, emane_id, EmaneIeee80211abgModel.name, {
|
||||||
|
"unicastrate": "3",
|
||||||
|
})
|
||||||
|
|
||||||
|
# node specific config
|
||||||
|
core.set_emane_model_config(session_id, node_id, EmaneIeee80211abgModel.name, {
|
||||||
|
"unicastrate": "3",
|
||||||
|
})
|
||||||
|
|
||||||
|
# node interface specific config
|
||||||
|
core.set_emane_model_config(session_id, node_id, EmaneIeee80211abgModel.name, {
|
||||||
|
"unicastrate": "3",
|
||||||
|
}, iface_id)
|
||||||
|
```
|
||||||
|
|
||||||
|
## File Examples
|
||||||
|
|
||||||
|
File versions of these examples can be found
|
||||||
[here](https://github.com/coreemu/core/tree/master/daemon/examples/grpc).
|
[here](https://github.com/coreemu/core/tree/master/daemon/examples/grpc).
|
||||||
These examples will create a session using the gRPC API when the core-daemon is running.
|
These examples will create a session using the gRPC API when the core-daemon is running.
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,9 @@ networking scenarios, security studies, and increasing the size of physical test
|
||||||
|[Installation](install.md)|How to install CORE and its requirements|
|
|[Installation](install.md)|How to install CORE and its requirements|
|
||||||
|[GUI](gui.md)|How to use the GUI|
|
|[GUI](gui.md)|How to use the GUI|
|
||||||
|[(BETA) Python GUI](pygui.md)|How to use the BETA python based GUI|
|
|[(BETA) Python GUI](pygui.md)|How to use the BETA python based GUI|
|
||||||
|
|[Python API](python.md)|Covers how to control core directly using python|
|
||||||
|
|[gRPC API](grpc.md)|Covers how control core using gRPC|
|
||||||
|[Distributed](distributed.md)|Details for running CORE across multiple servers|
|
|[Distributed](distributed.md)|Details for running CORE across multiple servers|
|
||||||
|[Python Scripting](scripting.md)|How to write python scripts for creating a CORE session|
|
|
||||||
|[gRPC API](grpc.md)|How to enable and use the gRPC API|
|
|
||||||
|[Node Types](nodetypes.md)|Overview of node types supported within CORE|
|
|[Node Types](nodetypes.md)|Overview of node types supported within CORE|
|
||||||
|[CTRLNET](ctrlnet.md)|How to use control networks to communicate with nodes from host|
|
|[CTRLNET](ctrlnet.md)|How to use control networks to communicate with nodes from host|
|
||||||
|[Services](services.md)|Overview of provided services and creating custom ones|
|
|[Services](services.md)|Overview of provided services and creating custom ones|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
|
# Python API
|
||||||
# CORE Python Scripting
|
|
||||||
|
|
||||||
* Table of Contents
|
* Table of Contents
|
||||||
{:toc}
|
{:toc}
|
Loading…
Add table
Reference in a new issue