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_spec_dst (Ipv4Address ()),
34  m_ifindex (0),
35  m_ttl (0)
36 {
37  NS_LOG_FUNCTION (this);
38 }
39 
40 void
42 {
43  NS_LOG_FUNCTION (this << addr);
44  m_addr = addr;
45 }
46 
49 {
50  NS_LOG_FUNCTION (this);
51  return m_addr;
52 }
53 
54 void
56 {
57  NS_LOG_FUNCTION (this << addr);
58  m_spec_dst = addr;
59 }
60 
63 {
64  NS_LOG_FUNCTION (this);
65  return m_spec_dst;
66 }
67 
68 void
69 Ipv4PacketInfoTag::SetRecvIf (uint32_t ifindex)
70 {
71  NS_LOG_FUNCTION (this << ifindex);
72  m_ifindex = ifindex;
73 }
74 
75 uint32_t
77 {
78  NS_LOG_FUNCTION (this);
79  return m_ifindex;
80 }
81 
82 void
84 {
85  NS_LOG_FUNCTION (this << static_cast<uint32_t> (ttl));
86  m_ttl = ttl;
87 }
88 
89 uint8_t
91 {
92  NS_LOG_FUNCTION (this);
93  return m_ttl;
94 }
95 
96 
97 
98 TypeId
100 {
101  static TypeId tid = TypeId ("ns3::Ipv4PacketInfoTag")
102  .SetParent<Tag> ()
103  .SetGroupName ("Internet")
104  .AddConstructor<Ipv4PacketInfoTag> ()
105  ;
106  return tid;
107 }
108 TypeId
110 {
111  NS_LOG_FUNCTION (this);
112  return GetTypeId ();
113 }
114 
115 uint32_t
117 {
118  NS_LOG_FUNCTION (this);
119  return 4 + 4
120  + sizeof (uint32_t)
121  + sizeof (uint8_t);
122 }
123 void
125 {
126  NS_LOG_FUNCTION (this << &i);
127  uint8_t buf[4];
128  m_addr.Serialize (buf);
129  i.Write (buf, 4);
130  m_spec_dst.Serialize (buf);
131  i.Write (buf, 4);
132  i.WriteU32 (m_ifindex);
133  i.WriteU8 (m_ttl);
134 }
135 void
137 {
138  NS_LOG_FUNCTION (this<< &i);
139  uint8_t buf[4];
140  i.Read (buf, 4);
142  i.Read (buf, 4);
144  m_ifindex = i.ReadU32 ();
145  m_ttl = i.ReadU8 ();
146 }
147 void
148 Ipv4PacketInfoTag::Print (std::ostream &os) const
149 {
150  NS_LOG_FUNCTION (this << &os);
151  os << "Ipv4 PKTINFO [DestAddr: " << m_addr;
152  os << ", Local Address:" << m_spec_dst;
153  os << ", RecvIf:" << (uint32_t) m_ifindex;
154  os << ", TTL:" << (uint32_t) m_ttl;
155  os << "] ";
156 }
157 } // namespace ns3
158 
static Ipv4Address Deserialize(const uint8_t buf[4])
void Write(const uint8_t *buffer, uint32_t size)
Definition: tag-buffer.cc:125
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint32_t GetRecvIf(void) const
Get the tag&#39;s receiving interface.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
TAG_BUFFER_INLINE uint32_t ReadU32(void)
Definition: tag-buffer.h:215
Ipv4Address m_addr
Header destination address.
TAG_BUFFER_INLINE uint8_t ReadU8(void)
Definition: tag-buffer.h:195
uint32_t m_ifindex
interface index
virtual void Serialize(TagBuffer i) const
void SetTtl(uint8_t ttl)
Set the tag&#39;s Time to Live Implemented, but not used in the stack yet.
Ipv4Address GetAddress(void) const
Get the tag&#39;s address.
Ipv4Address m_spec_dst
Local address.
virtual void Print(std::ostream &os) const
TAG_BUFFER_INLINE void WriteU32(uint32_t v)
Definition: tag-buffer.h:186
uint8_t GetTtl(void) const
Get the tag&#39;s Time to Live Implemented, but not used in the stack yet.
tag a set of bytes in a packet
Definition: tag.h:36
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TypeId GetTypeId(void)
Get the type ID.
uint8_t m_ttl
Time to Live.
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
Definition: tag-buffer.h:172
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
read and write tag data
Definition: tag-buffer.h:51
virtual void Deserialize(TagBuffer i)
virtual uint32_t GetSerializedSize(void) const
void SetLocalAddress(Ipv4Address addr)
Set the tag&#39;s local address.
void Read(uint8_t *buffer, uint32_t size)
Definition: tag-buffer.cc:176
void SetAddress(Ipv4Address addr)
Set the tag&#39;s address.
Ipv4Address GetLocalAddress(void) const
Get the tag&#39;s local address.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
void Serialize(uint8_t buf[4]) const
Serialize this address to a 4-byte buffer.
void SetRecvIf(uint32_t ifindex)
Set the tag&#39;s receiving interface.