• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sim.Sim类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中src.sim.Sim的典型用法代码示例。如果您正苦于以下问题:Python Sim类的具体用法?Python Sim怎么用?Python Sim使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Sim类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: run

    def run(self):
        # parameters
        Sim.scheduler.reset()
        Sim.set_debug(True)

        # setup network
        net = Network('../networks/one-hop.txt')

        # setup routes
        n1 = net.get_node('n1')
        n2 = net.get_node('n2')
        n1.add_forwarding_entry(address=n2.get_address('n1'),link=n1.links[0])
        n2.add_forwarding_entry(address=n1.get_address('n2'),link=n2.links[0])

        # setup transport
        t1 = Transport(n1)
        t2 = Transport(n2)

        # setup application
        a = AppHandler(self.filename)

        # setup connection
        c1 = StopAndWait(t1,n1.get_address('n2'),1,n2.get_address('n1'),1,a)
        c2 = StopAndWait(t2,n2.get_address('n1'),1,n1.get_address('n2'),1,a)

        # send a file
        with open(self.filename,'r') as f:
            while True:
                data = f.read(1000)
                if not data:
                    break
                Sim.scheduler.add(delay=0, event=data, handler=c1.send)

        # run the simulation
        Sim.scheduler.run()
开发者ID:Steve525,项目名称:bene-lab-4-routing,代码行数:35,代码来源:transfer.py


示例2: retransmit

 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)
开发者ID:Steve525,项目名称:bene,代码行数:7,代码来源:tcp.py


示例3: receive_data

 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()
开发者ID:StevenC4,项目名称:bene,代码行数:7,代码来源:transfer-old.py


示例4: handle_packet

	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"
开发者ID:mkeagar,项目名称:cs460,代码行数:34,代码来源:my_rtp.py


示例5: handle_ack

 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()
开发者ID:dallinski,项目名称:bene,代码行数:7,代码来源:reliabletransport.py


示例6: send_one_packet

	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
开发者ID:mkeagar,项目名称:cs460,代码行数:25,代码来源:my_rtp.py


示例7: run

    def run(self):
        # parameters
        Sim.scheduler.reset()
        Sim.set_debug(True)

        # setup network
        n1 = Node()
        n2 = Node()
        l = Link(address=1,startpoint=n1,endpoint=n2,queue_size=self.queue_size,bandwidth=10000000,propagation=0.01,loss=self.loss, printOut=True)
        n1.add_link(l)
        n1.add_forwarding_entry(address=2,link=l)
        l = Link(address=2,startpoint=n2,endpoint=n1,queue_size=self.queue_size,bandwidth=10000000,propagation=0.01,loss=self.loss)
        n2.add_link(l)
        n2.add_forwarding_entry(address=1,link=l)

        # setup transport
        t1 = Transport(n1)
        t2 = Transport(n2)

        # setup application
        a = AppHandler("2_1-" + self.filename)

        # setup connection
        c1 = My_RTP(t1,1,1,2,1,a)
        c2 = My_RTP(t2,2,1,1,1,a)

        # setup application
        a = AppHandler("2_2-" + self.filename)

        # setup connection
        c3 = My_RTP(t1,1,2,2,2,a)
        c4 = My_RTP(t2,2,2,1,2,a)

        # send a file
        with open(self.filename,'r') as f:
            while True:
                data = f.read(1000)
                if not data:
                    break
                c1.load_buffer(data)
                c3.load_buffer(data)

        c1.set_file_prefix("2_1")
        c2.set_file_prefix("2_1")
        c3.set_file_prefix("2_2")
        c4.set_file_prefix("2_2")

        c1.open_window_file()
        c3.open_window_file()

        Sim.scheduler.add(delay=0, event="window_init", handler=c1.window_init)
        Sim.scheduler.add(delay=0, event="window_init", handler=c3.window_init)

        # run the simulation
        Sim.scheduler.run()
        n1.links[0].myfile.close()
        c1.close_window_file()
        c3.close_window_file()
        Sim.close_rate_file()
开发者ID:mkeagar,项目名称:cs460,代码行数:59,代码来源:transfer2.py


示例8: send_ack

 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)
开发者ID:dallinski,项目名称:bene,代码行数:9,代码来源:reliabletransport.py


示例9: send_ack

	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)
开发者ID:mkeagar,项目名称:cs460,代码行数:9,代码来源:my_rtp.py


示例10: send_cumulative_ack

 def send_cumulative_ack(self):
     sequences = sorted(self.receive_temp_buffer)
     for i in range(self.ack/self.mss, len(sequences)):
         if sequences[i] == self.ack:
             pkt = self.find_packet(self.ack)
             self.increment_ack(pkt.sequence + pkt.length)
             self.app.handle_packet(pkt)
             Sim.trace_custom("%d %d" % (pkt.sequence, pkt.length), 'rate', self.source_port)
     
     self.send_ack()
开发者ID:Steve525,项目名称:bene,代码行数:10,代码来源:tcp.py


示例11: run

    def run(self):
        # parameters
        Sim.scheduler.reset()

        if "a" in self.debug:
            Sim.set_debug('AppHandler')
        if "t" in self.debug:
            Sim.set_debug('TCP')

        # setup network
        networkPlotter = Plotter('out/2-flows-simple')
        net = Network(config='networks/one-hop.txt',plotter=networkPlotter)
        net.loss(self.loss)

        # setup routes
        n1 = net.get_node('n1')
        n2 = net.get_node('n2')
        n1.add_forwarding_entry(address=n2.get_address('n1'),link=n1.links[0])
        n2.add_forwarding_entry(address=n1.get_address('n2'),link=n2.links[0])

        # setup transport
        t1 = Transport(n1)
        t2 = Transport(n2)

        # setup connection
        c1 = TCP(t1,n1.get_address('n2'),1,n2.get_address('n1'),1,AppHandler(inputfile=self.inputfile,identifier="c1"),window=self.window,type=self.type,window_size_plot=True,sequence_plot=True)
        c2 = TCP(t2,n2.get_address('n1'),1,n1.get_address('n2'),1,AppHandler(inputfile=self.inputfile,plot=True,identifier="c2"),window=self.window,type=self.type,receiver_flow_plot=True)
        
        c3 = TCP(t1,n1.get_address('n2'),2,n2.get_address('n1'),2,AppHandler(inputfile=self.inputfile,identifier="c3"),window=self.window,type=self.type,window_size_plot=True,sequence_plot=True)
        c4 = TCP(t2,n2.get_address('n1'),2,n1.get_address('n2'),2,AppHandler(inputfile=self.inputfile,plot=True,identifier="c4"),window=self.window,type=self.type,receiver_flow_plot=True)

        global tcps
        tcps = [c1, c2, c3, c4]

        global original_size
        f = open(self.inputfile, "rb")
        try:
            data = f.read(1000)
            while data != "":
                original_size += len(data)
                Sim.scheduler.add(delay=0, event=data, handler=c1.send)
                Sim.scheduler.add(delay=0, event=data, handler=c3.send)
                data = f.read(1000)
        finally:
            f.close()

        # run the simulation

        global decisecondEvent
        decisecondEvent = Sim.scheduler.add(delay=0.1, event=Sim, handler=self.decisecond)

        Sim.scheduler.run()

        networkPlotter.plot(self.sequencefile)
        plotter.plot(self.sequencefile);
开发者ID:StevenC4,项目名称:bene,代码行数:55,代码来源:2-flows-basic.py


示例12: send_ack

 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)
开发者ID:Steve525,项目名称:bene,代码行数:11,代码来源:tcp.py


示例13: handle_packet

 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))
         self.not_yet_acknowledged_segments -= ((packet.ack_number - self.send_base) / self.mss)
         self.cancel_timer()
         self.timer = Sim.scheduler.add(delay=self.timeout, event='new_ack_data', handler=self.retransmit)
         self.send_base = packet.ack_number
         self.send_if_possible()
     else:
         self.triple_dup_ack_counter+=1
         if self.triple_dup_ack_counter == 3:
             Sim.trace("FAST RETRANSMIT: Duplicate ACK: %d"%(packet.ack_number))
             Sim.trace("Outstanding acks: %d" % self.not_yet_acknowledged_segments)
             self.send_one_packet(packet.ack_number)
             self.triple_dup_ack_counter = 0
         
         
     # 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()
开发者ID:Steve525,项目名称:bene,代码行数:26,代码来源:tcp.py


示例14: retransmit

	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")
开发者ID:mkeagar,项目名称:cs460,代码行数:16,代码来源:my_rtp.py


示例15: handle_ack

    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
开发者ID:dallinski,项目名称:bene,代码行数:16,代码来源:tcp.py


示例16: receive_data

 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)
开发者ID:StevenC4,项目名称:bene,代码行数:16,代码来源:1-flow-advanced-aiad.py


示例17: handle_sequence

    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()
开发者ID:dallinski,项目名称:bene,代码行数:16,代码来源:tcp.py


示例18: send_one_packet

 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
开发者ID:dallinski,项目名称:bene,代码行数:16,代码来源:reliabletransport.py


示例19: handle_sequence

    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()
开发者ID:dallinski,项目名称:bene,代码行数:16,代码来源:reliabletransport.py


示例20: run

    def run(self):
        # parameters
        Sim.scheduler.reset()

        if "a" in self.debug:
            Sim.set_debug('AppHandler')
        if "t" in self.debug:
            Sim.set_debug('TCP')

        # setup network
        net = Network('networks/one-hop.txt')
        net.loss(self.loss)

        # setup routes
        n1 = net.get_node('n1')
        n2 = net.get_node('n2')
        n1.add_forwarding_entry(address=n2.get_address('n1'),link=n1.links[0])
        n2.add_forwarding_entry(address=n1.get_address('n2'),link=n2.links[0])

        # setup transport
        t1 = Transport(n1)
        t2 = Transport(n2)

        # setup application
        a = AppHandler(self.inputfile)

        # setup connection
        c1 = TCP(t1,n1.get_address('n2'),1,n2.get_address('n1'),1,a,window=self.window,type=self.type)
        c2 = TCP(t2,n2.get_address('n1'),1,n1.get_address('n2'),1,a,window=self.window,type=self.type)

        global original_size
        f = open(self.inputfile, "rb")
        try:
            data = f.read(1000)
            while data != "":
                original_size += len(data)
                Sim.scheduler.add(delay=0, event=data, handler=c1.send)
                data = f.read(1000)
        finally:
            f.close()

        # run the simulation
        Sim.scheduler.run()

        plotter.plot(self.sequencefile);
开发者ID:StevenC4,项目名称:bene,代码行数:45,代码来源:transfer.py



注:本文中的src.sim.Sim类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python CommandHelper.CommandHelper类代码示例发布时间:2022-05-27
下一篇:
Python nex.UpdateByJsonMixin类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap