OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 This software was developed at the National Institute of Standards and |
| 4 Technology by employees of the Federal Government in the course of |
| 5 their official duties. Pursuant to titleElement 17 Section 105 of the United |
| 6 States Code this software is not subject to copyright protection and |
| 7 is in the public domain. |
| 8 NIST assumes no responsibility whatsoever for its use by other parties, |
| 9 and makes no guarantees, expressed or implied, about its quality, |
| 10 reliability, or any other characteristic. |
| 11 |
| 12 We would appreciate acknowledgement if the software is used. |
| 13 |
| 14 NIST ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND |
| 15 DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING |
| 16 FROM THE USE OF THIS SOFTWARE. |
| 17 */ |
| 18 |
| 19 #include <ns3/simulator.h> |
| 20 #include <ns3/log.h> |
| 21 |
| 22 #include "nist-header.h" |
| 23 |
| 24 namespace ns3 { |
| 25 |
| 26 NS_LOG_COMPONENT_DEFINE ("NistHeader"); |
| 27 NS_OBJECT_ENSURE_REGISTERED (NistBriefHeader); |
| 28 NS_OBJECT_ENSURE_REGISTERED (NistHeader); |
| 29 |
| 30 // Initialize static member· |
| 31 uint64_t NistSequenceNumber::s_sequenceNumber = 0; |
| 32 |
| 33 /// NistBriefHeader |
| 34 NistBriefHeader::NistBriefHeader () |
| 35 { |
| 36 m_seqnum = 0; |
| 37 m_sentTime = Simulator::Now (); |
| 38 } |
| 39 |
| 40 NistBriefHeader::~NistBriefHeader () |
| 41 { |
| 42 } |
| 43 |
| 44 TypeId |
| 45 NistBriefHeader::GetTypeId (void)· |
| 46 { |
| 47 static TypeId tid = TypeId ("ns3::NistBriefHeader") |
| 48 .SetParent<Header> () |
| 49 .AddConstructor<NistBriefHeader> () |
| 50 ; |
| 51 return tid; |
| 52 } |
| 53 |
| 54 TypeId |
| 55 NistBriefHeader::GetInstanceTypeId (void) const |
| 56 { |
| 57 return GetTypeId (); |
| 58 } |
| 59 |
| 60 void |
| 61 NistBriefHeader::SetSeqNum (uint64_t seqnum) |
| 62 { |
| 63 m_seqnum = seqnum; |
| 64 } |
| 65 |
| 66 uint64_t |
| 67 NistBriefHeader::GetSeqNum (void) |
| 68 { |
| 69 return m_seqnum; |
| 70 } |
| 71 |
| 72 void· |
| 73 NistBriefHeader::SetSentTime (Time sentTime) |
| 74 { |
| 75 m_sentTime = sentTime; |
| 76 } |
| 77 |
| 78 Time |
| 79 NistBriefHeader::GetSentTime (void) |
| 80 { |
| 81 return m_sentTime; |
| 82 } |
| 83 |
| 84 uint32_t· |
| 85 NistBriefHeader::Deserialize (Buffer::Iterator start)· |
| 86 { |
| 87 Buffer::Iterator i = start; |
| 88 m_seqnum = i.ReadNtohU64 (); |
| 89 m_sentTime = Time (i.ReadNtohU64 ()); |
| 90 |
| 91 return GetSerializedSize (); |
| 92 } |
| 93 |
| 94 uint32_t |
| 95 NistBriefHeader::GetSerializedSize (void) const |
| 96 { |
| 97 return· |
| 98 sizeof (m_seqnum) +· |
| 99 sizeof (m_sentTime); |
| 100 } |
| 101 |
| 102 void· |
| 103 NistBriefHeader::Print (std::ostream &os) const |
| 104 { |
| 105 os << "SeqNum: " << m_seqnum << " TimeSent: " << m_sentTime.GetSeconds (); |
| 106 } |
| 107 |
| 108 void |
| 109 NistBriefHeader::Serialize (Buffer::Iterator start) const |
| 110 { |
| 111 Buffer::Iterator i = start; |
| 112 i.WriteHtonU32 (m_seqnum); |
| 113 i.WriteHtonU64 (m_sentTime.GetNanoSeconds () ); |
| 114 } |
| 115 |
| 116 |
| 117 // Constructors |
| 118 NistHeader::NistHeader () |
| 119 : m_sequenceNumber (0), |
| 120 m_sourceId (0), |
| 121 m_destinationId (0), |
| 122 m_sourcePort (0), |
| 123 m_destinationPort (0), |
| 124 m_streamId (0), |
| 125 m_applicationId (0) |
| 126 { |
| 127 m_sequenceNumber = NistSequenceNumber::GetSequenceNumber(); |
| 128 } |
| 129 NistHeader::~NistHeader () |
| 130 { |
| 131 } |
| 132 |
| 133 // Setters |
| 134 void· |
| 135 NistHeader::SetParameters ( |
| 136 uint32_t sourceId,· |
| 137 uint32_t destinationId,· |
| 138 uint16_t sourcePort,· |
| 139 uint16_t destinationPort,· |
| 140 uint32_t streamId,· |
| 141 uint16_t applicationId |
| 142 ) |
| 143 { |
| 144 SetSourceId(sourceId); |
| 145 SetDestinationId(destinationId); |
| 146 SetSourcePort(sourcePort); |
| 147 SetDestinationPort(destinationPort); |
| 148 SetStreamId(streamId); |
| 149 SetApplicationId(applicationId); |
| 150 } |
| 151 |
| 152 void |
| 153 NistHeader:: SetSourceId (uint32_t id) |
| 154 { |
| 155 m_sourceId = id; |
| 156 } |
| 157 |
| 158 void |
| 159 NistHeader:: SetDestinationId (uint32_t id) |
| 160 { |
| 161 m_destinationId = id; |
| 162 } |
| 163 |
| 164 void· |
| 165 NistHeader::SetSourcePort (uint16_t port) |
| 166 { |
| 167 m_sourcePort = port; |
| 168 } |
| 169 |
| 170 void· |
| 171 NistHeader::SetDestinationPort (uint16_t port) |
| 172 { |
| 173 m_destinationPort = port; |
| 174 } |
| 175 |
| 176 void |
| 177 NistHeader::SetStreamId (uint32_t id) |
| 178 { |
| 179 m_streamId = id; |
| 180 } |
| 181 |
| 182 void |
| 183 NistHeader::SetApplicationId (uint16_t id) |
| 184 { |
| 185 m_applicationId = id; |
| 186 } |
| 187 |
| 188 // Getters |
| 189 uint64_t· |
| 190 NistHeader::GetSequenceNumber (void) const |
| 191 { |
| 192 return m_sequenceNumber; |
| 193 } |
| 194 |
| 195 uint32_t· |
| 196 NistHeader::GetSourceId (void) const |
| 197 { |
| 198 return m_sourceId; |
| 199 } |
| 200 |
| 201 uint32_t· |
| 202 NistHeader::GetDestinationId (void) const |
| 203 { |
| 204 return m_destinationId; |
| 205 } |
| 206 |
| 207 uint16_t· |
| 208 NistHeader::GetSourcePort (void) const |
| 209 { |
| 210 return m_sourcePort; |
| 211 } |
| 212 |
| 213 uint16_t· |
| 214 NistHeader::GetDestinationPort (void) const |
| 215 { |
| 216 return m_destinationPort; |
| 217 } |
| 218 |
| 219 uint32_t |
| 220 NistHeader::GetStreamId (void) const |
| 221 { |
| 222 return m_streamId; |
| 223 } |
| 224 |
| 225 uint16_t |
| 226 NistHeader::GetApplicationId (void) const |
| 227 { |
| 228 return m_applicationId; |
| 229 } |
| 230 |
| 231 // Other functions |
| 232 TypeId· |
| 233 NistHeader::GetTypeId (void) |
| 234 { |
| 235 static TypeId tid = TypeId ("ns3::NistHeader") |
| 236 .SetParent<Header> () |
| 237 .AddConstructor<NistHeader> () |
| 238 ; |
| 239 return tid; |
| 240 } |
| 241 |
| 242 TypeId· |
| 243 NistHeader::GetInstanceTypeId (void) const |
| 244 { |
| 245 return GetTypeId (); |
| 246 } |
| 247 |
| 248 void· |
| 249 NistHeader::Print (std::ostream &os) const |
| 250 { |
| 251 os << m_sequenceNumber << " "· |
| 252 << m_sourceId << " "· |
| 253 << m_destinationId << " " |
| 254 << m_streamId << " " |
| 255 << m_applicationId; |
| 256 } |
| 257 |
| 258 uint32_t· |
| 259 NistHeader::GetSerializedSize (void) const |
| 260 { |
| 261 return· |
| 262 sizeof (m_sequenceNumber) + |
| 263 sizeof (m_sourceId) + |
| 264 sizeof (m_destinationId) + |
| 265 sizeof (m_sourcePort) + |
| 266 sizeof (m_destinationPort) + |
| 267 sizeof (m_streamId) + |
| 268 sizeof (m_applicationId) |
| 269 ; |
| 270 } |
| 271 |
| 272 void |
| 273 NistHeader::Serialize (Buffer::Iterator start) const |
| 274 { |
| 275 Buffer::Iterator i = start; |
| 276 |
| 277 i.WriteHtonU64 (m_sequenceNumber); |
| 278 i.WriteHtonU32 (m_sourceId); |
| 279 i.WriteHtonU32 (m_destinationId); |
| 280 i.WriteHtonU16 (m_sourcePort); |
| 281 i.WriteHtonU16 (m_destinationPort); |
| 282 i.WriteHtonU32 (m_streamId); |
| 283 i.WriteHtonU16 (m_applicationId); |
| 284 } |
| 285 |
| 286 uint32_t |
| 287 NistHeader::Deserialize (Buffer::Iterator start) |
| 288 { |
| 289 Buffer::Iterator i = start; |
| 290 ·· |
| 291 m_sequenceNumber = i.ReadNtohU64 (); |
| 292 m_sourceId= i.ReadNtohU32 (); |
| 293 m_destinationId = i.ReadNtohU32 (); |
| 294 m_sourcePort = i.ReadNtohU16 (); |
| 295 m_destinationPort = i.ReadNtohU16 (); |
| 296 m_streamId = i.ReadNtohU32 (); |
| 297 m_applicationId = i.ReadNtohU16 (); |
| 298 |
| 299 return GetSerializedSize (); |
| 300 } |
| 301 |
| 302 |
| 303 } // namespace ns3 |
| 304 |
OLD | NEW |