grpc: removed old client, refactored wrapped client to be the new standard client, removed old client tests, updated documentation
This commit is contained in:
parent
924e86da2b
commit
15acdaa40f
14 changed files with 698 additions and 3008 deletions
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -12,7 +12,7 @@ from typing import TYPE_CHECKING, Dict, Iterable, List, Optional, Set, Tuple
|
||||||
|
|
||||||
import grpc
|
import grpc
|
||||||
|
|
||||||
from core.api.grpc import clientw, configservices_pb2, core_pb2
|
from core.api.grpc import client, configservices_pb2, core_pb2
|
||||||
from core.api.grpc.wrappers import (
|
from core.api.grpc.wrappers import (
|
||||||
ConfigOption,
|
ConfigOption,
|
||||||
ConfigService,
|
ConfigService,
|
||||||
|
@ -66,7 +66,7 @@ class CoreClient:
|
||||||
"""
|
"""
|
||||||
self.app: "Application" = app
|
self.app: "Application" = app
|
||||||
self.master: tk.Tk = app.master
|
self.master: tk.Tk = app.master
|
||||||
self._client: clientw.CoreGrpcClient = clientw.CoreGrpcClient(proxy=proxy)
|
self._client: client.CoreGrpcClient = client.CoreGrpcClient(proxy=proxy)
|
||||||
self.session: Optional[Session] = None
|
self.session: Optional[Session] = None
|
||||||
self.user = getpass.getuser()
|
self.user = getpass.getuser()
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ class CoreClient:
|
||||||
self.handling_events: Optional[grpc.Future] = None
|
self.handling_events: Optional[grpc.Future] = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def client(self) -> clientw.CoreGrpcClient:
|
def client(self) -> client.CoreGrpcClient:
|
||||||
if self.session:
|
if self.session:
|
||||||
if not self._client.check_session(self.session.id):
|
if not self._client.check_session(self.session.id):
|
||||||
throughputs_enabled = self.handling_throughputs is not None
|
throughputs_enabled = self.handling_throughputs is not None
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from core.api.grpc import clientw
|
from core.api.grpc import client
|
||||||
from core.api.grpc.wrappers import NodeType, Position
|
from core.api.grpc.wrappers import NodeType, Position
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,10 +11,10 @@ def log_event(event):
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
# helper to create interfaces
|
# helper to create interfaces
|
||||||
interface_helper = clientw.InterfaceHelper(ip4_prefix="10.83.0.0/16")
|
interface_helper = client.InterfaceHelper(ip4_prefix="10.83.0.0/16")
|
||||||
|
|
||||||
# create grpc client and connect
|
# create grpc client and connect
|
||||||
core = clientw.CoreGrpcClient()
|
core = client.CoreGrpcClient()
|
||||||
core.connect()
|
core.connect()
|
||||||
|
|
||||||
# create session
|
# create session
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
# required imports
|
# required imports
|
||||||
from core.api.grpc import clientw
|
from core.api.grpc import client
|
||||||
from core.api.grpc.wrappers import NodeType, Position
|
from core.api.grpc.wrappers import NodeType, Position
|
||||||
from core.emane.ieee80211abg import EmaneIeee80211abgModel
|
from core.emane.ieee80211abg import EmaneIeee80211abgModel
|
||||||
|
|
||||||
# interface helper
|
# interface helper
|
||||||
iface_helper = clientw.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
||||||
|
|
||||||
# create grpc client and connect
|
# create grpc client and connect
|
||||||
core = clientw.CoreGrpcClient()
|
core = client.CoreGrpcClient()
|
||||||
core.connect()
|
core.connect()
|
||||||
|
|
||||||
# add session
|
# add session
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
from core.api.grpc import clientw
|
from core.api.grpc import client
|
||||||
from core.api.grpc.wrappers import Position
|
from core.api.grpc.wrappers import Position
|
||||||
|
|
||||||
# interface helper
|
# interface helper
|
||||||
iface_helper = clientw.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
||||||
|
|
||||||
# create grpc client and connect
|
# create grpc client and connect
|
||||||
core = clientw.CoreGrpcClient()
|
core = client.CoreGrpcClient()
|
||||||
core.connect()
|
core.connect()
|
||||||
|
|
||||||
# add session
|
# add session
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
from core.api.grpc import clientw
|
from core.api.grpc import client
|
||||||
from core.api.grpc.wrappers import NodeType, Position
|
from core.api.grpc.wrappers import NodeType, Position
|
||||||
|
|
||||||
# interface helper
|
# interface helper
|
||||||
iface_helper = clientw.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
||||||
|
|
||||||
# create grpc client and connect
|
# create grpc client and connect
|
||||||
core = clientw.CoreGrpcClient()
|
core = client.CoreGrpcClient()
|
||||||
core.connect()
|
core.connect()
|
||||||
|
|
||||||
# add session
|
# add session
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
from core.api.grpc import clientw
|
from core.api.grpc import client
|
||||||
from core.api.grpc.wrappers import NodeType, Position
|
from core.api.grpc.wrappers import NodeType, Position
|
||||||
|
|
||||||
# interface helper
|
# interface helper
|
||||||
iface_helper = clientw.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
||||||
|
|
||||||
# create grpc client and connect
|
# create grpc client and connect
|
||||||
core = clientw.CoreGrpcClient()
|
core = client.CoreGrpcClient()
|
||||||
core.connect()
|
core.connect()
|
||||||
|
|
||||||
# add session
|
# add session
|
||||||
|
|
|
@ -15,7 +15,7 @@ import grpc
|
||||||
import netaddr
|
import netaddr
|
||||||
from netaddr import EUI, AddrFormatError, IPNetwork
|
from netaddr import EUI, AddrFormatError, IPNetwork
|
||||||
|
|
||||||
from core.api.grpc.clientw import CoreGrpcClient
|
from core.api.grpc.client import CoreGrpcClient
|
||||||
from core.api.grpc.wrappers import (
|
from core.api.grpc.wrappers import (
|
||||||
Geo,
|
Geo,
|
||||||
Interface,
|
Interface,
|
||||||
|
|
|
@ -5,7 +5,7 @@ import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from core import utils
|
from core import utils
|
||||||
from core.api.grpc.clientw import CoreGrpcClient
|
from core.api.grpc.client import CoreGrpcClient
|
||||||
from core.errors import CoreCommandError
|
from core.errors import CoreCommandError
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -15,7 +15,7 @@ from typing import Dict, Tuple
|
||||||
import grpc
|
import grpc
|
||||||
|
|
||||||
from core import utils
|
from core import utils
|
||||||
from core.api.grpc.clientw import CoreGrpcClient
|
from core.api.grpc.client import CoreGrpcClient
|
||||||
from core.api.grpc.wrappers import NodeType
|
from core.api.grpc.wrappers import NodeType
|
||||||
|
|
||||||
SDT_HOST = "127.0.0.1"
|
SDT_HOST = "127.0.0.1"
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -9,7 +9,7 @@ import pytest
|
||||||
from mock import patch
|
from mock import patch
|
||||||
|
|
||||||
from core.api.grpc import core_pb2
|
from core.api.grpc import core_pb2
|
||||||
from core.api.grpc.clientw import CoreGrpcClient, InterfaceHelper, MoveNodesStreamer
|
from core.api.grpc.client import CoreGrpcClient, InterfaceHelper, MoveNodesStreamer
|
||||||
from core.api.grpc.server import CoreGrpcServer
|
from core.api.grpc.server import CoreGrpcServer
|
||||||
from core.api.grpc.wrappers import (
|
from core.api.grpc.wrappers import (
|
||||||
ConfigOption,
|
ConfigOption,
|
||||||
|
|
281
docs/grpc.md
281
docs/grpc.md
|
@ -53,15 +53,15 @@ and the services they map to.
|
||||||
|
|
||||||
There is an interface helper class that can be leveraged for convenience
|
There is an interface helper class that can be leveraged for convenience
|
||||||
when creating interface data for nodes. Alternatively one can manually create
|
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
|
```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
|
# id is optional and will set to the next available id
|
||||||
# name is optional and will default to eth<id>
|
# name is optional and will default to eth<id>
|
||||||
# mac is optional and will result in a randomly generated mac
|
# mac is optional and will result in a randomly generated mac
|
||||||
iface_data = core_pb2.Interface(
|
iface = Interface(
|
||||||
id=0,
|
id=0,
|
||||||
name="eth0",
|
name="eth0",
|
||||||
ip4="10.0.0.1",
|
ip4="10.0.0.1",
|
||||||
|
@ -98,16 +98,24 @@ Event types:
|
||||||
* file - file events when the legacy gui joins a session
|
* file - file events when the legacy gui joins a session
|
||||||
|
|
||||||
```python
|
```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):
|
def event_listener(event):
|
||||||
print(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
|
# 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
|
# 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
|
### Configuring Links
|
||||||
|
@ -122,27 +130,47 @@ Currently supported configuration options:
|
||||||
* loss (%)
|
* loss (%)
|
||||||
|
|
||||||
```python
|
```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
|
# configuring when creating a link
|
||||||
options = core_pb2.LinkOptions(
|
options = LinkOptions(
|
||||||
bandwidth=54_000_000,
|
bandwidth=54_000_000,
|
||||||
delay=5000,
|
delay=5000,
|
||||||
dup=5,
|
dup=5,
|
||||||
loss=5.5,
|
loss=5.5,
|
||||||
jitter=0,
|
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
|
# 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
|
### Peer to Peer Example
|
||||||
```python
|
```python
|
||||||
# required imports
|
# required imports
|
||||||
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 Position
|
||||||
|
|
||||||
# interface helper
|
# interface helper
|
||||||
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
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 = client.CoreGrpcClient()
|
||||||
core.connect()
|
core.connect()
|
||||||
|
|
||||||
# create session and get id
|
# add session
|
||||||
response = core.create_session()
|
session = core.add_session()
|
||||||
session_id = response.session_id
|
|
||||||
|
|
||||||
# change session state to configuration so that nodes get started when added
|
# create nodes
|
||||||
core.set_session_state(session_id, SessionState.CONFIGURATION)
|
|
||||||
|
|
||||||
# create node one
|
|
||||||
position = Position(x=100, y=100)
|
position = Position(x=100, y=100)
|
||||||
n1 = Node(type=NodeType.DEFAULT, position=position, model="PC")
|
node1 = session.add_node(1, position=position)
|
||||||
response = core.add_node(session_id, n1)
|
|
||||||
n1_id = response.node_id
|
|
||||||
|
|
||||||
# create node two
|
|
||||||
position = Position(x=300, y=100)
|
position = Position(x=300, y=100)
|
||||||
n2 = Node(type=NodeType.DEFAULT, position=position, model="PC")
|
node2 = session.add_node(2, position=position)
|
||||||
response = core.add_node(session_id, n2)
|
|
||||||
n2_id = response.node_id
|
|
||||||
|
|
||||||
# links nodes together
|
# create link
|
||||||
iface1 = iface_helper.create_iface(n1_id, 0)
|
iface1 = iface_helper.create_iface(node1.id, 0)
|
||||||
iface2 = iface_helper.create_iface(n2_id, 0)
|
iface2 = iface_helper.create_iface(node2.id, 0)
|
||||||
core.add_link(session_id, n1_id, n2_id, iface1, iface2)
|
session.add_link(node1=node1, node2=node2, iface1=iface1, iface2=iface2)
|
||||||
|
|
||||||
# change session state
|
# start session
|
||||||
core.set_session_state(session_id, SessionState.INSTANTIATION)
|
core.start_session(session)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Switch/Hub Example
|
### Switch/Hub Example
|
||||||
```python
|
```python
|
||||||
# required imports
|
# required imports
|
||||||
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 NodeType, Position
|
||||||
|
|
||||||
# interface helper
|
# interface helper
|
||||||
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
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 = client.CoreGrpcClient()
|
||||||
core.connect()
|
core.connect()
|
||||||
|
|
||||||
# create session and get id
|
# add session
|
||||||
response = core.create_session()
|
session = core.add_session()
|
||||||
session_id = response.session_id
|
|
||||||
|
|
||||||
# change session state to configuration so that nodes get started when added
|
# create nodes
|
||||||
core.set_session_state(session_id, SessionState.CONFIGURATION)
|
|
||||||
|
|
||||||
# create switch node
|
|
||||||
position = Position(x=200, y=200)
|
position = Position(x=200, y=200)
|
||||||
switch = Node(type=NodeType.SWITCH, position=position)
|
switch = session.add_node(1, _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)
|
position = Position(x=100, y=100)
|
||||||
n1 = Node(type=NodeType.DEFAULT, position=position, model="PC")
|
node1 = session.add_node(2, position=position)
|
||||||
response = core.add_node(session_id, n1)
|
|
||||||
n1_id = response.node_id
|
|
||||||
|
|
||||||
# create node two
|
|
||||||
position = Position(x=300, y=100)
|
position = Position(x=300, y=100)
|
||||||
n2 = Node(type=NodeType.DEFAULT, position=position, model="PC")
|
node2 = session.add_node(3, position=position)
|
||||||
response = core.add_node(session_id, n2)
|
|
||||||
n2_id = response.node_id
|
|
||||||
|
|
||||||
# links nodes to switch
|
# create links
|
||||||
iface1 = iface_helper.create_iface(n1_id, 0)
|
iface1 = iface_helper.create_iface(node1.id, 0)
|
||||||
core.add_link(session_id, n1_id, switch_id, iface1)
|
session.add_link(node1=node1, node2=switch, iface1=iface1)
|
||||||
iface1 = iface_helper.create_iface(n2_id, 0)
|
iface1 = iface_helper.create_iface(node2.id, 0)
|
||||||
core.add_link(session_id, n2_id, switch_id, iface1)
|
session.add_link(node1=node2, node2=switch, iface1=iface1)
|
||||||
|
|
||||||
# change session state
|
# start session
|
||||||
core.set_session_state(session_id, SessionState.INSTANTIATION)
|
core.start_session(session)
|
||||||
```
|
```
|
||||||
|
|
||||||
### WLAN Example
|
### WLAN Example
|
||||||
```python
|
```python
|
||||||
# required imports
|
# required imports
|
||||||
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 NodeType, Position
|
||||||
|
|
||||||
# interface helper
|
# interface helper
|
||||||
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
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 = client.CoreGrpcClient()
|
||||||
core.connect()
|
core.connect()
|
||||||
|
|
||||||
# create session and get id
|
# add session
|
||||||
response = core.create_session()
|
session = core.add_session()
|
||||||
session_id = response.session_id
|
|
||||||
|
|
||||||
# change session state to configuration so that nodes get started when added
|
# create nodes
|
||||||
core.set_session_state(session_id, SessionState.CONFIGURATION)
|
|
||||||
|
|
||||||
# create wlan node
|
|
||||||
position = Position(x=200, y=200)
|
position = Position(x=200, y=200)
|
||||||
wlan = Node(type=NodeType.WIRELESS_LAN, position=position)
|
wlan = session.add_node(1, _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)
|
position = Position(x=100, y=100)
|
||||||
n1 = Node(type=NodeType.DEFAULT, position=position, model="mdr")
|
node1 = session.add_node(2, model="mdr", position=position)
|
||||||
response = core.add_node(session_id, n1)
|
|
||||||
n1_id = response.node_id
|
|
||||||
|
|
||||||
# create node two
|
|
||||||
position = Position(x=300, y=100)
|
position = Position(x=300, y=100)
|
||||||
n2 = Node(type=NodeType.DEFAULT, position=position, model="mdr")
|
node2 = session.add_node(3, model="mdr", position=position)
|
||||||
response = core.add_node(session_id, n2)
|
|
||||||
n2_id = response.node_id
|
|
||||||
|
|
||||||
# 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
|
# support values as strings
|
||||||
core.set_wlan_config(session_id, wlan_id, {
|
wlan.set_wlan(
|
||||||
"range": "280",
|
{
|
||||||
"bandwidth": "55000000",
|
"range": "280",
|
||||||
"delay": "6000",
|
"bandwidth": "55000000",
|
||||||
"jitter": "5",
|
"delay": "6000",
|
||||||
"error": "5",
|
"jitter": "5",
|
||||||
})
|
"error": "5",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
# links nodes to wlan
|
# start session
|
||||||
iface1 = iface_helper.create_iface(n1_id, 0)
|
core.start_session(session)
|
||||||
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
|
### EMANE Example
|
||||||
|
@ -307,7 +299,7 @@ will use the defaults. When no configuration is used, the defaults are used.
|
||||||
```python
|
```python
|
||||||
# required imports
|
# required imports
|
||||||
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 NodeType, Position
|
||||||
from core.emane.ieee80211abg import EmaneIeee80211abgModel
|
from core.emane.ieee80211abg import EmaneIeee80211abgModel
|
||||||
|
|
||||||
# interface helper
|
# interface helper
|
||||||
|
@ -317,68 +309,45 @@ iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001
|
||||||
core = client.CoreGrpcClient()
|
core = client.CoreGrpcClient()
|
||||||
core.connect()
|
core.connect()
|
||||||
|
|
||||||
# create session and get id
|
# add session
|
||||||
response = core.create_session()
|
session = core.add_session()
|
||||||
session_id = response.session_id
|
|
||||||
|
|
||||||
# change session state to configuration so that nodes get started when added
|
# create nodes
|
||||||
core.set_session_state(session_id, SessionState.CONFIGURATION)
|
|
||||||
|
|
||||||
# create emane node
|
|
||||||
position = Position(x=200, y=200)
|
position = Position(x=200, y=200)
|
||||||
emane = Node(type=NodeType.EMANE, position=position, emane=EmaneIeee80211abgModel.name)
|
emane = session.add_node(
|
||||||
response = core.add_node(session_id, emane)
|
1, _type=NodeType.EMANE, position=position, emane=EmaneIeee80211abgModel.name
|
||||||
emane_id = response.node_id
|
)
|
||||||
|
|
||||||
# create node one
|
|
||||||
position = Position(x=100, y=100)
|
position = Position(x=100, y=100)
|
||||||
n1 = Node(type=NodeType.DEFAULT, position=position, model="mdr")
|
node1 = session.add_node(2, model="mdr", position=position)
|
||||||
response = core.add_node(session_id, n1)
|
|
||||||
n1_id = response.node_id
|
|
||||||
|
|
||||||
# create node two
|
|
||||||
position = Position(x=300, y=100)
|
position = Position(x=300, y=100)
|
||||||
n2 = Node(type=NodeType.DEFAULT, position=position, model="mdr")
|
node2 = session.add_node(3, model="mdr", position=position)
|
||||||
response = core.add_node(session_id, n2)
|
|
||||||
n2_id = response.node_id
|
|
||||||
|
|
||||||
# configure general emane settings
|
# create links
|
||||||
core.set_emane_config(session_id, {
|
iface1 = iface_helper.create_iface(node1.id, 0)
|
||||||
"eventservicettl": "2"
|
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
|
# setting global emane configuration
|
||||||
# using a dict mapping currently support values as strings
|
session.set_emane({"eventservicettl": "2"})
|
||||||
core.set_emane_model_config(session_id, emane_id, EmaneIeee80211abgModel.name, {
|
# setting emane specific emane model configuration
|
||||||
"unicastrate": "3",
|
emane.set_emane_model(EmaneIeee80211abgModel.name, {"unicastrate": "3"})
|
||||||
})
|
|
||||||
|
|
||||||
# links nodes to emane
|
# start session
|
||||||
iface1 = iface_helper.create_iface(n1_id, 0)
|
core.start_session(session)
|
||||||
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:
|
EMANE Model Configuration:
|
||||||
```python
|
```python
|
||||||
# emane network specific config
|
# emane network specific config, set on an emane node
|
||||||
core.set_emane_model_config(session_id, emane_id, EmaneIeee80211abgModel.name, {
|
# this setting applies to all nodes connected
|
||||||
"unicastrate": "3",
|
emane.set_emane_model(EmaneIeee80211abgModel.name, {"unicastrate": "3"})
|
||||||
})
|
|
||||||
|
|
||||||
# node specific config
|
# node specific config for an individual node connected to an emane network
|
||||||
core.set_emane_model_config(session_id, node_id, EmaneIeee80211abgModel.name, {
|
node.set_emane_model(EmaneIeee80211abgModel.name, {"unicastrate": "3"})
|
||||||
"unicastrate": "3",
|
|
||||||
})
|
|
||||||
|
|
||||||
# node interface specific config
|
# node interface specific config for an individual node connected to an emane network
|
||||||
core.set_emane_model_config(session_id, node_id, EmaneIeee80211abgModel.name, {
|
node.set_emane_model(EmaneIeee80211abgModel.name, {"unicastrate": "3"}, iface_id=0)
|
||||||
"unicastrate": "3",
|
|
||||||
}, iface_id)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Configuring a Service
|
## Configuring a Service
|
||||||
|
@ -398,11 +367,8 @@ The following features can be configured for a service:
|
||||||
Editing service properties:
|
Editing service properties:
|
||||||
```python
|
```python
|
||||||
# configure a service, for a node, for a given session
|
# configure a service, for a node, for a given session
|
||||||
core.set_node_service(
|
node.service_configs[service_name] = NodeServiceData(
|
||||||
session_id,
|
configs=["file1.sh", "file2.sh"],
|
||||||
node_id,
|
|
||||||
service_name,
|
|
||||||
files=["file1.sh", "file2.sh"],
|
|
||||||
directories=["/etc/node"],
|
directories=["/etc/node"],
|
||||||
startup=["bash file1.sh"],
|
startup=["bash file1.sh"],
|
||||||
validate=[],
|
validate=[],
|
||||||
|
@ -417,13 +383,8 @@ Editing a service file:
|
||||||
```python
|
```python
|
||||||
# to edit the contents of a generated file you can specify
|
# to edit the contents of a generated file you can specify
|
||||||
# the service, the file name, and its contents
|
# the service, the file name, and its contents
|
||||||
core.set_node_service_file(
|
file_configs = node.service_file_configs.setdefault(service_name, {})
|
||||||
session_id,
|
file_configs[file_name] = "echo hello world"
|
||||||
node_id,
|
|
||||||
service_name,
|
|
||||||
file_name,
|
|
||||||
"echo hello",
|
|
||||||
)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## File Examples
|
## File Examples
|
||||||
|
|
Loading…
Reference in a new issue