Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper topology with both TCP and UDP apps sending packets. #7

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f6bdac0
Congestion simulation with sockets, not clear if tracing correctly. N…
charliebarber Mar 4, 2024
e53b180
Merge branch 'main' into congestion-framework
charliebarber Mar 5, 2024
c9dd4c4
UDP setup on basic_congestion
charliebarber Mar 6, 2024
9bd1391
:sparkles: add basic congestion policy
YousefEZ Mar 9, 2024
2056fe7
:bug: fix the congestion policy checking
YousefEZ Mar 9, 2024
ff3dc05
:sparkles: add basic_congestion policy
YousefEZ Mar 9, 2024
e674c43
Merge branch 'main' of github.com:YousefEZ/CongestionFRR into addBasi…
YousefEZ Mar 9, 2024
201ca0a
:construction: WIP on basic congestion
YousefEZ Mar 9, 2024
250ec53
Merge branch 'main' into congestion-framework
YousefEZ Mar 9, 2024
0528da7
Simple changed + format
charliebarber Mar 9, 2024
e61f7e1
:art: format files
YousefEZ Mar 9, 2024
5004e64
Merge branch 'congestion-framework' into addBasicCongestionPolicy
YousefEZ Mar 9, 2024
217f4e6
:twisted_rightwards_arrows: merge with origin branch
YousefEZ Mar 9, 2024
8e1b61f
:art: format files
YousefEZ Mar 9, 2024
8e49833
:twisted_rightwards_arrow: resolve merge
YousefEZ Mar 11, 2024
ddeeca5
Full topology combining both UDP and TCP traffic in combined.cc
charliebarber Mar 12, 2024
c25fcdd
Combined setup, need help with alternate routes and also deref zero p…
charliebarber Mar 12, 2024
a14e4ef
:loud_sound: added more logging
YousefEZ Mar 12, 2024
12b0d68
:test_tube: testing
YousefEZ Mar 12, 2024
15afa1b
:art: format files
YousefEZ Mar 12, 2024
cd36531
Merge branch 'testingRerouting' into congestion-framework
charliebarber Mar 12, 2024
9beeb62
Pcaps enabled
charliebarber Mar 12, 2024
bed7a0d
Pcaps enabled.
charliebarber Mar 12, 2024
0385b42
:construction: wip
YousefEZ Mar 12, 2024
46cbe11
:construction: wip
YousefEZ Mar 12, 2024
05ed7e0
:sparkles: change the protocol number to 4
YousefEZ Mar 12, 2024
ba93070
:bug: fix the frr queue
YousefEZ Mar 12, 2024
4118192
:sparkles: add queue base to upcast templated queue
YousefEZ Mar 14, 2024
f17d320
:sparkles: reconfigure the frr queue to handle only congestion
YousefEZ Mar 14, 2024
29792f7
:sparkles: add custom point to point net device for frr
YousefEZ Mar 14, 2024
fe3ea44
:sparkles: add custom p2p helper for point-to-point frr net device
YousefEZ Mar 14, 2024
b68b109
:recycle: update policies to match changes
YousefEZ Mar 14, 2024
c15b511
:recycle: update scripts to reflect the changes
YousefEZ Mar 14, 2024
3586c29
:wastebasket: remove old code
YousefEZ Mar 14, 2024
7de17db
Replaced reserved DISCARD port 9 with 50000
charliebarber Mar 14, 2024
d33eff8
Merge branch 'addCustomNetDevice' into congestion-framework
charliebarber Mar 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions libs/basic_congestion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef BASIC_CONGESTION_POLICY_H
#define BASIC_CONGESTION_POLICY_H

namespace ns3
{

template <int MAX_USAGE_PERCENTAGE>
class BasicCongestionPolicy
{
static_assert(MAX_USAGE_PERCENTAGE >= 0 && MAX_USAGE_PERCENTAGE <= 100,
"MAX_USAGE_PERCENTAGE must be between 1 and 100");

public:
static bool isCongested(ns3::Queue<ns3::Packet>* queue);
};

template <>
bool BasicCongestionPolicy<0>::isCongested(ns3::Queue<ns3::Packet>* queue)
{
return true;
}

template <>
bool BasicCongestionPolicy<100>::isCongested(ns3::Queue<ns3::Packet>* queue)
{
return queue->GetNPackets() >= queue->GetMaxSize().GetValue();
}

template <int MAX_USAGE_PERCENTAGE>
bool BasicCongestionPolicy<MAX_USAGE_PERCENTAGE>::isCongested(
ns3::Queue<ns3::Packet>* queue)
{
return queue->GetNPackets() * 100 >=
queue->GetMaxSize().GetValue() * MAX_USAGE_PERCENTAGE;
}

} // namespace ns3

#endif
118 changes: 47 additions & 71 deletions libs/frr_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,30 @@
#include <utility>

#include <typeinfo>
#include <cxxabi.h> // For __cxa_demangle
#include <cxxabi.h>

#include "point_to_point_frr_net_device.h"
#include "ns3/object-base.h"
#include "ns3/queue.h"
#include "ns3/packet.h"
#include "ns3/point-to-point-net-device.h"
#include <ns3/boolean.h>
#include "frr_queue_base.h"

#define STRINGIFY_TYPE_ALIAS(alias) typeid(alias).name()

namespace ns3
{

template <typename CONGESTION_POLICY, typename FRR_POLICY>
class FRRQueue : public Queue<Packet>
template <typename CONGESTION_POLICY>
class FRRQueue : public FRRQueueBase
{
public:
int m_uid;

private:
using Queue<Packet>::GetContainer;
using Queue<Packet>::DoEnqueue;
using Queue<Packet>::DoDequeue;
using Queue<Packet>::DoRemove;
using Queue<Packet>::DoPeek;
using FRRQueueBase::DoDequeue;
using FRRQueueBase::DoEnqueue;
using FRRQueueBase::DoPeek;
using FRRQueueBase::DoRemove;
using FRRQueueBase::GetContainer;

NS_LOG_TEMPLATE_DECLARE;

Expand All @@ -40,40 +42,42 @@ class FRRQueue : public Queue<Packet>
virtual Ptr<const Packet> Peek() const override;

public:
FRR_POLICY m_frrPolicy;
static int s_uid;
CONGESTION_POLICY m_congestionPolicy;

static TypeId GetTypeId();
FRRQueue();
~FRRQueue();

template <typename... DEVICES>
void addAlternateTargets(DEVICES&&... devices);
virtual ~FRRQueue() = default;

virtual bool isCongested() override;
static const std::string& getQueueString();
static Mac48Address sinkAddress;
};

template <typename CONGESTION_POLICY, typename FRR_POLICY>
FRRQueue<CONGESTION_POLICY, FRR_POLICY>::FRRQueue()
: Queue<Packet>(), NS_LOG_TEMPLATE_DEFINE("FRRQueue")
template <typename CONGESTION_POLICY>
bool FRRQueue<CONGESTION_POLICY>::isCongested()
{
NS_LOG_FUNCTION(this);
return m_congestionPolicy.isCongested(this);
}

template <typename CONGESTION_POLICY, typename FRR_POLICY>
FRRQueue<CONGESTION_POLICY, FRR_POLICY>::~FRRQueue()
template <typename CONGESTION_POLICY>
int FRRQueue<CONGESTION_POLICY>::s_uid = 0;

template <typename CONGESTION_POLICY>
FRRQueue<CONGESTION_POLICY>::FRRQueue()
: FRRQueueBase(), m_uid(s_uid++), NS_LOG_TEMPLATE_DEFINE("FRRQueue")
{
NS_LOG_FUNCTION(this);
}

template <typename CONGESTION_POLICY, typename FRR_POLICY>
TypeId FRRQueue<CONGESTION_POLICY, FRR_POLICY>::GetTypeId()
template <typename CONGESTION_POLICY>
TypeId FRRQueue<CONGESTION_POLICY>::GetTypeId()
{
static TypeId tid =
TypeId(getQueueString())
.SetParent<Queue<Packet>>()
.SetGroupName("Network")
.template AddConstructor<FRRQueue<CONGESTION_POLICY, FRR_POLICY>>()
.template AddConstructor<FRRQueue<CONGESTION_POLICY>>()
.AddAttribute("MaxSize", "The max queue size",
QueueSizeValue(QueueSize("100p")),
MakeQueueSizeAccessor(&QueueBase::SetMaxSize,
Expand All @@ -82,35 +86,25 @@ TypeId FRRQueue<CONGESTION_POLICY, FRR_POLICY>::GetTypeId()
return tid;
}

template <typename CONGESTION_POLICY, typename FRR_POLICY>
bool FRRQueue<CONGESTION_POLICY, FRR_POLICY>::Enqueue(Ptr<Packet> packet)
template <typename CONGESTION_POLICY>
bool FRRQueue<CONGESTION_POLICY>::Enqueue(Ptr<Packet> packet)
{
NS_LOG_FUNCTION(this << packet);
if (m_congestionPolicy.isCongested(GetContainer())) {
NS_LOG_LOGIC("Congested Route, Rerouting packet: " << packet);
ForwardToAlternateTarget(packet);
NS_LOG_LOGIC("Rerouting complete");
return false;
}
NS_LOG_LOGIC("Enqueued " << packet << " to " << GetContainer().size()
<< " packets in queue.");
DoEnqueue(GetContainer().end(), packet);
return true;
NS_LOG_LOGIC("(" << m_uid << ") Enqueuing: " << packet);
return DoEnqueue(GetContainer().end(), packet);
}

template <typename CONGESTION_POLICY, typename FRR_POLICY>
Ptr<Packet> FRRQueue<CONGESTION_POLICY, FRR_POLICY>::Dequeue()
template <typename CONGESTION_POLICY>
Ptr<Packet> FRRQueue<CONGESTION_POLICY>::Dequeue()
{
NS_LOG_FUNCTION(this);
// NS_LOG_FUNCTION(this);

Ptr<Packet> packet = DoDequeue(GetContainer().begin());

NS_LOG_LOGIC("Popped " << packet);
NS_LOG_LOGIC("(" << m_uid << ") Popped " << packet);
return packet;
}

template <typename CONGESTION_POLICY, typename FRR_POLICY>
Ptr<Packet> FRRQueue<CONGESTION_POLICY, FRR_POLICY>::Remove()
template <typename CONGESTION_POLICY>
Ptr<Packet> FRRQueue<CONGESTION_POLICY>::Remove()
{
NS_LOG_FUNCTION(this);

Expand All @@ -121,34 +115,18 @@ Ptr<Packet> FRRQueue<CONGESTION_POLICY, FRR_POLICY>::Remove()
return packet;
}

template <typename CONGESTION_POLICY, typename FRR_POLICY>
Ptr<const Packet> FRRQueue<CONGESTION_POLICY, FRR_POLICY>::Peek() const
template <typename CONGESTION_POLICY>
Ptr<const Packet> FRRQueue<CONGESTION_POLICY>::Peek() const
{
NS_LOG_FUNCTION(this);

return DoPeek(GetContainer().begin());
}

template <typename CONGESTION_POLICY, typename FRR_POLICY>
void FRRQueue<CONGESTION_POLICY, FRR_POLICY>::ForwardToAlternateTarget(
Ptr<Packet> packet)
template <typename CONGESTION_POLICY>
std::string FRRQueue<CONGESTION_POLICY>::makeQueueString()
{
auto alternativeTarget = m_frrPolicy.selectAlternativeTarget();
alternativeTarget->Send(packet, alternativeTarget->GetAddress(), 0x0800);
}

template <typename CONGESTION_POLICY, typename FRR_POLICY>
template <typename... DEVICES>
void FRRQueue<CONGESTION_POLICY, FRR_POLICY>::addAlternateTargets(
DEVICES&&... devices)
{
m_frrPolicy.addAlternateTargets(std::forward<DEVICES>(devices)...);
}

template <typename CONGESTION_POLICY, typename FRR_POLICY>
std::string FRRQueue<CONGESTION_POLICY, FRR_POLICY>::makeQueueString()
{
using QueueType = FRRQueue<CONGESTION_POLICY, FRR_POLICY>;
using QueueType = FRRQueue<CONGESTION_POLICY>;
int status;
char* demangled = abi::__cxa_demangle(STRINGIFY_TYPE_ALIAS(QueueType),
nullptr, nullptr, &status);
Expand All @@ -159,16 +137,14 @@ std::string FRRQueue<CONGESTION_POLICY, FRR_POLICY>::makeQueueString()
return result;
}

template <typename CONGESTION_POLICY, typename FRR_POLICY>
const std::string& FRRQueue<CONGESTION_POLICY, FRR_POLICY>::getQueueString()
template <typename CONGESTION_POLICY>
const std::string& FRRQueue<CONGESTION_POLICY>::getQueueString()
{
const static std::string result =
FRRQueue<CONGESTION_POLICY, FRR_POLICY>::makeQueueString();
FRRQueue<CONGESTION_POLICY>::makeQueueString();
return result;
}

NS_LOG_COMPONENT_DEFINE("FRRQueue");

} // namespace ns3

#endif
28 changes: 28 additions & 0 deletions libs/frr_queue_base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef FRR_QUEUE_BASE_H
#define FRR_QUEUE_BASE_H

#include "ns3/queue.h"
#include "ns3/packet.h"

namespace ns3
{

class FRRQueueBase : public Queue<Packet>
{
protected:
using Queue<Packet>::GetContainer;
using Queue<Packet>::DoEnqueue;
using Queue<Packet>::DoDequeue;
using Queue<Packet>::DoRemove;
using Queue<Packet>::DoPeek;

public:
FRRQueueBase() = default;
virtual ~FRRQueueBase() = default;

virtual bool isCongested() = 0;
};

} // namespace ns3

#endif
22 changes: 15 additions & 7 deletions libs/lfa_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,27 @@

#include "ns3/queue.h"
#include "ns3/packet.h"
#include "ns3/point-to-point-net-device.h"
#include "point_to_point_frr_net_device.h"

namespace ns3
{

class LFAPolicy;

class LFAPolicy
{
private:
std::list<ns3::Ptr<ns3::PointToPointNetDevice>> m_alternateTargets;
std::list<ns3::Ptr<ns3::PointToPointFRRNetDevice<LFAPolicy>>>
m_alternateTargets;

public:
LFAPolicy() = default;

template <typename... DEVICES>
void addAlternateTargets(DEVICES&&... devices);

ns3::Ptr<ns3::PointToPointNetDevice> selectAlternativeTarget();
bool reroute(Ptr<Packet> packet, const Address& dest,
uint16_t protocolNumber);
};

template <typename... DEVICES>
Expand All @@ -31,12 +35,16 @@ void LFAPolicy::addAlternateTargets(DEVICES&&... devices)
(m_alternateTargets.push_back(std::forward<DEVICES>(devices)), ...);
}

ns3::Ptr<ns3::PointToPointNetDevice> LFAPolicy::selectAlternativeTarget()
bool LFAPolicy::reroute(Ptr<Packet> packet, const Address& dest,
uint16_t protocolNumber)
{
if (m_alternateTargets.empty()) {
return nullptr;
for (auto& target : m_alternateTargets) {
if (!target->isCongested()) {
target->Send(packet, dest, protocolNumber);
return true;
}
}
return m_alternateTargets.front();
return false;
}

} // namespace ns3
Expand Down
3 changes: 1 addition & 2 deletions libs/modulo_congestion_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ class ModuloCongestionPolicy
int counter;

public:
template <typename CONTAINER>
bool isCongested(const CONTAINER& container)
bool isCongested(ns3::Queue<ns3::Packet>* queue)
{
increment();
return counter;
Expand Down
Loading
Loading