00001
00002
00003
00004 import roslib; roslib.load_manifest('network_monitor_udp')
00005 import rospy
00006
00007 import sys
00008 import network_monitor_udp.msg as msgs
00009 from network_monitor_udp.udpmoncli import MonitorClient
00010
00011 if __name__ == "__main__":
00012 try:
00013 rospy.init_node('udpmonclinode', anonymous=True)
00014 host = rospy.get_param("~host")
00015 port = int(rospy.get_param("~port", 1234))
00016 rate = float(rospy.get_param("~pkt_rate", 100.0))
00017 size = int(rospy.get_param("~pkt_size", 32))
00018 interface = rospy.get_param("~interface", "0.0.0.0")
00019 update_rate = float(rospy.get_param("~update_rate", 2.0))
00020 bin_limits = rospy.get_param("~bin_limits", "0.005 0.01 0.1 0.2 0.3 0.4 0.5")
00021 bin_limits = [float(val) for val in bin_limits.split()]
00022 cli = MonitorClient(bin_limits, (host, port), rate, size, sourceaddr = (interface, 0))
00023 pub = rospy.Publisher('udpmonitor', msgs.UdpMonitor)
00024 try:
00025 display_interval_sec = 1.0 / update_rate
00026 display_interval = rospy.Duration(display_interval_sec)
00027 start_time = rospy.Time.now()
00028 next_time = start_time
00029 msg = msgs.UdpMonitor()
00030 msg.server_host = host
00031 msg.server_port = port
00032 msg.source_interface = interface
00033 msg.latency_bin_limits = bin_limits
00034 msg.packet_size = size
00035 msg.packet_rate = rate
00036
00037 while not rospy.is_shutdown():
00038 next_time = next_time + display_interval
00039 sleeptime = next_time - rospy.Time.now()
00040 rospy.sleep(sleeptime)
00041 msg.latency_bin_values, msg.average_latency_all, msg.average_latency_fresh = \
00042 cli.get_smart_bins(display_interval_sec)
00043 msg.header.stamp = rospy.Time.now()
00044 msg.loss_fresh = 1. - sum(msg.latency_bin_values[:-1])
00045 pub.publish(msg)
00046
00047 finally:
00048 cli.shutdown()
00049
00050 except KeyboardInterrupt:
00051 print >> sys.stderr, "Exiting on CTRL+C."
00052