Skip to content

Commit

Permalink
Merge branch 'congestion-framework' into addBasicCongestionPolicy
Browse files Browse the repository at this point in the history
  • Loading branch information
YousefEZ authored Mar 9, 2024
2 parents e674c43 + e61f7e1 commit 5004e64
Show file tree
Hide file tree
Showing 11 changed files with 1,853 additions and 1,784 deletions.
2 changes: 2 additions & 0 deletions format.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#!/bin/bash

find . -regex '.*\.\(cpp\|hpp\|cc\|cxx\|h\)' -exec clang-format -style=file -i {} \;
2 changes: 0 additions & 2 deletions libs/dummy_congestion_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ class DummyCongestionPolicy
static bool isCongested(ns3::Queue<ns3::Packet>* queue);
};


bool DummyCongestionPolicy::isCongested(ns3::Queue<ns3::Packet>* queue)
{
// Placeholder for congestion detection
return false;
}


} // namespace ns3

#endif
95 changes: 48 additions & 47 deletions libs/frr_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,45 @@ namespace ns3
template <typename CONGESTION_POLICY, typename FRR_POLICY>
class FRRQueue : public Queue<Packet>
{
private:

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

NS_LOG_TEMPLATE_DECLARE;


void ForwardToAlternateTarget(Ptr<Packet> packet);
static std::string makeQueueString();

protected:
virtual bool Enqueue(Ptr<Packet> p) override;
virtual bool Enqueue(Ptr<Packet> p) override;
virtual Ptr<Packet> Dequeue() override;
virtual Ptr<Packet> Remove(void) override;
virtual Ptr<const Packet> Peek() const override;

public:

FRR_POLICY m_frrPolicy;
CONGESTION_POLICY m_congestionPolicy;

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

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

static const std::string& getQueueString();
};


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


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



template <typename CONGESTION_POLICY, typename FRR_POLICY>
bool FRRQueue<CONGESTION_POLICY, FRR_POLICY>::Enqueue(Ptr<Packet> packet)
{
Expand All @@ -96,79 +91,85 @@ bool FRRQueue<CONGESTION_POLICY, FRR_POLICY>::Enqueue(Ptr<Packet> packet)
NS_LOG_LOGIC("Congested Route, Rerouting packet: " << packet);
ForwardToAlternateTarget(packet);
NS_LOG_LOGIC("Rerouting complete");
return false;
return false;
}
NS_LOG_LOGIC("Enqueued " << packet << " to " << GetContainer().size() << " packets in queue.");
NS_LOG_LOGIC("Enqueued " << packet << " to " << GetContainer().size()
<< " packets in queue.");
DoEnqueue(GetContainer().end(), packet);
return true;
}

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

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

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

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

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

NS_LOG_LOGIC("Removed " << packet);

return packet;
}

template <typename CONGESTION_POLICY, typename FRR_POLICY>
Ptr<const Packet> FRRQueue<CONGESTION_POLICY, FRR_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)
void FRRQueue<CONGESTION_POLICY, FRR_POLICY>::ForwardToAlternateTarget(
Ptr<Packet> packet)
{
auto alternativeTarget = m_frrPolicy.selectAlternativeTarget();
alternativeTarget->Send(packet, alternativeTarget->GetAddress(), 0x0800);
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)
void FRRQueue<CONGESTION_POLICY, FRR_POLICY>::addAlternateTargets(
DEVICES&&... devices)
{
m_frrPolicy.addAlternateTargets(std::forward<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, FRR_POLICY>;
int status;
char* demangled = abi::__cxa_demangle(STRINGIFY_TYPE_ALIAS(QueueType), nullptr, nullptr, &status);
std::string result = (status == 0 && demangled != nullptr) ? demangled : STRINGIFY_TYPE_ALIAS(QueueType);
free(demangled);
char* demangled = abi::__cxa_demangle(STRINGIFY_TYPE_ALIAS(QueueType),
nullptr, nullptr, &status);
std::string result = (status == 0 && demangled != nullptr)
? demangled
: STRINGIFY_TYPE_ALIAS(QueueType);
free(demangled);
return result;
}

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

NS_LOG_COMPONENT_DEFINE("FRRQueue");

} // namespace ns3

#endif
#endif
19 changes: 8 additions & 11 deletions libs/lfa_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,32 @@ namespace ns3

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

public:
LFAPolicy() = default;

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

ns3::Ptr<ns3::PointToPointNetDevice> selectAlternativeTarget();
};


template <typename... DEVICES>
void LFAPolicy::addAlternateTargets(DEVICES&&... devices)
{
(m_alternateTargets.push_back(std::forward<DEVICES>(devices)), ...);
(m_alternateTargets.push_back(std::forward<DEVICES>(devices)), ...);
}

ns3::Ptr<ns3::PointToPointNetDevice> LFAPolicy::selectAlternativeTarget()
{
if (m_alternateTargets.empty())
{
return nullptr;
}
return m_alternateTargets.front();
if (m_alternateTargets.empty()) {
return nullptr;
}
return m_alternateTargets.front();
}


} // namespace ns3

#endif
13 changes: 4 additions & 9 deletions libs/modulo_congestion_policy.h
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
#ifndef MODULO_CONGESTION_POLICY_H
#define MODULO_CONGESTION_POLICY_H



template <int MODULO>
class ModuloCongestionPolicy
{

private:
int counter;
int counter;

public:

bool isCongested(ns3::Queue<ns3::Packet>* queue)
{
increment();
return counter;
increment();
return counter;
}


void increment()
{
counter = (counter + 1) % MODULO;
counter = (counter + 1) % MODULO;
}

};


#endif
Loading

0 comments on commit 5004e64

Please sign in to comment.