added session/node dir to grpc responses and node channels, updating route monitor to use grpc for getting session/node information
This commit is contained in:
parent
2750a69e79
commit
0742c08b59
3 changed files with 45 additions and 34 deletions
|
@ -111,7 +111,7 @@ from core.emulator.enumerations import EventTypes, LinkTypes, MessageFlags
|
|||
from core.emulator.session import Session
|
||||
from core.errors import CoreCommandError, CoreError
|
||||
from core.location.mobility import BasicRangeModel, Ns2ScriptedMobility
|
||||
from core.nodes.base import CoreNodeBase, NodeBase
|
||||
from core.nodes.base import CoreNode, CoreNodeBase, NodeBase
|
||||
from core.nodes.docker import DockerNode
|
||||
from core.nodes.lxd import LxcNode
|
||||
from core.services.coreservices import ServiceManager
|
||||
|
@ -373,6 +373,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
state=session.state.value,
|
||||
nodes=session.get_node_count(),
|
||||
file=session.file_name,
|
||||
dir=session.session_dir,
|
||||
)
|
||||
sessions.append(session_summary)
|
||||
return core_pb2.GetSessionsResponse(sessions=sessions)
|
||||
|
@ -543,7 +544,6 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
node = session.nodes[_id]
|
||||
if not isinstance(node.id, int):
|
||||
continue
|
||||
|
||||
node_type = session.get_node_type(node.__class__)
|
||||
model = getattr(node, "type", None)
|
||||
position = core_pb2.Position(
|
||||
|
@ -558,8 +558,12 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
emane_model = None
|
||||
if isinstance(node, EmaneNet):
|
||||
emane_model = node.model.name
|
||||
node_dir = None
|
||||
channel = None
|
||||
if isinstance(node, CoreNode):
|
||||
node_dir = node.nodedir
|
||||
channel = node.ctrlchnlname
|
||||
image = getattr(node, "image", None)
|
||||
|
||||
node_proto = core_pb2.Node(
|
||||
id=node.id,
|
||||
name=node.name,
|
||||
|
@ -571,16 +575,17 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
icon=node.icon,
|
||||
image=image,
|
||||
config_services=config_services,
|
||||
dir=node_dir,
|
||||
channel=channel,
|
||||
)
|
||||
if isinstance(node, (DockerNode, LxcNode)):
|
||||
node_proto.image = node.image
|
||||
nodes.append(node_proto)
|
||||
|
||||
node_links = get_links(session, node)
|
||||
links.extend(node_links)
|
||||
|
||||
session_proto = core_pb2.Session(
|
||||
state=session.state.value, nodes=nodes, links=links
|
||||
state=session.state.value, nodes=nodes, links=links, dir=session.session_dir
|
||||
)
|
||||
return core_pb2.GetSessionResponse(session=session_proto)
|
||||
|
||||
|
@ -713,21 +718,22 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
logging.debug("get node: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
node = self.get_node(session, request.node_id, context)
|
||||
|
||||
interfaces = []
|
||||
for interface_id in node._netif:
|
||||
interface = node._netif[interface_id]
|
||||
interface_proto = grpcutils.interface_to_proto(interface)
|
||||
interfaces.append(interface_proto)
|
||||
|
||||
emane_model = None
|
||||
if isinstance(node, EmaneNet):
|
||||
emane_model = node.model.name
|
||||
|
||||
node_dir = None
|
||||
channel = None
|
||||
if isinstance(node, CoreNode):
|
||||
node_dir = node.nodedir
|
||||
channel = node.ctrlchnlname
|
||||
services = []
|
||||
if node.services:
|
||||
services = [x.name for x in node.services]
|
||||
|
||||
position = core_pb2.Position(
|
||||
x=node.position.x, y=node.position.y, z=node.position.z
|
||||
)
|
||||
|
@ -740,10 +746,11 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
model=node.type,
|
||||
position=position,
|
||||
services=services,
|
||||
dir=node_dir,
|
||||
channel=channel,
|
||||
)
|
||||
if isinstance(node, (DockerNode, LxcNode)):
|
||||
node_proto.image = node.image
|
||||
|
||||
return core_pb2.GetNodeResponse(node=node_proto, interfaces=interfaces)
|
||||
|
||||
def EditNode(
|
||||
|
|
|
@ -650,6 +650,7 @@ message Session {
|
|||
SessionState.Enum state = 2;
|
||||
repeated Node nodes = 3;
|
||||
repeated Link links = 4;
|
||||
string dir = 5;
|
||||
}
|
||||
|
||||
message SessionSummary {
|
||||
|
@ -657,6 +658,7 @@ message SessionSummary {
|
|||
SessionState.Enum state = 2;
|
||||
int32 nodes = 3;
|
||||
string file = 4;
|
||||
string dir = 5;
|
||||
}
|
||||
|
||||
message Node {
|
||||
|
@ -673,6 +675,8 @@ message Node {
|
|||
string server = 11;
|
||||
repeated string config_services = 12;
|
||||
Geo geo = 13;
|
||||
string dir = 14;
|
||||
string channel = 15;
|
||||
}
|
||||
|
||||
message Link {
|
||||
|
|
|
@ -7,11 +7,13 @@ import subprocess
|
|||
import time
|
||||
from argparse import ArgumentDefaultsHelpFormatter
|
||||
from functools import cmp_to_key
|
||||
from glob import glob
|
||||
from queue import Queue
|
||||
from threading import Thread
|
||||
from typing import Dict, Tuple
|
||||
|
||||
from core.api.grpc.client import CoreGrpcClient
|
||||
from core.api.grpc.core_pb2 import NodeType
|
||||
|
||||
SDT_HOST = "127.0.0.1"
|
||||
SDT_PORT = 50000
|
||||
ROUTE_LAYER = "CORE Route"
|
||||
|
@ -20,25 +22,6 @@ ROUTE_TIME = 3
|
|||
PACKET_CHOICES = ["udp", "tcp", "icmp"]
|
||||
|
||||
|
||||
def find_nodes() -> Dict[str, str]:
|
||||
sessions = glob("/tmp/pycore.*")
|
||||
session = None
|
||||
if sessions:
|
||||
session = sessions[0]
|
||||
if not session:
|
||||
raise Exception("failed to find core session")
|
||||
print("core session: ", session)
|
||||
nodes = {}
|
||||
with open(f"{session}/nodes", "r") as f:
|
||||
for line in f.readlines():
|
||||
line = line.strip()
|
||||
values = line.split()
|
||||
if values[2] == "NodeTypes.DEFAULT":
|
||||
print("node: ", values[1])
|
||||
nodes[values[0]] = f"{session}/{values[1]}"
|
||||
return nodes
|
||||
|
||||
|
||||
class RouteEnum(enum.Enum):
|
||||
ADD = 0
|
||||
DEL = 1
|
||||
|
@ -70,10 +53,10 @@ class SdtClient:
|
|||
|
||||
|
||||
class RouterMonitor:
|
||||
def __init__(self, nodes: Dict[str, str], src_id: str, src: str, dst: str, pkt: str,
|
||||
def __init__(self, src_id: str, src: str, dst: str, pkt: str,
|
||||
sdt_host: str, sdt_port: int) -> None:
|
||||
self.queue = Queue()
|
||||
self.nodes = nodes
|
||||
self.core = CoreGrpcClient()
|
||||
self.src_id = src_id
|
||||
self.src = src
|
||||
self.dst = dst
|
||||
|
@ -82,6 +65,25 @@ class RouterMonitor:
|
|||
self.running = False
|
||||
self.route_time = None
|
||||
self.sdt = SdtClient((sdt_host, sdt_port))
|
||||
self.nodes = self.get_nodes()
|
||||
|
||||
def get_nodes(self) -> Dict[str, str]:
|
||||
nodes = {}
|
||||
with self.core.context_connect():
|
||||
response = self.core.get_sessions()
|
||||
sessions = response.sessions
|
||||
session = None
|
||||
if sessions:
|
||||
session = sessions[0]
|
||||
if not session:
|
||||
raise Exception("no current core sessions")
|
||||
print(session.dir)
|
||||
response = self.core.get_session(session.id)
|
||||
for node in response.session.nodes:
|
||||
if node.type != NodeType.DEFAULT:
|
||||
continue
|
||||
nodes[node.id] = node.channel
|
||||
return nodes
|
||||
|
||||
def start(self) -> None:
|
||||
self.running = True
|
||||
|
@ -176,9 +178,7 @@ def main() -> None:
|
|||
parser.add_argument("--sdt-port", type=int, default=SDT_PORT, help="sdt port")
|
||||
args = parser.parse_args()
|
||||
|
||||
nodes = find_nodes()
|
||||
monitor = RouterMonitor(
|
||||
nodes,
|
||||
args.id,
|
||||
args.src,
|
||||
args.dst,
|
||||
|
|
Loading…
Reference in a new issue