From 3baf0b7442b45212ad859904fb061c3de4daef69 Mon Sep 17 00:00:00 2001 From: sjana Date: Sun, 3 May 2020 21:48:26 -0400 Subject: [PATCH] Incorporating changes to Xapp Descriptor Issue-ID: RICAPP-99 Signed-off-by: sjana Change-Id: Ifba457ecb7a309687346cdad4b29a571121f378e --- init/config-file.json | 122 ++++++++++++++++++++++++++++++++++---------------- init/init_script.py | 119 +++++++++++++----------------------------------- init/routes.txt | 13 ++++++ 3 files changed, 126 insertions(+), 128 deletions(-) create mode 100644 init/routes.txt diff --git a/init/config-file.json b/init/config-file.json index a3ca2e7..d4db879 100644 --- a/init/config-file.json +++ b/init/config-file.json @@ -1,39 +1,83 @@ -{ - "service_ports":{ - "xapp_port":4560, - "rmr_port":4561 - }, - - "rmr":{ - "protPort": "tcp:4560", - "maxSize": 2072, - "numWorkers": 1, - "txMessages": ["RIC_SUB_REQ", "RIC_SUB_DEL_REQ", "RIC_CONTROL_REQ", "A1_POLICY_RESP", "A1_POLICY_QUERY","RIC_HEALTH_CHECK_RESP"], - "rxMessages": ["RIC_SUB_RESP", "RIC_SUB_FAILURE", "RIC_SUB_DEL_RESP", "RIC_SUB_DEL_FAILURE", "RIC_INDICATION", "RIC_CONTROL_ACK", "RIC_CONTROL_FAILURE","RIC_HEALTH_CHECK_REQ", "A1_POLICY_REQ"], - "policies": ["1","00000"], - "file_path":"/tmp/routeinfo/routes.txt", - "contents": "newrt|start\nrte|0|127.0.0.1:4560\nrte|100|127.0.0.1:4560\nrte|2|127.0.0.1:38000\nrte|10002|127.0.0.1:4560\nrte|10005|127.0.0.1:4560\nrte|10003|127.0.0.1:38000\nrte|12010|127.0.0.1:38000\nrte|12020|127.0.0.1:38000\nrte|12011|127.0.0.1:4560\nrte|12012|127.0.0.1:4560\nrte|12021|127.0.0.1:4560\nrte|12022|127.0.0.1:4560\nrte|20000|127.0.0.1:4560\nrte|12040|127.0.0.1:38000\nrte|20001|127.0.0.1:4566\nrte|20010|127.0.0.1:4560\nrte|20012|127.0.0.1:4560\nnewrt|end" - }, - - "envs":{ - "RMR_SEED_RT":"/tmp/routeinfo/routes.txt", - "RMR_RTG_SVC":"9999", - "DBAAS_SERVICE_HOST":"127.0.0.1", - "DBAAS_SERVICE_PORT":"6379", - "XAPP_NAME":"HELLOWORLD_XAPP", - "HW_PORTS":"4560", - "MSG_MAX_BUFFER":"2048", - "THREADS":"1", - "VERBOSE":"0", - "CONFIG_FILE":"config-file.json", - "GNODEB":"NYC123", - "XAPP_ID":"3489-er492k-92389", - "A1_SCHEMA_FILE":"schemas/hwxapp-policy.json", - "VES_SCHEMA_FILE":"schemas/hwxapp-ves.json", - "VES_COLLECTOR_URL":"127.0.0.1:6350", - "VES_MEASUREMENT_INTERVAL":"10", - "LOG_LEVEL":"MDCLOG_ERR", - "OPERATING_MODE":"REPORT" - - } -} +{ + "config-file.json": { + "xapp_name": "hwxapp", + "version": "1.0.0", + "containers": [ + { + "name": "hwxapp", + "image": { + "registry": "nexus3.o-ran-sc.org:10002", + "name": "o-ran-sc/ric-app-hw", + "tag": "0.0.1" + }, + "command": "python3 init.py config-file.json" + } + ], + "livenessProbe": { + "exec": { + "command": [ + "/usr/local/bin/health_ck" + ] + }, + "initialDelaySeconds": 5, + "periodSeconds": 15 + }, + "messaging": { + "ports": [ + { + "name": "rmr-data", + "container": "hwxapp", + "port": 4560, + "rxMessages": [ + "RIC_SUB_RESP", + "RIC_SUB_FAILURE", + "RIC_SUB_DEL_RESP", "RIC_SUB_DEL_FAILURE", "RIC_INDICATION", "RIC_CONTROL_ACK", "RIC_CONTROL_FAILURE", "A1_POLICY_REQ", "RIC_HEALTH_CHECK_REQ" + ], + "txMessages": [ "RIC_SUB_REQ", "RIC_SUB_DEL_REQ", "RIC_CONTROL_REQ", "A1_POLICY_RESP", "A1_POLICY_QUERY", "RIC_HEALTH_CHECK_RESP" ], + "policies": [1], + "description": "rmr receive data port for HWxapp" + }, + { + "name": "rmr-route", + "container": "hwxapp", + "port": 4561, + "description": "rmr route port for hwxapp" + } + ] + }, + "controls": { + "ves_collector_address": "xapp-sandbox2.research.att.com:8888" + }, + "rmr": { + "protPort": "tcp:4560", + "maxSize": 2072, + "numWorkers": 1, + "txMessages": [ + "RIC_SUB_REQ", "RIC_SUB_DEL_REQ", "RIC_CONTROL_REQ", "A1_POLICY_RESP", "A1_POLICY_QUERY", "RIC_HEALTH_CHECK_RESP" + ], + "rxMessages": [ + "RIC_SUB_RESP", + "RIC_SUB_FAILURE", + "RIC_SUB_DEL_RESP", "RIC_SUB_DEL_FAILURE", "RIC_INDICATION", "RIC_CONTROL_ACK", "RIC_CONTROL_FAILURE", "A1_POLICY_REQ", "RIC_HEALTH_CHECK_REQ" + ] + } + }, + "controls-schema.json": { + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "#/controls", + "type": "object", + "title": "Controls Section Schema", + "required": [], + "properties": { + "ves_collector_address": { + "$id": "#/controls/ves_collector_address", + "type": "string", + "title": "ves_collector_address", + "default": "localhost:8080", + "examples": [ + "localhost:8080" + ] + } + } + } +} \ No newline at end of file diff --git a/init/init_script.py b/init/init_script.py index c6c1421..85f00d1 100644 --- a/init/init_script.py +++ b/init/init_script.py @@ -42,98 +42,42 @@ def signal_handler(signum, frame): def parseConfigJson(config): - for key in config: - print("Processing ", key); - if key in ParseSection: - result = ParseSection[key](config); - if result == False: - return False; + for k1 in config.keys(): + for k2 in config[k1].keys(): + #print(k2); + if k2 in ParseSection: + result = ParseSection[k2](config[k1]); + if result == False: + return False; - -def getRMRTable(config): - myKey= "rmr"; - if myKey not in config: - print(("Error ! No information found for {0} in config\n".format(myKey))); - return False; - # Get the rmr routing table - if "file_path" not in config[myKey]: - print(("Warning ! No file path specified to store seed routing table. Choosing default = {1}\n".format(default_routing_file))); - route_file = default_routing_file; - else: - route_file = config[myKey]["file_path"]; - - # Get the rmr routing table contents - if "contents" not in config[myKey]: - print("No contents for routing table found in config"); - return False; - else: - route_contents = config[myKey]["contents"]; - # Get directory : if not exists create it - directory = os.path.dirname(route_file); - if not os.path.exists(directory): - # create directory - try: - os.mkdir(directory); - except OSError as oe: - print(("Error making directory {0}. Reason = {1}\n".format(directory, oe))); - return False; - - # Write contents to file - try: - with open(route_file, "w") as f : - f.write(config[myKey]["contents"]); - f.close(); - except Exception as e: - print(("Error writing contents to file {0}. Reason = {1}\n".format(route_file, e))); - return False; - - # Set the environment variable - os.environ["RMR_SEED_RT"] = route_file; - -def getPort(config): - myKey = "service_ports"; - if myKey not in config: +def getMessagingInfo(config): + if 'messaging' in config.keys() and 'ports' in config['messaging'].keys(): + port_list = config['messaging']['ports'] + for portdesc in port_list : + if 'port' in portdesc.keys() and 'name' in portdesc.keys() and portdesc['name'] == 'rmr-data': + lport = portdesc['port'] + # Set the environment variable + os.environ["HW_PORT"] = str(lport) + return True; + if lport == 0: + print("Error! No valid listening port"); + return False; + +def getXappName(config): + myKey = "xapp_name"; + if myKey not in config.keys(): print(("Error ! No information found for {0} in config\n".format(myKey))); return False; - port_config = config[myKey]; - if "xapp_port" in port_config: - try: - xapp_port = int(port_config["xapp_port"]); - if xapp_port < 1024: - raise Exception("Port must be > 1024"); - except Exception as e: - print(("Error processing xapp port {0}. Reason = {1}\n".format(port_config["xapp_port"], e))); - return False; - else: - xapp_port = 0; - - -def getEnvs(config): - myKey = "envs"; - if myKey not in config: - print(("Error ! No information found for {0} in config\n".format(myKey))); - return False; - - env_config = config[myKey]; - - for env_key in env_config: - os.environ[env_key] = env_config[env_key]; - print("Set environment variable {0} = {1}\n".format(env_key, os.environ[env_key])); - - return True; - - -# Global variables ... -xapp_subprocess = None; -xapp_pid = None; -ParseSection = {}; -xapp_port = 0; -ParseSection["rmr"] = getRMRTable; -ParseSection["envs"] = getEnvs; + xapp_name = config[myKey]; + os.environ["XAPP_NAME"] = xapp_name; default_routing_file = "/tmp/routeinfo/routes.txt"; +lport = 0; +ParseSection = {}; +ParseSection["xapp_name"] = getXappName; +ParseSection["messaging"] = getMessagingInfo; #================================================================ @@ -142,9 +86,6 @@ if __name__ == "__main__": import subprocess; # cmd = ["../src/hw_xapp_main"]; cmd = ["/usr/local/bin/hw_xapp_main"]; - if xapp_port > 0: - cmd.append("-p"); - cmd.append(xapp_port); if len(sys.argv) > 1: config_file = sys.argv[1]; @@ -163,7 +104,7 @@ if __name__ == "__main__": sys.exit(1); result = parseConfigJson(config); - + time.sleep(10); if result == False: print("Error parsing json. Not executing xAPP"); sys.exit(1); diff --git a/init/routes.txt b/init/routes.txt new file mode 100644 index 0000000..02fb39f --- /dev/null +++ b/init/routes.txt @@ -0,0 +1,13 @@ +newrt|start +rte|100|127.0.0.1:4560 +rte|101|127.0.0.1:38000 +rte|20010|127.0.0.1:4560 +rte|20011|127.0.0.1:38000 +rte|20012|127.0.0.1:4560 +rte|12010|127.0.0.1:38000 +rte|12011|127.0.0.1:4560 +rte|12012|127.0.0.1:4560 +rte|12020|127.0.0.1:38000 +rte|12021|127.0.0.1:4560 +rte|12022|127.0.0.1:4560 +newrt|end -- 2.16.6