Exemplo n.º 1
0
    def subscribe_multicast(self):
        """Automated multicasting subscription"""
        parse_address = StreamAddress._parse_address_string
        try:
            n_xengs = self.katcp_rct.sensor.n_xengs.get_value()
        except Exception:
            n_xengs = len(self.get_multicast_ips) * 2

        if self.config_filename is None:
            return
        config = self.corr_config
        if config is None:
            LOGGER.error('Failed to retrieve correlator config file, ensure that the cbf is running')
            return False

        def confirm_multicast_subs(mul_ip='239.100.0.10'):
            """"""
            # or use [netstat -g | grep eth2]
            list_inets = subprocess.check_output(['ip', 'maddr', 'show'])
            return True if mul_ip in list_inets else False

        outputIPs = {}
        for i in [key for key, value in config.items() if 'output_destinations_base' in value]:
            _IP, _num, _Port = list(parse_address(config[i]['output_destinations_base']))
            outputIPs[i] = [tengbe.IpAddress(_IP), int(_Port)]
        if outputIPs.get('xengine'):
            LOGGER.info('Multicast subscription is only valid for xengines')
            multicastIP, DataPort = outputIPs.get('xengine')
            if multicastIP.is_multicast():
                LOGGER.info('source is multicast %s.' % (multicastIP))
                # look up multicast group address in name server and find out IP version
                addrinfo = socket.getaddrinfo(str(multicastIP), None)[0]
                # create a socket
                try:
                    mcast_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
                except Exception:
                    mcast_sock = socket.socket(addrinfo[0], socket.SOCK_DGRAM)
                mcast_sock.setblocking(False)
                # Do not bind as this will cause a conflict when instantiating a receiver on the main script
                # Join group
                # mcast_sock.bind(('', DataPort))
                add_cleanup(mcast_sock.close)
                def join_mcast_group(address):
                    group_bin = socket.inet_pton(socket.AF_INET, address)
                    if addrinfo[0] == socket.AF_INET:  # IPv4
                        mreq = group_bin + struct.pack('=I', socket.INADDR_ANY)
                        mcast_sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
                        LOGGER.info('Successfully subscribed to %s:%s.' % (str(multicastIP), DataPort))
                    else:
                        mreq = group_bin + struct.pack('@I', 0)
                        mcast_sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_JOIN_GROUP, mreq)
                        LOGGER.info('Successfully subscribed to %s:%s.' % (str(multicastIP), DataPort))
                for addcntr in range(n_xengs):
                    _address = tengbe.IpAddress(multicastIP.ip_int + addcntr)
                    join_mcast_group(str(_address))
            else:
                mcast_sock = None
                LOGGER.info('Source is not multicast: %s:%s' % (str(multicastIP), DataPort))
                return False
        return confirm_multicast_subs(mul_ip=str(_address))
Exemplo n.º 2
0
    for spead_pkt in spead_processor.packets:
        spead_data.extend(spead_pkt.get_strings())
    coredata[data_key] = spead_data

packet_counter = 0
for ctr in range(0, len(coredata[data_key])):
    if coredata[eof_key][ctr - 1]:
        packet_counter = 0
    print('%5d,%3d' % (ctr, packet_counter), end='')
    for key in key_order:
        if key == ip_key:
            if key == 'ip':
                display_key = 'dst_ip'
            elif key == 'ip_in':
                display_key = 'src_ip'
            else:
                raise RuntimeError('Unknown IP key?')
            ip_str = str(tengbe.IpAddress(coredata[key][ctr]))
            print('%s(%s)\t' % (display_key, ip_str), end='')
        elif (key == data_key) and args.spead:
            print('%s(%s)\t' % (key, coredata[data_key][ctr]), end='')
        else:
            if args.hex:
                print('%s(0x%X)\t' % (key, coredata[key][ctr]), end='')
            else:
                print('%s(%s)\t' % (key, coredata[key][ctr]), end='')
    print('')
    packet_counter += 1

# end
Exemplo n.º 3
0
    for spead_pkt in spead_processor.packets:
        spead_data.extend(spead_pkt.get_strings())
    coredata[data_key] = spead_data

packet_counter = 0
for ctr in range(0, len(coredata[data_key])):
    if coredata[eof_key][ctr - 1]:
        packet_counter = 0
    print '%5d,%3d' % (ctr, packet_counter),
    for key in key_order:
        if key == ip_key:
            if key == 'ip':
                display_key = 'dst_ip'
            elif key == 'ip_in':
                display_key = 'src_ip'
            else:
                raise RuntimeError('Unknown IP key?')
            print '%s(%s)' % (display_key,
                              str(tengbe.IpAddress(coredata[key][ctr]))), '\t',
        elif (key == data_key) and args.spead:
            print '%s(%s)' % (key, coredata[data_key][ctr]), '\t',
        else:
            if args.hex:
                print '%s(0x%X)' % (key, coredata[key][ctr]), '\t',
            else:
                print '%s(%s)' % (key, coredata[key][ctr]), '\t',
    print ''
    packet_counter += 1

# end
Exemplo n.º 4
0
        ftx.get_system_information(args.txfpg)
        frx.get_system_information(args.rxfpg)
        logging.info('Stopping TX.')
        ftx.registers.control.write(tx_en=0, pkt_rst='pulse')
        frx.registers.control.write(snap_arm=0)

    to_pc = False

    # set up TX
    import IPython
    IPython.embed()
    print frx
    ip_dest = frx.gbes["forty_gbe"].get_ip()
    if to_pc:
        from casperfpga import tengbe
        ip_dest = tengbe.IpAddress('10.99.1.1')
    logging.info('Setting TX destination to %s.' % ip_dest)
    ftx.registers.tx_ip = int(ip_dest)
    ftx.registers.tx_port = 8765
    ftx.registers.control.write(pkt_len=args.pktsize)
    clk_ghz = ftx.registers.clk_mhz.read()['data']['reg'] / 1000.0
    if args.decimate > -1:
        decimation = args.decimate
    else:
        decimation = int((clk_ghz * 256.0 / args.rate) + 1)
    actual_rate = clk_ghz * 256.0 / decimation
    logging.info('Sending data at %.3fGbps (%.3fGhz * 256 / %i)' %
                 (actual_rate, clk_ghz, decimation))
    ftx.registers.decimation.write(reg=decimation)

    # set up RX