|
|
|
@ -53,15 +53,15 @@ and the services they map to.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
a `core.api.grpc.wrappers.Interface` class instead with appropriate information.
|
|
|
|
|
|
|
|
|
|
Manually creating gRPC interface data:
|
|
|
|
|
Manually creating gRPC client interface:
|
|
|
|
|
```python
|
|
|
|
|
from core.api.grpc import core_pb2
|
|
|
|
|
from core.api.grpc.wrappers import Interface
|
|
|
|
|
# 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(
|
|
|
|
|
iface = Interface(
|
|
|
|
|
id=0,
|
|
|
|
|
name="eth0",
|
|
|
|
|
ip4="10.0.0.1",
|
|
|
|
@ -98,16 +98,24 @@ Event types:
|
|
|
|
|
* file - file events when the legacy gui joins a session
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
from core.api.grpc import core_pb2
|
|
|
|
|
from core.api.grpc import client
|
|
|
|
|
from core.api.grpc.wrappers import EventType
|
|
|
|
|
|
|
|
|
|
def event_listener(event):
|
|
|
|
|
print(event)
|
|
|
|
|
|
|
|
|
|
# create grpc client and connect
|
|
|
|
|
core = client.CoreGrpcClient()
|
|
|
|
|
core.connect()
|
|
|
|
|
|
|
|
|
|
# add session
|
|
|
|
|
session = core.add_session()
|
|
|
|
|
|
|
|
|
|
# provide no events to listen to all events
|
|
|
|
|
core.events(session_id, event_listener)
|
|
|
|
|
core.events(session.id, event_listener)
|
|
|
|
|
|
|
|
|
|
# provide events to listen to specific events
|
|
|
|
|
core.events(session_id, event_listener, [core_pb2.EventType.NODE])
|
|
|
|
|
core.events(session.id, event_listener, [EventType.NODE])
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Configuring Links
|
|
|
|
@ -122,27 +130,47 @@ Currently supported configuration options:
|
|
|
|
|
* loss (%)
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
from core.api.grpc import core_pb2
|
|
|
|
|
from core.api.grpc import client
|
|
|
|
|
from core.api.grpc.wrappers import LinkOptions, 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.add_session()
|
|
|
|
|
|
|
|
|
|
# create nodes
|
|
|
|
|
position = Position(x=100, y=100)
|
|
|
|
|
node1 = session.add_node(1, position=position)
|
|
|
|
|
position = Position(x=300, y=100)
|
|
|
|
|
node2 = session.add_node(2, position=position)
|
|
|
|
|
|
|
|
|
|
# configuring when creating a link
|
|
|
|
|
options = core_pb2.LinkOptions(
|
|
|
|
|
options = LinkOptions(
|
|
|
|
|
bandwidth=54_000_000,
|
|
|
|
|
delay=5000,
|
|
|
|
|
dup=5,
|
|
|
|
|
loss=5.5,
|
|
|
|
|
jitter=0,
|
|
|
|
|
)
|
|
|
|
|
core.add_link(session_id, n1_id, n2_id, iface1_data, iface2_data, options)
|
|
|
|
|
iface1 = iface_helper.create_iface(node1.id, 0)
|
|
|
|
|
iface2 = iface_helper.create_iface(node2.id, 0)
|
|
|
|
|
link = session.add_link(node1=node1, node2=node2, iface1=iface1, iface2=iface2)
|
|
|
|
|
|
|
|
|
|
# configuring during runtime
|
|
|
|
|
core.edit_link(session_id, n1_id, n2_id, iface1_id, iface2_id, options)
|
|
|
|
|
link.options.loss = 10.0
|
|
|
|
|
core.edit_link(session.id, link)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Peer to Peer Example
|
|
|
|
|
```python
|
|
|
|
|
# required imports
|
|
|
|
|
from core.api.grpc import client
|
|
|
|
|
from core.api.grpc.core_pb2 import Node, NodeType, Position, SessionState
|
|
|
|
|
from core.api.grpc.core_pb2 import Position
|
|
|
|
|
|
|
|
|
|
# interface helper
|
|
|
|
|
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
|
|
|
@ -151,39 +179,29 @@ iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001
|
|
|
|
|
core = client.CoreGrpcClient()
|
|
|
|
|
core.connect()
|
|
|
|
|
|
|
|
|
|
# create session and get id
|
|
|
|
|
response = core.create_session()
|
|
|
|
|
session_id = response.session_id
|
|
|
|
|
# add session
|
|
|
|
|
session = core.add_session()
|
|
|
|
|
|
|
|
|
|
# change session state to configuration so that nodes get started when added
|
|
|
|
|
core.set_session_state(session_id, SessionState.CONFIGURATION)
|
|
|
|
|
|
|
|
|
|
# create node one
|
|
|
|
|
# create nodes
|
|
|
|
|
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
|
|
|
|
|
node1 = session.add_node(1, position=position)
|
|
|
|
|
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
|
|
|
|
|
node2 = session.add_node(2, position=position)
|
|
|
|
|
|
|
|
|
|
# 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)
|
|
|
|
|
# create link
|
|
|
|
|
iface1 = iface_helper.create_iface(node1.id, 0)
|
|
|
|
|
iface2 = iface_helper.create_iface(node2.id, 0)
|
|
|
|
|
session.add_link(node1=node1, node2=node2, iface1=iface1, iface2=iface2)
|
|
|
|
|
|
|
|
|
|
# change session state
|
|
|
|
|
core.set_session_state(session_id, SessionState.INSTANTIATION)
|
|
|
|
|
# start session
|
|
|
|
|
core.start_session(session)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Switch/Hub Example
|
|
|
|
|
```python
|
|
|
|
|
# required imports
|
|
|
|
|
from core.api.grpc import client
|
|
|
|
|
from core.api.grpc.core_pb2 import Node, NodeType, Position, SessionState
|
|
|
|
|
from core.api.grpc.core_pb2 import NodeType, Position
|
|
|
|
|
|
|
|
|
|
# interface helper
|
|
|
|
|
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
|
|
|
@ -192,46 +210,32 @@ iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001
|
|
|
|
|
core = client.CoreGrpcClient()
|
|
|
|
|
core.connect()
|
|
|
|
|
|
|
|
|
|
# create session and get id
|
|
|
|
|
response = core.create_session()
|
|
|
|
|
session_id = response.session_id
|
|
|
|
|
# add session
|
|
|
|
|
session = core.add_session()
|
|
|
|
|
|
|
|
|
|
# change session state to configuration so that nodes get started when added
|
|
|
|
|
core.set_session_state(session_id, SessionState.CONFIGURATION)
|
|
|
|
|
|
|
|
|
|
# create switch node
|
|
|
|
|
# create nodes
|
|
|
|
|
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
|
|
|
|
|
switch = session.add_node(1, _type=NodeType.SWITCH, position=position)
|
|
|
|
|
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
|
|
|
|
|
node1 = session.add_node(2, position=position)
|
|
|
|
|
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
|
|
|
|
|
node2 = session.add_node(3, position=position)
|
|
|
|
|
|
|
|
|
|
# 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 links
|
|
|
|
|
iface1 = iface_helper.create_iface(node1.id, 0)
|
|
|
|
|
session.add_link(node1=node1, node2=switch, iface1=iface1)
|
|
|
|
|
iface1 = iface_helper.create_iface(node2.id, 0)
|
|
|
|
|
session.add_link(node1=node2, node2=switch, iface1=iface1)
|
|
|
|
|
|
|
|
|
|
# change session state
|
|
|
|
|
core.set_session_state(session_id, SessionState.INSTANTIATION)
|
|
|
|
|
# start session
|
|
|
|
|
core.start_session(session)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### WLAN Example
|
|
|
|
|
```python
|
|
|
|
|
# required imports
|
|
|
|
|
from core.api.grpc import client
|
|
|
|
|
from core.api.grpc.core_pb2 import Node, NodeType, Position, SessionState
|
|
|
|
|
from core.api.grpc.core_pb2 import NodeType, Position
|
|
|
|
|
|
|
|
|
|
# interface helper
|
|
|
|
|
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
|
|
|
@ -240,49 +244,37 @@ iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001
|
|
|
|
|
core = client.CoreGrpcClient()
|
|
|
|
|
core.connect()
|
|
|
|
|
|
|
|
|
|
# create session and get id
|
|
|
|
|
response = core.create_session()
|
|
|
|
|
session_id = response.session_id
|
|
|
|
|
# add session
|
|
|
|
|
session = core.add_session()
|
|
|
|
|
|
|
|
|
|
# change session state to configuration so that nodes get started when added
|
|
|
|
|
core.set_session_state(session_id, SessionState.CONFIGURATION)
|
|
|
|
|
|
|
|
|
|
# create wlan node
|
|
|
|
|
# create nodes
|
|
|
|
|
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
|
|
|
|
|
wlan = session.add_node(1, _type=NodeType.WIRELESS_LAN, position=position)
|
|
|
|
|
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
|
|
|
|
|
node1 = session.add_node(2, model="mdr", position=position)
|
|
|
|
|
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
|
|
|
|
|
node2 = session.add_node(3, model="mdr", position=position)
|
|
|
|
|
|
|
|
|
|
# configure wlan using a dict mapping currently
|
|
|
|
|
# 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)
|
|
|
|
|
|
|
|
|
|
# set wlan config 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",
|
|
|
|
|
})
|
|
|
|
|
wlan.set_wlan(
|
|
|
|
|
{
|
|
|
|
|
"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)
|
|
|
|
|
# start session
|
|
|
|
|
core.start_session(session)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### EMANE Example
|
|
|
|
@ -307,7 +299,7 @@ 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.api.grpc.core_pb2 import NodeType, Position
|
|
|
|
|
from core.emane.ieee80211abg import EmaneIeee80211abgModel
|
|
|
|
|
|
|
|
|
|
# interface helper
|
|
|
|
@ -317,68 +309,45 @@ iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001
|
|
|
|
|
core = client.CoreGrpcClient()
|
|
|
|
|
core.connect()
|
|
|
|
|
|
|
|
|
|
# create session and get id
|
|
|
|
|
response = core.create_session()
|
|
|
|
|
session_id = response.session_id
|
|
|
|
|
# add session
|
|
|
|
|
session = core.add_session()
|
|
|
|
|
|
|
|
|
|
# change session state to configuration so that nodes get started when added
|
|
|
|
|
core.set_session_state(session_id, SessionState.CONFIGURATION)
|
|
|
|
|
|
|
|
|
|
# create emane node
|
|
|
|
|
# create nodes
|
|
|
|
|
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
|
|
|
|
|
emane = session.add_node(
|
|
|
|
|
1, _type=NodeType.EMANE, position=position, emane=EmaneIeee80211abgModel.name
|
|
|
|
|
)
|
|
|
|
|
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
|
|
|
|
|
node1 = session.add_node(2, model="mdr", position=position)
|
|
|
|
|
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
|
|
|
|
|
node2 = session.add_node(3, model="mdr", position=position)
|
|
|
|
|
|
|
|
|
|
# configure general emane settings
|
|
|
|
|
core.set_emane_config(session_id, {
|
|
|
|
|
"eventservicettl": "2"
|
|
|
|
|
})
|
|
|
|
|
# create links
|
|
|
|
|
iface1 = iface_helper.create_iface(node1.id, 0)
|
|
|
|
|
session.add_link(node1=node1, node2=emane, iface1=iface1)
|
|
|
|
|
iface1 = iface_helper.create_iface(node2.id, 0)
|
|
|
|
|
session.add_link(node1=node2, node2=emane, iface1=iface1)
|
|
|
|
|
|
|
|
|
|
# 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",
|
|
|
|
|
})
|
|
|
|
|
# setting global emane configuration
|
|
|
|
|
session.set_emane({"eventservicettl": "2"})
|
|
|
|
|
# setting emane specific emane model configuration
|
|
|
|
|
emane.set_emane_model(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)
|
|
|
|
|
# start session
|
|
|
|
|
core.start_session(session)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
EMANE Model Configuration:
|
|
|
|
|
```python
|
|
|
|
|
# emane network specific config
|
|
|
|
|
core.set_emane_model_config(session_id, emane_id, EmaneIeee80211abgModel.name, {
|
|
|
|
|
"unicastrate": "3",
|
|
|
|
|
})
|
|
|
|
|
# emane network specific config, set on an emane node
|
|
|
|
|
# this setting applies to all nodes connected
|
|
|
|
|
emane.set_emane_model(EmaneIeee80211abgModel.name, {"unicastrate": "3"})
|
|
|
|
|
|
|
|
|
|
# node specific config
|
|
|
|
|
core.set_emane_model_config(session_id, node_id, EmaneIeee80211abgModel.name, {
|
|
|
|
|
"unicastrate": "3",
|
|
|
|
|
})
|
|
|
|
|
# node specific config for an individual node connected to an emane network
|
|
|
|
|
node.set_emane_model(EmaneIeee80211abgModel.name, {"unicastrate": "3"})
|
|
|
|
|
|
|
|
|
|
# node interface specific config
|
|
|
|
|
core.set_emane_model_config(session_id, node_id, EmaneIeee80211abgModel.name, {
|
|
|
|
|
"unicastrate": "3",
|
|
|
|
|
}, iface_id)
|
|
|
|
|
# node interface specific config for an individual node connected to an emane network
|
|
|
|
|
node.set_emane_model(EmaneIeee80211abgModel.name, {"unicastrate": "3"}, iface_id=0)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Configuring a Service
|
|
|
|
@ -398,11 +367,8 @@ The following features can be configured for a service:
|
|
|
|
|
Editing service properties:
|
|
|
|
|
```python
|
|
|
|
|
# configure a service, for a node, for a given session
|
|
|
|
|
core.set_node_service(
|
|
|
|
|
session_id,
|
|
|
|
|
node_id,
|
|
|
|
|
service_name,
|
|
|
|
|
files=["file1.sh", "file2.sh"],
|
|
|
|
|
node.service_configs[service_name] = NodeServiceData(
|
|
|
|
|
configs=["file1.sh", "file2.sh"],
|
|
|
|
|
directories=["/etc/node"],
|
|
|
|
|
startup=["bash file1.sh"],
|
|
|
|
|
validate=[],
|
|
|
|
@ -417,13 +383,8 @@ Editing a service file:
|
|
|
|
|
```python
|
|
|
|
|
# to edit the contents of a generated file you can specify
|
|
|
|
|
# the service, the file name, and its contents
|
|
|
|
|
core.set_node_service_file(
|
|
|
|
|
session_id,
|
|
|
|
|
node_id,
|
|
|
|
|
service_name,
|
|
|
|
|
file_name,
|
|
|
|
|
"echo hello",
|
|
|
|
|
)
|
|
|
|
|
file_configs = node.service_file_configs.setdefault(service_name, {})
|
|
|
|
|
file_configs[file_name] = "echo hello world"
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## File Examples
|
|
|
|
|