View | Details | Raw Unified | Return to bug 1383
Collapse All | Expand All

(-)a/src/network/model/packet-tag-list.cc (-126 / +122 lines)
 Lines 28-177   NS_LOG_COMPONENT_DEFINE ("PacketTagList"); Link Here 
28
28
29
namespace ns3 {
29
namespace ns3 {
30
30
31
#ifdef USE_FREE_LIST
32
33
struct PacketTagList::TagData *PacketTagList::g_free = 0;
34
uint32_t PacketTagList::g_nfree = 0;
35
36
struct PacketTagList::TagData *
37
PacketTagList::AllocData (void) const
38
{
39
  NS_LOG_FUNCTION (g_nfree);
40
  struct PacketTagList::TagData *retval;
41
  if (g_free != 0) 
42
    {
43
      retval = g_free;
44
      g_free = g_free->m_next;
45
      g_nfree--;
46
    } 
47
  else 
48
    {
49
      retval = new struct PacketTagList::TagData ();
50
    }
51
  return retval;
52
}
53
54
void
31
void
55
PacketTagList::FreeData (struct TagData *data) const
32
PacketTagList::Add (Ptr<const Tag> tag)
56
{
57
  NS_LOG_FUNCTION (g_nfree << data);
58
  if (g_nfree > 1000) 
59
    {
60
      delete data;
61
      return;
62
    }
63
  g_nfree++;
64
  data->next = g_free;
65
  data->tid = TypeId ();
66
  g_free = data;
67
}
68
#else
69
struct PacketTagList::TagData *
70
PacketTagList::AllocData (void) const
71
{
33
{
72
  NS_LOG_FUNCTION_NOARGS ();
34
  NS_LOG_FUNCTION (this << tag->GetInstanceTypeId ());
73
  struct PacketTagList::TagData *retval;
74
  retval = new struct PacketTagList::TagData ();
75
  return retval;
76
}
77
35
78
void
36
  NS_ASSERT_MSG (Peek (tag->GetInstanceTypeId ()) == 0,
79
PacketTagList::FreeData (struct TagData *data) const
37
                 "Only one tag type per packet is allowed");
80
{
38
81
  NS_LOG_FUNCTION (data);
39
  push_back (tag);
82
  delete data;
83
}
40
}
84
#endif
85
41
86
bool
42
Ptr<const Tag>
87
PacketTagList::Remove (Tag &tag)
43
PacketTagList::Remove (TypeId tagType)
88
{
44
{
89
  NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ());
45
  NS_LOG_FUNCTION (this << tagType);
90
  TypeId tid = tag.GetInstanceTypeId ();
46
  
91
  bool found = false;
47
  for (iterator tag = begin (); tag != end (); tag++)
92
  for (struct TagData *cur = m_next; cur != 0; cur = cur->next) 
93
    {
94
      if (cur->tid == tid) 
95
        {
96
          found = true;
97
          tag.Deserialize (TagBuffer (cur->data, cur->data+PACKET_TAG_MAX_SIZE));
98
        }
99
    }
100
  if (!found) 
101
    {
48
    {
102
      return false;
49
      if ((*tag)->GetInstanceTypeId () == tagType)
103
    }
104
  struct TagData *start = 0;
105
  struct TagData **prevNext = &start;
106
  for (struct TagData *cur = m_next; cur != 0; cur = cur->next) 
107
    {
108
      if (cur->tid == tid) 
109
        {
50
        {
110
          /**
51
          Ptr<const Tag> retval = *tag;
111
           * XXX
52
          erase (tag);
112
           * Note: I believe that we could optimize this to
53
          return retval;
113
           * avoid copying each TagData located after the target id
114
           * and just link the already-copied list to the next tag.
115
           */
116
          continue;
117
        }
54
        }
118
      struct TagData *copy = AllocData ();
119
      copy->tid = cur->tid;
120
      copy->count = 1;
121
      copy->next = 0;
122
      memcpy (copy->data, cur->data, PACKET_TAG_MAX_SIZE);
123
      *prevNext = copy;
124
      prevNext = &copy->next;
125
    }
55
    }
126
  *prevNext = 0;
127
  RemoveAll ();
128
  m_next = start;
129
  return true;
130
}
131
56
132
void 
57
  return 0;
133
PacketTagList::Add (const Tag &tag) const
134
{
135
  NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ());
136
  // ensure this id was not yet added
137
  for (struct TagData *cur = m_next; cur != 0; cur = cur->next) 
138
    {
139
      NS_ASSERT (cur->tid != tag.GetInstanceTypeId ());
140
    }
141
  struct TagData *head = AllocData ();
142
  head->count = 1;
143
  head->next = 0;
144
  head->tid = tag.GetInstanceTypeId ();
145
  head->next = m_next;
146
  NS_ASSERT (tag.GetSerializedSize () <= PACKET_TAG_MAX_SIZE);
147
  tag.Serialize (TagBuffer (head->data, head->data+tag.GetSerializedSize ()));
148
149
  const_cast<PacketTagList *> (this)->m_next = head;
150
}
58
}
151
59
152
bool
60
Ptr<const Tag>
153
PacketTagList::Peek (Tag &tag) const
61
PacketTagList::Peek (TypeId tagType) const
154
{
62
{
155
  NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ());
63
  NS_LOG_FUNCTION (this << tagType);
156
  TypeId tid = tag.GetInstanceTypeId ();
64
  for (const_iterator tag = begin (); tag != end (); tag++)
157
  for (struct TagData *cur = m_next; cur != 0; cur = cur->next) 
158
    {
65
    {
159
      if (cur->tid == tid) 
66
      if ((*tag)->GetInstanceTypeId () == tagType)
160
        {
67
        return *tag;
161
          /* found tag */
162
          tag.Deserialize (TagBuffer (cur->data, cur->data+PACKET_TAG_MAX_SIZE));
163
          return true;
164
        }
165
    }
68
    }
166
  /* no tag found */
167
  return false;
168
}
169
69
170
const struct PacketTagList::TagData *
70
  return 0;
171
PacketTagList::Head (void) const
172
{
173
  return m_next;
174
}
71
}
175
72
73
74
// bool
75
// PacketTagList::Remove (Tag &tag)
76
// {
77
//   NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ());
78
79
//   return false;
80
  
81
//   // TypeId tid = tag.GetInstanceTypeId ();
82
//   // bool found = false;
83
//   // for (struct TagData *cur = m_next; cur != 0; cur = cur->next) 
84
//   //   {
85
//   //     if (cur->tid == tid) 
86
//   //       {
87
//   //         found = true;
88
//   //         tag.Deserialize (TagBuffer (cur->data, cur->data+PACKET_TAG_MAX_SIZE));
89
//   //       }
90
//   //   }
91
//   // if (!found) 
92
//   //   {
93
//   //     return false;
94
//   //   }
95
//   // struct TagData *start = 0;
96
//   // struct TagData **prevNext = &start;
97
//   // for (struct TagData *cur = m_next; cur != 0; cur = cur->next) 
98
//   //   {
99
//   //     if (cur->tid == tid) 
100
//   //       {
101
//   //         /**
102
//   //          * XXX
103
//   //          * Note: I believe that we could optimize this to
104
//   //          * avoid copying each TagData located after the target id
105
//   //          * and just link the already-copied list to the next tag.
106
//   //          */
107
//   //         continue;
108
//   //       }
109
//   //     struct TagData *copy = AllocData ();
110
//   //     copy->tid = cur->tid;
111
//   //     copy->count = 1;
112
//   //     copy->next = 0;
113
//   //     memcpy (copy->data, cur->data, PACKET_TAG_MAX_SIZE);
114
//   //     *prevNext = copy;
115
//   //     prevNext = &copy->next;
116
//   //   }
117
//   // *prevNext = 0;
118
//   // RemoveAll ();
119
//   // m_next = start;
120
//   // return true;
121
// }
122
123
// void 
124
// PacketTagList::Add (const Tag &tag) const
125
// {
126
//   NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ());
127
//   // ensure this id was not yet added
128
129
//   // for (struct TagData *cur = m_next; cur != 0; cur = cur->next) 
130
//   //   {
131
//   //     NS_ASSERT (cur->tid != tag.GetInstanceTypeId ());
132
//   //   }
133
134
//   // struct TagData *head = AllocData ();
135
//   // head->count = 1;
136
//   // head->next = 0;
137
//   // head->tid = tag.GetInstanceTypeId ();
138
//   // head->next = m_next;
139
//   // NS_ASSERT (tag.GetSerializedSize () <= PACKET_TAG_MAX_SIZE);
140
//   // tag.Serialize (TagBuffer (head->data, head->data+tag.GetSerializedSize ()));
141
142
//   // const_cast<PacketTagList *> (this)->m_next = head;
143
144
//   // m_tags.
145
// }
146
147
// bool
148
// PacketTagList::Peek (Tag &tag) const
149
// {
150
//   NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ());
151
//   // TypeId tid = tag.GetInstanceTypeId ();
152
//   // for (struct TagData *cur = m_next; cur != 0; cur = cur->next) 
153
//   //   {
154
//   //     if (cur->tid == tid) 
155
//   //       {
156
//   //         /* found tag */
157
//   //         tag.Deserialize (TagBuffer (cur->data, cur->data+PACKET_TAG_MAX_SIZE));
158
//   //         return true;
159
//   //       }
160
//   //   }
161
  
162
//   /* no tag found */
163
//   return false;
164
// }
165
166
// // const struct PacketTagList::TagData *
167
// // PacketTagList::Head (void) const
168
// // {
169
// //   return m_next;
170
// // }
171
176
} // namespace ns3
172
} // namespace ns3
177
173
(-)a/src/network/model/packet-tag-list.h (-87 / +50 lines)
 Lines 21-27    Link Here 
21
#define PACKET_TAG_LIST_H
21
#define PACKET_TAG_LIST_H
22
22
23
#include <stdint.h>
23
#include <stdint.h>
24
#include <ostream>
24
#include <list>
25
#include "ns3/type-id.h"
25
#include "ns3/type-id.h"
26
26
27
namespace ns3 {
27
namespace ns3 {
 Lines 34-73   class Tag; Link Here 
34
 * The maximum size (in bytes) of a Tag is stored
34
 * The maximum size (in bytes) of a Tag is stored
35
 * in this constant.
35
 * in this constant.
36
 */
36
 */
37
#define PACKET_TAG_MAX_SIZE 20
37
// #define PACKET_TAG_MAX_SIZE 20
38
38
39
class PacketTagList 
39
class PacketTagList : public std::list<Ptr<const Tag> >
40
{
40
{
41
public:
41
public:
42
  struct TagData {
42
  // struct TagData {
43
    uint8_t data[PACKET_TAG_MAX_SIZE];
43
  //   std::vector<uint8_t> data;
44
    struct TagData *next;
44
  //   TypeId tid;
45
    TypeId tid;
45
  //   uint32_t count;
46
    uint32_t count;
46
  // };
47
  };
48
47
49
  inline PacketTagList ();
48
  // inline PacketTagList ();
50
  inline PacketTagList (PacketTagList const &o);
49
  // inline PacketTagList (PacketTagList const &o);
51
  inline PacketTagList &operator = (PacketTagList const &o);
50
  // inline PacketTagList &operator = (PacketTagList const &o);
52
  inline ~PacketTagList ();
51
  // inline ~PacketTagList ();
53
52
54
  void Add (Tag const&tag) const;
53
  void
55
  bool Remove (Tag &tag);
54
  Add (Ptr<const Tag> tag);
56
  bool Peek (Tag &tag) const;
57
  inline void RemoveAll (void);
58
55
59
  const struct PacketTagList::TagData *Head (void) const;
56
  Ptr<const Tag>
57
  Remove (TypeId tagType);
60
58
61
private:
59
  Ptr<const Tag>
62
60
  Peek (TypeId tagType) const;
63
  bool Remove (TypeId tid);
64
  struct PacketTagList::TagData *AllocData (void) const;
65
  void FreeData (struct TagData *data) const;
66
67
  static struct PacketTagList::TagData *g_free;
68
  static uint32_t g_nfree;
69
70
  struct TagData *m_next;
71
};
61
};
72
62
73
} // namespace ns3
63
} // namespace ns3
 Lines 78-142   private: Link Here 
78
68
79
namespace ns3 {
69
namespace ns3 {
80
70
81
PacketTagList::PacketTagList ()
71
// PacketTagList::PacketTagList ()
82
  : m_next ()
72
// {
83
{
73
// }
84
}
74
85
75
// PacketTagList::PacketTagList (PacketTagList const &o)
86
PacketTagList::PacketTagList (PacketTagList const &o)
76
//   : m_tags (o.m_tags)
87
  : m_next (o.m_next)
77
// {
88
{
78
// }
89
  if (m_next != 0)
79
90
    {
80
// PacketTagList &
91
      m_next->count++;
81
// PacketTagList::operator = (PacketTagList const &o)
92
    }
82
// {
93
}
83
//   // self assignment
94
84
//   if (&o == this)
95
PacketTagList &
85
//     {
96
PacketTagList::operator = (PacketTagList const &o)
86
//       return *this;
97
{
87
//     }
98
  // self assignment
88
//   // RemoveAll (); // ???
99
  if (m_next == o.m_next) 
89
//   m_tags = o.m_tags;
100
    {
90
//   return *this;
101
      return *this;
91
// }
102
    }
92
103
  RemoveAll ();
93
// PacketTagList::~PacketTagList ()
104
  m_next = o.m_next;
94
// {
105
  if (m_next != 0) 
95
//   RemoveAll ();
106
    {
96
// }
107
      m_next->count++;
97
108
    }
98
// void
109
  return *this;
99
// PacketTagList::RemoveAll (void)
110
}
100
// {
111
101
//   m_tags.clear ();
112
PacketTagList::~PacketTagList ()
102
// }
113
{
114
  RemoveAll ();
115
}
116
117
void
118
PacketTagList::RemoveAll (void)
119
{
120
  struct TagData *prev = 0;
121
  for (struct TagData *cur = m_next; cur != 0; cur = cur->next) 
122
    {
123
      cur->count--;
124
      if (cur->count > 0) 
125
        {
126
          break;
127
        }
128
      if (prev != 0) 
129
        {
130
          FreeData (prev);
131
        }
132
      prev = cur;
133
    }
134
  if (prev != 0) 
135
    {
136
      FreeData (prev);
137
    }
138
  m_next = 0;
139
}
140
103
141
} // namespace ns3
104
} // namespace ns3
142
105
(-)a/src/network/model/packet.cc (-66 / +96 lines)
 Lines 81-119   ByteTagIterator::ByteTagIterator (ByteTagList::Iterator i) Link Here 
81
}
81
}
82
82
83
83
84
PacketTagIterator::PacketTagIterator (const struct PacketTagList::TagData *head)
84
// PacketTagIterator::PacketTagIterator (const struct PacketTagList::TagData *head)
85
  : m_current (head)
85
//   : m_current (head)
86
{
86
// {
87
}
87
// }
88
bool
88
// bool
89
PacketTagIterator::HasNext (void) const
89
// PacketTagIterator::HasNext (void) const
90
{
90
// {
91
  return m_current != 0;
91
//   return m_current != 0;
92
}
92
// }
93
PacketTagIterator::Item
93
// PacketTagIterator::Item
94
PacketTagIterator::Next (void)
94
// PacketTagIterator::Next (void)
95
{
95
// {
96
  NS_ASSERT (HasNext ());
96
//   NS_ASSERT (HasNext ());
97
  const struct PacketTagList::TagData *prev = m_current;
97
//   const struct PacketTagList::TagData *prev = m_current;
98
  m_current = m_current->next;
98
//   m_current = m_current->next;
99
  return PacketTagIterator::Item (prev);
99
//   return PacketTagIterator::Item (prev);
100
}
100
// }
101
101
102
PacketTagIterator::Item::Item (const struct PacketTagList::TagData *data)
102
// PacketTagIterator::Item::Item (const struct PacketTagList::TagData *data)
103
  : m_data (data)
103
//   : m_data (data)
104
{
104
// {
105
}
105
// }
106
TypeId
106
// TypeId
107
PacketTagIterator::Item::GetTypeId (void) const
107
// PacketTagIterator::Item::GetTypeId (void) const
108
{
108
// {
109
  return m_data->tid;
109
//   return m_data->tid;
110
}
110
// }
111
void
111
// void
112
PacketTagIterator::Item::GetTag (Tag &tag) const
112
// PacketTagIterator::Item::GetTag (Tag &tag) const
113
{
113
// {
114
  NS_ASSERT (tag.GetInstanceTypeId () == m_data->tid);
114
//   NS_ASSERT (tag.GetInstanceTypeId () == m_data->tid);
115
  tag.Deserialize (TagBuffer ((uint8_t*)m_data->data, (uint8_t*)m_data->data+PACKET_TAG_MAX_SIZE));
115
//   tag.Deserialize (TagBuffer ((uint8_t*)m_data->data, (uint8_t*)m_data->data+PACKET_TAG_MAX_SIZE));
116
}
116
// }
117
117
118
118
119
Ptr<Packet> 
119
Ptr<Packet> 
 Lines 835-894   Packet::FindFirstMatchingByteTag (Tag &tag) const Link Here 
835
  return false;
835
  return false;
836
}
836
}
837
837
838
void 
838
// void 
839
Packet::AddPacketTag (const Tag &tag) const
839
// Packet::AddPacketTag (const Tag &tag) const
840
// {
841
//   NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ().GetName () << tag.GetSerializedSize ());
842
//   m_packetTagList.Add (tag);
843
// }
844
// bool 
845
// Packet::RemovePacketTag (Tag &tag)
846
// {
847
//   NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ().GetName () << tag.GetSerializedSize ());
848
//   bool found = m_packetTagList.Remove (tag);
849
//   return found;
850
// }
851
// bool 
852
// Packet::PeekPacketTag (Tag &tag) const
853
// {
854
//   bool found = m_packetTagList.Peek (tag);
855
//   return found;
856
// }
857
858
void
859
Packet::AddPacketTag (Ptr<const Tag> tag)
840
{
860
{
841
  NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ().GetName () << tag.GetSerializedSize ());
842
  m_packetTagList.Add (tag);
861
  m_packetTagList.Add (tag);
843
}
862
}
844
bool 
863
845
Packet::RemovePacketTag (Tag &tag)
864
Ptr<const Tag>
865
Packet::RemovePacketTag (TypeId tagType)
846
{
866
{
847
  NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ().GetName () << tag.GetSerializedSize ());
867
  return m_packetTagList.Remove (tagType);
848
  bool found = m_packetTagList.Remove (tag);
849
  return found;
850
}
868
}
851
bool 
869
852
Packet::PeekPacketTag (Tag &tag) const
870
Ptr<const Tag>
871
Packet::PeekPacketTag (TypeId tagType) const
853
{
872
{
854
  bool found = m_packetTagList.Peek (tag);
873
  return m_packetTagList.Peek (tagType);
855
  return found;
856
}
874
}
875
857
void 
876
void 
858
Packet::RemoveAllPacketTags (void)
877
Packet::RemoveAllPacketTags (void)
859
{
878
{
860
  NS_LOG_FUNCTION (this);
879
  NS_LOG_FUNCTION (this);
861
  m_packetTagList.RemoveAll ();
880
  m_packetTagList.clear ();
862
}
881
}
863
882
864
void 
883
void 
865
Packet::PrintPacketTags (std::ostream &os) const
884
Packet::PrintPacketTags (std::ostream &os) const
866
{
885
{
867
  PacketTagIterator i = GetPacketTagIterator ();
886
  for (PacketTagList::const_iterator tag = m_packetTagList.begin ();
868
  while (i.HasNext ())
887
       tag != m_packetTagList.end ();
888
       tag++)
869
    {
889
    {
870
      PacketTagIterator::Item item = i.Next ();
890
      if (tag != m_packetTagList.begin ())
871
      NS_ASSERT (item.GetTypeId ().HasConstructor ());
872
      Callback<ObjectBase *> constructor = item.GetTypeId ().GetConstructor ();
873
      NS_ASSERT (!constructor.IsNull ());
874
      ObjectBase *instance = constructor ();
875
      Tag *tag = dynamic_cast<Tag *> (instance);
876
      NS_ASSERT (tag != 0);
877
      item.GetTag (*tag);
878
      tag->Print (os);
879
      delete tag;
880
      if (i.HasNext ())
881
        {
891
        {
882
          os << " ";
892
          os << " ";
883
        }
893
        }
884
    }
885
}
886
894
887
PacketTagIterator 
895
      (*tag)->Print (os);
888
Packet::GetPacketTagIterator (void) const
896
    }
889
{
897
  // PacketTagIterator i = GetPacketTagIterator ();
890
  return PacketTagIterator (m_packetTagList.Head ());
898
  // while (i.HasNext ())
891
}
899
  //   {
900
  //     PacketTagIterator::Item item = i.Next ();
901
  //     NS_ASSERT (item.GetTypeId ().HasConstructor ());
902
  //     Callback<ObjectBase *> constructor = item.GetTypeId ().GetConstructor ();
903
  //     NS_ASSERT (!constructor.IsNull ());
904
  //     ObjectBase *instance = constructor ();
905
  //     Tag *tag = dynamic_cast<Tag *> (instance);
906
  //     NS_ASSERT (tag != 0);
907
  //     item.GetTag (*tag);
908
  //     tag->Print (os);
909
  //     delete tag;
910
  //     if (i.HasNext ())
911
  //       {
912
  //         os << " ";
913
  //       }
914
  //   }
915
}
916
917
// PacketTagIterator 
918
// Packet::GetPacketTagIterator (void) const
919
// {
920
//   return PacketTagIterator (m_packetTagList.Head ());
921
// }
892
922
893
std::ostream& operator<< (std::ostream& os, const Packet &packet)
923
std::ostream& operator<< (std::ostream& os, const Packet &packet)
894
{
924
{
(-)a/src/network/model/packet.h (-59 / +44 lines)
 Lines 106-158   private: Link Here 
106
106
107
/**
107
/**
108
 * \ingroup packet
108
 * \ingroup packet
109
 * \brief Iterator over the set of 'packet' tags in a packet
110
 *
111
 * This is a java-style iterator.
112
 */
113
class PacketTagIterator
114
{
115
public:
116
  /**
117
   * Identifies a tag within a packet.
118
   */
119
  class Item 
120
  {
121
public:
122
    /**
123
     * \returns the ns3::TypeId associated to this tag.
124
     */
125
    TypeId GetTypeId (void) const;
126
    /**
127
     * \param tag the user tag to which the data should be copied.
128
     *
129
     * Read the requested tag and store it in the user-provided
130
     * tag instance. This method will crash if the type of the
131
     * tag provided by the user does not match the type of
132
     * the underlying tag.
133
     */
134
    void GetTag (Tag &tag) const;
135
private:
136
    friend class PacketTagIterator;
137
    Item (const struct PacketTagList::TagData *data);
138
    const struct PacketTagList::TagData *m_data;
139
  };
140
  /**
141
   * \returns true if calling Next is safe, false otherwise.
142
   */
143
  bool HasNext (void) const;
144
  /**
145
   * \returns the next item found and prepare for the next one.
146
   */
147
  Item Next (void);
148
private:
149
  friend class Packet;
150
  PacketTagIterator (const struct PacketTagList::TagData *head);
151
  const struct PacketTagList::TagData *m_current;
152
};
153
154
/**
155
 * \ingroup packet
156
 * \brief network packets
109
 * \brief network packets
157
 *
110
 *
158
 * Each network packet contains a byte buffer, a set of byte tags, a set of
111
 * Each network packet contains a byte buffer, a set of byte tags, a set of
 Lines 498-528   public: Link Here 
498
  /**
451
  /**
499
   * \param tag the tag to store in this packet
452
   * \param tag the tag to store in this packet
500
   *
453
   *
501
   * Add a tag to this packet. This method calls the
454
   * Add a tag to this packet.
502
   * Tag::GetSerializedSize and, then, Tag::Serialize.
455
   */
456
  void
457
  AddPacketTag (Ptr<const Tag> tag);
458
459
  /**
460
   * \param tag the tag to remove from this packet
461
   * \returns smart pointer to a constant Tag object if the requested tag is found, 
462
   *          0 otherwise.
503
   *
463
   *
504
   * Note that this method is const, that is, it does not
464
   * Remove a tag from this packet. 
505
   * modify the state of this packet, which is fairly
506
   * un-intuitive.
507
   */
465
   */
508
  void AddPacketTag (const Tag &tag) const;
466
  Ptr<const Tag>
467
  RemovePacketTag (TypeId tagType);
468
509
  /**
469
  /**
510
   * \param tag the tag to remove from this packet
470
   * \param tag the tag to remove from this packet
471
   * \returns smart pointer to a constant Tag object if the requested tag is found, 
472
   *          0 otherwise.
473
   *
474
   * Templated version to remove a tag from this packet.
475
   * In addition to non-templated version, there is a DynamicCast to
476
   * the requested tag type
477
   */
478
  template<class T>
479
  Ptr<const T>
480
  RemovePacketTag ()
481
  {
482
    return DynamicCast<const T> (RemovePacketTag (T::GetTypeId ()));
483
  }
484
  
485
  /**
486
   * \param tag the tag to search in this packet
511
   * \returns true if the requested tag is found, false
487
   * \returns true if the requested tag is found, false
512
   *          otherwise.
488
   *          otherwise.
513
   *
489
   *
514
   * Remove a tag from this packet. This method calls
490
   * Search a matching tag and return it if found
515
   * Tag::Deserialize if the tag is found.
516
   */
491
   */
517
  bool RemovePacketTag (Tag &tag);
492
  Ptr<const Tag>
493
  PeekPacketTag (TypeId tagType) const;
494
518
  /**
495
  /**
519
   * \param tag the tag to search in this packet
496
   * \param tag the tag to search in this packet
520
   * \returns true if the requested tag is found, false
497
   * \returns true if the requested tag is found, false
521
   *          otherwise.
498
   *          otherwise.
522
   *
499
   *
523
   * Search a matching tag and call Tag::Deserialize if it is found.
500
   * Templated version of search for a matching tag and returning it if found
501
   * In addition to non-templated version, there is a DynamicCast to
502
   * the requested tag type
524
   */
503
   */
525
  bool PeekPacketTag (Tag &tag) const;
504
  template<class T>
505
  Ptr<const T>
506
  PeekPacketTag () const
507
  {
508
    return DynamicCast<const T> (PeekPacketTag (T::GetTypeId ()));
509
  }
510
  
526
  /**
511
  /**
527
   * Remove all packet tags.
512
   * Remove all packet tags.
528
   */
513
   */
 Lines 542-548   public: Link Here 
542
   * \returns an object which can be used to iterate over the list of
527
   * \returns an object which can be used to iterate over the list of
543
   *  packet tags.
528
   *  packet tags.
544
   */
529
   */
545
  PacketTagIterator GetPacketTagIterator (void) const;
530
  // PacketTagIterator GetPacketTagIterator (void) const;
546
531
547
  /* Note: These functions support a temporary solution 
532
  /* Note: These functions support a temporary solution 
548
   * to a specific problem in this generic class, i.e. 
533
   * to a specific problem in this generic class, i.e. 
(-)a/src/network/model/tag.h (-3 / +9 lines)
 Lines 20-26    Link Here 
20
#ifndef TAG_H
20
#ifndef TAG_H
21
#define TAG_H
21
#define TAG_H
22
22
23
#include "ns3/object-base.h"
23
#include "ns3/object.h"
24
#include "tag-buffer.h"
24
#include "tag-buffer.h"
25
#include <stdint.h>
25
#include <stdint.h>
26
26
 Lines 33-39   namespace ns3 { Link Here 
33
 *
33
 *
34
 * New kinds of tags can be created by subclassing this base class.
34
 * New kinds of tags can be created by subclassing this base class.
35
 */
35
 */
36
class Tag : public ObjectBase
36
class Tag : public Object
37
{
37
{
38
public:
38
public:
39
  static TypeId GetTypeId (void);
39
  static TypeId GetTypeId (void);
 Lines 71-76   public: Link Here 
71
  virtual void Print (std::ostream &os) const = 0;
71
  virtual void Print (std::ostream &os) const = 0;
72
};
72
};
73
73
74
inline std::ostream &
75
operator << (std::ostream &os, const Tag &tag)
76
{
77
  tag.Print (os);
78
  return os;
79
}
80
74
} // namespace ns3
81
} // namespace ns3
75
82
76
#endif /* TAG_H */
83
#endif /* TAG_H */
77
- 

Return to bug 1383