Skip to content

Commit

Permalink
Merge branch 'congestion-framework' into testingRerouting
Browse files Browse the repository at this point in the history
  • Loading branch information
YousefEZ authored Mar 13, 2024
2 parents 056caca + ba93070 commit aa38a24
Show file tree
Hide file tree
Showing 2 changed files with 243 additions and 3 deletions.
13 changes: 10 additions & 3 deletions libs/random_congestion_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,29 @@ class RandomCongestionPolicy
static_assert(PERCENTAGE >= 0 && PERCENTAGE <= 100,
"Percentage must be between 0 and 100");

bool m_off;
bool m_off = true;
bool m_enabled = false;

public:
RandomCongestionPolicy() = default;

bool isCongested(ns3::Queue<ns3::Packet>* queue) const
{
std::random_device rd;
if (!m_enabled) return false;
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(0, 100);
return !m_off && dis(gen) < PERCENTAGE;
}

void turnOff()
{
m_off = true;
m_off = false;
}

void enable()
{
m_enabled = true;
}
};

Expand Down
233 changes: 233 additions & 0 deletions src/combined.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
#include <iostream>

#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/log.h"

#include "../libs/frr_queue.h"
#include "../libs/dummy_congestion_policy.h"
#include "../libs/modulo_congestion_policy.h"
#include "../libs/lfa_policy.h"
#include "../libs/random_congestion_policy.h"
#include "../libs/basic_congestion.h"

using namespace ns3;

using CongestionPolicy = BasicCongestionPolicy<0>;
using FRRPolicy = LFAPolicy;

using SimulationQueue = FRRQueue<CongestionPolicy, FRRPolicy>;

void enableRerouting(Ptr<SimulationQueue> queue)
{
//queue->m_congestionPolicy.enable();
}

NS_OBJECT_ENSURE_REGISTERED(SimulationQueue);

template <int INDEX>
Ptr<PointToPointNetDevice> getDevice(const NetDeviceContainer& devices)
{
return devices.Get(INDEX)->GetObject<PointToPointNetDevice>();
}

template <int INDEX>
Ptr<SimulationQueue> getQueue(const NetDeviceContainer& devices)
{
return DynamicCast<SimulationQueue>(getDevice<INDEX>(devices)->GetQueue());
}

template <int INDEX>
void setAlternateTarget(const NetDeviceContainer& devices,
Ptr<PointToPointNetDevice> target)
{
getQueue<INDEX>(devices)->addAlternateTargets(target);
}

void SetupTCPConfig()
{
// TCP recovery algorithm
Config::SetDefault(
"ns3::TcpL4Protocol::RecoveryType",
TypeIdValue(TypeId::LookupByName("ns3::TcpClassicRecovery")));
// Congestion control algorithm
Config::SetDefault("ns3::TcpL4Protocol::SocketType",
StringValue("ns3::TcpLinuxReno"));
Config::SetDefault("ns3::TcpSocket::SndBufSize", UintegerValue(1073741824));
Config::SetDefault("ns3::TcpSocket::RcvBufSize", UintegerValue(1073741824));
// Initial congestion window
Config::SetDefault("ns3::TcpSocket::InitialCwnd", UintegerValue(1));
// Set delayed ack count
Config::SetDefault("ns3::TcpSocket::DelAckTimeout", TimeValue(Time("1ms")));
Config::SetDefault("ns3::TcpSocket::DelAckCount", UintegerValue(1));
// Set segment size of packet
Config::SetDefault("ns3::TcpSocket::SegmentSize", UintegerValue(1024));
// Enable/disable SACKs (disabled)
Config::SetDefault("ns3::TcpSocketBase::Sack", BooleanValue(false));
Config::SetDefault("ns3::TcpSocketBase::MinRto", TimeValue(Seconds(1.0)));
}

// NS_LOG_COMPONENT_DEFINE("CongestionFastReRoute");
int main(int argc, char* argv[])
{
LogComponentEnable("FRRQueue", LOG_LEVEL_LOGIC);
/*
* +----------+ +-----------+
* |Congestion| | Traffic |
* | Sender | | Sender |
* 0+----+-----+ 1+-----+-----+
* | |
* | +----------+ |
* +---+ Router +---+
* | 01 |
* 2+----+-----+--------+
* | |
* | +-----+----+
* | | Router |
* | | 03 |
* +----+-----+ 4+----+-----+
* | Router | |
* | 02 +-------+
* 3+----+-----+
* |
* |
* +----+-----+
* | Receiver |
* | |
* 5+----------+
*/
// Topology setup
NS_LOG_INFO("Creating Topology");
NodeContainer nodes;
nodes.Create(6);
Names::Add("CongestionSender", nodes.Get(0));
Names::Add("TrafficSender", nodes.Get(1));
Names::Add("Router01", nodes.Get(2));
Names::Add("Router02", nodes.Get(3));
Names::Add("Router03", nodes.Get(4));
Names::Add("Receiver", nodes.Get(5));

InternetStackHelper stack;
stack.Install(nodes);

// Configure PointToPoint link for normal traffic
PointToPointHelper p2p_traffic;
p2p_traffic.SetDeviceAttribute("DataRate", StringValue("1Mbps"));
p2p_traffic.SetChannelAttribute("Delay", StringValue("1ms"));
// Set the custom queue for the device
p2p_traffic.SetQueue("ns3::DropTailQueue<Packet>");
// Install devices and channels between nodes

PointToPointHelper p2p_congested_link;
p2p_congested_link.SetDeviceAttribute("DataRate", StringValue("1Mbps"));
p2p_congested_link.SetChannelAttribute("Delay", StringValue("1ms"));

p2p_congested_link.SetQueue(SimulationQueue::getQueueString());

NetDeviceContainer devices_0_2 =
p2p_traffic.Install(nodes.Get(0), nodes.Get(2));
NetDeviceContainer devices_2_3 =
p2p_congested_link.Install(nodes.Get(2), nodes.Get(3));
NetDeviceContainer devices_2_4 =
p2p_traffic.Install(nodes.Get(2), nodes.Get(4));
NetDeviceContainer devices_4_3 =
p2p_traffic.Install(nodes.Get(4), nodes.Get(3));
NetDeviceContainer devices_3_5 =
p2p_traffic.Install(nodes.Get(3), nodes.Get(5));

// Configure PointToPoint link for congestion link
PointToPointHelper p2p_congestion;
p2p_congestion.SetDeviceAttribute("DataRate", StringValue("1Mbps"));
p2p_congestion.SetChannelAttribute("Delay", StringValue("1ms"));
// Set the custom queue for the device
p2p_congestion.SetQueue("ns3::DropTailQueue<Packet>");
// Install devices and channels between nodes
NetDeviceContainer devices_1_2 =
p2p_congestion.Install(nodes.Get(1), nodes.Get(2));

// Assign IP addresses to subnets
Ipv4AddressHelper address;
address.SetBase("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer interfaces_0_2 = address.Assign(devices_0_2);
Ipv4InterfaceContainer interfaces_1_2 = address.Assign(devices_1_2);
address.NewNetwork();
address.SetBase("10.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer interfaces_2_3 = address.Assign(devices_2_3);
address.NewNetwork();
address.SetBase("10.1.3.0", "255.255.255.0");
Ipv4InterfaceContainer interfaces_2_4 = address.Assign(devices_2_4);
address.NewNetwork();
address.SetBase("10.1.4.0", "255.255.255.0");
Ipv4InterfaceContainer interfaces_4_3 = address.Assign(devices_4_3);
address.NewNetwork();
address.SetBase("10.1.5.0", "255.255.255.0");
Ipv4InterfaceContainer interfaces_3_5 = address.Assign(devices_3_5);
address.NewNetwork();
Ipv4GlobalRoutingHelper::PopulateRoutingTables();

// Receiver address
Ipv4Address receiver_addr = interfaces_3_5.GetAddress(1);

// UDP Congestion traffic setup
uint16_t udp_port = 5001;
OnOffHelper udp_source("ns3::UdpSocketFactory",
InetSocketAddress(receiver_addr, udp_port));
udp_source.SetAttribute(
"OnTime", StringValue("ns3::ConstantRandomVariable[Constant=1]"));
udp_source.SetAttribute(
"OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0]"));
udp_source.SetAttribute("DataRate", DataRateValue(DataRate("1Mbps")));
udp_source.SetAttribute("PacketSize", UintegerValue(1024));

ApplicationContainer udp_app = udp_source.Install(nodes.Get(0));
udp_app.Start(Seconds(3.0));
udp_app.Stop(Seconds(6.0));

// TCP Setup
SetupTCPConfig();
uint16_t tcp_port = 5002;
BulkSendHelper tcp_source("ns3::TcpSocketFactory",
InetSocketAddress(receiver_addr, tcp_port));
tcp_source.SetAttribute("MaxBytes", UintegerValue(10000)); // Tweak this
ApplicationContainer tcp_app = tcp_source.Install(nodes.Get(1));
tcp_app.Start(Seconds(0.0));
tcp_app.Stop(Seconds(10.0));

// Packet sink setup (Receiver node)
PacketSinkHelper sink("ns3::TcpSocketFactory",
InetSocketAddress(Ipv4Address::GetAny(), tcp_port));
ApplicationContainer sink_app = sink.Install(nodes.Get(5));
tcp_app.Start(Seconds(0.0));
tcp_app.Start(Seconds(10.0));

SimulationQueue::sinkAddress = Mac48Address::ConvertFrom(getDevice<1>(devices_3_5)->GetAddress());
// NOTE: Is TrafficControlHelper needed here?

// LFA Alternate Path setup
// Set up an alternate forwarding target, assuming you have an alternate
// path configured

// TODO: Need some help with setting alternate target
setAlternateTarget<0>(devices_2_3, getDevice<0>(devices_2_4));
setAlternateTarget<1>(devices_2_3, getDevice<1>(devices_4_3));
// setAlternateTarget<0>(devices01, getDevice<0>(devices02));
// setAlternateTarget<0>(devices02, getDevice<0>(devices01));

// setAlternateTarget<0>(devices12, getDevice<1>(devices01));
// setAlternateTarget<1>(devices01, getDevice<0>(devices12));

// setAlternateTarget<1>(devices02, getDevice<1>(devices12));
// setAlternateTarget<1>(devices12, getDevice<1>(devices02));

//enableRerouting(getQueue<0>(devices_2_3));

p2p_traffic.EnablePcapAll("traces/");
p2p_congestion.EnablePcapAll("traces/");

Simulator::Run();
Simulator::Destroy();
return 0;
}

0 comments on commit aa38a24

Please sign in to comment.