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.location.mobility import BasicRangeModel, Ns2ScriptedMobility
|
||||
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
|
||||
|
||||
_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.set_state(EventTypes.DEFINITION_STATE)
|
||||
session.location.setrefgeo(47.57917, -122.13232, 2.0)
|
||||
session.location.refscale = 150000.0
|
||||
session.location.refscale = 150.0
|
||||
return core_pb2.CreateSessionResponse(
|
||||
session_id=session.id, state=session.state.value
|
||||
)
|
||||
|
@ -556,7 +556,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
nodes = []
|
||||
for _id in session.nodes:
|
||||
node = session.nodes[_id]
|
||||
if not isinstance(node, PtpNet):
|
||||
if not isinstance(node, (PtpNet, CtrlNet)):
|
||||
node_proto = grpcutils.get_node_proto(session, node)
|
||||
nodes.append(node_proto)
|
||||
node_links = get_links(node)
|
||||
|
|
|
@ -1,74 +1,51 @@
|
|||
"""
|
||||
Example using gRPC API to create a simple EMANE 80211 network.
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
# 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")
|
||||
|
||||
def log_event(event):
|
||||
logging.info("event: %s", event)
|
||||
# create grpc client and connect
|
||||
core = client.CoreGrpcClient()
|
||||
core.connect()
|
||||
|
||||
# create session and get id
|
||||
response = core.create_session()
|
||||
session_id = response.session_id
|
||||
|
||||
def main():
|
||||
# helper to create interface addresses
|
||||
interface_helper = client.InterfaceHelper(ip4_prefix="10.83.0.0/24")
|
||||
# change session state to configuration so that nodes get started when added
|
||||
core.set_session_state(session_id, SessionState.CONFIGURATION)
|
||||
|
||||
# create grpc client and start connection context, which auto closes connection
|
||||
core = client.CoreGrpcClient()
|
||||
with core.context_connect():
|
||||
# create session
|
||||
response = core.create_session()
|
||||
logging.info("created session: %s", response)
|
||||
# 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
|
||||
|
||||
# handle events session may broadcast
|
||||
session_id = response.session_id
|
||||
core.events(session_id, log_event)
|
||||
# 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
|
||||
|
||||
# change session state to configuration so that nodes get started when added
|
||||
response = core.set_session_state(session_id, SessionState.CONFIGURATION)
|
||||
logging.info("set session state: %s", response)
|
||||
# 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
|
||||
|
||||
# create emane node
|
||||
position = Position(x=200, y=200)
|
||||
emane = Node(type=NodeType.EMANE, position=position)
|
||||
response = core.add_node(session_id, emane)
|
||||
logging.info("created emane: %s", response)
|
||||
emane_id = response.node_id
|
||||
# configure general emane settings
|
||||
core.set_emane_config(session_id, {"eventservicettl": "2"})
|
||||
|
||||
# an emane model must be configured for use, by the emane node
|
||||
core.set_emane_model_config(session_id, emane_id, EmaneIeee80211abgModel.name)
|
||||
# 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"}
|
||||
)
|
||||
|
||||
# create node one
|
||||
position = Position(x=100, y=100)
|
||||
node1 = Node(type=NodeType.DEFAULT, position=position)
|
||||
response = core.add_node(session_id, node1)
|
||||
logging.info("created node: %s", response)
|
||||
node1_id = response.node_id
|
||||
|
||||
# create node two
|
||||
position = Position(x=300, y=100)
|
||||
node2 = Node(type=NodeType.DEFAULT, position=position)
|
||||
response = core.add_node(session_id, node2)
|
||||
logging.info("created node: %s", response)
|
||||
node2_id = response.node_id
|
||||
|
||||
# links nodes to switch
|
||||
interface1 = interface_helper.create_iface(node1_id, 0)
|
||||
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
|
||||
response = core.set_session_state(session_id, SessionState.INSTANTIATION)
|
||||
logging.info("set session state: %s", response)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
main()
|
||||
# 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)
|
||||
|
|
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 @@
|
|||
"""
|
||||
Example using gRPC API to create a simple switch network.
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
# 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")
|
||||
|
||||
def log_event(event):
|
||||
logging.info("event: %s", event)
|
||||
# create grpc client and connect
|
||||
core = client.CoreGrpcClient()
|
||||
core.connect()
|
||||
|
||||
# create session and get id
|
||||
response = core.create_session()
|
||||
session_id = response.session_id
|
||||
|
||||
def main():
|
||||
# helper to create interface addresses
|
||||
interface_helper = client.InterfaceHelper(ip4_prefix="10.83.0.0/24")
|
||||
# change session state to configuration so that nodes get started when added
|
||||
core.set_session_state(session_id, SessionState.CONFIGURATION)
|
||||
|
||||
# create grpc client and start connection context, which auto closes connection
|
||||
core = client.CoreGrpcClient()
|
||||
with core.context_connect():
|
||||
# create session
|
||||
response = core.create_session()
|
||||
logging.info("created session: %s", response)
|
||||
# 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
|
||||
|
||||
# handle events session may broadcast
|
||||
session_id = response.session_id
|
||||
core.events(session_id, log_event)
|
||||
# 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
|
||||
|
||||
# change session state to configuration so that nodes get started when added
|
||||
response = core.set_session_state(session_id, SessionState.CONFIGURATION)
|
||||
logging.info("set session state: %s", response)
|
||||
# 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
|
||||
|
||||
# create switch node
|
||||
position = Position(x=200, y=200)
|
||||
switch = Node(type=NodeType.SWITCH, position=position)
|
||||
response = core.add_node(session_id, switch)
|
||||
logging.info("created switch: %s", response)
|
||||
switch_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)
|
||||
|
||||
# create node one
|
||||
position = Position(x=100, y=100)
|
||||
node1 = Node(type=NodeType.DEFAULT, position=position, model="PC")
|
||||
response = core.add_node(session_id, node1)
|
||||
logging.info("created node: %s", response)
|
||||
node1_id = response.node_id
|
||||
|
||||
# create node two
|
||||
position = Position(x=300, y=100)
|
||||
node2 = Node(type=NodeType.DEFAULT, position=position, model="PC")
|
||||
response = core.add_node(session_id, node2)
|
||||
logging.info("created node: %s", response)
|
||||
node2_id = response.node_id
|
||||
|
||||
# links nodes to switch
|
||||
interface1 = interface_helper.create_iface(node1_id, 0)
|
||||
response = core.add_link(session_id, node1_id, switch_id, interface1)
|
||||
logging.info("created link: %s", response)
|
||||
interface1 = interface_helper.create_iface(node2_id, 0)
|
||||
response = core.add_link(session_id, node2_id, switch_id, interface1)
|
||||
logging.info("created link: %s", response)
|
||||
|
||||
# change session state
|
||||
response = core.set_session_state(session_id, SessionState.INSTANTIATION)
|
||||
logging.info("set session state: %s", response)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
main()
|
||||
# change session state
|
||||
core.set_session_state(session_id, SessionState.INSTANTIATION)
|
||||
|
|
|
@ -1,82 +1,58 @@
|
|||
"""
|
||||
Example using gRPC API to create a simple wlan network.
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
# 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")
|
||||
|
||||
def log_event(event):
|
||||
logging.info("event: %s", event)
|
||||
# create grpc client and connect
|
||||
core = client.CoreGrpcClient()
|
||||
core.connect()
|
||||
|
||||
# create session and get id
|
||||
response = core.create_session()
|
||||
session_id = response.session_id
|
||||
|
||||
def main():
|
||||
# helper to create interface addresses
|
||||
interface_helper = client.InterfaceHelper(ip4_prefix="10.83.0.0/24")
|
||||
# change session state to configuration so that nodes get started when added
|
||||
core.set_session_state(session_id, SessionState.CONFIGURATION)
|
||||
|
||||
# create grpc client and start connection context, which auto closes connection
|
||||
core = client.CoreGrpcClient()
|
||||
with core.context_connect():
|
||||
# create session
|
||||
response = core.create_session()
|
||||
logging.info("created session: %s", response)
|
||||
# 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
|
||||
|
||||
# handle events session may broadcast
|
||||
session_id = response.session_id
|
||||
core.events(session_id, log_event)
|
||||
# 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
|
||||
|
||||
# change session state to configuration so that nodes get started when added
|
||||
response = core.set_session_state(session_id, SessionState.CONFIGURATION)
|
||||
logging.info("set session state: %s", response)
|
||||
# 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
|
||||
|
||||
# create wlan node
|
||||
position = Position(x=200, y=200)
|
||||
wlan = Node(type=NodeType.WIRELESS_LAN, position=position)
|
||||
response = core.add_node(session_id, wlan)
|
||||
logging.info("created wlan: %s", response)
|
||||
wlan_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",
|
||||
},
|
||||
)
|
||||
|
||||
# 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)
|
||||
# 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)
|
||||
|
||||
# create node one
|
||||
position = Position(x=100, y=100)
|
||||
node1 = Node(type=NodeType.DEFAULT, position=position)
|
||||
response = core.add_node(session_id, node1)
|
||||
logging.info("created node: %s", response)
|
||||
node1_id = response.node_id
|
||||
|
||||
# create node two
|
||||
position = Position(x=300, y=100)
|
||||
node2 = Node(type=NodeType.DEFAULT, position=position)
|
||||
response = core.add_node(session_id, node2)
|
||||
logging.info("created node: %s", response)
|
||||
node2_id = response.node_id
|
||||
|
||||
# links nodes to switch
|
||||
interface1 = interface_helper.create_iface(node1_id, 0)
|
||||
response = core.add_link(session_id, node1_id, wlan_id, interface1)
|
||||
logging.info("created link: %s", response)
|
||||
interface1 = interface_helper.create_iface(node2_id, 0)
|
||||
response = core.add_link(session_id, node2_id, wlan_id, interface1)
|
||||
logging.info("created link: %s", response)
|
||||
|
||||
# change session state
|
||||
response = core.set_session_state(session_id, SessionState.INSTANTIATION)
|
||||
logging.info("set session state: %s", response)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
main()
|
||||
# change session state
|
||||
core.set_session_state(session_id, SessionState.INSTANTIATION)
|
||||
|
|
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
|
||||
the python GUI for driving all functionality.
|
||||
* Table of Contents
|
||||
{:toc}
|
||||
|
||||
Currently we are providing a python client that wraps the generated files for
|
||||
leveraging the API, but proto files noted below can also be leveraged to generate
|
||||
bindings for other languages as well.
|
||||
[gRPC](https://grpc.io/) is a client/server API for interfacing with CORE
|
||||
and used by the python GUI for driving all functionality. It is dependent
|
||||
on having a running `core-daemon` instance to be leveraged.
|
||||
|
||||
## HTTP Proxy
|
||||
|
||||
Since gRPC is HTTP2 based, proxy configurations can cause issue. You can either
|
||||
properly account for this issue or clear out your proxy when running if needed.
|
||||
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
|
||||
some of the functionality to try and help make things easier.
|
||||
|
||||
## 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)
|
||||
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 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
|
||||
|
||||
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).
|
||||
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|
|
||||
|[GUI](gui.md)|How to use the 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|
|
||||
|[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|
|
||||
|[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|
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
# CORE Python Scripting
|
||||
# Python API
|
||||
|
||||
* Table of Contents
|
||||
{:toc}
|
Loading…
Reference in a new issue