LEFT | RIGHT |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2010 Hajime Tazaki | 3 * Copyright (c) 2010 Hajime Tazaki |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 }; | 98 }; |
99 | 99 |
100 | 100 |
101 Ipv4HeaderTest::Ipv4HeaderTest () | 101 Ipv4HeaderTest::Ipv4HeaderTest () |
102 : TestCase ("IPv4 Header Test") | 102 : TestCase ("IPv4 Header Test") |
103 { | 103 { |
104 } | 104 } |
105 | 105 |
106 void Ipv4HeaderTest::ReceivePacket (Ptr<Socket> socket, Ptr<Packet> packet, cons
t Address &from) | 106 void Ipv4HeaderTest::ReceivePacket (Ptr<Socket> socket, Ptr<Packet> packet, cons
t Address &from) |
107 { | 107 { |
108 NS_UNUSED(from); | 108 NS_UNUSED (from); |
109 m_receivedPacket = packet; | 109 m_receivedPacket = packet; |
110 } | 110 } |
111 | 111 |
112 void Ipv4HeaderTest::ReceivePkt (Ptr<Socket> socket) | 112 void Ipv4HeaderTest::ReceivePkt (Ptr<Socket> socket) |
113 { | 113 { |
114 uint32_t availableData; | 114 uint32_t availableData; |
115 availableData = socket->GetRxAvailable (); | 115 availableData = socket->GetRxAvailable (); |
116 m_receivedPacket = socket->Recv (2, MSG_PEEK); | 116 m_receivedPacket = socket->Recv (2, MSG_PEEK); |
117 NS_ASSERT (m_receivedPacket->GetSize () == 2); | 117 NS_ASSERT (m_receivedPacket->GetSize () == 2); |
118 m_receivedPacket = socket->Recv (std::numeric_limits<uint32_t>::max (), 0); | 118 m_receivedPacket = socket->Recv (std::numeric_limits<uint32_t>::max (), 0); |
119 NS_ASSERT (availableData == m_receivedPacket->GetSize ()); | 119 NS_ASSERT (availableData == m_receivedPacket->GetSize ()); |
120 m_receivedPacket->PeekHeader (m_receivedHeader); | 120 m_receivedPacket->PeekHeader (m_receivedHeader); |
121 } | 121 } |
122 | 122 |
123 void | 123 void |
124 Ipv4HeaderTest::DoSendData_IpHdr_Dscp (Ptr<Socket> socket, std::string to, Ipv4H
eader::DscpType dscp, Ipv4Header::EcnType ecn) | 124 Ipv4HeaderTest::DoSendData_IpHdr_Dscp (Ptr<Socket> socket, std::string to, Ipv4H
eader::DscpType dscp, Ipv4Header::EcnType ecn) |
125 { | 125 { |
126 Address realTo = InetSocketAddress (Ipv4Address (to.c_str ()), 0); | 126 Address realTo = InetSocketAddress (Ipv4Address (to.c_str ()), 0); |
127 socket->SetAttribute ("IpHeaderInclude", BooleanValue (true)); | 127 socket->SetAttribute ("IpHeaderInclude", BooleanValue (true)); |
128 Ptr<Packet> p = Create<Packet> (123); | 128 Ptr<Packet> p = Create<Packet> (123); |
129 Ipv4Header ipHeader; | 129 Ipv4Header ipHeader; |
130 ipHeader.SetSource (Ipv4Address ("10.0.0.2")); | 130 ipHeader.SetSource (Ipv4Address ("10.0.0.2")); |
131 ipHeader.SetDestination (Ipv4Address (to.c_str ())); | 131 ipHeader.SetDestination (Ipv4Address (to.c_str ())); |
132 ipHeader.SetProtocol (0); | 132 ipHeader.SetProtocol (0); |
133 ipHeader.SetPayloadSize (static_cast<uint16_t>(p->GetSize ())); | 133 ipHeader.SetPayloadSize (static_cast<uint16_t> (p->GetSize ())); |
134 ipHeader.SetTtl (255); | 134 ipHeader.SetTtl (255); |
135 ipHeader.SetDscp (dscp); | 135 ipHeader.SetDscp (dscp); |
136 ipHeader.SetEcn (ecn); | 136 ipHeader.SetEcn (ecn); |
137 p->AddHeader (ipHeader); | 137 p->AddHeader (ipHeader); |
138 | 138 |
139 NS_TEST_EXPECT_MSG_EQ (socket->SendTo (p, 0, realTo), | 139 NS_TEST_EXPECT_MSG_EQ (socket->SendTo (p, 0, realTo), |
140 143, to); | 140 143, to); |
141 socket->SetAttribute ("IpHeaderInclude", BooleanValue (false)); | 141 socket->SetAttribute ("IpHeaderInclude", BooleanValue (false)); |
142 } | 142 } |
143 | 143 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 class Ipv4HeaderTestSuite : public TestSuite | 275 class Ipv4HeaderTestSuite : public TestSuite |
276 { | 276 { |
277 public: | 277 public: |
278 Ipv4HeaderTestSuite () : TestSuite ("ipv4-header", UNIT) | 278 Ipv4HeaderTestSuite () : TestSuite ("ipv4-header", UNIT) |
279 { | 279 { |
280 AddTestCase (new Ipv4HeaderTest, TestCase::QUICK); | 280 AddTestCase (new Ipv4HeaderTest, TestCase::QUICK); |
281 } | 281 } |
282 }; | 282 }; |
283 | 283 |
284 static Ipv4HeaderTestSuite g_ipv4HeaderTestSuite; //!< Static variable for test
initialization | 284 static Ipv4HeaderTestSuite g_ipv4HeaderTestSuite; //!< Static variable for test
initialization |
LEFT | RIGHT |