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

🎨 Format all the files #9

Merged
merged 2 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
98 changes: 49 additions & 49 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,102 +69,106 @@ 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)
{
NS_LOG_FUNCTION(this << packet);
if (m_congestionPolicy.isCongested(GetContainer()))
{
if (m_congestionPolicy.isCongested(GetContainer())) {
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
14 changes: 4 additions & 10 deletions libs/modulo_congestion_policy.h
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
#ifndef MODULO_CONGESTION_POLICY_H
#define MODULO_CONGESTION_POLICY_H



template <int MODULO>
class ModuloCongestionPolicy
{

private:
int counter;
int counter;

public:

template <typename CONTAINER>
bool isCongested(const CONTAINER& container)
{
increment();
return counter;
increment();
return counter;
}


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

};


#endif
Loading
Loading