updated logging usage, to use the library directly and avoid imposing a core config by default, allowing users of the core library to configure logging as desired

This commit is contained in:
bharnden 2019-02-16 09:50:19 -08:00
parent 37f747c212
commit 7aee2b2ba7
44 changed files with 552 additions and 527 deletions

View file

@ -1,18 +1,24 @@
import json import json
import logging
import logging.config import logging.config
import os import os
import subprocess import subprocess
from core import constants from core import constants
# setup logging # setup default null handler
log_config_path = os.path.join(constants.CORE_CONF_DIR, "logging.conf") logging.getLogger(__name__).addHandler(logging.NullHandler())
with open(log_config_path, "r") as log_config_file:
log_config = json.load(log_config_file)
logging.config.dictConfig(log_config)
logger = logging.getLogger()
def load_logging_config():
"""
Load CORE logging configuration file.
:return: nothing
"""
log_config_path = os.path.join(constants.CORE_CONF_DIR, "logging.conf")
with open(log_config_path, "r") as log_config_file:
log_config = json.load(log_config_file)
logging.config.dictConfig(log_config)
class CoreCommandError(subprocess.CalledProcessError): class CoreCommandError(subprocess.CalledProcessError):

View file

@ -4,12 +4,12 @@ other emulation servers. The broker is consulted when handling messages to deter
should be handled locally or forwarded on to another emulation server. should be handled locally or forwarded on to another emulation server.
""" """
import logging
import os import os
import select import select
import socket import socket
import threading import threading
from core import logger
from core.api import coreapi from core.api import coreapi
from core.coreobj import PyCoreNet from core.coreobj import PyCoreNet
from core.coreobj import PyCoreNode from core.coreobj import PyCoreNode
@ -148,7 +148,7 @@ class CoreBroker(object):
while len(self.servers) > 0: while len(self.servers) > 0:
name, server = self.servers.popitem() name, server = self.servers.popitem()
if server.sock is not None: if server.sock is not None:
logger.info("closing connection with %s: %s:%s", name, server.host, server.port) logging.info("closing connection with %s: %s:%s", name, server.host, server.port)
server.close() server.close()
self.dorecvloop = False self.dorecvloop = False
if self.recvthread is not None: if self.recvthread is not None:
@ -158,7 +158,7 @@ class CoreBroker(object):
""" """
Reset to initial state. Reset to initial state.
""" """
logger.info("clearing state") logging.info("clearing state")
self.nodemap_lock.acquire() self.nodemap_lock.acquire()
self.nodemap.clear() self.nodemap.clear()
for server, count in self.nodecounts.iteritems(): for server, count in self.nodecounts.iteritems():
@ -178,13 +178,13 @@ class CoreBroker(object):
Spawn the receive loop for receiving messages. Spawn the receive loop for receiving messages.
""" """
if self.recvthread is not None: if self.recvthread is not None:
logger.info("server receive loop already started") logging.info("server receive loop already started")
if self.recvthread.isAlive(): if self.recvthread.isAlive():
return return
else: else:
self.recvthread.join() self.recvthread.join()
# start reading data from connected sockets # start reading data from connected sockets
logger.info("starting server receive loop") logging.info("starting server receive loop")
self.dorecvloop = True self.dorecvloop = True
self.recvthread = threading.Thread(target=self.recvloop) self.recvthread = threading.Thread(target=self.recvloop)
self.recvthread.daemon = True self.recvthread.daemon = True
@ -207,14 +207,14 @@ class CoreBroker(object):
r, _w, _x = select.select(rlist, [], [], 1.0) r, _w, _x = select.select(rlist, [], [], 1.0)
for sock in r: for sock in r:
server = self.getserverbysock(sock) server = self.getserverbysock(sock)
logger.info("attempting to receive from server: peer:%s remote:%s", logging.info("attempting to receive from server: peer:%s remote:%s",
server.sock.getpeername(), server.sock.getsockname()) server.sock.getpeername(), server.sock.getsockname())
if server is None: if server is None:
# servers may have changed; loop again # servers may have changed; loop again
continue continue
rcvlen = self.recv(server) rcvlen = self.recv(server)
if rcvlen == 0: if rcvlen == 0:
logger.info("connection with server(%s) closed: %s:%s", server.name, server.host, server.port) logging.info("connection with server(%s) closed: %s:%s", server.name, server.host, server.port)
def recv(self, server): def recv(self, server):
""" """
@ -230,23 +230,23 @@ class CoreBroker(object):
msghdr = server.sock.recv(coreapi.CoreMessage.header_len) msghdr = server.sock.recv(coreapi.CoreMessage.header_len)
if len(msghdr) == 0: if len(msghdr) == 0:
# server disconnected # server disconnected
logger.info("server disconnected, closing server") logging.info("server disconnected, closing server")
server.close() server.close()
return 0 return 0
if len(msghdr) != coreapi.CoreMessage.header_len: if len(msghdr) != coreapi.CoreMessage.header_len:
logger.warn("warning: broker received not enough data len=%s", len(msghdr)) logging.warn("warning: broker received not enough data len=%s", len(msghdr))
return len(msghdr) return len(msghdr)
msgtype, msgflags, msglen = coreapi.CoreMessage.unpack_header(msghdr) msgtype, msgflags, msglen = coreapi.CoreMessage.unpack_header(msghdr)
msgdata = server.sock.recv(msglen) msgdata = server.sock.recv(msglen)
data = msghdr + msgdata data = msghdr + msgdata
count = None count = None
logger.debug("received message type: %s", MessageTypes(msgtype)) logging.debug("received message type: %s", MessageTypes(msgtype))
# snoop exec response for remote interactive TTYs # snoop exec response for remote interactive TTYs
if msgtype == MessageTypes.EXECUTE.value and msgflags & MessageFlags.TTY.value: if msgtype == MessageTypes.EXECUTE.value and msgflags & MessageFlags.TTY.value:
data = self.fixupremotetty(msghdr, msgdata, server.host) data = self.fixupremotetty(msghdr, msgdata, server.host)
logger.debug("created remote tty message: %s", data) logging.debug("created remote tty message: %s", data)
elif msgtype == MessageTypes.NODE.value: elif msgtype == MessageTypes.NODE.value:
# snoop node delete response to decrement node counts # snoop node delete response to decrement node counts
if msgflags & MessageFlags.DELETE.value: if msgflags & MessageFlags.DELETE.value:
@ -266,13 +266,13 @@ class CoreBroker(object):
if self.instantiation_complete(): if self.instantiation_complete():
self.session.check_runtime() self.session.check_runtime()
else: else:
logger.error("unknown message type received: %s", msgtype) logging.error("unknown message type received: %s", msgtype)
try: try:
for session_client in self.session_clients: for session_client in self.session_clients:
session_client.sendall(data) session_client.sendall(data)
except IOError: except IOError:
logger.exception("error sending message") logging.exception("error sending message")
if count is not None and count < 1: if count is not None and count < 1:
return 0 return 0
@ -296,17 +296,17 @@ class CoreBroker(object):
# leave this socket connected # leave this socket connected
return return
logger.info("closing connection with %s @ %s:%s", name, server.host, server.port) logging.info("closing connection with %s @ %s:%s", name, server.host, server.port)
server.close() server.close()
del self.servers[name] del self.servers[name]
logger.info("adding broker server(%s): %s:%s", name, host, port) logging.info("adding broker server(%s): %s:%s", name, host, port)
server = CoreDistributedServer(name, host, port) server = CoreDistributedServer(name, host, port)
if host is not None and port is not None: if host is not None and port is not None:
try: try:
server.connect() server.connect()
except IOError: except IOError:
logger.exception("error connecting to server(%s): %s:%s", name, host, port) logging.exception("error connecting to server(%s): %s:%s", name, host, port)
if server.sock is not None: if server.sock is not None:
self.startrecvloop() self.startrecvloop()
self.servers[name] = server self.servers[name] = server
@ -324,10 +324,10 @@ class CoreBroker(object):
if s != server: if s != server:
raise ValueError("server removed was not the server provided") raise ValueError("server removed was not the server provided")
except KeyError: except KeyError:
logger.exception("error deleting server") logging.exception("error deleting server")
if server.sock is not None: if server.sock is not None:
logger.info("closing connection with %s @ %s:%s", server.name, server.host, server.port) logging.info("closing connection with %s @ %s:%s", server.name, server.host, server.port)
server.close() server.close()
def getserverbyname(self, name): def getserverbyname(self, name):
@ -411,10 +411,10 @@ class CoreBroker(object):
remotenum = n2num remotenum = n2num
if key in self.tunnels.keys(): if key in self.tunnels.keys():
logger.warn("tunnel with key %s (%s-%s) already exists!", key, n1num, n2num) logging.warn("tunnel with key %s (%s-%s) already exists!", key, n1num, n2num)
else: else:
objid = key & ((1 << 16) - 1) objid = key & ((1 << 16) - 1)
logger.info("adding tunnel for %s-%s to %s with key %s", n1num, n2num, remoteip, key) logging.info("adding tunnel for %s-%s to %s with key %s", n1num, n2num, remoteip, key)
if localnum in self.physical_nodes: if localnum in self.physical_nodes:
# no bridge is needed on physical nodes; use the GreTap directly # no bridge is needed on physical nodes; use the GreTap directly
gt = GreTap(node=None, name=None, session=self.session, gt = GreTap(node=None, name=None, session=self.session,
@ -431,7 +431,7 @@ class CoreBroker(object):
Add GreTaps between network devices on different machines. Add GreTaps between network devices on different machines.
The GreTapBridge is not used since that would add an extra bridge. The GreTapBridge is not used since that would add an extra bridge.
""" """
logger.debug("adding network tunnels for nodes: %s", self.network_nodes) logging.debug("adding network tunnels for nodes: %s", self.network_nodes)
for n in self.network_nodes: for n in self.network_nodes:
self.addnettunnel(n) self.addnettunnel(n)
@ -445,30 +445,30 @@ class CoreBroker(object):
""" """
try: try:
net = self.session.get_object(node_id) net = self.session.get_object(node_id)
logger.info("adding net tunnel for: id(%s) %s", node_id, net) logging.info("adding net tunnel for: id(%s) %s", node_id, net)
except KeyError: except KeyError:
raise KeyError("network node %s not found" % node_id) raise KeyError("network node %s not found" % node_id)
# add other nets here that do not require tunnels # add other nets here that do not require tunnels
if nodeutils.is_node(net, NodeTypes.EMANE_NET): if nodeutils.is_node(net, NodeTypes.EMANE_NET):
logger.warn("emane network does not require a tunnel") logging.warn("emane network does not require a tunnel")
return None return None
server_interface = getattr(net, "serverintf", None) server_interface = getattr(net, "serverintf", None)
if nodeutils.is_node(net, NodeTypes.CONTROL_NET) and server_interface is not None: if nodeutils.is_node(net, NodeTypes.CONTROL_NET) and server_interface is not None:
logger.warn("control networks with server interfaces do not need a tunnel") logging.warn("control networks with server interfaces do not need a tunnel")
return None return None
servers = self.getserversbynode(node_id) servers = self.getserversbynode(node_id)
if len(servers) < 2: if len(servers) < 2:
logger.warn("not enough servers to create a tunnel: %s", servers) logging.warn("not enough servers to create a tunnel: %s", servers)
return None return None
hosts = [] hosts = []
for server in servers: for server in servers:
if server.host is None: if server.host is None:
continue continue
logger.info("adding server host for net tunnel: %s", server.host) logging.info("adding server host for net tunnel: %s", server.host)
hosts.append(server.host) hosts.append(server.host)
if len(hosts) == 0: if len(hosts) == 0:
@ -476,7 +476,7 @@ class CoreBroker(object):
# get IP address from API message sender (master) # get IP address from API message sender (master)
if session_client.client_address != "": if session_client.client_address != "":
address = session_client.client_address[0] address = session_client.client_address[0]
logger.info("adding session_client host: %s", address) logging.info("adding session_client host: %s", address)
hosts.append(address) hosts.append(address)
r = [] r = []
@ -489,11 +489,11 @@ class CoreBroker(object):
myip = host myip = host
key = self.tunnelkey(node_id, IpAddress.to_int(myip)) key = self.tunnelkey(node_id, IpAddress.to_int(myip))
if key in self.tunnels.keys(): if key in self.tunnels.keys():
logger.info("tunnel already exists, returning existing tunnel: %s", key) logging.info("tunnel already exists, returning existing tunnel: %s", key)
gt = self.tunnels[key] gt = self.tunnels[key]
r.append(gt) r.append(gt)
continue continue
logger.info("adding tunnel for net %s to %s with key %s", node_id, host, key) logging.info("adding tunnel for net %s to %s with key %s", node_id, host, key)
gt = GreTap(node=None, name=None, session=self.session, remoteip=host, key=key) gt = GreTap(node=None, name=None, session=self.session, remoteip=host, key=key)
self.tunnels[key] = gt self.tunnels[key] = gt
r.append(gt) r.append(gt)
@ -513,7 +513,7 @@ class CoreBroker(object):
""" """
key = self.tunnelkey(n1num, n2num) key = self.tunnelkey(n1num, n2num)
try: try:
logger.info("deleting tunnel between %s - %s with key: %s", n1num, n2num, key) logging.info("deleting tunnel between %s - %s with key: %s", n1num, n2num, key)
gt = self.tunnels.pop(key) gt = self.tunnels.pop(key)
except KeyError: except KeyError:
gt = None gt = None
@ -530,7 +530,7 @@ class CoreBroker(object):
:return: gre tap between nodes or none :return: gre tap between nodes or none
""" """
key = self.tunnelkey(n1num, n2num) key = self.tunnelkey(n1num, n2num)
logger.debug("checking for tunnel(%s) in: %s", key, self.tunnels.keys()) logging.debug("checking for tunnel(%s) in: %s", key, self.tunnels.keys())
if key in self.tunnels.keys(): if key in self.tunnels.keys():
return self.tunnels[key] return self.tunnels[key]
else: else:
@ -600,9 +600,9 @@ class CoreBroker(object):
:param int nodenum: node id to add :param int nodenum: node id to add
:return: nothing :return: nothing
""" """
logger.info("adding net to broker: %s", nodenum) logging.info("adding net to broker: %s", nodenum)
self.network_nodes.add(nodenum) self.network_nodes.add(nodenum)
logger.info("broker network nodes: %s", self.network_nodes) logging.info("broker network nodes: %s", self.network_nodes)
def addphys(self, nodenum): def addphys(self, nodenum):
""" """
@ -677,11 +677,11 @@ class CoreBroker(object):
""" """
server = self.getserverbyname(servername) server = self.getserverbyname(servername)
if server is None: if server is None:
logger.warn("ignoring unknown server: %s", servername) logging.warn("ignoring unknown server: %s", servername)
return return
if server.sock is None or server.host is None or server.port is None: if server.sock is None or server.host is None or server.port is None:
logger.info("ignoring disconnected server: %s", servername) logging.info("ignoring disconnected server: %s", servername)
return return
# communicate this session"s current state to the server # communicate this session"s current state to the server
@ -753,10 +753,10 @@ class CoreBroker(object):
try: try:
nodecls = nodeutils.get_node_class(NodeTypes(nodetype)) nodecls = nodeutils.get_node_class(NodeTypes(nodetype))
except KeyError: except KeyError:
logger.warn("broker invalid node type %s", nodetype) logging.warn("broker invalid node type %s", nodetype)
return handle_locally, servers return handle_locally, servers
if nodecls is None: if nodecls is None:
logger.warn("broker unimplemented node type %s", nodetype) logging.warn("broker unimplemented node type %s", nodetype)
return handle_locally, servers return handle_locally, servers
if issubclass(nodecls, PyCoreNet) and nodetype != NodeTypes.WIRELESS_LAN.value: if issubclass(nodecls, PyCoreNet) and nodetype != NodeTypes.WIRELESS_LAN.value:
# network node replicated on all servers; could be optimized # network node replicated on all servers; could be optimized
@ -808,7 +808,7 @@ class CoreBroker(object):
# determine link message destination using non-network nodes # determine link message destination using non-network nodes
nn = message.node_numbers() nn = message.node_numbers()
logger.debug("checking link nodes (%s) with network nodes (%s)", nn, self.network_nodes) logging.debug("checking link nodes (%s) with network nodes (%s)", nn, self.network_nodes)
if nn[0] in self.network_nodes: if nn[0] in self.network_nodes:
if nn[1] in self.network_nodes: if nn[1] in self.network_nodes:
# two network nodes linked together - prevent loops caused by # two network nodes linked together - prevent loops caused by
@ -819,11 +819,11 @@ class CoreBroker(object):
elif nn[1] in self.network_nodes: elif nn[1] in self.network_nodes:
servers = self.getserversbynode(nn[0]) servers = self.getserversbynode(nn[0])
else: else:
logger.debug("link nodes are not network nodes") logging.debug("link nodes are not network nodes")
servers1 = self.getserversbynode(nn[0]) servers1 = self.getserversbynode(nn[0])
logger.debug("servers for node(%s): %s", nn[0], servers1) logging.debug("servers for node(%s): %s", nn[0], servers1)
servers2 = self.getserversbynode(nn[1]) servers2 = self.getserversbynode(nn[1])
logger.debug("servers for node(%s): %s", nn[1], servers2) logging.debug("servers for node(%s): %s", nn[1], servers2)
# nodes are on two different servers, build tunnels as needed # nodes are on two different servers, build tunnels as needed
if servers1 != servers2: if servers1 != servers2:
localn = None localn = None
@ -852,7 +852,7 @@ class CoreBroker(object):
if host is None: if host is None:
host = self.getlinkendpoint(message, localn == nn[0]) host = self.getlinkendpoint(message, localn == nn[0])
logger.debug("handle locally(%s) and local node(%s)", handle_locally, localn) logging.debug("handle locally(%s) and local node(%s)", handle_locally, localn)
if localn is None: if localn is None:
message = self.addlinkendpoints(message, servers1, servers2) message = self.addlinkendpoints(message, servers1, servers2)
elif message.flags & MessageFlags.ADD.value: elif message.flags & MessageFlags.ADD.value:
@ -955,10 +955,10 @@ class CoreBroker(object):
# local emulation server, handle this locally # local emulation server, handle this locally
handle_locally = True handle_locally = True
elif server.sock is None: elif server.sock is None:
logger.info("server %s @ %s:%s is disconnected", server.name, server.host, server.port) logging.info("server %s @ %s:%s is disconnected", server.name, server.host, server.port)
else: else:
logger.info("forwarding message to server(%s): %s:%s", server.name, server.host, server.port) logging.info("forwarding message to server(%s): %s:%s", server.name, server.host, server.port)
logger.debug("message being forwarded:\n%s", message) logging.debug("message being forwarded:\n%s", message)
server.sock.send(message.raw_message) server.sock.send(message.raw_message)
return handle_locally return handle_locally
@ -986,7 +986,7 @@ class CoreBroker(object):
lhost, lport = server.sock.getsockname() lhost, lport = server.sock.getsockname()
f.write("%s %s %s %s %s\n" % (server.name, server.host, server.port, lhost, lport)) f.write("%s %s %s %s %s\n" % (server.name, server.host, server.port, lhost, lport))
except IOError: except IOError:
logger.exception("error writing server list to the file: %s", filename) logging.exception("error writing server list to the file: %s", filename)
def writenodeserver(self, nodestr, server): def writenodeserver(self, nodestr, server):
""" """
@ -1007,13 +1007,13 @@ class CoreBroker(object):
os.makedirs(dirname) os.makedirs(dirname)
except OSError: except OSError:
# directory may already exist from previous distributed run # directory may already exist from previous distributed run
logger.exception("error creating directory: %s", dirname) logging.exception("error creating directory: %s", dirname)
try: try:
with open(filename, "w") as f: with open(filename, "w") as f:
f.write("%s\n%s\n" % (serverstr, nodestr)) f.write("%s\n%s\n" % (serverstr, nodestr))
except IOError: except IOError:
logger.exception("error writing server file %s for node %s", filename, name) logging.exception("error writing server file %s for node %s", filename, name)
def local_instantiation_complete(self): def local_instantiation_complete(self):
""" """
@ -1089,12 +1089,12 @@ class CoreBroker(object):
control_nets = value.split() control_nets = value.split()
if len(control_nets) < 2: if len(control_nets) < 2:
logger.warn("multiple controlnet prefixes do not exist") logging.warn("multiple controlnet prefixes do not exist")
return return
servers = self.session.broker.getservernames() servers = self.session.broker.getservernames()
if len(servers) < 2: if len(servers) < 2:
logger.warn("not distributed") logging.warn("not distributed")
return return
servers.remove("localhost") servers.remove("localhost")

View file

@ -2,9 +2,9 @@
Common support for configurable CORE objects. Common support for configurable CORE objects.
""" """
import logging
from collections import OrderedDict from collections import OrderedDict
from core import logger
from core.data import ConfigData from core.data import ConfigData
@ -63,9 +63,9 @@ class ConfigShim(object):
captions = None captions = None
data_types = [] data_types = []
possible_values = [] possible_values = []
logger.debug("configurable: %s", configurable_options) logging.debug("configurable: %s", configurable_options)
logger.debug("configuration options: %s", configurable_options.configurations) logging.debug("configuration options: %s", configurable_options.configurations)
logger.debug("configuration data: %s", config) logging.debug("configuration data: %s", config)
for configuration in configurable_options.configurations(): for configuration in configurable_options.configurations():
if not captions: if not captions:
captions = configuration.label captions = configuration.label
@ -159,7 +159,7 @@ class ConfigurableManager(object):
:param int node_id: node id to clear configurations for, default is None and clears all configurations :param int node_id: node id to clear configurations for, default is None and clears all configurations
:return: nothing :return: nothing
""" """
logger.debug("resetting all configurations: %s", self.__class__.__name__) logging.debug("resetting all configurations: %s", self.__class__.__name__)
if not node_id: if not node_id:
self.node_configurations.clear() self.node_configurations.clear()
elif node_id in self.node_configurations: elif node_id in self.node_configurations:
@ -175,7 +175,7 @@ class ConfigurableManager(object):
:param str config_type: configuration type to store configuration for :param str config_type: configuration type to store configuration for
:return: nothing :return: nothing
""" """
logger.debug("setting config for node(%s) type(%s): %s=%s", node_id, config_type, _id, value) logging.debug("setting config for node(%s) type(%s): %s=%s", node_id, config_type, _id, value)
node_configs = self.node_configurations.setdefault(node_id, OrderedDict()) node_configs = self.node_configurations.setdefault(node_id, OrderedDict())
node_type_configs = node_configs.setdefault(config_type, OrderedDict()) node_type_configs = node_configs.setdefault(config_type, OrderedDict())
node_type_configs[_id] = value node_type_configs[_id] = value
@ -189,7 +189,7 @@ class ConfigurableManager(object):
:param str config_type: configuration type to store configuration for :param str config_type: configuration type to store configuration for
:return: nothing :return: nothing
""" """
logger.debug("setting config for node(%s) type(%s): %s", node_id, config_type, config) logging.debug("setting config for node(%s) type(%s): %s", node_id, config_type, config)
node_configs = self.node_configurations.setdefault(node_id, OrderedDict()) node_configs = self.node_configurations.setdefault(node_id, OrderedDict())
node_configs[config_type] = config node_configs[config_type] = config
@ -204,7 +204,7 @@ class ConfigurableManager(object):
:return: configuration value :return: configuration value
:rtype str :rtype str
""" """
logger.debug("getting config for node(%s) type(%s): %s", node_id, config_type, _id) logging.debug("getting config for node(%s) type(%s): %s", node_id, config_type, _id)
result = default result = default
node_type_configs = self.get_configs(node_id, config_type) node_type_configs = self.get_configs(node_id, config_type)
if node_type_configs: if node_type_configs:
@ -220,7 +220,7 @@ class ConfigurableManager(object):
:return: configurations :return: configurations
:rtype: dict :rtype: dict
""" """
logger.debug("getting configs for node(%s) type(%s)", node_id, config_type) logging.debug("getting configs for node(%s) type(%s)", node_id, config_type)
result = None result = None
node_configs = self.node_configurations.get(node_id) node_configs = self.node_configurations.get(node_id)
if node_configs: if node_configs:
@ -235,7 +235,7 @@ class ConfigurableManager(object):
:return: all configuration types for a node :return: all configuration types for a node
:rtype: dict :rtype: dict
""" """
logger.debug("getting all configs for node(%s)", node_id) logging.debug("getting all configs for node(%s)", node_id)
return self.node_configurations.get(node_id) return self.node_configurations.get(node_id)
@ -369,7 +369,7 @@ class ModelManager(ConfigurableManager):
:param dict config: model configuration, None for default configuration :param dict config: model configuration, None for default configuration
:return: nothing :return: nothing
""" """
logger.info("setting mobility model(%s) for node(%s): %s", model_class.name, node.objid, config) logging.info("setting mobility model(%s) for node(%s): %s", model_class.name, node.objid, config)
self.set_model_config(node.objid, model_class.name, config) self.set_model_config(node.objid, model_class.name, config)
config = self.get_model_config(node.objid, model_class.name) config = self.get_model_config(node.objid, model_class.name)
node.setmodel(model_class, config) node.setmodel(model_class, config)
@ -394,5 +394,5 @@ class ModelManager(ConfigurableManager):
model_class = self.models[model_name] model_class = self.models[model_name]
models.append((model_class, config)) models.append((model_class, config))
logger.debug("models for node(%s): %s", node.objid, models) logging.debug("models for node(%s): %s", node.objid, models)
return models return models

View file

@ -4,6 +4,7 @@ socket server request handlers leveraged by core servers.
import Queue import Queue
import SocketServer import SocketServer
import logging
import os import os
import shlex import shlex
import shutil import shutil
@ -12,7 +13,6 @@ import threading
import time import time
from itertools import repeat from itertools import repeat
from core import logger
from core.api import coreapi from core.api import coreapi
from core.api import dataconversion from core.api import dataconversion
from core.conf import ConfigShim from core.conf import ConfigShim
@ -81,7 +81,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
if num_threads < 1: if num_threads < 1:
raise ValueError("invalid number of threads: %s" % num_threads) raise ValueError("invalid number of threads: %s" % num_threads)
logger.debug("launching core server handler threads: %s", num_threads) logging.debug("launching core server handler threads: %s", num_threads)
for _ in xrange(num_threads): for _ in xrange(num_threads):
thread = threading.Thread(target=self.handler_thread) thread = threading.Thread(target=self.handler_thread)
self.handler_threads.append(thread) self.handler_threads.append(thread)
@ -102,7 +102,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
:return: nothing :return: nothing
""" """
logger.debug("new TCP connection: %s", self.client_address) logging.debug("new TCP connection: %s", self.client_address)
def finish(self): def finish(self):
""" """
@ -111,35 +111,35 @@ class CoreHandler(SocketServer.BaseRequestHandler):
:return: nothing :return: nothing
""" """
logger.debug("finishing request handler") logging.debug("finishing request handler")
logger.debug("remaining message queue size: %s", self.message_queue.qsize()) logging.debug("remaining message queue size: %s", self.message_queue.qsize())
# give some time for message queue to deplete # give some time for message queue to deplete
timeout = 10 timeout = 10
wait = 0 wait = 0
while not self.message_queue.empty(): while not self.message_queue.empty():
logger.debug("waiting for message queue to empty: %s seconds", wait) logging.debug("waiting for message queue to empty: %s seconds", wait)
time.sleep(1) time.sleep(1)
wait += 1 wait += 1
if wait == timeout: if wait == timeout:
logger.warn("queue failed to be empty, finishing request handler") logging.warn("queue failed to be empty, finishing request handler")
break break
logger.info("client disconnected: notifying threads") logging.info("client disconnected: notifying threads")
self.done = True self.done = True
for thread in self.handler_threads: for thread in self.handler_threads:
logger.info("waiting for thread: %s", thread.getName()) logging.info("waiting for thread: %s", thread.getName())
thread.join(timeout) thread.join(timeout)
if thread.isAlive(): if thread.isAlive():
logger.warn("joining %s failed: still alive after %s sec", thread.getName(), timeout) logging.warn("joining %s failed: still alive after %s sec", thread.getName(), timeout)
logger.info("connection closed: %s", self.client_address) logging.info("connection closed: %s", self.client_address)
if self.session: if self.session:
# remove client from session broker and shutdown if there are no clients # remove client from session broker and shutdown if there are no clients
self.remove_session_handlers() self.remove_session_handlers()
self.session.broker.session_clients.remove(self) self.session.broker.session_clients.remove(self)
if not self.session.broker.session_clients and not self.session.is_active(): if not self.session.broker.session_clients and not self.session.is_active():
logger.info("no session clients left and not active, initiating shutdown") logging.info("no session clients left and not active, initiating shutdown")
self.coreemu.delete_session(self.session.session_id) self.coreemu.delete_session(self.session.session_id)
return SocketServer.BaseRequestHandler.finish(self) return SocketServer.BaseRequestHandler.finish(self)
@ -217,7 +217,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
:param core.data.EventData event_data: event data to handle :param core.data.EventData event_data: event data to handle
:return: nothing :return: nothing
""" """
logger.debug("handling broadcast event: %s", event_data) logging.debug("handling broadcast event: %s", event_data)
tlv_data = structutils.pack_values(coreapi.CoreEventTlv, [ tlv_data = structutils.pack_values(coreapi.CoreEventTlv, [
(EventTlvs.NODE, event_data.node), (EventTlvs.NODE, event_data.node),
@ -232,7 +232,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
try: try:
self.sendall(message) self.sendall(message)
except IOError: except IOError:
logger.exception("error sending event message") logging.exception("error sending event message")
def handle_broadcast_file(self, file_data): def handle_broadcast_file(self, file_data):
""" """
@ -241,7 +241,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
:param core.data.FileData file_data: file data to handle :param core.data.FileData file_data: file data to handle
:return: nothing :return: nothing
""" """
logger.debug("handling broadcast file: %s", file_data) logging.debug("handling broadcast file: %s", file_data)
tlv_data = structutils.pack_values(coreapi.CoreFileTlv, [ tlv_data = structutils.pack_values(coreapi.CoreFileTlv, [
(FileTlvs.NODE, file_data.node), (FileTlvs.NODE, file_data.node),
@ -259,7 +259,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
try: try:
self.sendall(message) self.sendall(message)
except IOError: except IOError:
logger.exception("error sending file message") logging.exception("error sending file message")
def handle_broadcast_config(self, config_data): def handle_broadcast_config(self, config_data):
""" """
@ -268,12 +268,12 @@ class CoreHandler(SocketServer.BaseRequestHandler):
:param core.data.ConfigData config_data: config data to handle :param core.data.ConfigData config_data: config data to handle
:return: nothing :return: nothing
""" """
logger.debug("handling broadcast config: %s", config_data) logging.debug("handling broadcast config: %s", config_data)
message = dataconversion.convert_config(config_data) message = dataconversion.convert_config(config_data)
try: try:
self.sendall(message) self.sendall(message)
except IOError: except IOError:
logger.exception("error sending config message") logging.exception("error sending config message")
def handle_broadcast_exception(self, exception_data): def handle_broadcast_exception(self, exception_data):
""" """
@ -282,7 +282,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
:param core.data.ExceptionData exception_data: exception data to handle :param core.data.ExceptionData exception_data: exception data to handle
:return: nothing :return: nothing
""" """
logger.debug("handling broadcast exception: %s", exception_data) logging.debug("handling broadcast exception: %s", exception_data)
tlv_data = structutils.pack_values(coreapi.CoreExceptionTlv, [ tlv_data = structutils.pack_values(coreapi.CoreExceptionTlv, [
(ExceptionTlvs.NODE, exception_data.node), (ExceptionTlvs.NODE, exception_data.node),
(ExceptionTlvs.SESSION, exception_data.session), (ExceptionTlvs.SESSION, exception_data.session),
@ -296,7 +296,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
try: try:
self.sendall(message) self.sendall(message)
except IOError: except IOError:
logger.exception("error sending exception message") logging.exception("error sending exception message")
def handle_broadcast_node(self, node_data): def handle_broadcast_node(self, node_data):
""" """
@ -305,12 +305,12 @@ class CoreHandler(SocketServer.BaseRequestHandler):
:param core.data.NodeData node_data: node data to handle :param core.data.NodeData node_data: node data to handle
:return: nothing :return: nothing
""" """
logger.debug("handling broadcast node: %s", node_data) logging.debug("handling broadcast node: %s", node_data)
message = dataconversion.convert_node(node_data) message = dataconversion.convert_node(node_data)
try: try:
self.sendall(message) self.sendall(message)
except IOError: except IOError:
logger.exception("error sending node message") logging.exception("error sending node message")
def handle_broadcast_link(self, link_data): def handle_broadcast_link(self, link_data):
""" """
@ -319,7 +319,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
:param core.data.LinkData link_data: link data to handle :param core.data.LinkData link_data: link data to handle
:return: nothing :return: nothing
""" """
logger.debug("handling broadcast link: %s", link_data) logging.debug("handling broadcast link: %s", link_data)
tlv_data = structutils.pack_values(coreapi.CoreLinkTlv, [ tlv_data = structutils.pack_values(coreapi.CoreLinkTlv, [
(LinkTlvs.N1_NUMBER, link_data.node1_id), (LinkTlvs.N1_NUMBER, link_data.node1_id),
@ -361,7 +361,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
try: try:
self.sendall(message) self.sendall(message)
except IOError: except IOError:
logger.exception("error sending Event Message") logging.exception("error sending Event Message")
def register(self): def register(self):
""" """
@ -369,7 +369,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
:return: register message data :return: register message data
""" """
logger.info("GUI has connected to session %d at %s", self.session.session_id, time.ctime()) logging.info("GUI has connected to session %d at %s", self.session.session_id, time.ctime())
tlv_data = "" tlv_data = ""
tlv_data += coreapi.CoreRegisterTlv.pack(RegisterTlvs.EXECUTE_SERVER.value, "core-daemon") tlv_data += coreapi.CoreRegisterTlv.pack(RegisterTlvs.EXECUTE_SERVER.value, "core-daemon")
@ -418,7 +418,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
message_type, message_flags, message_len = coreapi.CoreMessage.unpack_header(header) message_type, message_flags, message_len = coreapi.CoreMessage.unpack_header(header)
if message_len == 0: if message_len == 0:
logger.warn("received message with no data") logging.warn("received message with no data")
data = "" data = ""
while len(data) < message_len: while len(data) < message_len:
@ -426,7 +426,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
if len(data) > message_len: if len(data) > message_len:
error_message = "received message length does not match received data (%s != %s)" % ( error_message = "received message length does not match received data (%s != %s)" % (
len(data), message_len) len(data), message_len)
logger.error(error_message) logging.error(error_message)
raise IOError(error_message) raise IOError(error_message)
try: try:
@ -435,7 +435,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
except KeyError: except KeyError:
message = coreapi.CoreMessage(message_flags, header, data) message = coreapi.CoreMessage(message_flags, header, data)
message.message_type = message_type message.message_type = message_type
logger.exception("unimplemented core message type: %s", message.type_str()) logging.exception("unimplemented core message type: %s", message.type_str())
return message return message
@ -446,7 +446,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
:param message: message to queue :param message: message to queue
:return: nothing :return: nothing
""" """
logger.debug("queueing msg (queuedtimes = %s): type %s", message.queuedtimes, MessageTypes( logging.debug("queueing msg (queuedtimes = %s): type %s", message.queuedtimes, MessageTypes(
message.message_type)) message.message_type))
self.message_queue.put(message) self.message_queue.put(message)
@ -474,13 +474,13 @@ class CoreHandler(SocketServer.BaseRequestHandler):
:return: nothing :return: nothing
""" """
if self.session and self.session.broker.handle_message(message): if self.session and self.session.broker.handle_message(message):
logger.debug("message not being handled locally") logging.debug("message not being handled locally")
return return
logger.debug("%s handling message:\n%s", threading.currentThread().getName(), message) logging.debug("%s handling message:\n%s", threading.currentThread().getName(), message)
if message.message_type not in self.message_handlers: if message.message_type not in self.message_handlers:
logger.error("no handler for message type: %s", message.type_str()) logging.error("no handler for message type: %s", message.type_str())
return return
message_handler = self.message_handlers[message.message_type] message_handler = self.message_handlers[message.message_type]
@ -490,7 +490,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
replies = message_handler(message) replies = message_handler(message)
self.dispatch_replies(replies, message) self.dispatch_replies(replies, message)
except: except:
logger.exception("%s: exception while handling message: %s", threading.currentThread().getName(), message) logging.exception("%s: exception while handling message: %s", threading.currentThread().getName(), message)
def dispatch_replies(self, replies, message): def dispatch_replies(self, replies, message):
""" """
@ -500,7 +500,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
:param message: message for replies :param message: message for replies
:return: nothing :return: nothing
""" """
logger.debug("dispatching replies") logging.debug("dispatching replies")
for reply in replies: for reply in replies:
message_type, message_flags, message_length = coreapi.CoreMessage.unpack_header(reply) message_type, message_flags, message_length = coreapi.CoreMessage.unpack_header(reply)
try: try:
@ -514,12 +514,12 @@ class CoreHandler(SocketServer.BaseRequestHandler):
reply_message = "CoreMessage (type %d flags %d length %d)" % ( reply_message = "CoreMessage (type %d flags %d length %d)" % (
message_type, message_flags, message_length) message_type, message_flags, message_length)
logger.debug("dispatch reply:\n%s", reply_message) logging.debug("dispatch reply:\n%s", reply_message)
try: try:
self.sendall(reply) self.sendall(reply)
except IOError: except IOError:
logger.exception("error dispatching reply") logging.exception("error dispatching reply")
def handle(self): def handle(self):
""" """
@ -535,12 +535,12 @@ class CoreHandler(SocketServer.BaseRequestHandler):
# TODO: add shutdown handler for session # TODO: add shutdown handler for session
self.session = self.coreemu.create_session(port, master=False) self.session = self.coreemu.create_session(port, master=False)
# self.session.shutdown_handlers.append(self.session_shutdown) # self.session.shutdown_handlers.append(self.session_shutdown)
logger.debug("created new session for client: %s", self.session.session_id) logging.debug("created new session for client: %s", self.session.session_id)
# TODO: hack to associate this handler with this sessions broker for broadcasting # TODO: hack to associate this handler with this sessions broker for broadcasting
# TODO: broker needs to be pulled out of session to the server/handler level # TODO: broker needs to be pulled out of session to the server/handler level
if self.master: if self.master:
logger.debug("session set to master") logging.debug("session set to master")
self.session.master = True self.session.master = True
self.session.broker.session_clients.append(self) self.session.broker.session_clients.append(self)
@ -554,10 +554,10 @@ class CoreHandler(SocketServer.BaseRequestHandler):
try: try:
message = self.receive_message() message = self.receive_message()
except EOFError: except EOFError:
logger.info("client disconnected") logging.info("client disconnected")
break break
except IOError: except IOError:
logger.exception("error receiving message") logging.exception("error receiving message")
break break
message.queuedtimes = 0 message.queuedtimes = 0
@ -575,7 +575,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
if client == self: if client == self:
continue continue
logger.debug("BROADCAST TO OTHER CLIENT: %s", client) logging.debug("BROADCAST TO OTHER CLIENT: %s", client)
client.sendall(message.raw_message) client.sendall(message.raw_message)
def send_exception(self, level, source, text, node=None): def send_exception(self, level, source, text, node=None):
@ -599,7 +599,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
self.handle_broadcast_exception(exception_data) self.handle_broadcast_exception(exception_data)
def add_session_handlers(self): def add_session_handlers(self):
logger.debug("adding session broadcast handlers") logging.debug("adding session broadcast handlers")
self.session.event_handlers.append(self.handle_broadcast_event) self.session.event_handlers.append(self.handle_broadcast_event)
self.session.exception_handlers.append(self.handle_broadcast_exception) self.session.exception_handlers.append(self.handle_broadcast_exception)
self.session.node_handlers.append(self.handle_broadcast_node) self.session.node_handlers.append(self.handle_broadcast_node)
@ -608,7 +608,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
self.session.config_handlers.append(self.handle_broadcast_config) self.session.config_handlers.append(self.handle_broadcast_config)
def remove_session_handlers(self): def remove_session_handlers(self):
logger.debug("removing session broadcast handlers") logging.debug("removing session broadcast handlers")
self.session.event_handlers.remove(self.handle_broadcast_event) self.session.event_handlers.remove(self.handle_broadcast_event)
self.session.exception_handlers.remove(self.handle_broadcast_exception) self.session.exception_handlers.remove(self.handle_broadcast_exception)
self.session.node_handlers.remove(self.handle_broadcast_node) self.session.node_handlers.remove(self.handle_broadcast_node)
@ -625,7 +625,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
""" """
replies = [] replies = []
if message.flags & MessageFlags.ADD.value and message.flags & MessageFlags.DELETE.value: if message.flags & MessageFlags.ADD.value and message.flags & MessageFlags.DELETE.value:
logger.warn("ignoring invalid message: add and delete flag both set") logging.warn("ignoring invalid message: add and delete flag both set")
return () return ()
node_type = None node_type = None
@ -792,7 +792,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
reply = coreapi.CoreExecMessage.pack(MessageFlags.TTY.value, tlv_data) reply = coreapi.CoreExecMessage.pack(MessageFlags.TTY.value, tlv_data)
return reply, return reply,
else: else:
logger.info("execute message with cmd=%s", command) logging.info("execute message with cmd=%s", command)
# execute command and send a response # execute command and send a response
if message.flags & MessageFlags.STRING.value or message.flags & MessageFlags.TEXT.value: if message.flags & MessageFlags.STRING.value or message.flags & MessageFlags.TEXT.value:
# shlex.split() handles quotes within the string # shlex.split() handles quotes within the string
@ -800,7 +800,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
status, res = utils.cmd_output(command) status, res = utils.cmd_output(command)
else: else:
status, res = node.cmd_output(command) status, res = node.cmd_output(command)
logger.info("done exec cmd=%s with status=%d res=(%d bytes)", command, status, len(res)) logging.info("done exec cmd=%s with status=%d res=(%d bytes)", command, status, len(res))
if message.flags & MessageFlags.TEXT.value: if message.flags & MessageFlags.TEXT.value:
tlv_data += coreapi.CoreExecuteTlv.pack(ExecuteTlvs.RESULT.value, res) tlv_data += coreapi.CoreExecuteTlv.pack(ExecuteTlvs.RESULT.value, res)
if message.flags & MessageFlags.STRING.value: if message.flags & MessageFlags.STRING.value:
@ -814,7 +814,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
else: else:
node.cmd(command, wait=False) node.cmd(command, wait=False)
except KeyError: except KeyError:
logger.exception("error getting object: %s", node_num) logging.exception("error getting object: %s", node_num)
# XXX wait and queue this message to try again later # XXX wait and queue this message to try again later
# XXX maybe this should be done differently # XXX maybe this should be done differently
if not message.flags & MessageFlags.LOCAL.value: if not message.flags & MessageFlags.LOCAL.value:
@ -836,7 +836,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
execute_server = message.get_tlv(RegisterTlvs.EXECUTE_SERVER.value) execute_server = message.get_tlv(RegisterTlvs.EXECUTE_SERVER.value)
if execute_server: if execute_server:
try: try:
logger.info("executing: %s", execute_server) logging.info("executing: %s", execute_server)
if message.flags & MessageFlags.STRING.value: if message.flags & MessageFlags.STRING.value:
old_session_ids = set(self.coreemu.sessions.keys()) old_session_ids = set(self.coreemu.sessions.keys())
sys.argv = shlex.split(execute_server) sys.argv = shlex.split(execute_server)
@ -864,22 +864,22 @@ class CoreHandler(SocketServer.BaseRequestHandler):
new_sid = new_session_ids.difference(old_session_ids) new_sid = new_session_ids.difference(old_session_ids)
try: try:
sid = new_sid.pop() sid = new_sid.pop()
logger.info("executed: %s as session %d", execute_server, sid) logging.info("executed: %s as session %d", execute_server, sid)
except KeyError: except KeyError:
logger.info("executed %s with unknown session ID", execute_server) logging.info("executed %s with unknown session ID", execute_server)
return replies return replies
logger.debug("checking session %d for RUNTIME state", sid) logging.debug("checking session %d for RUNTIME state", sid)
session = self.coreemu.sessions.get(sid) session = self.coreemu.sessions.get(sid)
retries = 10 retries = 10
# wait for session to enter RUNTIME state, to prevent GUI from # wait for session to enter RUNTIME state, to prevent GUI from
# connecting while nodes are still being instantiated # connecting while nodes are still being instantiated
while session.state != EventTypes.RUNTIME_STATE.value: while session.state != EventTypes.RUNTIME_STATE.value:
logger.debug("waiting for session %d to enter RUNTIME state", sid) logging.debug("waiting for session %d to enter RUNTIME state", sid)
time.sleep(1) time.sleep(1)
retries -= 1 retries -= 1
if retries <= 0: if retries <= 0:
logger.debug("session %d did not enter RUNTIME state", sid) logging.debug("session %d did not enter RUNTIME state", sid)
return replies return replies
tlv_data = coreapi.CoreRegisterTlv.pack(RegisterTlvs.EXECUTE_SERVER.value, execute_server) tlv_data = coreapi.CoreRegisterTlv.pack(RegisterTlvs.EXECUTE_SERVER.value, execute_server)
@ -887,7 +887,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
message = coreapi.CoreRegMessage.pack(0, tlv_data) message = coreapi.CoreRegMessage.pack(0, tlv_data)
replies.append(message) replies.append(message)
except Exception as e: except Exception as e:
logger.exception("error executing: %s", execute_server) logging.exception("error executing: %s", execute_server)
tlv_data = coreapi.CoreExceptionTlv.pack(ExceptionTlvs.LEVEL.value, 2) tlv_data = coreapi.CoreExceptionTlv.pack(ExceptionTlvs.LEVEL.value, 2)
tlv_data += coreapi.CoreExceptionTlv.pack(ExceptionTlvs.TEXT.value, str(e)) tlv_data += coreapi.CoreExceptionTlv.pack(ExceptionTlvs.TEXT.value, str(e))
message = coreapi.CoreExceptionMessage.pack(0, tlv_data) message = coreapi.CoreExceptionMessage.pack(0, tlv_data)
@ -897,7 +897,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
gui = message.get_tlv(RegisterTlvs.GUI.value) gui = message.get_tlv(RegisterTlvs.GUI.value)
if gui is None: if gui is None:
logger.debug("ignoring Register message") logging.debug("ignoring Register message")
else: else:
# register capabilities with the GUI # register capabilities with the GUI
self.master = True self.master = True
@ -905,7 +905,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
# find the session containing this client and set the session to master # find the session containing this client and set the session to master
for session in self.coreemu.sessions.itervalues(): for session in self.coreemu.sessions.itervalues():
if self in session.broker.session_clients: if self in session.broker.session_clients:
logger.debug("setting session to master: %s", session.session_id) logging.debug("setting session to master: %s", session.session_id)
session.master = True session.master = True
break break
@ -937,7 +937,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
network_id=message.get_tlv(ConfigTlvs.NETWORK_ID.value), network_id=message.get_tlv(ConfigTlvs.NETWORK_ID.value),
opaque=message.get_tlv(ConfigTlvs.OPAQUE.value) opaque=message.get_tlv(ConfigTlvs.OPAQUE.value)
) )
logger.debug("configuration message for %s node %s", config_data.object, config_data.node) logging.debug("configuration message for %s node %s", config_data.object, config_data.node)
message_type = ConfigFlags(config_data.type) message_type = ConfigFlags(config_data.type)
replies = [] replies = []
@ -1003,7 +1003,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
self.session.location.reset() self.session.location.reset()
else: else:
if not config_data.data_values: if not config_data.data_values:
logger.warn("location data missing") logging.warn("location data missing")
else: else:
values = [float(x) for x in config_data.data_values.split("|")] values = [float(x) for x in config_data.data_values.split("|")]
@ -1016,9 +1016,9 @@ class CoreHandler(SocketServer.BaseRequestHandler):
# geographic reference point # geographic reference point
self.session.location.setrefgeo(lat, lon, alt) self.session.location.setrefgeo(lat, lon, alt)
self.session.location.refscale = values[5] self.session.location.refscale = values[5]
logger.info("location configured: %s = %s scale=%s", self.session.location.refxyz, logging.info("location configured: %s = %s scale=%s", self.session.location.refxyz,
self.session.location.refgeo, self.session.location.refscale) self.session.location.refgeo, self.session.location.refscale)
logger.info("location configured: UTM%s", self.session.location.refutm) logging.info("location configured: UTM%s", self.session.location.refutm)
def handle_config_metadata(self, message_type, config_data): def handle_config_metadata(self, message_type, config_data):
replies = [] replies = []
@ -1045,7 +1045,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
if message_type not in [ConfigFlags.REQUEST, ConfigFlags.RESET]: if message_type not in [ConfigFlags.REQUEST, ConfigFlags.RESET]:
session_id = config_data.session session_id = config_data.session
if not config_data.data_values: if not config_data.data_values:
logger.info("emulation server data missing") logging.info("emulation server data missing")
else: else:
values = config_data.data_values.split("|") values = config_data.data_values.split("|")
@ -1086,7 +1086,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
session_id = config_data.session session_id = config_data.session
opaque = config_data.opaque opaque = config_data.opaque
logger.debug("configuration request: node(%s) session(%s) opaque(%s)", node_id, session_id, opaque) logging.debug("configuration request: node(%s) session(%s) opaque(%s)", node_id, session_id, opaque)
# send back a list of available services # send back a list of available services
if opaque is None: if opaque is None:
@ -1108,10 +1108,10 @@ class CoreHandler(SocketServer.BaseRequestHandler):
values = [] values = []
group_strings = [] group_strings = []
start_index = 1 start_index = 1
logger.info("sorted groups: %s", groups) logging.info("sorted groups: %s", groups)
for group in groups: for group in groups:
services = sorted(group_map[group], key=lambda x: x.name.lower()) services = sorted(group_map[group], key=lambda x: x.name.lower())
logger.info("sorted services for group(%s): %s", group, services) logging.info("sorted services for group(%s): %s", group, services)
end_index = start_index + len(services) - 1 end_index = start_index + len(services) - 1
group_strings.append("%s:%s-%s" % (group, start_index, end_index)) group_strings.append("%s:%s-%s" % (group, start_index, end_index))
start_index += len(services) start_index += len(services)
@ -1135,7 +1135,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
node = self.session.get_object(node_id) node = self.session.get_object(node_id)
if node is None: if node is None:
logger.warn("request to configure service for unknown node %s", node_id) logging.warn("request to configure service for unknown node %s", node_id)
return replies return replies
services = ServiceShim.servicesfromopaque(opaque) services = ServiceShim.servicesfromopaque(opaque)
@ -1186,17 +1186,17 @@ class CoreHandler(SocketServer.BaseRequestHandler):
error_message = "services config message that I don't know how to handle" error_message = "services config message that I don't know how to handle"
if values is None: if values is None:
logger.error(error_message) logging.error(error_message)
else: else:
if opaque is None: if opaque is None:
values = values.split("|") values = values.split("|")
# store default services for a node type in self.defaultservices[] # store default services for a node type in self.defaultservices[]
if data_types is None or data_types[0] != ConfigDataTypes.STRING.value: if data_types is None or data_types[0] != ConfigDataTypes.STRING.value:
logger.info(error_message) logging.info(error_message)
return None return None
key = values.pop(0) key = values.pop(0)
self.session.services.default_services[key] = values self.session.services.default_services[key] = values
logger.debug("default services for type %s set to %s", key, values) logging.debug("default services for type %s set to %s", key, values)
elif node_id: elif node_id:
services = ServiceShim.servicesfromopaque(opaque) services = ServiceShim.servicesfromopaque(opaque)
if services: if services:
@ -1230,14 +1230,14 @@ class CoreHandler(SocketServer.BaseRequestHandler):
if interface_id is not None: if interface_id is not None:
node_id = node_id * 1000 + interface_id node_id = node_id * 1000 + interface_id
logger.debug("received configure message for %s nodenum: %s", object_name, node_id) logging.debug("received configure message for %s nodenum: %s", object_name, node_id)
if message_type == ConfigFlags.REQUEST: if message_type == ConfigFlags.REQUEST:
logger.info("replying to configure request for model: %s", object_name) logging.info("replying to configure request for model: %s", object_name)
typeflags = ConfigFlags.NONE.value typeflags = ConfigFlags.NONE.value
model_class = self.session.mobility.models.get(object_name) model_class = self.session.mobility.models.get(object_name)
if not model_class: if not model_class:
logger.warn("model class does not exist: %s", object_name) logging.warn("model class does not exist: %s", object_name)
return [] return []
config = self.session.mobility.get_model_config(node_id, object_name) config = self.session.mobility.get_model_config(node_id, object_name)
@ -1246,7 +1246,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
elif message_type != ConfigFlags.RESET: elif message_type != ConfigFlags.RESET:
# store the configuration values for later use, when the node # store the configuration values for later use, when the node
if not object_name: if not object_name:
logger.warn("no configuration object for node: %s", node_id) logging.warn("no configuration object for node: %s", node_id)
return [] return []
parsed_config = {} parsed_config = {}
@ -1267,16 +1267,16 @@ class CoreHandler(SocketServer.BaseRequestHandler):
if interface_id is not None: if interface_id is not None:
node_id = node_id * 1000 + interface_id node_id = node_id * 1000 + interface_id
logger.debug("received configure message for %s nodenum: %s", object_name, node_id) logging.debug("received configure message for %s nodenum: %s", object_name, node_id)
if message_type == ConfigFlags.REQUEST: if message_type == ConfigFlags.REQUEST:
logger.info("replying to configure request for %s model", object_name) logging.info("replying to configure request for %s model", object_name)
typeflags = ConfigFlags.NONE.value typeflags = ConfigFlags.NONE.value
config = self.session.emane.get_configs() config = self.session.emane.get_configs()
config_response = ConfigShim.config_data(0, node_id, typeflags, self.session.emane.emane_config, config) config_response = ConfigShim.config_data(0, node_id, typeflags, self.session.emane.emane_config, config)
replies.append(config_response) replies.append(config_response)
elif message_type != ConfigFlags.RESET: elif message_type != ConfigFlags.RESET:
if not object_name: if not object_name:
logger.info("no configuration object for node %s", node_id) logging.info("no configuration object for node %s", node_id)
return [] return []
if values_str: if values_str:
@ -1300,14 +1300,14 @@ class CoreHandler(SocketServer.BaseRequestHandler):
if interface_id is not None: if interface_id is not None:
node_id = node_id * 1000 + interface_id node_id = node_id * 1000 + interface_id
logger.debug("received configure message for %s nodenum: %s", object_name, node_id) logging.debug("received configure message for %s nodenum: %s", object_name, node_id)
if message_type == ConfigFlags.REQUEST: if message_type == ConfigFlags.REQUEST:
logger.info("replying to configure request for model: %s", object_name) logging.info("replying to configure request for model: %s", object_name)
typeflags = ConfigFlags.NONE.value typeflags = ConfigFlags.NONE.value
model_class = self.session.emane.models.get(object_name) model_class = self.session.emane.models.get(object_name)
if not model_class: if not model_class:
logger.warn("model class does not exist: %s", object_name) logging.warn("model class does not exist: %s", object_name)
return [] return []
config = self.session.emane.get_model_config(node_id, object_name) config = self.session.emane.get_model_config(node_id, object_name)
@ -1316,7 +1316,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
elif message_type != ConfigFlags.RESET: elif message_type != ConfigFlags.RESET:
# store the configuration values for later use, when the node # store the configuration values for later use, when the node
if not object_name: if not object_name:
logger.warn("no configuration object for node: %s", node_id) logging.warn("no configuration object for node: %s", node_id)
return [] return []
parsed_config = {} parsed_config = {}
@ -1343,11 +1343,11 @@ class CoreHandler(SocketServer.BaseRequestHandler):
compressed_data = message.get_tlv(FileTlvs.COMPRESSED_DATA.value) compressed_data = message.get_tlv(FileTlvs.COMPRESSED_DATA.value)
if compressed_data: if compressed_data:
logger.warn("Compressed file data not implemented for File message.") logging.warn("Compressed file data not implemented for File message.")
return () return ()
if source_name and data: if source_name and data:
logger.warn("ignoring invalid File message: source and data TLVs are both present") logging.warn("ignoring invalid File message: source and data TLVs are both present")
return () return ()
# some File Messages store custom files in services, # some File Messages store custom files in services,
@ -1360,7 +1360,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
elif file_type.startswith("hook:"): elif file_type.startswith("hook:"):
_, state = file_type.split(':')[:2] _, state = file_type.split(':')[:2]
if not state.isdigit(): if not state.isdigit():
logger.error("error setting hook having state '%s'", state) logging.error("error setting hook having state '%s'", state)
return () return ()
state = int(state) state = int(state)
self.session.add_hook(state, file_name, source_name, data) self.session.add_hook(state, file_name, source_name, data)
@ -1388,7 +1388,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
:param message: interface message to handle :param message: interface message to handle
:return: reply messages :return: reply messages
""" """
logger.info("ignoring Interface message") logging.info("ignoring Interface message")
return () return ()
def handle_event_message(self, message): def handle_event_message(self, message):
@ -1412,7 +1412,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
event_type = EventTypes(event_data.event_type) event_type = EventTypes(event_data.event_type)
node_id = event_data.node node_id = event_data.node
logger.debug("handling event %s at %s", event_type.name, time.ctime()) logging.debug("handling event %s at %s", event_type.name, time.ctime())
if event_type.value <= EventTypes.SHUTDOWN_STATE.value: if event_type.value <= EventTypes.SHUTDOWN_STATE.value:
if node_id is not None: if node_id is not None:
try: try:
@ -1425,7 +1425,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
self.session.start_mobility(node_ids=(node.objid,)) self.session.start_mobility(node_ids=(node.objid,))
return () return ()
logger.warn("dropping unhandled Event message with node number") logging.warn("dropping unhandled Event message with node number")
return () return ()
self.session.set_state(event_type) self.session.set_state(event_type)
@ -1444,7 +1444,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
self.send_node_emulation_id(obj.objid) self.send_node_emulation_id(obj.objid)
elif event_type == EventTypes.RUNTIME_STATE: elif event_type == EventTypes.RUNTIME_STATE:
if self.session.master: if self.session.master:
logger.warn("Unexpected event message: RUNTIME state received at session master") logging.warn("Unexpected event message: RUNTIME state received at session master")
else: else:
# master event queue is started in session.checkruntime() # master event queue is started in session.checkruntime()
self.session.start_events() self.session.start_events()
@ -1452,7 +1452,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
self.session.data_collect() self.session.data_collect()
elif event_type == EventTypes.SHUTDOWN_STATE: elif event_type == EventTypes.SHUTDOWN_STATE:
if self.session.master: if self.session.master:
logger.warn("Unexpected event message: SHUTDOWN state received at session master") logging.warn("Unexpected event message: SHUTDOWN state received at session master")
elif event_type in {EventTypes.START, EventTypes.STOP, EventTypes.RESTART, EventTypes.PAUSE, elif event_type in {EventTypes.START, EventTypes.STOP, EventTypes.RESTART, EventTypes.PAUSE,
EventTypes.RECONFIGURE}: EventTypes.RECONFIGURE}:
handled = False handled = False
@ -1467,7 +1467,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
self.session.mobility_event(event_data) self.session.mobility_event(event_data)
handled = True handled = True
if not handled: if not handled:
logger.warn("Unhandled event message: event type %s ", event_type.name) logging.warn("Unhandled event message: event type %s ", event_type.name)
elif event_type == EventTypes.FILE_OPEN: elif event_type == EventTypes.FILE_OPEN:
filename = event_data.name filename = event_data.name
self.session.open_xml(filename, start=False) self.session.open_xml(filename, start=False)
@ -1482,14 +1482,14 @@ class CoreHandler(SocketServer.BaseRequestHandler):
name = event_data.name name = event_data.name
data = event_data.data data = event_data.data
if etime is None: if etime is None:
logger.warn("Event message scheduled event missing start time") logging.warn("Event message scheduled event missing start time")
return () return ()
if message.flags & MessageFlags.ADD.value: if message.flags & MessageFlags.ADD.value:
self.session.add_event(float(etime), node=node, name=name, data=data) self.session.add_event(float(etime), node=node, name=name, data=data)
else: else:
raise NotImplementedError raise NotImplementedError
else: else:
logger.warn("unhandled event message: event type %s", event_type) logging.warn("unhandled event message: event type %s", event_type)
return () return ()
@ -1508,7 +1508,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
try: try:
node = self.session.get_object(node_id) node = self.session.get_object(node_id)
except KeyError: except KeyError:
logger.warn("ignoring event for service '%s', unknown node '%s'", name, node_id) logging.warn("ignoring event for service '%s', unknown node '%s'", name, node_id)
return return
fail = "" fail = ""
@ -1546,7 +1546,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
if num > 1: if num > 1:
unknown_data += ", " unknown_data += ", "
num -= 1 num -= 1
logger.warn("Event requested for unknown service(s): %s", unknown_data) logging.warn("Event requested for unknown service(s): %s", unknown_data)
unknown_data = "Unknown:" + unknown_data unknown_data = "Unknown:" + unknown_data
event_data = EventData( event_data = EventData(
@ -1574,7 +1574,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
files = coreapi.str_to_list(file_str) files = coreapi.str_to_list(file_str)
thumb = message.get_tlv(SessionTlvs.THUMB.value) thumb = message.get_tlv(SessionTlvs.THUMB.value)
user = message.get_tlv(SessionTlvs.USER.value) user = message.get_tlv(SessionTlvs.USER.value)
logger.debug("SESSION message flags=0x%x sessions=%s" % (message.flags, session_id_str)) logging.debug("SESSION message flags=0x%x sessions=%s" % (message.flags, session_id_str))
if message.flags == 0: if message.flags == 0:
for index, session_id in enumerate(session_ids): for index, session_id in enumerate(session_ids):
@ -1585,10 +1585,10 @@ class CoreHandler(SocketServer.BaseRequestHandler):
session = self.coreemu.sessions.get(session_id) session = self.coreemu.sessions.get(session_id)
if session is None: if session is None:
logger.warn("session %s not found", session_id) logging.warn("session %s not found", session_id)
continue continue
logger.info("request to modify to session: %s", session.session_id) logging.info("request to modify to session: %s", session.session_id)
if names is not None: if names is not None:
session.name = names[index] session.name = names[index]
@ -1610,12 +1610,12 @@ class CoreHandler(SocketServer.BaseRequestHandler):
session = self.coreemu.sessions.get(session_id) session = self.coreemu.sessions.get(session_id)
if session is None: if session is None:
logger.info("session %s not found (flags=0x%x)", session_id, message.flags) logging.info("session %s not found (flags=0x%x)", session_id, message.flags)
continue continue
if message.flags & MessageFlags.ADD.value: if message.flags & MessageFlags.ADD.value:
# connect to the first session that exists # connect to the first session that exists
logger.info("request to connect to session %s", session_id) logging.info("request to connect to session %s", session_id)
# remove client from session broker and shutdown if needed # remove client from session broker and shutdown if needed
self.remove_session_handlers() self.remove_session_handlers()
@ -1632,7 +1632,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
self.session.broker.session_clients.append(self) self.session.broker.session_clients.append(self)
# add broadcast handlers # add broadcast handlers
logger.info("adding session broadcast handlers") logging.info("adding session broadcast handlers")
self.add_session_handlers() self.add_session_handlers()
if user: if user:
@ -1642,10 +1642,10 @@ class CoreHandler(SocketServer.BaseRequestHandler):
self.send_objects() self.send_objects()
elif message.flags & MessageFlags.DELETE.value: elif message.flags & MessageFlags.DELETE.value:
# shut down the specified session(s) # shut down the specified session(s)
logger.info("request to terminate session %s", session_id) logging.info("request to terminate session %s", session_id)
self.coreemu.delete_session(session_id) self.coreemu.delete_session(session_id)
else: else:
logger.warn("unhandled session flags for session %s", session_id) logging.warn("unhandled session flags for session %s", session_id)
return () return ()
@ -1665,7 +1665,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
try: try:
self.sendall(reply) self.sendall(reply)
except IOError: except IOError:
logger.exception("error sending node emulation id message: %s", node_id) logging.exception("error sending node emulation id message: %s", node_id)
del self.node_status_request[node_id] del self.node_status_request[node_id]
@ -1698,7 +1698,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
for node_id in self.session.mobility.nodes(): for node_id in self.session.mobility.nodes():
for model_name, config in self.session.mobility.get_all_configs(node_id).iteritems(): for model_name, config in self.session.mobility.get_all_configs(node_id).iteritems():
model_class = self.session.mobility.models[model_name] model_class = self.session.mobility.models[model_name]
logger.debug("mobility config: node(%s) class(%s) values(%s)", node_id, model_class, config) logging.debug("mobility config: node(%s) class(%s) values(%s)", node_id, model_class, config)
config_data = ConfigShim.config_data(0, node_id, ConfigFlags.UPDATE.value, model_class, config) config_data = ConfigShim.config_data(0, node_id, ConfigFlags.UPDATE.value, model_class, config)
self.session.broadcast_config(config_data) self.session.broadcast_config(config_data)
@ -1706,7 +1706,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
for node_id in self.session.emane.nodes(): for node_id in self.session.emane.nodes():
for model_name, config in self.session.emane.get_all_configs(node_id).iteritems(): for model_name, config in self.session.emane.get_all_configs(node_id).iteritems():
model_class = self.session.emane.models[model_name] model_class = self.session.emane.models[model_name]
logger.debug("emane config: node(%s) class(%s) values(%s)", node_id, model_class, config) logging.debug("emane config: node(%s) class(%s) values(%s)", node_id, model_class, config)
config_data = ConfigShim.config_data(0, node_id, ConfigFlags.UPDATE.value, model_class, config) config_data = ConfigShim.config_data(0, node_id, ConfigFlags.UPDATE.value, model_class, config)
self.session.broadcast_config(config_data) self.session.broadcast_config(config_data)
@ -1769,4 +1769,4 @@ class CoreHandler(SocketServer.BaseRequestHandler):
) )
self.session.broadcast_config(config_data) self.session.broadcast_config(config_data)
logger.info("informed GUI about %d nodes and %d links", len(nodes_data), len(links_data)) logging.info("informed GUI about %d nodes and %d links", len(nodes_data), len(links_data))

View file

@ -2,11 +2,11 @@
commeffect.py: EMANE CommEffect model for CORE commeffect.py: EMANE CommEffect model for CORE
""" """
import logging
import os import os
from lxml import etree from lxml import etree
from core import logger
from core.conf import ConfigGroup from core.conf import ConfigGroup
from core.emane import emanemanifest from core.emane import emanemanifest
from core.emane import emanemodel from core.emane import emanemodel
@ -18,7 +18,7 @@ except ImportError:
try: try:
from emanesh.events.commeffectevent import CommEffectEvent from emanesh.events.commeffectevent import CommEffectEvent
except ImportError: except ImportError:
logger.debug("compatible emane python bindings not installed") logging.debug("compatible emane python bindings not installed")
def convert_none(x): def convert_none(x):
@ -110,11 +110,11 @@ class EmaneCommEffectModel(emanemodel.EmaneModel):
""" """
service = self.session.emane.service service = self.session.emane.service
if service is None: if service is None:
logger.warn("%s: EMANE event service unavailable", self.name) logging.warn("%s: EMANE event service unavailable", self.name)
return return
if netif is None or netif2 is None: if netif is None or netif2 is None:
logger.warn("%s: missing NEM information", self.name) logging.warn("%s: missing NEM information", self.name)
return return
# TODO: batch these into multiple events per transmission # TODO: batch these into multiple events per transmission
@ -124,7 +124,7 @@ class EmaneCommEffectModel(emanemodel.EmaneModel):
nemid = emane_node.getnemid(netif) nemid = emane_node.getnemid(netif)
nemid2 = emane_node.getnemid(netif2) nemid2 = emane_node.getnemid(netif2)
mbw = bw mbw = bw
logger.info("sending comm effect event") logging.info("sending comm effect event")
event.append( event.append(
nemid, nemid,
latency=convert_none(delay), latency=convert_none(delay),

View file

@ -2,12 +2,12 @@
emane.py: definition of an Emane class for implementing configuration control of an EMANE emulation. emane.py: definition of an Emane class for implementing configuration control of an EMANE emulation.
""" """
import logging
import os import os
import threading import threading
from core import CoreCommandError from core import CoreCommandError
from core import constants from core import constants
from core import logger
from core.api import coreapi from core.api import coreapi
from core.api import dataconversion from core.api import dataconversion
from core.conf import ConfigGroup from core.conf import ConfigGroup
@ -42,7 +42,7 @@ except ImportError:
from emanesh.events import LocationEvent from emanesh.events import LocationEvent
from emanesh.events.eventserviceexception import EventServiceException from emanesh.events.eventserviceexception import EventServiceException
except ImportError: except ImportError:
logger.debug("compatible emane python bindings not installed") logging.debug("compatible emane python bindings not installed")
EMANE_MODELS = [ EMANE_MODELS = [
EmaneRfPipeModel, EmaneRfPipeModel,
@ -147,7 +147,7 @@ class EmaneManager(ModelManager):
try: try:
# check for emane # check for emane
emane_version = utils.check_cmd(["emane", "--version"]) emane_version = utils.check_cmd(["emane", "--version"])
logger.info("using EMANE: %s", emane_version) logging.info("using EMANE: %s", emane_version)
# load default emane models # load default emane models
self.load_models(EMANE_MODELS) self.load_models(EMANE_MODELS)
@ -158,7 +158,7 @@ class EmaneManager(ModelManager):
emane_models = utils.load_classes(custom_models_path, EmaneModel) emane_models = utils.load_classes(custom_models_path, EmaneModel)
self.load_models(emane_models) self.load_models(emane_models)
except CoreCommandError: except CoreCommandError:
logger.info("emane is not installed") logging.info("emane is not installed")
def deleteeventservice(self): def deleteeventservice(self):
if self.service: if self.service:
@ -186,7 +186,7 @@ class EmaneManager(ModelManager):
self.event_device = self.get_config("eventservicedevice") self.event_device = self.get_config("eventservicedevice")
eventnetidx = self.session.get_control_net_index(self.event_device) eventnetidx = self.session.get_control_net_index(self.event_device)
if eventnetidx < 0: if eventnetidx < 0:
logger.error("invalid emane event service device provided: %s", self.event_device) logging.error("invalid emane event service device provided: %s", self.event_device)
return False return False
# make sure the event control network is in place # make sure the event control network is in place
@ -198,11 +198,11 @@ class EmaneManager(ModelManager):
# disabled otachannel for event service # disabled otachannel for event service
# only needed for e.g. antennaprofile events xmit by models # only needed for e.g. antennaprofile events xmit by models
logger.info("using %s for event service traffic", self.event_device) logging.info("using %s for event service traffic", self.event_device)
try: try:
self.service = EventService(eventchannel=eventchannel, otachannel=None) self.service = EventService(eventchannel=eventchannel, otachannel=None)
except EventServiceException: except EventServiceException:
logger.exception("error instantiating emane EventService") logging.exception("error instantiating emane EventService")
return True return True
@ -211,7 +211,7 @@ class EmaneManager(ModelManager):
Load EMANE models and make them available. Load EMANE models and make them available.
""" """
for emane_model in emane_models: for emane_model in emane_models:
logger.info("loading emane model: %s", emane_model.__name__) logging.info("loading emane model: %s", emane_model.__name__)
self.models[emane_model.name] = emane_model self.models[emane_model.name] = emane_model
def add_node(self, emane_node): def add_node(self, emane_node):
@ -245,17 +245,17 @@ class EmaneManager(ModelManager):
Emane.(SUCCESS, NOT_NEEDED, NOT_READY) in order to delay session Emane.(SUCCESS, NOT_NEEDED, NOT_READY) in order to delay session
instantiation. instantiation.
""" """
logger.debug("emane setup") logging.debug("emane setup")
# TODO: drive this from the session object # TODO: drive this from the session object
with self.session._objects_lock: with self.session._objects_lock:
for node in self.session.objects.itervalues(): for node in self.session.objects.itervalues():
if nodeutils.is_node(node, NodeTypes.EMANE): if nodeutils.is_node(node, NodeTypes.EMANE):
logger.debug("adding emane node: id(%s) name(%s)", node.objid, node.name) logging.debug("adding emane node: id(%s) name(%s)", node.objid, node.name)
self.add_node(node) self.add_node(node)
if not self._emane_nodes: if not self._emane_nodes:
logger.debug("no emane nodes in session") logging.debug("no emane nodes in session")
return EmaneManager.NOT_NEEDED return EmaneManager.NOT_NEEDED
# control network bridge required for EMANE 0.9.2 # control network bridge required for EMANE 0.9.2
@ -264,20 +264,20 @@ class EmaneManager(ModelManager):
if self.session.master: if self.session.master:
otadev = self.get_config("otamanagerdevice") otadev = self.get_config("otamanagerdevice")
netidx = self.session.get_control_net_index(otadev) netidx = self.session.get_control_net_index(otadev)
logger.debug("emane ota manager device: index(%s) otadev(%s)", netidx, otadev) logging.debug("emane ota manager device: index(%s) otadev(%s)", netidx, otadev)
if netidx < 0: if netidx < 0:
logger.error("EMANE cannot start, check core config. invalid OTA device provided: %s", otadev) logging.error("EMANE cannot start, check core config. invalid OTA device provided: %s", otadev)
return EmaneManager.NOT_READY return EmaneManager.NOT_READY
ctrlnet = self.session.add_remove_control_net(net_index=netidx, remove=False, conf_required=False) ctrlnet = self.session.add_remove_control_net(net_index=netidx, remove=False, conf_required=False)
self.distributedctrlnet(ctrlnet) self.distributedctrlnet(ctrlnet)
eventdev = self.get_config("eventservicedevice") eventdev = self.get_config("eventservicedevice")
logger.debug("emane event service device: eventdev(%s)", eventdev) logging.debug("emane event service device: eventdev(%s)", eventdev)
if eventdev != otadev: if eventdev != otadev:
netidx = self.session.get_control_net_index(eventdev) netidx = self.session.get_control_net_index(eventdev)
logger.debug("emane event service device index: %s", netidx) logging.debug("emane event service device index: %s", netidx)
if netidx < 0: if netidx < 0:
logger.error("EMANE cannot start, check core config. invalid event service device: %s", eventdev) logging.error("EMANE cannot start, check core config. invalid event service device: %s", eventdev)
return EmaneManager.NOT_READY return EmaneManager.NOT_READY
ctrlnet = self.session.add_remove_control_net(net_index=netidx, remove=False, conf_required=False) ctrlnet = self.session.add_remove_control_net(net_index=netidx, remove=False, conf_required=False)
@ -328,7 +328,7 @@ class EmaneManager(ModelManager):
for nodename, ifname, nemid in nems: for nodename, ifname, nemid in nems:
f.write("%s %s %s\n" % (nodename, ifname, nemid)) f.write("%s %s %s\n" % (nodename, ifname, nemid))
except IOError: except IOError:
logger.exception("Error writing EMANE NEMs file: %s") logging.exception("Error writing EMANE NEMs file: %s")
return EmaneManager.SUCCESS return EmaneManager.SUCCESS
@ -342,7 +342,7 @@ class EmaneManager(ModelManager):
with self._emane_node_lock: with self._emane_node_lock:
for key in sorted(self._emane_nodes.keys()): for key in sorted(self._emane_nodes.keys()):
emane_node = self._emane_nodes[key] emane_node = self._emane_nodes[key]
logger.debug("post startup for emane node: %s - %s", emane_node.objid, emane_node.name) logging.debug("post startup for emane node: %s - %s", emane_node.objid, emane_node.name)
emane_node.model.post_startup() emane_node.model.post_startup()
for netif in emane_node.netifs(): for netif in emane_node.netifs():
x, y, z = netif.node.position.get() x, y, z = netif.node.position.get()
@ -370,7 +370,7 @@ class EmaneManager(ModelManager):
with self._emane_node_lock: with self._emane_node_lock:
if not self._emane_nodes: if not self._emane_nodes:
return return
logger.info("stopping EMANE daemons.") logging.info("stopping EMANE daemons.")
self.deinstallnetifs() self.deinstallnetifs()
self.stopdaemons() self.stopdaemons()
self.stopeventmonitor() self.stopeventmonitor()
@ -407,7 +407,7 @@ class EmaneManager(ModelManager):
with self._emane_node_lock: with self._emane_node_lock:
if self._emane_nodes: if self._emane_nodes:
master = self.session.master master = self.session.master
logger.info("emane check distributed as master: %s.", master) logging.info("emane check distributed as master: %s.", master)
# we are not the master Emane object, wait for nem id and ports # we are not the master Emane object, wait for nem id and ports
if not master: if not master:
@ -460,7 +460,7 @@ class EmaneManager(ModelManager):
events and data. events and data.
""" """
# assume self._objslock is already held here # assume self._objslock is already held here
logger.info("emane building xml...") logging.info("emane building xml...")
# on master, control network bridge added earlier in startup() # on master, control network bridge added earlier in startup()
ctrlnet = self.session.add_remove_control_net(net_index=0, remove=False, conf_required=False) ctrlnet = self.session.add_remove_control_net(net_index=0, remove=False, conf_required=False)
self.buildplatformxml(ctrlnet) self.buildplatformxml(ctrlnet)
@ -491,7 +491,7 @@ class EmaneManager(ModelManager):
return return
# this generates a config message having controlnet prefix assignments # this generates a config message having controlnet prefix assignments
logger.info("Setting up default controlnet prefixes for distributed (%d configured)" % len(prefixes)) logging.info("Setting up default controlnet prefixes for distributed (%d configured)" % len(prefixes))
prefixes = ctrlnet.DEFAULT_PREFIX_LIST[0] prefixes = ctrlnet.DEFAULT_PREFIX_LIST[0]
vals = 'controlnet="%s"' % prefixes vals = 'controlnet="%s"' % prefixes
tlvdata = "" tlvdata = ""
@ -510,21 +510,21 @@ class EmaneManager(ModelManager):
""" """
for node_id in self._emane_nodes: for node_id in self._emane_nodes:
emane_node = self._emane_nodes[node_id] emane_node = self._emane_nodes[node_id]
logger.debug("checking emane model for node: %s", node_id) logging.debug("checking emane model for node: %s", node_id)
# skip nodes that already have a model set # skip nodes that already have a model set
if emane_node.model: if emane_node.model:
logger.debug("node(%s) already has model(%s)", emane_node.objid, emane_node.model.name) logging.debug("node(%s) already has model(%s)", emane_node.objid, emane_node.model.name)
continue continue
# set model configured for node, due to legacy messaging configuration before nodes exist # set model configured for node, due to legacy messaging configuration before nodes exist
model_name = self.node_models.get(node_id) model_name = self.node_models.get(node_id)
if not model_name: if not model_name:
logger.error("emane node(%s) has no node model", node_id) logging.error("emane node(%s) has no node model", node_id)
raise ValueError("emane node has no model set") raise ValueError("emane node has no model set")
config = self.get_model_config(node_id=node_id, model_name=model_name) config = self.get_model_config(node_id=node_id, model_name=model_name)
logger.debug("setting emane model(%s) config(%s)", model_name, config) logging.debug("setting emane model(%s) config(%s)", model_name, config)
model_class = self.models[model_name] model_class = self.models[model_name]
emane_node.setmodel(model_class, config) emane_node.setmodel(model_class, config)
@ -603,7 +603,7 @@ class EmaneManager(ModelManager):
try: try:
group, port = self.get_config("eventservicegroup").split(":") group, port = self.get_config("eventservicegroup").split(":")
except ValueError: except ValueError:
logger.exception("invalid eventservicegroup in EMANE config") logging.exception("invalid eventservicegroup in EMANE config")
return return
dev = self.get_config("eventservicedevice") dev = self.get_config("eventservicedevice")
@ -615,12 +615,12 @@ class EmaneManager(ModelManager):
Start one EMANE daemon per node having a radio. Start one EMANE daemon per node having a radio.
Add a control network even if the user has not configured one. Add a control network even if the user has not configured one.
""" """
logger.info("starting emane daemons...") logging.info("starting emane daemons...")
loglevel = str(EmaneManager.DEFAULT_LOG_LEVEL) loglevel = str(EmaneManager.DEFAULT_LOG_LEVEL)
cfgloglevel = self.session.options.get_config_int("emane_log_level") cfgloglevel = self.session.options.get_config_int("emane_log_level")
realtime = self.session.options.get_config_bool("emane_realtime", default=True) realtime = self.session.options.get_config_bool("emane_realtime", default=True)
if cfgloglevel: if cfgloglevel:
logger.info("setting user-defined EMANE log level: %d", cfgloglevel) logging.info("setting user-defined EMANE log level: %d", cfgloglevel)
loglevel = str(cfgloglevel) loglevel = str(cfgloglevel)
emanecmd = ["emane", "-d", "-l", loglevel] emanecmd = ["emane", "-d", "-l", loglevel]
@ -647,11 +647,11 @@ class EmaneManager(ModelManager):
self.session.add_remove_control_interface(node, 0, remove=False, conf_required=False) self.session.add_remove_control_interface(node, 0, remove=False, conf_required=False)
if otanetidx > 0: if otanetidx > 0:
logger.info("adding ota device ctrl%d", otanetidx) logging.info("adding ota device ctrl%d", otanetidx)
self.session.add_remove_control_interface(node, otanetidx, remove=False, conf_required=False) self.session.add_remove_control_interface(node, otanetidx, remove=False, conf_required=False)
if eventservicenetidx >= 0: if eventservicenetidx >= 0:
logger.info("adding event service device ctrl%d", eventservicenetidx) logging.info("adding event service device ctrl%d", eventservicenetidx)
self.session.add_remove_control_interface(node, eventservicenetidx, remove=False, conf_required=False) self.session.add_remove_control_interface(node, eventservicenetidx, remove=False, conf_required=False)
# multicast route is needed for OTA data # multicast route is needed for OTA data
@ -666,8 +666,8 @@ class EmaneManager(ModelManager):
# start emane # start emane
args = emanecmd + ["-f", os.path.join(path, "emane%d.log" % n), os.path.join(path, "platform%d.xml" % n)] args = emanecmd + ["-f", os.path.join(path, "emane%d.log" % n), os.path.join(path, "platform%d.xml" % n)]
output = node.check_cmd(args) output = node.check_cmd(args)
logger.info("node(%s) emane daemon running: %s", node.name, args) logging.info("node(%s) emane daemon running: %s", node.name, args)
logger.info("node(%s) emane daemon output: %s", node.name, output) logging.info("node(%s) emane daemon output: %s", node.name, output)
if not run_emane_on_host: if not run_emane_on_host:
return return
@ -676,7 +676,7 @@ class EmaneManager(ModelManager):
emanecmd += ["-f", os.path.join(path, "emane.log")] emanecmd += ["-f", os.path.join(path, "emane.log")]
args = emanecmd + [os.path.join(path, "platform.xml")] args = emanecmd + [os.path.join(path, "platform.xml")]
utils.check_cmd(args, cwd=path) utils.check_cmd(args, cwd=path)
logger.info("host emane daemon running: %s", args) logging.info("host emane daemon running: %s", args)
def stopdaemons(self): def stopdaemons(self):
""" """
@ -699,7 +699,7 @@ class EmaneManager(ModelManager):
utils.check_cmd(args) utils.check_cmd(args)
utils.check_cmd(["killall", "-q", "emanetransportd"]) utils.check_cmd(["killall", "-q", "emanetransportd"])
except CoreCommandError: except CoreCommandError:
logger.exception("error shutting down emane daemons") logging.exception("error shutting down emane daemons")
def installnetifs(self): def installnetifs(self):
""" """
@ -708,7 +708,7 @@ class EmaneManager(ModelManager):
""" """
for key in sorted(self._emane_nodes.keys()): for key in sorted(self._emane_nodes.keys()):
emane_node = self._emane_nodes[key] emane_node = self._emane_nodes[key]
logger.info("emane install netifs for node: %d", key) logging.info("emane install netifs for node: %d", key)
emane_node.installnetifs() emane_node.installnetifs()
def deinstallnetifs(self): def deinstallnetifs(self):
@ -742,12 +742,12 @@ class EmaneManager(ModelManager):
""" """
Start monitoring EMANE location events if configured to do so. Start monitoring EMANE location events if configured to do so.
""" """
logger.info("emane start event monitor") logging.info("emane start event monitor")
if not self.doeventmonitor(): if not self.doeventmonitor():
return return
if self.service is None: if self.service is None:
logger.error("Warning: EMANE events will not be generated " logging.error("Warning: EMANE events will not be generated "
"because the emaneeventservice\n binding was " "because the emaneeventservice\n binding was "
"unable to load " "unable to load "
"(install the python-emaneeventservice bindings)") "(install the python-emaneeventservice bindings)")
@ -779,7 +779,7 @@ class EmaneManager(ModelManager):
""" """
if self.service is None: if self.service is None:
return return
logger.info("subscribing to EMANE location events. (%s)", threading.currentThread().getName()) logging.info("subscribing to EMANE location events. (%s)", threading.currentThread().getName())
while self.doeventloop is True: while self.doeventloop is True:
_uuid, _seq, events = self.service.nextEvent() _uuid, _seq, events = self.service.nextEvent()
@ -792,7 +792,7 @@ class EmaneManager(ModelManager):
if eid == LocationEvent.IDENTIFIER: if eid == LocationEvent.IDENTIFIER:
self.handlelocationevent(nem, eid, data) self.handlelocationevent(nem, eid, data)
logger.info("unsubscribing from EMANE location events. (%s)", threading.currentThread().getName()) logging.info("unsubscribing from EMANE location events. (%s)", threading.currentThread().getName())
def handlelocationevent(self, rxnemid, eid, data): def handlelocationevent(self, rxnemid, eid, data):
""" """
@ -803,14 +803,14 @@ class EmaneManager(ModelManager):
for event in events: for event in events:
txnemid, attrs = event txnemid, attrs = event
if "latitude" not in attrs or "longitude" not in attrs or "altitude" not in attrs: if "latitude" not in attrs or "longitude" not in attrs or "altitude" not in attrs:
logger.warn("dropped invalid location event") logging.warn("dropped invalid location event")
continue continue
# yaw,pitch,roll,azimuth,elevation,velocity are unhandled # yaw,pitch,roll,azimuth,elevation,velocity are unhandled
lat = attrs["latitude"] lat = attrs["latitude"]
lon = attrs["longitude"] lon = attrs["longitude"]
alt = attrs["altitude"] alt = attrs["altitude"]
logger.debug("emane location event: %s,%s,%s", lat, lon, alt) logging.debug("emane location event: %s,%s,%s", lat, lon, alt)
self.handlelocationeventtoxyz(txnemid, lat, lon, alt) self.handlelocationeventtoxyz(txnemid, lat, lon, alt)
def handlelocationeventtoxyz(self, nemid, lat, lon, alt): def handlelocationeventtoxyz(self, nemid, lat, lon, alt):
@ -822,7 +822,7 @@ class EmaneManager(ModelManager):
# convert nemid to node number # convert nemid to node number
_emanenode, netif = self.nemlookup(nemid) _emanenode, netif = self.nemlookup(nemid)
if netif is None: if netif is None:
logger.info("location event for unknown NEM %s", nemid) logging.info("location event for unknown NEM %s", nemid)
return False return False
n = netif.node.objid n = netif.node.objid
@ -831,12 +831,12 @@ class EmaneManager(ModelManager):
x = int(x) x = int(x)
y = int(y) y = int(y)
z = int(z) z = int(z)
logger.info("location event NEM %s (%s, %s, %s) -> (%s, %s, %s)", nemid, lat, lon, alt, x, y, z) logging.info("location event NEM %s (%s, %s, %s) -> (%s, %s, %s)", nemid, lat, lon, alt, x, y, z)
xbit_check = x.bit_length() > 16 or x < 0 xbit_check = x.bit_length() > 16 or x < 0
ybit_check = y.bit_length() > 16 or y < 0 ybit_check = y.bit_length() > 16 or y < 0
zbit_check = z.bit_length() > 16 or z < 0 zbit_check = z.bit_length() > 16 or z < 0
if any([xbit_check, ybit_check, zbit_check]): if any([xbit_check, ybit_check, zbit_check]):
logger.error("Unable to build node location message, received lat/long/alt exceeds coordinate " logging.error("Unable to build node location message, received lat/long/alt exceeds coordinate "
"space: NEM %s (%d, %d, %d)", nemid, x, y, z) "space: NEM %s (%d, %d, %d)", nemid, x, y, z)
return False return False
@ -844,7 +844,7 @@ class EmaneManager(ModelManager):
try: try:
node = self.session.get_object(n) node = self.session.get_object(n)
except KeyError: except KeyError:
logger.exception("location event NEM %s has no corresponding node %s" % (nemid, n)) logging.exception("location event NEM %s has no corresponding node %s" % (nemid, n))
return False return False
# don"t use node.setposition(x,y,z) which generates an event # don"t use node.setposition(x,y,z) which generates an event

View file

@ -1,4 +1,5 @@
from core import logger import logging
from core.conf import Configuration from core.conf import Configuration
from core.enumerations import ConfigDataTypes from core.enumerations import ConfigDataTypes
@ -9,7 +10,7 @@ except ImportError:
try: try:
from emanesh import manifest from emanesh import manifest
except ImportError: except ImportError:
logger.debug("compatible emane python bindings not installed") logging.debug("compatible emane python bindings not installed")
def _type_value(config_type): def _type_value(config_type):

View file

@ -1,9 +1,9 @@
""" """
Defines Emane Models used within CORE. Defines Emane Models used within CORE.
""" """
import logging
import os import os
from core import logger
from core.conf import ConfigGroup from core.conf import ConfigGroup
from core.conf import Configuration from core.conf import Configuration
from core.emane import emanemanifest from core.emane import emanemanifest
@ -95,7 +95,7 @@ class EmaneModel(WirelessModel):
:return: nothing :return: nothing
""" """
logger.info("emane model(%s) has no post setup tasks", self.name) logging.info("emane model(%s) has no post setup tasks", self.name)
def update(self, moved, moved_netifs): def update(self, moved, moved_netifs):
""" """
@ -111,7 +111,7 @@ class EmaneModel(WirelessModel):
wlan = self.session.get_object(self.object_id) wlan = self.session.get_object(self.object_id)
wlan.setnempositions(moved_netifs) wlan.setnempositions(moved_netifs)
except KeyError: except KeyError:
logger.exception("error during update") logging.exception("error during update")
def linkconfig(self, netif, bw=None, delay=None, loss=None, duplicate=None, jitter=None, netif2=None): def linkconfig(self, netif, bw=None, delay=None, loss=None, duplicate=None, jitter=None, netif2=None):
""" """
@ -126,4 +126,4 @@ class EmaneModel(WirelessModel):
:param core.netns.vif.Veth netif2: interface two :param core.netns.vif.Veth netif2: interface two
:return: nothing :return: nothing
""" """
logger.warn("emane model(%s) does not support link configuration", self.name) logging.warn("emane model(%s) does not support link configuration", self.name)

View file

@ -4,7 +4,8 @@ control of an EMANE emulation. An EmaneNode has several attached NEMs that
share the same MAC+PHY model. share the same MAC+PHY model.
""" """
from core import logger import logging
from core.coreobj import PyCoreNet from core.coreobj import PyCoreNet
from core.enumerations import LinkTypes from core.enumerations import LinkTypes
from core.enumerations import NodeTypes from core.enumerations import NodeTypes
@ -16,7 +17,7 @@ except ImportError:
try: try:
from emanesh.events import LocationEvent from emanesh.events import LocationEvent
except ImportError: except ImportError:
logger.debug("compatible emane python bindings not installed") logging.debug("compatible emane python bindings not installed")
class EmaneNet(PyCoreNet): class EmaneNet(PyCoreNet):
@ -68,14 +69,14 @@ class EmaneNode(EmaneNet):
def updatemodel(self, config): def updatemodel(self, config):
if not self.model: if not self.model:
raise ValueError("no model set to update for node(%s)", self.objid) raise ValueError("no model set to update for node(%s)", self.objid)
logger.info("node(%s) updating model(%s): %s", self.objid, self.model.name, config) logging.info("node(%s) updating model(%s): %s", self.objid, self.model.name, config)
self.model.set_configs(config, node_id=self.objid) self.model.set_configs(config, node_id=self.objid)
def setmodel(self, model, config): def setmodel(self, model, config):
""" """
set the EmaneModel associated with this node set the EmaneModel associated with this node
""" """
logger.info("adding model: %s", model.name) logging.info("adding model: %s", model.name)
if model.config_type == RegisterTlvs.WIRELESS.value: if model.config_type == RegisterTlvs.WIRELESS.value:
# EmaneModel really uses values from ConfigurableManager # EmaneModel really uses values from ConfigurableManager
# when buildnemxml() is called, not during init() # when buildnemxml() is called, not during init()
@ -126,7 +127,7 @@ class EmaneNode(EmaneNet):
if self.session.emane.genlocationevents() and self.session.emane.service is None: if self.session.emane.genlocationevents() and self.session.emane.service is None:
warntxt = "unable to publish EMANE events because the eventservice " warntxt = "unable to publish EMANE events because the eventservice "
warntxt += "Python bindings failed to load" warntxt += "Python bindings failed to load"
logger.error(warntxt) logging.error(warntxt)
for netif in self.netifs(): for netif in self.netifs():
external = self.session.emane.get_config("external", self.objid, self.model.name) external = self.session.emane.get_config("external", self.objid, self.model.name)
@ -159,15 +160,15 @@ class EmaneNode(EmaneNet):
Publish a NEM location change event using the EMANE event service. Publish a NEM location change event using the EMANE event service.
""" """
if self.session.emane.service is None: if self.session.emane.service is None:
logger.info("position service not available") logging.info("position service not available")
return return
nemid = self.getnemid(netif) nemid = self.getnemid(netif)
ifname = netif.localname ifname = netif.localname
if nemid is None: if nemid is None:
logger.info("nemid for %s is unknown" % ifname) logging.info("nemid for %s is unknown" % ifname)
return return
lat, long, alt = self.session.location.getgeo(x, y, z) lat, long, alt = self.session.location.getgeo(x, y, z)
logger.info("setnemposition %s (%s) x,y,z=(%d,%d,%s)(%.6f,%.6f,%.6f)", ifname, nemid, x, y, z, lat, long, alt) logging.info("setnemposition %s (%s) x,y,z=(%d,%d,%s)(%.6f,%.6f,%.6f)", ifname, nemid, x, y, z, lat, long, alt)
event = LocationEvent() event = LocationEvent()
# altitude must be an integer or warning is printed # altitude must be an integer or warning is printed
@ -186,7 +187,7 @@ class EmaneNode(EmaneNet):
return return
if self.session.emane.service is None: if self.session.emane.service is None:
logger.info("position service not available") logging.info("position service not available")
return return
event = LocationEvent() event = LocationEvent()
@ -195,11 +196,11 @@ class EmaneNode(EmaneNet):
nemid = self.getnemid(netif) nemid = self.getnemid(netif)
ifname = netif.localname ifname = netif.localname
if nemid is None: if nemid is None:
logger.info("nemid for %s is unknown" % ifname) logging.info("nemid for %s is unknown" % ifname)
continue continue
x, y, z = netif.node.getposition() x, y, z = netif.node.getposition()
lat, long, alt = self.session.location.getgeo(x, y, z) lat, long, alt = self.session.location.getgeo(x, y, z)
logger.info("setnempositions %d %s (%s) x,y,z=(%d,%d,%s)(%.6f,%.6f,%.6f)", logging.info("setnempositions %d %s (%s) x,y,z=(%d,%d,%s)(%.6f,%.6f,%.6f)",
i, ifname, nemid, x, y, z, lat, long, alt) i, ifname, nemid, x, y, z, lat, long, alt)
# altitude must be an integer or warning is printed # altitude must be an integer or warning is printed
alt = int(round(alt)) alt = int(round(alt))

View file

@ -2,10 +2,10 @@
tdma.py: EMANE TDMA model bindings for CORE tdma.py: EMANE TDMA model bindings for CORE
""" """
import logging
import os import os
from core import constants from core import constants
from core import logger
from core.conf import Configuration from core.conf import Configuration
from core.emane import emanemanifest from core.emane import emanemanifest
from core.emane import emanemodel from core.emane import emanemodel
@ -55,5 +55,5 @@ class EmaneTdmaModel(emanemodel.EmaneModel):
event_device = self.session.emane.event_device event_device = self.session.emane.event_device
# initiate tdma schedule # initiate tdma schedule
logger.info("setting up tdma schedule: schedule(%s) device(%s)", schedule, event_device) logging.info("setting up tdma schedule: schedule(%s) device(%s)", schedule, event_device)
utils.check_cmd(["emaneevent-tdmaschedule", "-i", event_device, schedule]) utils.check_cmd(["emaneevent-tdmaschedule", "-i", event_device, schedule])

View file

@ -1,10 +1,10 @@
import atexit import atexit
import logging
import os import os
import signal import signal
import sys import sys
import core.services import core.services
from core import logger
from core.coreobj import PyCoreNet from core.coreobj import PyCoreNet
from core.coreobj import PyCoreNode from core.coreobj import PyCoreNode
from core.data import NodeData from core.data import NodeData
@ -28,7 +28,7 @@ def signal_handler(signal_number, _):
:param _: ignored :param _: ignored
:return: nothing :return: nothing
""" """
logger.info("caught signal: %s", signal_number) logging.info("caught signal: %s", signal_number)
sys.exit(signal_number) sys.exit(signal_number)
@ -142,7 +142,7 @@ class EmuSession(Session):
:return: nodes, network nodes if present, and tunnel if present :return: nodes, network nodes if present, and tunnel if present
:rtype: tuple :rtype: tuple
""" """
logger.debug("link message between node1(%s) and node2(%s)", node_one_id, node_two_id) logging.debug("link message between node1(%s) and node2(%s)", node_one_id, node_two_id)
# values to fill # values to fill
net_one = None net_one = None
@ -154,7 +154,7 @@ class EmuSession(Session):
# both node ids are provided # both node ids are provided
tunnel = self.broker.gettunnel(node_one_id, node_two_id) tunnel = self.broker.gettunnel(node_one_id, node_two_id)
logger.debug("tunnel between nodes: %s", tunnel) logging.debug("tunnel between nodes: %s", tunnel)
if nodeutils.is_node(tunnel, NodeTypes.TAP_BRIDGE): if nodeutils.is_node(tunnel, NodeTypes.TAP_BRIDGE):
net_one = tunnel net_one = tunnel
if tunnel.remotenum == node_one_id: if tunnel.remotenum == node_one_id:
@ -182,7 +182,7 @@ class EmuSession(Session):
net_two = node_two net_two = node_two
node_two = None node_two = None
logger.debug("link node types n1(%s) n2(%s) net1(%s) net2(%s) tunnel(%s)", logging.debug("link node types n1(%s) n2(%s) net1(%s) net2(%s) tunnel(%s)",
node_one, node_two, net_one, net_two, tunnel) node_one, node_two, net_one, net_two, tunnel)
return node_one, node_two, net_one, net_two, tunnel return node_one, node_two, net_one, net_two, tunnel
@ -198,17 +198,17 @@ class EmuSession(Session):
objects = [x for x in objects if x] objects = [x for x in objects if x]
if len(objects) < 2: if len(objects) < 2:
raise ValueError("wireless link failure: %s", objects) raise ValueError("wireless link failure: %s", objects)
logger.debug("handling wireless linking objects(%s) connect(%s)", objects, connect) logging.debug("handling wireless linking objects(%s) connect(%s)", objects, connect)
common_networks = objects[0].commonnets(objects[1]) common_networks = objects[0].commonnets(objects[1])
if not common_networks: if not common_networks:
raise ValueError("no common network found for wireless link/unlink") raise ValueError("no common network found for wireless link/unlink")
for common_network, interface_one, interface_two in common_networks: for common_network, interface_one, interface_two in common_networks:
if not nodeutils.is_node(common_network, [NodeTypes.WIRELESS_LAN, NodeTypes.EMANE]): if not nodeutils.is_node(common_network, [NodeTypes.WIRELESS_LAN, NodeTypes.EMANE]):
logger.info("skipping common network that is not wireless/emane: %s", common_network) logging.info("skipping common network that is not wireless/emane: %s", common_network)
continue continue
logger.info("wireless linking connect(%s): %s - %s", connect, interface_one, interface_two) logging.info("wireless linking connect(%s): %s - %s", connect, interface_one, interface_two)
if connect: if connect:
common_network.link(interface_one, interface_two) common_network.link(interface_one, interface_two)
else: else:
@ -242,27 +242,27 @@ class EmuSession(Session):
else: else:
# 2 nodes being linked, ptp network # 2 nodes being linked, ptp network
if all([node_one, node_two]) and not net_one: if all([node_one, node_two]) and not net_one:
logger.info("adding link for peer to peer nodes: %s - %s", node_one.name, node_two.name) logging.info("adding link for peer to peer nodes: %s - %s", node_one.name, node_two.name)
ptp_class = nodeutils.get_node_class(NodeTypes.PEER_TO_PEER) ptp_class = nodeutils.get_node_class(NodeTypes.PEER_TO_PEER)
start = self.state > EventTypes.DEFINITION_STATE.value start = self.state > EventTypes.DEFINITION_STATE.value
net_one = self.add_object(cls=ptp_class, start=start) net_one = self.add_object(cls=ptp_class, start=start)
# node to network # node to network
if node_one and net_one: if node_one and net_one:
logger.info("adding link from node to network: %s - %s", node_one.name, net_one.name) logging.info("adding link from node to network: %s - %s", node_one.name, net_one.name)
interface = create_interface(node_one, net_one, interface_one) interface = create_interface(node_one, net_one, interface_one)
link_config(net_one, interface, link_options) link_config(net_one, interface, link_options)
# network to node # network to node
if node_two and net_one: if node_two and net_one:
logger.info("adding link from network to node: %s - %s", node_two.name, net_one.name) logging.info("adding link from network to node: %s - %s", node_two.name, net_one.name)
interface = create_interface(node_two, net_one, interface_two) interface = create_interface(node_two, net_one, interface_two)
if not link_options.unidirectional: if not link_options.unidirectional:
link_config(net_one, interface, link_options) link_config(net_one, interface, link_options)
# network to network # network to network
if net_one and net_two: if net_one and net_two:
logger.info("adding link from network to network: %s - %s", net_one.name, net_two.name) logging.info("adding link from network to network: %s - %s", net_one.name, net_two.name)
if nodeutils.is_node(net_two, NodeTypes.RJ45): if nodeutils.is_node(net_two, NodeTypes.RJ45):
interface = net_two.linknet(net_one) interface = net_two.linknet(net_one)
else: else:
@ -286,12 +286,12 @@ class EmuSession(Session):
# tunnel node logic # tunnel node logic
key = link_options.key key = link_options.key
if key and nodeutils.is_node(net_one, NodeTypes.TUNNEL): if key and nodeutils.is_node(net_one, NodeTypes.TUNNEL):
logger.info("setting tunnel key for: %s", net_one.name) logging.info("setting tunnel key for: %s", net_one.name)
net_one.setkey(key) net_one.setkey(key)
if addresses: if addresses:
net_one.addrconfig(addresses) net_one.addrconfig(addresses)
if key and nodeutils.is_node(net_two, NodeTypes.TUNNEL): if key and nodeutils.is_node(net_two, NodeTypes.TUNNEL):
logger.info("setting tunnel key for: %s", net_two.name) logging.info("setting tunnel key for: %s", net_two.name)
net_two.setkey(key) net_two.setkey(key)
if addresses: if addresses:
net_two.addrconfig(addresses) net_two.addrconfig(addresses)
@ -299,12 +299,12 @@ class EmuSession(Session):
# physical node connected with tunnel # physical node connected with tunnel
if not net_one and not net_two and (node_one or node_two): if not net_one and not net_two and (node_one or node_two):
if node_one and nodeutils.is_node(node_one, NodeTypes.PHYSICAL): if node_one and nodeutils.is_node(node_one, NodeTypes.PHYSICAL):
logger.info("adding link for physical node: %s", node_one.name) logging.info("adding link for physical node: %s", node_one.name)
addresses = interface_one.get_addresses() addresses = interface_one.get_addresses()
node_one.adoptnetif(tunnel, interface_one.id, interface_one.mac, addresses) node_one.adoptnetif(tunnel, interface_one.id, interface_one.mac, addresses)
link_config(node_one, tunnel, link_options) link_config(node_one, tunnel, link_options)
elif node_two and nodeutils.is_node(node_two, NodeTypes.PHYSICAL): elif node_two and nodeutils.is_node(node_two, NodeTypes.PHYSICAL):
logger.info("adding link for physical node: %s", node_two.name) logging.info("adding link for physical node: %s", node_two.name)
addresses = interface_two.get_addresses() addresses = interface_two.get_addresses()
node_two.adoptnetif(tunnel, interface_two.id, interface_two.mac, addresses) node_two.adoptnetif(tunnel, interface_two.id, interface_two.mac, addresses)
link_config(node_two, tunnel, link_options) link_config(node_two, tunnel, link_options)
@ -360,7 +360,7 @@ class EmuSession(Session):
if interface_one.net != interface_two.net and all([interface_one.up, interface_two.up]): if interface_one.net != interface_two.net and all([interface_one.up, interface_two.up]):
raise ValueError("no common network found") raise ValueError("no common network found")
logger.info("deleting link node(%s):interface(%s) node(%s):interface(%s)", logging.info("deleting link node(%s):interface(%s) node(%s):interface(%s)",
node_one.name, interface_one.name, node_two.name, interface_two.name) node_one.name, interface_one.name, node_two.name, interface_two.name)
net_one = interface_one.net net_one = interface_one.net
interface_one.detachnet() interface_one.detachnet()
@ -470,7 +470,7 @@ class EmuSession(Session):
try: try:
node_class = nodeutils.get_node_class(_type) node_class = nodeutils.get_node_class(_type)
except KeyError: except KeyError:
logger.error("invalid node type to create: %s", _type) logging.error("invalid node type to create: %s", _type)
return None return None
# set node start based on current session state, override and check when rj45 # set node start based on current session state, override and check when rj45
@ -492,7 +492,7 @@ class EmuSession(Session):
name = "%s%s" % (node_class.__name__, _id) name = "%s%s" % (node_class.__name__, _id)
# create node # create node
logger.info("creating node(%s) id(%s) name(%s) start(%s)", node_class.__name__, _id, name, start) logging.info("creating node(%s) id(%s) name(%s) start(%s)", node_class.__name__, _id, name, start)
node = self.add_object(cls=node_class, objid=_id, name=name, start=start) node = self.add_object(cls=node_class, objid=_id, name=name, start=start)
# set node attributes # set node attributes
@ -506,7 +506,7 @@ class EmuSession(Session):
# add services to default and physical nodes only # add services to default and physical nodes only
if _type in [NodeTypes.DEFAULT, NodeTypes.PHYSICAL]: if _type in [NodeTypes.DEFAULT, NodeTypes.PHYSICAL]:
node.type = node_options.model node.type = node_options.model
logger.debug("set node type: %s", node.type) logging.debug("set node type: %s", node.type)
self.services.add_services(node, node.type, node_options.services) self.services.add_services(node, node.type, node_options.services)
# boot nodes if created after runtime, LcxNodes, Physical, and RJ45 are all PyCoreNodes # boot nodes if created after runtime, LcxNodes, Physical, and RJ45 are all PyCoreNodes
@ -542,7 +542,7 @@ class EmuSession(Session):
# set node as updated successfully # set node as updated successfully
result = True result = True
except KeyError: except KeyError:
logger.error("failure to update node that does not exist: %s", node_id) logging.error("failure to update node that does not exist: %s", node_id)
return result return result
@ -620,7 +620,7 @@ class EmuSession(Session):
:return: nothing :return: nothing
""" """
logger.info("session(%s) shutting down", self.session_id) logging.info("session(%s) shutting down", self.session_id)
self.set_state(EventTypes.DATACOLLECT_STATE, send_event=True) self.set_state(EventTypes.DATACOLLECT_STATE, send_event=True)
self.set_state(EventTypes.SHUTDOWN_STATE, send_event=True) self.set_state(EventTypes.SHUTDOWN_STATE, send_event=True)
super(EmuSession, self).shutdown() super(EmuSession, self).shutdown()
@ -647,7 +647,7 @@ class EmuSession(Session):
:return: True if active, False otherwise :return: True if active, False otherwise
""" """
result = self.state in {EventTypes.RUNTIME_STATE.value, EventTypes.DATACOLLECT_STATE.value} result = self.state in {EventTypes.RUNTIME_STATE.value, EventTypes.DATACOLLECT_STATE.value}
logger.info("session(%s) checking if active: %s", self.session_id, result) logging.info("session(%s) checking if active: %s", self.session_id, result)
return result return result
def open_xml(self, file_name, start=False): def open_xml(self, file_name, start=False):
@ -813,7 +813,7 @@ class CoreEmu(object):
# load custom services # load custom services
service_paths = self.config.get("custom_services_dir") service_paths = self.config.get("custom_services_dir")
logger.debug("custom service paths: %s", service_paths) logging.debug("custom service paths: %s", service_paths)
if service_paths: if service_paths:
for service_path in service_paths.split(','): for service_path in service_paths.split(','):
service_path = service_path.strip() service_path = service_path.strip()
@ -835,7 +835,7 @@ class CoreEmu(object):
:return: nothing :return: nothing
""" """
logger.info("shutting down all sessions") logging.info("shutting down all sessions")
sessions = self.sessions.copy() sessions = self.sessions.copy()
self.sessions.clear() self.sessions.clear()
for session in sessions.itervalues(): for session in sessions.itervalues():
@ -860,7 +860,7 @@ class CoreEmu(object):
break break
session = _cls(session_id, config=self.config) session = _cls(session_id, config=self.config)
logger.info("created session: %s", session_id) logging.info("created session: %s", session_id)
if master: if master:
session.master = True session.master = True
@ -875,14 +875,14 @@ class CoreEmu(object):
:return: True if deleted, False otherwise :return: True if deleted, False otherwise
:rtype: bool :rtype: bool
""" """
logger.info("deleting session: %s", _id) logging.info("deleting session: %s", _id)
session = self.sessions.pop(_id, None) session = self.sessions.pop(_id, None)
result = False result = False
if session: if session:
logger.info("shutting session down: %s", _id) logging.info("shutting session down: %s", _id)
session.shutdown() session.shutdown()
result = True result = True
else: else:
logger.error("session to delete did not exist: %s", _id) logging.error("session to delete did not exist: %s", _id)
return result return result

View file

@ -5,7 +5,8 @@ systems. Depends on utm contributed module, from
https://pypi.python.org/pypi/utm (version 0.3.0). https://pypi.python.org/pypi/utm (version 0.3.0).
""" """
from core import logger import logging
from core.enumerations import RegisterTlvs from core.enumerations import RegisterTlvs
from core.misc import utm from core.misc import utm
@ -117,7 +118,7 @@ class CoreLocation(object):
try: try:
lat, lon = utm.to_latlon(e, n, zone[0], zone[1]) lat, lon = utm.to_latlon(e, n, zone[0], zone[1])
except utm.OutOfRangeError: except utm.OutOfRangeError:
logger.exception("UTM out of range error for n=%s zone=%s xyz=(%s,%s,%s)", n, zone, x, y, z) logging.exception("UTM out of range error for n=%s zone=%s xyz=(%s,%s,%s)", n, zone, x, y, z)
lat, lon = self.refgeo[:2] lat, lon = self.refgeo[:2]
# self.info("getgeo(%s,%s,%s) e=%s n=%s zone=%s lat,lon,alt=" \ # self.info("getgeo(%s,%s,%s) e=%s n=%s zone=%s lat,lon,alt=" \
# "%.3f,%.3f,%.3f" % (x, y, z, e, n, zone, lat, lon, alt)) # "%.3f,%.3f,%.3f" % (x, y, z, e, n, zone, lat, lon, alt))

View file

@ -2,14 +2,13 @@
Helper objects for dealing with IPv4/v6 addresses. Helper objects for dealing with IPv4/v6 addresses.
""" """
import logging
import random import random
import socket import socket
import struct import struct
from socket import AF_INET from socket import AF_INET
from socket import AF_INET6 from socket import AF_INET6
from core import logger
class MacAddress(object): class MacAddress(object):
""" """
@ -151,7 +150,7 @@ class IpAddress(object):
try: try:
carry = int(other) carry = int(other)
except ValueError: except ValueError:
logger.exception("error during addition") logging.exception("error during addition")
return NotImplemented return NotImplemented
tmp = [ord(x) for x in self.addr] tmp = [ord(x) for x in self.addr]
@ -174,7 +173,7 @@ class IpAddress(object):
try: try:
tmp = -int(other) tmp = -int(other)
except ValueError: except ValueError:
logger.exception("error during subtraction") logging.exception("error during subtraction")
return NotImplemented return NotImplemented
return self.__add__(tmp) return self.__add__(tmp)
@ -276,7 +275,7 @@ class IpPrefix(object):
try: try:
tmp = int(other) tmp = int(other)
except ValueError: except ValueError:
logger.exception("error during addition") logging.exception("error during addition")
return NotImplemented return NotImplemented
a = IpAddress(self.af, self.prefix) + (tmp << (self.addrlen - self.prefixlen)) a = IpAddress(self.af, self.prefix) + (tmp << (self.addrlen - self.prefixlen))
@ -297,7 +296,7 @@ class IpPrefix(object):
try: try:
tmp = -int(other) tmp = -int(other)
except ValueError: except ValueError:
logger.exception("error during subtraction") logging.exception("error during subtraction")
return NotImplemented return NotImplemented
return self.__add__(tmp) return self.__add__(tmp)

View file

@ -2,7 +2,7 @@
Serves as a global point for storing and retrieving node types needed during simulation. Serves as a global point for storing and retrieving node types needed during simulation.
""" """
from core import logger import logging
_NODE_MAP = None _NODE_MAP = None
@ -13,7 +13,7 @@ def _log_map():
name = None name = None
if value: if value:
name = value.__name__ name = value.__name__
logger.debug("node type (%s) - class (%s)", key.name, name) logging.debug("node type (%s) - class (%s)", key.name, name)
def _convert_map(x, y): def _convert_map(x, y):

View file

@ -2,7 +2,7 @@
Utilities for working with python struct data. Utilities for working with python struct data.
""" """
from core import logger import logging
def pack_values(clazz, packers): def pack_values(clazz, packers):
@ -40,7 +40,7 @@ def pack_values(clazz, packers):
value = transformer(value) value = transformer(value)
# pack and add to existing data # pack and add to existing data
logger.debug("packing: %s - %s", tlv_type, value) logging.debug("packing: %s - %s", tlv_type, value)
data += clazz.pack(tlv_type.value, value) data += clazz.pack(tlv_type.value, value)
return data return data

View file

@ -4,6 +4,7 @@ Miscellaneous utility functions, wrappers around some subprocess procedures.
import importlib import importlib
import inspect import inspect
import logging
import os import os
import shlex import shlex
import subprocess import subprocess
@ -12,7 +13,6 @@ import sys
import fcntl import fcntl
from core import CoreCommandError from core import CoreCommandError
from core import logger
DEVNULL = open(os.devnull, "wb") DEVNULL = open(os.devnull, "wb")
@ -179,7 +179,7 @@ def cmd(args, wait=True):
:rtype: int :rtype: int
""" """
args = split_args(args) args = split_args(args)
logger.debug("command: %s", args) logging.debug("command: %s", args)
try: try:
p = subprocess.Popen(args) p = subprocess.Popen(args)
if not wait: if not wait:
@ -200,7 +200,7 @@ def cmd_output(args):
:raises CoreCommandError: when the file to execute is not found :raises CoreCommandError: when the file to execute is not found
""" """
args = split_args(args) args = split_args(args)
logger.debug("command: %s", args) logging.debug("command: %s", args)
try: try:
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout, _ = p.communicate() stdout, _ = p.communicate()
@ -224,7 +224,7 @@ def check_cmd(args, **kwargs):
kwargs["stdout"] = subprocess.PIPE kwargs["stdout"] = subprocess.PIPE
kwargs["stderr"] = subprocess.STDOUT kwargs["stderr"] = subprocess.STDOUT
args = split_args(args) args = split_args(args)
logger.debug("command: %s", args) logging.debug("command: %s", args)
try: try:
p = subprocess.Popen(args, **kwargs) p = subprocess.Popen(args, **kwargs)
stdout, _ = p.communicate() stdout, _ = p.communicate()
@ -362,7 +362,7 @@ def load_config(filename, d):
key, value = line.split("=", 1) key, value = line.split("=", 1)
d[key] = value.strip() d[key] = value.strip()
except ValueError: except ValueError:
logger.exception("error reading file to dict: %s", filename) logging.exception("error reading file to dict: %s", filename)
def load_classes(path, clazz): def load_classes(path, clazz):
@ -374,13 +374,13 @@ def load_classes(path, clazz):
:return: list of classes loaded :return: list of classes loaded
""" """
# validate path exists # validate path exists
logger.debug("attempting to load modules from path: %s", path) logging.debug("attempting to load modules from path: %s", path)
if not os.path.isdir(path): if not os.path.isdir(path):
logger.warn("invalid custom module directory specified" ": %s" % path) logging.warn("invalid custom module directory specified" ": %s" % path)
# check if path is in sys.path # check if path is in sys.path
parent_path = os.path.dirname(path) parent_path = os.path.dirname(path)
if parent_path not in sys.path: if parent_path not in sys.path:
logger.debug("adding parent path to allow imports: %s", parent_path) logging.debug("adding parent path to allow imports: %s", parent_path)
sys.path.append(parent_path) sys.path.append(parent_path)
# retrieve potential service modules, and filter out invalid modules # retrieve potential service modules, and filter out invalid modules
@ -393,7 +393,7 @@ def load_classes(path, clazz):
classes = [] classes = []
for module_name in module_names: for module_name in module_names:
import_statement = "%s.%s" % (base_module, module_name) import_statement = "%s.%s" % (base_module, module_name)
logger.debug("importing custom module: %s", import_statement) logging.debug("importing custom module: %s", import_statement)
try: try:
module = importlib.import_module(import_statement) module = importlib.import_module(import_statement)
members = inspect.getmembers(module, lambda x: _is_class(module, x, clazz)) members = inspect.getmembers(module, lambda x: _is_class(module, x, clazz))
@ -401,6 +401,6 @@ def load_classes(path, clazz):
valid_class = member[1] valid_class = member[1]
classes.append(valid_class) classes.append(valid_class)
except: except:
logger.exception("unexpected error during import, skipping: %s", import_statement) logging.exception("unexpected error during import, skipping: %s", import_statement)
return classes return classes

View file

@ -3,12 +3,12 @@ mobility.py: mobility helpers for moving nodes and calculating wireless range.
""" """
import heapq import heapq
import logging
import math import math
import os import os
import threading import threading
import time import time
from core import logger
from core.conf import ConfigGroup from core.conf import ConfigGroup
from core.conf import ConfigurableOptions from core.conf import ConfigurableOptions
from core.conf import Configuration from core.conf import Configuration
@ -63,13 +63,13 @@ class MobilityManager(ModelManager):
node_ids = self.nodes() node_ids = self.nodes()
for node_id in node_ids: for node_id in node_ids:
logger.info("checking mobility startup for node: %s", node_id) logging.info("checking mobility startup for node: %s", node_id)
logger.info("node mobility configurations: %s", self.get_all_configs(node_id)) logging.info("node mobility configurations: %s", self.get_all_configs(node_id))
try: try:
node = self.session.get_object(node_id) node = self.session.get_object(node_id)
except KeyError: except KeyError:
logger.warn("skipping mobility configuration for unknown node: %s", node_id) logging.warn("skipping mobility configuration for unknown node: %s", node_id)
continue continue
for model_name in self.models.iterkeys(): for model_name in self.models.iterkeys():
@ -100,7 +100,7 @@ class MobilityManager(ModelManager):
try: try:
node = self.session.get_object(node_id) node = self.session.get_object(node_id)
except KeyError: except KeyError:
logger.exception("Ignoring event for model '%s', unknown node '%s'", name, node_id) logging.exception("Ignoring event for model '%s', unknown node '%s'", name, node_id)
return return
# name is e.g. "mobility:ns2script" # name is e.g. "mobility:ns2script"
@ -109,7 +109,7 @@ class MobilityManager(ModelManager):
try: try:
cls = self.models[model] cls = self.models[model]
except KeyError: except KeyError:
logger.warn("Ignoring event for unknown model '%s'", model) logging.warn("Ignoring event for unknown model '%s'", model)
continue continue
if cls.config_type in [RegisterTlvs.WIRELESS.value, RegisterTlvs.MOBILITY.value]: if cls.config_type in [RegisterTlvs.WIRELESS.value, RegisterTlvs.MOBILITY.value]:
@ -118,11 +118,11 @@ class MobilityManager(ModelManager):
continue continue
if model is None: if model is None:
logger.warn("Ignoring event, %s has no model", node.name) logging.warn("Ignoring event, %s has no model", node.name)
continue continue
if cls.name != model.name: if cls.name != model.name:
logger.warn("Ignoring event for %s wrong model %s,%s", node.name, cls.name, model.name) logging.warn("Ignoring event for %s wrong model %s,%s", node.name, cls.name, model.name)
continue continue
if event_type == EventTypes.STOP.value or event_type == EventTypes.RESTART.value: if event_type == EventTypes.STOP.value or event_type == EventTypes.RESTART.value:
@ -232,7 +232,7 @@ class MobilityManager(ModelManager):
nodeypos = message.get_tlv(NodeTlvs.Y_POSITION.value) nodeypos = message.get_tlv(NodeTlvs.Y_POSITION.value)
dummy.setposition(nodexpos, nodeypos, None) dummy.setposition(nodexpos, nodeypos, None)
except KeyError: except KeyError:
logger.exception("error retrieving physical node: %s", nodenum) logging.exception("error retrieving physical node: %s", nodenum)
def installphysnodes(self, net): def installphysnodes(self, net):
""" """
@ -358,7 +358,7 @@ class BasicRangeModel(WirelessModel):
:return: nothing :return: nothing
""" """
self.range = float(config["range"]) self.range = float(config["range"])
logger.info("basic range model configured for WLAN %d using range %d", self.wlan.objid, self.range) logging.info("basic range model configured for WLAN %d using range %d", self.wlan.objid, self.range)
self.bw = int(config["bandwidth"]) self.bw = int(config["bandwidth"])
if self.bw == 0.0: if self.bw == 0.0:
self.bw = None self.bw = None
@ -467,20 +467,20 @@ class BasicRangeModel(WirelessModel):
with self.wlan._linked_lock: with self.wlan._linked_lock:
linked = self.wlan.linked(a, b) linked = self.wlan.linked(a, b)
logger.debug("checking range netif1(%s) netif2(%s): linked(%s) actual(%s) > config(%s)", logging.debug("checking range netif1(%s) netif2(%s): linked(%s) actual(%s) > config(%s)",
a.name, b.name, linked, d, self.range) a.name, b.name, linked, d, self.range)
if d > self.range: if d > self.range:
if linked: if linked:
logger.debug("was linked, unlinking") logging.debug("was linked, unlinking")
self.wlan.unlink(a, b) self.wlan.unlink(a, b)
self.sendlinkmsg(a, b, unlink=True) self.sendlinkmsg(a, b, unlink=True)
else: else:
if not linked: if not linked:
logger.debug("was not linked, linking") logging.debug("was not linked, linking")
self.wlan.link(a, b) self.wlan.link(a, b)
self.sendlinkmsg(a, b) self.sendlinkmsg(a, b)
except KeyError: except KeyError:
logger.exception("error getting interfaces during calclinkS") logging.exception("error getting interfaces during calclinkS")
@staticmethod @staticmethod
def calcdistance(p1, p2): def calcdistance(p1, p2):
@ -689,7 +689,7 @@ class WayPointMobility(WirelessModel):
:return: nothing :return: nothing
""" """
logger.info("running mobility scenario") logging.info("running mobility scenario")
self.timezero = time.time() self.timezero = time.time()
self.lasttime = self.timezero - (0.001 * self.refresh_ms) self.lasttime = self.timezero - (0.001 * self.refresh_ms)
self.movenodesinitial() self.movenodesinitial()
@ -947,7 +947,7 @@ class Ns2ScriptedMobility(WayPointMobility):
def update_config(self, config): def update_config(self, config):
self.file = config["file"] self.file = config["file"]
logger.info("ns-2 scripted mobility configured for WLAN %d using file: %s", self.object_id, self.file) logging.info("ns-2 scripted mobility configured for WLAN %d using file: %s", self.object_id, self.file)
self.refresh_ms = int(config["refresh_ms"]) self.refresh_ms = int(config["refresh_ms"])
self.loop = config["loop"].lower() == "on" self.loop = config["loop"].lower() == "on"
self.autostart = config["autostart"] self.autostart = config["autostart"]
@ -971,9 +971,9 @@ class Ns2ScriptedMobility(WayPointMobility):
try: try:
f = open(filename, "r") f = open(filename, "r")
except IOError: except IOError:
logger.exception("ns-2 scripted mobility failed to load file: %s", self.file) logging.exception("ns-2 scripted mobility failed to load file: %s", self.file)
return return
logger.info("reading ns-2 script file: %s" % filename) logging.info("reading ns-2 script file: %s" % filename)
ln = 0 ln = 0
ix = iy = iz = None ix = iy = iz = None
inodenum = None inodenum = None
@ -1017,7 +1017,7 @@ class Ns2ScriptedMobility(WayPointMobility):
else: else:
raise ValueError raise ValueError
except ValueError: except ValueError:
logger.exception("skipping line %d of file %s '%s'", ln, self.file, line) logging.exception("skipping line %d of file %s '%s'", ln, self.file, line)
continue continue
if ix is not None and iy is not None: if ix is not None and iy is not None:
self.addinitial(self.map(inodenum), ix, iy, iz) self.addinitial(self.map(inodenum), ix, iy, iz)
@ -1067,7 +1067,7 @@ class Ns2ScriptedMobility(WayPointMobility):
raise ValueError raise ValueError
self.nodemap[int(parts[0])] = int(parts[1]) self.nodemap[int(parts[0])] = int(parts[1])
except ValueError: except ValueError:
logger.exception("ns-2 mobility node map error") logging.exception("ns-2 mobility node map error")
def map(self, nodenum): def map(self, nodenum):
""" """
@ -1090,15 +1090,15 @@ class Ns2ScriptedMobility(WayPointMobility):
:return: nothing :return: nothing
""" """
if self.autostart == '': if self.autostart == '':
logger.info("not auto-starting ns-2 script for %s" % self.wlan.name) logging.info("not auto-starting ns-2 script for %s" % self.wlan.name)
return return
try: try:
t = float(self.autostart) t = float(self.autostart)
except ValueError: except ValueError:
logger.exception("Invalid auto-start seconds specified '%s' for %s", self.autostart, self.wlan.name) logging.exception("Invalid auto-start seconds specified '%s' for %s", self.autostart, self.wlan.name)
return return
self.movenodesinitial() self.movenodesinitial()
logger.info("scheduling ns-2 script for %s autostart at %s" % (self.wlan.name, t)) logging.info("scheduling ns-2 script for %s autostart at %s" % (self.wlan.name, t))
self.state = self.STATE_RUNNING self.state = self.STATE_RUNNING
self.session.event_loop.add_event(t, self.run) self.session.event_loop.add_event(t, self.run)
@ -1108,7 +1108,7 @@ class Ns2ScriptedMobility(WayPointMobility):
:return: nothing :return: nothing
""" """
logger.info("starting script") logging.info("starting script")
laststate = self.state laststate = self.state
super(Ns2ScriptedMobility, self).start() super(Ns2ScriptedMobility, self).start()
if laststate == self.STATE_PAUSED: if laststate == self.STATE_PAUSED:

View file

@ -3,6 +3,7 @@ Definition of LxcNode, CoreNode, and other node classes that inherit from the Co
implementing specific node types. implementing specific node types.
""" """
import logging
import socket import socket
import threading import threading
from socket import AF_INET from socket import AF_INET
@ -10,7 +11,6 @@ from socket import AF_INET6
from core import CoreCommandError from core import CoreCommandError
from core import constants from core import constants
from core import logger
from core.coreobj import PyCoreNetIf from core.coreobj import PyCoreNetIf
from core.coreobj import PyCoreNode from core.coreobj import PyCoreNode
from core.coreobj import PyCoreObj from core.coreobj import PyCoreObj
@ -80,15 +80,15 @@ class CtrlNet(LxBrNet):
else: else:
addr = self.prefix.max_addr() addr = self.prefix.max_addr()
logger.info("added control network bridge: %s %s", self.brname, self.prefix) logging.info("added control network bridge: %s %s", self.brname, self.prefix)
if self.assign_address: if self.assign_address:
addrlist = ["%s/%s" % (addr, self.prefix.prefixlen)] addrlist = ["%s/%s" % (addr, self.prefix.prefixlen)]
self.addrconfig(addrlist=addrlist) self.addrconfig(addrlist=addrlist)
logger.info("address %s", addr) logging.info("address %s", addr)
if self.updown_script: if self.updown_script:
logger.info("interface %s updown script (%s startup) called", self.brname, self.updown_script) logging.info("interface %s updown script (%s startup) called", self.brname, self.updown_script)
utils.check_cmd([self.updown_script, self.brname, "startup"]) utils.check_cmd([self.updown_script, self.brname, "startup"])
if self.serverintf: if self.serverintf:
@ -108,7 +108,7 @@ class CtrlNet(LxBrNet):
""" """
status, output = utils.cmd_output([constants.BRCTL_BIN, "show"]) status, output = utils.cmd_output([constants.BRCTL_BIN, "show"])
if status != 0: if status != 0:
logger.error("Unable to retrieve list of installed bridges") logging.error("Unable to retrieve list of installed bridges")
else: else:
lines = output.split("\n") lines = output.split("\n")
for line in lines[1:]: for line in lines[1:]:
@ -117,7 +117,7 @@ class CtrlNet(LxBrNet):
flds = cols[0].split(".") flds = cols[0].split(".")
if len(flds) == 3: if len(flds) == 3:
if flds[0] == "b" and flds[1] == self.objid: if flds[0] == "b" and flds[1] == self.objid:
logger.error( logging.error(
"error: An active control net bridge (%s) found. " "error: An active control net bridge (%s) found. "
"An older session might still be running. " "An older session might still be running. "
"Stop all sessions and, if needed, delete %s to continue.", oldbr, oldbr "Stop all sessions and, if needed, delete %s to continue.", oldbr, oldbr
@ -135,14 +135,14 @@ class CtrlNet(LxBrNet):
try: try:
utils.check_cmd([constants.BRCTL_BIN, "delif", self.brname, self.serverintf]) utils.check_cmd([constants.BRCTL_BIN, "delif", self.brname, self.serverintf])
except CoreCommandError: except CoreCommandError:
logger.exception("error deleting server interface %s from bridge %s", self.serverintf, self.brname) logging.exception("error deleting server interface %s from bridge %s", self.serverintf, self.brname)
if self.updown_script is not None: if self.updown_script is not None:
try: try:
logger.info("interface %s updown script (%s shutdown) called", self.brname, self.updown_script) logging.info("interface %s updown script (%s shutdown) called", self.brname, self.updown_script)
utils.check_cmd([self.updown_script, self.brname, "shutdown"]) utils.check_cmd([self.updown_script, self.brname, "shutdown"])
except CoreCommandError: except CoreCommandError:
logger.exception("error issuing shutdown script shutdown") logging.exception("error issuing shutdown script shutdown")
LxBrNet.shutdown(self) LxBrNet.shutdown(self)
@ -383,7 +383,7 @@ class WlanNode(LxBrNet):
:param dict config: configuration for model being set :param dict config: configuration for model being set
:return: nothing :return: nothing
""" """
logger.info("adding model: %s", model.name) logging.info("adding model: %s", model.name)
if model.config_type == RegisterTlvs.WIRELESS.value: if model.config_type == RegisterTlvs.WIRELESS.value:
self.model = model(session=self.session, object_id=self.objid) self.model = model(session=self.session, object_id=self.objid)
self.model.update_config(config) self.model.update_config(config)
@ -406,7 +406,7 @@ class WlanNode(LxBrNet):
def updatemodel(self, config): def updatemodel(self, config):
if not self.model: if not self.model:
raise ValueError("no model set to update for node(%s)", self.objid) raise ValueError("no model set to update for node(%s)", self.objid)
logger.info("node(%s) updating model(%s): %s", self.objid, self.model.name, config) logging.info("node(%s) updating model(%s): %s", self.objid, self.model.name, config)
self.model.set_configs(config, node_id=self.objid) self.model.set_configs(config, node_id=self.objid)
if self.model.position_callback: if self.model.position_callback:
for netif in self.netifs(): for netif in self.netifs():
@ -492,7 +492,7 @@ class RJ45Node(PyCoreNode, PyCoreNetIf):
utils.check_cmd([constants.IP_BIN, "addr", "flush", "dev", self.localname]) utils.check_cmd([constants.IP_BIN, "addr", "flush", "dev", self.localname])
utils.check_cmd([constants.TC_BIN, "qdisc", "del", "dev", self.localname, "root"]) utils.check_cmd([constants.TC_BIN, "qdisc", "del", "dev", self.localname, "root"])
except CoreCommandError: except CoreCommandError:
logger.exception("error shutting down") logging.exception("error shutting down")
self.up = False self.up = False
self.restorestate() self.restorestate()

View file

@ -2,6 +2,7 @@
TODO: probably goes away, or implement the usage of "unshare", or docker formal. TODO: probably goes away, or implement the usage of "unshare", or docker formal.
""" """
import logging
import socket import socket
import threading import threading
from socket import AF_INET from socket import AF_INET
@ -9,7 +10,6 @@ from socket import AF_INET6
from core import CoreCommandError from core import CoreCommandError
from core import constants from core import constants
from core import logger
from core.coreobj import PyCoreNet from core.coreobj import PyCoreNet
from core.data import LinkData from core.data import LinkData
from core.enumerations import LinkTypes from core.enumerations import LinkTypes
@ -100,7 +100,7 @@ class OvsNet(PyCoreNet):
def shutdown(self): def shutdown(self):
if not self.up: if not self.up:
logger.info("exiting shutdown, object is not up") logging.info("exiting shutdown, object is not up")
return return
ebtables_queue.stopupdateloop(self) ebtables_queue.stopupdateloop(self)
@ -113,7 +113,7 @@ class OvsNet(PyCoreNet):
[constants.EBTABLES_BIN, "-X", self.bridge_name] [constants.EBTABLES_BIN, "-X", self.bridge_name]
]) ])
except CoreCommandError: except CoreCommandError:
logger.exception("error bringing bridge down and removing it") logging.exception("error bringing bridge down and removing it")
# removes veth pairs used for bridge-to-bridge connections # removes veth pairs used for bridge-to-bridge connections
for interface in self.netifs(): for interface in self.netifs():
@ -206,7 +206,7 @@ class OvsNet(PyCoreNet):
burst = max(2 * netif.mtu, bw / 1000) burst = max(2 * netif.mtu, bw / 1000)
limit = 0xffff # max IP payload limit = 0xffff # max IP payload
tbf = ["tbf", "rate", str(bw), "burst", str(burst), "limit", str(limit)] tbf = ["tbf", "rate", str(bw), "burst", str(burst), "limit", str(limit)]
logger.info("linkconfig: %s" % [tc + parent + ["handle", "1:"] + tbf]) logging.info("linkconfig: %s" % [tc + parent + ["handle", "1:"] + tbf])
utils.check_cmd(tc + parent + ["handle", "1:"] + tbf) utils.check_cmd(tc + parent + ["handle", "1:"] + tbf)
netif.setparam("has_tbf", True) netif.setparam("has_tbf", True)
elif netif.getparam("has_tbf") and bw <= 0: elif netif.getparam("has_tbf") and bw <= 0:
@ -262,12 +262,12 @@ class OvsNet(PyCoreNet):
tc[2] = "delete" tc[2] = "delete"
if self.up: if self.up:
logger.info("linkconfig: %s" % ([tc + parent + ["handle", "10:"]],)) logging.info("linkconfig: %s" % ([tc + parent + ["handle", "10:"]],))
utils.check_cmd(tc + parent + ["handle", "10:"]) utils.check_cmd(tc + parent + ["handle", "10:"])
netif.setparam("has_netem", False) netif.setparam("has_netem", False)
elif len(netem) > 1: elif len(netem) > 1:
if self.up: if self.up:
logger.info("linkconfig: %s" % ([tc + parent + ["handle", "10:"] + netem],)) logging.info("linkconfig: %s" % ([tc + parent + ["handle", "10:"] + netem],))
utils.check_cmd(tc + parent + ["handle", "10:"] + netem) utils.check_cmd(tc + parent + ["handle", "10:"] + netem)
netif.setparam("has_netem", True) netif.setparam("has_netem", True)
@ -373,10 +373,10 @@ class OvsCtrlNet(OvsNet):
if self.assign_address: if self.assign_address:
self.addrconfig(addresses=addresses) self.addrconfig(addresses=addresses)
message += " address %s" % addr message += " address %s" % addr
logger.info(message) logging.info(message)
if self.updown_script: if self.updown_script:
logger.info("interface %s updown script %s startup called" % (self.bridge_name, self.updown_script)) logging.info("interface %s updown script %s startup called" % (self.bridge_name, self.updown_script))
utils.check_cmd([self.updown_script, self.bridge_name, "startup"]) utils.check_cmd([self.updown_script, self.bridge_name, "startup"])
if self.serverintf: if self.serverintf:
@ -395,7 +395,7 @@ class OvsCtrlNet(OvsNet):
for line in output.split("\n"): for line in output.split("\n"):
bride_name = line.split(".") bride_name = line.split(".")
if bride_name[0] == "b" and bride_name[1] == self.objid: if bride_name[0] == "b" and bride_name[1] == self.objid:
logger.error("older session may still be running with conflicting id for bridge: %s", line) logging.error("older session may still be running with conflicting id for bridge: %s", line)
return True return True
return False return False
@ -405,15 +405,15 @@ class OvsCtrlNet(OvsNet):
try: try:
utils.check_cmd([constants.OVS_BIN, "del-port", self.bridge_name, self.serverintf]) utils.check_cmd([constants.OVS_BIN, "del-port", self.bridge_name, self.serverintf])
except CoreCommandError: except CoreCommandError:
logger.exception("error deleting server interface %s to controlnet bridge %s", logging.exception("error deleting server interface %s to controlnet bridge %s",
self.serverintf, self.bridge_name) self.serverintf, self.bridge_name)
if self.updown_script: if self.updown_script:
try: try:
logger.info("interface %s updown script (%s shutdown) called", self.bridge_name, self.updown_script) logging.info("interface %s updown script (%s shutdown) called", self.bridge_name, self.updown_script)
utils.check_cmd([self.updown_script, self.bridge_name, "shutdown"]) utils.check_cmd([self.updown_script, self.bridge_name, "shutdown"])
except CoreCommandError: except CoreCommandError:
logger.exception("error during updown script shutdown") logging.exception("error during updown script shutdown")
OvsNet.shutdown(self) OvsNet.shutdown(self)
@ -595,7 +595,7 @@ class OvsWlanNode(OvsNet):
""" """
Mobility and wireless model. Mobility and wireless model.
""" """
logger.info("adding model %s", model.name) logging.info("adding model %s", model.name)
if model.type == RegisterTlvs.WIRELESS.value: if model.type == RegisterTlvs.WIRELESS.value:
self.model = model(session=self.session, object_id=self.objid, config=config) self.model = model(session=self.session, object_id=self.objid, config=config)
@ -612,7 +612,7 @@ class OvsWlanNode(OvsNet):
def updatemodel(self, config): def updatemodel(self, config):
if not self.model: if not self.model:
raise ValueError("no model set to update for node(%s)", self.objid) raise ValueError("no model set to update for node(%s)", self.objid)
logger.info("node(%s) updating model(%s): %s", self.objid, self.model.name, config) logging.info("node(%s) updating model(%s): %s", self.objid, self.model.name, config)
self.model.set_configs(config, node_id=self.objid) self.model.set_configs(config, node_id=self.objid)
if self.model.position_callback: if self.model.position_callback:
for netif in self.netifs(): for netif in self.netifs():

View file

@ -2,11 +2,11 @@
virtual ethernet classes that implement the interfaces available under Linux. virtual ethernet classes that implement the interfaces available under Linux.
""" """
import logging
import time import time
from core import CoreCommandError from core import CoreCommandError
from core import constants from core import constants
from core import logger
from core.coreobj import PyCoreNetIf from core.coreobj import PyCoreNetIf
from core.enumerations import NodeTypes from core.enumerations import NodeTypes
from core.misc import nodeutils from core.misc import nodeutils
@ -65,13 +65,13 @@ class VEth(PyCoreNetIf):
try: try:
self.node.check_cmd([constants.IP_BIN, "-6", "addr", "flush", "dev", self.name]) self.node.check_cmd([constants.IP_BIN, "-6", "addr", "flush", "dev", self.name])
except CoreCommandError: except CoreCommandError:
logger.exception("error shutting down interface") logging.exception("error shutting down interface")
if self.localname: if self.localname:
try: try:
utils.check_cmd([constants.IP_BIN, "link", "delete", self.localname]) utils.check_cmd([constants.IP_BIN, "link", "delete", self.localname])
except CoreCommandError: except CoreCommandError:
logger.exception("error deleting link") logging.exception("error deleting link")
self.up = False self.up = False
@ -126,7 +126,7 @@ class TunTap(PyCoreNetIf):
try: try:
self.node.check_cmd([constants.IP_BIN, "-6", "addr", "flush", "dev", self.name]) self.node.check_cmd([constants.IP_BIN, "-6", "addr", "flush", "dev", self.name])
except CoreCommandError: except CoreCommandError:
logger.exception("error shutting down tunnel tap") logging.exception("error shutting down tunnel tap")
self.up = False self.up = False
@ -150,14 +150,14 @@ class TunTap(PyCoreNetIf):
msg = "attempt %s failed with nonzero exit status %s" % (i, r) msg = "attempt %s failed with nonzero exit status %s" % (i, r)
if i < attempts + 1: if i < attempts + 1:
msg += ", retrying..." msg += ", retrying..."
logger.info(msg) logging.info(msg)
time.sleep(delay) time.sleep(delay)
delay += delay delay += delay
if delay > maxretrydelay: if delay > maxretrydelay:
delay = maxretrydelay delay = maxretrydelay
else: else:
msg += ", giving up" msg += ", giving up"
logger.info(msg) logging.info(msg)
return result return result
@ -169,7 +169,7 @@ class TunTap(PyCoreNetIf):
:return: wait for device local response :return: wait for device local response
:rtype: int :rtype: int
""" """
logger.debug("waiting for device local: %s", self.localname) logging.debug("waiting for device local: %s", self.localname)
def localdevexists(): def localdevexists():
args = [constants.IP_BIN, "link", "show", self.localname] args = [constants.IP_BIN, "link", "show", self.localname]
@ -183,7 +183,7 @@ class TunTap(PyCoreNetIf):
:return: nothing :return: nothing
""" """
logger.debug("waiting for device node: %s", self.name) logging.debug("waiting for device node: %s", self.name)
def nodedevexists(): def nodedevexists():
args = [constants.IP_BIN, "link", "show", self.name] args = [constants.IP_BIN, "link", "show", self.name]
@ -300,7 +300,7 @@ class GreTap(PyCoreNetIf):
args = [constants.IP_BIN, "link", "del", self.localname] args = [constants.IP_BIN, "link", "del", self.localname]
utils.check_cmd(args) utils.check_cmd(args)
except CoreCommandError: except CoreCommandError:
logger.exception("error during shutdown") logging.exception("error during shutdown")
self.localname = None self.localname = None

View file

@ -3,13 +3,13 @@ PyCoreNet and LxBrNet classes that implement virtual networks using
Linux Ethernet bridging and ebtables rules. Linux Ethernet bridging and ebtables rules.
""" """
import logging
import os import os
import threading import threading
import time import time
from core import CoreCommandError from core import CoreCommandError
from core import constants from core import constants
from core import logger
from core.coreobj import PyCoreNet from core.coreobj import PyCoreNet
from core.misc import utils from core.misc import utils
from core.netns.vif import GreTap from core.netns.vif import GreTap
@ -80,7 +80,7 @@ class EbtablesQueue(object):
try: try:
del self.last_update_time[wlan] del self.last_update_time[wlan]
except KeyError: except KeyError:
logger.exception("error deleting last update time for wlan, ignored before: %s", wlan) logging.exception("error deleting last update time for wlan, ignored before: %s", wlan)
if len(self.last_update_time) > 0: if len(self.last_update_time) > 0:
return return
@ -181,7 +181,7 @@ class EbtablesQueue(object):
try: try:
os.unlink(self.atomic_file) os.unlink(self.atomic_file)
except OSError: except OSError:
logger.exception("error removing atomic file: %s", self.atomic_file) logging.exception("error removing atomic file: %s", self.atomic_file)
def ebchange(self, wlan): def ebchange(self, wlan):
""" """
@ -310,7 +310,7 @@ class LxBrNet(PyCoreNet):
[constants.EBTABLES_BIN, "-X", self.brname] [constants.EBTABLES_BIN, "-X", self.brname]
]) ])
except CoreCommandError: except CoreCommandError:
logger.exception("error during shutdown") logging.exception("error during shutdown")
# removes veth pairs used for bridge-to-bridge connections # removes veth pairs used for bridge-to-bridge connections
for netif in self.netifs(): for netif in self.netifs():
@ -438,7 +438,7 @@ class LxBrNet(PyCoreNet):
"burst", str(burst), "limit", str(limit)] "burst", str(burst), "limit", str(limit)]
if bw > 0: if bw > 0:
if self.up: if self.up:
logger.debug("linkconfig: %s" % ([tc + parent + ["handle", "1:"] + tbf],)) logging.debug("linkconfig: %s" % ([tc + parent + ["handle", "1:"] + tbf],))
utils.check_cmd(tc + parent + ["handle", "1:"] + tbf) utils.check_cmd(tc + parent + ["handle", "1:"] + tbf)
netif.setparam("has_tbf", True) netif.setparam("has_tbf", True)
changed = True changed = True
@ -483,12 +483,12 @@ class LxBrNet(PyCoreNet):
return return
tc[2] = "delete" tc[2] = "delete"
if self.up: if self.up:
logger.debug("linkconfig: %s" % ([tc + parent + ["handle", "10:"]],)) logging.debug("linkconfig: %s" % ([tc + parent + ["handle", "10:"]],))
utils.check_cmd(tc + parent + ["handle", "10:"]) utils.check_cmd(tc + parent + ["handle", "10:"])
netif.setparam("has_netem", False) netif.setparam("has_netem", False)
elif len(netem) > 1: elif len(netem) > 1:
if self.up: if self.up:
logger.debug("linkconfig: %s" % ([tc + parent + ["handle", "10:"] + netem],)) logging.debug("linkconfig: %s" % ([tc + parent + ["handle", "10:"] + netem],))
utils.check_cmd(tc + parent + ["handle", "10:"] + netem) utils.check_cmd(tc + parent + ["handle", "10:"] + netem)
netif.setparam("has_netem", True) netif.setparam("has_netem", True)

View file

@ -3,6 +3,7 @@ PyCoreNode and LxcNode classes that implement the network namespac virtual node.
""" """
import errno import errno
import logging
import os import os
import random import random
import shutil import shutil
@ -12,7 +13,6 @@ import threading
from core import CoreCommandError from core import CoreCommandError
from core import constants from core import constants
from core import logger
from core.coreobj import PyCoreNetIf from core.coreobj import PyCoreNetIf
from core.coreobj import PyCoreNode from core.coreobj import PyCoreNode
from core.enumerations import NodeTypes from core.enumerations import NodeTypes
@ -107,11 +107,11 @@ class SimpleLxcNode(PyCoreNode):
self.client = vnodeclient.VnodeClient(self.name, self.ctrlchnlname) self.client = vnodeclient.VnodeClient(self.name, self.ctrlchnlname)
# bring up the loopback interface # bring up the loopback interface
logger.debug("bringing up loopback interface") logging.debug("bringing up loopback interface")
self.check_cmd([constants.IP_BIN, "link", "set", "lo", "up"]) self.check_cmd([constants.IP_BIN, "link", "set", "lo", "up"])
# set hostname for node # set hostname for node
logger.debug("setting hostname: %s", self.name) logging.debug("setting hostname: %s", self.name)
self.check_cmd(["hostname", self.name]) self.check_cmd(["hostname", self.name])
# mark node as up # mark node as up
@ -141,7 +141,7 @@ class SimpleLxcNode(PyCoreNode):
os.waitpid(self.pid, 0) os.waitpid(self.pid, 0)
except OSError as e: except OSError as e:
if e.errno != 10: if e.errno != 10:
logger.exception("error killing process") logging.exception("error killing process")
# remove node directory if present # remove node directory if present
try: try:
@ -149,7 +149,7 @@ class SimpleLxcNode(PyCoreNode):
except OSError as e: except OSError as e:
# no such file or directory # no such file or directory
if e.errno != errno.ENOENT: if e.errno != errno.ENOENT:
logger.exception("error removing node directory") logging.exception("error removing node directory")
# clear interface data, close client, and mark self and not up # clear interface data, close client, and mark self and not up
self._netif.clear() self._netif.clear()
@ -207,7 +207,7 @@ class SimpleLxcNode(PyCoreNode):
:raises CoreCommandError: when a non-zero exit status occurs :raises CoreCommandError: when a non-zero exit status occurs
""" """
source = os.path.abspath(source) source = os.path.abspath(source)
logger.info("node(%s) mounting: %s at %s", self.name, source, target) logging.info("node(%s) mounting: %s at %s", self.name, source, target)
cmd = 'mkdir -p "%s" && %s -n --bind "%s" "%s"' % (target, constants.MOUNT_BIN, source, target) cmd = 'mkdir -p "%s" && %s -n --bind "%s" "%s"' % (target, constants.MOUNT_BIN, source, target)
status, output = self.client.shcmd_result(cmd) status, output = self.client.shcmd_result(cmd)
if status: if status:
@ -267,12 +267,12 @@ class SimpleLxcNode(PyCoreNode):
# TODO: potentially find better way to query interface ID # TODO: potentially find better way to query interface ID
# retrieve interface information # retrieve interface information
output = self.check_cmd(["ip", "link", "show", veth.name]) output = self.check_cmd(["ip", "link", "show", veth.name])
logger.debug("interface command output: %s", output) logging.debug("interface command output: %s", output)
output = output.split("\n") output = output.split("\n")
veth.flow_id = int(output[0].strip().split(":")[0]) + 1 veth.flow_id = int(output[0].strip().split(":")[0]) + 1
logger.debug("interface flow index: %s - %s", veth.name, veth.flow_id) logging.debug("interface flow index: %s - %s", veth.name, veth.flow_id)
veth.hwaddr = MacAddress.from_string(output[1].strip().split()[1]) veth.hwaddr = MacAddress.from_string(output[1].strip().split()[1])
logger.debug("interface mac: %s - %s", veth.name, veth.hwaddr) logging.debug("interface mac: %s - %s", veth.name, veth.hwaddr)
try: try:
self.addnetif(veth, ifindex) self.addnetif(veth, ifindex)
@ -359,7 +359,7 @@ class SimpleLxcNode(PyCoreNode):
try: try:
self._netif[ifindex].deladdr(addr) self._netif[ifindex].deladdr(addr)
except ValueError: except ValueError:
logger.exception("trying to delete unknown address: %s" % addr) logging.exception("trying to delete unknown address: %s" % addr)
if self.up: if self.up:
self.check_cmd([constants.IP_BIN, "addr", "del", str(addr), "dev", self.ifname(ifindex)]) self.check_cmd([constants.IP_BIN, "addr", "del", str(addr), "dev", self.ifname(ifindex)])
@ -475,7 +475,7 @@ class SimpleLxcNode(PyCoreNode):
:return: nothing :return: nothing
:raises CoreCommandError: when a non-zero exit status occurs :raises CoreCommandError: when a non-zero exit status occurs
""" """
logger.info("adding file from %s to %s", srcname, filename) logging.info("adding file from %s to %s", srcname, filename)
directory = os.path.dirname(filename) directory = os.path.dirname(filename)
cmd = 'mkdir -p "%s" && mv "%s" "%s" && sync' % (directory, srcname, filename) cmd = 'mkdir -p "%s" && mv "%s" "%s" && sync' % (directory, srcname, filename)
@ -530,7 +530,7 @@ class LxcNode(SimpleLxcNode):
try: try:
super(LxcNode, self).shutdown() super(LxcNode, self).shutdown()
except OSError: except OSError:
logger.exception("error during shutdown") logging.exception("error during shutdown")
finally: finally:
self.rmnodedir() self.rmnodedir()
@ -590,7 +590,7 @@ class LxcNode(SimpleLxcNode):
with self.opennodefile(filename, "w") as open_file: with self.opennodefile(filename, "w") as open_file:
open_file.write(contents) open_file.write(contents)
os.chmod(open_file.name, mode) os.chmod(open_file.name, mode)
logger.info("node(%s) added file: %s; mode: 0%o", self.name, open_file.name, mode) logging.info("node(%s) added file: %s; mode: 0%o", self.name, open_file.name, mode)
def nodefilecopy(self, filename, srcfilename, mode=None): def nodefilecopy(self, filename, srcfilename, mode=None):
""" """
@ -606,4 +606,4 @@ class LxcNode(SimpleLxcNode):
shutil.copy2(srcfilename, hostfilename) shutil.copy2(srcfilename, hostfilename)
if mode is not None: if mode is not None:
os.chmod(hostfilename, mode) os.chmod(hostfilename, mode)
logger.info("node(%s) copied file: %s; mode: %s", self.name, hostfilename, mode) logging.info("node(%s) copied file: %s; mode: %s", self.name, hostfilename, mode)

View file

@ -5,13 +5,13 @@ The control channel can be accessed via calls to the vcmd Python module or
by invoking the vcmd shell command. by invoking the vcmd shell command.
""" """
import logging
import os import os
import vcmd import vcmd
from core import CoreCommandError from core import CoreCommandError
from core import constants from core import constants
from core import logger
from core.misc import utils from core.misc import utils
@ -158,7 +158,7 @@ class VnodeClient(object):
# wait for and return exit status # wait for and return exit status
status = p.wait() status = p.wait()
if status: if status:
logger.warn("cmd exited with status %s: %s", status, args) logging.warn("cmd exited with status %s: %s", status, args)
return status return status
def term(self, sh="/bin/sh"): def term(self, sh="/bin/sh"):
@ -236,16 +236,16 @@ class VnodeClient(object):
elif line[3] == "link": elif line[3] == "link":
interface["inet6link"].append(line[1]) interface["inet6link"].append(line[1])
else: else:
logger.warn("unknown scope: %s" % line[3]) logging.warn("unknown scope: %s" % line[3])
err = stderr.read() err = stderr.read()
stdout.close() stdout.close()
stderr.close() stderr.close()
status = p.wait() status = p.wait()
if status: if status:
logger.warn("nonzero exist status (%s) for cmd: %s", status, args) logging.warn("nonzero exist status (%s) for cmd: %s", status, args)
if err: if err:
logger.warn("error output: %s", err) logging.warn("error output: %s", err)
self._addr[ifname] = interface self._addr[ifname] = interface
return interface return interface
@ -285,9 +285,9 @@ class VnodeClient(object):
stderr.close() stderr.close()
status = p.wait() status = p.wait()
if status: if status:
logger.warn("nonzero exist status (%s) for cmd: %s", status, args) logging.warn("nonzero exist status (%s) for cmd: %s", status, args)
if err: if err:
logger.warn("error output: %s", err) logging.warn("error output: %s", err)
if ifname is not None: if ifname is not None:
return stats[ifname] return stats[ifname]
else: else:

View file

@ -2,13 +2,13 @@
PhysicalNode class for including real systems in the emulated network. PhysicalNode class for including real systems in the emulated network.
""" """
import logging
import os import os
import subprocess import subprocess
import threading import threading
from core import CoreCommandError from core import CoreCommandError
from core import constants from core import constants
from core import logger
from core.coreobj import PyCoreNode from core.coreobj import PyCoreNode
from core.misc import utils from core.misc import utils
from core.netns.vnet import GreTap from core.netns.vnet import GreTap
@ -121,7 +121,7 @@ class PhysicalNode(PyCoreNode):
try: try:
self._netif[ifindex].deladdr(addr) self._netif[ifindex].deladdr(addr)
except ValueError: except ValueError:
logger.exception("trying to delete unknown address: %s", addr) logging.exception("trying to delete unknown address: %s", addr)
if self.up: if self.up:
self.check_cmd([constants.IP_BIN, "addr", "del", str(addr), "dev", self.ifname(ifindex)]) self.check_cmd([constants.IP_BIN, "addr", "del", str(addr), "dev", self.ifname(ifindex)])
@ -172,7 +172,7 @@ class PhysicalNode(PyCoreNode):
return ifindex return ifindex
def newnetif(self, net=None, addrlist=None, hwaddr=None, ifindex=None, ifname=None): def newnetif(self, net=None, addrlist=None, hwaddr=None, ifindex=None, ifname=None):
logger.info("creating interface") logging.info("creating interface")
if not addrlist: if not addrlist:
addrlist = [] addrlist = []
@ -210,17 +210,17 @@ class PhysicalNode(PyCoreNode):
def mount(self, source, target): def mount(self, source, target):
source = os.path.abspath(source) source = os.path.abspath(source)
logger.info("mounting %s at %s", source, target) logging.info("mounting %s at %s", source, target)
os.makedirs(target) os.makedirs(target)
self.check_cmd([constants.MOUNT_BIN, "--bind", source, target]) self.check_cmd([constants.MOUNT_BIN, "--bind", source, target])
self._mounts.append((source, target)) self._mounts.append((source, target))
def umount(self, target): def umount(self, target):
logger.info("unmounting '%s'" % target) logging.info("unmounting '%s'" % target)
try: try:
self.check_cmd([constants.UMOUNT_BIN, "-l", target]) self.check_cmd([constants.UMOUNT_BIN, "-l", target])
except CoreCommandError: except CoreCommandError:
logger.exception("unmounting failed for %s", target) logging.exception("unmounting failed for %s", target)
def opennodefile(self, filename, mode="w"): def opennodefile(self, filename, mode="w"):
dirname, basename = os.path.split(filename) dirname, basename = os.path.split(filename)
@ -242,4 +242,4 @@ class PhysicalNode(PyCoreNode):
with self.opennodefile(filename, "w") as node_file: with self.opennodefile(filename, "w") as node_file:
node_file.write(contents) node_file.write(contents)
os.chmod(node_file.name, mode) os.chmod(node_file.name, mode)
logger.info("created nodefile: '%s'; mode: 0%o", node_file.name, mode) logging.info("created nodefile: '%s'; mode: 0%o", node_file.name, mode)

View file

@ -2,11 +2,11 @@
sdt.py: Scripted Display Tool (SDT3D) helper sdt.py: Scripted Display Tool (SDT3D) helper
""" """
import logging
import socket import socket
from urlparse import urlparse from urlparse import urlparse
from core import constants from core import constants
from core import logger
from core.coreobj import PyCoreNet from core.coreobj import PyCoreNet
from core.coreobj import PyCoreObj from core.coreobj import PyCoreObj
from core.enumerations import EventTypes from core.enumerations import EventTypes
@ -149,7 +149,7 @@ class Sdt(object):
return False return False
self.seturl() self.seturl()
logger.info("connecting to SDT at %s://%s" % (self.protocol, self.address)) logging.info("connecting to SDT at %s://%s" % (self.protocol, self.address))
if self.sock is None: if self.sock is None:
try: try:
if self.protocol.lower() == "udp": if self.protocol.lower() == "udp":
@ -159,7 +159,7 @@ class Sdt(object):
# Default to tcp # Default to tcp
self.sock = socket.create_connection(self.address, 5) self.sock = socket.create_connection(self.address, 5)
except IOError: except IOError:
logger.exception("SDT socket connect error") logging.exception("SDT socket connect error")
return False return False
if not self.initialize(): if not self.initialize():
@ -199,7 +199,7 @@ class Sdt(object):
try: try:
self.sock.close() self.sock.close()
except IOError: except IOError:
logger.error("error closing socket") logging.error("error closing socket")
finally: finally:
self.sock = None self.sock = None
@ -211,7 +211,7 @@ class Sdt(object):
:return: nothing :return: nothing
""" """
logger.info("SDT shutdown!") logging.info("SDT shutdown!")
self.cmd("clear all") self.cmd("clear all")
self.disconnect() self.disconnect()
self.showerror = True self.showerror = True
@ -229,11 +229,11 @@ class Sdt(object):
if self.sock is None: if self.sock is None:
return False return False
try: try:
logger.info("sdt: %s" % cmdstr) logging.info("sdt: %s" % cmdstr)
self.sock.sendall("%s\n" % cmdstr) self.sock.sendall("%s\n" % cmdstr)
return True return True
except IOError: except IOError:
logger.exception("SDT connection error") logging.exception("SDT connection error")
self.sock = None self.sock = None
self.connected = False self.connected = False
return False return False

View file

@ -7,6 +7,7 @@ a list of available services to the GUI and for configuring individual
services. services.
""" """
import logging
import time import time
from multiprocessing.pool import ThreadPool from multiprocessing.pool import ThreadPool
@ -14,7 +15,6 @@ import enum
from core.constants import which from core.constants import which
from core import CoreCommandError from core import CoreCommandError
from core import logger
from core.data import FileData from core.data import FileData
from core.enumerations import MessageFlags from core.enumerations import MessageFlags
from core.enumerations import RegisterTlvs from core.enumerations import RegisterTlvs
@ -63,7 +63,7 @@ class ServiceDependencies(object):
paths = [] paths = []
for service in self.node_services.itervalues(): for service in self.node_services.itervalues():
if service.name in self.booted: if service.name in self.booted:
logger.debug("skipping service that will already be booted: %s", service.name) logging.debug("skipping service that will already be booted: %s", service.name)
continue continue
path = self._start(service) path = self._start(service)
@ -81,12 +81,12 @@ class ServiceDependencies(object):
self.visiting.clear() self.visiting.clear()
def _start(self, service): def _start(self, service):
logger.debug("starting service dependency check: %s", service.name) logging.debug("starting service dependency check: %s", service.name)
self._reset() self._reset()
return self._visit(service) return self._visit(service)
def _visit(self, current_service): def _visit(self, current_service):
logger.debug("visiting service(%s): %s", current_service.name, self.path) logging.debug("visiting service(%s): %s", current_service.name, self.path)
self.visited.add(current_service.name) self.visited.add(current_service.name)
self.visiting.add(current_service.name) self.visiting.add(current_service.name)
@ -103,7 +103,7 @@ class ServiceDependencies(object):
self._visit(service) self._visit(service)
# add service when bottom is found # add service when bottom is found
logger.debug("adding service to boot path: %s", current_service.name) logging.debug("adding service to boot path: %s", current_service.name)
self.booted.add(current_service.name) self.booted.add(current_service.name)
self.path.append(current_service) self.path.append(current_service)
self.visiting.remove(current_service.name) self.visiting.remove(current_service.name)
@ -157,7 +157,7 @@ class ServiceShim(object):
cls.setvalue(service, key, values[cls.keys.index(key)]) cls.setvalue(service, key, values[cls.keys.index(key)])
except IndexError: except IndexError:
# old config does not need to have new keys # old config does not need to have new keys
logger.exception("error indexing into key") logging.exception("error indexing into key")
@classmethod @classmethod
def setvalue(cls, service, key, value): def setvalue(cls, service, key, value):
@ -223,7 +223,7 @@ class ServiceManager(object):
:return: nothing :return: nothing
""" """
name = service.name name = service.name
logger.debug("loading service: class(%s) name(%s)", service.__name__, name) logging.debug("loading service: class(%s) name(%s)", service.__name__, name)
# avoid duplicate services # avoid duplicate services
if name in cls.services: if name in cls.services:
@ -232,7 +232,7 @@ class ServiceManager(object):
# validate dependent executables are present # validate dependent executables are present
for executable in service.executables: for executable in service.executables:
if not which(executable): if not which(executable):
logger.debug("service(%s) missing executable: %s", service.name, executable) logging.debug("service(%s) missing executable: %s", service.name, executable)
raise ValueError("service(%s) missing executable: %s" % (service.name, executable)) raise ValueError("service(%s) missing executable: %s" % (service.name, executable))
# make service available # make service available
@ -269,7 +269,7 @@ class ServiceManager(object):
cls.add(service) cls.add(service)
except ValueError as e: except ValueError as e:
service_errors.append(service.name) service_errors.append(service.name)
logger.debug("not loading service: %s", e) logging.debug("not loading service: %s", e)
return service_errors return service_errors
@ -311,14 +311,14 @@ class CoreServices(object):
:return: default services :return: default services
:rtype: list[CoreService] :rtype: list[CoreService]
""" """
logger.debug("getting default services for type: %s", node_type) logging.debug("getting default services for type: %s", node_type)
results = [] results = []
defaults = self.default_services.get(node_type, []) defaults = self.default_services.get(node_type, [])
for name in defaults: for name in defaults:
logger.debug("checking for service with service manager: %s", name) logging.debug("checking for service with service manager: %s", name)
service = ServiceManager.get(name) service = ServiceManager.get(name)
if not service: if not service:
logger.warn("default service %s is unknown", name) logging.warn("default service %s is unknown", name)
else: else:
results.append(service) results.append(service)
return results return results
@ -349,7 +349,7 @@ class CoreServices(object):
:param str service_name: name of service to set :param str service_name: name of service to set
:return: nothing :return: nothing
""" """
logger.debug("setting custom service(%s) for node: %s", service_name, node_id) logging.debug("setting custom service(%s) for node: %s", service_name, node_id)
service = self.get_service(node_id, service_name) service = self.get_service(node_id, service_name)
if not service: if not service:
service_class = ServiceManager.get(service_name) service_class = ServiceManager.get(service_name)
@ -369,16 +369,16 @@ class CoreServices(object):
:return: nothing :return: nothing
""" """
if not services: if not services:
logger.info("using default services for node(%s) type(%s)", node.name, node_type) logging.info("using default services for node(%s) type(%s)", node.name, node_type)
services = self.default_services.get(node_type, []) services = self.default_services.get(node_type, [])
logger.info("setting services for node(%s): %s", node.name, services) logging.info("setting services for node(%s): %s", node.name, services)
for service_name in services: for service_name in services:
service = self.get_service(node.objid, service_name, default_service=True) service = self.get_service(node.objid, service_name, default_service=True)
if not service: if not service:
logger.warn("unknown service(%s) for node(%s)", service_name, node.name) logging.warn("unknown service(%s) for node(%s)", service_name, node.name)
continue continue
logger.info("adding service to node(%s): %s", node.name, service_name) logging.info("adding service to node(%s): %s", node.name, service_name)
node.addservice(service) node.addservice(service)
def all_configs(self): def all_configs(self):
@ -444,12 +444,12 @@ class CoreServices(object):
:param list[CoreService] boot_path: service to start in dependent order :param list[CoreService] boot_path: service to start in dependent order
:return: nothing :return: nothing
""" """
logger.info("booting node services: %s", " -> ".join([x.name for x in boot_path])) logging.info("booting node services: %s", " -> ".join([x.name for x in boot_path]))
for service in boot_path: for service in boot_path:
try: try:
self.boot_service(node, service) self.boot_service(node, service)
except: except:
logger.exception("exception booting service: %s", service.name) logging.exception("exception booting service: %s", service.name)
raise raise
def boot_service(self, node, service): def boot_service(self, node, service):
@ -461,7 +461,7 @@ class CoreServices(object):
:param CoreService service: service to start :param CoreService service: service to start
:return: nothing :return: nothing
""" """
logger.info("starting node(%s) service(%s) validation(%s)", node.name, service.name, logging.info("starting node(%s) service(%s) validation(%s)", node.name, service.name,
service.validation_mode.name) service.validation_mode.name)
# create service directories # create service directories
@ -469,7 +469,7 @@ class CoreServices(object):
try: try:
node.privatedir(directory) node.privatedir(directory)
except (CoreCommandError, ValueError) as e: except (CoreCommandError, ValueError) as e:
logger.warn("error mounting private dir '%s' for service '%s': %s", logging.warn("error mounting private dir '%s' for service '%s': %s",
directory, service.name, e) directory, service.name, e)
# create service files # create service files
@ -534,19 +534,19 @@ class CoreServices(object):
:return: service validation status :return: service validation status
:rtype: int :rtype: int
""" """
logger.info("validating node(%s) service(%s)", node.name, service.name) logging.info("validating node(%s) service(%s)", node.name, service.name)
cmds = service.validate cmds = service.validate
if not service.custom: if not service.custom:
cmds = service.get_validate(node) cmds = service.get_validate(node)
status = 0 status = 0
for cmd in cmds: for cmd in cmds:
logger.debug("validating service(%s) using: %s", service.name, cmd) logging.debug("validating service(%s) using: %s", service.name, cmd)
try: try:
node.check_cmd(cmd) node.check_cmd(cmd)
except CoreCommandError as e: except CoreCommandError as e:
logger.error("node(%s) service(%s) validate failed", node.name, service.name) logging.error("node(%s) service(%s) validate failed", node.name, service.name)
logger.error("cmd(%s): %s", e.cmd, e.output) logging.error("cmd(%s): %s", e.cmd, e.output)
status = -1 status = -1
break break
@ -576,7 +576,7 @@ class CoreServices(object):
try: try:
node.check_cmd(args) node.check_cmd(args)
except CoreCommandError: except CoreCommandError:
logger.exception("error running stop command %s", args) logging.exception("error running stop command %s", args)
status = -1 status = -1
return status return status
@ -638,13 +638,13 @@ class CoreServices(object):
# retrieve custom service # retrieve custom service
service = self.get_service(node_id, service_name) service = self.get_service(node_id, service_name)
if service is None: if service is None:
logger.warn("received file name for unknown service: %s", service_name) logging.warn("received file name for unknown service: %s", service_name)
return return
# validate file being set is valid # validate file being set is valid
config_files = service.configs config_files = service.configs
if file_name not in config_files: if file_name not in config_files:
logger.warn("received unknown file(%s) for service(%s)", file_name, service_name) logging.warn("received unknown file(%s) for service(%s)", file_name, service_name)
return return
# set custom service file data # set custom service file data
@ -673,7 +673,7 @@ class CoreServices(object):
else: else:
node.cmd(cmd, wait=False) node.cmd(cmd, wait=False)
except CoreCommandError: except CoreCommandError:
logger.exception("error starting command") logging.exception("error starting command")
status = -1 status = -1
return status return status
@ -685,14 +685,14 @@ class CoreServices(object):
:param CoreService service: service to reconfigure :param CoreService service: service to reconfigure
:return: nothing :return: nothing
""" """
logger.info("node(%s) service(%s) creating config files", node.name, service.name) logging.info("node(%s) service(%s) creating config files", node.name, service.name)
# get values depending on if custom or not # get values depending on if custom or not
config_files = service.configs config_files = service.configs
if not service.custom: if not service.custom:
config_files = service.get_configs(node) config_files = service.get_configs(node)
for file_name in config_files: for file_name in config_files:
logger.debug("generating service config: %s", file_name) logging.debug("generating service config: %s", file_name)
if service.custom: if service.custom:
cfg = service.config_data.get(file_name) cfg = service.config_data.get(file_name)
if cfg is None: if cfg is None:
@ -703,7 +703,7 @@ class CoreServices(object):
if self.copy_service_file(node, file_name, cfg): if self.copy_service_file(node, file_name, cfg):
continue continue
except IOError: except IOError:
logger.exception("error copying service file: %s", file_name) logging.exception("error copying service file: %s", file_name)
continue continue
else: else:
cfg = service.generate_config(node, file_name) cfg = service.generate_config(node, file_name)

View file

@ -97,14 +97,15 @@ Limitations:
depending on how many nodes you have. depending on how many nodes you have.
""" """
from core import logger import logging
from core.service import CoreService from core.service import CoreService
from core.service import ServiceManager from core.service import ServiceManager
try: try:
from docker import Client from docker import Client
except ImportError: except ImportError:
logger.debug("missing python docker bindings") logging.debug("missing python docker bindings")
class DockerService(CoreService): class DockerService(CoreService):
@ -154,7 +155,7 @@ done
@classmethod @classmethod
def on_load(cls): def on_load(cls):
logger.debug("loading custom docker services") logging.debug("loading custom docker services")
if "Client" in globals(): if "Client" in globals():
client = Client(version="1.10") client = Client(version="1.10")

View file

@ -3,8 +3,9 @@ security.py: defines security services (vpnclient, vpnserver, ipsec and
firewall) firewall)
""" """
import logging
from core import constants from core import constants
from core import logger
from core.service import CoreService from core.service import CoreService
@ -29,7 +30,7 @@ class VPNClient(CoreService):
try: try:
cfg += open(fname, "rb").read() cfg += open(fname, "rb").read()
except IOError: except IOError:
logger.exception("Error opening VPN client configuration template (%s)", fname) logging.exception("Error opening VPN client configuration template (%s)", fname)
return cfg return cfg
@ -56,7 +57,7 @@ class VPNServer(CoreService):
try: try:
cfg += open(fname, "rb").read() cfg += open(fname, "rb").read()
except IOError: except IOError:
logger.exception("Error opening VPN server configuration template (%s)", fname) logging.exception("Error opening VPN server configuration template (%s)", fname)
return cfg return cfg
@ -83,7 +84,7 @@ class IPsec(CoreService):
try: try:
cfg += open(fname, "rb").read() cfg += open(fname, "rb").read()
except IOError: except IOError:
logger.exception("Error opening IPsec configuration template (%s)", fname) logging.exception("Error opening IPsec configuration template (%s)", fname)
return cfg return cfg
@ -107,7 +108,7 @@ class Firewall(CoreService):
try: try:
cfg += open(fname, "rb").read() cfg += open(fname, "rb").read()
except IOError: except IOError:
logger.exception("Error opening Firewall configuration template (%s)", fname) logging.exception("Error opening Firewall configuration template (%s)", fname)
return cfg return cfg

View file

@ -2,7 +2,8 @@
xorp.py: defines routing services provided by the XORP routing suite. xorp.py: defines routing services provided by the XORP routing suite.
""" """
from core import logger import logging
from core.service import CoreService from core.service import CoreService
@ -42,7 +43,7 @@ class XorpRtrmgr(CoreService):
s.dependencies.index(cls.name) s.dependencies.index(cls.name)
cfg += s.generatexorpconfig(node) cfg += s.generatexorpconfig(node)
except ValueError: except ValueError:
logger.exception("error getting value from service: %s", cls.name) logging.exception("error getting value from service: %s", cls.name)
return cfg return cfg

View file

@ -3,6 +3,7 @@ session.py: defines the Session class used by the core-daemon daemon program
that manages a CORE session. that manages a CORE session.
""" """
import logging
import os import os
import random import random
import shutil import shutil
@ -15,7 +16,6 @@ from multiprocessing.pool import ThreadPool
import pwd import pwd
from core import constants from core import constants
from core import logger
from core.api import coreapi from core.api import coreapi
from core.broker import CoreBroker from core.broker import CoreBroker
from core.conf import ConfigurableManager from core.conf import ConfigurableManager
@ -207,12 +207,12 @@ class Session(object):
state_name = state.name state_name = state.name
if self.state == state_value: if self.state == state_value:
logger.info("session(%s) is already in state: %s, skipping change", self.session_id, state_name) logging.info("session(%s) is already in state: %s, skipping change", self.session_id, state_name)
return return
self.state = state_value self.state = state_value
self._state_time = time.time() self._state_time = time.time()
logger.info("changing session(%s) to state %s", self.session_id, state_name) logging.info("changing session(%s) to state %s", self.session_id, state_name)
self.write_state(state_value) self.write_state(state_value)
self.run_hooks(state_value) self.run_hooks(state_value)
@ -234,7 +234,7 @@ class Session(object):
state_file.write("%d %s\n" % (state, coreapi.state_name(state))) state_file.write("%d %s\n" % (state, coreapi.state_name(state)))
state_file.close() state_file.close()
except IOError: except IOError:
logger.exception("error writing state file: %s", state) logging.exception("error writing state file: %s", state)
def run_hooks(self, state): def run_hooks(self, state):
""" """
@ -256,7 +256,7 @@ class Session(object):
for hook in hooks: for hook in hooks:
self.run_hook(hook) self.run_hook(hook)
else: else:
logger.info("no state hooks for %s", state) logging.info("no state hooks for %s", state)
def set_hook(self, hook_type, file_name, source_name, data): def set_hook(self, hook_type, file_name, source_name, data):
""" """
@ -268,11 +268,11 @@ class Session(object):
:param data: hook data :param data: hook data
:return: nothing :return: nothing
""" """
logger.info("setting state hook: %s - %s from %s", hook_type, file_name, source_name) logging.info("setting state hook: %s - %s from %s", hook_type, file_name, source_name)
_hook_id, state = hook_type.split(':')[:2] _hook_id, state = hook_type.split(':')[:2]
if not state.isdigit(): if not state.isdigit():
logger.error("error setting hook having state '%s'", state) logging.error("error setting hook having state '%s'", state)
return return
state = int(state) state = int(state)
@ -285,7 +285,7 @@ class Session(object):
# immediately run a hook if it is in the current state # immediately run a hook if it is in the current state
# (this allows hooks in the definition and configuration states) # (this allows hooks in the definition and configuration states)
if self.state == state: if self.state == state:
logger.info("immediately running new state hook") logging.info("immediately running new state hook")
self.run_hook(hook) self.run_hook(hook)
def del_hooks(self): def del_hooks(self):
@ -302,7 +302,7 @@ class Session(object):
:return: nothing :return: nothing
""" """
file_name, data = hook file_name, data = hook
logger.info("running hook %s", file_name) logging.info("running hook %s", file_name)
# write data to hook file # write data to hook file
try: try:
@ -310,14 +310,14 @@ class Session(object):
hook_file.write(data) hook_file.write(data)
hook_file.close() hook_file.close()
except IOError: except IOError:
logger.exception("error writing hook '%s'", file_name) logging.exception("error writing hook '%s'", file_name)
# setup hook stdout and stderr # setup hook stdout and stderr
try: try:
stdout = open(os.path.join(self.session_dir, file_name + ".log"), "w") stdout = open(os.path.join(self.session_dir, file_name + ".log"), "w")
stderr = subprocess.STDOUT stderr = subprocess.STDOUT
except IOError: except IOError:
logger.exception("error setting up hook stderr and stdout") logging.exception("error setting up hook stderr and stdout")
stdout = None stdout = None
stderr = None stderr = None
@ -327,7 +327,7 @@ class Session(object):
subprocess.check_call(args, stdout=stdout, stderr=stderr, subprocess.check_call(args, stdout=stdout, stderr=stderr,
close_fds=True, cwd=self.session_dir, env=self.get_environment()) close_fds=True, cwd=self.session_dir, env=self.get_environment())
except (OSError, subprocess.CalledProcessError): except (OSError, subprocess.CalledProcessError):
logger.exception("error running hook: %s", file_name) logging.exception("error running hook: %s", file_name)
def run_state_hooks(self, state): def run_state_hooks(self, state):
""" """
@ -341,7 +341,7 @@ class Session(object):
hook(state) hook(state)
except: except:
message = "exception occured when running %s state hook: %s" % (coreapi.state_name(state), hook) message = "exception occured when running %s state hook: %s" % (coreapi.state_name(state), hook)
logger.exception(message) logging.exception(message)
self.exception(ExceptionLevels.ERROR, "Session.run_state_hooks", None, message) self.exception(ExceptionLevels.ERROR, "Session.run_state_hooks", None, message)
def add_state_hook(self, state, hook): def add_state_hook(self, state, hook):
@ -414,7 +414,7 @@ class Session(object):
if os.path.isfile(environment_config_file): if os.path.isfile(environment_config_file):
utils.load_config(environment_config_file, env) utils.load_config(environment_config_file, env)
except IOError: except IOError:
logger.warn("environment configuration file does not exist: %s", environment_config_file) logging.warn("environment configuration file does not exist: %s", environment_config_file)
# attempt to read and add user environment file # attempt to read and add user environment file
if self.user: if self.user:
@ -422,7 +422,7 @@ class Session(object):
try: try:
utils.load_config(environment_user_file, env) utils.load_config(environment_user_file, env)
except IOError: except IOError:
logger.debug("user core environment settings file not present: %s", environment_user_file) logging.debug("user core environment settings file not present: %s", environment_user_file)
return env return env
@ -434,7 +434,7 @@ class Session(object):
:return: nothing :return: nothing
""" """
if not os.path.exists(thumb_file): if not os.path.exists(thumb_file):
logger.error("thumbnail file to set does not exist: %s", thumb_file) logging.error("thumbnail file to set does not exist: %s", thumb_file)
self.thumbnail = None self.thumbnail = None
return return
@ -456,7 +456,7 @@ class Session(object):
gid = os.stat(self.session_dir).st_gid gid = os.stat(self.session_dir).st_gid
os.chown(self.session_dir, uid, gid) os.chown(self.session_dir, uid, gid)
except IOError: except IOError:
logger.exception("failed to set permission on %s", self.session_dir) logging.exception("failed to set permission on %s", self.session_dir)
self.user = user self.user = user
@ -532,7 +532,7 @@ class Session(object):
obj = self.objects.pop(object_id) obj = self.objects.pop(object_id)
obj.shutdown() obj.shutdown()
except KeyError: except KeyError:
logger.error("failed to remove object, object with id was not found: %s", object_id) logging.error("failed to remove object, object with id was not found: %s", object_id)
def delete_objects(self): def delete_objects(self):
""" """
@ -556,14 +556,14 @@ class Session(object):
nodes_file.write("%s %s %s %s\n" % (object_id, obj.name, obj.apitype, type(obj))) nodes_file.write("%s %s %s %s\n" % (object_id, obj.name, obj.apitype, type(obj)))
nodes_file.close() nodes_file.close()
except IOError: except IOError:
logger.exception("error writing nodes file") logging.exception("error writing nodes file")
def dump_session(self): def dump_session(self):
""" """
Log information about the session in its current state. Log information about the session in its current state.
""" """
logger.info("session id=%s name=%s state=%s", self.session_id, self.name, self.state) logging.info("session id=%s name=%s state=%s", self.session_id, self.name, self.state)
logger.info("file=%s thumbnail=%s node_count=%s/%s", logging.info("file=%s thumbnail=%s node_count=%s/%s",
self.file_name, self.thumbnail, self.get_node_count(), len(self.objects)) self.file_name, self.thumbnail, self.get_node_count(), len(self.objects))
def exception(self, level, source, object_id, text): def exception(self, level, source, object_id, text):
@ -647,10 +647,10 @@ class Session(object):
# this is called from instantiate() after receiving an event message # this is called from instantiate() after receiving an event message
# for the instantiation state, and from the broker when distributed # for the instantiation state, and from the broker when distributed
# nodes have been started # nodes have been started
logger.info("session(%s) checking if not in runtime state, current state: %s", self.session_id, logging.info("session(%s) checking if not in runtime state, current state: %s", self.session_id,
coreapi.state_name(self.state)) coreapi.state_name(self.state))
if self.state == EventTypes.RUNTIME_STATE.value: if self.state == EventTypes.RUNTIME_STATE.value:
logger.info("valid runtime state found, returning") logging.info("valid runtime state found, returning")
return return
# check to verify that all nodes and networks are running # check to verify that all nodes and networks are running
@ -694,7 +694,7 @@ class Session(object):
and links remain. and links remain.
""" """
node_count = self.get_node_count() node_count = self.get_node_count()
logger.info("session(%s) checking shutdown: %s nodes remaining", self.session_id, node_count) logging.info("session(%s) checking shutdown: %s nodes remaining", self.session_id, node_count)
shutdown = False shutdown = False
if node_count == 0: if node_count == 0:
@ -726,7 +726,7 @@ class Session(object):
# TODO: PyCoreNode is not the type to check # TODO: PyCoreNode is not the type to check
if isinstance(obj, nodes.PyCoreNode) and not nodeutils.is_node(obj, NodeTypes.RJ45): if isinstance(obj, nodes.PyCoreNode) and not nodeutils.is_node(obj, NodeTypes.RJ45):
# add a control interface if configured # add a control interface if configured
logger.info("booting node: %s", obj.name) logging.info("booting node: %s", obj.name)
self.add_remove_control_interface(node=obj, remove=False) self.add_remove_control_interface(node=obj, remove=False)
result = pool.apply_async(self.services.boot_services, (obj,)) result = pool.apply_async(self.services.boot_services, (obj,))
results.append(result) results.append(result)
@ -735,7 +735,7 @@ class Session(object):
pool.join() pool.join()
for result in results: for result in results:
result.get() result.get()
logger.debug("boot run time: %s", time.time() - start) logging.debug("boot run time: %s", time.time() - start)
self.update_control_interface_hosts() self.update_control_interface_hosts()
@ -766,7 +766,7 @@ class Session(object):
""" """
d0 = self.options.get_config("controlnetif0") d0 = self.options.get_config("controlnetif0")
if d0: if d0:
logger.error("controlnet0 cannot be assigned with a host interface") logging.error("controlnet0 cannot be assigned with a host interface")
d1 = self.options.get_config("controlnetif1") d1 = self.options.get_config("controlnetif1")
d2 = self.options.get_config("controlnetif2") d2 = self.options.get_config("controlnetif2")
d3 = self.options.get_config("controlnetif3") d3 = self.options.get_config("controlnetif3")
@ -806,7 +806,7 @@ class Session(object):
:return: control net object :return: control net object
:rtype: core.netns.nodes.CtrlNet :rtype: core.netns.nodes.CtrlNet
""" """
logger.debug("add/remove control net: index(%s) remove(%s) conf_required(%s)", net_index, remove, conf_required) logging.debug("add/remove control net: index(%s) remove(%s) conf_required(%s)", net_index, remove, conf_required)
prefix_spec_list = self.get_control_net_prefixes() prefix_spec_list = self.get_control_net_prefixes()
prefix_spec = prefix_spec_list[net_index] prefix_spec = prefix_spec_list[net_index]
if not prefix_spec: if not prefix_spec:
@ -816,7 +816,7 @@ class Session(object):
else: else:
control_net_class = nodeutils.get_node_class(NodeTypes.CONTROL_NET) control_net_class = nodeutils.get_node_class(NodeTypes.CONTROL_NET)
prefix_spec = control_net_class.DEFAULT_PREFIX_LIST[net_index] prefix_spec = control_net_class.DEFAULT_PREFIX_LIST[net_index]
logger.debug("prefix spec: %s", prefix_spec) logging.debug("prefix spec: %s", prefix_spec)
server_interface = self.get_control_net_server_interfaces()[net_index] server_interface = self.get_control_net_server_interfaces()[net_index]
@ -842,7 +842,7 @@ class Session(object):
if net_index == 0: if net_index == 0:
updown_script = self.options.get_config("controlnet_updown_script") updown_script = self.options.get_config("controlnet_updown_script")
if not updown_script: if not updown_script:
logger.warning("controlnet updown script not configured") logging.warning("controlnet updown script not configured")
prefixes = prefix_spec.split() prefixes = prefix_spec.split()
if len(prefixes) > 1: if len(prefixes) > 1:
@ -875,7 +875,7 @@ class Session(object):
break break
if not prefix: if not prefix:
logger.error("Control network prefix not found for server '%s'" % servers[0]) logging.error("Control network prefix not found for server '%s'" % servers[0])
assign_address = False assign_address = False
try: try:
prefix = prefixes[0].split(':', 1)[1] prefix = prefixes[0].split(':', 1)[1]
@ -935,7 +935,7 @@ class Session(object):
msg = "Control interface not added to node %s. " % node.objid msg = "Control interface not added to node %s. " % node.objid
msg += "Invalid control network prefix (%s). " % control_net.prefix msg += "Invalid control network prefix (%s). " % control_net.prefix
msg += "A longer prefix length may be required for this many nodes." msg += "A longer prefix length may be required for this many nodes."
logger.exception(msg) logging.exception(msg)
return return
interface1 = node.newnetif(net=control_net, interface1 = node.newnetif(net=control_net,
@ -958,12 +958,12 @@ class Session(object):
try: try:
control_net = self.get_control_net_object(net_index) control_net = self.get_control_net_object(net_index)
except KeyError: except KeyError:
logger.exception("error retrieving control net object") logging.exception("error retrieving control net object")
return return
header = "CORE session %s host entries" % self.session_id header = "CORE session %s host entries" % self.session_id
if remove: if remove:
logger.info("Removing /etc/hosts file entries.") logging.info("Removing /etc/hosts file entries.")
utils.file_demunge("/etc/hosts", header) utils.file_demunge("/etc/hosts", header)
return return
@ -973,7 +973,7 @@ class Session(object):
for address in interface.addrlist: for address in interface.addrlist:
entries.append("%s %s" % (address.split("/")[0], name)) entries.append("%s %s" % (address.split("/")[0], name))
logger.info("Adding %d /etc/hosts file entries." % len(entries)) logging.info("Adding %d /etc/hosts file entries." % len(entries))
utils.file_munge("/etc/hosts", header, "\n".join(entries) + "\n") utils.file_munge("/etc/hosts", header, "\n".join(entries) + "\n")
@ -1003,7 +1003,7 @@ class Session(object):
if current_time > 0.0: if current_time > 0.0:
if time <= current_time: if time <= current_time:
logger.warn("could not schedule past event for time %s (run time is now %s)", time, current_time) logging.warn("could not schedule past event for time %s (run time is now %s)", time, current_time)
return return
event_time = event_time - current_time event_time = event_time - current_time
@ -1011,7 +1011,7 @@ class Session(object):
if not name: if not name:
name = "" name = ""
logger.info("scheduled event %s at time %s data=%s", name, event_time + current_time, data) logging.info("scheduled event %s at time %s data=%s", name, event_time + current_time, data)
# TODO: if data is None, this blows up, but this ties into how event functions are ran, need to clean that up # TODO: if data is None, this blows up, but this ties into how event functions are ran, need to clean that up
def run_event(self, node_id=None, name=None, data=None): def run_event(self, node_id=None, name=None, data=None):
@ -1027,7 +1027,7 @@ class Session(object):
if not name: if not name:
name = "" name = ""
logger.info("running event %s at time %s cmd=%s" % (name, now, data)) logging.info("running event %s at time %s cmd=%s" % (name, now, data))
if not node_id: if not node_id:
utils.mute_detach(data) utils.mute_detach(data)
else: else:

View file

@ -1,7 +1,8 @@
import logging
from lxml import etree from lxml import etree
from core import coreobj from core import coreobj
from core import logger
from core.emulator.emudata import InterfaceData from core.emulator.emudata import InterfaceData
from core.emulator.emudata import LinkOptions from core.emulator.emudata import LinkOptions
from core.emulator.emudata import NodeOptions from core.emulator.emudata import NodeOptions
@ -321,7 +322,7 @@ class CoreXmlWriter(object):
continue continue
for model_name, config in all_configs.iteritems(): for model_name, config in all_configs.iteritems():
logger.info("writing emane config node(%s) model(%s)", node_id, model_name) logging.info("writing emane config node(%s) model(%s)", node_id, model_name)
if model_name == -1: if model_name == -1:
emane_configuration = create_emane_config(node_id, self.session.emane.emane_config, config) emane_configuration = create_emane_config(node_id, self.session.emane.emane_config, config)
else: else:
@ -340,7 +341,7 @@ class CoreXmlWriter(object):
continue continue
for model_name, config in all_configs.iteritems(): for model_name, config in all_configs.iteritems():
logger.info("writing mobility config node(%s) model(%s)", node_id, model_name) logging.info("writing mobility config node(%s) model(%s)", node_id, model_name)
mobility_configuration = etree.SubElement(mobility_configurations, "mobility_configuration") mobility_configuration = etree.SubElement(mobility_configurations, "mobility_configuration")
add_attribute(mobility_configuration, "node", node_id) add_attribute(mobility_configuration, "node", node_id)
add_attribute(mobility_configuration, "model", model_name) add_attribute(mobility_configuration, "model", model_name)
@ -399,7 +400,7 @@ class CoreXmlWriter(object):
for netif in node.netifs(sort=True): for netif in node.netifs(sort=True):
othernet = getattr(netif, "othernet", None) othernet = getattr(netif, "othernet", None)
if othernet and othernet.objid != node.objid: if othernet and othernet.objid != node.objid:
logger.info("writer ignoring node(%s) othernet(%s)", node.name, othernet.name) logging.info("writer ignoring node(%s) othernet(%s)", node.name, othernet.name)
return return
network = NetworkElement(self.session, node) network = NetworkElement(self.session, node)
@ -525,7 +526,7 @@ class CoreXmlReader(object):
services = [] services = []
for service in node.iterchildren(): for service in node.iterchildren():
services.append(service.get("name")) services.append(service.get("name"))
logger.info("reading default services for nodes(%s): %s", node_type, services) logging.info("reading default services for nodes(%s): %s", node_type, services)
self.session.services.default_services[node_type] = services self.session.services.default_services[node_type] = services
def read_session_metadata(self): def read_session_metadata(self):
@ -538,7 +539,7 @@ class CoreXmlReader(object):
name = data.get("name") name = data.get("name")
value = data.get("value") value = data.get("value")
configs[name] = value configs[name] = value
logger.info("reading session metadata: %s", configs) logging.info("reading session metadata: %s", configs)
self.session.metadata.set_configs(configs) self.session.metadata.set_configs(configs)
def read_session_options(self): def read_session_options(self):
@ -551,7 +552,7 @@ class CoreXmlReader(object):
name = config.get("name") name = config.get("name")
value = config.get("value") value = config.get("value")
configs[name] = value configs[name] = value
logger.info("reading session options: %s", configs) logging.info("reading session options: %s", configs)
self.session.options.set_configs(configs) self.session.options.set_configs(configs)
def read_session_hooks(self): def read_session_hooks(self):
@ -564,7 +565,7 @@ class CoreXmlReader(object):
state = hook.get("state") state = hook.get("state")
data = hook.text data = hook.text
hook_type = "hook:%s" % state hook_type = "hook:%s" % state
logger.info("reading hook: state(%s) name(%s)", state, name) logging.info("reading hook: state(%s) name(%s)", state, name)
self.session.set_hook(hook_type, file_name=name, source_name=None, data=data) self.session.set_hook(hook_type, file_name=name, source_name=None, data=data)
def read_session_origin(self): def read_session_origin(self):
@ -576,19 +577,19 @@ class CoreXmlReader(object):
lon = get_float(session_origin, "lon") lon = get_float(session_origin, "lon")
alt = get_float(session_origin, "alt") alt = get_float(session_origin, "alt")
if all([lat, lon, alt]): if all([lat, lon, alt]):
logger.info("reading session reference geo: %s, %s, %s", lat, lon, alt) logging.info("reading session reference geo: %s, %s, %s", lat, lon, alt)
self.session.location.setrefgeo(lat, lon, alt) self.session.location.setrefgeo(lat, lon, alt)
scale = get_float(session_origin, "scale") scale = get_float(session_origin, "scale")
if scale: if scale:
logger.info("reading session reference scale: %s", scale) logging.info("reading session reference scale: %s", scale)
self.session.location.refscale = scale self.session.location.refscale = scale
x = get_float(session_origin, "x") x = get_float(session_origin, "x")
y = get_float(session_origin, "y") y = get_float(session_origin, "y")
z = get_float(session_origin, "z") z = get_float(session_origin, "z")
if all([x, y]): if all([x, y]):
logger.info("reading session reference xyz: %s, %s, %s", x, y, z) logging.info("reading session reference xyz: %s, %s, %s", x, y, z)
self.session.location.refxyz = (x, y, z) self.session.location.refxyz = (x, y, z)
def read_service_configs(self): def read_service_configs(self):
@ -599,7 +600,7 @@ class CoreXmlReader(object):
for service_configuration in service_configurations.iterchildren(): for service_configuration in service_configurations.iterchildren():
node_id = get_int(service_configuration, "node") node_id = get_int(service_configuration, "node")
service_name = service_configuration.get("name") service_name = service_configuration.get("name")
logger.info("reading custom service(%s) for node(%s)", service_name, node_id) logging.info("reading custom service(%s) for node(%s)", service_name, node_id)
self.session.services.set_service(node_id, service_name) self.session.services.set_service(node_id, service_name)
service = self.session.services.get_service(node_id, service_name) service = self.session.services.get_service(node_id, service_name)
@ -654,7 +655,7 @@ class CoreXmlReader(object):
value = config.get("value") value = config.get("value")
configs[name] = value configs[name] = value
logger.info("reading emane configuration node(%s) model(%s)", node_id, model_name) logging.info("reading emane configuration node(%s) model(%s)", node_id, model_name)
self.session.emane.set_model_config(node_id, model_name, configs) self.session.emane.set_model_config(node_id, model_name, configs)
def read_mobility_configs(self): def read_mobility_configs(self):
@ -672,7 +673,7 @@ class CoreXmlReader(object):
value = config.get("value") value = config.get("value")
configs[name] = value configs[name] = value
logger.info("reading mobility configuration node(%s) model(%s)", node_id, model_name) logging.info("reading mobility configuration node(%s) model(%s)", node_id, model_name)
self.session.mobility.set_model_config(node_id, model_name, configs) self.session.mobility.set_model_config(node_id, model_name, configs)
def read_nodes(self): def read_nodes(self):
@ -709,7 +710,7 @@ class CoreXmlReader(object):
if all([lat, lon, alt]): if all([lat, lon, alt]):
node_options.set_location(lat, lon, alt) node_options.set_location(lat, lon, alt)
logger.info("reading node id(%s) model(%s) name(%s)", node_id, model, name) logging.info("reading node id(%s) model(%s) name(%s)", node_id, model, name)
self.session.add_node(_id=node_id, node_options=node_options) self.session.add_node(_id=node_id, node_options=node_options)
def read_network(self, network_element): def read_network(self, network_element):
@ -731,7 +732,7 @@ class CoreXmlReader(object):
if all([lat, lon, alt]): if all([lat, lon, alt]):
node_options.set_location(lat, lon, alt) node_options.set_location(lat, lon, alt)
logger.info("reading node id(%s) node_type(%s) name(%s)", node_id, node_type, name) logging.info("reading node id(%s) node_type(%s) name(%s)", node_id, node_type, name)
self.session.add_node(_type=node_type, _id=node_id, node_options=node_options) self.session.add_node(_type=node_type, _id=node_id, node_options=node_options)
def read_links(self): def read_links(self):
@ -772,5 +773,5 @@ class CoreXmlReader(object):
link_options.opaque = options_element.get("opaque") link_options.opaque = options_element.get("opaque")
link_options.gui_attributes = options_element.get("gui_attributes") link_options.gui_attributes = options_element.get("gui_attributes")
logger.info("reading link node_one(%s) node_two(%s)", node_one, node_two) logging.info("reading link node_one(%s) node_two(%s)", node_one, node_two)
self.session.add_link(node_one, node_two, interface_one, interface_two, link_options) self.session.add_link(node_one, node_two, interface_one, interface_two, link_options)

View file

@ -4,7 +4,6 @@ import socket
from lxml import etree from lxml import etree
from core import constants from core import constants
from core import logger
from core.coreobj import PyCoreNode from core.coreobj import PyCoreNode
from core.enumerations import NodeTypes from core.enumerations import NodeTypes
from core.misc import utils, nodeutils, ipaddress from core.misc import utils, nodeutils, ipaddress

View file

@ -1,8 +1,8 @@
import logging
import os import os
from lxml import etree from lxml import etree
from core import logger
from core.misc import utils from core.misc import utils
from core.misc.ipaddress import MacAddress from core.misc.ipaddress import MacAddress
from core.xml import corexml from core.xml import corexml
@ -40,7 +40,7 @@ def _value_to_params(value):
return values return values
except SyntaxError: except SyntaxError:
logger.exception("error in value string to param list") logging.exception("error in value string to param list")
return None return None
@ -108,11 +108,11 @@ def build_node_platform_xml(emane_manager, control_net, node, nem_id, platform_x
:return: the next nem id that can be used for creating platform xml files :return: the next nem id that can be used for creating platform xml files
:rtype: int :rtype: int
""" """
logger.debug("building emane platform xml for node(%s): %s", node, node.name) logging.debug("building emane platform xml for node(%s): %s", node, node.name)
nem_entries = {} nem_entries = {}
if node.model is None: if node.model is None:
logger.warn("warning: EmaneNode %s has no associated model", node.name) logging.warn("warning: EmaneNode %s has no associated model", node.name)
return nem_entries return nem_entries
for netif in node.netifs(): for netif in node.netifs():
@ -133,7 +133,7 @@ def build_node_platform_xml(emane_manager, control_net, node, nem_id, platform_x
# build transport xml # build transport xml
transport_type = netif.transport_type transport_type = netif.transport_type
if not transport_type: if not transport_type:
logger.info("warning: %s interface type unsupported!", netif.name) logging.info("warning: %s interface type unsupported!", netif.name)
transport_type = "raw" transport_type = "raw"
transport_file = transport_file_name(node.objid, transport_type) transport_file = transport_file_name(node.objid, transport_type)
transport_element = etree.SubElement(nem_element, "transport", definition=transport_file) transport_element = etree.SubElement(nem_element, "transport", definition=transport_file)
@ -209,7 +209,7 @@ def build_xml_files(emane_manager, node):
:param core.emane.nodes.EmaneNode node: node to write platform xml for :param core.emane.nodes.EmaneNode node: node to write platform xml for
:return: nothing :return: nothing
""" """
logger.debug("building all emane xml for node(%s): %s", node, node.name) logging.debug("building all emane xml for node(%s): %s", node, node.name)
if node.model is None: if node.model is None:
return return

View file

@ -5,11 +5,14 @@
import datetime import datetime
import parser import parser
from core import load_logging_config
from core.emane.ieee80211abg import EmaneIeee80211abgModel from core.emane.ieee80211abg import EmaneIeee80211abgModel
from core.emulator.coreemu import CoreEmu from core.emulator.coreemu import CoreEmu
from core.emulator.emudata import IpPrefixes from core.emulator.emudata import IpPrefixes
from core.enumerations import EventTypes from core.enumerations import EventTypes
load_logging_config()
def example(options): def example(options):
# ip generator for example # ip generator for example

View file

@ -8,10 +8,13 @@
import datetime import datetime
import parser import parser
from core import load_logging_config
from core.emulator.coreemu import CoreEmu from core.emulator.coreemu import CoreEmu
from core.emulator.emudata import IpPrefixes from core.emulator.emudata import IpPrefixes
from core.enumerations import NodeTypes, EventTypes from core.enumerations import NodeTypes, EventTypes
load_logging_config()
def example(options): def example(options):
# ip generator for example # ip generator for example

View file

@ -4,10 +4,12 @@
# n nodes are connected to a virtual wlan; run test for testsec # n nodes are connected to a virtual wlan; run test for testsec
# and repeat for minnodes <= n <= maxnodes with a step size of # and repeat for minnodes <= n <= maxnodes with a step size of
# nodestep # nodestep
from core import load_logging_config
from core.emulator.emudata import IpPrefixes from core.emulator.emudata import IpPrefixes
from core.enumerations import NodeTypes, EventTypes from core.enumerations import NodeTypes, EventTypes
load_logging_config()
def example(nodes): def example(nodes):
# ip generator for example # ip generator for example

View file

@ -8,11 +8,14 @@
import datetime import datetime
import parser import parser
from core import load_logging_config
from core.emulator.coreemu import CoreEmu from core.emulator.coreemu import CoreEmu
from core.emulator.emudata import IpPrefixes, NodeOptions from core.emulator.emudata import IpPrefixes, NodeOptions
from core.enumerations import NodeTypes, EventTypes from core.enumerations import NodeTypes, EventTypes
from core.mobility import BasicRangeModel from core.mobility import BasicRangeModel
load_logging_config()
def example(options): def example(options):
# ip generator for example # ip generator for example

View file

@ -1,6 +1,6 @@
import logging
import time import time
from core import logger
from core.misc.event import EventLoop from core.misc.event import EventLoop
@ -9,7 +9,7 @@ def main():
def msg(arg): def msg(arg):
delta = time.time() - loop.start delta = time.time() - loop.start
logger.debug("%s arg: %s", delta, arg) logging.debug("%s arg: %s", delta, arg)
def repeat(interval, count): def repeat(interval, count):
count -= 1 count -= 1

View file

@ -6,17 +6,20 @@ message handlers are defined and some support for sending messages.
""" """
import ConfigParser import ConfigParser
import logging
import optparse import optparse
import sys import sys
import time import time
from core import load_logging_config
from core import constants from core import constants
from core import enumerations from core import enumerations
from core import logger
from core.corehandlers import CoreHandler from core.corehandlers import CoreHandler
from core.coreserver import CoreServer from core.coreserver import CoreServer
from core.misc.utils import close_onexec from core.misc.utils import close_onexec
load_logging_config()
def banner(): def banner():
""" """
@ -24,7 +27,7 @@ def banner():
:return: nothing :return: nothing
""" """
logger.info("CORE daemon v.%s started %s", constants.COREDPY_VERSION, time.ctime()) logging.info("CORE daemon v.%s started %s", constants.COREDPY_VERSION, time.ctime())
def cored(cfg, use_ovs): def cored(cfg, use_ovs):
@ -46,11 +49,11 @@ def cored(cfg, use_ovs):
from core.netns.openvswitch import OVS_NODES from core.netns.openvswitch import OVS_NODES
server.coreemu.update_nodes(OVS_NODES) server.coreemu.update_nodes(OVS_NODES)
except: except:
logger.exception("error starting main server on: %s:%s", host, port) logging.exception("error starting main server on: %s:%s", host, port)
sys.exit(1) sys.exit(1)
close_onexec(server.fileno()) close_onexec(server.fileno())
logger.info("server started, listening on: %s:%s", host, port) logging.info("server started, listening on: %s:%s", host, port)
server.serve_forever() server.serve_forever()
@ -113,7 +116,7 @@ def main():
# get a configuration merged from config file and command-line arguments # get a configuration merged from config file and command-line arguments
cfg, args = get_merged_config("%s/core.conf" % constants.CORE_CONF_DIR) cfg, args = get_merged_config("%s/core.conf" % constants.CORE_CONF_DIR)
for a in args: for a in args:
logger.error("ignoring command line argument: %s", a) logging.error("ignoring command line argument: %s", a)
banner() banner()
@ -123,7 +126,7 @@ def main():
try: try:
cored(cfg, use_ovs) cored(cfg, use_ovs)
except KeyboardInterrupt: except KeyboardInterrupt:
logger.info("keyboard interrupt, stopping core daemon") logging.info("keyboard interrupt, stopping core daemon")
sys.exit(0) sys.exit(0)

View file

@ -2,6 +2,7 @@
ns3.py: defines classes for running emulations with ns-3 simulated networks. ns3.py: defines classes for running emulations with ns-3 simulated networks.
""" """
import logging
import subprocess import subprocess
import threading import threading
import time import time
@ -16,7 +17,6 @@ import ns.wifi
import ns.wimax import ns.wimax
from core import constants from core import constants
from core import logger
from core.coreobj import PyCoreNet from core.coreobj import PyCoreNet
from core.enumerations import EventTypes from core.enumerations import EventTypes
from core.enumerations import LinkTypes from core.enumerations import LinkTypes
@ -174,7 +174,7 @@ class CoreNs3Net(PyCoreNet):
netif.poshook = self.setns3position netif.poshook = self.setns3position
def setns3position(self, netif, x, y, z): def setns3position(self, netif, x, y, z):
logger.info("setns3position: %s (%s, %s, %s)", netif.node.name, x, y, z) logging.info("setns3position: %s (%s, %s, %s)", netif.node.name, x, y, z)
netif.node.setns3position(x, y, z) netif.node.setns3position(x, y, z)
@ -246,7 +246,7 @@ class Ns3LteNet(CoreNs3Net):
# ns.core.IntegerValue(ns.tap_bridge.TapBridge.USE_LOCAL)) # ns.core.IntegerValue(ns.tap_bridge.TapBridge.USE_LOCAL))
tap = self.tapbridge.Install(netif.node, ns3dev) tap = self.tapbridge.Install(netif.node, ns3dev)
# tap.SetMode(ns.tap_bridge.TapBridge.USE_LOCAL) # tap.SetMode(ns.tap_bridge.TapBridge.USE_LOCAL)
logger.info("using TAP device %s for %s/%s", netif.localname, netif.node.name, netif.name) logging.info("using TAP device %s for %s/%s", netif.localname, netif.node.name, netif.name)
subprocess.check_call(['tunctl', '-t', netif.localname, '-n']) subprocess.check_call(['tunctl', '-t', netif.localname, '-n'])
# check_call([IP_BIN, 'link', 'set', 'dev', netif.localname, \ # check_call([IP_BIN, 'link', 'set', 'dev', netif.localname, \
# 'address', '%s' % netif.hwaddr]) # 'address', '%s' % netif.hwaddr])
@ -373,12 +373,12 @@ class Ns3Session(Session):
def runthread(): def runthread():
ns.core.Simulator.Stop(ns.core.Seconds(self.duration)) ns.core.Simulator.Stop(ns.core.Seconds(self.duration))
logger.info("running ns-3 simulation for %d seconds", self.duration) logging.info("running ns-3 simulation for %d seconds", self.duration)
if vis: if vis:
try: try:
import visualizer import visualizer
except ImportError: except ImportError:
logger.exception("visualizer is not available") logging.exception("visualizer is not available")
ns.core.Simulator.Run() ns.core.Simulator.Run()
else: else:
visualizer.start() visualizer.start()
@ -509,7 +509,7 @@ class Ns3Session(Session):
net.mobility.setnodeposition(node, x, y, z) net.mobility.setnodeposition(node, x, y, z)
nodemap[node.GetId()] = node nodemap[node.GetId()] = node
logger.info("mobilitytrace opening '%s'", filename) logging.info("mobilitytrace opening '%s'", filename)
f = None f = None
try: try:
@ -529,7 +529,7 @@ class Ns3Session(Session):
continue continue
sleep = 0.001 sleep = 0.001
items = dict(x.split("=") for x in line.split()) items = dict(x.split("=") for x in line.split())
logger.info("trace: %s %s %s", items['node'], items['pos'], items['vel']) logging.info("trace: %s %s %s", items['node'], items['pos'], items['vel'])
x, y, z = map(float, items['pos'].split(':')) x, y, z = map(float, items['pos'].split(':'))
vel = map(float, items['vel'].split(':')) vel = map(float, items['vel'].split(':'))
node = nodemap[int(items['node'])] node = nodemap[int(items['node'])]
@ -544,7 +544,7 @@ class Ns3Session(Session):
net.mobility.state = net.mobility.STATE_RUNNING net.mobility.state = net.mobility.STATE_RUNNING
self.event_loop.add_event(0, net.mobility.runround) self.event_loop.add_event(0, net.mobility.runround)
except IOError: except IOError:
logger.exception("mobilitytrace error opening: %s", filename) logging.exception("mobilitytrace error opening: %s", filename)
finally: finally:
if f: if f:
f.close() f.close()

View file

@ -4,13 +4,13 @@ ns3lte.py - This script demonstrates using CORE with the ns-3 LTE model.
- issues connecting TapBridge with LteNetDevice - issues connecting TapBridge with LteNetDevice
""" """
import logging
import optparse import optparse
import sys import sys
import ns.core import ns.core
import ns.mobility import ns.mobility
from core import logger
from core.misc import ipaddress from core.misc import ipaddress
from core.misc import nodemaps from core.misc import nodemaps
from core.misc import nodeutils from core.misc import nodeutils
@ -84,13 +84,13 @@ def main():
usage("invalid numnodes: %s" % opt.numnodes) usage("invalid numnodes: %s" % opt.numnodes)
for a in args: for a in args:
logger.warn("ignoring command line argument: '%s'", a) logging.warn("ignoring command line argument: '%s'", a)
return ltesession(opt) return ltesession(opt)
def cleanup(): def cleanup():
logger.info("shutting down session") logging.info("shutting down session")
session.shutdown() session.shutdown()

View file

@ -22,12 +22,12 @@ To run with the CORE GUI:
""" """
import logging
import optparse import optparse
import sys import sys
import ns.core import ns.core
from core import logger
from core.misc import ipaddress from core.misc import ipaddress
from core.misc import nodeutils from core.misc import nodeutils
from core.misc import nodemaps from core.misc import nodemaps
@ -105,11 +105,11 @@ def main():
usage("invalid numnodes: %s" % opt.numnodes) usage("invalid numnodes: %s" % opt.numnodes)
for a in args: for a in args:
logger.warn("ignoring command line argument: '%s'", a) logging.warn("ignoring command line argument: '%s'", a)
return wifisession(opt) return wifisession(opt)
if __name__ == "__main__" or __name__ == "__builtin__": if __name__ == "__main__" or __name__ == "__builtin__":
session = main() session = main()
logger.info("\nsession =%s", session) logging.info("\nsession =%s", session)

View file

@ -11,6 +11,7 @@ How to run this:
python -i ns3wifirandomwalk.py python -i ns3wifirandomwalk.py
""" """
import logging
import optparse import optparse
import sys import sys
@ -19,7 +20,6 @@ import ns.network
from corens3.obj import Ns3Session from corens3.obj import Ns3Session
from corens3.obj import Ns3WifiNet from corens3.obj import Ns3WifiNet
from core import logger
from core.misc import ipaddress from core.misc import ipaddress
from core.misc import nodemaps from core.misc import nodemaps
from core.misc import nodeutils from core.misc import nodeutils
@ -109,11 +109,11 @@ def main():
usage("invalid numnodes: %s" % opt.numnodes) usage("invalid numnodes: %s" % opt.numnodes)
for a in args: for a in args:
logger.warn("ignoring command line argument: '%s'", a) logging.warn("ignoring command line argument: '%s'", a)
return wifisession(opt) return wifisession(opt)
if __name__ == "__main__" or __name__ == "__builtin__": if __name__ == "__main__" or __name__ == "__builtin__":
session = main() session = main()
logger.info("\nsession =%s", session) logging.info("\nsession =%s", session)

View file

@ -9,10 +9,10 @@ Current issues:
- no packets are sent between nodes - no connection? - no packets are sent between nodes - no connection?
""" """
import logging
import optparse import optparse
import sys import sys
from core import logger
from core.misc import ipaddress from core.misc import ipaddress
from core.misc import nodemaps from core.misc import nodemaps
from core.misc import nodeutils from core.misc import nodeutils
@ -76,7 +76,7 @@ def main():
usage("invalid numnodes: %s" % opt.numnodes) usage("invalid numnodes: %s" % opt.numnodes)
for a in args: for a in args:
logger.warn("ignoring command line argument: '%s'", a) logging.warn("ignoring command line argument: '%s'", a)
return wimaxsession(opt) return wimaxsession(opt)