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

(-)a/src/internet-stack/ipv4-l3-protocol.cc (+11 lines)
 Lines 520-525    Link Here 
520
520
521
void 
521
void 
522
Ipv4L3Protocol::Send (Ptr<Packet> packet, 
522
Ipv4L3Protocol::Send (Ptr<Packet> packet, 
523
                      Ipv4Header ipHeader,
524
                      Ptr<Ipv4Route> route)
525
{
526
  NS_LOG_FUNCTION (this << packet << ipHeader << route);
527
  Ipv4Header hdr;
528
  packet->RemoveHeader (hdr);
529
  SendRealOut (route, packet, hdr);
530
}
531
532
void 
533
Ipv4L3Protocol::Send (Ptr<Packet> packet, 
523
            Ipv4Address source, 
534
            Ipv4Address source, 
524
            Ipv4Address destination,
535
            Ipv4Address destination,
525
            uint8_t protocol,
536
            uint8_t protocol,
(-)a/src/internet-stack/ipv4-l3-protocol.h (+9 lines)
 Lines 162-167    Link Here 
162
   */
162
   */
163
  void Send (Ptr<Packet> packet, Ipv4Address source, 
163
  void Send (Ptr<Packet> packet, Ipv4Address source, 
164
	     Ipv4Address destination, uint8_t protocol, Ptr<Ipv4Route> route);
164
	     Ipv4Address destination, uint8_t protocol, Ptr<Ipv4Route> route);
165
  /**
166
   * \param packet packet to send
167
   * \param ipHeader IP Heeader
168
   * \param route route entry
169
   *
170
   * Higher-level layers call this method to send a packet with IPv4 Header
171
   * (Intend to be used with IpHeaderInclude attribute.)
172
   */
173
  void Send (Ptr<Packet> packet, Ipv4Header ipHeader, Ptr<Ipv4Route> route);
165
174
166
  uint32_t AddInterface (Ptr<NetDevice> device);
175
  uint32_t AddInterface (Ptr<NetDevice> device);
167
  Ptr<Ipv4Interface> GetInterface (uint32_t i) const;
176
  Ptr<Ipv4Interface> GetInterface (uint32_t i) const;
(-)a/src/internet-stack/ipv4-raw-socket-impl.cc (-3 / +32 lines)
 Lines 7-12    Link Here 
7
#include "ns3/node.h"
7
#include "ns3/node.h"
8
#include "ns3/packet.h"
8
#include "ns3/packet.h"
9
#include "ns3/uinteger.h"
9
#include "ns3/uinteger.h"
10
#include "ns3/boolean.h"
10
#include "ns3/log.h"
11
#include "ns3/log.h"
11
12
12
NS_LOG_COMPONENT_DEFINE ("Ipv4RawSocketImpl");
13
NS_LOG_COMPONENT_DEFINE ("Ipv4RawSocketImpl");
 Lines 29-34    Link Here 
29
		   UintegerValue (0),
30
		   UintegerValue (0),
30
		   MakeUintegerAccessor (&Ipv4RawSocketImpl::m_icmpFilter),
31
		   MakeUintegerAccessor (&Ipv4RawSocketImpl::m_icmpFilter),
31
		   MakeUintegerChecker<uint32_t> ())
32
		   MakeUintegerChecker<uint32_t> ())
33
    // 
34
    //  from raw (7), linux, returned length of Send/Recv should be
35
    // 
36
    //            | IP_HDRINC on  |      off    |
37
    //  ----------+---------------+-------------+-
38
    //  Send(Ipv4)| hdr + payload | payload     |
39
    //  Recv(Ipv4)| hdr + payload | hdr+payload |
40
    //  ----------+---------------+-------------+-
41
    .AddAttribute ("IpHeaderInclude", 
42
		   "Include IP Header information (a.k.a setsockopt (IP_HDRINCL)).",
43
		   BooleanValue (false),
44
		   MakeBooleanAccessor (&Ipv4RawSocketImpl::m_iphdrincl),
45
		   MakeBooleanChecker ())
32
    ;
46
    ;
33
  return tid;
47
  return tid;
34
}
48
}
 Lines 175-182    Link Here 
175
  if (ipv4->GetRoutingProtocol ())
189
  if (ipv4->GetRoutingProtocol ())
176
    {
190
    {
177
      Ipv4Header header;
191
      Ipv4Header header;
178
      header.SetDestination (dst);
192
      if (!m_iphdrincl)
179
      header.SetProtocol (m_protocol);
193
        {
194
          header.SetDestination (dst);
195
          header.SetProtocol (m_protocol);
196
        }
197
      else
198
        {
199
          p->PeekHeader (header);
200
          dst = header.GetDestination ();
201
        }
180
      SocketErrno errno_ = ERROR_NOTERROR;//do not use errno as it is the standard C last error number 
202
      SocketErrno errno_ = ERROR_NOTERROR;//do not use errno as it is the standard C last error number 
181
      Ptr<Ipv4Route> route;
203
      Ptr<Ipv4Route> route;
182
      Ptr<NetDevice> oif = m_boundnetdevice; //specify non-zero if bound to a source address
204
      Ptr<NetDevice> oif = m_boundnetdevice; //specify non-zero if bound to a source address
 Lines 193-199    Link Here 
193
      if (route != 0)
215
      if (route != 0)
194
        {
216
        {
195
          NS_LOG_LOGIC ("Route exists");
217
          NS_LOG_LOGIC ("Route exists");
196
          ipv4->Send (p, route->GetSource (), dst, m_protocol, route);
218
          if (!m_iphdrincl)
219
            {
220
              ipv4->Send (p, route->GetSource (), dst, m_protocol, route);
221
            }
222
          else
223
            {
224
              ipv4->Send (p, header, route);
225
            }
197
          NotifyDataSent (p->GetSize ());
226
          NotifyDataSent (p->GetSize ());
198
          NotifySend (GetTxAvailable ());
227
          NotifySend (GetTxAvailable ());
199
          return p->GetSize();
228
          return p->GetSize();
(-)a/src/internet-stack/ipv4-raw-socket-impl.h (+1 lines)
 Lines 59-64    Link Here 
59
  bool m_shutdownSend;
59
  bool m_shutdownSend;
60
  bool m_shutdownRecv;
60
  bool m_shutdownRecv;
61
  uint32_t m_icmpFilter;
61
  uint32_t m_icmpFilter;
62
  bool m_iphdrincl;
62
};
63
};
63
64
64
} // namespace ns3
65
} // namespace ns3
(-)a/src/internet-stack/ipv4-raw-test.cc (+40 lines)
 Lines 33-38    Link Here 
33
#include "ns3/log.h"
33
#include "ns3/log.h"
34
#include "ns3/node.h"
34
#include "ns3/node.h"
35
#include "ns3/inet-socket-address.h"
35
#include "ns3/inet-socket-address.h"
36
#include "ns3/boolean.h"
36
37
37
#include "arp-l3-protocol.h"
38
#include "arp-l3-protocol.h"
38
#include "ipv4-l3-protocol.h"
39
#include "ipv4-l3-protocol.h"
 Lines 74-79    Link Here 
74
  Ptr<Packet> m_receivedPacket2;
75
  Ptr<Packet> m_receivedPacket2;
75
  void DoSendData (Ptr<Socket> socket, std::string to);
76
  void DoSendData (Ptr<Socket> socket, std::string to);
76
  void SendData (Ptr<Socket> socket, std::string to);
77
  void SendData (Ptr<Socket> socket, std::string to);
78
  void DoSendData_IpHdr (Ptr<Socket> socket, std::string to);
79
  void SendData_IpHdr (Ptr<Socket> socket, std::string to);
77
80
78
public:
81
public:
79
  virtual bool DoRun (void);
82
  virtual bool DoRun (void);
 Lines 139-144    Link Here 
139
  Simulator::Run ();
142
  Simulator::Run ();
140
}
143
}
141
144
145
void
146
Ipv4RawSocketImplTest::DoSendData_IpHdr (Ptr<Socket> socket, std::string to)
147
{
148
  Address realTo = InetSocketAddress (Ipv4Address(to.c_str()), 0);
149
  socket->SetAttribute ("IpHeaderInclude", BooleanValue (true));
150
  Ptr<Packet> p = Create<Packet> (123);
151
  Ipv4Header ipHeader;
152
  ipHeader.SetSource (Ipv4Address ("10.0.0.2"));
153
  ipHeader.SetDestination (Ipv4Address (to.c_str ()));
154
  ipHeader.SetProtocol (0);
155
  ipHeader.SetPayloadSize (p->GetSize ());
156
  ipHeader.SetTtl (255);
157
  p->AddHeader (ipHeader);
158
159
  NS_TEST_EXPECT_MSG_EQ (socket->SendTo (p, 0, realTo),
160
                         143, to);
161
  socket->SetAttribute ("IpHeaderInclude", BooleanValue (false));
162
}
163
164
void
165
Ipv4RawSocketImplTest::SendData_IpHdr (Ptr<Socket> socket, std::string to)
166
{
167
  m_receivedPacket = Create<Packet> ();
168
  m_receivedPacket2 = Create<Packet> ();
169
  Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (0),
170
                                  &Ipv4RawSocketImplTest::DoSendData_IpHdr, this, socket, to);
171
  Simulator::Run ();
172
}
173
142
bool
174
bool
143
Ipv4RawSocketImplTest::DoRun (void)
175
Ipv4RawSocketImplTest::DoRun (void)
144
{
176
{
 Lines 229-234    Link Here 
229
  m_receivedPacket->RemoveAllByteTags ();
261
  m_receivedPacket->RemoveAllByteTags ();
230
  m_receivedPacket2->RemoveAllByteTags ();
262
  m_receivedPacket2->RemoveAllByteTags ();
231
263
264
  // Unicast w/ header test
265
  SendData_IpHdr (txSocket, "10.0.0.1");
266
  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 143, "recv(hdrincl): 10.0.0.1");
267
  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 0, "second interface should not receive it");
268
269
  m_receivedPacket->RemoveAllByteTags ();
270
  m_receivedPacket2->RemoveAllByteTags ();
271
232
#if 0
272
#if 0
233
  // Simple broadcast test
273
  // Simple broadcast test
234
274

Return to bug 932