本文整理汇总了Python中src.sim.Sim.trace方法的典型用法代码示例。如果您正苦于以下问题:Python Sim.trace方法的具体用法?Python Sim.trace怎么用?Python Sim.trace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类src.sim.Sim
的用法示例。
在下文中一共展示了Sim.trace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_packet
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import trace [as 别名]
def handle_packet(self,packet):
# handle ACK (Sender)
# if the ACK number is greater than our send base...
# update the acknowledged segment counter, restart timer and send if possible
if packet.ack_number > self.send_base:
Sim.trace("ACK RCVD: %d <=== %d : %d" % (packet.destination_address,packet.source_address,packet.ack_number))
bytes_acked = packet.ack_number - self.send_base
self.not_yet_acknowledged_segments -= bytes_acked
if self.cwnd >= self.ssthreshold:
self.cwnd += (self.mss * bytes_acked) / self.cwnd
else:
self.cwnd += bytes_acked
self.cancel_timer()
self.timer = Sim.scheduler.add(delay=self.timeout, event='new_ack_data', handler=self.retransmit)
self.send_if_possible()
self.send_base = packet.ack_number
# print congestion window
if self.source_port > 3:
Sim.trace_custom("%f" % (self.cwnd/self.mss), 'cwnd', self.source_port)
# handle data (Receiver)
if packet.length > 0:
Sim.trace("SEGMENT RCVD: %d <=== %d : %d" % (packet.destination_address,packet.source_address,packet.sequence))
self.receive_temp_buffer.add(packet.sequence)
self.receive_packet_buffer.append(packet)
self.send_cumulative_ack()
示例2: receive_data
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import trace [as 别名]
def receive_data(self,data):
global original_size
global received_size
Sim.trace('AppHandler',"application got %d bytes" % (len(data)))
self.f.write(data)
received_size += len(data)
self.f.flush()
示例3: handle_ack
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import trace [as 别名]
def handle_ack(self, packet):
Sim.trace("%d received ReliableTransport ACK from %d for %d" % (packet.destination_address,packet.source_address,packet.ack_number))
self.unacked_packet_count -= ((packet.ack_number - self.received_ack_number) / self.mss)
self.cancel_timer()
self.timer = Sim.scheduler.add(delay=self.timeout, event='new_ack_data', handler=self.retransmit)
self.received_ack_number = packet.ack_number
self.send_if_possible()
示例4: handle_packet
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import trace [as 别名]
def handle_packet(self,packet):
# handle ACK
if packet.ack_number > self.window_start and packet.ack_number <= self.sequence:
# this acks new data, so advance the window with slide_window()
Sim.trace("%d received My_RTP ACK from %d for %d" % (packet.destination_address,packet.source_address,packet.ack_number))
self.slide_window(packet.ack_number)
# handle data
if packet.length > 0:
self.pkts_rcvd += 1
Sim.trace("%d received My_RTP segment from %d for %d" % (packet.destination_address,packet.source_address,packet.sequence))
# if the packet is the one we're expecting increment our
# ack number and add the data to the receive buffer
if packet.sequence >= self.ack:
self.receive_buffer.append(packet)
if packet.sequence == self.ack:
self.receive_buffer = sorted(self.receive_buffer, key=lambda TCPPacket: TCPPacket.sequence)
while self.receive_buffer and (self.ack == self.receive_buffer[0].sequence):
pkt = self.receive_buffer.pop(0)
self.increment_ack(pkt.sequence + pkt.length)
# deliver data that is in order
self.app.handle_packet(pkt)
# always send an ACK
self.send_ack()
if packet.queueing_delay > self.pkt_q_delay_threshold:
self.queueing_delay += packet.queueing_delay
print "\n[Average Queuing Delay so far:", str(self.queueing_delay / self.pkts_rcvd) + "]"
print "\n[Total Queueing Delay so far:", str(self.queueing_delay) + "]\n"
示例5: retransmit
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import trace [as 别名]
def retransmit(self,event):
if self.send_base >= len(self.send_buffer):
return
Sim.trace("%d's retransmission timer fired" % (self.source_address))
self.loss_detected()
packet = self.send_one_packet(self.send_base)
self.timer = Sim.scheduler.add(delay=self.timeout, event='retransmit', handler=self.retransmit)
示例6: send_one_packet
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import trace [as 别名]
def send_one_packet(self, sequence):
if sequence >= len(self.send_buffer):
return
if sequence + self.mss > len(self.send_buffer):
body = self.send_buffer[sequence : ]
else:
body = self.send_buffer[sequence : sequence + self.mss]
# get one packet worth of data
packet = TCPPacket(source_address=self.source_address,
source_port=self.source_port,
destination_address=self.destination_address,
destination_port=self.destination_port,
body=body,
sequence=sequence,ack_number=self.ack)
# send the packet
Sim.trace("%d sending My_RTP segment to %d for %d" % (self.source_address,self.destination_address,packet.sequence))
self.transport.send_packet(packet)
# set a timer
if not self.timer_set:
self.timer = Sim.scheduler.add(delay=self.timeout, event='retransmit', handler=self.retransmit)
self.timer_set = True
return packet
示例7: send_ack
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import trace [as 别名]
def send_ack(self):
packet = TCPPacket(source_address=self.source_address,
source_port=self.source_port,
destination_address=self.destination_address,
destination_port=self.destination_port,
sequence=self.sequence,ack_number=self.ack, flow_id=int(self.file_prefix.split("_")[-1]))
# send the packet
Sim.trace("%d sending My_RTP ACK to %d for %d" % (self.source_address,self.destination_address,packet.ack_number))
self.transport.send_packet(packet)
示例8: send_ack
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import trace [as 别名]
def send_ack(self):
packet = TCPPacket(source_address=self.source_address,
source_port=self.source_port,
destination_address=self.destination_address,
destination_port=self.destination_port,
sequence=self.sequence,ack_number=self.ack)
# send the packet
Sim.trace("%d sending ReliableTransport ACK to %d for %d" % (self.source_address,self.destination_address,packet.ack_number))
self.transport.send_packet(packet)
示例9: send_ack
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import trace [as 别名]
def send_ack(self):
packet = TCPPacket(source_address=self.source_address,
source_port=self.source_port,
destination_address=self.destination_address,
destination_port=self.destination_port,
sequence=self.next_sequence_num,ack_number=self.ack)
# since we are sending ACK, we're not waiting to send cumulative ACK anymore
self.next_inorder_seg_pending = False
# send the packet
Sim.trace("SEND ACK: %d ===> %d : %d" % (self.source_address,self.destination_address,packet.ack_number))
self.transport.send_packet(packet)
示例10: handle_sequence
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import trace [as 别名]
def handle_sequence(self, packet):
# print "We want sequence number:%d\nGot sequence number:%d\n" % (self.ack, packet.sequence)
Sim.trace("%d received ReliableTransport segment from %d for %d" % (packet.destination_address,packet.source_address,packet.sequence))
ReliableTransport.stats.add(packet.queueing_delay)
self.received_sequences.add(packet.sequence)
self.receive_buffer.append(packet)
# cumulative ack
sequence_list = sorted(self.received_sequences)
for i in range(self.ack/self.mss, len(sequence_list)):
if sequence_list[i] == self.ack:
tempPacket = [p for p in self.receive_buffer if p.sequence == self.ack][0]
self.increment_ack(tempPacket.sequence + tempPacket.length)
self.app.handle_packet(tempPacket)
self.send_ack()
示例11: retransmit
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import trace [as 别名]
def retransmit(self,event):
self.timer_set = False
if self.packets_outstanding <= 0:
return
self.ssthresh = int(max(math.ceil(self.window_size / 2.0), 1))
self.window_size = 1
self.bytes_acked = 0
self.packets_outstanding = 1
Sim.trace("%d retransmission timer fired" % (self.source_address))
packet = self.send_one_packet(self.window_start)
if packet:
self.sequence = self.window_start + packet.length
self.window_file.write(str(Sim.scheduler.current_time()) + " " + str(self.window_size) + "\n")
示例12: handle_sequence
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import trace [as 别名]
def handle_sequence(self, packet):
print >> self.sequence_file, Sim.scheduler.current_time(), packet.ack_number, packet.length
Sim.trace("%d received TcpTahoe segment from %d for %d" % (packet.destination_address,packet.source_address,packet.sequence))
self.received_sequences.add(packet.sequence)
self.receive_buffer.append(packet)
# cumulative ack
sequence_list = sorted(self.received_sequences)
for i in range(self.ack/self.mss, len(sequence_list)):
if sequence_list[i] == self.ack:
tempPacket = [p for p in self.receive_buffer if p.sequence == self.ack][0]
self.increment_ack(tempPacket.sequence + tempPacket.length)
print >> self.rate_file, Sim.scheduler.current_time(), self.ack, tempPacket.length
self.app.handle_packet(tempPacket)
self.send_ack()
示例13: send_one_packet
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import trace [as 别名]
def send_one_packet(self, sequence):
# get one packet worth of data
body = self.send_buffer[sequence:(sequence + self.mss)]
packet = TCPPacket(source_address=self.source_address,
source_port=self.source_port,
destination_address=self.destination_address,
destination_port=self.destination_port,
body=body,
sequence=sequence,ack_number=self.ack)
# send the packet
Sim.trace("%d sending ReliableTransport segment to %d for %d" % (self.source_address,self.destination_address,packet.sequence))
self.transport.send_packet(packet)
# set a timer if it's not already going
if not self.timer:
self.timer = Sim.scheduler.add(delay=self.timeout, event='retransmit', handler=self.retransmit)
return packet
示例14: handle_ack
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import trace [as 别名]
def handle_ack(self, packet):
print >> self.ack_file, Sim.scheduler.current_time(), packet.ack_number, packet.length
Sim.trace("%d received TcpTahoe ACK from %d for %d" % (packet.destination_address,packet.source_address,packet.ack_number))
new_bytes = packet.ack_number - self.received_ack_number
self.unacked_packet_count -= new_bytes
if self.cwnd >= self.threshold:
self.cwnd += (self.mss*new_bytes)/self.cwnd
self.threshold = self.cwnd
else:
self.cwnd += new_bytes
self.cancel_timer()
self.timer = Sim.scheduler.add(delay=self.timeout, event='new_ack_data', handler=self.retransmit)
self.send_if_possible()
self.received_ack_number = packet.ack_number
示例15: receive_data
# 需要导入模块: from src.sim import Sim [as 别名]
# 或者: from src.sim.Sim import trace [as 别名]
def receive_data(self,data):
if self.plot:
global original_size
global received_size
Sim.trace('AppHandler',"application got %d bytes" % (len(data)))
self.f.write(data)
received_size[self.identifier] += len(data)
self.f.flush()
turn_timer_off = True
for identifier in received_size.keys():
if received_size[identifier] != original_size:
turn_timer_off = False
break
if turn_timer_off:
global decisecondEvent
Sim.scheduler.cancel(decisecondEvent)