def set_time(self, time, time_id=None): """Sets the time in microseconds on the node. Attributes: time -- Time to send to the board (either float in sec or int in us) """ self.send_cmd(cmds.NodeProcTime(cmds.CMD_PARAM_WRITE, time, time_id))
def _broadcast_time_to_nodes(time_cmd, host_config, time=0.0, time_id=None): """Internal method to issue broadcast time commands This method will iterate through all host interfaces and issue a broadcast packet on each interface that will set the time to the timebase. The method keeps track of how long it takes to send each packet so that the time on all nodes is as close as possible even across interface. Attributes: time_cmd -- NodeProcTime command to issue host_config -- A WnConfiguration object describing the host configuration time -- Optional time to broadcast to the nodes (defaults to 0.0) either as an integer number of microseconds or a floating point number in seconds time_id -- Optional value to identify broadcast time commands across nodes """ import wlan_exp.cmds as cmds import wlan_exp.warpnet.util as util import wlan_exp.warpnet.transport_eth_udp_py_bcast as bcast time_factor = 6 # Time can be in # of microseconds (ie 10^(-6) seconds) # Get information out of the WnConfiguration interfaces = host_config.get_param('network', 'host_interfaces') tx_buf_size = host_config.get_param('network', 'tx_buffer_size') rx_buf_size = host_config.get_param('network', 'rx_buffer_size') # Need to convert time input to float so that it can be added to _time() if (type(time) is float): node_time = time elif (type(time) is int): node_time = float(time / (10**time_factor)) # Convert to float else: raise TypeError("Time must be either a float or int") # Send the broadcast commands for ech interface for idx, interface in enumerate(interfaces): # Create broadcast transport transport_bcast = bcast.TransportEthUdpPyBcast(host_config, interface); transport_bcast.wn_open(tx_buf_size, rx_buf_size) if (idx == 0): node_time = node_time start_time = _time() else: node_time = node_time + (_time() - start_time) cmd = cmds.NodeProcTime(time_cmd, node_time, time_id); transport_bcast.send(cmd.serialize(), 'message') msg = "" if (time_cmd == cmds.CMD_PARAM_WRITE): msg += "Initializing the time of all nodes on " msg += "{0} to: {1}".format(util._get_ip_address_subnet(interface), node_time) elif (time_cmd == cmds.CMD_PARAM_TIME_ADD_TO_LOG): msg += "Adding current time to log for nodes on {0}".format(util._get_ip_address_subnet(interface)) print(msg)
def _broadcast_time_to_nodes(time_cmd, network_config, time=0.0, time_id=None): """Internal method to issue broadcast time commands This method will iterate through all host interfaces and issue a broadcast packet on each interface that will set the time to the timebase. The method keeps track of how long it takes to send each packet so that the time on all nodes is as close as possible even across interface. Attributes: time_cmd -- NodeProcTime command to issue network_config -- A NetworkConfiguration object time -- Optional time to broadcast to the nodes (defaults to 0.0) either as an integer number of microseconds or a floating point number in seconds time_id -- Optional value to identify broadcast time commands across nodes """ import wlan_exp.cmds as cmds time_factor = 6 # Time can be in # of microseconds (ie 10^(-6) seconds) # Need to convert time input to float so that it can be added to _time() if (type(time) is float): node_time = time elif (type(time) is int): node_time = float(time / (10**time_factor)) # Convert to float else: raise TypeError("Time must be either a float or int") # Determine if we are sending to multiple networks if type(network_config) is list: configs = network_config else: configs = [network_config] # Send command to each network for idx, config in enumerate(configs): network_addr = config.get_param('network') if (idx == 0): node_time = node_time start_time = _time() else: node_time = node_time + (_time() - start_time) cmd = cmds.NodeProcTime(time_cmd, node_time, time_id) _broadcast_cmd_to_nodes_helper(cmd, network_config) msg = "" if (time_cmd == cmds.CMD_PARAM_WRITE): msg += "Initializing the time of all nodes on network " msg += "{0} to: {1}".format(network_addr, node_time) elif (time_cmd == cmds.CMD_PARAM_TIME_ADD_TO_LOG): msg += "Adding current time to log for nodes on network {0}".format( network_addr) print(msg)
def write_time_to_log(self, time_id=None): """Adds the current time in microseconds to the log.""" return self.send_cmd( cmds.NodeProcTime(cmds.CMD_PARAM_TIME_ADD_TO_LOG, cmds.CMD_PARAM_RSVD_TIME, time_id))
def get_time(self): """Gets the time in microseconds from the node.""" return self.send_cmd( cmds.NodeProcTime(cmds.CMD_PARAM_READ, cmds.CMD_PARAM_RSVD_TIME))