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

(-)a/src/core/log.h (+14 lines)
 Lines 108-113    Link Here 
108
    }                                                   \
108
    }                                                   \
109
  while (false)
109
  while (false)
110
110
111
#define NS_LOG_M(level)                                 \
112
  do                                                    \
113
    {                                                   \
114
      if (g_log.IsEnabled (level))                      \
115
        {                                               \
116
          std::clog << __PRETTY_FUNCTION__              \
117
                    <<"(this="<<this<<")" << std::endl; \
118
        }                                               \
119
    }                                                   \
120
  while (false)
121
111
#define NS_LOG_ERROR(msg) \
122
#define NS_LOG_ERROR(msg) \
112
  NS_LOG(ns3::LOG_ERROR, msg)
123
  NS_LOG(ns3::LOG_ERROR, msg)
113
124
 Lines 122-127    Link Here 
122
133
123
#define NS_LOG_FUNCTION \
134
#define NS_LOG_FUNCTION \
124
  NS_LOG_F(ns3::LOG_FUNCTION)
135
  NS_LOG_F(ns3::LOG_FUNCTION)
136
137
#define NS_LOG_METHOD \
138
  NS_LOG_M(ns3::LOG_FUNCTION)
125
139
126
#define NS_LOG_PARAM(msg) \
140
#define NS_LOG_PARAM(msg) \
127
  NS_LOG(ns3::LOG_PARAM, msg)
141
  NS_LOG(ns3::LOG_PARAM, msg)
(-)a/src/internet-node/ipv4-end-point-demux.cc (-9 / +29 lines)
 Lines 85-97   Ipv4EndPointDemux::Allocate (void) Link Here 
85
    }
85
    }
86
  Ipv4EndPoint *endPoint = new Ipv4EndPoint (Ipv4Address::GetAny (), port);
86
  Ipv4EndPoint *endPoint = new Ipv4EndPoint (Ipv4Address::GetAny (), port);
87
  m_endPoints.push_back (endPoint);
87
  m_endPoints.push_back (endPoint);
88
  NS_LOG_DEBUG ("Now have >>" << m_endPoints.size () << "<< endpoints.");
88
  return endPoint;
89
  return endPoint;
89
}
90
}
90
91
91
Ipv4EndPoint *
92
Ipv4EndPoint *
92
Ipv4EndPointDemux::Allocate (Ipv4Address address)
93
Ipv4EndPointDemux::Allocate (Ipv4Address address)
93
{
94
{
94
  NS_LOG_FUNCTION;
95
  NS_LOG_METHOD;
95
  NS_LOG_PARAM ("(" << address << ")");
96
  NS_LOG_PARAM ("(" << address << ")");
96
  uint16_t port = AllocateEphemeralPort ();
97
  uint16_t port = AllocateEphemeralPort ();
97
  if (port == 0) 
98
  if (port == 0) 
 Lines 101-120   Ipv4EndPointDemux::Allocate (Ipv4Address Link Here 
101
    }
102
    }
102
  Ipv4EndPoint *endPoint = new Ipv4EndPoint (address, port);
103
  Ipv4EndPoint *endPoint = new Ipv4EndPoint (address, port);
103
  m_endPoints.push_back (endPoint);
104
  m_endPoints.push_back (endPoint);
105
  NS_LOG_DEBUG ("Now have >>" << m_endPoints.size () << "<< endpoints.");
104
  return endPoint;
106
  return endPoint;
105
}
107
}
106
108
107
Ipv4EndPoint *
109
Ipv4EndPoint *
108
Ipv4EndPointDemux::Allocate (uint16_t port)
110
Ipv4EndPointDemux::Allocate (uint16_t port)
109
{
111
{
110
  NS_LOG_FUNCTION;
112
  NS_LOG_METHOD;
111
  return Allocate (Ipv4Address::GetAny (), port);
113
  return Allocate (Ipv4Address::GetAny (), port);
112
}
114
}
113
115
114
Ipv4EndPoint *
116
Ipv4EndPoint *
115
Ipv4EndPointDemux::Allocate (Ipv4Address address, uint16_t port)
117
Ipv4EndPointDemux::Allocate (Ipv4Address address, uint16_t port)
116
{
118
{
117
  NS_LOG_FUNCTION;
119
  NS_LOG_METHOD;
118
  NS_LOG_PARAM ("(" << address << ", " << port << ")");
120
  NS_LOG_PARAM ("(" << address << ", " << port << ")");
119
  if (LookupLocal (address, port)) 
121
  if (LookupLocal (address, port)) 
120
    {
122
    {
 Lines 123-128   Ipv4EndPointDemux::Allocate (Ipv4Address Link Here 
123
    }
125
    }
124
  Ipv4EndPoint *endPoint = new Ipv4EndPoint (address, port);
126
  Ipv4EndPoint *endPoint = new Ipv4EndPoint (address, port);
125
  m_endPoints.push_back (endPoint);
127
  m_endPoints.push_back (endPoint);
128
  NS_LOG_DEBUG ("Now have >>" << m_endPoints.size () << "<< endpoints.");
126
  return endPoint;
129
  return endPoint;
127
}
130
}
128
131
 Lines 150-155   Ipv4EndPointDemux::Allocate (Ipv4Address Link Here 
150
  Ipv4EndPoint *endPoint = new Ipv4EndPoint (localAddress, localPort);
153
  Ipv4EndPoint *endPoint = new Ipv4EndPoint (localAddress, localPort);
151
  endPoint->SetPeer (peerAddress, peerPort);
154
  endPoint->SetPeer (peerAddress, peerPort);
152
  m_endPoints.push_back (endPoint);
155
  m_endPoints.push_back (endPoint);
156
157
  NS_LOG_DEBUG ("Now have >>" << m_endPoints.size () << "<< endpoints.");
158
153
  return endPoint;
159
  return endPoint;
154
}
160
}
155
161
 Lines 175-183   Ipv4EndPointDemux::DeAllocate (Ipv4EndPo Link Here 
175
 */
181
 */
176
Ipv4EndPointDemux::EndPoints
182
Ipv4EndPointDemux::EndPoints
177
Ipv4EndPointDemux::Lookup (Ipv4Address daddr, uint16_t dport, 
183
Ipv4EndPointDemux::Lookup (Ipv4Address daddr, uint16_t dport, 
178
                           Ipv4Address saddr, uint16_t sport)
184
                           Ipv4Address saddr, uint16_t sport,
179
{
185
                           Ptr<Ipv4Interface> interface)
180
  NS_LOG_FUNCTION;
186
{
187
  NS_LOG_METHOD;
181
  uint32_t genericity = 3;
188
  uint32_t genericity = 3;
182
  Ipv4EndPoint *generic = 0;
189
  Ipv4EndPoint *generic = 0;
183
  EndPoints retval;
190
  EndPoints retval;
 Lines 187-205   Ipv4EndPointDemux::Lookup (Ipv4Address d Link Here 
187
194
188
  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
195
  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
189
    {
196
    {
197
      NS_LOG_DEBUG ("Looking at endpoint dport=" << (*i)->GetLocalPort ()
198
                    << " daddr=" << (*i)->GetLocalAddress ()
199
                    << " sport=" << (*i)->GetPeerPort ()
200
                    << " saddr=" << (*i)->GetPeerAddress ());
190
      if ((*i)->GetLocalPort () != dport) 
201
      if ((*i)->GetLocalPort () != dport) 
191
        {
202
        {
203
          NS_LOG_LOGIC ("Skipping endpoint " << &(*i)
204
                        << " because endpoint dport "
205
                        << (*i)->GetLocalPort ()
206
                        << " does not match packet dport " << dport);
192
          continue;
207
          continue;
193
        }
208
        }
209
      bool isBroadcast = 
210
        (daddr.IsBroadcast () ||
211
         daddr.IsSubnetDirectedBroadcast (interface->GetNetworkMask ()));
212
      NS_LOG_DEBUG ("dest addr " << daddr << " broadcast? " << isBroadcast);
213
194
      NS_LOG_LOGIC ("Local address matches: " << 
214
      NS_LOG_LOGIC ("Local address matches: " << 
195
        bool ((*i)->GetLocalAddress () == daddr || daddr.IsBroadcast ()));
215
        bool ((*i)->GetLocalAddress () == daddr || isBroadcast));
196
      NS_LOG_LOGIC ("Peer port matches: " << 
216
      NS_LOG_LOGIC ("Peer port matches: " << 
197
        bool ((*i)->GetPeerPort () == sport || sport == 0));
217
        bool ((*i)->GetPeerPort () == sport || (*i)->GetPeerPort () == 0));
198
      NS_LOG_LOGIC ("Peer address matches: " << 
218
      NS_LOG_LOGIC ("Peer address matches: " << 
199
        bool ((*i)->GetPeerAddress () == saddr ||
219
        bool ((*i)->GetPeerAddress () == saddr ||
200
        (*i)->GetPeerAddress () == Ipv4Address::GetAny ()));
220
        (*i)->GetPeerAddress () == Ipv4Address::GetAny ()));
201
      
221
      
202
      if ( ((*i)->GetLocalAddress () == daddr || daddr.IsBroadcast ())
222
      if ( ((*i)->GetLocalAddress () == daddr || isBroadcast)
203
           && ((*i)->GetPeerPort () == sport || (*i)->GetPeerPort () == 0)
223
           && ((*i)->GetPeerPort () == sport || (*i)->GetPeerPort () == 0)
204
           && ((*i)->GetPeerAddress () == saddr || (*i)->GetPeerAddress () == Ipv4Address::GetAny ()))
224
           && ((*i)->GetPeerAddress () == saddr || (*i)->GetPeerAddress () == Ipv4Address::GetAny ()))
205
        {
225
        {
(-)a/src/internet-node/ipv4-end-point-demux.h (-1 / +3 lines)
 Lines 25-30    Link Here 
25
#include <stdint.h>
25
#include <stdint.h>
26
#include <list>
26
#include <list>
27
#include "ns3/ipv4-address.h"
27
#include "ns3/ipv4-address.h"
28
#include "ipv4-interface.h"
28
29
29
namespace ns3 {
30
namespace ns3 {
30
31
 Lines 43-49   public: Link Here 
43
  EndPoints Lookup (Ipv4Address daddr, 
44
  EndPoints Lookup (Ipv4Address daddr, 
44
                    uint16_t dport, 
45
                    uint16_t dport, 
45
                    Ipv4Address saddr, 
46
                    Ipv4Address saddr, 
46
                    uint16_t sport);
47
                    uint16_t sport,
48
                    Ptr<Ipv4Interface> interface);
47
49
48
  Ipv4EndPoint *Allocate (void);
50
  Ipv4EndPoint *Allocate (void);
49
  Ipv4EndPoint *Allocate (Ipv4Address address);
51
  Ipv4EndPoint *Allocate (Ipv4Address address);
(-)a/src/internet-node/ipv4-l3-protocol.cc (-4 / +7 lines)
 Lines 546-556   Ipv4L3Protocol::Receive( Ptr<NetDevice> Link Here 
546
  NS_LOG_LOGIC ("Packet from " << from);
546
  NS_LOG_LOGIC ("Packet from " << from);
547
547
548
  uint32_t index = 0;
548
  uint32_t index = 0;
549
  Ptr<Ipv4Interface> ipv4Interface;
549
  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); 
550
  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); 
550
       i != m_interfaces.end (); 
551
       i != m_interfaces.end (); 
551
       i++)
552
       i++)
552
    {
553
    {
553
      if ((*i)->GetDevice () == device)
554
      ipv4Interface = *i;
555
      if (ipv4Interface->GetDevice () == device)
554
        {
556
        {
555
          m_rxTrace (p, index);
557
          m_rxTrace (p, index);
556
          break;
558
          break;
 Lines 572-578   Ipv4L3Protocol::Receive( Ptr<NetDevice> Link Here 
572
    }
574
    }
573
575
574
  NS_LOG_LOGIC ("Forward up");
576
  NS_LOG_LOGIC ("Forward up");
575
  ForwardUp (packet, ipHeader);
577
  ForwardUp (packet, ipHeader, ipv4Interface);
576
}
578
}
577
579
578
580
 Lines 745-758   Ipv4L3Protocol::Forwarding ( Link Here 
745
}
747
}
746
748
747
void
749
void
748
Ipv4L3Protocol::ForwardUp (Packet p, Ipv4Header const&ip)
750
Ipv4L3Protocol::ForwardUp (Packet p, Ipv4Header const&ip,
751
                           Ptr<Ipv4Interface> interface)
749
{
752
{
750
  NS_LOG_FUNCTION;
753
  NS_LOG_FUNCTION;
751
  NS_LOG_PARAM ("(" << &p << ", " << &ip << ")");
754
  NS_LOG_PARAM ("(" << &p << ", " << &ip << ")");
752
755
753
  Ptr<Ipv4L4Demux> demux = m_node->QueryInterface<Ipv4L4Demux> (Ipv4L4Demux::iid);
756
  Ptr<Ipv4L4Demux> demux = m_node->QueryInterface<Ipv4L4Demux> (Ipv4L4Demux::iid);
754
  Ptr<Ipv4L4Protocol> protocol = demux->GetProtocol (ip.GetProtocol ());
757
  Ptr<Ipv4L4Protocol> protocol = demux->GetProtocol (ip.GetProtocol ());
755
  protocol->Receive (p, ip.GetSource (), ip.GetDestination ());
758
  protocol->Receive (p, ip.GetSource (), ip.GetDestination (), interface);
756
}
759
}
757
760
758
void 
761
void 
(-)a/src/internet-node/ipv4-l3-protocol.h (-1 / +1 lines)
 Lines 227-233   private: Link Here 
227
                   Packet const &packet, 
227
                   Packet const &packet, 
228
                   Ipv4Header &ipHeader, 
228
                   Ipv4Header &ipHeader, 
229
                   Ptr<NetDevice> device);
229
                   Ptr<NetDevice> device);
230
  void ForwardUp (Packet p, Ipv4Header const&ip);
230
  void ForwardUp (Packet p, Ipv4Header const&ip, Ptr<Ipv4Interface> interface);
231
  uint32_t AddIpv4Interface (Ptr<Ipv4Interface> interface);
231
  uint32_t AddIpv4Interface (Ptr<Ipv4Interface> interface);
232
  void SetupLoopback (void);
232
  void SetupLoopback (void);
233
233
(-)a/src/internet-node/ipv4-l4-protocol.h (-1 / +3 lines)
 Lines 26-31    Link Here 
26
#define IPV4_L4_PROTOCOL_H
26
#define IPV4_L4_PROTOCOL_H
27
27
28
#include "ns3/object.h"
28
#include "ns3/object.h"
29
#include "ipv4-interface.h"
29
30
30
namespace ns3 {
31
namespace ns3 {
31
32
 Lines 65-71   public: Link Here 
65
   */
66
   */
66
  virtual void Receive(Packet& p, 
67
  virtual void Receive(Packet& p, 
67
                       Ipv4Address const &source,
68
                       Ipv4Address const &source,
68
                       Ipv4Address const &destination) = 0;
69
                       Ipv4Address const &destination,
70
                       Ptr<Ipv4Interface> interface) = 0;
69
protected:
71
protected:
70
  virtual void DoDispose (void);
72
  virtual void DoDispose (void);
71
private:
73
private:
(-)a/src/internet-node/udp-l4-protocol.cc (-3 / +4 lines)
 Lines 123-130   UdpL4Protocol::DeAllocate (Ipv4EndPoint Link Here 
123
123
124
void 
124
void 
125
UdpL4Protocol::Receive(Packet& packet, 
125
UdpL4Protocol::Receive(Packet& packet, 
126
             Ipv4Address const &source,
126
                       Ipv4Address const &source,
127
             Ipv4Address const &destination)
127
                       Ipv4Address const &destination,
128
                       Ptr<Ipv4Interface> interface)
128
{
129
{
129
  NS_LOG_FUNCTION; 
130
  NS_LOG_FUNCTION; 
130
  NS_LOG_PARAM ("(" << &packet << ", " << source << ", " << destination << 
131
  NS_LOG_PARAM ("(" << &packet << ", " << source << ", " << destination << 
 Lines 134-140   UdpL4Protocol::Receive(Packet& packet, Link Here 
134
  packet.RemoveHeader (udpHeader);
135
  packet.RemoveHeader (udpHeader);
135
  Ipv4EndPointDemux::EndPoints endPoints =
136
  Ipv4EndPointDemux::EndPoints endPoints =
136
    m_endPoints->Lookup (destination, udpHeader.GetDestination (),
137
    m_endPoints->Lookup (destination, udpHeader.GetDestination (),
137
                         source, udpHeader.GetSource ());
138
                         source, udpHeader.GetSource (), interface);
138
  for (Ipv4EndPointDemux::EndPointsI endPoint = endPoints.begin ();
139
  for (Ipv4EndPointDemux::EndPointsI endPoint = endPoints.begin ();
139
       endPoint != endPoints.end (); endPoint++)
140
       endPoint != endPoints.end (); endPoint++)
140
    {
141
    {
(-)a/src/internet-node/udp-l4-protocol.h (-1 / +2 lines)
 Lines 85-91   public: Link Here 
85
  // inherited from Ipv4L4Protocol
85
  // inherited from Ipv4L4Protocol
86
  virtual void Receive(Packet& p, 
86
  virtual void Receive(Packet& p, 
87
                       Ipv4Address const &source,
87
                       Ipv4Address const &source,
88
                       Ipv4Address const &destination);
88
                       Ipv4Address const &destination,
89
                       Ptr<Ipv4Interface> interface);
89
protected:
90
protected:
90
  virtual void DoDispose (void);
91
  virtual void DoDispose (void);
91
private:
92
private:
(-)a/src/internet-node/udp-socket.cc (-7 / +7 lines)
 Lines 410-422   UdpSocketTest::RunTests (void) Link Here 
410
410
411
411
412
  // Create the UDP sockets
412
  // Create the UDP sockets
413
  Ptr<SocketFactory> socketFactory = rxNode->QueryInterface<SocketFactory> (Udp::iid);
413
  Ptr<SocketFactory> rxSocketFactory = rxNode->QueryInterface<SocketFactory> (Udp::iid);
414
  Ptr<Socket> rxSocket = socketFactory->CreateSocket ();
414
  Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
415
  NS_TEST_ASSERT_EQUAL (rxSocket->Bind (InetSocketAddress (1234)), 0);
415
  NS_TEST_ASSERT_EQUAL (rxSocket->Bind (InetSocketAddress (Ipv4Address ("10.0.0.2"), 1234)), 0);
416
  rxSocket->SetRecvCallback (MakeCallback (&UdpSocketTest::ReceivePacket, this));
416
  rxSocket->SetRecvCallback (MakeCallback (&UdpSocketTest::ReceivePacket, this));
417
417
418
  socketFactory = txNode->QueryInterface<SocketFactory> (Udp::iid);
418
  Ptr<SocketFactory> txSocketFactory = txNode->QueryInterface<SocketFactory> (Udp::iid);
419
  Ptr<Socket> txSocket = socketFactory->CreateSocket ();
419
  Ptr<Socket> txSocket = txSocketFactory->CreateSocket ();
420
420
421
  // ------ Now the tests ------------
421
  // ------ Now the tests ------------
422
422
 Lines 440-448   UdpSocketTest::RunTests (void) Link Here 
440
440
441
  // When receiving broadcast packets, all sockets sockets bound to
441
  // When receiving broadcast packets, all sockets sockets bound to
442
  // the address/port should receive a copy of the same packet.
442
  // the address/port should receive a copy of the same packet.
443
  Ptr<Socket> rxSocket2 = socketFactory->CreateSocket ();
443
  Ptr<Socket> rxSocket2 = rxSocketFactory->CreateSocket ();
444
  rxSocket2->SetRecvCallback (MakeCallback (&UdpSocketTest::ReceivePacket2, this));
444
  rxSocket2->SetRecvCallback (MakeCallback (&UdpSocketTest::ReceivePacket2, this));
445
  NS_TEST_ASSERT_EQUAL (rxSocket2->Bind (InetSocketAddress (Ipv4Address ("10.0.0.1"), 1234)), 0);
445
  NS_TEST_ASSERT_EQUAL (rxSocket2->Bind (InetSocketAddress (Ipv4Address ("0.0.0.0"), 1234)), 0);
446
446
447
  m_receivedPacket = Packet ();
447
  m_receivedPacket = Packet ();
448
  m_receivedPacket2 = Packet ();
448
  m_receivedPacket2 = Packet ();

Return to bug 51