Skip to content

Commit

Permalink
move queue out to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed May 6, 2016
1 parent ad23c93 commit ea3bffe
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 41 deletions.
70 changes: 70 additions & 0 deletions include/simulator/queue.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
Copyright (c) 2015, Arvid Norberg
All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef QUEUE_HPP_INCLUDED
#define QUEUE_HPP_INCLUDED

#include "simulator/simulator.hpp"

namespace sim
{

// this is a queue. It can be configured to contrain
struct SIMULATOR_DECL queue : sink
{
queue(asio::io_service& ios, int bandwidth
, chrono::high_resolution_clock::duration propagation_delay
, int max_queue_size, std::string name = "queue");

virtual void incoming_packet(aux::packet p) override final;

virtual std::string label() const override final;

private:

void begin_send_next_packet();
void next_packet_sent();

// the queue can't hold more than this number of bytes. Once it's full,
// any new packets arriving will be dropped (tail drop)
const int m_max_queue_size;

// the amount of time it takes to forward a packet. Every packet is
// delayed by at least this much before being forwarded
const chrono::high_resolution_clock::duration m_forwarding_latency;

// the number of bytes per second that can be sent. This includes the
// packet overhead
const int m_bandwidth;

// the number of bytes currently in the packet queue
int m_queue_size;

std::string m_node_name;

// this is the queue of packets and the time each packet was enqueued
std::deque<std::pair<chrono::high_resolution_clock::time_point, aux::packet>> m_queue;
asio::high_resolution_timer m_forward_timer;

chrono::high_resolution_clock::time_point m_last_forward;
};

}

#endif

40 changes: 0 additions & 40 deletions include/simulator/simulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1446,46 +1446,6 @@ namespace sim

} // aux

// this is a queue. It can be configured to contrain
struct SIMULATOR_DECL queue : sink
{
queue(asio::io_service& ios, int bandwidth
, chrono::high_resolution_clock::duration propagation_delay
, int max_queue_size, std::string name = "queue");

virtual void incoming_packet(aux::packet p) override final;

virtual std::string label() const override final;

private:

void begin_send_next_packet();
void next_packet_sent();

// the queue can't hold more than this number of bytes. Once it's full,
// any new packets arriving will be dropped (tail drop)
const int m_max_queue_size;

// the amount of time it takes to forward a packet. Every packet is
// delayed by at least this much before being forwarded
const chrono::high_resolution_clock::duration m_forwarding_latency;

// the number of bytes per second that can be sent. This includes the
// packet overhead
const int m_bandwidth;

// the number of bytes currently in the packet queue
int m_queue_size;

std::string m_node_name;

// this is the queue of packets and the time each packet was enqueued
std::deque<std::pair<chrono::high_resolution_clock::time_point, aux::packet>> m_queue;
asio::high_resolution_timer m_forward_timer;

chrono::high_resolution_clock::time_point m_last_forward;
};

void SIMULATOR_DECL dump_network_graph(simulation const& s, std::string filename);
}

Expand Down
1 change: 1 addition & 0 deletions src/default_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ All rights reserved.
*/

#include "simulator/simulator.hpp"
#include "simulator/queue.hpp"
#include <memory>

typedef sim::chrono::high_resolution_clock::time_point time_point;
Expand Down
2 changes: 1 addition & 1 deletion src/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ All rights reserved.
*/

#include "simulator/simulator.hpp"
#include "simulator/queue.hpp"
#include <functional>

typedef sim::chrono::high_resolution_clock::time_point time_point;
Expand Down

0 comments on commit ea3bffe

Please sign in to comment.