Commit 037f9d4d authored by Joaquin Muguerza's avatar Joaquin Muguerza

Add modcod2simulation script

parent 5f972b57
#!/usr/bin/python2
# -*- coding: utf-8 -*-
"""Generate the attenuation file needed to obtain the simulated MODCODs
described by the input file.
This module generates the attenuation on the terminal side, supposing the C/N
between the satellite and the gateway is constant. The generated file is printed
on stdout, unless the output parameter is specified.
"""
# OpenSAND is an emulation testbed aiming to represent in a cost effective way a
# satellite telecommunication system for research and engineering activities.
#
#
# Copyright © 2018 TAS
# Copyright © 2018 CNES
#
#
# This file is part of the OpenSAND testbed.
#
#
# OpenSAND is free software : you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY, without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see http://www.gnu.org/licenses/.
__author__ = 'Viveris Technologies'
__credit__ = '''Contributors:
* Joaquin MUGUERZA <joaquin.muguerza@toulouse.viveris.com>
'''
import re
import sys
import math
import argparse
INPUT_LINE = re.compile(r'\A\s*(?P<time>\d+)\s+(?P<modcod>\d+)\s*\Z')
MODCOD_LINE = re.compile(r'\A\s*(?P<modcod_number>\d+)\s+(?P<modulation>\S+)\s+(?P<coding_rate>\S+)\s+(?P<spectral_efficiency>\d+\.\d+)\s+(?P<required_es_no>(?:-)?\d+\.\d+)\s*(?:(?P<burst_length>\d+)\s*)?\Z')
def command_line_parser():
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
'modcod_def_file', type=argparse.FileType('r'),
help='path to the MODCOD definition file')
parser.add_argument(
'simulated_modcod_file', type=argparse.FileType('r'),
help='path to the simulated MODCODs file')
parser.add_argument(
'-c', '--clear-sky', type=float, default=20.0, metavar='C/N',
help='the C/N (in dB) on both uplink and downlink with clear-sky'
' conditions')
parser.add_argument(
'-o', '--output', type=argparse.FileType('w'), default='-',
metavar='FILE', help='path to the output file')
parser.add_argument(
'-b', '--burst-length', type=int, default=536,
help='burst length to use for RCS2 MODCOD file')
parser.add_argument(
'-m', '--attenuation-margin', type=float, default=0.1,
help='attenuation margin to obtain the desired modcod')
return parser
def parse_modcod_file(modcod_file, burst_length):
""" Parse the MODCOD definitions file """
# TODO: check that the number of modcods is equal to nb_fmt?
modcods = {}
for line in modcod_file:
# consider only valid lines
try:
modcod = MODCOD_LINE.search(line).groupdict()
except AttributeError:
continue
# consider only modcods with the same burst length (if specified in the file)
if modcod['burst_length'] and int(modcod['burst_length']) != burst_length:
continue
# append modcod to modcods list
modcods[modcod['modcod_number']] = {
'modcod_number': int(modcod['modcod_number']),
'modulation': modcod['modulation'],
'coding_rate': modcod['coding_rate'],
'spectral_efficienty': float(modcod['spectral_efficiency']),
'required_es_no': float(modcod['required_es_no']),
'burst_length': modcod['burst_length'],
}
return modcods
def generate_attenuation_file(input_file, output_file, modcods, clear_sky, margin):
""" Generate the output attenuation file from the input simulated MODCODs
file"""
# iterate over the input_file
for line in input_file:
# consider only valid lines
try:
line = INPUT_LINE.search(line).groupdict()
except AttributeError:
continue
# get the necessary attenuation
attenuation = get_needed_attenuation(line['modcod'], modcods, clear_sky, margin)
# write the output line
output_file.write('{} {}\n'.format(line['time'], attenuation))
def toDb(a):
""" convert to db """
return 10.0 * math.log(a, 10)
def toMag(a):
""" convert to magnitude """
return math.pow(10, a/10.0)
def get_needed_attenuation(modcod, modcods, clear_sky, margin):
""" Get the needed attenuation for the desired modcod """
# supose that the clear sky condition is equal on both links, and that there
# is no attenuation on the gateway link
try:
attenuation = clear_sky - toDb(1 / ( 1 / ( toMag(modcods[modcod]['required_es_no'] + margin) ) - 1 / toMag(clear_sky) ))
except KeyError:
print("Specified MODCOD {} is not declared on the MODCOD definition "
"file".format(modcod))
sys.exit(1)
return attenuation
def main():
""" Generate the attenuation file from the input"""
args = command_line_parser().parse_args()
# Parse the MODCOD file
with args.modcod_def_file as modcod_def_file:
modcod_definitions = parse_modcod_file(modcod_def_file, args.burst_length)
# Parse the INPUT file and generate output
with args.simulated_modcod_file as simulated_modcod_file, args.output as output_file:
generate_attenuation_file(
simulated_modcod_file, output_file,
modcod_definitions, args.clear_sky,
args.attenuation_margin
)
if __name__ == '__main__':
main()
......@@ -37,5 +37,5 @@ setup(
('share/opensand/manager/images', img_files),
('share/pixmaps/', icon_files),
],
scripts=['sand-manager','sand-server']
scripts=['sand-manager', 'sand-server', 'modcod2attenuation']
)
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