Skip to content

Commit

Permalink
Merge pull request #26 from YousefEZ/tcpsplit
Browse files Browse the repository at this point in the history
✨ Added Tcp Sender (flows) as Argument to Commandline
  • Loading branch information
YousefEZ authored Apr 6, 2024
2 parents 302e655 + a5ba5b7 commit 000a626
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 181 deletions.
8 changes: 4 additions & 4 deletions run_ns3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ run_experiment() {
mkdir -p "$dir/baseline-udp/"
mkdir -p "$dir/baseline-no-udp/"

NS_LOG="" ./ns3 run "scratch/combined-frr.cc --$test_variable=$test_value --policy_threshold=$policy_threshold --dir=$dir/frr/"
NS_LOG="" ./ns3 run "scratch/combined-frr-no-udp.cc --$test_variable=$test_value --policy_threshold=$policy_threshold --dir=$dir/frr-no-udp/"
NS_LOG="" ./ns3 run "scratch/combined-baseline-udp.cc --$test_variable=$test_value --policy_threshold=$policy_threshold --dir=$dir/baseline-udp/"
NS_LOG="" ./ns3 run "scratch/combined-baseline-no-udp.cc --$test_variable=$test_value --policy_threshold=$policy_threshold --dir=$dir/baseline-no-udp/"
NS_LOG="" ./ns3 run "scratch/combined-frr.cc --$test_variable=$test_value --tcp_senders=1 --policy_threshold=$policy_threshold --dir=$dir/frr/"
NS_LOG="" ./ns3 run "scratch/combined-frr-no-udp.cc --$test_variable=$test_value --tcp_senders=1 --policy_threshold=$policy_threshold --dir=$dir/frr-no-udp/"
NS_LOG="" ./ns3 run "scratch/combined-baseline-udp.cc --$test_variable=$test_value --tcp_senders=1 --policy_threshold=$policy_threshold --dir=$dir/baseline-udp/"
NS_LOG="" ./ns3 run "scratch/combined-baseline-no-udp.cc --$test_variable=$test_value --tcp_senders=1 --policy_threshold=$policy_threshold --dir=$dir/baseline-no-udp/"
}

# Delay primary experiments
Expand Down
142 changes: 55 additions & 87 deletions src/combined-baseline-no-udp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,6 @@

using namespace ns3;

using CongestionPolicy = BasicCongestionPolicy;

// using CongestionPolicy = RandomCongestionPolicy<100>;
using FRRPolicy = LFAPolicy;

using SimulationQueue = FRRQueue<CongestionPolicy>;
using FRRNetDevice = PointToPointFRRNetDevice<FRRPolicy>;
using FRRChannel = PointToPointFRRChannel<FRRPolicy>;

void toggleCongestion(Ptr<SimulationQueue> queue)
{
;
// queue->m_congestionPolicy.turnOff();
}

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

NS_OBJECT_ENSURE_REGISTERED(SimulationQueue);
NS_OBJECT_ENSURE_REGISTERED(FRRChannel);
NS_OBJECT_ENSURE_REGISTERED(FRRNetDevice);

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

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

template <int INDEX>
void setAlternateTarget(const NetDeviceContainer& devices,
Ptr<ns3::NetDevice> target)
{
getDevice<INDEX, FRRNetDevice>(devices)->addAlternateTarget(target);
}

// TCP parameters
uint32_t segmentSize = 1024;
uint32_t MTU_bytes = segmentSize + 54;
Expand Down Expand Up @@ -127,6 +83,7 @@ void CalculateExpectedPackets(uint32_t tcp_max_bytes, DataRate udp_data_rate)
int main(int argc, char* argv[])
{
int cong_threshold = 0;
int number_of_tcp_senders = 1;
std::string dir = "";
CommandLine cmd;
cmd.AddValue("bandwidth_primary", "Bandwidth primary",
Expand All @@ -141,6 +98,7 @@ int main(int argc, char* argv[])
bandwidth_alternate);
cmd.AddValue("policy_threshold", "Congestion policy threshold",
cong_threshold);
cmd.AddValue("tcp_senders", "Number of TCP Senders", number_of_tcp_senders);
cmd.AddValue("dir", "Traces directory", dir);
cmd.Parse(argc, argv);

Expand Down Expand Up @@ -176,16 +134,21 @@ int main(int argc, char* argv[])
// Topology setup
NS_LOG_INFO("Creating Topology");
NodeContainer nodes;
nodes.Create(6);
NodeContainer tcp_devices;
nodes.Create(5);
tcp_devices.Create(number_of_tcp_senders);
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));
for (int i = 0; i < number_of_tcp_senders; i++)
Names::Add("TrafficSender" + std::to_string(i), tcp_devices.Get(i));

Names::Add("Router01", nodes.Get(1));
Names::Add("Router02", nodes.Get(2));
Names::Add("Router03", nodes.Get(3));
Names::Add("Receiver", nodes.Get(4));

InternetStackHelper stack;
stack.Install(nodes);
stack.Install(tcp_devices);

// Configure PointToPoint link for normal traffic
PointToPointHelper p2p_traffic;
Expand All @@ -201,30 +164,32 @@ int main(int argc, char* argv[])
StringValue(bandwidth_bottleneck));
p2p_congested_link.SetChannelAttribute("Delay",
StringValue(delay_bottleneck));
// p2p_congested_link.SetQueue(SimulationQueue::getQueueString());
p2p_congested_link.SetQueue("ns3::DropTailQueue<Packet>");

Config::SetDefault("ns3::DropTailQueue<Packet>::MaxSize",
StringValue("10p"));
Config::SetDefault(SimulationQueue::getQueueString() + "::MaxSize",
StringValue("10p"));

PointToPointHelper p2p_alternate;
p2p_alternate.SetDeviceAttribute("DataRate",
StringValue(bandwidth_alternate));
p2p_alternate.SetChannelAttribute("Delay", StringValue(delay_alternate));
p2p_alternate.SetQueue("ns3::DropTailQueue<Packet>");

NetDeviceContainer devices_1_2 =
p2p_traffic.Install(nodes.Get(1), nodes.Get(2));
std::list<NetDeviceContainer> tcp_senders;

for (int i = 0; i < number_of_tcp_senders; i++) {
tcp_senders.push_back(
p2p_traffic.Install(tcp_devices.Get(i), nodes.Get(1)));
}

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

// Configure PointToPoint link for congestion link
PointToPointHelper p2p_congestion;
Expand All @@ -235,31 +200,33 @@ int main(int argc, char* argv[])
p2p_congestion.SetQueue("ns3::DropTailQueue<Packet>");
// Install devices and channels between nodes
NetDeviceContainer devices_0_2 =
p2p_congestion.Install(nodes.Get(0), nodes.Get(2));
p2p_congestion.Install(nodes.Get(0), nodes.Get(1));

// 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");

for (auto& tcp_sender : tcp_senders) {
address.Assign(tcp_sender);
address.NewNetwork();
}

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);

std::cout << receiver_addr << std::endl;
// UDP Congestion traffic setup
uint16_t udp_port = 50001;
OnOffHelper udp_source("ns3::UdpSocketFactory",
Expand All @@ -285,38 +252,39 @@ int main(int argc, char* argv[])
// TCP Setup
SetupTCPConfig();
uint16_t tcp_port = 50002;
BulkSendHelper tcp_source("ns3::TcpSocketFactory",
InetSocketAddress(receiver_addr, tcp_port));
tcp_source.SetAttribute("MaxBytes",
UintegerValue(100000)); // 0 for unlimited data
tcp_source.SetAttribute("SendSize",
UintegerValue(1024)); // Packet size in bytes
ApplicationContainer tcp_app = tcp_source.Install(nodes.Get(1));
tcp_app.Start(Seconds(0.0));
tcp_app.Stop(Seconds(5.0));

std::list<ApplicationContainer> tcp_apps;
for (int i = 0; i < number_of_tcp_senders; i++) {
BulkSendHelper tcp_source("ns3::TcpSocketFactory",
InetSocketAddress(receiver_addr, tcp_port));
tcp_source.SetAttribute("MaxBytes",
UintegerValue(100000)); // 0 for unlimited data
tcp_source.SetAttribute("SendSize",
UintegerValue(1024)); // Packet size in bytes

tcp_apps.push_back(tcp_source.Install(tcp_devices.Get(i)));
tcp_apps.back().Start(Seconds(0.0));
tcp_apps.back().Stop(Seconds(5.0));
}

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

PacketSinkHelper udp_sink(
"ns3::UdpSocketFactory",
InetSocketAddress(Ipv4Address::GetAny(), udp_port));
ApplicationContainer udp_sink_app = udp_sink.Install(nodes.Get(5));
ApplicationContainer udp_sink_app = udp_sink.Install(nodes.Get(4));
udp_sink_app.Start(Seconds(0.0));
udp_sink_app.Stop(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
// devices_2_3, getDevice<0, ns3::PointToPointNetDevice>(devices_2_4));
// setAlternateTarget<1>(
// devices_2_3, getDevice<1, ns3::PointToPointNetDevice>(devices_4_3));
// setAlternateTarget<0>(devices01, getDevice<0>(devices02));
// setAlternateTarget<0>(devices02, getDevice<0>(devices01));
// CalculateExpectedPackets(10000, DataRate("1Mbps"));

p2p_traffic.EnablePcapAll(dir);
p2p_congestion.EnablePcapAll(dir);
Expand Down
Loading

0 comments on commit 000a626

Please sign in to comment.