bug 299: packet socket broken by promiscuous update
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Fri Aug 29 20:40:54 2008 -0700 (17 months ago)
changeset 358701bebf28addd
parent 3583 92ef80f0352e
child 3588 ff3a7dc79a7e
bug 299: packet socket broken by promiscuous update
examples/csma-packet-socket.cc
src/node/packet-socket.cc
     1.1 --- a/examples/csma-packet-socket.cc	Thu Aug 28 15:06:49 2008 -0700
     1.2 +++ b/examples/csma-packet-socket.cc	Fri Aug 29 20:40:54 2008 -0700
     1.3 @@ -42,6 +42,14 @@
     1.4  
     1.5  NS_LOG_COMPONENT_DEFINE ("CsmaPacketSocketExample");
     1.6  
     1.7 +std::ofstream g_os;
     1.8 +
     1.9 +static void
    1.10 +SinkRx (std::string path, Ptr<const Packet> p, const Address &address)
    1.11 +{
    1.12 +  g_os << p->GetSize () << std::endl;
    1.13 +}
    1.14 +
    1.15  int
    1.16  main (int argc, char *argv[])
    1.17  {
    1.18 @@ -57,13 +65,15 @@
    1.19    CommandLine cmd;
    1.20    cmd.Parse (argc, argv);
    1.21  
    1.22 +  g_os.open ("csma-packet-socket-sink.tr");
    1.23 +
    1.24    // Here, we will explicitly create four nodes.
    1.25    NS_LOG_INFO ("Create nodes.");
    1.26 -  NodeContainer c;
    1.27 -  c.Create (4);
    1.28 +  NodeContainer nodes;
    1.29 +  nodes.Create (4);
    1.30  
    1.31    PacketSocketHelper packetSocket;
    1.32 -  packetSocket.Install (c);
    1.33 +  packetSocket.Install (nodes);
    1.34  
    1.35    // create the shared medium used by all csma devices.
    1.36    NS_LOG_INFO ("Create channels.");
    1.37 @@ -75,7 +85,7 @@
    1.38    NS_LOG_INFO ("Build Topology.");
    1.39    CsmaHelper csma;
    1.40    csma.SetDeviceAttribute ("EncapsulationMode", StringValue ("Llc"));
    1.41 -  NetDeviceContainer devs = csma.Install (c, channel);
    1.42 +  NetDeviceContainer devs = csma.Install (nodes, channel);
    1.43  
    1.44    NS_LOG_INFO ("Create Applications.");
    1.45    // Create the OnOff application to send raw datagrams
    1.46 @@ -86,19 +96,27 @@
    1.47    OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket));
    1.48    onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1.0)));
    1.49    onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0.0)));
    1.50 -
    1.51 -  ApplicationContainer apps = onoff.Install (c.Get (0));
    1.52 +  ApplicationContainer apps = onoff.Install (nodes.Get (0));
    1.53    apps.Start (Seconds (1.0));
    1.54    apps.Stop (Seconds (10.0));
    1.55 -  
    1.56 +
    1.57    socket.SetSingleDevice (devs.Get (3)->GetIfIndex ());
    1.58    socket.SetPhysicalAddress (devs.Get (0)->GetAddress ());
    1.59    socket.SetProtocol (3);
    1.60    onoff.SetAttribute ("Remote", AddressValue (socket));
    1.61    onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0.0)));
    1.62 -  apps = onoff.Install (c.Get (3));
    1.63 +  apps = onoff.Install (nodes.Get (3));
    1.64    apps.Start (Seconds (1.0));
    1.65    apps.Stop (Seconds (10.0));
    1.66 +
    1.67 +  PacketSinkHelper sink = PacketSinkHelper ("ns3::PacketSocketFactory",
    1.68 +                                            socket);
    1.69 +  apps = sink.Install (nodes.Get (0));
    1.70 +  apps.Start (Seconds (0.0));
    1.71 +  apps.Stop (Seconds (20.0));
    1.72 +
    1.73 +  Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::PacketSink/Rx",
    1.74 +                   MakeCallback (&SinkRx));
    1.75   
    1.76    // Configure tracing of all enqueue, dequeue, and NetDevice receive events
    1.77    // Trace output will be sent to the csma-packet-socket.tr file
    1.78 @@ -111,4 +129,8 @@
    1.79    Simulator::Run ();
    1.80    Simulator::Destroy ();
    1.81    NS_LOG_INFO ("Done.");
    1.82 +
    1.83 +  g_os.close ();
    1.84 +
    1.85 +  return 0;
    1.86  }
     2.1 --- a/src/node/packet-socket.cc	Thu Aug 28 15:06:49 2008 -0700
     2.2 +++ b/src/node/packet-socket.cc	Fri Aug 29 20:40:54 2008 -0700
     2.3 @@ -353,10 +353,6 @@
     2.4      {
     2.5        return;
     2.6      }
     2.7 -  if (packetType != NetDevice::PACKET_HOST)
     2.8 -    {
     2.9 -      return;
    2.10 -    }
    2.11  
    2.12  
    2.13    PacketSocketAddress address;