A Discrete-Event Network Simulator
API
ipv4-packet-info-tag.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2010 Hajime Tazaki
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Authors: Hajime Tazaki <tazaki@sfc.wide.ad.jp>
19  */
20 
21 
22 #include <stdint.h>
23 #include "ns3/ipv4-address.h"
24 #include "ipv4-packet-info-tag.h"
25 #include "ns3/log.h"
26 
27 namespace ns3 {
28 
29 NS_LOG_COMPONENT_DEFINE ("Ipv4PacketInfoTag");
30 
32  : m_addr (Ipv4Address ()),
33  m_ifindex (0),
34  m_ttl (0)
35 {
36  NS_LOG_FUNCTION (this);
37 }
38 
39 void
41 {
42  NS_LOG_FUNCTION (this << addr);
43  m_addr = addr;
44 }
45 
48 {
49  NS_LOG_FUNCTION (this);
50  return m_addr;
51 }
52 
53 void
54 Ipv4PacketInfoTag::SetRecvIf (uint32_t ifindex)
55 {
56  NS_LOG_FUNCTION (this << ifindex);
57  m_ifindex = ifindex;
58 }
59 
60 uint32_t
62 {
63  NS_LOG_FUNCTION (this);
64  return m_ifindex;
65 }
66 
67 void
69 {
70  NS_LOG_FUNCTION (this << static_cast<uint32_t> (ttl));
71  m_ttl = ttl;
72 }
73 
74 uint8_t
76 {
77  NS_LOG_FUNCTION (this);
78  return m_ttl;
79 }
80 
81 
82 
83 TypeId
85 {
86  static TypeId tid = TypeId ("ns3::Ipv4PacketInfoTag")
87  .SetParent<Tag> ()
88  .SetGroupName ("Internet")
89  .AddConstructor<Ipv4PacketInfoTag> ()
90  ;
91  return tid;
92 }
93 TypeId
95 {
96  NS_LOG_FUNCTION (this);
97  return GetTypeId ();
98 }
99 
100 uint32_t
102 {
103  NS_LOG_FUNCTION (this);
104  return 4 + sizeof (uint32_t) + sizeof (uint8_t);
105 }
106 void
108 {
109  NS_LOG_FUNCTION (this << &i);
110  uint8_t buf[4];
111  m_addr.Serialize (buf);
112  i.Write (buf, 4);
113  i.WriteU32 (m_ifindex);
114  i.WriteU8 (m_ttl);
115 }
116 void
118 {
119  NS_LOG_FUNCTION (this<< &i);
120  uint8_t buf[4];
121  i.Read (buf, 4);
123  m_ifindex = i.ReadU32 ();
124  m_ttl = i.ReadU8 ();
125 }
126 void
127 Ipv4PacketInfoTag::Print (std::ostream &os) const
128 {
129  NS_LOG_FUNCTION (this << &os);
130  os << "Ipv4 PKTINFO [DestAddr: " << m_addr;
131  os << ", RecvIf:" << (uint32_t) m_ifindex;
132  os << ", TTL:" << (uint32_t) m_ttl;
133  os << "] ";
134 }
135 } // namespace ns3
136 
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
void Serialize(uint8_t buf[4]) const
Serialize this address to a 4-byte buffer.
static Ipv4Address Deserialize(const uint8_t buf[4])
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
uint8_t m_ttl
Time to Live.
void SetRecvIf(uint32_t ifindex)
Set the tag's receiving interface.
virtual void Print(std::ostream &os) const
uint8_t GetTtl(void) const
Get the tag's Time to Live Implemented, but not used in the stack yet.
Ipv4Address GetAddress(void) const
Get the tag's address.
uint32_t GetRecvIf(void) const
Get the tag's receiving interface.
void SetAddress(Ipv4Address addr)
Set the tag's address.
Ipv4Address m_addr
Header destination address.
void SetTtl(uint8_t ttl)
Set the tag's Time to Live Implemented, but not used in the stack yet.
virtual void Deserialize(TagBuffer i)
uint32_t m_ifindex
interface index
static TypeId GetTypeId(void)
Get the type ID.
virtual void Serialize(TagBuffer i) const
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
virtual uint32_t GetSerializedSize(void) const
read and write tag data
Definition: tag-buffer.h:52
void Read(uint8_t *buffer, uint32_t size)
Definition: tag-buffer.cc:176
TAG_BUFFER_INLINE uint32_t ReadU32(void)
Definition: tag-buffer.h:215
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
Definition: tag-buffer.h:172
TAG_BUFFER_INLINE void WriteU32(uint32_t v)
Definition: tag-buffer.h:186
void Write(const uint8_t *buffer, uint32_t size)
Definition: tag-buffer.cc:125
TAG_BUFFER_INLINE uint8_t ReadU8(void)
Definition: tag-buffer.h:195
tag a set of bytes in a packet
Definition: tag.h:37
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.