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

        # 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 application
        a = AppHandler(self.filename, self.out_directory)

        # 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()
        # print str(self.window) + " & " + \
        #         str(Sim.scheduler.current_time()) + " & " + \
        #         str(4116160.0 / float(Sim.scheduler.current_time())) + " & " + \
        #         str(c2.totalQueueingDelay / float(c1.totalPacketsSent)) + " \\\\"

        # print str(self.window) + "," + str(4116160.0 / float(Sim.scheduler.current_time()))

        print str(self.window) + "," + str(
            c2.totalQueueingDelay / float(c1.totalPacketsSent))
Exemplo n.º 2
0
    def run(self):
        # parameters
        Sim.scheduler.reset()

        if hasattr(self, 'debug') and "a" in self.debug:
            Sim.set_debug('AppHandler')
        if hasattr(self, 'debug') and "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.filename)

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

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

        # run the simulation
        Sim.scheduler.run()
Exemplo n.º 3
0
    def __init__(self,transport,source_address,source_port,
                 destination_address,destination_port,app=None,window=1000):
        Connection.__init__(self,transport,source_address,source_port,
                            destination_address,destination_port,app)

        ### Sender functionality
        self.totalQueueingDelay = 0.0
        self.totalPacketsSent = 0
        self.port = source_port
        self.dynamic = True
        self.output = False
        self.proveTimer = False
        self.proveCong = False
        self.stand_trace = False
        self.seq_plot = False
        self.graph1 = True
        self.graph2 = False   # == This is controlled in the transfer file by Sim.set_debug('Link')
        self.graph3 = False
        self.graph4 = False

        if self.graph2:
            Sim.set_debug('Link')
        # send window; represents the total number of bytes that may
        # be outstanding at one time
        # maximum segment size, in bytes
        self.mss = 1000
        # Step 2
        self.window = self.mss  ######################### This one gets the mess adjusted out of it
        # threshold for slow start
        self.thresh = 100000
        self.inc_sum = 0
        # for fast retransmit
        self.last_ack = 0
        self.dup_counter = 0
        self.drop_next = False
        self.has_dropped = False
        self.dropped_count = 0
        # send buffer
        self.send_buffer = SendBuffer()
        ############################################# (this never gets adjusted)
        #self.mss = min(1000, window) ################ TODO: handle the case where window is bigger than mss
        # largest sequence number that has been ACKed so far; represents
        # the next sequence number the client expects to receive
        self.sequence = 0
        # retransmission timer
        self.timer = None
        # timeout duration in seconds
        self.timeout = 1.0
        if self.dynamic:
            self.timeout = 3.0
        # estimated rtt
        self.est_rtt = None
        # alpha
        self.alpha = 0.125
        # variation rtt
        self.var_rtt = None  ## TODO: revisit this later
        # beta
        self.beta = 0.25
        ### Receiver functionality

        # receive buffer
        self.receive_buffer = ReceiveBuffer()
        # ack number to send; represents the largest in-order sequence
        # number not yet received
        self.ack = 0
Exemplo n.º 4
0
    def __init__(self,transport,source_address,source_port,destination_address,destination_port,app=None):
        Connection.__init__(self,transport,source_address,source_port, destination_address,destination_port,app)

        ### RTO Timer Properties
        self.rtt_initialized = False
        self.rto = None
        self.srtt = None
        self.rttvar = None
        self.K = 4
        self.initialize_timer()

        # RTT Cap Seconds
        self.max_rtt = 60
        self.min_rtt = 1

        self.alpha = 0.125
        self.beta = 0.25

        ### Sender functionality

        self.transmission_finished = False

        # send buffer
        self.send_buffer = SendBuffer()
        # maximum segment size, in bytes
        self.mss = 1000
        # send window; represents the total number of bytes that may
        # be outstanding at one time
        self.window = self.mss
        # largest sequence number that has been ACKed so far; represents
        # the next sequence number the client expects to receive
        self.sequence = 0
        # retransmission timer
        self.timer = None
        # timeout duration in seconds
        self.timeout = 1
        # is_retransmitting prevents more duplicate ACKs from triggering another send.
        self.is_retransmitting = False

        self.force_drop = True

        ### Congestion Control

        self.restarting_slow_start = False
        self.threshold = 16000
        self.additive_increase_total = 0

        # Fast Retransmit ACKs
        self.retransmit_acks = [-1] * 3

        ### Receiver functionality

        # receive buffer
        self.receive_buffer = ReceiveBuffer()
        # ack number to send; represents the largest in-order sequence
        # number not yet received
        self.ack = 0

        ### Testing
        self.is_aiad = False

        ### FILE WRITING
        self.write_to_disk = True
        self.plot_port_number = 2

        self.plot_sequence_on = False
        self.plot_rate_on = True
        self.plot_queue_on = False
        self.plot_window_on = False

        file_name = "output.txt"
        header_message = "## header message ##"

        if self.plot_sequence_on:
            file_name = "sequence_plot.txt"
            header_message = "# Time (seconds) Sequence (number) Dropped (0 or 1) ACK (0 or 1)"
            Sim.set_debug("Link")
        elif self.plot_rate_on:
            file_name = "rate_plot.txt"
            header_message = "# Time (seconds) Size (number)"
        elif self.plot_queue_on:
            file_name = "queue_plot.txt"
            header_message = "# Time (seconds) Queue Size (bytes)"
            Sim.set_debug("Queue")
        elif self.plot_window_on:
            file_name = "window_plot.txt"
            header_message = "# Time (seconds) Congestion Window Size (bytes)"

        if self.write_to_disk:
            file_title,file_extension = file_name.split('.')
            new_file_name = file_title + str(self.plot_port_number) + '.' + file_extension
            self.trace("PRINTING TO: %s" % new_file_name)
            sys.stdout = open(new_file_name, 'w')
            print header_message
Exemplo n.º 5
0
def trace_on():
    Sim.set_debug("Node")
    Sim.set_debug("Link")
Exemplo n.º 6
0
    trace_on()

    simple_send(nodes, 0, 'n4', 11, 'n5', 0)
    # p = packet.Packet(source_address=nodes[0].get_address('n4'),destination_address=nodes[11].get_address('n5'),ident=1,length=100)
    # Sim.scheduler.add(delay=0, event=p, handler=nodes[0].send_packet)

    run()


def print_tables(nodes, apps):
    print "==============================="
    for i in range(0, len(nodes)):
        print "Final DV for " + str(nodes[i].hostname) + ": " + str(
            apps[i].dist_vector)

    print "==============================="

    for i in range(0, len(nodes)):
        print "Final forwarding table for " + str(
            nodes[i].hostname) + ": " + str(apps[i].pretty_ft())


if __name__ == '__main__':

    Sim.scheduler.reset()
    Sim.set_debug("DVR")

    # five_node_line_exp()
    five_node_ring_exp()
    # fifteen_nodes_exp()