Skip to content

Commit

Permalink
make the path MTU configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Aug 2, 2015
1 parent a3b12e9 commit 8ea2b3d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
10 changes: 10 additions & 0 deletions include/simulator/simulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,8 @@ namespace sim
route const& get_incoming_route() const
{ return m_incoming_route; }

int get_path_mtu(asio::ip::address ip) const;

private:

sim::simulation& m_sim;
Expand Down Expand Up @@ -981,6 +983,12 @@ namespace sim
// return the hops an outgoing packet from ep need to traverse before
// reaching the network (for instance a DSL modem)
virtual route outgoing_route(asio::ip::address ip) = 0;

// return the path MTU between the two IP addresses
// For TCP sockets, this will be called once when the connection is
// established. For UDP sockets it's called for every burst of packets
// that are sent
virtual int path_mtu(asio::ip::address ip1, asio::ip::address ip2) = 0;
};

struct default_config : configuration
Expand All @@ -992,6 +1000,8 @@ namespace sim
, asio::ip::address dst) override final;
virtual route incoming_route(asio::ip::address ip) override final;
virtual route outgoing_route(asio::ip::address ip) override final;
virtual int path_mtu(asio::ip::address ip1, asio::ip::address ip2)
override final;

private:
std::shared_ptr<queue> m_network;
Expand Down
5 changes: 5 additions & 0 deletions src/default_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ namespace sim {
return route(it->second);
}

int default_config::path_mtu(asio::ip::address ip1, asio::ip::address ip2)
{
return 1475;
}

// return the hops an outgoing packet from ep need to traverse before
// reaching the network (for instance a DSL modem)
route default_config::outgoing_route(asio::ip::address ip)
Expand Down
5 changes: 5 additions & 0 deletions src/io_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ namespace sim { namespace asio {
assert(false);
}

int io_service::get_path_mtu(asio::ip::address ip) const
{
return m_sim.config().path_mtu(m_ip, ip);
}

void io_service::stop()
{
// TODO: cancel all outstanding handler associated with this io_service
Expand Down
4 changes: 3 additions & 1 deletion src/tcp_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace ip {
tcp::socket::socket(io_service& ios)
: socket_base(ios)
, m_connect_timer(ios)
, m_mss(1475) // TODO: make configurable
, m_mss(1475)
, m_queue_size(0)
, m_recv_timer(ios)
, m_is_v4(true)
Expand Down Expand Up @@ -297,6 +297,8 @@ namespace ip {
m_bound_to = addr;
}
m_channel = m_io_service.internal_connect(this, target, ec);
m_mss = m_io_service.get_path_mtu(target.address());
m_cwnd = m_mss * 2;
if (ec)
{
m_channel.reset();
Expand Down
6 changes: 3 additions & 3 deletions src/udp_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,10 @@ namespace ip {

time_point now = chrono::high_resolution_clock::now();

// this is outgoing bandwidth
// this is outgoing NIC bandwidth
// TODO: make this configurable
const int bandwidth = 1000000; // 1 MB/s
const int mtu = 1475;
const int bandwidth = 100000000; // 100 MB/s
const int mtu = m_io_service.get_path_mtu(dst.address());

if (ret > mtu)
{
Expand Down

0 comments on commit 8ea2b3d

Please sign in to comment.