-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeachPacket.cc
90 lines (76 loc) · 2.31 KB
/
LeachPacket.cc
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
#include "LeachPacket.h"
#include "ns3/address-utils.h"
#include "ns3/packet.h"
#include "ns3/vector.h"
namespace ns3 {
namespace leach {
NS_OBJECT_ENSURE_REGISTERED(LeachHeader);
#if 1
//LeachHeader::LeachHeader (BooleanValue PIR, Vector position, Vector acceleration, Ipv4Address address, Time m)
LeachHeader::LeachHeader (BooleanValue PIR, Vector position, Vector acceleration, Ipv4Address address, Time m) :
m_PIR (PIR),
m_position (position),
m_acceleration (acceleration),
m_address (address),
m_deadline (m)
{
}
#endif
LeachHeader::~LeachHeader ()
{
}
TypeId
LeachHeader::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::leach::LeachHeader")
.SetParent<Header> ()
.SetGroupName("Leach")
.AddConstructor<LeachHeader>();
return tid;
}
TypeId
LeachHeader::GetInstanceTypeId () const
{
return GetTypeId ();
}
uint32_t
LeachHeader::GetSerializedSize () const
{
return sizeof(m_PIR)+sizeof(m_position)+sizeof(m_acceleration)+sizeof(m_address)+sizeof(m_deadline);
}
void
LeachHeader::Serialize (Buffer::Iterator i) const
{
i.Write ((const uint8_t*)&m_PIR, sizeof(m_PIR));
i.Write ((const uint8_t*)&m_acceleration, sizeof(m_acceleration));
i.Write ((const uint8_t*)&m_position, sizeof(m_position));
i.Write ((const uint8_t*)&m_address, sizeof(m_address));
i.Write ((const uint8_t*)&m_address+4, sizeof(m_address));
i.Write ((const uint8_t*)&m_deadline, sizeof(m_deadline));
}
uint32_t
LeachHeader::Deserialize (Buffer::Iterator start)
{
Buffer::Iterator i = start;
i.Read ((uint8_t*)&m_PIR, sizeof(m_PIR));
i.Read ((uint8_t*)&m_position, sizeof(m_position));
i.Read ((uint8_t*)&m_acceleration, sizeof(m_acceleration));
i.Read ((uint8_t*)&m_address, sizeof(m_address));
i.ReadU32();
i.Read ((uint8_t*)&m_deadline, sizeof(m_deadline));
uint32_t dist = i.GetDistanceFrom(start);
NS_ASSERT (dist == GetSerializedSize());
return dist;
}
void
LeachHeader::Print(std::ostream &os) const
{
os << " PIR: " << m_PIR
<< " Position: " << m_position
<< " Acceleration: " << m_acceleration
<< ", IP: " << m_address
<< ", Deadline:" << m_deadline
<< "\n";
}
} /* namespace leach */
} /* namespace ns3 */