A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
cognitive-packet-tags.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2006,2007 INRIA
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  * Author: Abdulla Al-Ali <al-ali.a@husky.neu.edu>
19  */
20 
21 #include "cognitive-packet-tags.h"
22 
23 namespace ns3 {
24 
25 PacketTypePacketTag::PacketTypePacketTag (PacketType t) :
26  m_type (t)
27 {
28 }
29 
30 TypeId
31 PacketTypePacketTag::GetTypeId (void)
32 {
33  static TypeId tid = TypeId ("ns3::PacketTypePacketTag")
34  .SetParent<Tag> ()
35  .AddConstructor<PacketTypePacketTag> ()
36  ;
37  return tid;
38 }
39 TypeId
41 {
42  return GetTypeId ();
43 }
44 
45 uint32_t
47 {
48  return 1;
49 }
50 void
52 {
53  i.WriteU8 (m_type);
54 }
55 void
57 {
58  m_type = (PacketType) i.ReadU8 ();
59 }
60 
61 void
62 PacketTypePacketTag::Print (std::ostream &os) const
63 {
64  switch (m_type)
65  {
66  case CTRL_PACKET:
67  {
68  os << "ctrl_packet";
69  break;
70  }
71  case DATA_PACKET:
72  {
73  os << "data_packet";
74  break;
75  }
76  default:
77  os << "UNKNOWN_TYPE";
78  break;
79  }
80 }
81 
82 PacketChannelPacketTag::PacketChannelPacketTag (uint16_t t) :
83  m_channel (t)
84 {
85 }
86 
87 TypeId
88 PacketChannelPacketTag::GetTypeId (void)
89 {
90  static TypeId tid = TypeId ("ns3::PacketChannelPacketTag")
91  .SetParent<Tag> ()
92  .AddConstructor<PacketChannelPacketTag> ()
93  ;
94  return tid;
95 }
96 TypeId
98 {
99  return GetTypeId ();
100 }
101 
102 uint32_t
104 {
105  return 2;
106 }
107 void
109 {
110  i.WriteU16 (m_channel);
111 }
112 void
114 {
115  m_channel = i.ReadU16 ();
116 }
117 
118 void
119 PacketChannelPacketTag::Print (std::ostream &os) const
120 {
121  os << "packet channel: " << m_channel;
122 }
123 
124 }
virtual void Deserialize(TagBuffer i)
virtual uint32_t GetSerializedSize(void) const
TAG_BUFFER_INLINE uint8_t ReadU8(void)
Definition: tag-buffer.h:179
virtual void Deserialize(TagBuffer i)
virtual TypeId GetInstanceTypeId(void) const
virtual uint32_t GetSerializedSize(void) const
TAG_BUFFER_INLINE void WriteU16(uint16_t v)
Definition: tag-buffer.h:164
void Print(std::ostream &os) const
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
Definition: tag-buffer.h:156
read and write tag data
Definition: tag-buffer.h:51
virtual void Serialize(TagBuffer i) const
TAG_BUFFER_INLINE uint16_t ReadU16(void)
Definition: tag-buffer.h:189
virtual TypeId GetInstanceTypeId(void) const
virtual void Serialize(TagBuffer i) const
void Print(std::ostream &os) const