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

(-)ns-3-dev/src/internet-node/arp-cache.cc (+2 lines)
 Lines 109-114   ArpCache::Lookup (Ipv4Address to) 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;
(-)ns-3-dev/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);
(-)ns-3-dev/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   void 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   void 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);
(-)ns-3-dev/src/internet-node/ipv4-l3-protocol.cc (-16 / +39 lines)
 Lines 322-327   Ipv4L3Protocol::AddIpv4Interface (Ipv4In Link Here 
322
  uint32_t index = m_nInterfaces;
322
  uint32_t index = m_nInterfaces;
323
  m_interfaces.push_back (interface);
323
  m_interfaces.push_back (interface);
324
  m_nInterfaces++;
324
  m_nInterfaces++;
325
  if (interface->IsUp ())
326
    {
327
      AddNetworkRouteTo (interface->GetAddress () & interface->GetNetworkMask (),
328
                         interface->GetNetworkMask (), index);
329
    }
325
  return index;
330
  return index;
326
}
331
}
327
Ipv4Interface *
332
Ipv4Interface *
 Lines 404-426   Ipv4L3Protocol::Send (Packet const &pack Link Here 
404
409
405
  m_identification ++;
410
  m_identification ++;
406
411
407
  // XXX Note here that in most ipv4 stacks in the world,
412
  if (destination.IsBroadcast ())
408
  // the route calculation for an outgoing packet is not
409
  // done in the ip layer. It is done within the application
410
  // socket when the first packet is sent to avoid this
411
  // costly lookup on a per-packet basis.
412
  // That would require us to get the route from the packet,
413
  // most likely with a packet tag. The higher layers do not
414
  // do this yet for us.
415
  Ipv4Route *route = Lookup (ipHeader.GetDestination ());
416
  if (route == 0) 
417
    {
413
    {
418
      NS_DEBUG ("not for me -- forwarding but no route to host. drop.");
414
      Packet packet1 = packet;
419
      m_dropTrace (packet);
415
      packet1.AddHeader (ipHeader);
420
      return;
421
    }
422
416
423
  SendRealOut (packet, ipHeader, *route);
417
      for (Ipv4InterfaceList::iterator ifaceIter = m_interfaces.begin ();
418
           ifaceIter != m_interfaces.end (); ifaceIter++)
419
        {
420
          Ipv4Interface *outInterface = *ifaceIter;
421
          // XXX log trace here.
422
          NS_ASSERT (packet.GetSize () <= outInterface->GetMtu ());
423
          outInterface->Send (packet1, destination);
424
        }
425
    }
426
  else
427
    {
428
      // XXX Note here that in most ipv4 stacks in the world,
429
      // the route calculation for an outgoing packet is not
430
      // done in the ip layer. It is done within the application
431
      // socket when the first packet is sent to avoid this
432
      // costly lookup on a per-packet basis.
433
      // That would require us to get the route from the packet,
434
      // most likely with a packet tag. The higher layers do not
435
      // do this yet for us.
436
      Ipv4Route *route = Lookup (ipHeader.GetDestination ());
437
      if (route == 0) 
438
        {
439
          NS_DEBUG ("not for me -- forwarding but no route to host. drop.");
440
          m_dropTrace (packet);
441
          return;
442
        }
443
      SendRealOut (packet, ipHeader, *route);
444
    }
424
}
445
}
425
446
426
void
447
void
 Lines 470-476   Ipv4L3Protocol::Forwarding (Packet const Link Here 
470
	}
491
	}
471
    }
492
    }
472
      
493
      
473
  if (ipHeader.GetDestination ().IsEqual (Ipv4Address::GetBroadcast ())) 
494
  if (ipHeader.GetDestination ().IsBroadcast ()) 
474
    {
495
    {
475
      NS_DEBUG ("for me 3");
496
      NS_DEBUG ("for me 3");
476
      return false;
497
      return false;
 Lines 551-556   Ipv4L3Protocol::SetUp (uint32_t i) Link Here 
551
{
572
{
552
  Ipv4Interface *interface = GetInterface (i);
573
  Ipv4Interface *interface = GetInterface (i);
553
  interface->SetUp ();
574
  interface->SetUp ();
575
  AddNetworkRouteTo (interface->GetAddress () & interface->GetNetworkMask (),
576
                     interface->GetNetworkMask (), i);
554
}
577
}
555
void 
578
void 
556
Ipv4L3Protocol::SetDown (uint32_t i)
579
Ipv4L3Protocol::SetDown (uint32_t i)
(-)ns-3-dev/src/node/ipv4-address.h (-1 / +10 lines)
 Lines 80-86   public: Link Here 
80
   */
80
   */
81
  void Print (std::ostream &os) const;
81
  void Print (std::ostream &os) const;
82
82
83
  bool IsBroadcast (void);
83
  bool IsBroadcast (void) const {
84
    return (m_address == 0xffffffffU);
85
  }
86
84
  bool IsMulticast (void);
87
  bool IsMulticast (void);
85
88
86
  static Ipv4Address GetZero (void);
89
  static Ipv4Address GetZero (void);
 Lines 128-133   public: Link Here 
128
};
131
};
129
bool operator != (Ipv4Address const &a, Ipv4Address const &b);
132
bool operator != (Ipv4Address const &a, Ipv4Address const &b);
130
133
134
135
inline Ipv4Address operator & (Ipv4Address const &address, Ipv4Mask const &mask)
136
{
137
  return Ipv4Address (address.GetHostOrder () & mask.GetHostOrder ());
138
}
139
131
}; // namespace ns3
140
}; // namespace ns3
132
141
133
#endif /* IPV4_ADDRESS_H */
142
#endif /* IPV4_ADDRESS_H */

Return to bug 36