Ejemplo n.º 1
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        logging.getLogger('app').setLevel(logging.INFO)
        logging.getLogger('bene.link.queue').setLevel(logging.DEBUG)
        logging.getLogger('bene.tcp.sequence').setLevel(logging.DEBUG)
        logging.getLogger('bene.tcp.cwnd').setLevel(logging.DEBUG)
        if self.debug:
            logging.getLogger('bene.tcp').setLevel(logging.DEBUG)
            logging.getLogger('bene.tcp.sender').setLevel(logging.DEBUG)
            logging.getLogger('bene.tcp.receiver').setLevel(logging.DEBUG)

        # 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(n2.get_address('n1'), n1.links[0])
        n2.add_forwarding_entry(n1.get_address('n2'), n2.links[0])

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

        # setup application
        a = AppHandler(self.filename)

        window = 1000

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

        # 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()
Ejemplo n.º 2
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))
Ejemplo n.º 3
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()
Ejemplo n.º 4
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()
Ejemplo n.º 5
0
    def run(self):
        # parameters
        Sim.scheduler.reset()

        # setup network
        net = Network('experiment.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,
                 measure=True)
        TCP(t2,
            n2.get_address('n1'),
            1,
            n1.get_address('n2'),
            1,
            a,
            window=self.window,
            fast_retransmit=self.fast_retransmit,
            measure=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()
        result_file = open("results.txt", "r")
        results = result_file.read()
        result_file.close()
        f = open("experiment.csv", "a")
        f.write(str(self.window) + "," + results + "\n")
Ejemplo n.º 6
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))
Ejemplo n.º 7
0
 def __init__(self, ipAddress):
     self.sq = Queue()
     self.rq = Queue()
     self.struct = Struct('BBbB')  #command, selector, value, checksum
     self.sender = TCP(isServer=False,
                       isSender=True,
                       host=ipAddress,
                       port=1234,
                       q=self.sq)
     self.receiver = TCP(isServer=False,
                         isSender=False,
                         host=ipAddress,
                         port=5678,
                         q=self.rq)
Ejemplo n.º 8
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        Sim.set_debug('AppHandler')
        Sim.set_debug('TCP')
        Sim.set_debug('Plot')

        # 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)
        TCP(t2,
            n2.get_address('n1'),
            1,
            n1.get_address('n2'),
            1,
            a,
            window=self.window)

        # 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()
Ejemplo n.º 9
0
    def __init__(self, address: Tuple[str, int]):
        self.root_logger = logging.getLogger() # root_logger
        self._root_logging_lvl_default = self.root_logger.level
        self.sh = self.root_logger.handlers[0] # stream_handler
        self._sh_lvl_default = self.sh.level

        self.logger = logging.getLogger(self.__class__.__name__)
        self.logger.setLevel(logging.DEBUG)
        fh = logging.FileHandler('spam.log')
        fh.setLevel(logging.DEBUG)
        self.logger.addHandler(fh)
        self._stop_connections = False
        self._reset_connection = False
        self._exit_measurement = False
        self.cycle_continuously = False
        self.return_data = b""
        self.return_data_queue = b""
        self.measurement_timeout = 0
        self.keylisten_thread = None
        self.command_queue = Queue(0)  # 0 indicates no maximum queue length enforced.
        self.element_tags = []  # for debugging
        self.devices = []

        # instantiate the device objects
        self.hsdio = HSDIO(self)
        self.tcp = TCP(self, address)
        self.analog_input = AnalogInput(self)
        self.analog_output = AnalogOutput(self)
        self.ttl = TTLInput(self)
        # self.daqmx_do = DAQmxDO(self)
        self.hamamatsu = Hamamatsu(self)
        self.counters = Counters(self)
Ejemplo n.º 10
0
    def __init__(self, game_id, player_name, is_not_tcp):
        self.game_id = game_id
        self.player_name = player_name
        self.is_my_turn = False
        self.winner_status = GameWinnerStatus.NoWinner
        self.last_turn_illegal = False
        self.action_options = []
        self.winning_points_dim = np.zeros(shape=(9, 9), dtype=int)

        # join_game(self.game_id, self.player_name)

        if not is_not_tcp:
            self.tcp = TCP(game_id, player_name, self.on_recieved)
            self.wait_for_my_turn()

        self.action_space = spaces.Discrete(Global.num_of_actions)

        self.observation_space = spaces.Tuple((
            spaces.MultiBinary([9, 9]),
            spaces.MultiBinary([9, 9]),
            spaces.MultiBinary([9, 9]),
            spaces.MultiBinary([9, 9]),
            spaces.MultiBinary([9, 9])
        ))

        self.seed()
Ejemplo n.º 11
0
 def start_training_session(self, num_of_episodes):
     for episode_num in range(num_of_episodes):
         self.headline_print("start game of episode number {}".format(episode_num + 1))
         self.game_id = rest_api.create_game(self.name).content.decode("utf-8")
         print("Trainer created game with id: {}".format(self.game_id))
         self.tcp = TCP(self.game_id, self.name, self.on_recieved)
         self.start_game_with_agent(self.game_id)
         self.headline_print("end of episode number {}".format(episode_num + 1))
Ejemplo n.º 12
0
def main(url):

    parsed = urlparse(url)
    # exit on unsupported application protocol
    if parsed.scheme.lower() != 'http':
        print '"' + parsed.scheme  + '"' + ' scheme address is not supported'
        sys.exit()
    host = parsed.netloc
    filename = getFilename(parsed.path)
    request = getRequest(parsed.path, host)
    print filename
    print request
    # Initiate the download
    startTime = time.time()
    sock = TCP()
    sock.connect(host)
    sock.sendGet(request)

    # Start the retrieve
    filedata = sock.transmission()
    	
    print filedata

    # if found it is a non-200 packet, exit
    if not filedata.startswith("HTTP/1.1 200"):
        print ('Non-200 HTTP status code is not supported')
    	sys.exit(0)

    # remove the HTTP header:
    pos = filedata.find("\r\n\r\n")
    if pos > -1:
        pos += 4
        filedata = filedata[pos:]

    endTime = time.time()

    # save file to disk
    saveFile(filename, filedata)
    print len(filedata),
    print 'Bytes received'
    #timecost = '%.2g' % (endTime - startTime)
    #print timecost,
    #print 'seconds passed. Average speed:',
    #throughput = '%f' % (len(filedata) / float(timecost) / 1000)
    #print throughput,
    #print 'KBps'
    sock.sock.close()
Ejemplo n.º 13
0
    print('Ethernet Frame:')
    print(TAB_1 + 'Destination: {}, Source: {}, Protocol: {}'.format(
        eth.dest_mac, eth.src_mac, eth.proto))

    # IPv4
    if eth.proto == 8:
        ipv4 = IPv4(eth.data)
        print(TAB_1 + 'IPv4 Packet:')
        print(TAB_2 + 'Version: {}, Header Length: {}, TTL: {},'.format(
            ipv4.version, ipv4.header_length, ipv4.ttl))
        print(TAB_2 + 'Protocol: {}, Source: {}, Target: {}'.format(
            ipv4.proto, ipv4.src, ipv4.target))

        # TCP
        if ipv4.proto == 6:
            tcp = TCP(ipv4.data)
            print(TAB_1 + 'TCP Segment:')
            print(TAB_2 + 'Source Port: {}, Destination Port: {}'.format(
                tcp.src_port, tcp.dest_port))
            print(TAB_2 + 'Sequence: {}, Acknowledgment: {}'.format(
                tcp.sequence, tcp.acknowledgment))
            print(TAB_2 + 'Flags:')
            print(TAB_3 + 'URG: {}, ACK: {}, PSH: {}'.format(
                tcp.flag_urg, tcp.flag_ack, tcp.flag_psh))
            print(TAB_3 + 'RST: {}, SYN: {}, FIN:{}'.format(
                tcp.flag_rst, tcp.flag_syn, tcp.flag_fin))

            if len(tcp.data) > 0:
                # HTTP
                if tcp.src_port == 80 or tcp.dest_port == 80:
                    print(TAB_2 + 'HTTP Data:')
Ejemplo n.º 14
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')
Ejemplo n.º 15
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")
Ejemplo n.º 16
0
def fn(x, y):
    tcp = TCP([x, y], arms=2, armlengths=armlengths)
    tcp.computeTcp()
    return tcp.tcp  # should be list of length 3
Ejemplo n.º 17
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        logging.getLogger('app').setLevel(logging.INFO)
        logging.getLogger('bene.link.queue').setLevel(logging.DEBUG)
        logging.getLogger('bene.tcp.sequence').setLevel(logging.DEBUG)
        logging.getLogger('bene.tcp.cwnd').setLevel(logging.DEBUG)
        if self.debug:
            logging.getLogger('bene.tcp').setLevel(logging.DEBUG)
            logging.getLogger('bene.tcp.sender').setLevel(logging.DEBUG)
            logging.getLogger('bene.tcp.receiver').setLevel(logging.DEBUG)

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

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

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

        # setup application
        a = AppHandler(self.filename)

        window = self.wsize

        # setup connection
        drop = []
        c1 = TCP(t1,
                 n1.get_address('n2'),
                 1,
                 n2.get_address('n1'),
                 1,
                 a,
                 window=window,
                 drop=drop,
                 retran=self.retran)
        c2 = TCP(t2,
                 n2.get_address('n1'),
                 1,
                 n1.get_address('n2'),
                 1,
                 a,
                 window=window)
        # send a file
        strin = ""
        times = []
        for i in range(5):
            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)
                # break
            Sim.scheduler.run()
            times.append(Sim.scheduler.current_time())
            Sim.scheduler.reset()
        times.append(sum(times) / len(times))
        with open("report/w10000_TESTING.txt", 'w') as f2:
            f2.writelines(["%s\n" % item for item in times])
Ejemplo n.º 18
0
def main(*args, **kwargs):
    start = time.time()
    global client, passphrase, host, port
    network = []
    chain = BlockChain(client, passphrase)
    files = Filemng(client, chain)
    encrypt = files.Load_Both_Keys()
    files.Load_Month()
    print("Loading Logs")
    sensors = Sensor()
    sensors.Config_Sensors()
    print("Configued Sensors")
    que = queue.Queue()
    send_que = queue.Queue()
    recv_que = queue.Queue()
    comm = TCP(encrypt, passphrase, host, port, que, send_que, recv_que)

    Showdown = False
    while not Showdown:
        print("Collecting Sensors data")
        Collect_Sensor(chain, sensors)
        print("Saving Log")
        files.Save_Log()
        error = 0
        transmit = False
        water_count = 0
        print("Checking Water level/Levels")
        if (float(chain.chain[-1].sensor.water_level) < MAX_WATER_LEVEL
                and float(chain.chain[-1].sensor.water_level) != 0.00
                or 0 < water_count <= 10):
            if (float(chain.chain[-1].sensor.water_level) < MAX_WATER_LEVEL):
                water_count = 0
            water_count += 1
            attenna_status = True  #sensors.boot_antenna()
            while (not attenna_status and not Showdown):
                attenna_status = sensors.boot_antenna()
                error += 1
                if (error >= 3):
                    chain.Set_Network_Error(112)
                    Shutdown(files)
                    Showdown = True
            if (not comm.State):
                Start_Comm(comm)
                time.sleep(1)
            print("Water level High")
            transmit = True
        print("Checking Unsent Object")
        if (Check_Unsent_Blocks(chain) > UNSENT_SEND and not transmit):
            attenna_status = True  #sensors.boot_antenna()
            while (not attenna_status and not Showdown):
                attenna_status = sensors.boot_antenna()
                error += 1
                if (error >= 3):
                    chain.Set_Network_Error(112)
                    Shutdown(files)
                    Showdown = True
            if (not comm.State):
                Start_Comm(comm)
                time.sleep(1)
            print("Unsent blocks High")
            transmit = True

        if (transmit):
            Send_Blocks(chain, send_que)
            time.sleep(5)
            Remove_blocks(chain, recv_que)
            print("Transmitting")
        else:
            print("Nothing to transmitt")
            files.Save_Log()
            Showdown = True

        if not que.empty():
            network.append(que.get())
        if (len(network) > 0):
            chain.Set_Network_Error(network[0][0])
            if (network[0][0] == 111):
                Showdown = True
        time.sleep(2)
        print("Cycling ")
    print("Shutting Down")
    Soft_Shutdown(files, comm)
Ejemplo n.º 19
0
# This file is part of openWNS (open Wireless Network Simulator)
# _____________________________________________________________________________
#
# Copyright (C) 2004-2007
# Chair of Communication Networks (ComNets)
# Kopernikusstr. 16, D-52074 Aachen, Germany
# phone: ++49-241-80-27910,
# fax: ++49-241-80-22242
# email: [email protected]
# www: http://www.openwns.org
# _____________________________________________________________________________
#
# openWNS is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License version 2 as published by the
# Free Software Foundation;
#
# openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################

import openwns
import tcp.TCP

openwns.simulator.OpenWNS.modules.tcp = TCP.TCP()
Ejemplo n.º 20
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")
Ejemplo n.º 21
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)
Ejemplo n.º 22
0
    def run(self, size):
        # parameters
        Sim.scheduler.reset()
        logging.getLogger('app').setLevel(logging.INFO)
        logging.getLogger('bene.link.queue').setLevel(logging.DEBUG)
        logging.getLogger('bene.tcp.sequence').setLevel(logging.DEBUG)
        logging.getLogger('bene.tcp.cwnd').setLevel(logging.DEBUG)
        if self.debug:
            logging.getLogger('bene.tcp').setLevel(logging.DEBUG)
            logging.getLogger('bene.tcp.sender').setLevel(logging.DEBUG)
            logging.getLogger('bene.tcp.receiver').setLevel(logging.DEBUG)

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

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

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

        # setup application
        a = AppHandler(self.filename)

        window = size

        # setup connection
        drop = []
        filen = ("data/queue-%i.csv" % size)
        fd = open(filen, "w")
        fd.write("Time_stamp,qDelay\n")
        c1 = TCP(t1,
                 n1.get_address('n2'),
                 1,
                 n2.get_address('n1'),
                 1,
                 a,
                 window=window,
                 drop=drop,
                 retran=self.retran)
        c2 = TCP(t2,
                 n2.get_address('n1'),
                 1,
                 n1.get_address('n2'),
                 1,
                 a,
                 window=window,
                 fd=fd)
        # send a file
        time_before = Sim.scheduler.current_time()
        count = 0
        with open(self.filename, 'rb') as f:
            while True:
                data = f.read(1000)
                count += len(data)
                # print("0",count)
                if not data:
                    break
                Sim.scheduler.add(delay=0, event=data, handler=c1.send)
            Sim.scheduler.run()
        time_after = Sim.scheduler.current_time()
        Sim.scheduler.reset()
        fd.close()
        return (time_after - time_before), count