A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
26 namespace ns3 {
27 
29  : m_addr (Ipv4Address ()),
30  m_spec_dst (Ipv4Address ()),
31  m_ifindex (0),
32  m_ttl (0)
33 {
34 }
35 
36 void
38 {
39  m_addr = addr;
40 }
41 
44 {
45  return m_addr;
46 }
47 
48 void
50 {
51  m_spec_dst = addr;
52 }
53 
56 {
57  return m_spec_dst;
58 }
59 
60 void
61 Ipv4PacketInfoTag::SetRecvIf (uint32_t ifindex)
62 {
63  m_ifindex = ifindex;
64 }
65 
66 uint32_t
68 {
69  return m_ifindex;
70 }
71 
72 void
74 {
75  m_ttl = ttl;
76 }
77 
78 uint8_t
80 {
81  return m_ttl;
82 }
83 
84 
85 
86 TypeId
88 {
89  static TypeId tid = TypeId ("ns3::Ipv4PacketInfoTag")
90  .SetParent<Tag> ()
91  .AddConstructor<Ipv4PacketInfoTag> ()
92  ;
93  return tid;
94 }
95 TypeId
97 {
98  return GetTypeId ();
99 }
100 
101 uint32_t
103 {
104  return 4 + 4
105  + sizeof (uint32_t)
106  + sizeof (uint8_t);
107 }
108 void
110 {
111  uint8_t buf[4];
112  m_addr.Serialize (buf);
113  i.Write (buf, 4);
114  m_spec_dst.Serialize (buf);
115  i.Write (buf, 4);
116  i.WriteU32 (m_ifindex);
117  i.WriteU8 (m_ttl);
118 }
119 void
121 {
122  uint8_t buf[4];
123  i.Read (buf, 4);
125  i.Read (buf, 4);
127  m_ifindex = i.ReadU32 ();
128  m_ttl = i.ReadU8 ();
129 }
130 void
131 Ipv4PacketInfoTag::Print (std::ostream &os) const
132 {
133  os << "Ipv4 PKTINFO [DestAddr: " << m_addr;
134  os << ", Local Address:" << m_spec_dst;
135  os << ", RecvIf:" << (uint32_t) m_ifindex;
136  os << ", TTL:" << (uint32_t) m_ttl;
137  os << "] ";
138 }
139 } // namespace ns3
140