2019-07-11 14:13:13 +00:00
|
|
|
#!/usr/bin/env python
|
2017-11-21 11:25:43 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2018-03-12 18:09:56 +00:00
|
|
|
# TRX Toolkit
|
2017-11-21 11:35:24 +00:00
|
|
|
# Auxiliary tool to send existing bursts via TRX DATA interface
|
2017-11-21 11:25:43 +00:00
|
|
|
#
|
2018-01-27 14:47:31 +00:00
|
|
|
# (C) 2017-2018 by Vadim Yanitskiy <axilirator@gmail.com>
|
2017-11-21 11:25:43 +00:00
|
|
|
#
|
|
|
|
# All Rights Reserved
|
|
|
|
#
|
|
|
|
# This program 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 2 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, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
2018-12-07 03:04:14 +00:00
|
|
|
APP_CR_HOLDERS = [("2017-2018", "Vadim Yanitskiy <axilirator@gmail.com>")]
|
2018-03-12 13:48:24 +00:00
|
|
|
|
trx_toolkit: use generic logging module instead of print()
There are multiple advantages of using Python's logging module:
- advanced message formatting (file name, line number, etc.),
- multiple logging targets (e.g. stderr, file, socket),
- logging levels (e.g. DEBUG, INFO, ERROR),
- the pythonic way ;)
so, let's replace multiple print() calls by logging calls,
add use the following logging message format by default:
[%(levelname)s] %(filename)s:%(lineno)d %(message)s
Examples:
[INFO] ctrl_if_bts.py:57 Starting transceiver...
[DEBUG] clck_gen.py:87 IND CLOCK 26826
[DEBUG] ctrl_if_bts.py:71 Recv POWEROFF cmd
[INFO] ctrl_if_bts.py:73 Stopping transceiver...
[INFO] fake_trx.py:127 Shutting down...
Please note that there is no way to filter messages by logging
level yet. This is to be introduced soon, together with argparse.
Change-Id: I7fcafabafe8323b58990997a47afdd48b6d1f357
2018-12-06 22:00:26 +00:00
|
|
|
import logging as log
|
2017-11-21 11:25:43 +00:00
|
|
|
import signal
|
2018-12-07 00:15:45 +00:00
|
|
|
import argparse
|
2017-11-21 11:25:43 +00:00
|
|
|
import sys
|
|
|
|
|
2018-12-07 02:34:00 +00:00
|
|
|
from app_common import ApplicationBase
|
2018-02-20 12:21:54 +00:00
|
|
|
from data_dump import DATADumpFile
|
2017-11-21 11:25:43 +00:00
|
|
|
from data_if import DATAInterface
|
2018-01-27 14:47:31 +00:00
|
|
|
from data_msg import *
|
2017-11-21 11:25:43 +00:00
|
|
|
|
2018-12-07 02:34:00 +00:00
|
|
|
class Application(ApplicationBase):
|
2017-11-21 11:25:43 +00:00
|
|
|
def __init__(self):
|
2018-12-07 03:04:14 +00:00
|
|
|
self.app_print_copyright(APP_CR_HOLDERS)
|
2018-12-07 00:15:45 +00:00
|
|
|
self.argv = self.parse_argv()
|
2017-11-21 11:25:43 +00:00
|
|
|
|
|
|
|
# Set up signal handlers
|
|
|
|
signal.signal(signal.SIGINT, self.sig_handler)
|
|
|
|
|
trx_toolkit: use generic logging module instead of print()
There are multiple advantages of using Python's logging module:
- advanced message formatting (file name, line number, etc.),
- multiple logging targets (e.g. stderr, file, socket),
- logging levels (e.g. DEBUG, INFO, ERROR),
- the pythonic way ;)
so, let's replace multiple print() calls by logging calls,
add use the following logging message format by default:
[%(levelname)s] %(filename)s:%(lineno)d %(message)s
Examples:
[INFO] ctrl_if_bts.py:57 Starting transceiver...
[DEBUG] clck_gen.py:87 IND CLOCK 26826
[DEBUG] ctrl_if_bts.py:71 Recv POWEROFF cmd
[INFO] ctrl_if_bts.py:73 Stopping transceiver...
[INFO] fake_trx.py:127 Shutting down...
Please note that there is no way to filter messages by logging
level yet. This is to be introduced soon, together with argparse.
Change-Id: I7fcafabafe8323b58990997a47afdd48b6d1f357
2018-12-06 22:00:26 +00:00
|
|
|
# Configure logging
|
2018-12-07 02:34:00 +00:00
|
|
|
self.app_init_logging(self.argv)
|
trx_toolkit: use generic logging module instead of print()
There are multiple advantages of using Python's logging module:
- advanced message formatting (file name, line number, etc.),
- multiple logging targets (e.g. stderr, file, socket),
- logging levels (e.g. DEBUG, INFO, ERROR),
- the pythonic way ;)
so, let's replace multiple print() calls by logging calls,
add use the following logging message format by default:
[%(levelname)s] %(filename)s:%(lineno)d %(message)s
Examples:
[INFO] ctrl_if_bts.py:57 Starting transceiver...
[DEBUG] clck_gen.py:87 IND CLOCK 26826
[DEBUG] ctrl_if_bts.py:71 Recv POWEROFF cmd
[INFO] ctrl_if_bts.py:73 Stopping transceiver...
[INFO] fake_trx.py:127 Shutting down...
Please note that there is no way to filter messages by logging
level yet. This is to be introduced soon, together with argparse.
Change-Id: I7fcafabafe8323b58990997a47afdd48b6d1f357
2018-12-06 22:00:26 +00:00
|
|
|
|
2018-02-20 12:21:54 +00:00
|
|
|
# Open requested capture file
|
2018-12-07 00:15:45 +00:00
|
|
|
self.ddf = DATADumpFile(self.argv.capture_file)
|
2018-02-20 12:21:54 +00:00
|
|
|
|
2017-11-21 11:25:43 +00:00
|
|
|
def run(self):
|
|
|
|
# Init DATA interface with TRX or L1
|
2018-12-07 00:15:45 +00:00
|
|
|
if self.argv.conn_mode == "TRX":
|
|
|
|
self.data_if = DATAInterface(
|
|
|
|
self.argv.remote_addr, self.argv.base_port + 2,
|
|
|
|
self.argv.bind_addr, self.argv.base_port + 102)
|
|
|
|
elif self.argv.conn_mode == "L1":
|
|
|
|
self.data_if = DATAInterface(
|
|
|
|
self.argv.remote_addr, self.argv.base_port + 102,
|
|
|
|
self.argv.bind_addr, self.argv.base_port + 2)
|
2017-11-21 11:25:43 +00:00
|
|
|
|
2018-02-20 12:21:54 +00:00
|
|
|
# Read messages from the capture
|
|
|
|
messages = self.ddf.parse_all(
|
2018-12-07 00:15:45 +00:00
|
|
|
skip = self.argv.cnt_skip, count = self.argv.cnt_count)
|
2018-02-20 12:21:54 +00:00
|
|
|
if messages is False:
|
2018-12-15 23:55:38 +00:00
|
|
|
log.error("Parsing failed, nothing to send")
|
|
|
|
sys.exit(1)
|
2017-11-21 11:25:43 +00:00
|
|
|
|
2018-02-20 12:21:54 +00:00
|
|
|
for msg in messages:
|
|
|
|
# Pass filter
|
2018-12-07 00:15:45 +00:00
|
|
|
if not self.msg_pass_filter(msg):
|
2017-11-21 11:25:43 +00:00
|
|
|
continue
|
|
|
|
|
trx_toolkit: use generic logging module instead of print()
There are multiple advantages of using Python's logging module:
- advanced message formatting (file name, line number, etc.),
- multiple logging targets (e.g. stderr, file, socket),
- logging levels (e.g. DEBUG, INFO, ERROR),
- the pythonic way ;)
so, let's replace multiple print() calls by logging calls,
add use the following logging message format by default:
[%(levelname)s] %(filename)s:%(lineno)d %(message)s
Examples:
[INFO] ctrl_if_bts.py:57 Starting transceiver...
[DEBUG] clck_gen.py:87 IND CLOCK 26826
[DEBUG] ctrl_if_bts.py:71 Recv POWEROFF cmd
[INFO] ctrl_if_bts.py:73 Stopping transceiver...
[INFO] fake_trx.py:127 Shutting down...
Please note that there is no way to filter messages by logging
level yet. This is to be introduced soon, together with argparse.
Change-Id: I7fcafabafe8323b58990997a47afdd48b6d1f357
2018-12-06 22:00:26 +00:00
|
|
|
log.info("Sending a burst %s to %s..."
|
2018-12-07 00:15:45 +00:00
|
|
|
% (msg.desc_hdr(), self.argv.conn_mode))
|
2018-01-27 14:47:31 +00:00
|
|
|
|
|
|
|
# Send message
|
|
|
|
self.data_if.send_msg(msg)
|
2017-11-21 11:25:43 +00:00
|
|
|
|
2018-12-07 00:15:45 +00:00
|
|
|
def msg_pass_filter(self, msg):
|
2018-02-20 12:21:54 +00:00
|
|
|
# Direction filter
|
2018-12-07 00:15:45 +00:00
|
|
|
l12trx = self.argv.conn_mode == "TRX"
|
2018-02-20 12:21:54 +00:00
|
|
|
if isinstance(msg, DATAMSG_L12TRX) and not l12trx:
|
|
|
|
return False
|
|
|
|
elif isinstance(msg, DATAMSG_TRX2L1) and l12trx:
|
|
|
|
return False
|
|
|
|
|
|
|
|
# Timeslot filter
|
2018-12-07 00:15:45 +00:00
|
|
|
if self.argv.pf_tn is not None:
|
|
|
|
if msg.tn != self.argv.pf_tn:
|
2018-02-20 12:21:54 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
# Frame number filter
|
2018-12-07 00:15:45 +00:00
|
|
|
if self.argv.pf_fn_lt is not None:
|
|
|
|
if msg.fn > self.argv.pf_fn_lt:
|
2018-02-20 12:21:54 +00:00
|
|
|
return False
|
2018-12-07 00:15:45 +00:00
|
|
|
if self.argv.pf_fn_gt is not None:
|
|
|
|
if msg.fn < self.argv.pf_fn_gt:
|
2018-02-20 12:21:54 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
# Burst passed ;)
|
|
|
|
return True
|
|
|
|
|
2017-11-21 11:25:43 +00:00
|
|
|
def parse_argv(self):
|
2018-12-07 00:15:45 +00:00
|
|
|
parser = argparse.ArgumentParser(prog = "burst_send",
|
|
|
|
description = "Auxiliary tool to send (reply) captured bursts")
|
|
|
|
|
2018-12-07 02:34:00 +00:00
|
|
|
# Register common logging options
|
|
|
|
self.app_reg_logging_options(parser)
|
|
|
|
|
2018-12-07 00:15:45 +00:00
|
|
|
trx_group = parser.add_argument_group("TRX interface")
|
|
|
|
trx_group.add_argument("-r", "--remote-addr",
|
|
|
|
dest = "remote_addr", type = str, default = "127.0.0.1",
|
|
|
|
help = "Set remote address (default %(default)s)")
|
|
|
|
trx_group.add_argument("-b", "--bind-addr",
|
|
|
|
dest = "bind_addr", type = str, default = "0.0.0.0",
|
|
|
|
help = "Set bind address (default %(default)s)")
|
|
|
|
trx_group.add_argument("-p", "--base-port",
|
|
|
|
dest = "base_port", type = int, default = 6700,
|
|
|
|
help = "Set base port number (default %(default)s)")
|
|
|
|
trx_group.add_argument("-m", "--conn-mode",
|
|
|
|
dest = "conn_mode", type = str,
|
|
|
|
choices = ["TRX", "L1"], default = "TRX",
|
|
|
|
help = "Where to send bursts (default %(default)s)")
|
|
|
|
trx_group.add_argument("-i", "--capture-file", metavar = "FILE",
|
|
|
|
dest = "capture_file", type = str, required = True,
|
|
|
|
help = "Capture file to read bursts from")
|
|
|
|
|
|
|
|
cnt_group = parser.add_argument_group("Count limitations (optional)")
|
|
|
|
cnt_group.add_argument("--skip", metavar = "N",
|
|
|
|
dest = "cnt_skip", type = int,
|
|
|
|
help = "Skip N messages before sending")
|
|
|
|
cnt_group.add_argument("--count", metavar = "N",
|
|
|
|
dest = "cnt_count", type = int,
|
|
|
|
help = "Stop after sending N messages")
|
|
|
|
|
|
|
|
pf_group = parser.add_argument_group("Filtering (optional)")
|
2018-12-15 13:56:02 +00:00
|
|
|
pf_group.add_argument("--timeslot", metavar = "TN",
|
2018-12-07 00:15:45 +00:00
|
|
|
dest = "pf_tn", type = int, choices = range(0, 8),
|
|
|
|
help = "TDMA timeslot number (equal TN)")
|
2018-12-15 13:56:02 +00:00
|
|
|
pf_group.add_argument("--frame-num-lt", metavar = "FN",
|
2018-12-07 00:15:45 +00:00
|
|
|
dest = "pf_fn_lt", type = int,
|
|
|
|
help = "TDMA frame number (lower than FN)")
|
2018-12-15 13:56:02 +00:00
|
|
|
pf_group.add_argument("--frame-num-gt", metavar = "FN",
|
2018-12-07 00:15:45 +00:00
|
|
|
dest = "pf_fn_gt", type = int,
|
|
|
|
help = "TDMA frame number (greater than FN)")
|
|
|
|
|
|
|
|
return parser.parse_args()
|
2017-11-21 11:25:43 +00:00
|
|
|
|
|
|
|
def sig_handler(self, signum, frame):
|
trx_toolkit: use generic logging module instead of print()
There are multiple advantages of using Python's logging module:
- advanced message formatting (file name, line number, etc.),
- multiple logging targets (e.g. stderr, file, socket),
- logging levels (e.g. DEBUG, INFO, ERROR),
- the pythonic way ;)
so, let's replace multiple print() calls by logging calls,
add use the following logging message format by default:
[%(levelname)s] %(filename)s:%(lineno)d %(message)s
Examples:
[INFO] ctrl_if_bts.py:57 Starting transceiver...
[DEBUG] clck_gen.py:87 IND CLOCK 26826
[DEBUG] ctrl_if_bts.py:71 Recv POWEROFF cmd
[INFO] ctrl_if_bts.py:73 Stopping transceiver...
[INFO] fake_trx.py:127 Shutting down...
Please note that there is no way to filter messages by logging
level yet. This is to be introduced soon, together with argparse.
Change-Id: I7fcafabafe8323b58990997a47afdd48b6d1f357
2018-12-06 22:00:26 +00:00
|
|
|
log.info("Signal %d received" % signum)
|
2019-07-23 22:40:37 +00:00
|
|
|
if signum == signal.SIGINT:
|
2017-11-21 11:25:43 +00:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
app = Application()
|
|
|
|
app.run()
|