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

(-)a/src/internet-node/arp-cache.cc (+2 lines)
 Lines 109-114   ArpCache::Entry * Link Here 
109
ArpCache::Entry *
109
ArpCache::Entry *
110
ArpCache::Add (Ipv4Address to)
110
ArpCache::Add (Ipv4Address to)
111
{
111
{
112
  NS_ASSERT (m_arpCache.find (to) == m_arpCache.end ());
113
112
  ArpCache::Entry *entry = new ArpCache::Entry (this);
114
  ArpCache::Entry *entry = new ArpCache::Entry (this);
113
  m_arpCache[to] = entry;  
115
  m_arpCache[to] = entry;  
114
  return entry;
116
  return entry;
(-)a/src/internet-node/arp-ipv4-interface.cc (-1 / +14 lines)
 Lines 21-26    Link Here 
21
 */
21
 */
22
22
23
#include "ns3/packet.h"
23
#include "ns3/packet.h"
24
#include "ns3/debug.h"
24
#include "ns3/composite-trace-resolver.h"
25
#include "ns3/composite-trace-resolver.h"
25
#include "ns3/node.h"
26
#include "ns3/node.h"
26
#include "ns3/net-device.h"
27
#include "ns3/net-device.h"
 Lines 60-66   ArpIpv4Interface::SendTo (Packet p, Ipv4 Link Here 
60
    {
61
    {
61
      Ptr<ArpPrivate> arp = m_node->QueryInterface<ArpPrivate> (ArpPrivate::iid);
62
      Ptr<ArpPrivate> arp = m_node->QueryInterface<ArpPrivate> (ArpPrivate::iid);
62
      MacAddress hardwareDestination;
63
      MacAddress hardwareDestination;
63
      bool found = arp->Lookup (p, dest, GetDevice (), &hardwareDestination);
64
      bool found;
65
66
      if (dest.IsBroadcast ())
67
        {
68
           hardwareDestination = GetDevice ()->GetBroadcast ();
69
           found = true;
70
        }
71
      else
72
        {
73
          Ptr<ArpPrivate> arp = m_node->QueryInterface<ArpPrivate> (ArpPrivate::iid);
74
          found = arp->Lookup (p, dest, GetDevice (), &hardwareDestination);
75
        }
76
64
      if (found)
77
      if (found)
65
        {
78
        {
66
          GetDevice ()->Send (p, hardwareDestination, Ipv4L3Protocol::PROT_NUMBER);
79
          GetDevice ()->Send (p, hardwareDestination, Ipv4L3Protocol::PROT_NUMBER);
(-)a/src/internet-node/arp-l3-protocol.cc (+22 lines)
 Lines 87-92   ArpL3Protocol::Receive(Packet& packet, P Link Here 
87
  ArpCache *cache = FindCache (device);
87
  ArpCache *cache = FindCache (device);
88
  ArpHeader arp;
88
  ArpHeader arp;
89
  packet.RemoveHeader (arp);
89
  packet.RemoveHeader (arp);
90
  
91
  NS_DEBUG ("ARP: received "<< (arp.IsRequest ()? "request" : "reply") <<
92
            " node="<<m_node->GetId ()<<", got request from " <<
93
            arp.GetSourceIpv4Address () << " for address " <<
94
            arp.GetDestinationIpv4Address () << "; we have address " <<
95
            cache->GetInterface ()->GetAddress ());
96
90
  if (arp.IsRequest () && 
97
  if (arp.IsRequest () && 
91
      arp.GetDestinationIpv4Address () == cache->GetInterface ()->GetAddress ()) 
98
      arp.GetDestinationIpv4Address () == cache->GetInterface ()->GetAddress ()) 
92
    {
99
    {
 Lines 128-133   ArpL3Protocol::Receive(Packet& packet, P Link Here 
128
	  // XXX report packet as dropped.
135
	  // XXX report packet as dropped.
129
        }
136
        }
130
    }
137
    }
138
  else
139
    {
140
      NS_DEBUG ("node="<<m_node->GetId ()<<", got request from " <<
141
                arp.GetSourceIpv4Address () << " for unknown address " <<
142
                arp.GetDestinationIpv4Address () << " -- drop");
143
    }
131
}
144
}
132
bool 
145
bool 
133
ArpL3Protocol::Lookup (Packet &packet, Ipv4Address destination, 
146
ArpL3Protocol::Lookup (Packet &packet, Ipv4Address destination, 
 Lines 203-208   ArpL3Protocol::SendArpRequest (ArpCache Link Here 
203
ArpL3Protocol::SendArpRequest (ArpCache const *cache, Ipv4Address to)
216
ArpL3Protocol::SendArpRequest (ArpCache const *cache, Ipv4Address to)
204
{
217
{
205
  ArpHeader arp;
218
  ArpHeader arp;
219
  NS_DEBUG ("ARP: sending request from node "<<m_node->GetId ()<<
220
            " || src: " << cache->GetDevice ()->GetAddress () <<
221
            " / " << cache->GetInterface ()->GetAddress () <<
222
            " || dst: " << cache->GetDevice ()->GetBroadcast () <<
223
            " / " << to);
206
  arp.SetRequest (cache->GetDevice ()->GetAddress (),
224
  arp.SetRequest (cache->GetDevice ()->GetAddress (),
207
		  cache->GetInterface ()->GetAddress (), 
225
		  cache->GetInterface ()->GetAddress (), 
208
                  cache->GetDevice ()->GetBroadcast (),
226
                  cache->GetDevice ()->GetBroadcast (),
 Lines 216-221   ArpL3Protocol::SendArpReply (ArpCache co Link Here 
216
ArpL3Protocol::SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac)
234
ArpL3Protocol::SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac)
217
{
235
{
218
  ArpHeader arp;
236
  ArpHeader arp;
237
  NS_DEBUG ("ARP: sending reply from node "<<m_node->GetId ()<<
238
            "|| src: " << cache->GetDevice ()->GetAddress () << 
239
            " / " << cache->GetInterface ()->GetAddress () <<
240
            " || dst: " << toMac << " / " << toIp);
219
  arp.SetReply (cache->GetDevice ()->GetAddress (),
241
  arp.SetReply (cache->GetDevice ()->GetAddress (),
220
                cache->GetInterface ()->GetAddress (),
242
                cache->GetInterface ()->GetAddress (),
221
                toMac, toIp);
243
                toMac, toIp);
(-)a/src/internet-node/ipv4-l3-protocol.cc (-18 / +35 lines)
 Lines 404-426   Ipv4L3Protocol::Send (Packet const &pack Link Here 
404
404
405
  m_identification ++;
405
  m_identification ++;
406
406
407
  // XXX Note here that in most ipv4 stacks in the world,
407
  if (destination.IsBroadcast ())
408
  // the route calculation for an outgoing packet is not
408
    {
409
  // done in the ip layer. It is done within the application
409
      uint32_t ifaceIndex = 0;
410
  // socket when the first packet is sent to avoid this
410
      for (Ipv4InterfaceList::iterator ifaceIter = m_interfaces.begin ();
411
  // costly lookup on a per-packet basis.
411
           ifaceIter != m_interfaces.end (); ifaceIter++, ifaceIndex++)
412
  // That would require us to get the route from the packet,
412
        {
413
  // most likely with a packet tag. The higher layers do not
413
          Ipv4Interface *outInterface = *ifaceIter;
414
  // do this yet for us.
414
          Packet packetCopy = packet;
415
  Ipv4Route *route = Lookup (ipHeader.GetDestination ());
415
416
  if (route == 0) 
416
          NS_ASSERT (packetCopy.GetSize () <= outInterface->GetMtu ());
417
    {
417
          packetCopy.AddHeader (ipHeader);
418
      NS_DEBUG ("not for me -- forwarding but no route to host. drop.");
418
          m_txTrace (packetCopy, ifaceIndex);
419
      m_dropTrace (packet);
419
          outInterface->Send (packetCopy, destination);
420
      return;
420
        }
421
    }
421
    }
422
422
  else
423
  SendRealOut (packet, ipHeader, *route);
423
    {
424
      // XXX Note here that in most ipv4 stacks in the world,
425
      // the route calculation for an outgoing packet is not
426
      // done in the ip layer. It is done within the application
427
      // socket when the first packet is sent to avoid this
428
      // costly lookup on a per-packet basis.
429
      // That would require us to get the route from the packet,
430
      // most likely with a packet tag. The higher layers do not
431
      // do this yet for us.
432
      Ipv4Route *route = Lookup (ipHeader.GetDestination ());
433
      if (route == 0) 
434
        {
435
          NS_DEBUG ("not for me -- forwarding but no route to host. drop.");
436
          m_dropTrace (packet);
437
          return;
438
        }
439
      SendRealOut (packet, ipHeader, *route);
440
    }
424
}
441
}
425
442
426
void
443
void
 Lines 470-476   Ipv4L3Protocol::Forwarding (Packet const Link Here 
470
	}
487
	}
471
    }
488
    }
472
      
489
      
473
  if (ipHeader.GetDestination ().IsEqual (Ipv4Address::GetBroadcast ())) 
490
  if (ipHeader.GetDestination ().IsBroadcast ()) 
474
    {
491
    {
475
      NS_DEBUG ("for me 3");
492
      NS_DEBUG ("for me 3");
476
      return false;
493
      return false;
(-)a/src/node/ipv4-address.cc (+12 lines)
 Lines 145-150   Ipv4Address::IsEqual (Ipv4Address other) Link Here 
145
  }
145
  }
146
}
146
}
147
147
148
bool
149
Ipv4Address::IsBroadcast (void) const
150
{
151
  return (m_address == 0xffffffffU);
152
}
153
154
Ipv4Address
155
Ipv4Address::CombineMask (Ipv4Mask const &mask) const
156
{
157
  return Ipv4Address (GetHostOrder () & mask.GetHostOrder ());
158
}
159
148
bool 
160
bool 
149
Ipv4Address::IsMulticast (void)
161
Ipv4Address::IsMulticast (void)
150
{
162
{
(-)a/src/node/ipv4-address.h (-1 / +14 lines)
 Lines 26-31    Link Here 
26
#include <ostream>
26
#include <ostream>
27
27
28
namespace ns3 {
28
namespace ns3 {
29
30
class Ipv4Mask;
29
31
30
/** Ipv4 addresses are stored in host order in
32
/** Ipv4 addresses are stored in host order in
31
  * this class.
33
  * this class.
 Lines 80-87   public: Link Here 
80
   */
82
   */
81
  void Print (std::ostream &os) const;
83
  void Print (std::ostream &os) const;
82
84
83
  bool IsBroadcast (void);
85
  bool IsBroadcast (void) const;
84
  bool IsMulticast (void);
86
  bool IsMulticast (void);
87
  
88
  /**
89
   * \brief Combine this address with a network mask
90
   *
91
   * This method returns an IPv4 address that is this address combined
92
   * (bitwise and) with a network mask, yielding an IPv4 network
93
   * address.
94
   *
95
   * \param a network mask 
96
   */
97
  Ipv4Address CombineMask (Ipv4Mask const &mask) const;
85
98
86
  static Ipv4Address GetZero (void);
99
  static Ipv4Address GetZero (void);
87
  static Ipv4Address GetAny (void);
100
  static Ipv4Address GetAny (void);

Return to bug 36