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

(-)a/src/internet/model/ipv4-l3-protocol.cc (+16 lines)
 Lines 573-578    Link Here 
573
      tos = ipTosTag.GetTos ();
573
      tos = ipTosTag.GetTos ();
574
    }
574
    }
575
575
576
  if (destination.IsMulticast ())
577
    {
578
      SocketIpMulticastLoopTag ipMulticastLoopTag;
579
      found = packet->RemovePacketTag (ipMulticastLoopTag);
580
      if (found && ipMulticastLoopTag.IsEnabled ())
581
        {
582
          Ptr<Ipv4Route> rtentry = Create<Ipv4Route> ();
583
          rtentry->SetSource (source);
584
          rtentry->SetDestination (destination);
585
          rtentry->SetGateway (Ipv4Address::GetAny ());
586
          rtentry->SetOutputDevice (m_node->GetLoopbackDevice ());
587
588
          SendRealOut (rtentry, packet->Copy (), BuildHeader (source, destination, protocol, packet->GetSize (), ttl, tos, mayFragment));
589
        }
590
    }
591
576
  // Handle a few cases:
592
  // Handle a few cases:
577
  // 1) packet is destined to limited broadcast address
593
  // 1) packet is destined to limited broadcast address
578
  // 2) packet is destined to a subnet-directed broadcast address
594
  // 2) packet is destined to a subnet-directed broadcast address
(-)a/src/internet/model/ipv6-l3-protocol.cc (+16 lines)
 Lines 720-725    Link Here 
720
      tclass = tclassTag.GetTclass ();
720
      tclass = tclassTag.GetTclass ();
721
    }
721
    }
722
722
723
  if (destination.IsMulticast ())
724
    {
725
      SocketIpMulticastLoopTag ipMulticastLoopTag;
726
      found = packet->RemovePacketTag (ipMulticastLoopTag);
727
      if (found && ipMulticastLoopTag.IsEnabled ())
728
        {
729
          Ptr<Ipv6Route> rtentry = Create<Ipv6Route> ();
730
          rtentry->SetSource (source);
731
          rtentry->SetDestination (destination);
732
          rtentry->SetGateway (Ipv6Address::GetAny ());
733
          rtentry->SetOutputDevice (m_node->GetLoopbackDevice ());
734
735
          SendRealOut (rtentry, packet->Copy (), BuildHeader (source, destination, protocol, packet->GetSize (), ttl, tclass));
736
        }
737
    }
738
723
  /* Handle 3 cases:
739
  /* Handle 3 cases:
724
   * 1) Packet is passed in with a route entry
740
   * 1) Packet is passed in with a route entry
725
   * 2) Packet is passed in with a route entry but route->GetGateway is not set (e.g., same network)
741
   * 2) Packet is passed in with a route entry but route->GetGateway is not set (e.g., same network)
(-)a/src/internet/model/udp-socket-impl.cc (+16 lines)
 Lines 519-524    Link Here 
519
        p->AddPacketTag (tag);
519
        p->AddPacketTag (tag);
520
      }
520
      }
521
  }
521
  }
522
523
  if (dest.IsMulticast () && m_ipMulticastLoop)
524
    {
525
      SocketIpMulticastLoopTag tag;
526
      tag.Enable ();
527
      p->AddPacketTag (tag);
528
    }
529
522
  //
530
  //
523
  // If dest is set to the limited broadcast address (all ones),
531
  // If dest is set to the limited broadcast address (all ones),
524
  // convert it to send a copy of the packet out of every 
532
  // convert it to send a copy of the packet out of every 
 Lines 698-703    Link Here 
698
      tag.SetHopLimit (GetIpv6HopLimit ());
706
      tag.SetHopLimit (GetIpv6HopLimit ());
699
      p->AddPacketTag (tag);
707
      p->AddPacketTag (tag);
700
    }
708
    }
709
710
  if (dest.IsMulticast () && m_ipMulticastLoop)
711
    {
712
      SocketIpMulticastLoopTag tag;
713
      tag.Enable ();
714
      p->AddPacketTag (tag);
715
    }
716
701
  // There is no analgous to an IPv4 broadcast address in IPv6.
717
  // There is no analgous to an IPv4 broadcast address in IPv6.
702
  // Instead, we use a set of link-local, site-local, and global
718
  // Instead, we use a set of link-local, site-local, and global
703
  // multicast addresses.  The Ipv6 routing layers should all
719
  // multicast addresses.  The Ipv6 routing layers should all
(-)a/src/network/model/socket.cc (+64 lines)
 Lines 868-871    Link Here 
868
  os << "IPV6_TCLASS = " << m_ipv6Tclass;
868
  os << "IPV6_TCLASS = " << m_ipv6Tclass;
869
}
869
}
870
870
871
SocketIpMulticastLoopTag::SocketIpMulticastLoopTag () :
872
  m_multicastLoop (false)
873
{
874
  NS_LOG_FUNCTION (this);
875
}
876
void
877
SocketIpMulticastLoopTag::Enable (void)
878
{
879
  NS_LOG_FUNCTION (this);
880
  m_multicastLoop = true;
881
}
882
void
883
SocketIpMulticastLoopTag::Disable (void)
884
{
885
  NS_LOG_FUNCTION (this);
886
  m_multicastLoop = false;
887
}
888
bool
889
SocketIpMulticastLoopTag::IsEnabled (void) const
890
{
891
  NS_LOG_FUNCTION (this);
892
  return m_multicastLoop;
893
}
894
895
NS_OBJECT_ENSURE_REGISTERED (SocketIpMulticastLoopTag);
896
897
TypeId
898
SocketIpMulticastLoopTag::GetTypeId (void)
899
{
900
  static TypeId tid = TypeId ("ns3::SocketIpMulticastLoopTag")
901
    .SetParent<Tag> ()
902
    .AddConstructor<SocketIpMulticastLoopTag> ();
903
  return tid;
904
}
905
TypeId
906
SocketIpMulticastLoopTag::GetInstanceTypeId (void) const
907
{
908
  return GetTypeId ();
909
}
910
uint32_t
911
SocketIpMulticastLoopTag::GetSerializedSize (void) const
912
{
913
  NS_LOG_FUNCTION (this);
914
  return 1;
915
}
916
void
917
SocketIpMulticastLoopTag::Serialize (TagBuffer i) const
918
{
919
  NS_LOG_FUNCTION (this << &i);
920
  i.WriteU8 (m_multicastLoop ? 1 : 0);
921
}
922
void
923
SocketIpMulticastLoopTag::Deserialize (TagBuffer i)
924
{
925
  NS_LOG_FUNCTION (this << &i);
926
  m_multicastLoop = (i.ReadU8 () == 1) ? true : false;
927
}
928
void
929
SocketIpMulticastLoopTag::Print (std::ostream &os) const
930
{
931
  NS_LOG_FUNCTION (this << &os);
932
  os << (m_multicastLoop ? "true" : "false");
933
}
934
871
} // namespace ns3
935
} // namespace ns3
(-)a/src/network/model/socket.h (+22 lines)
 Lines 1229-1234    Link Here 
1229
  uint8_t m_ipv6Tclass; //!< the Tclass carried by the tag
1229
  uint8_t m_ipv6Tclass; //!< the Tclass carried by the tag
1230
};
1230
};
1231
1231
1232
/**
1233
 * \brief indicated whether multicast packets should be looped back to
1234
 * local sockets.
1235
 */
1236
class SocketIpMulticastLoopTag : public Tag
1237
{
1238
public:
1239
  SocketIpMulticastLoopTag ();
1240
  void Enable (void);
1241
  void Disable (void);
1242
  bool IsEnabled (void) const;
1243
1244
  static TypeId GetTypeId (void);
1245
  virtual TypeId GetInstanceTypeId (void) const;
1246
  virtual uint32_t GetSerializedSize (void) const;
1247
  virtual void Serialize (TagBuffer i) const;
1248
  virtual void Deserialize (TagBuffer i);
1249
  virtual void Print (std::ostream &os) const;
1250
private:
1251
  bool m_multicastLoop;
1252
};
1253
1232
} // namespace ns3
1254
} // namespace ns3
1233
1255
1234
#endif /* NS3_SOCKET_H */
1256
#endif /* NS3_SOCKET_H */
(-)a/src/internet/model/ipv4-interface.cc (-1 / +1 lines)
 Lines 19-25    Link Here 
19
 */
19
 */
20
20
21
#include "ipv4-interface.h"
21
#include "ipv4-interface.h"
22
#include "loopback-net-device.h"
22
#include "ns3/loopback-net-device.h"
23
#include "ns3/ipv4-address.h"
23
#include "ns3/ipv4-address.h"
24
#include "ipv4-l3-protocol.h"
24
#include "ipv4-l3-protocol.h"
25
#include "arp-l3-protocol.h"
25
#include "arp-l3-protocol.h"
(-)a/src/internet/model/ipv4-l3-protocol.cc (-15 / +1 lines)
 Lines 33-39    Link Here 
33
#include "ns3/boolean.h"
33
#include "ns3/boolean.h"
34
#include "ns3/ipv4-routing-table-entry.h"
34
#include "ns3/ipv4-routing-table-entry.h"
35
35
36
#include "loopback-net-device.h"
37
#include "arp-l3-protocol.h"
36
#include "arp-l3-protocol.h"
38
#include "ipv4-l3-protocol.h"
37
#include "ipv4-l3-protocol.h"
39
#include "icmpv4-l4-protocol.h"
38
#include "icmpv4-l4-protocol.h"
 Lines 241-260    Link Here 
241
  NS_LOG_FUNCTION (this);
240
  NS_LOG_FUNCTION (this);
242
241
243
  Ptr<Ipv4Interface> interface = CreateObject<Ipv4Interface> ();
242
  Ptr<Ipv4Interface> interface = CreateObject<Ipv4Interface> ();
244
  Ptr<LoopbackNetDevice> device = 0;
243
  Ptr<NetDevice> device = m_node->GetLoopbackDevice ();
245
  // First check whether an existing LoopbackNetDevice exists on the node
246
  for (uint32_t i = 0; i < m_node->GetNDevices (); i++)
247
    {
248
      if ((device = DynamicCast<LoopbackNetDevice> (m_node->GetDevice (i))))
249
        {
250
          break;
251
        }
252
    }
253
  if (device == 0)
254
    {
255
      device = CreateObject<LoopbackNetDevice> (); 
256
      m_node->AddDevice (device);
257
    }
258
  interface->SetDevice (device);
244
  interface->SetDevice (device);
259
  interface->SetNode (m_node);
245
  interface->SetNode (m_node);
260
  Ipv4InterfaceAddress ifaceAddr = Ipv4InterfaceAddress (Ipv4Address::GetLoopback (), Ipv4Mask::GetLoopback ());
246
  Ipv4InterfaceAddress ifaceAddr = Ipv4InterfaceAddress (Ipv4Address::GetLoopback (), Ipv4Mask::GetLoopback ());
(-)a/src/internet/model/ipv6-interface.cc (-1 / +1 lines)
 Lines 24-30    Link Here 
24
24
25
#include "ipv6-interface.h"
25
#include "ipv6-interface.h"
26
#include "ns3/net-device.h"
26
#include "ns3/net-device.h"
27
#include "loopback-net-device.h"
27
#include "ns3/loopback-net-device.h"
28
#include "ns3/mac16-address.h"
28
#include "ns3/mac16-address.h"
29
#include "ns3/mac64-address.h"
29
#include "ns3/mac64-address.h"
30
#include "ipv6-l3-protocol.h"
30
#include "ipv6-l3-protocol.h"
(-)a/src/internet/model/ipv6-l3-protocol.cc (-18 / +2 lines)
 Lines 30-37    Link Here 
30
#include "ns3/ipv6-route.h"
30
#include "ns3/ipv6-route.h"
31
#include "ns3/mac16-address.h"
31
#include "ns3/mac16-address.h"
32
#include "ns3/mac64-address.h"
32
#include "ns3/mac64-address.h"
33
#include "ns3/mac48-address.h"
33
34
34
#include "loopback-net-device.h"
35
#include "ipv6-l3-protocol.h"
35
#include "ipv6-l3-protocol.h"
36
#include "ipv6-interface.h"
36
#include "ipv6-interface.h"
37
#include "ipv6-raw-socket-impl.h"
37
#include "ipv6-raw-socket-impl.h"
 Lines 523-545    Link Here 
523
{
523
{
524
  NS_LOG_FUNCTION_NOARGS ();
524
  NS_LOG_FUNCTION_NOARGS ();
525
  Ptr<Ipv6Interface> interface = CreateObject<Ipv6Interface> ();
525
  Ptr<Ipv6Interface> interface = CreateObject<Ipv6Interface> ();
526
  Ptr<LoopbackNetDevice> device = 0;
526
  Ptr<NetDevice> device = m_node->GetLoopbackDevice ();
527
  uint32_t i = 0;
528
529
  /* see if we have already an loopback NetDevice */
530
  for (i = 0; i < m_node->GetNDevices (); i++)
531
    {
532
      if ((device = DynamicCast<LoopbackNetDevice> (m_node->GetDevice (i))))
533
        {
534
          break;
535
        }
536
    }
537
538
  if (device == 0)
539
    {
540
      device = CreateObject<LoopbackNetDevice> ();
541
      m_node->AddDevice (device);
542
    }
543
527
544
  interface->SetDevice (device);
528
  interface->SetDevice (device);
545
  interface->SetNode (m_node);
529
  interface->SetNode (m_node);
(-)a/src/internet/wscript (-2 lines)
 Lines 120-126    Link Here 
120
        'model/ipv4-raw-socket-impl.cc',
120
        'model/ipv4-raw-socket-impl.cc',
121
        'model/icmpv4.cc',
121
        'model/icmpv4.cc',
122
        'model/icmpv4-l4-protocol.cc',
122
        'model/icmpv4-l4-protocol.cc',
123
        'model/loopback-net-device.cc',
124
        'model/ndisc-cache.cc',
123
        'model/ndisc-cache.cc',
125
        'model/ipv6-interface.cc',
124
        'model/ipv6-interface.cc',
126
        'model/icmpv6-header.cc',
125
        'model/icmpv6-header.cc',
 Lines 247-253    Link Here 
247
        'model/icmpv6-l4-protocol.h',
246
        'model/icmpv6-l4-protocol.h',
248
        'model/ipv6-interface.h',
247
        'model/ipv6-interface.h',
249
        'model/ndisc-cache.h',
248
        'model/ndisc-cache.h',
250
        'model/loopback-net-device.h',
251
        'model/ipv4-packet-info-tag.h',
249
        'model/ipv4-packet-info-tag.h',
252
        'model/ipv6-packet-info-tag.h',
250
        'model/ipv6-packet-info-tag.h',
253
        'model/ipv4-interface-address.h',
251
        'model/ipv4-interface-address.h',
(-)a/src/network/model/node.cc (+13 lines)
 Lines 21-26    Link Here 
21
#include "node.h"
21
#include "node.h"
22
#include "node-list.h"
22
#include "node-list.h"
23
#include "net-device.h"
23
#include "net-device.h"
24
#include "loopback-net-device.h"
24
#include "application.h"
25
#include "application.h"
25
#include "ns3/packet.h"
26
#include "ns3/packet.h"
26
#include "ns3/simulator.h"
27
#include "ns3/simulator.h"
 Lines 142-147    Link Here 
142
  NS_LOG_FUNCTION (this);
143
  NS_LOG_FUNCTION (this);
143
  return m_devices.size ();
144
  return m_devices.size ();
144
}
145
}
146
Ptr<NetDevice>
147
Node::GetLoopbackDevice ()
148
{
149
  NS_LOG_FUNCTION (this);
150
  if (!m_loopbackDevice)
151
    {
152
      Ptr<LoopbackNetDevice> device = CreateObject<LoopbackNetDevice> ();
153
      AddDevice (device);
154
      m_loopbackDevice = device;
155
    }
156
  return m_loopbackDevice;
157
}
145
158
146
uint32_t 
159
uint32_t 
147
Node::AddApplication (Ptr<Application> application)
160
Node::AddApplication (Ptr<Application> application)
(-)a/src/network/model/node.h (+5 lines)
 Lines 100-105    Link Here 
100
   *          to this Node.
100
   *          to this Node.
101
   */
101
   */
102
  uint32_t GetNDevices (void) const;
102
  uint32_t GetNDevices (void) const;
103
  /**
104
   * \returns the LoopbackNetDevice associated with this Node.
105
   */
106
  Ptr<NetDevice> GetLoopbackDevice ();
103
107
104
  /**
108
  /**
105
   * \param application Application to associate to this node.
109
   * \param application Application to associate to this node.
 Lines 224-229    Link Here 
224
228
225
  uint32_t    m_id;         // Node id for this node
229
  uint32_t    m_id;         // Node id for this node
226
  uint32_t    m_sid;        // System id for this node
230
  uint32_t    m_sid;        // System id for this node
231
  Ptr<NetDevice> m_loopbackDevice;
227
  std::vector<Ptr<NetDevice> > m_devices;
232
  std::vector<Ptr<NetDevice> > m_devices;
228
  std::vector<Ptr<Application> > m_applications;
233
  std::vector<Ptr<Application> > m_applications;
229
  ProtocolHandlerList m_handlers;
234
  ProtocolHandlerList m_handlers;
(-)a/src/network/wscript (+2 lines)
 Lines 15-20    Link Here 
15
        'model/node.cc',
15
        'model/node.cc',
16
        'model/node-list.cc',
16
        'model/node-list.cc',
17
        'model/net-device.cc',
17
        'model/net-device.cc',
18
        'model/loopback-net-device.cc',
18
        'model/packet.cc',
19
        'model/packet.cc',
19
        'model/packet-metadata.cc',
20
        'model/packet-metadata.cc',
20
        'model/packet-tag-list.cc',
21
        'model/packet-tag-list.cc',
 Lines 89-94    Link Here 
89
        'model/chunk.h',
90
        'model/chunk.h',
90
        'model/header.h',
91
        'model/header.h',
91
        'model/net-device.h',
92
        'model/net-device.h',
93
        'model/loopback-net-device.h',
92
        'model/nix-vector.h',
94
        'model/nix-vector.h',
93
        'model/node.h',
95
        'model/node.h',
94
        'model/node-list.h',
96
        'model/node-list.h',

Return to bug 1834