grpc: updates to wrapper classes to help write client code in a more simple way using the consolidated api, updated examples to used the wrapped client
This commit is contained in:
parent
38e162aec5
commit
917c45e70b
8 changed files with 196 additions and 235 deletions
|
@ -352,6 +352,10 @@ class CoreGrpcClient:
|
||||||
response = self.stub.StopSession(request)
|
response = self.stub.StopSession(request)
|
||||||
return response.result
|
return response.result
|
||||||
|
|
||||||
|
def add_session(self, session_id: int = None) -> wrappers.Session:
|
||||||
|
session_id = self.create_session(session_id)
|
||||||
|
return self.get_session(session_id)
|
||||||
|
|
||||||
def create_session(self, session_id: int = None) -> int:
|
def create_session(self, session_id: int = None) -> int:
|
||||||
"""
|
"""
|
||||||
Create a session.
|
Create a session.
|
||||||
|
|
|
@ -395,11 +395,11 @@ class ExceptionEvent:
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ConfigOption:
|
class ConfigOption:
|
||||||
label: str
|
|
||||||
name: str
|
name: str
|
||||||
value: str
|
value: str
|
||||||
type: ConfigOptionType
|
label: str = None
|
||||||
group: str
|
type: ConfigOptionType = None
|
||||||
|
group: str = None
|
||||||
select: List[str] = None
|
select: List[str] = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -737,6 +737,25 @@ class Node:
|
||||||
canvas=self.canvas,
|
canvas=self.canvas,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def set_wlan(self, config: Dict[str, str]) -> None:
|
||||||
|
for key, value in config.items():
|
||||||
|
option = ConfigOption(name=key, value=value)
|
||||||
|
self.wlan_config[key] = option
|
||||||
|
|
||||||
|
def set_mobility(self, config: Dict[str, str]) -> None:
|
||||||
|
for key, value in config.items():
|
||||||
|
option = ConfigOption(name=key, value=value)
|
||||||
|
self.mobility_config[key] = option
|
||||||
|
|
||||||
|
def set_emane_model(
|
||||||
|
self, model: str, config: Dict[str, str], iface_id: int = None
|
||||||
|
) -> None:
|
||||||
|
key = (model, iface_id)
|
||||||
|
config_options = self.emane_model_configs.setdefault(key, {})
|
||||||
|
for key, value in config.items():
|
||||||
|
option = ConfigOption(name=key, value=value)
|
||||||
|
config_options[key] = option
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Session:
|
class Session:
|
||||||
|
@ -757,9 +776,6 @@ class Session:
|
||||||
file: Path = None
|
file: Path = None
|
||||||
options: Dict[str, ConfigOption] = field(default_factory=dict)
|
options: Dict[str, ConfigOption] = field(default_factory=dict)
|
||||||
|
|
||||||
def set_node(self, node: Node) -> None:
|
|
||||||
self.nodes[node.id] = node
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_proto(cls, proto: core_pb2.Session) -> "Session":
|
def from_proto(cls, proto: core_pb2.Session) -> "Session":
|
||||||
nodes: Dict[int, Node] = {x.id: Node.from_proto(x) for x in proto.nodes}
|
nodes: Dict[int, Node] = {x.id: Node.from_proto(x) for x in proto.nodes}
|
||||||
|
@ -813,6 +829,62 @@ class Session:
|
||||||
options=options,
|
options=options,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def add_node(
|
||||||
|
self,
|
||||||
|
_id: int,
|
||||||
|
*,
|
||||||
|
name: str = None,
|
||||||
|
_type: NodeType = NodeType.DEFAULT,
|
||||||
|
model: str = "PC",
|
||||||
|
position: Position = None,
|
||||||
|
geo: Geo = None,
|
||||||
|
emane: str = None,
|
||||||
|
image: str = None,
|
||||||
|
server: str = None,
|
||||||
|
) -> Node:
|
||||||
|
node = Node(
|
||||||
|
id=_id,
|
||||||
|
name=name,
|
||||||
|
type=_type,
|
||||||
|
model=model,
|
||||||
|
position=position,
|
||||||
|
geo=geo,
|
||||||
|
emane=emane,
|
||||||
|
image=image,
|
||||||
|
server=server,
|
||||||
|
)
|
||||||
|
self.nodes[node.id] = node
|
||||||
|
return node
|
||||||
|
|
||||||
|
def add_link(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
node1: Node,
|
||||||
|
node2: Node,
|
||||||
|
iface1: Interface = None,
|
||||||
|
iface2: Interface = None,
|
||||||
|
options: LinkOptions = None,
|
||||||
|
) -> Link:
|
||||||
|
link = Link(
|
||||||
|
node1_id=node1.id,
|
||||||
|
node2_id=node2.id,
|
||||||
|
iface1=iface1,
|
||||||
|
iface2=iface2,
|
||||||
|
options=options,
|
||||||
|
)
|
||||||
|
self.links.append(link)
|
||||||
|
return link
|
||||||
|
|
||||||
|
def set_emane(self, config: Dict[str, str]) -> None:
|
||||||
|
for key, value in config.items():
|
||||||
|
option = ConfigOption(name=key, value=value)
|
||||||
|
self.emane_config[key] = option
|
||||||
|
|
||||||
|
def set_options(self, config: Dict[str, str]) -> None:
|
||||||
|
for key, value in config.items():
|
||||||
|
option = ConfigOption(name=key, value=value)
|
||||||
|
self.options[key] = option
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class LinkEvent:
|
class LinkEvent:
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from core.api.grpc import client
|
from core.api.grpc import clientw
|
||||||
from core.api.grpc.core_pb2 import Node, NodeType, Position, SessionState
|
from core.api.grpc.wrappers import NodeType, Position
|
||||||
|
|
||||||
|
|
||||||
def log_event(event):
|
def log_event(event):
|
||||||
|
@ -10,62 +10,41 @@ def log_event(event):
|
||||||
|
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
core = client.CoreGrpcClient()
|
# helper to create interfaces
|
||||||
|
interface_helper = clientw.InterfaceHelper(ip4_prefix="10.83.0.0/16")
|
||||||
|
|
||||||
with core.context_connect():
|
# create grpc client and connect
|
||||||
# create session
|
core = clientw.CoreGrpcClient()
|
||||||
response = core.create_session()
|
core.connect()
|
||||||
session_id = response.session_id
|
|
||||||
logging.info("created session: %s", response)
|
|
||||||
|
|
||||||
# add distributed server
|
# create session
|
||||||
server_name = "core2"
|
session = core.add_session()
|
||||||
response = core.add_session_server(session_id, server_name, args.server)
|
logging.info("created session: %s", session.id)
|
||||||
logging.info("added session server: %s", response)
|
|
||||||
|
|
||||||
# handle events session may broadcast
|
# add distributed server
|
||||||
core.events(session_id, log_event)
|
server_name = "core2"
|
||||||
|
result = core.add_session_server(session.id, server_name, args.server)
|
||||||
|
logging.info("added session server: %s", result)
|
||||||
|
|
||||||
# change session state
|
# handle events session may broadcast
|
||||||
response = core.set_session_state(session_id, SessionState.CONFIGURATION)
|
core.events(session.id, log_event)
|
||||||
logging.info("set session state: %s", response)
|
|
||||||
|
|
||||||
# create switch node
|
# create switch node
|
||||||
switch = Node(type=NodeType.SWITCH)
|
position = Position(x=150, y=100)
|
||||||
response = core.add_node(session_id, switch)
|
switch = session.add_node(1, _type=NodeType.SWITCH, position=position)
|
||||||
logging.info("created switch: %s", response)
|
position = Position(x=100, y=50)
|
||||||
switch_id = response.node_id
|
node1 = session.add_node(2, position=position)
|
||||||
|
position = Position(x=200, y=50)
|
||||||
|
node2 = session.add_node(3, position=position, server=server_name)
|
||||||
|
|
||||||
# helper to create interfaces
|
# create links
|
||||||
interface_helper = client.InterfaceHelper(ip4_prefix="10.83.0.0/16")
|
iface1 = interface_helper.create_iface(node1.id, 0)
|
||||||
|
session.add_link(node1=node1, node2=switch, iface1=iface1)
|
||||||
|
iface1 = interface_helper.create_iface(node2.id, 0)
|
||||||
|
session.add_link(node1=node2, node2=switch, iface1=iface1)
|
||||||
|
|
||||||
# create node one
|
# start session
|
||||||
position = Position(x=100, y=50)
|
core.start_session(session)
|
||||||
node = Node(position=position)
|
|
||||||
response = core.add_node(session_id, node)
|
|
||||||
logging.info("created node one: %s", response)
|
|
||||||
node1_id = response.node_id
|
|
||||||
|
|
||||||
# create link
|
|
||||||
interface1 = interface_helper.create_iface(node1_id, 0)
|
|
||||||
response = core.add_link(session_id, node1_id, switch_id, interface1)
|
|
||||||
logging.info("created link from node one to switch: %s", response)
|
|
||||||
|
|
||||||
# create node two
|
|
||||||
position = Position(x=200, y=50)
|
|
||||||
node = Node(position=position, server=server_name)
|
|
||||||
response = core.add_node(session_id, node)
|
|
||||||
logging.info("created node two: %s", response)
|
|
||||||
node2_id = response.node_id
|
|
||||||
|
|
||||||
# create link
|
|
||||||
interface1 = interface_helper.create_iface(node2_id, 0)
|
|
||||||
response = core.add_link(session_id, node2_id, switch_id, interface1)
|
|
||||||
logging.info("created link from node two to switch: %s", response)
|
|
||||||
|
|
||||||
# change session state
|
|
||||||
response = core.set_session_state(session_id, SessionState.INSTANTIATION)
|
|
||||||
logging.info("set session state: %s", response)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -1,54 +1,37 @@
|
||||||
# required imports
|
# required imports
|
||||||
from core.api.grpc import client
|
from core.api.grpc import clientw
|
||||||
from core.api.grpc.core_pb2 import Node, NodeType, Position, SessionState
|
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 = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
iface_helper = clientw.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
||||||
|
|
||||||
# create grpc client and connect
|
# create grpc client and connect
|
||||||
core = client.CoreGrpcClient()
|
core = clientw.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)
|
|
||||||
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"}
|
|
||||||
)
|
)
|
||||||
|
position = Position(x=100, y=100)
|
||||||
|
node1 = session.add_node(2, model="mdr", position=position)
|
||||||
|
position = Position(x=300, y=100)
|
||||||
|
node2 = session.add_node(3, model="mdr", position=position)
|
||||||
|
|
||||||
# links nodes to emane
|
# 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, emane_id, iface1)
|
session.add_link(node1=node1, node2=emane, 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, emane_id, iface1)
|
session.add_link(node1=node2, node2=emane, iface1=iface1)
|
||||||
|
|
||||||
# change session state
|
# setup emane configurations using a dict mapping currently support values as strings
|
||||||
core.set_session_state(session_id, SessionState.INSTANTIATION)
|
session.set_emane({"eventservicettl": "2"})
|
||||||
|
emane.set_emane_model(EmaneIeee80211abgModel.name, {"unicastrate": "3"})
|
||||||
|
|
||||||
|
# start session
|
||||||
|
core.start_session(session)
|
||||||
|
|
|
@ -1,36 +1,26 @@
|
||||||
from core.api.grpc import client
|
from core.api.grpc import clientw
|
||||||
from core.api.grpc.core_pb2 import Node, NodeType, Position, SessionState
|
from core.api.grpc.wrappers import Position
|
||||||
|
|
||||||
# interface helper
|
# interface helper
|
||||||
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
iface_helper = clientw.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
||||||
|
|
||||||
# create grpc client and connect
|
# create grpc client and connect
|
||||||
core = client.CoreGrpcClient()
|
core = clientw.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)
|
||||||
|
|
|
@ -1,44 +1,29 @@
|
||||||
# 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.core_pb2 import Node, NodeType, Position, SessionState
|
|
||||||
|
|
||||||
# interface helper
|
# interface helper
|
||||||
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
iface_helper = clientw.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
||||||
|
|
||||||
# create grpc client and connect
|
# create grpc client and connect
|
||||||
core = client.CoreGrpcClient()
|
core = clientw.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)
|
||||||
|
|
|
@ -1,58 +1,41 @@
|
||||||
# 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.core_pb2 import Node, NodeType, Position, SessionState
|
|
||||||
|
|
||||||
# interface helper
|
# interface helper
|
||||||
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
iface_helper = clientw.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
||||||
|
|
||||||
# create grpc client and connect
|
# create grpc client and connect
|
||||||
core = client.CoreGrpcClient()
|
core = clientw.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(
|
wlan.set_wlan(
|
||||||
session_id,
|
|
||||||
wlan_id,
|
|
||||||
{
|
{
|
||||||
"range": "280",
|
"range": "280",
|
||||||
"bandwidth": "55000000",
|
"bandwidth": "55000000",
|
||||||
"delay": "6000",
|
"delay": "6000",
|
||||||
"jitter": "5",
|
"jitter": "5",
|
||||||
"error": "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)
|
|
||||||
|
|
|
@ -55,18 +55,11 @@ class TestGrpcw:
|
||||||
session_id = client.create_session()
|
session_id = client.create_session()
|
||||||
session = client.get_session(session_id)
|
session = client.get_session(session_id)
|
||||||
position = Position(x=50, y=100)
|
position = Position(x=50, y=100)
|
||||||
node1 = Node(
|
node1 = session.add_node(1, position=position)
|
||||||
id=1, name="n1", position=position, type=NodeType.DEFAULT, model="PC"
|
|
||||||
)
|
|
||||||
position = Position(x=100, y=100)
|
position = Position(x=100, y=100)
|
||||||
node2 = Node(
|
node2 = session.add_node(2, position=position)
|
||||||
id=2, name="n2", position=position, type=NodeType.DEFAULT, model="PC"
|
|
||||||
)
|
|
||||||
position = Position(x=200, y=200)
|
position = Position(x=200, y=200)
|
||||||
wlan_node = Node(id=3, name="n3", type=NodeType.WIRELESS_LAN, position=position)
|
wlan_node = session.add_node(3, _type=NodeType.WIRELESS_LAN, position=position)
|
||||||
session.set_node(node1)
|
|
||||||
session.set_node(node2)
|
|
||||||
session.set_node(wlan_node)
|
|
||||||
iface_helper = InterfaceHelper(ip4_prefix="10.83.0.0/16")
|
iface_helper = InterfaceHelper(ip4_prefix="10.83.0.0/16")
|
||||||
iface1_id = 0
|
iface1_id = 0
|
||||||
iface1 = iface_helper.create_iface(node1.id, iface1_id)
|
iface1 = iface_helper.create_iface(node1.id, iface1_id)
|
||||||
|
@ -96,38 +89,17 @@ class TestGrpcw:
|
||||||
# setup global emane config
|
# setup global emane config
|
||||||
emane_config_key = "platform_id_start"
|
emane_config_key = "platform_id_start"
|
||||||
emane_config_value = "2"
|
emane_config_value = "2"
|
||||||
option = ConfigOption(
|
session.set_emane({emane_config_key: emane_config_value})
|
||||||
label=emane_config_key,
|
|
||||||
name=emane_config_key,
|
|
||||||
value=emane_config_value,
|
|
||||||
type=ConfigOptionType.INT64,
|
|
||||||
group="Default",
|
|
||||||
)
|
|
||||||
session.emane_config[emane_config_key] = option
|
|
||||||
|
|
||||||
# setup wlan config
|
# setup wlan config
|
||||||
wlan_config_key = "range"
|
wlan_config_key = "range"
|
||||||
wlan_config_value = "333"
|
wlan_config_value = "333"
|
||||||
option = ConfigOption(
|
wlan_node.set_wlan({wlan_config_key: wlan_config_value})
|
||||||
label=wlan_config_key,
|
|
||||||
name=wlan_config_key,
|
|
||||||
value=wlan_config_value,
|
|
||||||
type=ConfigOptionType.INT64,
|
|
||||||
group="Default",
|
|
||||||
)
|
|
||||||
wlan_node.wlan_config[wlan_config_key] = option
|
|
||||||
|
|
||||||
# setup mobility config
|
# setup mobility config
|
||||||
mobility_config_key = "refresh_ms"
|
mobility_config_key = "refresh_ms"
|
||||||
mobility_config_value = "60"
|
mobility_config_value = "60"
|
||||||
option = ConfigOption(
|
wlan_node.set_mobility({mobility_config_key: mobility_config_value})
|
||||||
label=mobility_config_key,
|
|
||||||
name=mobility_config_key,
|
|
||||||
value=mobility_config_value,
|
|
||||||
type=ConfigOptionType.INT64,
|
|
||||||
group="Default",
|
|
||||||
)
|
|
||||||
wlan_node.mobility_config[mobility_config_key] = option
|
|
||||||
|
|
||||||
# setup service config
|
# setup service config
|
||||||
service_name = "DefaultRoute"
|
service_name = "DefaultRoute"
|
||||||
|
@ -153,14 +125,7 @@ class TestGrpcw:
|
||||||
# setup session option
|
# setup session option
|
||||||
option_key = "controlnet"
|
option_key = "controlnet"
|
||||||
option_value = "172.16.0.0/24"
|
option_value = "172.16.0.0/24"
|
||||||
option = ConfigOption(
|
session.set_options({option_key: option_value})
|
||||||
label=option_key,
|
|
||||||
name=option_key,
|
|
||||||
value=option_value,
|
|
||||||
type=ConfigOptionType.STRING,
|
|
||||||
group="Default",
|
|
||||||
)
|
|
||||||
session.options[option_key] = option
|
|
||||||
|
|
||||||
# when
|
# when
|
||||||
with patch.object(CoreXmlWriter, "write"):
|
with patch.object(CoreXmlWriter, "write"):
|
||||||
|
|
Loading…
Add table
Reference in a new issue