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

(-)a/src/internet/test/ipv4-fragmentation-test.cc (-3 / +74 lines)
 Lines 54-59    Link Here 
54
54
55
class UdpSocketImpl;
55
class UdpSocketImpl;
56
56
57
/* ----------------------------------------------------------------------------------
58
 * Tag
59
 --------------------------------------------------------------------------------- */
60
class IPv4TestTag : public Tag {
61
private:
62
  uint64_t token;
63
public:
64
  static TypeId GetTypeId () {
65
    static TypeId tid = TypeId ("ns3::IPv4TestTag").SetParent<Tag> ().AddConstructor<IPv4TestTag> ();
66
    return tid;
67
  }
68
  virtual TypeId GetInstanceTypeId () const { return GetTypeId (); }
69
  virtual uint32_t GetSerializedSize () const { return sizeof (token); }
70
  virtual void Serialize (TagBuffer buffer) const { buffer.WriteU64 (token); }
71
  virtual void Deserialize (TagBuffer buffer) { token = buffer.ReadU64 (); }
72
  virtual void Print (std::ostream &os) const { os << "token=" << token; }
73
  void setToken (uint64_t token) { this->token = token; }
74
  uint64_t getToken () { return token; }
75
};
76
57
static void
77
static void
58
AddInternetStack (Ptr<Node> node)
78
AddInternetStack (Ptr<Node> node)
59
{
79
{
 Lines 161-169    Link Here 
161
    {
181
    {
162
      if (InetSocketAddress::IsMatchingType (from))
182
      if (InetSocketAddress::IsMatchingType (from))
163
        {
183
        {
164
          packet->RemoveAllPacketTags ();
165
          packet->RemoveAllByteTags ();
166
167
          m_receivedPacketServer = packet->Copy();
184
          m_receivedPacketServer = packet->Copy();
168
        }
185
        }
169
    }
186
    }
 Lines 247-252    Link Here 
247
    {
264
    {
248
      p = Create<Packet> (m_size);
265
      p = Create<Packet> (m_size);
249
    }
266
    }
267
  IPv4TestTag tag;
268
  tag.setToken (42);
269
  p->AddPacketTag (tag);
270
  p->AddByteTag (tag);
271
250
  m_socketClient->Send (p);
272
  m_socketClient->Send (p);
251
273
252
  return p;
274
  return p;
 Lines 398-403    Link Here 
398
      NS_TEST_EXPECT_MSG_EQ ((m_icmpType == 11), true, "Client did not receive ICMP::TIME_EXCEEDED");
420
      NS_TEST_EXPECT_MSG_EQ ((m_icmpType == 11), true, "Client did not receive ICMP::TIME_EXCEEDED");
399
    }
421
    }
400
422
423
  // Fourth test: normal channel, no errors, no delays.
424
  // We check tags
425
  clientDevErrorModel->Disable();
426
  serverDevErrorModel->Disable();
427
  for( int i= 0; i<5; i++)
428
    {
429
      uint32_t packetSize = packetSizes[i];
430
431
      SetFill (fillData, 78, packetSize);
432
433
      m_receivedPacketServer = Create<Packet> ();
434
      Simulator::ScheduleWithContext (m_socketClient->GetNode ()->GetId (), Seconds (0),
435
                                      &Ipv4FragmentationTest::SendClient, this);
436
      Simulator::Run ();
437
438
      IPv4TestTag packetTag;
439
      bool found = m_receivedPacketServer->PeekPacketTag (packetTag);
440
441
      NS_TEST_EXPECT_MSG_EQ (found, true, "PacketTag not found");
442
      NS_TEST_EXPECT_MSG_EQ (packetTag.getToken (), 42, "PacketTag value not correct");
443
444
      ByteTagIterator i = m_receivedPacketServer->GetByteTagIterator ();
445
446
      uint32_t end = 0;
447
      uint32_t tagStart = 0;
448
      uint32_t tagEnd = 0;
449
      while (i.HasNext ())
450
        {
451
          ByteTagIterator::Item item = i.Next ();
452
          NS_TEST_EXPECT_MSG_EQ (item.GetTypeId ().GetName (), "ns3::IPv4TestTag", "ByteTag name not correct");
453
          tagStart = item.GetStart ();
454
          tagEnd = item.GetEnd ();
455
          if (end == 0)
456
            {
457
              NS_TEST_EXPECT_MSG_EQ (tagStart, 0, "First ByteTag Start not correct");
458
            }
459
          if (end != 0)
460
            {
461
              NS_TEST_EXPECT_MSG_EQ (tagStart, end, "ByteTag End not correct");
462
            }
463
          end = tagEnd;
464
          IPv4TestTag *byteTag = dynamic_cast<IPv4TestTag *> (item.GetTypeId ().GetConstructor () ());
465
          NS_TEST_EXPECT_MSG_NE (byteTag, 0, "ByteTag not found");
466
          item.GetTag (*byteTag);
467
          NS_TEST_EXPECT_MSG_EQ (byteTag->getToken (), 42, "ByteTag value not correct");
468
        }
469
      NS_TEST_EXPECT_MSG_EQ (end, m_receivedPacketServer->GetSize (), "trivial");
470
    }
471
401
472
402
  Simulator::Destroy ();
473
  Simulator::Destroy ();
403
}
474
}
(-)a/src/internet/test/ipv6-fragmentation-test.cc (-3 / +73 lines)
 Lines 63-68    Link Here 
63
63
64
class UdpSocketImpl;
64
class UdpSocketImpl;
65
65
66
/* ----------------------------------------------------------------------------------
67
 * Tag
68
 --------------------------------------------------------------------------------- */
69
class IPv6TestTag : public Tag {
70
private:
71
  uint64_t token;
72
public:
73
  static TypeId GetTypeId () {
74
    static TypeId tid = TypeId ("ns3::IPv6TestTag").SetParent<Tag> ().AddConstructor<IPv6TestTag> ();
75
    return tid;
76
  }
77
  virtual TypeId GetInstanceTypeId () const { return GetTypeId (); }
78
  virtual uint32_t GetSerializedSize () const { return sizeof (token); }
79
  virtual void Serialize (TagBuffer buffer) const { buffer.WriteU64 (token); }
80
  virtual void Deserialize (TagBuffer buffer) { token = buffer.ReadU64 (); }
81
  virtual void Print (std::ostream &os) const { os << "token=" << token; }
82
  void setToken (uint64_t token) { this->token = token; }
83
  uint64_t getToken () { return token; }
84
};
85
66
static void
86
static void
67
AddInternetStack (Ptr<Node> node)
87
AddInternetStack (Ptr<Node> node)
68
{
88
{
 Lines 170-178    Link Here 
170
    {
190
    {
171
      if (Inet6SocketAddress::IsMatchingType (from))
191
      if (Inet6SocketAddress::IsMatchingType (from))
172
        {
192
        {
173
          packet->RemoveAllPacketTags ();
174
          packet->RemoveAllByteTags ();
175
176
          m_receivedPacketServer = packet->Copy ();
193
          m_receivedPacketServer = packet->Copy ();
177
        }
194
        }
178
    }
195
    }
 Lines 257-262    Link Here 
257
    {
274
    {
258
      p = Create<Packet> (m_size);
275
      p = Create<Packet> (m_size);
259
    }
276
    }
277
  IPv6TestTag tag;
278
  tag.setToken (42);
279
  p->AddPacketTag (tag);
280
  p->AddByteTag (tag);
281
260
  m_socketClient->Send (p);
282
  m_socketClient->Send (p);
261
283
262
  return p;
284
  return p;
 Lines 409-414    Link Here 
409
                             true, "Client did not receive ICMPv6::TIME_EXCEEDED " << int(m_icmpType) << int(m_icmpCode) );
431
                             true, "Client did not receive ICMPv6::TIME_EXCEEDED " << int(m_icmpType) << int(m_icmpCode) );
410
    }
432
    }
411
433
434
  // Fourth test: normal channel, no errors, no delays.
435
  // We check tags
436
  clientDevErrorModel->Disable();
437
  serverDevErrorModel->Disable();
438
  for( int i= 0; i<5; i++)
439
    {
440
      uint32_t packetSize = packetSizes[i];
441
442
      SetFill (fillData, 78, packetSize);
443
444
      m_receivedPacketServer = Create<Packet> ();
445
      Simulator::ScheduleWithContext (m_socketClient->GetNode ()->GetId (), Seconds (0),
446
                                      &Ipv6FragmentationTest::SendClient, this);
447
      Simulator::Run ();
448
449
      IPv6TestTag packetTag;
450
      bool found = m_receivedPacketServer->PeekPacketTag (packetTag);
451
452
      NS_TEST_EXPECT_MSG_EQ (found, true, "PacketTag not found");
453
      NS_TEST_EXPECT_MSG_EQ (packetTag.getToken (), 42, "PacketTag value not correct");
454
455
      ByteTagIterator i = m_receivedPacketServer->GetByteTagIterator ();
456
457
      uint32_t end = 0;
458
      uint32_t tagStart = 0;
459
      uint32_t tagEnd = 0;
460
      while (i.HasNext ())
461
        {
462
          ByteTagIterator::Item item = i.Next ();
463
          NS_TEST_EXPECT_MSG_EQ (item.GetTypeId ().GetName (), "ns3::IPv6TestTag", "ByteTag name not correct");
464
          tagStart = item.GetStart ();
465
          tagEnd = item.GetEnd ();
466
          if (end == 0)
467
            {
468
              NS_TEST_EXPECT_MSG_EQ (tagStart, 0, "First ByteTag Start not correct");
469
            }
470
          if (end != 0)
471
            {
472
              NS_TEST_EXPECT_MSG_EQ (tagStart, end, "ByteTag End not correct");
473
            }
474
          end = tagEnd;
475
          IPv6TestTag *byteTag = dynamic_cast<IPv6TestTag *> (item.GetTypeId ().GetConstructor () ());
476
          NS_TEST_EXPECT_MSG_NE (byteTag, 0, "ByteTag not found");
477
          item.GetTag (*byteTag);
478
          NS_TEST_EXPECT_MSG_EQ (byteTag->getToken (), 42, "ByteTag value not correct");
479
        }
480
      NS_TEST_EXPECT_MSG_EQ (end, m_receivedPacketServer->GetSize (), "trivial");
481
    }
412
482
413
  Simulator::Destroy ();
483
  Simulator::Destroy ();
414
}
484
}

Return to bug 1816