Commit e455386f authored by Lu Xu's avatar Lu Xu 👀

WIP

parent bc349eae
#!{{ python_path }}
import json
import logging
from logging.handlers import RotatingFileHandler
import time
from websocket import create_connection
class enbWebSocket:
def __init__(self):
log_file = "{{ log_file }}"
self.logger = logging.getLogger('logger')
self.logger.setLevel(logging.INFO)
handler = RotatingFileHandler(log_file, maxBytes=30000, backupCount=2)
formatter = logging.Formatter('{"time": "%(asctime)s", "log_level": "%(levelname)s", "message": "%(message)s", "data": %(data)s}')
handler.setFormatter(formatter)
self.logger.addHandler(handler)
if {{ testing }}:
return
self.ws_url = "ws://127.0.1.2:9001"
self.ws = create_connection(self.ws_url)
def close(self):
if {{ testing }}:
return
self.ws.close()
def send(self, msg):
self.ws.send(json.dumps(msg))
def recv(self, message_type):
for i in range(1,20):
r = json.loads(self.ws.recv())
if r['message'] == message_type:
return r
def stats(self):
if {{ testing }}:
r = {
'message': 'rf',
'rf_info': "CPRI: x16 HW SW\n"
}
else:
self.send({
"message": "rf",
"rf_info": True
})
r = self.recv('rf')
self.logger.info('RF info', extra={'data': r})
if __name__ == '__main__':
ws = enbWebSocket()
try:
while True:
ws.stats()
time.sleep({{ stats_period }})
finally:
ws.close()
......@@ -16,19 +16,27 @@
[template]
filename = instance.cfg
md5sum = 61e9685d6aa973ae0c45c45ca357458a
md5sum = 4157948de24b3752047093b57adab631
[amarisoft-stats.jinja2.py]
_update_hash_filename_ = amarisoft-stats.jinja2.py
md5sum = 6e0a052bd0ca08cc0c7b4880d3deffcc
[amarisoft-rf-info.jinja2.py]
_update_hash_filename_ = amarisoft-rf-info.jinja2.py
md5sum = c930c28365c685a6066f382c9b5d8893
[lopcomm-rrh-stats.jinja2.py]
_update_hash_filename_ = lopcomm-rrh-stats.jinja2.py
md5sum = 39e191080722ac13ebc56b1e6350eb8f
[template-lte-enb-epc]
_update_hash_filename_ = instance-enb-epc.jinja2.cfg
md5sum = 833667743c693b8d5f78a2527b275a9e
[template-lte-enb]
_update_hash_filename_ = instance-enb.jinja2.cfg
md5sum = afd8867c4dec5c5c68a4005dec502ebb
md5sum = 3bbe1634ad650d0c93252c4822ffe616
[template-lte-gnb-epc]
_update_hash_filename_ = instance-gnb-epc.jinja2.cfg
......@@ -40,7 +48,7 @@ md5sum = 99c05a34678adb5a70aa64ecf2ee4e35
[template-lte-gnb]
_update_hash_filename_ = instance-gnb.jinja2.cfg
md5sum = cd0527037b7cb0ae53f2f822fcf551ac
md5sum = a897d8cd4c4022ca8f9812de5dbb6669
[template-lte-mme]
_update_hash_filename_ = instance-mme.jinja2.cfg
......@@ -60,7 +68,7 @@ md5sum = dcaac06553a3222b14c0013a13f4a149
[enb.jinja2.cfg]
filename = config/enb.jinja2.cfg
md5sum = d6cf05433937853960006b7f1f73c04f
md5sum = d424edfb2960779a4f8d5af760bee15b
[sib23.asn]
filename = config/sib23.asn
......@@ -117,3 +125,7 @@ md5sum = 6812310b65c2d95815afc2b034a5f90f
[interface-up-promise]
_update_hash_filename_ = promise/check_interface_up.py
md5sum = 44ae5693f62b7a4dbc98f700f68d8600
[vswr-promise]
_update_hash_filename_ = promise/check_vswr.py
md5sum = a639d6273413fe23ba97a8920fb1ac12
#define TDD 1
#define N_RB_DL {{ slapparameter_dict.get('n_rb_dl', slap_configuration['configuration.default_lte_n_rb_dl']) }}
#define N_ANTENNA_DL 2
#define N_ANTENNA_UL 2
......@@ -15,7 +14,8 @@
cpri_mult: 16,
cpri_rx_delay: 0,
cpri_tx_delay: 0,
ifname: "cpri0",
ifname: "{{ slap_configuration.get('tap-name', '') }}",
cpri_debug: 2,
},
tx_gain: 0,
rx_gain: 0,
......@@ -92,7 +92,8 @@
n_antenna_dl: N_ANTENNA_DL,
n_antenna_ul: N_ANTENNA_UL,
{% if slapparameter_dict.get('rrh', '') == "Lopcomm ORAN" %}
{% pass %}
// uldl_config: 2,
// sp_config: 7,
{% else %}
uldl_config: 2,
sp_config: 7,
......@@ -153,7 +154,7 @@
n1_pucch_sr_count: 11,
cqi_pucch_n_rb: 1,
{% if slapparameter_dict.get('rrh', '') == "Lopcomm ORAN" %}
{% pass %}
// tdd_ack_nack_feedback_mode: "multiplexing",
{% else %}
tdd_ack_nack_feedback_mode: "multiplexing",
{% endif %}
......
......@@ -5,11 +5,16 @@ parts =
lte-enb-config
lte-enb-service
amarisoft-stats-service
amarisoft-rf-info-service
sdr-busy-promise
cell-gain-saturated-promise
rx-saturated-promise
baseband-latency-promise
amarisoft-stats-log-promise
{% if slapparameter_dict.get('rrh', '') == "Lopcomm ORAN" %}
lopcomm-rrh-stats-service
vswr-promise
{% endif %}
{% if not slapparameter_dict.get("sub-instance", False) %}
cpu-temperature-promise
{% endif %}
......@@ -120,7 +125,37 @@ mode = 0775
url = {{ amarisoft_stats_template }}
output = ${directory:bin}/amarisoft-stats.py
### eNodeB (enb)
[amarisoft-rf-info-template]
recipe = slapos.recipe.template:jinja2
extensions = jinja2.ext.do
log-output = ${directory:var}/log/amarisoft-rf-info.json.log
context =
section directory directory
key slapparameter_dict slap-configuration:configuration
key log_file :log-output
raw stats_period {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}
raw testing {{ slapparameter_dict.get("testing", False) }}
raw python_path {{ buildout_directory}}/bin/pythonwitheggs
mode = 0775
url = {{ amarisoft_rf_info_template }}
output = ${directory:bin}/amarisoft-rf-info.py
[lopcomm-rrh-stats-template]
recipe = slapos.recipe.template:jinja2
extensions = jinja2.ext.do
log-output = ${directory:var}/log/lopcomm-rrh-stats.log
json-log-output = ${directory:var}/log/lopcomm-rrh-stats.json.log
context =
section directory directory
key slapparameter_dict slap-configuration:configuration
key log_file :log-output
key json_log_file :json-log-output
raw testing {{ slapparameter_dict.get("testing", False) }}
raw python_path {{ buildout_directory}}/bin/pythonwitheggs
mode = 0775
url = {{ lopcomm_rrh_stats_template }}
output = ${directory:bin}/lopcomm-rrh-stats.py
[amarisoft-stats-service]
recipe = slapos.cookbook:wrapper
command-line = ${amarisoft-stats-template:output}
......@@ -129,6 +164,22 @@ mode = 0775
hash-files =
${amarisoft-stats-template:output}
[amarisoft-rf-info-service]
recipe = slapos.cookbook:wrapper
command-line = ${amarisoft-rf-info-template:output}
wrapper-path = ${directory:service}/amarisoft-rf-info
mode = 0775
hash-files =
${amarisoft-rf-info-template:output}
[lopcomm-rrh-stats-service]
recipe = slapos.cookbook:wrapper
command-line = ${lopcomm-rrh-stats-template:output}
wrapper-path = ${directory:service}/lopcomm-rrh-stats
mode = 0775
hash-files =
${lopcomm-rrh-stats-template:output}
[config-base]
recipe = slapos.recipe.template:jinja2
extensions = jinja2.ext.do
......@@ -206,6 +257,16 @@ config-stats-period = {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}
config-min-txrx-delay = {{ slapparameter_dict.get("min_txrx_delay", 5) }}
config-avg-txrx-delay = {{ slapparameter_dict.get("avg_txrx_delay", 7) }}
[vswr-promise]
recipe = slapos.cookbook:promise.plugin
eggs =
slapos.core
python-dateutil
file = {{ vswr_promise }}
output = ${directory:plugins}/check-vswr.py
config-testing = {{ slapparameter_dict.get("testing", False) }}
config-lopcomm-stats-log = ${lopcomm-rrh-stats-template:json-log-output}
[amarisoft-stats-log-promise]
recipe = slapos.cookbook:promise.plugin
eggs =
......
......@@ -5,6 +5,7 @@ parts =
lte-gnb-config
lte-enb-service
amarisoft-stats-service
amarisoft-rf-info-service
sdr-busy-promise
cell-gain-saturated-promise
rx-saturated-promise
......@@ -120,6 +121,21 @@ mode = 0775
url = {{ amarisoft_stats_template }}
output = ${directory:bin}/amarisoft-stats.py
[amarisoft-rf-info-template]
recipe = slapos.recipe.template:jinja2
extensions = jinja2.ext.do
log-output = ${directory:var}/log/amarisoft-rf-info.json.log
context =
section directory directory
key slapparameter_dict slap-configuration:configuration
key log_file :log-output
raw stats_period {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}
raw testing {{ slapparameter_dict.get("testing", False) }}
raw python_path {{ buildout_directory}}/bin/pythonwitheggs
mode = 0775
url = {{ amarisoft_rf_info_template }}
output = ${directory:bin}/amarisoft-rf-info.py
### eNodeB (enb)
[amarisoft-stats-service]
recipe = slapos.cookbook:wrapper
......@@ -129,6 +145,14 @@ mode = 0775
hash-files =
${amarisoft-stats-template:output}
[amarisoft-rf-info-service]
recipe = slapos.cookbook:wrapper
command-line = ${amarisoft-rf-info-template:output}
wrapper-path = ${directory:service}/amarisoft-rf-info
mode = 0775
hash-files =
${amarisoft-rf-info-template:output}
[config-base]
recipe = slapos.recipe.template:jinja2
extensions = jinja2.ext.do
......
......@@ -32,7 +32,7 @@ context =
recipe = slapos.recipe.build
init =
import os
lte_version = "2021-09-18"
lte_version = "2022-10-27"
path = "/opt/amarisoft/v" + lte_version
options['lte-version'] = lte_version
options['path'] = path
......@@ -110,12 +110,15 @@ extra-context =
raw sib23 ${sib23.asn:target}
raw ltelogs_template ${ltelogs.jinja2.sh:target}
raw amarisoft_stats_template ${amarisoft-stats.jinja2.py:target}
raw amarisoft_rf_info_template ${amarisoft-rf-info.jinja2.py:target}
raw lopcomm_rrh_stats_template ${lopcomm-rrh-stats.jinja2.py:target}
raw sdr_busy_promise ${sdr-busy-promise:target}
raw cell_gain_saturated_promise ${cell-gain-saturated-promise:target}
raw rx_saturated_promise ${rx-saturated-promise:target}
raw baseband_latency_promise ${baseband-latency-promise:target}
raw amarisoft_stats_log_promise ${amarisoft-stats-log-promise:target}
raw cpu_temperature_promise ${cpu-temperature-promise:target}
raw vswr_promise ${vswr-promise:target}
raw openssl_location ${openssl:location}
raw default_dl_earfcn ${default-params:default-dl-earfcn}
raw default_lte_dl_freq ${default-params:default-lte-dl-freq}
......@@ -139,6 +142,7 @@ extra-context =
raw gnb_template ${gnb.jinja2.cfg:target}
raw ltelogs_template ${ltelogs.jinja2.sh:target}
raw amarisoft_stats_template ${amarisoft-stats.jinja2.py:target}
raw amarisoft_rf_info_template ${amarisoft-rf-info.jinja2.py:target}
raw sdr_busy_promise ${sdr-busy-promise:target}
raw cell_gain_saturated_promise ${cell-gain-saturated-promise:target}
raw rx_saturated_promise ${rx-saturated-promise:target}
......
#!{{ python_path }}
import json
import logging
import time
import xmltodict
from logging.handlers import RotatingFileHandler
from ncclient import manager
from ncclient.xml_ import *
from ncclient.devices.default import DefaultDeviceHandler
class LopcommNetconfClient:
def __init__(self):
log_file = "{{ log_file }}"
json_log_file = "{{ json_log_file }}"
self.logger = logging.getLogger('logger')
self.json_logger = logging.getLogger('json_logger')
self.logger.setLevel(logging.DEBUG)
self.json_logger.setLevel(logging.DEBUG)
json_handler = RotatingFileHandler(json_log_file, maxBytes=100000, backupCount=5)
json_formatter = logging.Formatter('{"time": "%(asctime)s", "log_level": "%(levelname)s", "message": "%(message)s", "data": %(data)s}')
json_handler.setFormatter(json_formatter)
self.json_logger.addHandler(json_handler)
handler = RotatingFileHandler(log_file, maxBytes=100000, backupCount=5)
self.logger.addHandler(handler)
formatter = logging.Formatter("%(asctime)s [%(levelname)s] %(message)s")
handler.setFormatter(formatter)
if {{ testing }}:
return
def connect(self, host, port, user, password):
if {{ testing }}:
return
self.address = (host, port)
self.logger.info('Connecting to %s, user %s...' % (self.address, user))
self.conn = manager.connect(host=host,
port=port,
username=user,
password=password,
timeout=1800,
device_params={
'name': 'huawei'
},
hostkey_verify=False)
self.logger.info('Connection to %s successful' % (self.address,))
def subscribe(self):
# Filter not compatible between ncclient and netconf server
#result = self.conn.create_subscription(filter=('xpath', '/o-ran-fm:*'))
sub = self.conn.create_subscription()
self.logger.info('Subscription to %s successful' % (self.address,))
def get_notification(self):
result = None
while result == None:
self.logger.debug('Waiting for notification from %s...' % (self.address,))
result = self.conn.take_notification(block=True)
if result:
self.logger.debug('Got new notification from %s...' % (self.address,))
result_in_xml = result._raw
data_dict = xmltodict.parse(result_in_xml)
self.json_logger.info('', extra={'data': data_dict})
def close(self):
# Close not compatible between ncclient and netconf server
#self.conn.close()
pass
if __name__ == '__main__':
nc = LopcommNetconfClient()
while True:
try:
nc.connect("192.168.0.210", 830, "oranuser", "oranpassword")
nc.subscribe()
while True:
nc.get_notification()
except Exception as e:
nc.logger.debug('Got exception, waiting 10 seconds before reconnecting...')
nc.logger.debug(e)
time.sleep(10)
finally:
nc.close()
import errno
import json
import logging
import os
from dateutil import parser
from zope.interface import implementer
from slapos.grid.promise import interface
from slapos.grid.promise.generic import GenericPromise
# Get all data in the last "interval" seconds from JSON log
def get_data_interval(log, interval):
log_number = 0
latest_timestamp = 0
data_list = []
while True:
try:
f = open("{}.{}".format(log, log_number) if log_number else log, "rb")
except OSError:
return data_list
try:
f.seek(0, os.SEEK_END)
while True:
try:
while f.seek(-2, os.SEEK_CUR) and f.read(1) != b'\n':
pass
except OSError:
break
pos = f.tell()
l = json.loads(f.readline().decode().replace("'", '"'))
timestamp = parser.parse(l['time'])
data_list.append(l['data'])
if not latest_timestamp:
latest_timestamp = timestamp
if (latest_timestamp - timestamp).total_seconds() > interval:
return data_list
f.seek(pos, os.SEEK_SET)
finally:
f.close()
log_number += 1
@implementer(interface.IPromise)
class RunPromise(GenericPromise):
def __init__(self, config):
self.__name = config.get('name', None)
self.__log_folder = config.get('log-folder', None)
super(RunPromise, self).__init__(config)
self.setPeriodicity(minute=1)
self.__title = os.path.splitext(self.__name)[0]
self.__log_file = os.path.join(self.__log_folder, '%s.json.log' % self.__title)
self.json_logger = logging.getLogger('json_logger')
self.json_logger.setLevel(logging.INFO)
handler = logging.FileHandler(self.__log_file)
formatter = logging.Formatter('{"time": "%(asctime)s", "log_level": "%(levelname)s", "message": "%(message)s", "data": %(data)s}')
handler.setFormatter(formatter)
self.json_logger.addHandler(handler)
def sense(self):
testing = self.getConfig('testing') == "True"
if testing:
self.logger.info("skipping promise")
return
lopcomm_stats_log = self.getConfig('lopcomm-stats-log')
data_list = get_data_interval(lopcomm_stats_log, 120)
# fault_texts = []
# Example of data_list
#('[\n'
# ' {\n'
# ' "notification": {\n'
# ' "@xmlns": "urn:ietf:params:xml:ns:netconf:notification:1.0",\n'
# ' "eventTime": "1970-01-05T00:38:50Z",\n'
# ' "alarm-notif": {\n'
# ' "@xmlns": "urn:o-ran:fm:1.0",\n'
# ' "fault-id": "9",\n'
# ' "fault-source": "Antport1",\n'
# ' "affected-objects": {\n'
# ' "name": "Antport1"\n'
# ' },\n'
# ' "fault-severity": "MAJOR",\n'
# ' "is-cleared": "false",\n'
# ' "fault-text": "PA 1 VSWR Alarm",\n'
# ' "event-time": "1970-01-05T00:38:50Z"\n'
# ' }\n'
# ' }\n'
# ' },\n'
# ']')
fault_text_list = []
alarm = False
for data in data_list:
notifications = data['notification']
alarm_notifs = notifications['alarm-notif']
fault_texts = alarm_notifs['fault-text']
fault_sources = alarm_notifs['fault-source']
is_cleared = alarm_notifs['is-cleared']
if not fault_text_list:
fault_text_list = ["None",]
for i, fault_text in enumerate(fault_texts):
if 'VSWR' in fault_text:
if is_cleared == 'false':
alarm = True
self.logger.error(fault_sources + ": " +fault_texts)
else:
self.logger.info(fault_sources + ": " +fault_texts + " is no longer over threshold")
if not data_list:
self.logger.error("No notification available")
elif not alarm:
self.logger.info("No VSWR alarm detected")
def test(self):
"""
Called after sense() if the instance is still converging.
Returns success or failure based on sense results.
In this case, fail if the previous sensor result is negative.
"""
return self._test(result_count=1, failure_amount=1)
def anomaly(self):
"""
Called after sense() if the instance has finished converging.
Returns success or failure based on sense results.
Failure signals the instance has diverged.
In this case, fail if two out of the last three results are negative.
"""
return self._anomaly(result_count=1, failure_amount=1)
......@@ -40,6 +40,12 @@ url = ${:_profile_base_location_}/${:_update_hash_filename_}
[amarisoft-stats.jinja2.py]
<= download-base
[amarisoft-rf-info.jinja2.py]
<= download-base
[lopcomm-rrh-stats.jinja2.py]
<= download-base
[template-lte-enb-epc]
<= download-base
......@@ -78,6 +84,8 @@ url = ${:_profile_base_location_}/${:_update_hash_filename_}
<= download-base
[interface-up-promise]
<= download-base
[vswr-promise]
<= download-base
[copy-to-instance]
recipe = slapos.recipe.build:download
......@@ -115,11 +123,29 @@ filename = ue-lte.jinja2.cfg
<= copy-config-to-instance
filename = ue-nr.jinja2.cfg
[pynacl]
recipe = zc.recipe.egg:custom
egg = pynacl
setup-eggs =
cffi
[bcrypt]
recipe = zc.recipe.egg:custom
egg = bcrypt
setup-eggs =
cffi
[eggs]
recipe = zc.recipe.egg
eggs =
websocket-client
${pynacl:egg}
${bcrypt:egg}
xmltodict
ncclient
interpreter = pythonwitheggs
[versions]
websocket-client = 1.4.2
ncclient = 0.6.13
xmltodict = 0.13.0
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment