Exemplo n.º 1
0
 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()
Exemplo n.º 2
0
Arquivo: tcp.py Projeto: Steve525/bene
 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)
Exemplo n.º 3
0
def main():
    # parameters
    Sim.scheduler.reset()
    Sim.set_debug("Node")

    # setup network
    net = Network("test2network.txt")
    for hostname, node in sorted(net.nodes.iteritems()):
        node.add_protocol(protocol="dvrouting", handler=RoutingApp(node))

    n3 = net.get_node("n3")
    n3.add_protocol(protocol="delay", handler=DelayHandler())

    p = Packet(destination_address=n3.get_address("n2"),
               ident=1,
               protocol="delay",
               length=1000)
    n2 = net.get_node("n2")
    Sim.scheduler.add(delay=1.2, event=p, handler=n2.send_packet)
    Sim.scheduler.add(delay=1.6, event=None, handler=n2.get_link("n3").down)
    Sim.scheduler.add(delay=1.6, event=None, handler=n3.get_link("n2").down)

    p = Packet(destination_address=n3.get_address("n2"),
               ident=2,
               protocol="delay",
               length=1000)
    Sim.scheduler.add(delay=6.6, event=p, handler=n2.send_packet)

    # run the simulation
    Sim.scheduler.run()
Exemplo n.º 4
0
	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"
Exemplo n.º 5
0
 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()
Exemplo n.º 6
0
	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
Exemplo n.º 7
0
    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()
Exemplo n.º 8
0
def main():
    # parameters
    Sim.scheduler.reset()
    Sim.set_debug(True)

    # setup network
    net = Network('../networks/five-nodes.txt')

    # get nodes
    n1 = net.get_node('n1')
    n2 = net.get_node('n2')
    n3 = net.get_node('n3')
    n4 = net.get_node('n4')
    n5 = net.get_node('n5')

    # setup broadcast application
    b1 = BroadcastApp(n1)
    n1.add_protocol(protocol="broadcast", handler=b1)
    b2 = BroadcastApp(n2)
    n2.add_protocol(protocol="broadcast", handler=b2)
    b3 = BroadcastApp(n3)
    n3.add_protocol(protocol="broadcast", handler=b3)
    b4 = BroadcastApp(n4)
    n4.add_protocol(protocol="broadcast", handler=b4)
    b5 = BroadcastApp(n5)
    n5.add_protocol(protocol="broadcast", handler=b5)

    # send a broadcast packet from 1 with TTL 2, so everyone should get it
    p = Packet(source_address=n1.get_address('n2'),
               destination_address=0,
               ident=1,
               ttl=2,
               protocol='broadcast',
               length=100)
    Sim.scheduler.add(delay=0, event=p, handler=n1.send_packet)

    # send a broadcast packet from 1 with TTL 1, so just nodes 2 and 3
    # should get it
    p = Packet(source_address=n1.get_address('n2'),
               destination_address=0,
               ident=2,
               ttl=1,
               protocol='broadcast',
               length=100)
    print("this is an address of n2", n1.get_address('n3'))
    Sim.scheduler.add(delay=1, event=p, handler=n1.send_packet)

    # send a broadcast packet from 3 with TTL 1, so just nodes 1, 4, and 5
    # should get it
    p = Packet(source_address=n3.get_address('n1'),
               destination_address=0,
               ident=3,
               ttl=1,
               protocol='broadcast',
               length=100)
    Sim.scheduler.add(delay=2, event=p, handler=n3.send_packet)

    # run the simulation
    Sim.scheduler.run()
Exemplo n.º 9
0
    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()
Exemplo n.º 10
0
def main():
    # parameters
    Sim.scheduler.reset()
    Sim.set_debug("Node")

    # setup network
    net = Network("test3network.txt")
    for hostname, node in sorted(net.nodes.iteritems()):
        node.add_protocol(protocol="dvrouting", handler=RoutingApp(node))

    n7 = net.get_node("n7")
    n7.add_protocol(protocol="delay", handler=DelayHandler())
    n10 = net.get_node("n10")
    n10.add_protocol(protocol="delay", handler=DelayHandler())
    n15 = net.get_node("n15")
    n15.add_protocol(protocol="delay", handler=DelayHandler())

    n8 = net.get_node("n8")
    n11 = net.get_node("n11")
    n12 = net.get_node("n12")

    p1 = Packet(destination_address=n7.get_address("n6"),
                ident=1,
                protocol="delay",
                length=1000)
    Sim.scheduler.add(delay=4.2, event=p1, handler=n12.send_packet)
    p3 = Packet(destination_address=n15.get_address("n14"),
                ident=2,
                protocol="delay",
                length=1000)
    Sim.scheduler.add(delay=4.3, event=p3, handler=n11.send_packet)
    p2 = Packet(destination_address=n10.get_address("n1"),
                ident=3,
                protocol="delay",
                length=1000)
    Sim.scheduler.add(delay=4.4, event=p2, handler=n8.send_packet)

    n2 = net.get_node("n2")
    Sim.scheduler.add(delay=4.8, event=None, handler=n2.get_link("n8").down)
    Sim.scheduler.add(delay=4.8, event=None, handler=n8.get_link("n2").down)

    p4 = Packet(destination_address=n10.get_address("n1"),
                ident=4,
                protocol="delay",
                length=1000)
    Sim.scheduler.add(delay=10.4, event=p4, handler=n8.send_packet)

    Sim.scheduler.add(delay=10.8, event=None, handler=n2.get_link("n8").up)
    Sim.scheduler.add(delay=10.8, event=None, handler=n8.get_link("n2").up)

    p5 = Packet(destination_address=n10.get_address("n1"),
                ident=5,
                protocol="delay",
                length=1000)
    Sim.scheduler.add(delay=16.4, event=p5, handler=n8.send_packet)

    # run the simulation
    Sim.scheduler.run()
Exemplo n.º 11
0
    def run(self):
        drop_packets = [14000, 26000, 28000]
        Sim.set_debug('Plot')

        # setup network
        net = Network('basic.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)

        plotter = Plotter()

        for i in range(0, 4):
            application = AppHandler(self.filename)
            Sim.scheduler.reset()
            Sim.files = {}

            # setup connection
            c1 = TCP(t1,
                     n1.get_address('n2'),
                     1,
                     n2.get_address('n1'),
                     1,
                     application,
                     fast_retransmit=True,
                     drop=drop_packets[:i])
            TCP(t2,
                n2.get_address('n1'),
                1,
                n1.get_address('n2'),
                1,
                application,
                fast_retransmit=True)

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

            Sim.scheduler.run()
            for filename, file in Sim.files.iteritems():
                file.close()

            plotter.sequence("sequence" + str(i + 1) + ".png")
            plotter.cwnd("cwnd" + str(i + 1) + ".png")

            self.diff()
Exemplo n.º 12
0
	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)
Exemplo n.º 13
0
 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)
Exemplo n.º 14
0
Arquivo: tcp.py Projeto: Steve525/bene
 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()
Exemplo n.º 15
0
    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);
Exemplo n.º 16
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        Sim.set_debug('AppHandler')
        Sim.set_debug('TCP')

        # setup network
        net = Network('network.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.filename)

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

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

        # run the simulation
        Sim.scheduler.run()
        if self.print_queueing_delay:
            print('average queueing delay: {}'.format(
                c2.total_queueing_delay / c2.total_packets_received))
Exemplo n.º 17
0
Arquivo: tcp.py Projeto: Steve525/bene
 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)
Exemplo n.º 18
0
    def run(self, fila, drop):

        self.filename = fila
        fast = True
        Sim.trace('Trans', "It is %s that I am using drop transmit." % (fast))
        Sim.set_debug("Plot")

        # parameters
        Sim.scheduler.reset()
        Sim.set_debug('AppHandler')
        Sim.set_debug('TCP')
        Sim.set_debug('Trans')

        # setup network
        net = Network('network.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 = TCP(t1, n1.get_address('n2'), 1, n2.get_address('n1'), 1, a, drop)
        c2 = TCP(t2, n2.get_address('n1'), 1, n1.get_address('n2'), 1, a, drop)

        # send a file
        with open(self.filename, 'rb') 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()

        self.diff()

        self.filename = None

        return Sim.scheduler.current_time()
Exemplo n.º 19
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        Sim.set_debug('AppHandler')
        Sim.set_debug('TCP')
        # Sim.set_debug('Link')

        # setup application
        a = AppHandler(self.filename, self.out_directory)

        # setup network
        net = Network('../networks/setup.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 connection
        c1 = TCP(t1,
                 n1.get_address('n2'),
                 1,
                 n2.get_address('n1'),
                 1,
                 a,
                 window=self.window)
        c2 = TCP(t2,
                 n2.get_address('n1'),
                 1,
                 n1.get_address('n2'),
                 1,
                 a,
                 window=self.window)

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

        # run the simulation
        Sim.scheduler.run()
Exemplo n.º 20
0
Arquivo: tcp.py Projeto: Steve525/bene
 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()
Exemplo n.º 21
0
	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")
Exemplo n.º 22
0
 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
Exemplo n.º 23
0
    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()
Exemplo n.º 24
0
    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
Exemplo n.º 25
0
    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()
Exemplo n.º 26
0
 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)
Exemplo n.º 27
0
    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);
Exemplo n.º 28
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        Sim.set_debug(False)

        # setup network
        n1 = Node()
        n2 = Node()

        l = Link(address=1,startpoint=n1,endpoint=n2,loss=self.loss,bandwidth=100000000,propagation=0.01)
        if self.experiments:
            l = Link(address=1,startpoint=n1,endpoint=n2,loss=self.loss,bandwidth=100000000,propagation=0.01, queue_size=100)
        n1.add_link(l)
        n1.add_forwarding_entry(address=2,link=l)
        l = Link(address=2,startpoint=n2,endpoint=n1,loss=self.loss,bandwidth=100000000,propagation=0.01)
        if self.experiments:
            l = Link(address=2,startpoint=n2,endpoint=n1,loss=self.loss,bandwidth=100000000,propagation=0.01, queue_size=100)
        n2.add_link(l)
        n2.add_forwarding_entry(address=1,link=l)

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

        # setup application
        a = AppHandler(self.filename)

        # setup connection
        c1 = ReliableTransport(t1,1,1,2,1,self.window_size,a)
        c2 = ReliableTransport(t2,2,1,1,1,self.window_size,a)

        # send a file
        with open(self.filename,'r') as f:
            c1.stats.set_size(os.path.getsize(self.filename))
            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()
        print "Average queueing delay =", c1.stats.average()
        print "Throughput =", c1.stats.throughput(Sim.scheduler.current_time())
Exemplo n.º 29
0
def exp3():
    # parameters
    Sim.scheduler.reset()
    Sim.set_debug(True)

    # setup network
    net = Network('../networks/l4e3.txt')

    # get nodes
    n1 = net.get_node('n1')
    n2 = net.get_node('n2')
    n3 = net.get_node('n3')
    n4 = net.get_node('n4')
    n5 = net.get_node('n5')
    n6 = net.get_node('n6')
    n7 = net.get_node('n7')
    n8 = net.get_node('n8')
    n9 = net.get_node('n9')
    n10 = net.get_node('n10')
    n11 = net.get_node('n11')
    n12 = net.get_node('n12')
    n13 = net.get_node('n13')
    n14 = net.get_node('n14')
    n15 = net.get_node('n15')

    # setup broadcast application
    p_setup(n1)
    p_setup(n2)
    p_setup(n3)
    p_setup(n4)
    p_setup(n5)
    p_setup(n6)
    p_setup(n7)
    p_setup(n8)
    p_setup(n9)
    p_setup(n10)
    p_setup(n11)
    p_setup(n12)
    p_setup(n13)
    p_setup(n14)
    p_setup(n15)

    # run the simulation
    Sim.scheduler.run()
Exemplo n.º 30
0
Arquivo: tcp.py Projeto: Steve525/bene
 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("SEND SEGMENT: %d ===> %d : %d at %d" % (self.source_address,self.destination_address,packet.sequence,packet.enter_queue))
     self.transport.send_packet(packet)
     Sim.trace("SENT AT: %d" % packet.enter_queue)
     
     if not self.timer:
         self.timer = Sim.scheduler.add(delay=self.timeout, event='retransmit', handler=self.retransmit)
     
     return packet
Exemplo n.º 31
0
    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)

                global previous_decisecond_stored_size
                bytes_per_second = (original_size - previous_decisecond_stored_size[self.identifier]) / Sim.scheduler.current_time()
                #print "Bytes per second: ", bytes_per_second
                self.add_plot_data(Sim.scheduler.current_time(),bytes_per_second,'ReceiverRate',self.identifier)
Exemplo n.º 32
0
Arquivo: tcp.py Projeto: Steve525/bene
    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()
Exemplo n.º 33
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        Sim.set_debug('AppHandler')
        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])  # n1 -> n2
        n2.add_forwarding_entry(address=n1.get_address('n2'),link=n2.links[0])  # n1 <- n2

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

        # setup application
        tcp_flows = 1
        a1 = AppHandler(self.filename, 1)

        # setup connection
        c1a = TCP(t1, n1.get_address('n2'), 1, n2.get_address('n1'), 1, 3000, a1)
        c2a = TCP(t2, n2.get_address('n1'), 1, n1.get_address('n2'), 1, 3000, a1)

        # 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=c1a.send)

        # run the simulation
        Sim.scheduler.run()
        return tcp_flows
Exemplo n.º 34
0
def main():
    # parameters
    Sim.scheduler.reset()
    Sim.set_debug("Node")

    # setup network
    net = Network("test1network.txt")
    for hostname, node in sorted(net.nodes.iteritems()):
        node.add_protocol(protocol="dvrouting", handler=RoutingApp(node))

    n5 = net.get_node("n5")
    n5.add_protocol(protocol="delay", handler=DelayHandler())

    p = Packet(destination_address=n5.get_address("n4"),
               ident=1,
               protocol="delay",
               length=1000)
    n1 = net.get_node("n1")
    Sim.scheduler.add(delay=3.2, event=p, handler=n1.send_packet)

    # run the simulation
    Sim.scheduler.run()
Exemplo n.º 35
0
    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,loss=self.loss,
                 bandwidth=10000000.0,propagation=0.01,queue_size=self.queue)
        n1.add_link(l)
        n1.add_forwarding_entry(address=2,link=l)
        l = Link(address=2,startpoint=n2,endpoint=n1,loss=self.loss,
                 bandwidth=10000000.0,propagation=0.01,queue_size=self.queue)
        n2.add_link(l)
        n2.add_forwarding_entry(address=1,link=l)

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

        # setup application
        a = AppHandler(self.filename)

        # setup connection
        c1 = TCP(t1,1,1,2,1,app=a,window=self.window)
        c2 = TCP(t2,2,1,1,1,app=a,window=self.window)

        # 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()
        print "Total queuing delay: ", a.total_queuing_delay
        print "Total packets sent: ", a.total_packets_sent
Exemplo n.º 36
0
    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)
        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(self.filename)

        # setup connection
        c1 = My_RTP(t1,1,1,2,1,a)
        c2 = My_RTP(t2,2,1,1,1,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)

        c1.window_init(self.window_size)

        # run the simulation
        Sim.scheduler.run()
Exemplo n.º 37
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        Sim.set_debug('AppHandler')
        Sim.set_debug('TCP')
        Sim.set_debug('Plot')

        # 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.filename)

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

        # setup fast retransmit
        if self.fast_retransmit:
            c1.set_fast_retransmit_enabled(True)
            c2.set_fast_retransmit_enabled(True)

        # send a file
        with open(self.filename, 'rb') 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()
Exemplo n.º 38
0
	def run(self):
		# parameters
		Sim.scheduler.reset()
		Sim.set_debug('AppHandler')
		Sim.set_debug('TCP')

		# setup network
		net = Network('basic.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.filename)

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

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

		Sim.scheduler.run()
Exemplo n.º 39
0
    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,loss=self.loss)
        n1.add_link(l)
        n1.add_forwarding_entry(address=2,link=l)
        l = Link(address=2,startpoint=n2,endpoint=n1,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(self.filename)

        # setup connection
        c1 = StopAndWait(t1,1,1,2,1,a)
        c2 = StopAndWait(t2,2,1,1,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()
Exemplo n.º 40
0
def exp1():
    # parameters
    Sim.scheduler.reset()
    Sim.set_debug(True)

    # setup network
    net = Network('../networks/l4e1.txt')

    # get nodes
    n1 = net.get_node('n1')
    n2 = net.get_node('n2')
    n3 = net.get_node('n3')
    n4 = net.get_node('n4')
    n5 = net.get_node('n5')

    # setup broadcast application
    p_setup(n1)
    p_setup(n2)
    p_setup(n3)
    p_setup(n4)
    p_setup(n5)

    #send to every node from n1
    p = Packet(destination_address=n2.get_address('n1'),
               ident=1,
               protocol='delay',
               length=1000)
    Sim.scheduler.add(delay=5, event=p, handler=n1.send_packet)
    p = Packet(destination_address=n3.get_address('n1'),
               ident=1,
               protocol='delay',
               length=1000)
    Sim.scheduler.add(delay=5, event=p, handler=n1.send_packet)
    p = Packet(destination_address=n4.get_address('n1'),
               ident=1,
               protocol='delay',
               length=1000)
    Sim.scheduler.add(delay=5, event=p, handler=n1.send_packet)
    p = Packet(destination_address=n5.get_address('n1'),
               ident=1,
               protocol='delay',
               length=1000)
    Sim.scheduler.add(delay=5, event=p, handler=n1.send_packet)

    #send to every node from n2
    p = Packet(destination_address=n1.get_address('n1'),
               ident=1,
               protocol='delay',
               length=1000)
    Sim.scheduler.add(delay=5, event=p, handler=n2.send_packet)
    p = Packet(destination_address=n5.get_address('n1'),
               ident=1,
               protocol='delay',
               length=1000)
    Sim.scheduler.add(delay=5, event=p, handler=n2.send_packet)
    p = Packet(destination_address=n3.get_address('n1'),
               ident=1,
               protocol='delay',
               length=1000)
    Sim.scheduler.add(delay=5, event=p, handler=n2.send_packet)
    p = Packet(destination_address=n4.get_address('n1'),
               ident=1,
               protocol='delay',
               length=1000)
    Sim.scheduler.add(delay=5, event=p, handler=n2.send_packet)

    #send to every node from n3
    p = Packet(destination_address=n1.get_address('n1'),
               ident=1,
               protocol='delay',
               length=1000)
    Sim.scheduler.add(delay=5, event=p, handler=n3.send_packet)
    p = Packet(destination_address=n2.get_address('n1'),
               ident=1,
               protocol='delay',
               length=1000)
    Sim.scheduler.add(delay=5, event=p, handler=n3.send_packet)
    p = Packet(destination_address=n4.get_address('n1'),
               ident=1,
               protocol='delay',
               length=1000)
    Sim.scheduler.add(delay=5, event=p, handler=n3.send_packet)
    p = Packet(destination_address=n5.get_address('n1'),
               ident=1,
               protocol='delay',
               length=1000)
    Sim.scheduler.add(delay=5, event=p, handler=n3.send_packet)

    #send to every node from n4
    p = Packet(destination_address=n2.get_address('n1'),
               ident=1,
               protocol='delay',
               length=1000)
    Sim.scheduler.add(delay=5, event=p, handler=n4.send_packet)
    p = Packet(destination_address=n1.get_address('n1'),
               ident=1,
               protocol='delay',
               length=1000)
    Sim.scheduler.add(delay=5, event=p, handler=n4.send_packet)
    p = Packet(destination_address=n3.get_address('n1'),
               ident=1,
               protocol='delay',
               length=1000)
    Sim.scheduler.add(delay=5, event=p, handler=n4.send_packet)
    p = Packet(destination_address=n5.get_address('n1'),
               ident=1,
               protocol='delay',
               length=1000)
    Sim.scheduler.add(delay=5, event=p, handler=n4.send_packet)

    #send to every node from n5
    p = Packet(destination_address=n2.get_address('n1'),
               ident=1,
               protocol='delay',
               length=1000)
    Sim.scheduler.add(delay=5, event=p, handler=n5.send_packet)
    p = Packet(destination_address=n3.get_address('n1'),
               ident=1,
               protocol='delay',
               length=1000)
    Sim.scheduler.add(delay=5, event=p, handler=n5.send_packet)
    p = Packet(destination_address=n4.get_address('n1'),
               ident=1,
               protocol='delay',
               length=1000)
    Sim.scheduler.add(delay=5, event=p, handler=n5.send_packet)
    p = Packet(destination_address=n1.get_address('n1'),
               ident=1,
               protocol='delay',
               length=1000)
    Sim.scheduler.add(delay=5, event=p, handler=n5.send_packet)

    # run the simulation
    Sim.scheduler.run()
Exemplo n.º 41
0
 def plot_sequence(self,sequence,event):
     if self.node.hostname =='n1':
         Sim.plot('sequence.csv','%s,%s,%s\n' % (Sim.scheduler.current_time(),sequence,event))
Exemplo n.º 42
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        Sim.set_debug('AppHandler')
        Sim.set_debug('TCP')
        # Sim.set_debug('Link')

        # setup application
        a1 = AppHandler(self.filename + str(1), self.out_directory)
        a2 = AppHandler(self.filename + str(2), self.out_directory)
        a3 = AppHandler(self.filename + str(3), self.out_directory)
        a4 = AppHandler(self.filename + str(4), self.out_directory)
        a5 = AppHandler(self.filename + str(5), self.out_directory)

        # setup network
        net = Network('../networks/setup.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 connection
        c1 = TCP(t1,
                 n1.get_address('n2'),
                 1,
                 n2.get_address('n1'),
                 1,
                 a1,
                 window=self.window)
        c2 = TCP(t2,
                 n2.get_address('n1'),
                 1,
                 n1.get_address('n2'),
                 1,
                 a1,
                 window=self.window)

        # setup connection
        c3 = TCP(t1,
                 n1.get_address('n2'),
                 2,
                 n2.get_address('n1'),
                 2,
                 a2,
                 window=self.window)
        c4 = TCP(t2,
                 n2.get_address('n1'),
                 2,
                 n1.get_address('n2'),
                 2,
                 a2,
                 window=self.window)

        # setup connection
        c5 = TCP(t1,
                 n1.get_address('n2'),
                 3,
                 n2.get_address('n1'),
                 3,
                 a3,
                 window=self.window)
        c6 = TCP(t2,
                 n2.get_address('n1'),
                 3,
                 n1.get_address('n2'),
                 3,
                 a3,
                 window=self.window)

        # setup connection
        c7 = TCP(t1,
                 n1.get_address('n2'),
                 4,
                 n2.get_address('n1'),
                 4,
                 a4,
                 window=self.window)
        c8 = TCP(t2,
                 n2.get_address('n1'),
                 4,
                 n1.get_address('n2'),
                 4,
                 a4,
                 window=self.window)

        # setup connection
        c9 = TCP(t1,
                 n1.get_address('n2'),
                 5,
                 n2.get_address('n1'),
                 5,
                 a5,
                 window=self.window)
        c0 = TCP(t2,
                 n2.get_address('n1'),
                 5,
                 n1.get_address('n2'),
                 5,
                 a5,
                 window=self.window)

        # send a file
        with open(self.in_directory + '/' + self.filename, 'r') as f:
            while True:
                data = f.read(10000)
                if not data:
                    break
                Sim.scheduler.add(delay=0.0, event=data, handler=c1.send)
                Sim.scheduler.add(delay=0.1, event=data, handler=c3.send)
                Sim.scheduler.add(delay=0.2, event=data, handler=c5.send)
                Sim.scheduler.add(delay=0.3, event=data, handler=c7.send)
                Sim.scheduler.add(delay=0.4, event=data, handler=c9.send)

        # run the simulation
        Sim.scheduler.run()
Exemplo n.º 43
0
 def plot_window_header(self):
     if self.node.hostname == 'n1':
         Sim.plot('cwnd.csv','Time,Congestion Window,Threshold,Event\n')
Exemplo n.º 44
0
 def receive_data(self, data):
     Sim.trace('AppHandler', "application got %d bytes" % (len(data)))
     self.f.write(data)
     self.f.flush()
Exemplo n.º 45
0
 def plot_window(self, event):
     if self.node.hostname == 'n1':
         Sim.plot('cwnd.csv', '%s,%s,%s,%s\n' % (Sim.scheduler.current_time(), self.window, self.threshold, event))
Exemplo n.º 46
0
 def trace(self, message, protocol=""):
     Sim.trace("Node" + protocol, message + " (" + protocol + ")")
Exemplo n.º 47
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        Sim.set_debug('AppHandler')
        Sim.set_debug('TCP')

        # setup network
        if self.use_queue:
            net = Network('networks/one-hop-queue.txt')
        else:
            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.filename)

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

        # 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()

        # print some results
        print
        print "========== Overall results =========="
        time = Sim.scheduler.current_time()
        print "Total time: %f seconds" % time
        avg = numpy.mean(c2.queueing_delay_list)
        print "Average queueing delay: %f" % avg
        max = numpy.max(c2.queueing_delay_list)
        print "Max queueing delay: %f" % max
        file_size = os.path.getsize(self.filename)
        print "File size: %i" % file_size
        throughput = file_size / time
        print "Throughput: %f" % throughput

        print "%i,%f,%f,%f,%i,%f\n" % (self.window, time, avg, max, file_size,
                                       throughput)
        if self.loss == 0.0:
            print "Outputing results to experiment.csv"
            output_fh = open('experiment.csv', 'a')
            output_fh.write(
                "%i,%f,%f,%f,%i,%f\n" %
                (self.window, time, avg, max, file_size, throughput))
            output_fh.close()

        print "Saving the sequence plot"
        self.create_sequence_plot(c1.x, c1.y, c1.dropX, c1.dropY, c1.ackX,
                                  c1.ackY)
Exemplo n.º 48
0
import random

from dvrouting import DVRoutingApp

class HandleDataApp(object):
    def __init__(self,node):
        self.node = node

    def receive_packet(self,packet):
        print Sim.scheduler.current_time(),self.node.hostname,"received data"

if __name__ == '__main__':
    # parameters
    Sim.scheduler.reset()
    Sim.set_debug(True)
    Sim.set_debug('Nodedata')

    # setup network
    net = Network('networks/five-nodes-ring.txt')

    # get nodes
    n1 = net.get_node('n1')
    n2 = net.get_node('n2')
    n3 = net.get_node('n3')
    n4 = net.get_node('n4')
    n5 = net.get_node('n5')

    # setup handling data for node 5
    n1.add_protocol(protocol="data",handler=HandleDataApp(n1))
    n2.add_protocol(protocol="data",handler=HandleDataApp(n2))
Exemplo n.º 49
0
 def trace(self, message):
     """ Print debugging messages. """
     Sim.trace("TCP", message)
Exemplo n.º 50
0
 def receive_data(self,data):
     Sim.trace('AppHandler',"application got %d bytes" % (len(data)))
     self.f.write(data)
     self.f.flush()
Exemplo n.º 51
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        #Sim.set_debug('AppHandler')
        #Sim.set_debug('TCP')
        Sim.set_debug('Link')

        net = Network('networks/one.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
        a1 = AppHandler('test.txt')

        # setup connection
        c1 = TCP(t1,
                 n1.get_address('n2'),
                 1,
                 n2.get_address('n1'),
                 1,
                 a1,
                 window=self.window,
                 threshold=self.threshold,
                 fast_recovery=True,
                 aimdc=5.0 / 6.0)
        c2 = TCP(t2,
                 n2.get_address('n1'),
                 1,
                 n1.get_address('n2'),
                 1,
                 a1,
                 window=self.window,
                 threshold=self.threshold,
                 fast_recovery=True,
                 aimdc=5.0 / 6.0)

        # send a file
        with open('test.txt', '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()

        # print some results
        print
        print "========== Overall results =========="
        time = Sim.scheduler.current_time()
        print "Total time: %f seconds" % time
        avg = numpy.mean(c2.queueing_delay_list)
        print "Average queueing delay: %f" % avg
        max = numpy.max(c2.queueing_delay_list)
        print "Max queueing delay: %f" % max
        file_size = os.path.getsize(self.filename)
        print "File size: %i" % file_size
        throughput = file_size / time
        print "Throughput: %f" % throughput

        plotter = Plotter()
        print "Saving the sequence plot"
        plotter.create_sequence_plot(c1.x,
                                     c1.y,
                                     c1.dropX,
                                     c1.dropY,
                                     c1.ackX,
                                     c1.ackY,
                                     chart_name='advanced/aimd/sequence.png')

        plotter.clear()
        plotter.rateTimePlot(c2.packets_received, Sim.scheduler.current_time(),
                             'advanced/aimd/rateTime1.png')

        linkab = n1.links[0]
        self.linkab = linkab
        plotter.clear()
        plotter.queueSizePlot(linkab.queue_log_x,
                              linkab.queue_log_y,
                              linkab.dropped_packets_x,
                              linkab.dropped_packets_y,
                              chart_name='advanced/aimd/queueSize.png')

        plotter.clear()
        plotter.windowSizePlot(c1.window_x,
                               c1.window_y,
                               chart_name="advanced/aimd/windowSize1.png")
Exemplo n.º 52
0
 def plot_cwnd_header(self):
     if self.node.hostname == 'n1':
         Sim.plot('cwnd.csv', 'Time,Congestion Window\n')
Exemplo n.º 53
0
 def plot_cwnd(self):
     if self.node.hostname == 'n1':
         Sim.plot(
             'cwnd.csv',
             '%s,%s\n' % (Sim.scheduler.current_time(), int(self.cwnd)))
Exemplo n.º 54
0
def main():
    Sim.set_debug('Node')
    # run_five_nodes_line()
    run_five_nodes_ring()
Exemplo n.º 55
0
 def trace(self, message):
     ''' Print debugging messages. '''
     Sim.trace("TCP", message)
Exemplo n.º 56
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        #Sim.set_debug('AppHandler')
        #Sim.set_debug('TCP')
        Sim.set_debug('Link')

        net = Network('networks/two.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
        a1 = AppHandler('test1.txt')
        a2 = AppHandler('test2.txt')

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

        c3 = TCP(t1,
                 n1.get_address('n2'),
                 2,
                 n2.get_address('n1'),
                 2,
                 a2,
                 window=self.window,
                 threshold=self.threshold,
                 fast_recovery=self.fast_recovery)
        c4 = TCP(t2,
                 n2.get_address('n1'),
                 2,
                 n1.get_address('n2'),
                 2,
                 a2,
                 window=self.window,
                 threshold=self.threshold,
                 fast_recovery=self.fast_recovery)

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

        # run the simulation
        Sim.scheduler.run()

        # print some results
        print
        print "========== Overall results =========="
        time = Sim.scheduler.current_time()
        print "Total time: %f seconds" % time
        avg = numpy.mean(c2.queueing_delay_list)
        print "Average queueing delay: %f" % avg
        max = numpy.max(c2.queueing_delay_list)
        print "Max queueing delay: %f" % max
        file_size = os.path.getsize(self.filename)
        print "File size: %i" % file_size
        throughput = file_size / time
        print "Throughput: %f" % throughput

        # Variables for debugging
        self.c3 = c3
        self.c4 = c4
        self.c2 = c2
        self.c1 = c1
        self.t1 = t1
        self.t2 = t2
        self.net = net
        linkab = n1.links[0]
        self.linkab = linkab
        l = linkab

        # Plotting
        plotter = Plotter()

        # Plot sequence charts
        plotter.clear()
        plotter.create_sequence_plot(c1.x,
                                     c1.y,
                                     c1.dropX,
                                     c1.dropY,
                                     c1.ackX,
                                     c1.ackY,
                                     chart_name='two/sequence1.png')
        plotter.clear()
        plotter.create_sequence_plot(c3.x,
                                     c3.y,
                                     c3.dropX,
                                     c3.dropY,
                                     c3.ackX,
                                     c3.ackY,
                                     chart_name='two/sequence2.png')

        # Plot receiver rate
        plotter.clear()
        plotter.rateTimePlot(c2.packets_received,
                             Sim.scheduler.current_time(),
                             chart_name=None)
        plotter.rateTimePlot(c4.packets_received,
                             Sim.scheduler.current_time(),
                             chart_name='two/rateTime.png')

        # Plot queue size
        plotter.clear()
        plotter.queueSizePlot(l.queue_log_x,
                              l.queue_log_y,
                              l.dropped_packets_x,
                              l.dropped_packets_y,
                              chart_name='two/queueSize.png')

        # Plot congestion window
        plotter.clear()
        plotter.windowSizePlot(c1.window_x,
                               c1.window_y,
                               chart_name="two/windowSize1.png")
        plotter.clear()
        plotter.windowSizePlot(c3.window_x,
                               c3.window_y,
                               chart_name="two/windowSize2.png")
Exemplo n.º 57
0
import random


class BroadcastApp(object):
    def __init__(self, node):
        self.node = node

    def receive_packet(self, packet):
        print Sim.scheduler.current_time(), self.node.hostname, packet.ident


if __name__ == '__main__':
    # parameters
    Sim.scheduler.reset()
    Sim.set_debug(True)

    # setup network
    net = Network('networks/five-nodes.txt')

    # get nodes
    n1 = net.get_node('n1')
    n2 = net.get_node('n2')
    n3 = net.get_node('n3')
    n4 = net.get_node('n4')
    n5 = net.get_node('n5')

    # setup broadcast application
    b1 = BroadcastApp(n1)
    n1.add_protocol(protocol="broadcast", handler=b1)
    b2 = BroadcastApp(n2)
Exemplo n.º 58
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        Sim.set_debug('AppHandler')
        #Sim.set_debug('TCP')
        Sim.set_debug('Link')

        net = Network('networks/one-hop-queue.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.filename)

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

        # 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()

        # print some results
        print
        print "========== Overall results =========="
        time = Sim.scheduler.current_time()
        print "Total time: %f seconds" % time
        avg = numpy.mean(c2.queueing_delay_list)
        print "Average queueing delay: %f" % avg
        max = numpy.max(c2.queueing_delay_list)
        print "Max queueing delay: %f" % max
        file_size = os.path.getsize(self.filename)
        print "File size: %i" % file_size
        throughput = file_size / time
        print "Throughput: %f" % throughput

        plotter = Plotter()
        #print "Saving the sequence plot"
        #plotter.create_sequence_plot(c1.x, c1.y, c1.dropX, c1.dropY, c1.ackX, c1.ackY)
        self.c2 = c2
        self.c1 = c1
        self.t1 = t1
        self.t2 = t2
        self.net = net
        plotter.rateTimePlot(c2.packets_received, Sim.scheduler.current_time(),
                             'one/rateTime.png')
Exemplo n.º 59
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        #Sim.set_debug('AppHandler')
        #Sim.set_debug('TCP')
        Sim.set_debug('Link')

        net = Network('networks/five.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
        a1 = AppHandler('test1.txt')
        a2 = AppHandler('test2.txt')
        a3 = AppHandler('test3.txt')
        a4 = AppHandler('test4.txt')
        a5 = AppHandler('test5.txt')

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

        c3 = TCP(t1,n1.get_address('n2'),2,n2.get_address('n1'),2,a2,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)
        c4 = TCP(t2,n2.get_address('n1'),2,n1.get_address('n2'),2,a2,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)

        c5 = TCP(t1,n1.get_address('n2'),3,n2.get_address('n1'),3,a3,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)
        c6 = TCP(t2,n2.get_address('n1'),3,n1.get_address('n2'),3,a3,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)

        c7 = TCP(t1,n1.get_address('n2'),4,n2.get_address('n1'),4,a4,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)
        c8 = TCP(t2,n2.get_address('n1'),4,n1.get_address('n2'),4,a4,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)

        c9 = TCP(t1,n1.get_address('n2'),5,n2.get_address('n1'),5,a5,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)
        c0 = TCP(t2,n2.get_address('n1'),5,n1.get_address('n2'),5,a5,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)

        # send a file
        with open('test1.txt','r') as f:
            while True:
                data = f.read(1000)
                if not data:
                    break
                Sim.scheduler.add(delay=0, event=data, handler=c1.send)
        with open('test2.txt','r') as f:
            while True:
                data = f.read(1000)
                if not data:
                    break
                Sim.scheduler.add(delay=1.5, event=data, handler=c3.send)
        with open('test3.txt','r') as f:
            while True:
                data = f.read(1000)
                if not data:
                    break
                Sim.scheduler.add(delay=2, event=data, handler=c5.send)
        with open('test4.txt','r') as f:
            while True:
                data = f.read(1000)
                if not data:
                    break
                Sim.scheduler.add(delay=2.5, event=data, handler=c7.send)
        with open('test5.txt','r') as f:
            while True:
                data = f.read(1000)
                if not data:
                    break
                Sim.scheduler.add(delay=3, event=data, handler=c9.send)

        # run the simulation
        Sim.scheduler.run()

        # print some results
        print
        print "========== Overall results =========="
        time = Sim.scheduler.current_time()
        print "Total time: %f seconds" % time
        avg = numpy.mean(c2.queueing_delay_list)
        print "Average queueing delay: %f" % avg
        max = numpy.max(c2.queueing_delay_list)
        print "Max queueing delay: %f" % max
        file_size = os.path.getsize(self.filename)
        print "File size: %i" % file_size
        throughput = file_size / time
        print "Throughput: %f" % throughput

        # Variables for debugging
        self.c3 = c3
        self.c4 = c4
        self.c2 = c2
        self.c1 = c1
        self.t1 = t1
        self.t2 = t2
        self.net = net
        linkab = n1.links[0]
        self.linkab = linkab
        l = linkab

        # Plotting
        plotter = Plotter()

        # Plot sequence charts
        #plotter.clear()
        #plotter.create_sequence_plot(c1.x, c1.y, c1.dropX, c1.dropY, c1.ackX, c1.ackY, chart_name='five/sequence1.png')
        #plotter.clear()
        #plotter.create_sequence_plot(c3.x, c3.y, c3.dropX, c3.dropY, c3.ackX, c3.ackY, chart_name='five/sequence2.png')

        # Plot receiver rate
        plotter.clear()
        plotter.rateTimePlot(c2.packets_received, Sim.scheduler.current_time(), chart_name='five/rateTime1.png')
        plotter.rateTimePlot(c4.packets_received, Sim.scheduler.current_time(), chart_name='five/rateTime2.png')
        plotter.rateTimePlot(c6.packets_received, Sim.scheduler.current_time(), chart_name='five/rateTime3.png')
        plotter.rateTimePlot(c8.packets_received, Sim.scheduler.current_time(), chart_name='five/rateTime4.png')
        plotter.rateTimePlot(c0.packets_received, Sim.scheduler.current_time(), chart_name='five/rateTime5.png')

        # Plot queue size
        plotter.clear()
        plotter.queueSizePlot(l.queue_log_x, l.queue_log_y, l.dropped_packets_x, l.dropped_packets_y, chart_name='five/queueSize.png')
Exemplo n.º 60
0
 def plot_sequence_header(self):
     if self.node.hostname =='n1':
         Sim.plot('sequence.csv','Time,Sequence Number,Event\n')