-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleach-routing-queue.cc
More file actions
92 lines (80 loc) · 1.87 KB
/
leach-routing-queue.cc
File metadata and controls
92 lines (80 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <algorithm>
#include <bits/stdint-uintn.h>
#include <functional>
#include <vector>
#include "leach-routing-queue.h"
#include "ns3/ipv4-route.h"
#include "ns3/log-macros-disabled.h"
#include "ns3/socket.h"
#include "ns3/log.h"
namespace ns3 {
NS_LOG_COMPONENT_DEFINE("LeachPacketQueue");
namespace leach {
uint32_t
PacketQueue::GetSize()
{
return m_queue.size();
}
bool
PacketQueue::Enqueue(QueueEntry &entry)
{
try
{
NS_LOG_FUNCTION("Enqueing packet destined for " << entry.GetIpv4Header().GetDestination());
m_queue.push_back(entry);
return true;
}
catch(...)
{
NS_LOG_ERROR("ERROR: Enqueing packet destined for " << entry.GetIpv4Header().GetDestination());
return false;
}
}
void
PacketQueue::Drop(uint32_t idx)
{
m_queue.erase(m_queue.begin()+idx);
}
bool
PacketQueue::Dequeue(Ipv4Address dst, QueueEntry &entry)
{
NS_LOG_FUNCTION("Dequeueing packet destined for " << dst);
for (std::vector<QueueEntry>::iterator i = m_queue.begin(); i != m_queue.end(); ++i)
{
if (i->GetIpv4Header().GetDestination() == dst)
{
entry = *i;
m_queue.erase(i);
return true;
}
}
return false;
}
bool
PacketQueue::Find(Ipv4Address dst)
{
for (std::vector<QueueEntry>::iterator i = m_queue.begin(); i!= m_queue.end(); ++i)
{
if (i->GetIpv4Header().GetDestination() == dst)
{
NS_LOG_DEBUG("Found");
return true;
}
}
return false;
}
uint32_t
PacketQueue::GetCountForPacketsWithDst(Ipv4Address dst)
{
uint32_t count = 0;
for (std::vector<QueueEntry>::iterator i = m_queue.begin(); i != m_queue.end(); ++i)
{
if (i->GetIpv4Header().GetDestination() == dst)
{
count++;
}
}
return count;
}
} /* namespace leach */
} /* namespace ns3 */