Init folder for HW Xapp 84/2884/1
authorsjana <sj492a@att.com>
Thu, 19 Mar 2020 17:42:14 +0000 (13:42 -0400)
committersjana <sj492a@att.com>
Thu, 19 Mar 2020 17:42:14 +0000 (13:42 -0400)
Issue-ID: RICAPP-63

Signed-off-by: sjana <sj492a@att.com>
Change-Id: Id72d609d10b8ac21be4f945287290e9afe60070a

init/config-file.json [new file with mode: 0644]
init/init_script.py [new file with mode: 0644]
init/schema.json [new file with mode: 0644]

diff --git a/init/config-file.json b/init/config-file.json
new file mode 100644 (file)
index 0000000..aa9e4c2
--- /dev/null
@@ -0,0 +1,38 @@
+{
+    "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"],
+       "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"],
+       "file_path":"/tmp/routeinfo/routes.txt",
+       "contents": "newrt|start\nrte|0|localhost:4560\nrte|2|localhost:38000\nrte|10002|localhost:4560\nrte|10005|localhost:4560\nrte|10003|localhost:38000\nrte|12010|localhost:38000\nrte|12020|localhost:38000\nrte|12011|localhost:4560\nrte|12012|localhost:4560\nrte|12021|localhost:4560\nrte|12022|localhost:4560\nrte|20000|localhost:4560\nrte|12040|localhost:38000\nrte|20001|localhost:4566\nrte|20011|localhost:4560\nrte|20012|localhost:4560\nnewrt|end"
+    },
+    
+    "envs":{
+       "RMR_SEED_RT":"../src/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"
+
+    }
+}
diff --git a/init/init_script.py b/init/init_script.py
new file mode 100644 (file)
index 0000000..b88ca35
--- /dev/null
@@ -0,0 +1,189 @@
+#==================================================================================
+
+#        Copyright (c) 2018-2019 AT&T Intellectual Property.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#==================================================================================
+
+#
+# Author : Ashwin Sridharan
+#   Date    : Feb 2019
+#
+
+
+# This initialization script reads in a json from the specified config map path
+# to set up the initializations (route config map, variables etc) for the main
+# xapp process
+
+import json;
+import sys;
+import os;
+import signal;
+import time;
+
+
+def signal_handler(signum, frame):
+    print("Received signal {0}\n".format(signum));
+    if(xapp_subprocess == None or xapp_pid == None):
+        print("No xapp running. Quiting without sending signal to xapp\n");
+    else:
+        print("Sending signal {0} to xapp ...".format(signum));
+        xapp_subprocess.send_signal(signum);
+        
+
+def parseConfigJson(config):
+    for key in config:
+        print("Processing ", key);
+        if key in ParseSection:
+            result = ParseSection[key](config);
+            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:
+        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;
+
+default_routing_file = "../src/routes.txt";
+
+
+#================================================================
+if __name__ == "__main__":
+
+    import subprocess;
+    cmd = ["../src/hw_xapp_main"];
+    if xapp_port > 0:
+        cmd.append("-p");
+        cmd.append(xapp_port);
+        
+    if len(sys.argv) > 1:
+        config_file = sys.argv[1];
+    else:
+        print("Error! No configuration file specified\n");
+        sys.exit(1);
+        
+    if len(sys.argv) > 2:
+        cmd[0] = sys.argv[2];
+
+    with open(config_file, 'r') as f:
+         try:
+             config = json.load(f);
+         except Exception as e:
+             print(("Error loading json file from {0}. Reason = {1}\n".format(config_file, e)));
+             sys.exit(1);
+             
+    result = parseConfigJson(config);
+
+    if result == False:
+        print("Error parsing json. Not executing xAPP");
+        sys.exit(1);
+
+    else:
+
+        # Register signal handlers
+        signal.signal(signal.SIGINT, signal_handler);
+        signal.signal(signal.SIGTERM, signal_handler);
+
+        # Start the xAPP
+        #print("Executing xAPP ....");
+        xapp_subprocess = subprocess.Popen(cmd, shell = False, stdin=None, stdout=None, stderr = None);
+        xapp_pid = xapp_subprocess.pid;
+
+        # Periodically poll the process every 5 seconds to check if still alive
+        while(1):
+            xapp_status = xapp_subprocess.poll();
+            if xapp_status == None:
+                time.sleep(5);
+            else:
+                print("XaPP terminated via signal {0}\n".format(-1 * xapp_status));
+                break;
+                
diff --git a/init/schema.json b/init/schema.json
new file mode 100644 (file)
index 0000000..3d8f476
--- /dev/null
@@ -0,0 +1,229 @@
+{
+  "definitions": {},
+  "$schema": "http://json-schema.org/draft-07/schema#",
+  "$id": "http://example.com/root.json",
+  "type": "object",
+  "title": "The Root Schema",
+  "required": [
+    "service_ports",
+    "rmr",
+    "envs"
+  ],
+  "properties": {
+    "service_ports": {
+      "$id": "#/properties/service_ports",
+      "type": "object",
+      "title": "The Service_ports Schema",
+      "required": [
+        "xapp_port",
+        "rmr_port"
+      ],
+      "properties": {
+        "xapp_port": {
+          "$id": "#/properties/service_ports/properties/xapp_port",
+          "type": "integer",
+          "title": "The Xapp_port Schema",
+          "default": 0,
+          "examples": [
+            4560
+          ]
+        },
+        "rmr_port": {
+          "$id": "#/properties/service_ports/properties/rmr_port",
+          "type": "integer",
+          "title": "The Rmr_port Schema",
+          "default": 0,
+          "examples": [
+            4561
+          ]
+        }
+      }
+    },
+    "rmr": {
+      "$id": "#/properties/rmr",
+      "type": "object",
+      "title": "The Rmr Schema",
+      "required": [
+        "protPort",
+        "maxSize",
+        "numWorkers",
+        "txMessages",
+        "rxMessages",
+        "file_path",
+        "contents"
+      ],
+      "properties": {
+        "protPort": {
+          "$id": "#/properties/rmr/properties/protPort",
+          "type": "string",
+          "title": "The Protport Schema",
+          "default": "",
+          "examples": [
+            "tcp:4560"
+          ],
+          "pattern": "^(.*)$"
+        },
+        "maxSize": {
+          "$id": "#/properties/rmr/properties/maxSize",
+          "type": "integer",
+          "title": "The Maxsize Schema",
+          "default": 0,
+          "examples": [
+            2072
+          ]
+        },
+        "numWorkers": {
+          "$id": "#/properties/rmr/properties/numWorkers",
+          "type": "integer",
+          "title": "The Numworkers Schema",
+          "default": 0,
+          "examples": [
+            1
+          ]
+        },
+        "txMessages": {
+          "$id": "#/properties/rmr/properties/txMessages",
+          "type": "array",
+          "title": "The Txmessages Schema",
+          "items": {
+            "$id": "#/properties/rmr/properties/txMessages/items",
+            "type": "string",
+            "title": "The Items Schema",
+            "default": "",
+            "examples": [
+              "RIC_SUB_REQ",
+              "RIC_SUB_DEL_REQ"
+            ],
+            "pattern": "^(.*)$"
+          }
+        },
+        "rxMessages": {
+          "$id": "#/properties/rmr/properties/rxMessages",
+          "type": "array",
+          "title": "The Rxmessages Schema",
+          "items": {
+            "$id": "#/properties/rmr/properties/rxMessages/items",
+            "type": "string",
+            "title": "The Items Schema",
+            "default": "",
+            "examples": [
+              "RIC_SUB_RESP",
+              "RIC_SUB_FAILURE",
+              "RIC_SUB_DEL_RESP",
+              "RIC_SUB_DEL_FAILURE",
+              "RIC_INDICATION"
+            ],
+            "pattern": "^(.*)$"
+          }
+        },
+        "file_path": {
+          "$id": "#/properties/rmr/properties/file_path",
+          "type": "string",
+          "title": "The File_path Schema",
+          "default": "",
+          "examples": [
+            "/tmp/routeinfo/routes.txt"
+          ],
+          "pattern": "^(.*)$"
+        },
+        "contents": {
+          "$id": "#/properties/rmr/properties/contents",
+          "type": "string",
+          "title": "The Contents Schema",
+          "default": "",
+          "examples": [
+            "newrt|start\nrte|0|localhost:4560\nrte|2|localhost:4591\nrte|10002|localhost:4560\nrte|10005|localhost:4560\nrte|10003|localhost:4591\nrte|12010|localhost:4591\nrte|12020|localhost:4591\nrte|12011|localhost:4560\nrte|12012|localhost:4560\nrte|12021|localhost:4560\nrte|12022|localhost:4560\nrte|20000|localhost:4560\nrte|20001|localhost:4566\nnewrt|end "
+          ],
+          "pattern": "^(.*)$"
+        }
+      }
+    },
+    "envs": {
+      "$id": "#/properties/envs",
+      "type": "object",
+      "title": "The Envs Schema",
+      "required": [
+        "gNodeB",
+        "THREADS",
+        "A1_SCHEMA_FILE",
+        "VES_SCHEMA_FILE",
+        "SAMPLE_FILE",
+        "VES_COLLECTOR_URL",
+        "VES_MEAUSUREMENT_INTERVAL"
+      ],
+      "properties": {
+        "gNodeB": {
+          "$id": "#/properties/envs/properties/gNodeB",
+          "type": "string",
+          "title": "The Gnodeb Schema",
+          "default": "",
+          "examples": [
+            "NYC123"
+          ],
+          "pattern": "^(.*)$"
+        },
+        "THREADS": {
+          "$id": "#/properties/envs/properties/THREADS",
+          "type": "string",
+          "title": "The Threads Schema",
+          "default": "",
+          "examples": [
+            "1"
+          ],
+          "pattern": "^(.*)$"
+        },
+        "A1_SCHEMA_FILE": {
+          "$id": "#/properties/envs/properties/A1_SCHEMA_FILE",
+          "type": "string",
+          "title": "The A1_schema_file Schema",
+          "default": "",
+          "examples": [
+            "/etc/xapp/adm-ctrl-xapp-schema.json"
+          ],
+          "pattern": "^(.*)$"
+        },
+        "VES_SCHEMA_FILE": {
+          "$id": "#/properties/envs/properties/VES_SCHEMA_FILE",
+          "type": "string",
+          "title": "The Ves_schema_file Schema",
+          "default": "",
+          "examples": [
+            "/etc/xapp/ves_schema.json"
+          ],
+          "pattern": "^(.*)$"
+        },
+        "SAMPLE_FILE": {
+          "$id": "#/properties/envs/properties/SAMPLE_FILE",
+          "type": "string",
+          "title": "The Sample_file Schema",
+          "default": "",
+          "examples": [
+            "/etc/xapp/samples.json"
+          ],
+          "pattern": "^(.*)$"
+        },
+        "VES_COLLECTOR_URL": {
+          "$id": "#/properties/envs/properties/VES_COLLECTOR_URL",
+          "type": "string",
+          "title": "The Ves_collector_url Schema",
+          "default": "",
+          "examples": [
+            "127.0.0.1:6350"
+          ],
+          "pattern": "^(.*)$"
+        },
+        "VES_MEAUSUREMENT_INTERVAL": {
+          "$id": "#/properties/envs/properties/VES_MEAUSUREMENT_INTERVAL",
+          "type": "string",
+          "title": "The Ves_meausurement_interval Schema",
+          "default": "",
+          "examples": [
+            "10"
+          ],
+          "pattern": "^(.*)$"
+        }
+      }
+    }
+  }
+}
+