Ejemplo n.º 1
0
def main_setup(output_name):
    '''
    This should be called at the beginning of main if you're running unit tests
    or simulations.
    We need to set |globals_.event_manager| for most class definitions and helper
    functions to make sense.
    '''
    globals_.event_manager = EventManager(output_name)
    globals_.stats_manager = StatsManager(output_name)
Ejemplo n.º 2
0
 def setUp(self):
     """Set up data and create a temporary directory to save data and stats."""
     self.tempdir = tempfile.mkdtemp()
     self.data = StatsManager()
     self.data.AddValue('A', 99999.5)
     self.data.AddValue('A', 100000.5)
     self.data.AddValue('A', 'ERROR')
     self.data.AddValue('B', 1.5)
     self.data.AddValue('B', 2.5)
     self.data.AddValue('B', 3.5)
     self.data.CalculateStats()
Ejemplo n.º 3
0
    def __init__(self,
                 brdfile,
                 cfgfile,
                 serial_a=None,
                 serial_b=None,
                 sync_date=False,
                 use_ms=False,
                 use_mW=False,
                 print_stats=False,
                 stats_dir=None,
                 stats_json_dir=None,
                 print_raw_data=True,
                 raw_data_dir=None):
        """Init the powerlog class and set the variables.

    Args:
      brdfile: string name of json file containing board layout.
      cfgfile: string name of json containing list of rails to read.
      serial_a: serial number of sweetberry A.
      serial_b: serial number of sweetberry B.
      sync_date: report timestamps synced with host datetime.
      use_ms: report timestamps in ms rather than us.
      use_mW: report power as milliwatts, otherwise default to microwatts.
      print_stats: print statistics for sweetberry readings at the end.
      stats_dir: directory to save sweetberry readings statistics; if None then
                 do not save the statistics.
      stats_json_dir: directory to save means of sweetberry readings in json
                      format; if None then do not save the statistics.
      print_raw_data: print sweetberry readings raw data in real time, default
                      is to print.
      raw_data_dir: directory to save sweetberry readings raw data; if None then
                    do not save the raw data.
    """
        self._data = StatsManager()
        self._pwr = {}
        self._use_ms = use_ms
        self._use_mW = use_mW
        self._print_stats = print_stats
        self._stats_dir = stats_dir
        self._stats_json_dir = stats_json_dir
        self._print_raw_data = print_raw_data
        self._raw_data_dir = raw_data_dir

        if not serial_a and not serial_b:
            self._pwr['A'] = Spower('A')
        if serial_a:
            self._pwr['A'] = Spower('A', serialname=serial_a)
        if serial_b:
            self._pwr['B'] = Spower('B', serialname=serial_b)

        with open(process_filename(cfgfile)) as data_file:
            names = json.load(data_file)
        self._names = self.process_scenario(names)

        for key in self._pwr:
            self._pwr[key].load_board(brdfile)
            self._pwr[key].reset()

        # Allocate the rails to the appropriate boards.
        used_boards = []
        for name in self._names:
            success = False
            for key in self._pwr.keys():
                if self._pwr[key].add_ina_name(name):
                    success = True
                    if key not in used_boards:
                        used_boards.append(key)
            if not success:
                raise Exception("Failed to add %s (maybe missing "
                                "sweetberry, or bad board file?)" % name)

        # Evict unused boards.
        for key in self._pwr.keys():
            if key not in used_boards:
                self._pwr.pop(key)

        for key in self._pwr.keys():
            if sync_date:
                self._pwr[key].set_time(time.time() * 1000000)
            else:
                self._pwr[key].set_time(0)
Ejemplo n.º 4
0
    def __init__(self, config, cred, specs, factory, notifier=None):
        """Create a new instance of chain runner.

        Create dependent components
        A new instance is created everytime the nfvbench config may have changed.

        config: the new nfvbench config to use for this run
        cred: openstack credentials (or None if no openstack)
        specs: TBD
        factory:
        notifier:
        """
        self.config = config
        self.cred = cred
        self.specs = specs
        self.factory = factory
        self.notifier = notifier
        self.chain_name = self.config.service_chain

        # get an instance of traffic client
        self.traffic_client = TrafficClient(config, notifier)

        if self.config.no_traffic:
            LOG.info('Dry run: traffic generation is disabled')
        else:
            # Start the traffic generator server
            self.traffic_client.start_traffic_generator()

        # get an instance of a chain manager
        self.chain_manager = ChainManager(self)

        # at this point all resources are setup/discovered
        # we need to program the traffic dest MAC and VLANs
        gen_config = self.traffic_client.generator_config
        if config.vlan_tagging:
            # VLAN is discovered from the networks
            gen_config.set_vlans(0, self.chain_manager.get_chain_vlans(0))
            gen_config.set_vlans(1, self.chain_manager.get_chain_vlans(1))

        # the only case we do not need to set the dest MAC is in the case of
        # l2-loopback (because the traffic gen will default to use the peer MAC)
        # or EXT+ARP+VLAN (because dest MAC will be discovered by TRex ARP)
        # Note that in the case of EXT+ARP+VxLAN, the dest MACs need to be loaded
        # because ARP only operates on the dest VTEP IP not on the VM dest MAC
        if not config.l2_loopback and \
                (config.service_chain != ChainType.EXT or config.no_arp or config.vxlan):
            gen_config.set_dest_macs(0, self.chain_manager.get_dest_macs(0))
            gen_config.set_dest_macs(1, self.chain_manager.get_dest_macs(1))

        if config.vxlan:
            # VXLAN is discovered from the networks
            vtep_vlan = gen_config.gen_config.vtep_vlan
            src_vteps = gen_config.gen_config.src_vteps
            dst_vtep = gen_config.gen_config.dst_vtep
            gen_config.set_vxlans(0, self.chain_manager.get_chain_vxlans(0))
            gen_config.set_vxlans(1, self.chain_manager.get_chain_vxlans(1))
            gen_config.set_vtep_vlan(0, vtep_vlan)
            gen_config.set_vtep_vlan(1, vtep_vlan)
            # Configuring source an remote VTEPs on TREx interfaces
            gen_config.set_vxlan_endpoints(0, src_vteps[0], dst_vtep)
            gen_config.set_vxlan_endpoints(1, src_vteps[1], dst_vtep)
            self.config['vxlan_gen_config'] = gen_config

        # get an instance of the stats manager
        self.stats_manager = StatsManager(self)
        LOG.info('ChainRunner initialized')
Ejemplo n.º 5
0
from functools import wraps
import settings.flask_settings as local_settings
import settings.global_settings as global_settings
import logging
from assets.streamer import Streamer
from assets.twitchapi import TwitchAPI
from assets.jwtworker import JWTworker
from stats_manager import StatsManager
from assets.profanity_filter import ProfanityFilter

application = Flask(__name__, template_folder='frontend', static_url_path="")
socketio = SocketIO(application)
logger = logging.getLogger('flask_app')
TwitchAPI.generate_oauth()
bubble = Bubble(read_data=True)
stats = StatsManager()


def log_setup(app, logger):
    log_f = logging.FileHandler(local_settings.FLASK_LOG_FILE)
    log_s = logging.StreamHandler()

    if (global_settings.DEBUG):
        logger.setLevel(logging.DEBUG)
        log_f.setLevel(logging.DEBUG)
        log_s.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)

    # Set formatter for requests
    formatter = local_settings.RequestFormatter(local_settings.REQUEST_FORMAT)
Ejemplo n.º 6
0
def main_setup():
    random.seed(0)
    globals_.event_manager = EventManager(None)
    globals_.stats_manager = StatsManager('output')