1 # Copyright (c) 2019 AT&T Intellectual Property.
2 # Copyright (c) 2019 Nokia.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 from redis import Redis
20 class E2SimUtils(object):
21 def __init__(self, dbaas, port=int(6379)):
23 self._db = Redis(host=dbaas, port=port)
25 def sdlKey(self, namespace, val):
26 return "{%s},%s" % (namespace, val)
28 def sdlKeyNamespace(self, k):
29 return k.split(",")[0][1:-1]
31 def sdlKeyVal(self, k):
32 return k.split(",")[1]
34 def e2RANKey(self, val):
35 return self.sdlKey("e2Manager", "RAN:" + val)
37 def e2RANKeyVal(self, k):
38 return self.sdlKeyVal(k).split(':')[-1]
40 def gNodeB(self, ranName="*"):
41 # return one or (by default) all e2 records
43 for k in self._db.keys(self.e2RANKey(ranName)):
44 gnbs[self.e2RANKeyVal(k.decode('utf-8'))]=self._db.get(k)
47 def gNodeBDelete(self, ranName="*"):
48 # delete one or (by default) all e2 records
49 # returns the deleted records to avoid
51 gnbs = self.gNodeB(ranName)
53 self._db.delete(self.e2RANKey(k))
56 def randomRANName(self, prefix=""):
57 prefix = prefix + ''.join(random.choice(string.ascii_uppercase) for _ in range(4-(min(4, len(prefix)))))
58 return prefix[0:4].upper() + ''.join(random.choice(string.digits) for _ in range(6))