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

(-)a/src/internet-stack/ipv4-l3-protocol.cc (+70 lines)
 Lines 362-367    Link Here 
362
  return -1;
362
  return -1;
363
}
363
}
364
364
365
bool
366
Ipv4L3Protocol::IsDestinationAddress (Ipv4Address address, uint32_t iif) const
367
{
368
  NS_LOG_FUNCTION (this << address << " " << iif);
369
370
  // First check the incoming interface for a unicast address match
371
  for (uint32_t i = 0; i < GetNAddresses (iif); i++)
372
    {
373
      Ipv4InterfaceAddress iaddr = GetAddress (iif, i);
374
      if (address.IsEqual (iaddr.GetLocal ()))
375
        {
376
          NS_LOG_LOGIC ("For me (destination " << address << " match)");
377
          return true;
378
        }
379
      if (address.IsEqual (iaddr.GetBroadcast ()))
380
        {
381
          NS_LOG_LOGIC ("For me (interface broadcast address)");
382
          return true;
383
        }
384
    }
385
386
  if (address.IsMulticast ())
387
    {
388
#ifdef NOTYET
389
      if (MulticastCheckGroup (iif, address ))
390
#endif
391
      if (true)
392
        {
393
          NS_LOG_LOGIC ("For me (Ipv4Addr multicast address");
394
          return true;
395
        }
396
    }
397
398
  if (address.IsBroadcast ())
399
    {
400
      NS_LOG_LOGIC ("For me (Ipv4Addr broadcast address)");
401
      return true;
402
    }
403
404
  if (GetWeakEsModel () == true)  // Check other interfaces
405
    { 
406
      for (uint32_t j = 0; j < GetNInterfaces (); j++)
407
        {
408
          if (j == uint32_t (iif)) continue;
409
          for (uint32_t i = 0; i < GetNAddresses (j); i++)
410
            {
411
              Ipv4InterfaceAddress iaddr = GetAddress (j, i);
412
              if (address.IsEqual (iaddr.GetLocal ()))
413
                {
414
                  NS_LOG_LOGIC ("For me (destination " << address << " match) on another interface");
415
                  return true;
416
                }
417
            }
418
        }
419
    }
420
  return false;
421
}
422
365
void 
423
void 
366
Ipv4L3Protocol::Receive( Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from,
424
Ipv4L3Protocol::Receive( Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from,
367
                         const Address &to, NetDevice::PacketType packetType)
425
                         const Address &to, NetDevice::PacketType packetType)
 Lines 909-914    Link Here 
909
  return m_ipForward;
967
  return m_ipForward;
910
}
968
}
911
969
970
void 
971
Ipv4L3Protocol::SetWeakEsModel (bool model)
972
{
973
  m_weakEsModel = model;
974
}
975
976
bool 
977
Ipv4L3Protocol::GetWeakEsModel (void) const
978
{
979
  return m_weakEsModel;
980
}
981
912
void
982
void
913
Ipv4L3Protocol::RouteInputError (Ptr<const Packet> p, const Ipv4Header & ipHeader, Socket::SocketErrno sockErrno)
983
Ipv4L3Protocol::RouteInputError (Ptr<const Packet> p, const Ipv4Header & ipHeader, Socket::SocketErrno sockErrno)
914
{
984
{
(-)a/src/internet-stack/ipv4-l3-protocol.h (+5 lines)
 Lines 169-174    Link Here 
169
  int32_t GetInterfaceForAddress (Ipv4Address addr) const;
169
  int32_t GetInterfaceForAddress (Ipv4Address addr) const;
170
  int32_t GetInterfaceForPrefix (Ipv4Address addr, Ipv4Mask mask) const;
170
  int32_t GetInterfaceForPrefix (Ipv4Address addr, Ipv4Mask mask) const;
171
  int32_t GetInterfaceForDevice (Ptr<const NetDevice> device) const;
171
  int32_t GetInterfaceForDevice (Ptr<const NetDevice> device) const;
172
  bool IsDestinationAddress (Ipv4Address address, uint32_t iif) const;
172
173
173
  bool AddAddress (uint32_t i, Ipv4InterfaceAddress address);
174
  bool AddAddress (uint32_t i, Ipv4InterfaceAddress address);
174
  Ipv4InterfaceAddress GetAddress (uint32_t interfaceIndex, uint32_t addressIndex) const;
175
  Ipv4InterfaceAddress GetAddress (uint32_t interfaceIndex, uint32_t addressIndex) const;
 Lines 199-206    Link Here 
199
  Ipv4L3Protocol(const Ipv4L3Protocol &);
200
  Ipv4L3Protocol(const Ipv4L3Protocol &);
200
  Ipv4L3Protocol &operator = (const Ipv4L3Protocol &);
201
  Ipv4L3Protocol &operator = (const Ipv4L3Protocol &);
201
202
203
  // class Ipv4 attributes
202
  virtual void SetIpForward (bool forward);
204
  virtual void SetIpForward (bool forward);
203
  virtual bool GetIpForward (void) const;
205
  virtual bool GetIpForward (void) const;
206
  virtual void SetWeakEsModel (bool model);
207
  virtual bool GetWeakEsModel (void) const;
204
208
205
  Ipv4Header BuildHeader (
209
  Ipv4Header BuildHeader (
206
            Ipv4Address source,
210
            Ipv4Address source,
 Lines 238-243    Link Here 
238
  typedef std::list<Ptr<Ipv4L4Protocol> > L4List_t;
242
  typedef std::list<Ptr<Ipv4L4Protocol> > L4List_t;
239
243
240
  bool m_ipForward;
244
  bool m_ipForward;
245
  bool m_weakEsModel;
241
  L4List_t m_protocols;
246
  L4List_t m_protocols;
242
  Ipv4InterfaceList m_interfaces;
247
  Ipv4InterfaceList m_interfaces;
243
  uint32_t m_nInterfaces;
248
  uint32_t m_nInterfaces;
(-)a/src/node/ipv4.cc (+6 lines)
 Lines 37-42    Link Here 
37
                   MakeBooleanAccessor (&Ipv4::SetIpForward,
37
                   MakeBooleanAccessor (&Ipv4::SetIpForward,
38
                                        &Ipv4::GetIpForward),
38
                                        &Ipv4::GetIpForward),
39
                   MakeBooleanChecker ())
39
                   MakeBooleanChecker ())
40
    .AddAttribute ("WeakEsModel", 
41
                   "RFC1122 term for whether host accepts datagram with a dest. address on another interface",
42
                   BooleanValue (true),
43
                   MakeBooleanAccessor (&Ipv4::SetWeakEsModel,
44
                                        &Ipv4::GetWeakEsModel),
45
                   MakeBooleanChecker ())
40
#if 0
46
#if 0
41
    .AddAttribute ("MtuDiscover", "If enabled, every outgoing ip packet will have the DF flag set.",
47
    .AddAttribute ("MtuDiscover", "If enabled, every outgoing ip packet will have the DF flag set.",
42
                   BooleanValue (false),
48
                   BooleanValue (false),
(-)a/src/node/ipv4.h (-1 / +26 lines)
 Lines 123-133    Link Here 
123
   * This method searches the list of interfaces for one that holds a
123
   * This method searches the list of interfaces for one that holds a
124
   * particular address.  This call takes an IP address as a parameter and
124
   * particular address.  This call takes an IP address as a parameter and
125
   * returns the interface number of the first interface that has been assigned
125
   * returns the interface number of the first interface that has been assigned
126
   * that address, or -1 if not found.  There must be an exact match.
126
   * that address, or -1 if not found.  There must be an exact match; this
127
   * method will not match broadcast or multicast addresses.
127
   */
128
   */
128
  virtual int32_t GetInterfaceForAddress (Ipv4Address address) const = 0;
129
  virtual int32_t GetInterfaceForAddress (Ipv4Address address) const = 0;
129
130
130
  /**
131
  /**
132
   * \brief Determine whether address and interface corresponding to
133
   *        received packet can be accepted for local delivery
134
   *
135
   * \param address The IP address being considered
136
   * \param iif The incoming Ipv4 interface index
137
   *
138
   * This method can be used to determine whether a received packet has
139
   * an acceptable address for local delivery on the host.  The address
140
   * may be a unicast, multicast, or broadcast address.  This method will
141
   * return true if address is an exact match of a unicast address on
142
   * one of the host's interfaces (see below), if address corresponds to 
143
   * a multicast group that the host has joined (and the incoming device
144
   * is acceptable), or if address corresponds to a broadcast address.
145
   *
146
   * If the Ipv4 attribute WeakEsModel is true, the unicast address may
147
   * match any of the Ipv4 addresses on any interface (a subnet directed
148
   * broadcast must match the incoming interface).  If the attribute is
149
   * false, address must match one assigned to the incoming device.
150
   */
151
  virtual bool IsDestinationAddress (Ipv4Address address, uint32_t iif) const = 0;
152
153
  /**
131
   * \brief Return the interface number of first interface found that 
154
   * \brief Return the interface number of first interface found that 
132
   *  has an Ipv4 address within the prefix specified by the input
155
   *  has an Ipv4 address within the prefix specified by the input
133
   *  address and mask parameters
156
   *  address and mask parameters
 Lines 257-262    Link Here 
257
  // Indirect the Ipv4 attributes through private pure virtual methods
280
  // Indirect the Ipv4 attributes through private pure virtual methods
258
  virtual void SetIpForward (bool forward) = 0;
281
  virtual void SetIpForward (bool forward) = 0;
259
  virtual bool GetIpForward (void) const = 0;
282
  virtual bool GetIpForward (void) const = 0;
283
  virtual void SetWeakEsModel (bool model) = 0;
284
  virtual bool GetWeakEsModel (void) const = 0;
260
};
285
};
261
286
262
} // namespace ns3 
287
} // namespace ns3 
(-)a/src/routing/list-routing/ipv4-list-routing.cc (-64 / +20 lines)
 Lines 108-182    Link Here 
108
  NS_ASSERT (m_ipv4->GetInterfaceForDevice (idev) >= 0);
108
  NS_ASSERT (m_ipv4->GetInterfaceForDevice (idev) >= 0);
109
  uint32_t iif = m_ipv4->GetInterfaceForDevice (idev); 
109
  uint32_t iif = m_ipv4->GetInterfaceForDevice (idev); 
110
110
111
  // Multicast recognition; handle local delivery here
111
  retVal = m_ipv4->IsDestinationAddress (header.GetDestination (), iif);
112
  //
112
  if (retVal == true)
113
  if (header.GetDestination().IsMulticast ())
114
    {
113
    {
115
#ifdef NOTYET
114
      NS_LOG_LOGIC ("Address "<< header.GetDestination () << " is a match for local delivery");
116
      if (m_ipv4->MulticastCheckGroup (iif, header.GetDestination ()))
115
      if (header.GetDestination ().IsMulticast ())
117
#endif
118
      if (true)
119
        {
116
        {
120
          NS_LOG_LOGIC ("Multicast packet for me-- local deliver");
121
          Ptr<Packet> packetCopy = p->Copy();
117
          Ptr<Packet> packetCopy = p->Copy();
122
          // Here may want to disable lcb callback in recursive RouteInput
123
          // call below
124
          lcb (packetCopy, header, iif);
118
          lcb (packetCopy, header, iif);
125
          // Fall through-- we may also need to forward this
126
          retVal = true;
119
          retVal = true;
120
          // Fall through
127
        }
121
        }
128
      for (Ipv4RoutingProtocolList::const_iterator rprotoIter =
122
      else
129
         m_routingProtocols.begin (); rprotoIter != m_routingProtocols.end ();
130
           rprotoIter++)
131
        {
123
        {
132
          NS_LOG_LOGIC ("Multicast packet for me-- trying to forward");
124
          lcb (p, header, iif);
133
          if ((*rprotoIter).second->RouteInput (p, header, idev, ucb, mcb, lcb, ecb))
125
          return true;
134
            {
135
              retVal = true;
136
            }
137
        }
138
      return retVal;
139
    }
140
141
  if (header.GetDestination ().IsBroadcast ())
142
    {
143
      NS_LOG_LOGIC ("For me (Ipv4Addr broadcast address)");
144
      // TODO:  Local Deliver for broadcast
145
      // TODO:  Forward broadcast
146
    }
147
148
 // TODO:  Configurable option to enable RFC 1222 Strong End System Model
149
 // Right now, we will be permissive and allow a source to send us
150
 // a packet to one of our other interface addresses; that is, the
151
 // destination unicast address does not match one of the iif addresses,
152
 // but we check our other interfaces.  This could be an option
153
 // (to remove the outer loop immediately below and just check iif).
154
  for (uint32_t j = 0; j < m_ipv4->GetNInterfaces (); j++)
155
    {
156
      for (uint32_t i = 0; i < m_ipv4->GetNAddresses (j); i++)
157
        {
158
          Ipv4InterfaceAddress iaddr = m_ipv4->GetAddress (j, i);
159
          Ipv4Address addr = iaddr.GetLocal ();
160
          if (addr.IsEqual (header.GetDestination ()))
161
            {
162
              if (j == iif)
163
                {
164
                  NS_LOG_LOGIC ("For me (destination " << addr << " match)");
165
                }
166
              else
167
                {
168
                  NS_LOG_LOGIC ("For me (destination " << addr << " match) on another interface " << header.GetDestination ());
169
                }
170
              lcb (p, header, iif);
171
              return true;
172
            }
173
          if (header.GetDestination ().IsEqual (iaddr.GetBroadcast ()))
174
            {
175
              NS_LOG_LOGIC ("For me (interface broadcast address)");
176
              lcb (p, header, iif);
177
              return true;
178
            }
179
          NS_LOG_LOGIC ("Address "<< addr << " not a match");
180
        }
126
        }
181
    }
127
    }
182
  // Check if input device supports IP forwarding
128
  // Check if input device supports IP forwarding
 Lines 187-200    Link Here 
187
      return false;
133
      return false;
188
    }
134
    }
189
  // Next, try to find a route
135
  // Next, try to find a route
136
  // If we have already delivered a packet locally (e.g. multicast)
137
  // we suppress further downstream local delivery by nulling the callback
138
  LocalDeliverCallback downstreamLcb = lcb;
139
  if (retVal == true)
140
    {
141
      downstreamLcb = MakeNullCallback<void, Ptr<const Packet>, const Ipv4Header &, uint32_t > ();
142
    }
190
  for (Ipv4RoutingProtocolList::const_iterator rprotoIter =
143
  for (Ipv4RoutingProtocolList::const_iterator rprotoIter =
191
         m_routingProtocols.begin ();
144
         m_routingProtocols.begin ();
192
       rprotoIter != m_routingProtocols.end ();
145
       rprotoIter != m_routingProtocols.end ();
193
       rprotoIter++)
146
       rprotoIter++)
194
    {
147
    {
195
      if ((*rprotoIter).second->RouteInput (p, header, idev, ucb, mcb, lcb, ecb))
148
      if (retVal == false)
196
        {
149
        {
197
          return true;
150
          if ((*rprotoIter).second->RouteInput (p, header, idev, ucb, mcb, downstreamLcb, ecb))
151
            {
152
              return true;
153
            }
198
        }
154
        }
199
    }
155
    }
200
  // No routing protocol has found a route.  
156
  // No routing protocol has found a route.  

Return to bug 735