def on_send_gap(match, state): """It happens when the writer send a GAP message.""" writer_oid = get_oid(match[0]) remote_part = parse_guid(state, match[1], match[2], match[3]) reader_oid = get_oid(match[4]) sn_start = parse_sn(match[5]) sn_end = parse_sn(match[6]) verb = 1 if is_builtin_entity(match[0]) else 0 log_send( remote_part, writer_oid, "Sent GAP to reader %s for [%d, %d)" % (reader_oid, sn_start, sn_end), state, verb) add_statistics_packet(writer_oid, 'send', 'GAP', state) # Check for large sequence number issues. if sn_end - sn_start >= (1 << 31): log_warning("[LP-1] Large Sequence Number difference in GAP.", state) # Check for reliable packet lost if 'packets_lost' not in state: return losts = [] for k in state['packets_lost']: info = k.split("-") oid = info[0] seqnum = int(info[1]) if oid == writer_oid and seqnum >= sn_start and seqnum < sn_end: log_warning("DATA (%d) may have been lost" % seqnum, state) losts.append(k) for k in losts: state['packets_lost'].remove(k)
def on_send_hb_response(match, state): """It happens when sending a HB response.""" writer_oid = get_oid(match[0]) sn_end = parse_sn(match[1]) sn_start = parse_sn(match[2]) verb = 1 if is_builtin_entity(match[0]) else 0 log_send("", writer_oid, "Sent HB response for [%d, %d]" % (sn_start, sn_end), state, verb)
def on_send_preemptive_hb(match, state): """It happens when sending a preemptive HB message.""" writer_oid = get_oid(match[0]) sn_start = parse_sn(match[1]) sn_end = parse_sn(match[2]) verb = 1 if is_builtin_entity(match[0]) else 0 log_send("", writer_oid, "Sent preemptive HB for [%d, %d]" % (sn_start, sn_end), state, verb)
def on_send_piggyback_hb(match, state): """It happens when sending a piggyback HB message.""" writer_oid = get_oid(match[0]) sn_first = parse_sn(match[1]) sn_last = parse_sn(match[2]) verb = 1 if is_builtin_entity(match[0]) else 0 log_send("", writer_oid, "Sent PIGGYBACK HB for [%d, %d]" % (sn_first, sn_last), state, verb) add_statistics_packet(writer_oid, "send", "PIGGYBACK HB", state)
def on_receive_hb(match, state): """It happens when the write receives a HB.""" reader_oid = get_oid(match[0]) sn_start = parse_sn(match[1]) sn_end = parse_sn(match[2]) remote = match[4].split('.') writer_addr = parse_guid(state, remote[0], remote[1], remote[2]) writer_oid = get_oid(remote[3]) verb = 1 if is_builtin_entity(remote[3]) else 0 log_recv( writer_addr, reader_oid, "Received HB from writer %s for [%d, %d]" % (writer_oid, sn_start, sn_end), state, verb)
def on_receive_data(match, state): """It happens when the reader receives data.""" comm = "best-effort" if match[0] == "Be" else "reliable" reader_oid = get_oid(match[1]) packet = match[2] seqnum = parse_sn(match[3], 16 if match[0] == "Be" else 10) remote = match[5].split('.') writer_addr = parse_guid(state, remote[0], remote[1], remote[2]) writer_oid = get_oid(remote[3]) # Sequece number check full_id = writer_addr + "." + writer_oid + ' to ' + reader_oid if 'last_sn' not in state: state['last_sn'] = {} if full_id in state['last_sn']: prev_seqnum = state['last_sn'][full_id] diff = seqnum - prev_seqnum # Add a warning message per missing packet to have a good count in # the warning summary. for _ in range(diff - 1): log_warning("Missing packet for %s" % full_id, state) state['last_sn'][full_id] = seqnum # Show the message after any possible warning. verb = 1 if is_builtin_entity(remote[3]) else 0 log_recv( writer_addr, reader_oid, "Received %s (%d) from writer %s (%s)" % (packet, seqnum, writer_oid, comm), state, verb)
def on_resend_data(match, state): """It happens when the writer resend a DATA message.""" writer_oid = get_oid(match[0]) remote_part = parse_guid(state, match[1], match[2], match[3]) remote_oid = get_oid(match[4]) seqnum = parse_sn(match[5]) verb = 1 if is_builtin_entity(match[0]) else 0 log_send(remote_part, writer_oid, "Resend DATA (%d) to reader %s" % (seqnum, remote_oid), state, verb)
def on_send_data(match, state): """It happens when a DATA packet is sent.""" writer_oid = get_oid(match[0]) seqnum = parse_sn(match[1]) log_send("", writer_oid, "Sent DATA (%d)" % seqnum, state) add_statistics_packet(writer_oid, "send", "DATA", state) key = writer_oid + "-" + str(seqnum) if 'packets_lost' in state and key in state['packets_lost']: state['packets_lost'].remove(key)
def on_receive_ack(match, state): """It happens when receiving an ACK message.""" writer_oid = get_oid(match[0]) remote = match[1].split('.') reader_addr = parse_guid(state, remote[0], remote[1], remote[2]) reader_oid = get_oid(remote[3]) seqnum = parse_sn(match[2]) verb = 1 if is_builtin_entity(match[0]) else 0 log_recv(reader_addr, writer_oid, "Received ACKNACK from reader %s for %d" % (reader_oid, seqnum), state, verb)
def on_send_nack(match, state): """It happens when a NACK message is sent.""" reader_oid = get_oid(match[0]) lead = parse_sn(match[1]) bitcount = int(match[2]) remote = match[4].split('.') writer_addr = parse_guid(state, remote[0], remote[1], remote[2]) writer_oid = get_oid(remote[3]) verb = 1 if is_builtin_entity(remote[3]) else 0 log_send( writer_addr, reader_oid, "Sent NACK to writer %s for %d count %d" % (writer_oid, lead, bitcount), state, verb)
def on_receive_out_order_data(match, state): """It happens when the received data sequence number isn't contiguous.""" reader_oid = get_oid(match[0]) kind = "old" if match[1] == "old" else "future" seqnum = parse_sn(match[2]) remote = match[3].split('.') writer_addr = parse_guid(state, remote[0], remote[1], remote[2]) writer_oid = get_oid(remote[3]) verb = 1 if is_builtin_entity(remote[3]) else 0 log_recv( writer_addr, reader_oid, "Received %s DATA (%d) from writer %s" % (kind, seqnum, writer_oid), state, verb)
def on_schedule_data(match, state): """It happens when a data is asynchronously scheduled.""" writer_oid = get_oid(match[0]) seqnum = parse_sn(match[1]) log_process("", writer_oid, "Scheduled DATA (%d)" % seqnum, state) if 'packets_lost' not in state: state['packets_lost'] = [] key = writer_oid + "-" + str(seqnum) if key in state['packets_lost']: state['packets_lost'].remove(key) else: state['packets_lost'].append(key)
def on_rejected_data(match, state): """It happens when the reader rejects data.""" seqnum = parse_sn(match[0]) log_process("", "", "Reader rejected DATA (%d)" % seqnum, state) log_warning("A DataReader rejected sample %d" % seqnum, state)
def on_accept_data(match, state): """It happens when the reader accepts data.""" seqnum = parse_sn(match[0]) log_process("", "", "Reader accepted DATA (%d)" % seqnum, state, 1)