Ejemplo n.º 1
0
def availability(resource, status) :
    # TUB server
    oml = OMLBase("myops2","PLE","PLETestbed","tcp:193.175.132.241:3003")
    
    oml.mpprefix = False
    
    oml.addmp("availability", "node:string up:double last_check:string")
    oml.start()
    
    oml.inject("availability", (resource, status, datetime.now().isoformat()  + "+01:00"))
    
    oml.close()
Ejemplo n.º 2
0
class TestOmlClient(threading.Thread):
    def __init__(self, interval=10):
        threading.Thread.__init__(self, name=APPLICATION_NAME)
        self.__mutex = threading.Lock()
        self.__stop = threading.Event()
        self.__interval = int(interval)
        self.daemon = True
        self.oml = OMLBase(APPLICATION_NAME, DOMAIN, IDENTIFIER, URL)
        self.start()

    def define_measurements(self):
        msformat = "freq:string amplitude:int32"
        self.oml.addmp(MEASUREMENT_POINT_NAME, msformat)
        print "%s: defined measurements format=%s" %\
            (MEASUREMENT_POINT_NAME, msformat)

    def action(self):
        tmp = [random.choice(S.ascii_letters + S.digits) for n in xrange(32)]
        data = [''.join(tmp), random.randint(0, 100)]
        self.oml.inject(MEASUREMENT_POINT_NAME, data)
        print "%s: sent data to collector=%s" % (MEASUREMENT_POINT_NAME, data)

    def run(self):
        print 'Run TestOmlClient'
        self.define_measurements()
        self.oml.start()
        try:
            while self.__isStopped() is False:
                self.action()
                print 'Waiting %dsecs' % (self.__interval)
                time.sleep(self.__interval)

        except Exception as e:
            print "Run error: %s" % str(e)
        finally:
            print "close communication to collector"
            self.oml.close()

    def loop(self, secs):
        while self.is_alive():
            self.join(secs)

    def stop(self):
        with self.__mutex:
            self.__stop.set()

    def __isStopped(self):
        with self.__mutex:
            return self.__stop.isSet()
Ejemplo n.º 3
0
def run ():
    for server in config.FACILITY_MON_SERVERS:

        oml=OMLBase(config.FM_APP, config.DOMAIN, config.SENDER, server)
        # MP for Controller Ping
        oml.addmp("icmp","node:string up:double last_check:string")
        # MP for Controller Http server (website)
        oml.addmp("http","node:string up:double last_check:string")
        
        controller_ping_up = ping_ipv4_is_ok(config.CLAB_CONTROLLER_IPv4)
        controller_http_up = website_is_ok(config.CLAB_CONTROLLER_URL)
        monitor_ping_up = ping_ipv4_is_ok(config.CLAB_MONITOR_IPV4)
        timestamp = current_timestamp()
        
        oml.start()
        oml.inject("icmp", ("controller", controller_ping_up, timestamp))
        oml.inject("http", ("controller", controller_http_up, timestamp))
        oml.close()

        print current_timestamp()+" - Facilitity Monitoring: data sent to "+server
Ejemplo n.º 4
0
def main():
    global n_rcvd, n_right, start_time, start, once
    once = 1
    n_rcvd = 0
    n_right = 0

    def rx_callback(ok, payload):
        global n_rcvd, n_right
        try:
            (pktno, ) = struct.unpack('!H', payload[0:2])
            data = payload[2:]
            n_rcvd += 1
            if ok:
                n_right += 1

                if options.server:
                    sock.sendall(data)
            current = time.time() - start
        except:
            print "except"

#print "current time = %f ok = %5s  pktno = %4d  n_rcvd = %4d  n_right = %4d" % (current, ok, pktno, n_rcvd, n_right)
        omlDb.inject("packets", ("received", n_rcvd))
        omlDb.inject("packets", ("correct", n_right))

    demods = digital.modulation_utils.type_1_demods()

    # Create Options Parser:
    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")

    parser.add_option("-m",
                      "--modulation",
                      type="choice",
                      choices=demods.keys(),
                      default='gfsk',
                      help="Select modulation from: %s [default=%%default]" %
                      (', '.join(demods.keys()), ))
    parser.add_option("",
                      "--from-file",
                      default=None,
                      help="input file of samples to demod")
    parser.add_option("-E",
                      "--exp-id",
                      type="string",
                      default="test",
                      help="specify the experiment ID")
    parser.add_option("-N",
                      "--node-id",
                      type="string",
                      default="rx",
                      help="specify the experiment ID")
    parser.add_option("",
                      "--server",
                      action="store_true",
                      default=False,
                      help="To take data from the server")
    parser.add_option("",
                      "--port",
                      type="int",
                      default=None,
                      help="specify the server port")

    receive_path.add_options(parser, expert_grp)
    uhd_receiver.add_options(parser)

    for mod in demods.values():
        mod.add_options(expert_grp)

    (options, args) = parser.parse_args()

    omlDb = OMLBase("gnuradiorx", options.exp_id, options.node_id,
                    "tcp:nitlab3.inf.uth.gr:3003")
    omlDb.addmp("packets", "type:string value:long")

    omlDb.start()

    if len(args) != 0:
        parser.print_help(sys.stderr)
        sys.exit(1)

    if options.from_file is None:
        if options.rx_freq is None:
            sys.stderr.write("You must specify -f FREQ or --freq FREQ\n")
            parser.print_help(sys.stderr)
            sys.exit(1)

    # connect to server
    if options.server:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        #    	server_address = ('10.0.1.200', 50001)
        server_address = ('10.0.1.200', options.port)
        print >> sys.stderr, 'connecting to %s port %s' % server_address
        sock.connect(server_address)

    # build the graph
    tb = my_top_block(demods[options.modulation], rx_callback, options)

    r = gr.enable_realtime_scheduling()
    if r != gr.RT_OK:
        print "Warning: Failed to enable realtime scheduling."

    tb.start()  # start flow graph
    start = time.time()

    while 1:
        current = time.time() - start
        if current >= 5:
            symbol_rate = options.bitrate / demods[options.modulation](
                **args).bits_per_symbol()
            tb.source.set_sample_rate(symbol_rate, options.samples_per_symbol)

            options.rx_freq += 0.75e6
            tb.source.set_freq(options.rx_freq, options.lo_offset)
            break
    #print "FROM OPTIONS.........", tb.source._freq
    tb.wait()  # wait for it to finish

    if options.server:
        sock.close()
Ejemplo n.º 5
0
class Agent(threading.Thread):
    __metaclass__ = ABCMeta

    @abstractmethod
    def define_measurements(self):
        pass

    @abstractmethod
    def action(self):
        pass

    def __init__(self, name, domain, id_, collector, interval, logger=None):
        threading.Thread.__init__(self, name=name)
        self.__mutex = threading.Lock()
        self.__stop = threading.Event()
        self.__logger = logger
        self.__interval = int(interval)
        self.daemon = True
        self.oml = OMLBase(name, domain, id_, collector)
        self.start()

    def loop(self, secs):
        while self.is_alive():
            self.join(secs)

    def run (self):
        self.__debug("Run agent base object")
        self.define_measurements()
        self.oml.start()
        try:
            while self.__isStopped() == False:
                self.action()

                self.__debug("Waiting %dsecs before perform an action" %
                             (self.__interval,))
                time.sleep(self.__interval)

        except Exception as e:
            self.error("Run error: %s" % (str(e),))

        finally:
            self.__debug("close communication to collector")
            self.oml.close()

    def stop(self):
        with self.__mutex:
            self.__stop.set()

    def info(self, msg):
        if self.__logger:
            self.__logger.info(msg)

    def error(self, msg):
        if self.__logger:
            self.__logger.error(msg)

    def __debug(self, msg):
        if self.__logger:
            self.__logger.debug(msg)

    def __isStopped(self):
        with self.__mutex:
            return self.__stop.isSet()
def main():
    
    random.seed(os.urandom(100))

    def send_pkt(payload='', eof=False):
        return tb.txpath.send_pkt(payload, eof)

    mods = digital.modulation_utils.type_1_mods()

    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")

    parser.add_option("-m", "--modulation", type="choice", choices=mods.keys(),
                      default='gmsk',
                      help="Select modulation from: %s [default=%%default]"
                            % (', '.join(mods.keys()),))

    parser.add_option("-s", "--size", type="eng_float", default=1500,
                      help="set packet size [default=%default]")
    parser.add_option("-M", "--megabytes", type="eng_float", default=1.0,
                      help="set megabytes to transmit [default=%default]")
    parser.add_option("","--discontinuous", action="store_true", default=False,
                      help="enable discontinous transmission (bursts of 5 packets)")
    parser.add_option("","--from-file", default=None,
                      help="use intput file for packet contents")
    parser.add_option("","--to-file", default=None,
                      help="Output file for modulated samples")
    parser.add_option("-E", "--exp-id", type="string", default="test",
                          help="specify the experiment ID")
    parser.add_option("-N", "--node-id", type="string", default="tx",
                          help="specify the experiment ID")
    parser.add_option("","--server", action="store_true", default=False,
                      help="To take data from the server")
    parser.add_option("", "--port", type="int", default=None,
                          help="specify the server port")

    transmit_path.add_options(parser, expert_grp)
    uhd_transmitter.add_options(parser)

    for mod in mods.values():
        mod.add_options(expert_grp)

    (options, args) = parser.parse_args ()


    omlDb = OMLBase("gnuradiorx",options.exp_id,options.node_id,"tcp:nitlab3.inf.uth.gr:3003")
    omlDb.addmp("packets", "type:string value:long")

    omlDb.start()


    if len(args) != 0:
        parser.print_help()
        sys.exit(1)
           
    if options.from_file is not None:
        source_file = open(options.from_file, 'r')

    # build the graph
    tb = my_top_block(mods[options.modulation], options)

    r = gr.enable_realtime_scheduling()
    if r != gr.RT_OK:
        print "Warning: failed to enable realtime scheduling"

    tb.start()                       # start flow graph
        
    # generate and send packets
    nbytes = int(1e6 * options.megabytes)
    n = 0
    pktno = 0
    pkt_size = int(options.size)

    # connect to server
    if options.server:
    	sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#	server_address = ('10.0.1.200', 51000)
        server_address = ('10.0.1.200', options.port)
    	print >>sys.stderr, 'connecting to %s port %s' % server_address
    	sock.connect(server_address)
    	


    freq_list = [options.tx_freq, options.tx_freq+1000000.0, options.tx_freq-1000000.0]


    payload_buffer = []
    curr_freq = best_freq= options.tx_freq
    while pktno<1000:
	if options.server:
            data = "";
            while len(data) < pkt_size:
		if (pktno<1000):
                    data += sock.recv(pkt_size - len(data))
                if data == '':
                    # No more data received from server
                    sock.close()
                    break;
        elif options.from_file is None:
            data = (pkt_size - 2) * chr(pktno & 0xff)
        else:
            data = source_file.read(pkt_size - 2)
            if data == '':
                break;

        if pktno%200==0:
			time.sleep(0.7)
			tb.source.set_center_freq(uhd.tune_request(curr_freq,0))
			time.sleep(0.01)
			
			if(tb.probe.level()>0.15): #find best freq
				lowest=3
				i=0
				for i in range (len(freq_list)):
					#if freq_list[i]!=curr_freq:
					tb.source.set_center_freq(uhd.tune_request(freq_list[i],0))
					time.sleep(0.01)
					measurement = tb.probe.level()
					if measurement<lowest:
						lowest = measurement
						best_freq = freq_list[i]
				curr_freq = best_freq
				tb.sink.set_freq(best_freq,0)
				


        payload = struct.pack('!H', pktno & 0xffff) + data
        send_pkt(payload)
        payload_buffer.insert(pktno,payload)
        n += len(payload)
        sys.stderr.write('.')
        omlDb.inject("packets", ("sent", pktno))
        if options.discontinuous and pktno % 5 == 4:
            time.sleep(1)
        pktno += 1
        
    i=0
    while(1):
		if i==40 :#problematic packets
			for k in range(0,5):
				send_pkt(payload_buffer[k*200+199])
				send_pkt(payload_buffer[k*200])
				
				
		if i%200==0:
			time.sleep(0.7)
			tb.source.set_center_freq(uhd.tune_request(curr_freq,0))
			time.sleep(0.01)
			if(tb.probe.level()>0.15): #find best freq
				
				
				
				lowest=3
				for j in range (len(freq_list)):
					#if freq_list[j]!=curr_freq:
					tb.source.set_center_freq(uhd.tune_request(freq_list[j],0))
					time.sleep(0.01)
					measurement = tb.probe.level()
					if measurement<lowest:
						lowest = measurement
						best_freq = freq_list[j]
				curr_freq = best_freq
				tb.sink.set_freq(best_freq,0)
				
				

		send_pkt(payload_buffer[i%1000])
		i+=1

    send_pkt(eof=True)

    tb.wait()                       # wait for it to finish
Ejemplo n.º 7
0
def main():
    def send_pkt(payload='', eof=False):
        return tb.txpath.send_pkt(payload, eof)

    mods = digital.modulation_utils.type_1_mods()

    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")

    parser.add_option("-m",
                      "--modulation",
                      type="choice",
                      choices=mods.keys(),
                      default='gfsk',
                      help="Select modulation from: %s [default=%%default]" %
                      (', '.join(mods.keys()), ))

    parser.add_option("-s",
                      "--size",
                      type="eng_float",
                      default=1500,
                      help="set packet size [default=%default]")
    parser.add_option("-M",
                      "--megabytes",
                      type="eng_float",
                      default=1.0,
                      help="set megabytes to transmit [default=%default]")
    parser.add_option(
        "",
        "--discontinuous",
        action="store_true",
        default=False,
        help="enable discontinous transmission (bursts of 5 packets)")
    parser.add_option("",
                      "--from-file",
                      default=None,
                      help="use intput file for packet contents")
    parser.add_option("",
                      "--to-file",
                      default=None,
                      help="Output file for modulated samples")
    parser.add_option("-E",
                      "--exp-id",
                      type="string",
                      default="test",
                      help="specify the experiment ID")
    parser.add_option("-N",
                      "--node-id",
                      type="string",
                      default="tx",
                      help="specify the experiment ID")
    parser.add_option("",
                      "--server",
                      action="store_true",
                      default=False,
                      help="To take data from the server")
    parser.add_option("",
                      "--port",
                      type="int",
                      default=None,
                      help="specify the server port")

    transmit_path.add_options(parser, expert_grp)
    uhd_transmitter.add_options(parser)

    for mod in mods.values():
        mod.add_options(expert_grp)

    (options, args) = parser.parse_args()

    omlDb = OMLBase("gnuradiorx", options.exp_id, options.node_id,
                    "tcp:nitlab3.inf.uth.gr:3003")
    omlDb.addmp("packets", "type:string value:long")

    omlDb.start()

    if len(args) != 0:
        parser.print_help()
        sys.exit(1)

    if options.from_file is not None:
        source_file = open(options.from_file, 'r')

    # build the graph
    tb = my_top_block(mods[options.modulation], options)

    r = gr.enable_realtime_scheduling()
    if r != gr.RT_OK:
        print "Warning: failed to enable realtime scheduling"

    tb.start()  # start flow graph

    start = time.time()
    # generate and send packets
    nbytes = int(1e6 * options.megabytes)
    n = 0
    pktno = 0
    pkt_size = int(options.size)
    buffer = []
    stable_buffer = []
    once = 1
    # connect to server
    if options.server:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        #server_address = ('10.0.1.200', 50000)
        server_address = ('10.0.1.200', options.port)
        print >> sys.stderr, 'connecting to %s port %s' % server_address
        sock.connect(server_address)

        while pktno < 1000:
            if n < nbytes or options.server:
                if options.server:
                    data = ""
                    while len(data) < pkt_size:
                        data += sock.recv(pkt_size - len(data))
                        if data == '':
                            # No more data received from server
                            sock.close()
                            break
                elif options.from_file is None:
                    data = (pkt_size - 2) * chr(pktno & 0xff)
                else:
                    data = source_file.read(pkt_size - 2)
                if data == '':
                    break

                payload = struct.pack('!H', pktno & 0xffff) + data
                buffer.insert(pktno, payload)
                stable_buffer.insert(pktno, payload)
                send_pkt(payload)
                n += len(payload)
                sys.stderr.write('.')
                omlDb.inject("packets", ("sent", pktno))
                if options.discontinuous and pktno % 5 == 4:
                    time.sleep(1)
                pktno += 1
            else:
                break

    while buffer:
        current_elapsed = time.time() - start
        if current_elapsed >= 3 and once == 1:
            options.bitrate = 1.3e6
            once = 0
            #gr.top_block.__init__(tb)

            args = mods[options.modulation].extract_kwargs_from_options(
                options)
            modulator = mods[options.modulation]

            symbol_rate = options.bitrate / modulator(**args).bits_per_symbol()

            tb.sink.set_sample_rate(symbol_rate, options.samples_per_symbol)
            options.tx_freq += 0.75e6
            tb.sink.set_freq(options.tx_freq, options.lo_offset)
            #print "from options.......... ", options.tx_freq
            print "IN FREQ", tb.sink._freq
            #print "WITH BITRATE ", options.bitrate
            #print "BITRATE FROM TB ", tb.txpath._bitrate

        for i in range(0, pktno):
            print "BITRATE FROM get ", tb.txpath.bitrate()

            send_pkt(buffer[i])

    send_pkt(eof=True)
    tb.wait()  # wait for it to finish
Ejemplo n.º 8
0
def main():
    global n_rcvd, n_right, nopkt, start

    random.seed(os.urandom(100))

    n_rcvd = 0
    n_right = 0
    nopkt = 1

    def rx_callback(ok, payload):
        global n_rcvd, n_right, start, nopkt
        (pktno, ) = struct.unpack('!H', payload[0:2])
        data = payload[2:]
        n_rcvd += 1

        if ok:
            nopkt = 0
            n_right += 1
            if options.server:
                sock.sendall(data)


#                if n_right == 1000:
#					print "JSHABJKWHBEWJQKBEHWQKJWQEJWQRKBKJWQRBOJWRQB\n"
#					sock.close()
        start = time.time()
        #print "ok = %5s  pktno = %4d  n_rcvd = %4d  n_right = %4d" % (
        #ok, pktno, n_rcvd, n_right)
        omlDb.inject("packets", ("received", n_rcvd))
        omlDb.inject("packets", ("correct", n_right))

    demods = digital.modulation_utils.type_1_demods()

    # Create Options Parser:
    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    expert_grp = parser.add_option_group("Expert")

    parser.add_option("-m",
                      "--modulation",
                      type="choice",
                      choices=demods.keys(),
                      default='gmsk',
                      help="Select modulation from: %s [default=%%default]" %
                      (', '.join(demods.keys()), ))
    parser.add_option("",
                      "--from-file",
                      default=None,
                      help="input file of samples to demod")
    parser.add_option("-E",
                      "--exp-id",
                      type="string",
                      default="test",
                      help="specify the experiment ID")
    parser.add_option("-N",
                      "--node-id",
                      type="string",
                      default="rx",
                      help="specify the experiment ID")
    parser.add_option("",
                      "--server",
                      action="store_true",
                      default=False,
                      help="To take data from the server")
    parser.add_option("",
                      "--port",
                      type="int",
                      default=None,
                      help="specify the server port")

    receive_path.add_options(parser, expert_grp)
    uhd_receiver.add_options(parser)

    for mod in demods.values():
        mod.add_options(expert_grp)

    (options, args) = parser.parse_args()

    omlDb = OMLBase("gnuradiorx", options.exp_id, options.node_id,
                    "tcp:nitlab3.inf.uth.gr:3003")
    omlDb.addmp("packets", "type:string value:long")

    omlDb.start()

    if len(args) != 0:
        parser.print_help(sys.stderr)
        sys.exit(1)

    if options.from_file is None:
        if options.rx_freq is None:
            sys.stderr.write("You must specify -f FREQ or --freq FREQ\n")
            parser.print_help(sys.stderr)
            sys.exit(1)

    # connect to server
    if options.server:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        #    	server_address = ('10.0.1.200', 51001)
        server_address = ('10.0.1.200', options.port)
        print >> sys.stderr, 'connecting to %s port %s' % server_address
        sock.connect(server_address)

    # build the graph
    tb = my_top_block(demods[options.modulation], rx_callback, options)

    r = gr.enable_realtime_scheduling()
    if r != gr.RT_OK:
        print "Warning: Failed to enable realtime scheduling."

    tb.start()  # start flow graph
    #    tb.wait()         # wait for it to finish

    freq_list = [
        options.rx_freq, options.rx_freq + 1000000.0,
        options.rx_freq - 1000000.0
    ]
    i = 0
    nopkt = 1
    while 1:
        #		pwr= tb.rxpath.probe.level()
        while (nopkt):
            tb.source.set_freq(freq_list[i % 3], 0)
            i += 1
            time.sleep(0.05)

        if (time.time() - start > 0.5):
            nopkt = 1

    if options.server:
        sock.close()