示例#1
0
    def setupProducerConfig(self):
        global sampleConfig, streamName
        if self.options['--config_file']:
            self.config = libconf.load(self.options['--config_file'])
        else:
            self.config = libconf.loads(sampleConfig)
            self.config['general']['log_path'] = self.runDir
            if self.options['--verbose']:
                self.config['general']['log_level'] = 'all'
            self.config['produce']['streams'][0]['source'][
                'name'] = self.sourcePipe
            # customize other things, if options are available
            if self.options['--video_size']:
                # TODO
                logger.debug("will setup video size here")
            if self.options['--bitrate']:
                # TODO
                logger.debug("will setup bitrate here")
            if self.options['--stream_name']:
                streamName = self.options['--stream_name']
                self.config['produce']['streams'][0]['name'] = self.options[
                    '--stream_name']
            if self.options['--thread_name']:
                self.config['produce']['streams'][0]['threads'][0][
                    'name'] = self.options['--thread_name']

        # save config to a temp file
        self.configFile = os.path.join(self.runDir, 'producer.cfg')
        with io.open(self.configFile, mode="w") as f:
            libconf.dump(self.config, f)
        logger.debug("saved config to %s" % self.configFile)
示例#2
0
    def setupConsumerConfig(self):
        global sampleConfig, streamName
        if self.options['--config_file']:
            self.config = libconf.load(self.options['--config_file'])
        else:
            self.config = libconf.loads(sampleConfig)
            self.config['general']['log_path'] = self.runDir
            if self.options['--verbose']:
                self.config['general']['log_level'] = 'all'
            streamPrefix = self.options['<stream_prefix>']
            if self.options['--instance_name']:
                utils.ndnrtcClientInstanceName = self.options[
                    '--instance_name']
            self.basePrefix = streamPrefix if streamPrefix.endswith(
                utils.ndnrtcClientInstanceName) else os.path.join(
                    streamPrefix, utils.ndnrtcClientInstanceName)
            self.config['consume']['streams'][0][
                'base_prefix'] = self.basePrefix
            self.sinkPipe = os.path.join(self.runDir, 'sink')
            self.config['consume']['streams'][0]['sink'][
                'name'] = self.sinkPipe
            if self.options['--stream_name']:
                streamName = self.options['--stream_name']
                self.config['consume']['streams'][0]['name'] = self.options[
                    '--stream_name']
            if self.options['--thread_name']:
                self.config['consume']['streams'][0][
                    'thread_to_fetch'] = self.options['--thread_name']

        self.configFile = os.path.join(self.runDir, 'consumer.cfg')
        with io.open(self.configFile, mode="w") as f:
            libconf.dump(self.config, f)
        logger.debug("saved config to %s" % self.configFile)
示例#3
0
def test_dumps_roundtrip():
    example_file = os.path.join(CURDIR, 'test_e2e.cfg')
    with io.open(example_file, 'r', encoding='utf-8') as f:
        c = libconf.load(f, includedir=CURDIR)

    c_dumped = libconf.loads(libconf.dumps(c))

    assert c == c_dumped
示例#4
0
def test_dumps_roundtrip():
    example_file = os.path.join(CURDIR, 'test_e2e.cfg')
    with io.open(example_file, 'r', encoding='utf-8') as f:
        c = libconf.load(f, includedir=CURDIR)

    c_dumped = libconf.loads(libconf.dumps(c))

    assert c == c_dumped
示例#5
0
def ues():
    if request.method == 'GET':
        res = requests.get(ems_conf['amf-service_url'] + "/ues")
        if res.status_code == requests.codes.ok:
            ret = json.loads(res.text)
            # add disconnected ues
            ue_set = set()
            for ue in ret["uelist"]:
                ue_set.add(ue["imsi"].replace('.', ''))
            for ue in config["UE_INFO"]:
                if ue["imsi"].replace('.', '') not in ue_set:
                    ue_tmp = {}
                    ue_tmp["imsi"] = ue["imsi"]
                    ue_tmp["uekey"] = ue["key"]["k"]
                    ue_tmp["status"] = "DISCONNECTED"
                    ret["uelist"].append(ue_tmp)
            return ret
        else:
            return '{ "message" : "cannot get data from amf-service" }'
    elif request.method == 'POST':  # create ue
        # create ue in config
        req_data_str = request.data.decode('ascii')
        # convert str to dict
        req_dict = json.loads(req_data_str)
        # convert dict to attrdict type string
        req_gen_conf = gen_conf(req_dict)
        # convert string to attrdict
        new_ue = libconf.loads(req_gen_conf[1:-1])
        # check ue format
        if not type_check(new_ue, "ue"):
            return '{ "message" : "wrong ue format" }'
        # check if imsi already exist
        ue_list_tmp = list(config["UE_INFO"])
        for ue_tmp in ue_list_tmp:
            if ue_tmp["imsi"].replace('.',
                                      '') == new_ue["imsi"].replace('.', ''):
                return '{ "message" : "ue already exist" }'
        imsi = new_ue["imsi"].replace('.', '')
        new_ue["imsi"] = imsi[:3] + "." + imsi[3:5] + "." + imsi[5:]
        ue_list_tmp.append(new_ue)
        config["UE_INFO"] = tuple(ue_list_tmp)
        configReadWrite.writeConfig(config, 'conf/all.conf')
        configReadWrite.genNfConf(config, containers)
        # create ue in 5gc
        post_data = {}
        post_data["imsi"] = new_ue["imsi"]
        post_data["key"] = {}
        post_data["key"]["k"] = new_ue["key"]["k"]
        if "op" in new_ue["key"]:
            post_data["key"]["op"] = new_ue["key"]["op"]
        if "opc" in new_ue["key"]:
            post_data["key"]["opc"] = new_ue["key"]["opc"]
        res = requests.post(ems_conf['amf-service_url'] + "/ues",
                            data=json.dumps(post_data))
        if res.status_code == requests.codes.ok:
            return '{ "message" : "ue created" }'
        else:
            return '{ "message" : "cannot create ue in amf" }'
示例#6
0
def configapi():
    global config
    if request.method == 'GET':
        # convert attrdict to json string
        return json.dumps(config)
    elif request.method == 'POST':
        req_data_str = request.data.decode('ascii')
        # convert str to dict
        req_dict = json.loads(req_data_str)
        # convert dict to attrdict type string
        req_gen_conf = gen_conf(req_dict)
        # convert string to attrdict
        config = libconf.loads(req_gen_conf[1:-1])
        # write config to config files
        configReadWrite.writeConfig(config, 'conf/all.conf')
        configReadWrite.genNfConf(config, containers)
        return '{ "message" : "success" }'
示例#7
0
def test_roundtrip_of_int64_values():
    s = u'a=2L;'
    s2 = libconf.dumps(libconf.loads(s))
    assert s == s2.replace(' ', '').replace('\n', '')
示例#8
0
def test_string_merging():
    # Unicode characters are supported, \u escapes not.
    input = u"""s = "abc\x21def\n" /* comment */ "newline-" # second comment
                   "here \u2603 \\u2603";"""
    assert libconf.loads(input).s == u"abc\x21def\nnewline-here \u2603 \\u2603"
示例#9
0
def test_roundtrip_preserves_config_entry_order():
    config = libconf.loads(u'''l: 1; i: 5; b: 3; c: 1; o: 9; n: 0; f: 7;''')
    dumped = libconf.dumps(config)
    reloaded = libconf.loads(dumped)

    assert ''.join(reloaded.keys()) == 'libconf'
示例#10
0
def test_loads_maintains_dict_order():
    config = libconf.loads(u'''l: 1; i: 5; b: 3; c: 1; o: 9; n: 0; f: 7;''')
    assert ''.join(config.keys()) == 'libconf'
示例#11
0
def test_roundtrip_preserves_config_entry_order():
    config = libconf.loads(u'''l: 1; i: 5; b: 3; c: 1; o: 9; n: 0; f: 7;''')
    dumped = libconf.dumps(config)
    reloaded = libconf.loads(dumped)

    assert ''.join(reloaded.keys()) == 'libconf'
示例#12
0
def test_dump_special_characters_roundtrip():
    d = {'a': ({'b': [u"\x00 \n \x7f abc \xff \u2603"]}, )}
    d2 = libconf.loads(libconf.dumps(d))
    assert d == d2
import json

import matplotlib.pyplot as plt
import numpy as np

parser = argparse.ArgumentParser()
add_common_arguments(parser)
args = parser.parse_args()

base_path_man = path_manager(args.root_data_dir,
                             args.root_output_dir,
                             data_dir_prefix=args.data_prefix)
base_path_man.ensure_directories()

with open(base_path_man.get_superhalo_config_file(), 'r') as config_file:
    config = libconf.loads(config_file.read().decode('utf8'))

catalog_helpers = {}

sim_numbers = config['all_sim_nums']

superhalo_data = config['superhalos']

num_halos = []
job_time = []

for sim_num in sim_numbers:
    path_man = path_manager(args.root_data_dir,
                            args.root_output_dir,
                            sim_num=("%i" % sim_num),
                            snap_name=config['time_slice'],
示例#14
0
def uesimsi(imsi):
    if not type_check(imsi, "imsi"):
        return '{ "message" : "wrong imsi format" }'
    if request.method == 'GET':  # read ue
        res = requests.get(ems_conf['amf-service_url'] + "/ues")
        if res.status_code == requests.codes.ok:
            data = json.loads(res.text)
            if "uelist" in data:
                for ue in data["uelist"]:
                    if ue["imsi"].replace('.', '') == imsi.replace('.', ''):
                        return ue
            # search in conf
            for ue in config["UE_INFO"]:
                if ue["imsi"].replace('.', '') == imsi.replace('.', ''):
                    ue_tmp = {}
                    ue_tmp["imsi"] = imsi
                    ue_tmp["uekey"] = ue["key"]["k"]
                    ue_tmp["status"] = "DISCONNECTED"
                    return ue_tmp
            return '{ "message" : "ue not exist" }'
        else:
            return '{ "message" : "cannot get data from amf-service" }'
    elif request.method == 'PUT':  # update ue
        # update ue in config
        for ue in config["UE_INFO"]:
            if ue["imsi"].replace('.', '') == imsi.replace('.', ''):
                ue_list_tmp = list(config["UE_INFO"])
                for i, ue_tmp in enumerate(ue_list_tmp):
                    if ue_tmp["imsi"].replace('.',
                                              '') == imsi.replace('.', ''):
                        req_data_str = request.data.decode('ascii')
                        # convert str to dict
                        req_dict = json.loads(req_data_str)
                        # convert dict to attrdict type string
                        req_gen_conf = gen_conf(req_dict)
                        # convert string to attrdict
                        new_ue = libconf.loads(req_gen_conf[1:-1])
                        if not type_check(new_ue, "key"):
                            return False
                        ue_list_tmp[i]["key"] = new_ue
                        break
                config["UE_INFO"] = tuple(ue_list_tmp)
                configReadWrite.writeConfig(config, 'conf/all.conf')
                configReadWrite.genNfConf(config, containers)
                # update ue in 5gc
                put_data = {}
                put_data["k"] = new_ue["k"]
                if "op" in new_ue:
                    put_data["op"] = new_ue["op"]
                if "opc" in new_ue:
                    put_data["opc"] = new_ue["opc"]
                imsi = imsi.replace('.', '')
                res = requests.put(ems_conf['amf-service_url'] + "/ues/" +
                                   imsi[:3] + "." + imsi[3:5] + "." + imsi[5:],
                                   data=json.dumps(put_data))
                if res.status_code == requests.codes.ok:
                    return '{ "message" : "ue updated" }'
                else:
                    return '{ "message" : "cannot update ue in amf" }'
        return '{ "message" : "ue not exist" }'
    elif request.method == 'DELETE':  # delete ue
        # delete ue in config
        for ue in config["UE_INFO"]:
            if ue["imsi"].replace('.', '') == imsi.replace('.', ''):
                ue_list_tmp = list(config["UE_INFO"])
                for ue_tmp in ue_list_tmp:
                    if ue_tmp["imsi"].replace('.',
                                              '') == imsi.replace('.', ''):
                        ue_list_tmp.remove(ue_tmp)
                        break
                config["UE_INFO"] = tuple(ue_list_tmp)
                configReadWrite.writeConfig(config, 'conf/all.conf')
                configReadWrite.genNfConf(config, containers)
                # delete ue in 5gc
                imsi = imsi.replace('.', '')
                res = requests.delete(ems_conf['amf-service_url'] + "/ues/" +
                                      imsi[:3] + "." + imsi[3:5] + "." +
                                      imsi[5:])
                if res.status_code == requests.codes.ok:
                    return '{ "message" : "ue deleted" }'
                else:
                    return '{ "message" : "cannot delete ue in amf" }'
        return '{ "message" : "ue not exist" }'
示例#15
0
def test_nonexisting_include_raises():
    input = u'''@include "/NON_EXISTING_FILE/DOESNT_EXIST"'''
    with pytest.raises(libconf.ConfigParseError):
        libconf.loads(input)
示例#16
0
 def LoadCfgStr(self, dat):
     """
     Load a configuration string into our config structure
     """
     self.cfg = libconf.loads(dat)
示例#17
0
def test_string_merging():
    # Unicode characters are supported, \u escapes not.
    input = u"""s = "abc\x21def\n" /* comment */ "newline-" # second comment
                   "here \u2603 \\u2603";"""
    assert libconf.loads(input).s == u"abc\x21def\nnewline-here \u2603 \\u2603"
示例#18
0
def test_loads_maintains_dict_order():
    config = libconf.loads(u'''l: 1; i: 5; b: 3; c: 1; o: 9; n: 0; f: 7;''')
    assert ''.join(config.keys()) == 'libconf'
示例#19
0
def test_roundtrip_of_int64_values():
    s = u'a=2L;'
    s2 = libconf.dumps(libconf.loads(s))
    assert s == s2.replace(' ', '').replace('\n', '')
示例#20
0
def test_nonexisting_include_raises():
    input = u'''@include "/NON_EXISTING_FILE/DOESNT_EXIST"'''
    with pytest.raises(libconf.ConfigParseError):
        libconf.loads(input)
示例#21
0
def test_lists_support_trailing_comma():
    config = libconf.loads(u'''a: (1, 2, 3,);''')
    assert config.a == (1, 2, 3)
示例#22
0
def test_loads_of_bytes_throws():
    with pytest.raises(TypeError) as excinfo:
        libconf.loads(b'')

    assert 'libconf.loads' in str(excinfo.value)
示例#23
0
def test_arrays_support_trailing_comma():
    config = libconf.loads(u'''a: [1, 2, 3,];''')
    assert config.a == [1, 2, 3]
示例#24
0
def test_loads_of_bytes_throws():
    with pytest.raises(TypeError) as excinfo:
        libconf.loads(b'')

    assert 'libconf.loads' in str(excinfo.value)
示例#25
0
def test_dump_special_characters_roundtrip():
    d = {'a': ({'b': [u"\x00 \n \x7f abc \xff \u2603"]},)}
    d2 = libconf.loads(libconf.dumps(d))
    assert d == d2