Ejemplo n.º 1
0
	def run(self):
		# Init shared clock generator
		self.clck_gen = CLCKGen([])

		# Power measurement emulation
		# Noise: -120 .. -105
		# BTS: -75 .. -50
		self.fake_pm = FakePM(-120, -105, -75, -50)

		# Init TRX instance for BTS
		self.bts_trx = FakeTRX(self.argv.trx_bind_addr,
			self.argv.bts_addr, self.argv.bts_base_port,
			clck_gen = self.clck_gen)

		# Init TRX instance for BB
		self.bb_trx = FakeTRX(self.argv.trx_bind_addr,
			self.argv.bb_addr, self.argv.bb_base_port,
			pwr_meas = self.fake_pm)

		# Burst forwarding between transceivers
		self.burst_fwd = BurstForwarder()
		self.burst_fwd.add_trx(self.bts_trx)
		self.burst_fwd.add_trx(self.bb_trx)

		log.info("Init complete")

		# Enter main loop
		while True:
			socks = [self.bts_trx.ctrl_if.sock, self.bb_trx.ctrl_if.sock,
				self.bts_trx.data_if.sock, self.bb_trx.data_if.sock]

			# Wait until we get any data on any socket
			r_event, w_event, x_event = select.select(socks, [], [])

			# Downlink: BTS -> BB
			if self.bts_trx.data_if.sock in r_event:
				msg = self.bts_trx.recv_data_msg()
				if msg is not None:
					self.burst_fwd.forward_msg(self.bts_trx, msg)

			# Uplink: BB -> BTS
			if self.bb_trx.data_if.sock in r_event:
				msg = self.bb_trx.recv_data_msg()
				if msg is not None:
					self.burst_fwd.forward_msg(self.bb_trx, msg)

			# CTRL commands from BTS
			if self.bts_trx.ctrl_if.sock in r_event:
				self.bts_trx.ctrl_if.handle_rx()

			# CTRL commands from BB
			if self.bb_trx.ctrl_if.sock in r_event:
				self.bb_trx.ctrl_if.handle_rx()
Ejemplo n.º 2
0
    def __init__(self):
        self.app_print_copyright(APP_CR_HOLDERS)
        self.argv = self.parse_argv()

        # Set up signal handlers
        signal.signal(signal.SIGINT, self.sig_handler)

        # Configure logging
        self.app_init_logging(self.argv)

        # List of all transceivers
        self.trx_list = TRXList()

        # Init shared clock generator
        self.clck_gen = CLCKGen([])

        # Power measurement emulation
        # Noise: -120 .. -105
        # BTS: -75 .. -50
        self.fake_pm = FakePM(-120, -105, -75, -50)
        self.fake_pm.trx_list = self.trx_list

        # Init TRX instance for BTS
        self.append_trx(self.argv.bts_addr,
                        self.argv.bts_base_port,
                        name="BTS")

        # Init TRX instance for BB
        self.append_trx(self.argv.bb_addr, self.argv.bb_base_port, name="MS")

        # Additional transceivers (optional)
        if self.argv.trx_list is not None:
            for trx_def in self.argv.trx_list:
                (name, addr, port, idx) = trx_def
                self.append_child_trx(addr, port, idx, name)

        # Burst forwarding between transceivers
        self.burst_fwd = BurstForwarder(self.trx_list.trx_list)

        log.info("Init complete")
Ejemplo n.º 3
0
	def __init__(self):
		self.app_print_copyright(APP_CR_HOLDERS)
		self.argv = self.parse_argv()

		# Set up signal handlers
		signal.signal(signal.SIGINT, self.sig_handler)

		# Configure logging
		self.app_init_logging(self.argv)

		# List of all transceivers
		self.trx_list = TRXList()

		# Init shared clock generator
		self.clck_gen = CLCKGen([])

		# Power measurement emulation
		# Noise: -120 .. -105
		# BTS: -75 .. -50
		self.fake_pm = FakePM(-120, -105, -75, -50)
		self.fake_pm.trx_list = self.trx_list

		# Init TRX instance for BTS
		self.append_trx(self.argv.bts_addr,
			self.argv.bts_base_port, name = "BTS")

		# Init TRX instance for BB
		self.append_trx(self.argv.bb_addr,
			self.argv.bb_base_port, name = "MS")

		# Additional transceivers (optional)
		if self.argv.trx_list is not None:
			for trx_def in self.argv.trx_list:
				(name, addr, port, idx) = trx_def
				self.append_child_trx(addr, port, idx, name)

		# Burst forwarding between transceivers
		self.burst_fwd = BurstForwarder(self.trx_list)

		log.info("Init complete")
Ejemplo n.º 4
0
class Application(ApplicationBase):
    def __init__(self):
        self.app_print_copyright(APP_CR_HOLDERS)
        self.argv = self.parse_argv()

        # Set up signal handlers
        signal.signal(signal.SIGINT, self.sig_handler)

        # Configure logging
        self.app_init_logging(self.argv)

        # List of all transceivers
        self.trx_list = TRXList()

        # Init shared clock generator
        self.clck_gen = CLCKGen([])

        # Power measurement emulation
        # Noise: -120 .. -105
        # BTS: -75 .. -50
        self.fake_pm = FakePM(-120, -105, -75, -50)
        self.fake_pm.trx_list = self.trx_list

        # Init TRX instance for BTS
        self.append_trx(self.argv.bts_addr,
                        self.argv.bts_base_port,
                        name="BTS")

        # Init TRX instance for BB
        self.append_trx(self.argv.bb_addr, self.argv.bb_base_port, name="MS")

        # Additional transceivers (optional)
        if self.argv.trx_list is not None:
            for trx_def in self.argv.trx_list:
                (name, addr, port, idx) = trx_def
                self.append_child_trx(addr, port, idx, name)

        # Burst forwarding between transceivers
        self.burst_fwd = BurstForwarder(self.trx_list.trx_list)

        log.info("Init complete")

    def append_trx(self, remote_addr, base_port, name=None):
        trx = FakeTRX(self.argv.trx_bind_addr,
                      remote_addr,
                      base_port,
                      clck_gen=self.clck_gen,
                      pwr_meas=self.fake_pm,
                      name=name)
        self.trx_list.add_trx(trx)

    def append_child_trx(self, remote_addr, base_port, child_idx, name=None):
        # Index 0 corresponds to the first transceiver
        if child_idx == 0:
            self.append_trx(remote_addr, base_port, name)
            return

        # Find 'parent' transceiver for a new child
        trx_parent = self.trx_list.find_trx(remote_addr, base_port)
        if trx_parent is None:
            raise IndexError("Couldn't find parent transceiver "
                             "for '%s:%d/%d'" %
                             (remote_addr, base_port, child_idx))

        # Allocate a new child
        trx_child = FakeTRX(self.argv.trx_bind_addr,
                            remote_addr,
                            base_port,
                            child_idx=child_idx,
                            pwr_meas=self.fake_pm,
                            name=name)
        self.trx_list.add_trx(trx_child)

        # Link a new 'child' with its 'parent'
        trx_parent.child_trx_list.add_trx(trx_child)

    def run(self):
        # Compose list of to be monitored sockets
        sock_list = []
        for trx in self.trx_list.trx_list:
            sock_list.append(trx.ctrl_if.sock)
            sock_list.append(trx.data_if.sock)

        # Enter main loop
        while True:
            # Wait until we get any data on any socket
            r_event, _, _ = select.select(sock_list, [], [])

            # Iterate over all transceivers
            for trx in self.trx_list.trx_list:
                # DATA interface
                if trx.data_if.sock in r_event:
                    msg = trx.recv_data_msg()
                    if msg is not None:
                        self.burst_fwd.forward_msg(trx, msg)

                # CTRL interface
                if trx.ctrl_if.sock in r_event:
                    trx.ctrl_if.handle_rx()

    def shutdown(self):
        log.info("Shutting down...")

        # Stop clock generator
        self.clck_gen.stop()

    # Parses a TRX definition of the following
    # format: REMOTE_ADDR:BIND_PORT[/TRX_NUM]
    # e.g. [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:5700/5
    # e.g. 127.0.0.1:5700 or 127.0.0.1:5700/1
    # e.g. [email protected]:5700 or [email protected]:5700/1
    @staticmethod
    def trx_def(val):
        try:
            result = re.match(r"(.+@)?(.+):([0-9]+)(/[0-9]+)?", val)
            (name, addr, port, idx) = result.groups()
        except:
            raise argparse.ArgumentTypeError("Invalid TRX definition: %s" %
                                             val)

        if idx is not None:
            idx = int(idx[1:])
        else:
            idx = 0

        # Cut '@' from TRX name
        if name is not None:
            name = name[:-1]

        return (name, addr, int(port), idx)

    def parse_argv(self):
        parser = argparse.ArgumentParser(
            prog="fake_trx",
            description="Virtual Um-interface (fake transceiver)")

        # Register common logging options
        self.app_reg_logging_options(parser)

        trx_group = parser.add_argument_group("TRX interface")
        trx_group.add_argument(
            "-b",
            "--trx-bind-addr",
            dest="trx_bind_addr",
            type=str,
            default="0.0.0.0",
            help="Set FakeTRX bind address (default %(default)s)")
        trx_group.add_argument(
            "-R",
            "--bts-addr",
            dest="bts_addr",
            type=str,
            default="127.0.0.1",
            help="Set BTS remote address (default %(default)s)")
        trx_group.add_argument(
            "-r",
            "--bb-addr",
            dest="bb_addr",
            type=str,
            default="127.0.0.1",
            help="Set BB remote address (default %(default)s)")
        trx_group.add_argument(
            "-P",
            "--bts-base-port",
            dest="bts_base_port",
            type=int,
            default=5700,
            help="Set BTS base port number (default %(default)s)")
        trx_group.add_argument(
            "-p",
            "--bb-base-port",
            dest="bb_base_port",
            type=int,
            default=6700,
            help="Set BB base port number (default %(default)s)")

        mtrx_group = parser.add_argument_group("Additional transceivers")
        mtrx_group.add_argument(
            "--trx",
            metavar="REMOTE_ADDR:BASE_PORT[/TRX_NUM]",
            dest="trx_list",
            type=self.trx_def,
            action="append",
            help="Add a transceiver for BTS or MS (e.g. 127.0.0.1:5703)")

        argv = parser.parse_args()

        # Make sure there is no overlap between ports
        if argv.bts_base_port == argv.bb_base_port:
            parser.error("BTS and BB base ports shall be different")

        return argv

    def sig_handler(self, signum, frame):
        log.info("Signal %d received" % signum)
        if signum == signal.SIGINT:
            self.shutdown()
            sys.exit(0)
Ejemplo n.º 5
0
    def run(self):
        # Init TRX CTRL interface for BTS
        self.bts_ctrl = CTRLInterfaceBTS(self.argv.bts_addr,
                                         self.argv.bts_base_port + 101,
                                         self.argv.trx_bind_addr,
                                         self.argv.bts_base_port + 1)

        # Init TRX CTRL interface for BB
        self.bb_ctrl = CTRLInterfaceBB(self.argv.bb_addr,
                                       self.argv.bb_base_port + 101,
                                       self.argv.trx_bind_addr,
                                       self.argv.bb_base_port + 1)

        # Power measurement emulation
        # Noise: -120 .. -105
        # BTS: -75 .. -50
        self.pm = FakePM(-120, -105, -75, -50)

        # Share a FakePM instance between both BTS and BB
        self.bts_ctrl.pm = self.pm
        self.bb_ctrl.pm = self.pm

        # Init DATA links
        self.bts_data = UDPLink(self.argv.bts_addr,
                                self.argv.bts_base_port + 102,
                                self.argv.trx_bind_addr,
                                self.argv.bts_base_port + 2)
        self.bb_data = UDPLink(self.argv.bb_addr, self.argv.bb_base_port + 102,
                               self.argv.trx_bind_addr,
                               self.argv.bb_base_port + 2)

        # BTS <-> BB burst forwarding
        self.burst_fwd = BurstForwarder(self.bts_data, self.bb_data)

        # Share a BurstForwarder instance between BTS and BB
        self.bts_ctrl.burst_fwd = self.burst_fwd
        self.bb_ctrl.burst_fwd = self.burst_fwd

        # Provide clock to BTS
        self.bts_clck = UDPLink(self.argv.bts_addr,
                                self.argv.bts_base_port + 100,
                                self.argv.trx_bind_addr,
                                self.argv.bts_base_port)
        self.clck_gen = CLCKGen([self.bts_clck])
        self.bts_ctrl.clck_gen = self.clck_gen

        log.info("Init complete")

        # Enter main loop
        while True:
            socks = [
                self.bts_ctrl.sock, self.bb_ctrl.sock, self.bts_data.sock,
                self.bb_data.sock
            ]

            # Wait until we get any data on any socket
            r_event, w_event, x_event = select.select(socks, [], [])

            # Downlink: BTS -> BB
            if self.bts_data.sock in r_event:
                self.burst_fwd.bts2bb()

            # Uplink: BB -> BTS
            if self.bb_data.sock in r_event:
                self.burst_fwd.bb2bts()

            # CTRL commands from BTS
            if self.bts_ctrl.sock in r_event:
                data, addr = self.bts_ctrl.sock.recvfrom(128)
                self.bts_ctrl.handle_rx(data.decode(), addr)

            # CTRL commands from BB
            if self.bb_ctrl.sock in r_event:
                data, addr = self.bb_ctrl.sock.recvfrom(128)
                self.bb_ctrl.handle_rx(data.decode(), addr)
Ejemplo n.º 6
0
class Application(ApplicationBase):
    def __init__(self):
        self.app_print_copyright(APP_CR_HOLDERS)
        self.argv = self.parse_argv()

        # Set up signal handlers
        signal.signal(signal.SIGINT, self.sig_handler)

        # Configure logging
        self.app_init_logging(self.argv)

    def run(self):
        # Init TRX CTRL interface for BTS
        self.bts_ctrl = CTRLInterfaceBTS(self.argv.bts_addr,
                                         self.argv.bts_base_port + 101,
                                         self.argv.trx_bind_addr,
                                         self.argv.bts_base_port + 1)

        # Init TRX CTRL interface for BB
        self.bb_ctrl = CTRLInterfaceBB(self.argv.bb_addr,
                                       self.argv.bb_base_port + 101,
                                       self.argv.trx_bind_addr,
                                       self.argv.bb_base_port + 1)

        # Power measurement emulation
        # Noise: -120 .. -105
        # BTS: -75 .. -50
        self.pm = FakePM(-120, -105, -75, -50)

        # Share a FakePM instance between both BTS and BB
        self.bts_ctrl.pm = self.pm
        self.bb_ctrl.pm = self.pm

        # Init DATA links
        self.bts_data = UDPLink(self.argv.bts_addr,
                                self.argv.bts_base_port + 102,
                                self.argv.trx_bind_addr,
                                self.argv.bts_base_port + 2)
        self.bb_data = UDPLink(self.argv.bb_addr, self.argv.bb_base_port + 102,
                               self.argv.trx_bind_addr,
                               self.argv.bb_base_port + 2)

        # BTS <-> BB burst forwarding
        self.burst_fwd = BurstForwarder(self.bts_data, self.bb_data)

        # Share a BurstForwarder instance between BTS and BB
        self.bts_ctrl.burst_fwd = self.burst_fwd
        self.bb_ctrl.burst_fwd = self.burst_fwd

        # Provide clock to BTS
        self.bts_clck = UDPLink(self.argv.bts_addr,
                                self.argv.bts_base_port + 100,
                                self.argv.trx_bind_addr,
                                self.argv.bts_base_port)
        self.clck_gen = CLCKGen([self.bts_clck])
        self.bts_ctrl.clck_gen = self.clck_gen

        log.info("Init complete")

        # Enter main loop
        while True:
            socks = [
                self.bts_ctrl.sock, self.bb_ctrl.sock, self.bts_data.sock,
                self.bb_data.sock
            ]

            # Wait until we get any data on any socket
            r_event, w_event, x_event = select.select(socks, [], [])

            # Downlink: BTS -> BB
            if self.bts_data.sock in r_event:
                self.burst_fwd.bts2bb()

            # Uplink: BB -> BTS
            if self.bb_data.sock in r_event:
                self.burst_fwd.bb2bts()

            # CTRL commands from BTS
            if self.bts_ctrl.sock in r_event:
                data, addr = self.bts_ctrl.sock.recvfrom(128)
                self.bts_ctrl.handle_rx(data.decode(), addr)

            # CTRL commands from BB
            if self.bb_ctrl.sock in r_event:
                data, addr = self.bb_ctrl.sock.recvfrom(128)
                self.bb_ctrl.handle_rx(data.decode(), addr)

    def shutdown(self):
        log.info("Shutting down...")

        # Stop clock generator
        self.clck_gen.stop()

    def parse_argv(self):
        parser = argparse.ArgumentParser(
            prog="fake_trx",
            description="Virtual Um-interface (fake transceiver)")

        # Register common logging options
        self.app_reg_logging_options(parser)

        trx_group = parser.add_argument_group("TRX interface")
        trx_group.add_argument(
            "-b",
            "--trx-bind-addr",
            dest="trx_bind_addr",
            type=str,
            default="0.0.0.0",
            help="Set FakeTRX bind address (default %(default)s)")
        trx_group.add_argument(
            "-R",
            "--bts-addr",
            dest="bts_addr",
            type=str,
            default="127.0.0.1",
            help="Set BTS remote address (default %(default)s)")
        trx_group.add_argument(
            "-r",
            "--bb-addr",
            dest="bb_addr",
            type=str,
            default="127.0.0.1",
            help="Set BB remote address (default %(default)s)")
        trx_group.add_argument(
            "-P",
            "--bts-base-port",
            dest="bts_base_port",
            type=int,
            default=5700,
            help="Set BTS base port number (default %(default)s)")
        trx_group.add_argument(
            "-p",
            "--bb-base-port",
            dest="bb_base_port",
            type=int,
            default=6700,
            help="Set BB base port number (default %(default)s)")

        argv = parser.parse_args()

        # Make sure there is no overlap between ports
        if argv.bts_base_port == argv.bb_base_port:
            parser.error("BTS and BB base ports shall be different")

        return argv

    def sig_handler(self, signum, frame):
        log.info("Signal %d received" % signum)
        if signum is signal.SIGINT:
            self.shutdown()
            sys.exit(0)
Ejemplo n.º 7
0
class Application(ApplicationBase):
	def __init__(self):
		self.app_print_copyright(APP_CR_HOLDERS)
		self.argv = self.parse_argv()

		# Set up signal handlers
		signal.signal(signal.SIGINT, self.sig_handler)

		# Configure logging
		self.app_init_logging(self.argv)

		# List of all transceivers
		self.trx_list = TRXList()

		# Init shared clock generator
		self.clck_gen = CLCKGen([])

		# Power measurement emulation
		# Noise: -120 .. -105
		# BTS: -75 .. -50
		self.fake_pm = FakePM(-120, -105, -75, -50)
		self.fake_pm.trx_list = self.trx_list

		# Init TRX instance for BTS
		self.append_trx(self.argv.bts_addr,
			self.argv.bts_base_port, name = "BTS")

		# Init TRX instance for BB
		self.append_trx(self.argv.bb_addr,
			self.argv.bb_base_port, name = "MS")

		# Additional transceivers (optional)
		if self.argv.trx_list is not None:
			for trx_def in self.argv.trx_list:
				(name, addr, port, idx) = trx_def
				self.append_child_trx(addr, port, idx, name)

		# Burst forwarding between transceivers
		self.burst_fwd = BurstForwarder(self.trx_list)

		log.info("Init complete")

	def append_trx(self, remote_addr, base_port, name = None):
		trx = FakeTRX(self.argv.trx_bind_addr, remote_addr, base_port,
			clck_gen = self.clck_gen, pwr_meas = self.fake_pm,
			name = name)
		self.trx_list.add_trx(trx)

	def append_child_trx(self, remote_addr, base_port, child_idx, name = None):
		# Index 0 corresponds to the first transceiver
		if child_idx is 0:
			self.append_trx(remote_addr, base_port, name)
			return

		# Find 'parent' transceiver for a new child
		trx_parent = self.trx_list.find_trx(remote_addr, base_port)
		if trx_parent is None:
			raise IndexError("Couldn't find parent transceiver "
				"for '%s:%d/%d'" % (remote_addr, base_port, child_idx))

		# Allocate a new child
		trx_child = FakeTRX(self.argv.trx_bind_addr, remote_addr, base_port,
			child_idx = child_idx, pwr_meas = self.fake_pm, name = name)
		self.trx_list.add_trx(trx_child)

		# Link a new 'child' with its 'parent'
		trx_parent.child_trx_list.add_trx(trx_child)

	def run(self):
		# Compose list of to be monitored sockets
		sock_list = []
		for trx in self.trx_list:
			sock_list.append(trx.ctrl_if.sock)
			sock_list.append(trx.data_if.sock)

		# Enter main loop
		while True:
			# Wait until we get any data on any socket
			r_event, _, _ = select.select(sock_list, [], [])

			# Iterate over all transceivers
			for trx in self.trx_list:
				# DATA interface
				if trx.data_if.sock in r_event:
					msg = trx.recv_data_msg()
					if msg is not None:
						self.burst_fwd.forward_msg(trx, msg)

				# CTRL interface
				if trx.ctrl_if.sock in r_event:
					trx.ctrl_if.handle_rx()

	def shutdown(self):
		log.info("Shutting down...")

		# Stop clock generator
		self.clck_gen.stop()

	# Parses a TRX definition of the following
	# format: REMOTE_ADDR:BIND_PORT[/TRX_NUM]
	# e.g. [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:5700/5
	# e.g. 127.0.0.1:5700 or 127.0.0.1:5700/1
	# e.g. [email protected]:5700 or [email protected]:5700/1
	@staticmethod
	def trx_def(val):
		try:
			result = re.match("(.+@)?(.+):([0-9]+)(\/[0-9]+)?", val)
			(name, addr, port, idx) = result.groups()
		except:
			raise argparse.ArgumentTypeError("Invalid TRX definition: %s" % val)

		if idx is not None:
			idx = int(idx[1:])
		else:
			idx = 0

		# Cut '@' from TRX name
		if name is not None:
			name = name[:-1]

		return (name, addr, int(port), idx)

	def parse_argv(self):
		parser = argparse.ArgumentParser(prog = "fake_trx",
			description = "Virtual Um-interface (fake transceiver)")

		# Register common logging options
		self.app_reg_logging_options(parser)

		trx_group = parser.add_argument_group("TRX interface")
		trx_group.add_argument("-b", "--trx-bind-addr",
			dest = "trx_bind_addr", type = str, default = "0.0.0.0",
			help = "Set FakeTRX bind address (default %(default)s)")
		trx_group.add_argument("-R", "--bts-addr",
			dest = "bts_addr", type = str, default = "127.0.0.1",
			help = "Set BTS remote address (default %(default)s)")
		trx_group.add_argument("-r", "--bb-addr",
			dest = "bb_addr", type = str, default = "127.0.0.1",
			help = "Set BB remote address (default %(default)s)")
		trx_group.add_argument("-P", "--bts-base-port",
			dest = "bts_base_port", type = int, default = 5700,
			help = "Set BTS base port number (default %(default)s)")
		trx_group.add_argument("-p", "--bb-base-port",
			dest = "bb_base_port", type = int, default = 6700,
			help = "Set BB base port number (default %(default)s)")

		mtrx_group = parser.add_argument_group("Additional transceivers")
		mtrx_group.add_argument("--trx",
			metavar = "REMOTE_ADDR:BASE_PORT[/TRX_NUM]",
			dest = "trx_list", type = self.trx_def, action = "append",
			help = "Add a transceiver for BTS or MS (e.g. 127.0.0.1:5703)")

		argv = parser.parse_args()

		# Make sure there is no overlap between ports
		if argv.bts_base_port == argv.bb_base_port:
			parser.error("BTS and BB base ports shall be different")

		return argv

	def sig_handler(self, signum, frame):
		log.info("Signal %d received" % signum)
		if signum is signal.SIGINT:
			self.shutdown()
			sys.exit(0)
Ejemplo n.º 8
0
class Application(ApplicationBase):
	def __init__(self):
		self.app_print_copyright(APP_CR_HOLDERS)
		self.argv = self.parse_argv()

		# Set up signal handlers
		signal.signal(signal.SIGINT, self.sig_handler)

		# Configure logging
		self.app_init_logging(self.argv)

	def run(self):
		# Init shared clock generator
		self.clck_gen = CLCKGen([])

		# Power measurement emulation
		# Noise: -120 .. -105
		# BTS: -75 .. -50
		self.fake_pm = FakePM(-120, -105, -75, -50)

		# Init TRX instance for BTS
		self.bts_trx = FakeTRX(self.argv.trx_bind_addr,
			self.argv.bts_addr, self.argv.bts_base_port,
			clck_gen = self.clck_gen)

		# Init TRX instance for BB
		self.bb_trx = FakeTRX(self.argv.trx_bind_addr,
			self.argv.bb_addr, self.argv.bb_base_port,
			pwr_meas = self.fake_pm)

		# Burst forwarding between transceivers
		self.burst_fwd = BurstForwarder()
		self.burst_fwd.add_trx(self.bts_trx)
		self.burst_fwd.add_trx(self.bb_trx)

		log.info("Init complete")

		# Enter main loop
		while True:
			socks = [self.bts_trx.ctrl_if.sock, self.bb_trx.ctrl_if.sock,
				self.bts_trx.data_if.sock, self.bb_trx.data_if.sock]

			# Wait until we get any data on any socket
			r_event, w_event, x_event = select.select(socks, [], [])

			# Downlink: BTS -> BB
			if self.bts_trx.data_if.sock in r_event:
				msg = self.bts_trx.recv_data_msg()
				if msg is not None:
					self.burst_fwd.forward_msg(self.bts_trx, msg)

			# Uplink: BB -> BTS
			if self.bb_trx.data_if.sock in r_event:
				msg = self.bb_trx.recv_data_msg()
				if msg is not None:
					self.burst_fwd.forward_msg(self.bb_trx, msg)

			# CTRL commands from BTS
			if self.bts_trx.ctrl_if.sock in r_event:
				self.bts_trx.ctrl_if.handle_rx()

			# CTRL commands from BB
			if self.bb_trx.ctrl_if.sock in r_event:
				self.bb_trx.ctrl_if.handle_rx()

	def shutdown(self):
		log.info("Shutting down...")

		# Stop clock generator
		self.clck_gen.stop()

	def parse_argv(self):
		parser = argparse.ArgumentParser(prog = "fake_trx",
			description = "Virtual Um-interface (fake transceiver)")

		# Register common logging options
		self.app_reg_logging_options(parser)

		trx_group = parser.add_argument_group("TRX interface")
		trx_group.add_argument("-b", "--trx-bind-addr",
			dest = "trx_bind_addr", type = str, default = "0.0.0.0",
			help = "Set FakeTRX bind address (default %(default)s)")
		trx_group.add_argument("-R", "--bts-addr",
			dest = "bts_addr", type = str, default = "127.0.0.1",
			help = "Set BTS remote address (default %(default)s)")
		trx_group.add_argument("-r", "--bb-addr",
			dest = "bb_addr", type = str, default = "127.0.0.1",
			help = "Set BB remote address (default %(default)s)")
		trx_group.add_argument("-P", "--bts-base-port",
			dest = "bts_base_port", type = int, default = 5700,
			help = "Set BTS base port number (default %(default)s)")
		trx_group.add_argument("-p", "--bb-base-port",
			dest = "bb_base_port", type = int, default = 6700,
			help = "Set BB base port number (default %(default)s)")

		argv = parser.parse_args()

		# Make sure there is no overlap between ports
		if argv.bts_base_port == argv.bb_base_port:
			parser.error("BTS and BB base ports shall be different")

		return argv

	def sig_handler(self, signum, frame):
		log.info("Signal %d received" % signum)
		if signum is signal.SIGINT:
			self.shutdown()
			sys.exit(0)
Ejemplo n.º 9
0
class Application:
    # Application variables
    bts_addr = "127.0.0.1"
    bb_addr = "127.0.0.1"
    trx_bind_addr = "0.0.0.0"
    bts_base_port = 5700
    bb_base_port = 6700

    # BurstForwarder field randomization
    randomize_dl_toa256 = False
    randomize_ul_toa256 = False
    randomize_dl_rssi = False
    randomize_ul_rssi = False

    def __init__(self):
        print_copyright(CR_HOLDERS)
        self.parse_argv()

        # Set up signal handlers
        signal.signal(signal.SIGINT, self.sig_handler)

    def run(self):
        # Init TRX CTRL interface for BTS
        self.bts_ctrl = CTRLInterfaceBTS(self.bts_addr,
                                         self.bts_base_port + 101,
                                         self.trx_bind_addr,
                                         self.bts_base_port + 1)

        # Init TRX CTRL interface for BB
        self.bb_ctrl = CTRLInterfaceBB(self.bb_addr, self.bb_base_port + 101,
                                       self.trx_bind_addr,
                                       self.bb_base_port + 1)

        # Power measurement emulation
        # Noise: -120 .. -105
        # BTS: -75 .. -50
        self.pm = FakePM(-120, -105, -75, -50)

        # Share a FakePM instance between both BTS and BB
        self.bts_ctrl.pm = self.pm
        self.bb_ctrl.pm = self.pm

        # Init DATA links
        self.bts_data = UDPLink(self.bts_addr, self.bts_base_port + 102,
                                self.trx_bind_addr, self.bts_base_port + 2)
        self.bb_data = UDPLink(self.bb_addr, self.bb_base_port + 102,
                               self.trx_bind_addr, self.bb_base_port + 2)

        # BTS <-> BB burst forwarding
        self.burst_fwd = BurstForwarder(self.bts_data, self.bb_data)
        self.burst_fwd.randomize_dl_toa256 = self.randomize_dl_toa256
        self.burst_fwd.randomize_ul_toa256 = self.randomize_ul_toa256
        self.burst_fwd.randomize_dl_rssi = self.randomize_dl_rssi
        self.burst_fwd.randomize_ul_rssi = self.randomize_ul_rssi

        # Share a BurstForwarder instance between BTS and BB
        self.bts_ctrl.burst_fwd = self.burst_fwd
        self.bb_ctrl.burst_fwd = self.burst_fwd

        # Provide clock to BTS
        self.bts_clck = UDPLink(self.bts_addr, self.bts_base_port + 100,
                                self.trx_bind_addr, self.bts_base_port)
        self.clck_gen = CLCKGen([self.bts_clck])
        self.bts_ctrl.clck_gen = self.clck_gen

        print("[i] Init complete")

        # Enter main loop
        while True:
            socks = [
                self.bts_ctrl.sock, self.bb_ctrl.sock, self.bts_data.sock,
                self.bb_data.sock
            ]

            # Wait until we get any data on any socket
            r_event, w_event, x_event = select.select(socks, [], [])

            # Downlink: BTS -> BB
            if self.bts_data.sock in r_event:
                self.burst_fwd.bts2bb()

            # Uplink: BB -> BTS
            if self.bb_data.sock in r_event:
                self.burst_fwd.bb2bts()

            # CTRL commands from BTS
            if self.bts_ctrl.sock in r_event:
                data, addr = self.bts_ctrl.sock.recvfrom(128)
                self.bts_ctrl.handle_rx(data.decode(), addr)

            # CTRL commands from BB
            if self.bb_ctrl.sock in r_event:
                data, addr = self.bb_ctrl.sock.recvfrom(128)
                self.bb_ctrl.handle_rx(data.decode(), addr)

    def shutdown(self):
        print("[i] Shutting down...")

        # Stop clock generator
        self.clck_gen.stop()

    def print_help(self, msg=None):
        s  = " Usage: " + sys.argv[0] + " [options]\n\n" \
          " Some help...\n" \
          "  -h --help           this text\n\n"

        s += " TRX interface specific\n" \
          "  -R --bts-addr       Set BTS remote address (default %s)\n"   \
          "  -r --bb-addr        Set BB remote address (default %s)\n"    \
          "  -P --bts-base-port  Set BTS base port number (default %d)\n" \
          "  -p --bb-base-port   Set BB base port number (default %d)\n" \
          "  -b --trx-bind-addr  Set TRX bind address (default %s)\n\n"

        s += " Simulation\n" \
          "  --rand-dl-rssi      Enable DL RSSI randomization\n"   \
          "  --rand-ul-rssi      Enable UL RSSI randomization\n"   \
          "  --rand-dl-toa       Enable DL ToA randomization\n"    \
          "  --rand-ul-toa       Enable UL ToA randomization\n"

        print(s % (self.bts_addr, self.bb_addr, self.bts_base_port,
                   self.bb_base_port, self.trx_bind_addr))

        if msg is not None:
            print(msg)

    def parse_argv(self):
        try:
            opts, args = getopt.getopt(sys.argv[1:], "R:r:P:p:b:h", [
                "help",
                "bts-addr=",
                "bb-addr=",
                "bts-base-port=",
                "bb-base-port=",
                "trx-bind-addr=",
                "rand-dl-rssi",
                "rand-ul-rssi",
                "rand-dl-toa",
                "rand-ul-toa",
            ])
        except getopt.GetoptError as err:
            self.print_help("[!] " + str(err))
            sys.exit(2)

        for o, v in opts:
            if o in ("-h", "--help"):
                self.print_help()
                sys.exit(2)

            elif o in ("-R", "--bts-addr"):
                self.bts_addr = v
            elif o in ("-r", "--bb-addr"):
                self.bb_addr = v

            elif o in ("-P", "--bts-base-port"):
                self.bts_base_port = int(v)
            elif o in ("-p", "--bb-base-port"):
                self.bb_base_port = int(v)

            elif o in ("-b", "--trx-bind-addr"):
                self.trx_bind_addr = v

            # Message field randomization
            elif o == "rand-dl-rssi":
                self.randomize_dl_rssi = True
            elif o == "rand-ul-rssi":
                self.randomize_ul_rssi = True
            elif o == "rand-dl-toa":
                self.randomize_dl_toa256 = True
            elif o == "rand-ul-toa":
                self.randomize_ul_toa256 = True

        # Ensure there is no overlap between ports
        if self.bts_base_port == self.bb_base_port:
            self.print_help("[!] BTS and BB base ports should be different")
            sys.exit(2)

        bts_ports = [
            self.bts_base_port + 0,
            self.bts_base_port + 100,
            self.bts_base_port + 1,
            self.bts_base_port + 101,
            self.bts_base_port + 2,
            self.bts_base_port + 102,
        ]

        bb_ports = [
            self.bb_base_port + 0,
            self.bb_base_port + 100,
            self.bb_base_port + 1,
            self.bb_base_port + 101,
            self.bb_base_port + 2,
            self.bb_base_port + 102,
        ]

        for p in bb_ports:
            if p in bts_ports:
                self.print_help("[!] BTS and BB ports overlap detected")
                sys.exit(2)

    def sig_handler(self, signum, frame):
        print("Signal %d received" % signum)
        if signum is signal.SIGINT:
            self.shutdown()
            sys.exit(0)
Ejemplo n.º 10
0
	def run(self):
		# Init TRX CTRL interface for BTS
		self.bts_ctrl = CTRLInterfaceBTS(self.bts_addr, self.bts_base_port + 101,
			self.trx_bind_addr, self.bts_base_port + 1)

		# Init TRX CTRL interface for BB
		self.bb_ctrl = CTRLInterfaceBB(self.bb_addr, self.bb_base_port + 101,
			self.trx_bind_addr, self.bb_base_port + 1)

		# Power measurement emulation
		# Noise: -120 .. -105
		# BTS: -75 .. -50
		self.pm = FakePM(-120, -105, -75, -50)

		# Share a FakePM instance between both BTS and BB
		self.bts_ctrl.pm = self.pm
		self.bb_ctrl.pm = self.pm

		# Init DATA links
		self.bts_data = UDPLink(self.bts_addr, self.bts_base_port + 102,
			self.trx_bind_addr, self.bts_base_port + 2)
		self.bb_data = UDPLink(self.bb_addr, self.bb_base_port + 102,
			self.trx_bind_addr, self.bb_base_port + 2)

		# BTS <-> BB burst forwarding
		self.burst_fwd = BurstForwarder(self.bts_data, self.bb_data)
		self.burst_fwd.randomize_dl_toa256 = self.randomize_dl_toa256
		self.burst_fwd.randomize_ul_toa256 = self.randomize_ul_toa256
		self.burst_fwd.randomize_dl_rssi = self.randomize_dl_rssi
		self.burst_fwd.randomize_ul_rssi = self.randomize_ul_rssi

		# Share a BurstForwarder instance between BTS and BB
		self.bts_ctrl.burst_fwd = self.burst_fwd
		self.bb_ctrl.burst_fwd = self.burst_fwd

		# Provide clock to BTS
		self.bts_clck = UDPLink(self.bts_addr, self.bts_base_port + 100,
			self.trx_bind_addr, self.bts_base_port)
		self.clck_gen = CLCKGen([self.bts_clck])
		self.bts_ctrl.clck_gen = self.clck_gen

		print("[i] Init complete")

		# Enter main loop
		while True:
			socks = [self.bts_ctrl.sock, self.bb_ctrl.sock,
				self.bts_data.sock, self.bb_data.sock]

			# Wait until we get any data on any socket
			r_event, w_event, x_event = select.select(socks, [], [])

			# Downlink: BTS -> BB
			if self.bts_data.sock in r_event:
				self.burst_fwd.bts2bb()

			# Uplink: BB -> BTS
			if self.bb_data.sock in r_event:
				self.burst_fwd.bb2bts()

			# CTRL commands from BTS
			if self.bts_ctrl.sock in r_event:
				data, addr = self.bts_ctrl.sock.recvfrom(128)
				self.bts_ctrl.handle_rx(data.decode(), addr)

			# CTRL commands from BB
			if self.bb_ctrl.sock in r_event:
				data, addr = self.bb_ctrl.sock.recvfrom(128)
				self.bb_ctrl.handle_rx(data.decode(), addr)
Ejemplo n.º 11
0
class Application:
	# Application variables
	bts_addr = "127.0.0.1"
	bb_addr = "127.0.0.1"
	trx_bind_addr = "0.0.0.0"
	bts_base_port = 5700
	bb_base_port = 6700

	# BurstForwarder field randomization
	randomize_dl_toa256 = False
	randomize_ul_toa256 = False
	randomize_dl_rssi = False
	randomize_ul_rssi = False

	def __init__(self):
		print_copyright(CR_HOLDERS)
		self.parse_argv()

		# Set up signal handlers
		signal.signal(signal.SIGINT, self.sig_handler)

	def run(self):
		# Init TRX CTRL interface for BTS
		self.bts_ctrl = CTRLInterfaceBTS(self.bts_addr, self.bts_base_port + 101,
			self.trx_bind_addr, self.bts_base_port + 1)

		# Init TRX CTRL interface for BB
		self.bb_ctrl = CTRLInterfaceBB(self.bb_addr, self.bb_base_port + 101,
			self.trx_bind_addr, self.bb_base_port + 1)

		# Power measurement emulation
		# Noise: -120 .. -105
		# BTS: -75 .. -50
		self.pm = FakePM(-120, -105, -75, -50)

		# Share a FakePM instance between both BTS and BB
		self.bts_ctrl.pm = self.pm
		self.bb_ctrl.pm = self.pm

		# Init DATA links
		self.bts_data = UDPLink(self.bts_addr, self.bts_base_port + 102,
			self.trx_bind_addr, self.bts_base_port + 2)
		self.bb_data = UDPLink(self.bb_addr, self.bb_base_port + 102,
			self.trx_bind_addr, self.bb_base_port + 2)

		# BTS <-> BB burst forwarding
		self.burst_fwd = BurstForwarder(self.bts_data, self.bb_data)
		self.burst_fwd.randomize_dl_toa256 = self.randomize_dl_toa256
		self.burst_fwd.randomize_ul_toa256 = self.randomize_ul_toa256
		self.burst_fwd.randomize_dl_rssi = self.randomize_dl_rssi
		self.burst_fwd.randomize_ul_rssi = self.randomize_ul_rssi

		# Share a BurstForwarder instance between BTS and BB
		self.bts_ctrl.burst_fwd = self.burst_fwd
		self.bb_ctrl.burst_fwd = self.burst_fwd

		# Provide clock to BTS
		self.bts_clck = UDPLink(self.bts_addr, self.bts_base_port + 100,
			self.trx_bind_addr, self.bts_base_port)
		self.clck_gen = CLCKGen([self.bts_clck])
		self.bts_ctrl.clck_gen = self.clck_gen

		print("[i] Init complete")

		# Enter main loop
		while True:
			socks = [self.bts_ctrl.sock, self.bb_ctrl.sock,
				self.bts_data.sock, self.bb_data.sock]

			# Wait until we get any data on any socket
			r_event, w_event, x_event = select.select(socks, [], [])

			# Downlink: BTS -> BB
			if self.bts_data.sock in r_event:
				self.burst_fwd.bts2bb()

			# Uplink: BB -> BTS
			if self.bb_data.sock in r_event:
				self.burst_fwd.bb2bts()

			# CTRL commands from BTS
			if self.bts_ctrl.sock in r_event:
				data, addr = self.bts_ctrl.sock.recvfrom(128)
				self.bts_ctrl.handle_rx(data.decode(), addr)

			# CTRL commands from BB
			if self.bb_ctrl.sock in r_event:
				data, addr = self.bb_ctrl.sock.recvfrom(128)
				self.bb_ctrl.handle_rx(data.decode(), addr)

	def shutdown(self):
		print("[i] Shutting down...")

		# Stop clock generator
		self.clck_gen.stop()

	def print_help(self, msg = None):
		s  = " Usage: " + sys.argv[0] + " [options]\n\n" \
			 " Some help...\n" \
			 "  -h --help           this text\n\n"

		s += " TRX interface specific\n" \
			 "  -R --bts-addr       Set BTS remote address (default %s)\n"   \
			 "  -r --bb-addr        Set BB remote address (default %s)\n"    \
			 "  -P --bts-base-port  Set BTS base port number (default %d)\n" \
			 "  -p --bb-base-port   Set BB base port number (default %d)\n" \
			 "  -b --trx-bind-addr  Set TRX bind address (default %s)\n\n"

		s += " Simulation\n" \
			 "  --rand-dl-rssi      Enable DL RSSI randomization\n"   \
			 "  --rand-ul-rssi      Enable UL RSSI randomization\n"   \
			 "  --rand-dl-toa       Enable DL ToA randomization\n"    \
			 "  --rand-ul-toa       Enable UL ToA randomization\n"

		print(s % (self.bts_addr, self.bb_addr,
			self.bts_base_port, self.bb_base_port,
			self.trx_bind_addr))

		if msg is not None:
			print(msg)

	def parse_argv(self):
		try:
			opts, args = getopt.getopt(sys.argv[1:],
				"R:r:P:p:b:h",
				[
					"help",
					"bts-addr=", "bb-addr=",
					"bts-base-port=", "bb-base-port=",
					"trx-bind-addr=",
					"rand-dl-rssi", "rand-ul-rssi",
					"rand-dl-toa", "rand-ul-toa",
				])
		except getopt.GetoptError as err:
			self.print_help("[!] " + str(err))
			sys.exit(2)

		for o, v in opts:
			if o in ("-h", "--help"):
				self.print_help()
				sys.exit(2)

			elif o in ("-R", "--bts-addr"):
				self.bts_addr = v
			elif o in ("-r", "--bb-addr"):
				self.bb_addr = v

			elif o in ("-P", "--bts-base-port"):
				self.bts_base_port = int(v)
			elif o in ("-p", "--bb-base-port"):
				self.bb_base_port = int(v)

			elif o in ("-b", "--trx-bind-addr"):
				self.trx_bind_addr = v

			# Message field randomization
			elif o == "rand-dl-rssi":
				self.randomize_dl_rssi = True
			elif o == "rand-ul-rssi":
				self.randomize_ul_rssi = True
			elif o == "rand-dl-toa":
				self.randomize_dl_toa256 = True
			elif o == "rand-ul-toa":
				self.randomize_ul_toa256 = True

		# Ensure there is no overlap between ports
		if self.bts_base_port == self.bb_base_port:
			self.print_help("[!] BTS and BB base ports should be different")
			sys.exit(2)

		bts_ports = [
			self.bts_base_port + 0, self.bts_base_port + 100,
			self.bts_base_port + 1, self.bts_base_port + 101,
			self.bts_base_port + 2, self.bts_base_port + 102,
		]

		bb_ports = [
			self.bb_base_port + 0, self.bb_base_port + 100,
			self.bb_base_port + 1, self.bb_base_port + 101,
			self.bb_base_port + 2, self.bb_base_port + 102,
		]

		for p in bb_ports:
			if p in bts_ports:
				self.print_help("[!] BTS and BB ports overlap detected")
				sys.exit(2)

	def sig_handler(self, signum, frame):
		print("Signal %d received" % signum)
		if signum is signal.SIGINT:
			self.shutdown()
			sys.exit(0)