<commit_before>#
# CORE
# Copyright (c)2010-2014 the Boeing Company.
# See the LICENSE file included in this distribution.
#
# author: <NAME> <<EMAIL>>
#
'''
emane.py: definition of an Emane class for implementing configuration
          control of an EMANE emulation.
'''

import sys, os, threading, subprocess, time, string
from xml.dom.minidom import parseString, Document
from core.constants import *
from core.api import coreapi
from core.misc.ipaddr import MacAddr
from core.misc.utils import maketuplefromstr, cmdresult, closeonexec
from core.misc.xmlutils import addtextelementsfromtuples, addparamlisttoparent
from core.conf import ConfigurableManager, Configurable
from core.mobility import WirelessModel
from core.emane.nodes import EmaneNode

# EMANE 0.7.4/0.8.1
try:
    import emaneeventservice
    import emaneeventlocation
except Exception, e:
    pass
# EMANE 0.9.1+
try:
    from emanesh.events import EventService
    from emanesh.events import LocationEvent
except Exception, e:
    pass

class Emane(ConfigurableManager):
    ''' EMANE controller object. Lives in a Session instance and is used for
        building EMANE config files from all of the EmaneNode objects in this
        emulation, and for controlling the EMANE daemons.
    '''
    _name = "emane"
    _type = coreapi.CORE_TLV_REG_EMULSRV
    _hwaddr_prefix = "02:02"
    (SUCCESS, NOT_NEEDED, NOT_READY) = (0, 1, 2)
    EVENTCFGVAR = 'LIBEMANEEVENTSERVICECONFIG'
    # possible self.version values
    (EMANEUNK, EMANE074, EMANE081, EMANE091, EMANE092, EMANE093) = \
        (0, 7, 8, 91, 92, 93)
    DEFAULT_LOG_LEVEL = 3

    def __init__(self, session):
        ConfigurableManager.__init__(self, session)
        self.verbose = self.session.getcfgitembool('verbose', False)
        self._objs = {}
        self._objslock = threading.Lock()
        self._ifccounts = {}
        self._ifccountslock = threading.Lock()
        self._modelclsmap = {}
        # Port numbers are allocated from these counters
        self.platformport = self.session.getcfgitemint('emane_platform_port',
                                                       8100)
        self.transformport = self.session.getcfgitemint('emane_transform_port',
                                                        8200)
        self.doeventloop = False
        self.eventmonthread = None
        self.logversion()
        # model for global EMANE configuration options
        self.emane_config = EmaneGlobalModel(session, None, self.verbose)
        session.broker.handlers += (self.handledistributed, )
        self.loadmodels()
        self.service = None

    def logversion(self):
        'Log the installed EMANE version.'
        if self.verbose:
            self.info("using EMANE version: %s" % self.versionstr)

    def initeventservice(self, filename=None, shutdown=False):
        ''' (Re-)initialize the EMANE Event service.
            The multicast group and/or port may be configured.
            - For versions < 0.9.1 this can be changed via XML config file
              and an environment variable pointing to that file.
            - For version >= 0.9.1 this is passed into the EventService
              constructor.
        '''
        if hasattr(self, 'service'):
            del self.service
        self.service = None

        # EMANE 0.9.1+ does not require event service XML config
        if self.version >= self.EMANE091:
            if shutdown:
                return
            #Get the control network to be used for events
            values = self.getconfig(None, "emane",
                                    self.emane_config.getdefaultvalues())[1]<commit_msg>daemon: Explicitly close EMANE event service files.<commit_after>#
# CORE
# Copyright (c)2010-2014 the Boeing Company.
# See the LICENSE file included in this distribution.
#
# author: <NAME> <<EMAIL>>
#
'''
emane.py: definition of an Emane class for implementing configuration
          control of an EMANE emulation.
'''

import sys, os, threading, subprocess, time, string
from xml.dom.minidom import parseString, Document
from core.constants import *
from core.api import coreapi
from core.misc.ipaddr import MacAddr
from core.misc.utils import maketuplefromstr, cmdresult, closeonexec
from core.misc.xmlutils import addtextelementsfromtuples, addparamlisttoparent
from core.conf import ConfigurableManager, Configurable
from core.mobility import WirelessModel
from core.emane.nodes import EmaneNode

# EMANE 0.7.4/0.8.1
try:
    import emaneeventservice
    import emaneeventlocation
except Exception, e:
    pass
# EMANE 0.9.1+
try:
    from emanesh.events import EventService
    from emanesh.events import LocationEvent
except Exception, e:
    pass

class Emane(ConfigurableManager):
    ''' EMANE controller object. Lives in a Session instance and is used for
        building EMANE config files from all of the EmaneNode objects in this
        emulation, and for controlling the EMANE daemons.
    '''
    _name = "emane"
    _type = coreapi.CORE_TLV_REG_EMULSRV
    _hwaddr_prefix = "02:02"
    (SUCCESS, NOT_NEEDED, NOT_READY) = (0, 1, 2)
    EVENTCFGVAR = 'LIBEMANEEVENTSERVICECONFIG'
    # possible self.version values
    (EMANEUNK, EMANE074, EMANE081, EMANE091, EMANE092, EMANE093) = \
        (0, 7, 8, 91, 92, 93)
    DEFAULT_LOG_LEVEL = 3

    def __init__(self, session):
        ConfigurableManager.__init__(self, session)
        self.verbose = self.session.getcfgitembool('verbose', False)
        self._objs = {}
        self._objslock = threading.Lock()
        self._ifccounts = {}
        self._ifccountslock = threading.Lock()
        self._modelclsmap = {}
        # Port numbers are allocated from these counters
        self.platformport = self.session.getcfgitemint('emane_platform_port',
                                                       8100)
        self.transformport = self.session.getcfgitemint('emane_transform_port',
                                                        8200)
        self.doeventloop = False
        self.eventmonthread = None
        self.logversion()
        # model for global EMANE configuration options
        self.emane_config = EmaneGlobalModel(session, None, self.verbose)
        session.broker.handlers += (self.handledistributed, )
        self.loadmodels()
        self.service = None

    def logversion(self):
        'Log the installed EMANE version.'
        if self.verbose:
            self.info("using EMANE version: %s" % self.versionstr)

    def deleteeventservice(self):
        if hasattr(self, 'service'):
            if self.service:
                for fd in self.service._readFd, self.service._writeFd:
                    if fd >= 0:
                        os.close(fd)
                for f in self.service._socket, self.service._socketOTA:
                    if f:
                        f.close()
            del self.service

    def initeventservice(self, filename=None, shutdown=False):
        ''' (Re-)initialize the EMANE Event service.
            The multicast group and/or port may be configured.
            - For versions < 0.9.1 this can be changed via XML config file
              and an environment variable pointing to that file.
            - For version >= 0.9.1 this is passed into the EventService
              constructor.
        '''
        self.deleteeventservice()
        self.service = None

        # EMANE 0.9.1+ does not require event service XML config
        if self.version >= self.EMANE091:
            if shutdown:
                return
            #Get the control network to be used for events
            values = self.getconfig(None, "emane",
                                    self.emane_config.getdefaultvalues())[1]
{'fraction_non_alphanumeric': 0.08005181347150259, 'fraction_numerical': 0.018264248704663213, 'mean_word_length': 2.345320623916811, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5687762', 'n_tokens_mistral': 2284, 'n_tokens_neox': 2162, 'n_words': 651}