X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=ric_robot_suite%2Fric-python-utils%2Fricutils%2FE2SimUtils.py;fp=ric_robot_suite%2Fric-python-utils%2Fricutils%2FE2SimUtils.py;h=d5f3fa18c6bd4d7a4ecad8cdb864edd7d31eae0d;hb=c5fa07bcd8cbd614bcd813cac698385b789bcfcb;hp=0000000000000000000000000000000000000000;hpb=59f84608ec15c016958a6e0e0ddd813f376c0925;p=it%2Ftest.git diff --git a/ric_robot_suite/ric-python-utils/ricutils/E2SimUtils.py b/ric_robot_suite/ric-python-utils/ricutils/E2SimUtils.py new file mode 100644 index 0000000..d5f3fa1 --- /dev/null +++ b/ric_robot_suite/ric-python-utils/ricutils/E2SimUtils.py @@ -0,0 +1,58 @@ +# Copyright (c) 2019 AT&T Intellectual Property. +# Copyright (c) 2019 Nokia. +# +# 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. + +from redis import Redis +import string +import random + +class E2SimUtils(object): + def __init__(self, dbaas, port=int(6379)): + + self._db = Redis(host=dbaas, port=port) + + def sdlKey(self, namespace, val): + return "{%s},%s" % (namespace, val) + + def sdlKeyNamespace(self, k): + return k.split(",")[0][1:-1] + + def sdlKeyVal(self, k): + return k.split(",")[1] + + def e2RANKey(self, val): + return self.sdlKey("e2Manager", "RAN:" + val) + + def e2RANKeyVal(self, k): + return self.sdlKeyVal(k).split(':')[-1] + + def gNodeB(self, ranName="*"): + # return one or (by default) all e2 records + gnbs={} + for k in self._db.keys(self.e2RANKey(ranName)): + gnbs[self.e2RANKeyVal(k.decode('utf-8'))]=self._db.get(k) + return gnbs + + def gNodeBDelete(self, ranName="*"): + # delete one or (by default) all e2 records + # returns the deleted records to avoid + # buyer's remorse. + gnbs = self.gNodeB(ranName) + for k in gnbs: + self._db.delete(self.e2RANKey(k)) + return gnbs + + def randomRANName(self, prefix=""): + prefix = prefix + ''.join(random.choice(string.ascii_uppercase) for _ in range(4-(min(4, len(prefix))))) + return prefix[0:4].upper() + ''.join(random.choice(string.digits) for _ in range(6))