1.1 --- a/examples/netfilter-example.cc Fri Jul 31 00:57:33 2009 +0600
1.2 +++ b/examples/netfilter-example.cc Thu Aug 06 11:34:29 2009 +0600
1.3 @@ -21,6 +21,7 @@
1.4 #include "ns3/global-route-manager.h"
1.5 #include "ns3/on-off-helper.h"
1.6 #include "ns3/v4ping-helper.h"
1.7 +#include "ns3/ipv4-l3-protocol.h"
1.8
1.9 using namespace ns3;
1.10
1.11 @@ -61,45 +62,54 @@
1.12 stack.Install (second.Get(1));
1.13
1.14 Ipv4AddressHelper address1;
1.15 - address1.SetBase ("10.1.1.0", "255.255.255.0");
1.16 + address1.SetBase ("192.168.1.0", "255.255.255.0");
1.17
1.18 Ipv4AddressHelper address2;
1.19 - address2.SetBase ("10.2.2.0", "255.255.255.0");
1.20 + address2.SetBase ("203.82.48.0", "255.255.255.0");
1.21
1.22 Ipv4InterfaceContainer firstInterfaces = address1.Assign (devices1);
1.23 - Ipv4InterfaceContainer rightInterfaces = address2.Assign (devices2);
1.24 + Ipv4InterfaceContainer secondInterfaces = address2.Assign (devices2);
1.25 +
1.26 + Ptr <Ipv4> ipv4 = first.Get (1)->GetObject<Ipv4> ();
1.27 + std::cout << "Number of interfaces on node " << first.Get (1)->GetId () << ": " << ipv4->GetNInterfaces () << std::endl;
1.28 +
1.29 + Ptr <Ipv4L3Protocol> ipv4L3 = DynamicCast <Ipv4L3Protocol>(first.Get (1)->GetObject<Ipv4> ());
1.30 + Ipv4Netfilter *netfilter = ipv4L3->GetNetfilter ();
1.31 + netfilter->EnableNat ();
1.32 + std::cout << "Adding rule at node " << first.Get (1)->GetId () << ", device " << first.Get (1)->GetDevice (1)->GetIfIndex () << std::endl;
1.33 + netfilter->AddNatRule ( NatRule (Ipv4Address ("192.168.1.1"), Ipv4Address ("203.82.48.1"), first.Get (1)->GetDevice (1)));
1.34
1.35 UdpEchoServerHelper echoServer (9);
1.36
1.37 - ApplicationContainer serverApps = echoServer.Install (first.Get (0));
1.38 + ApplicationContainer serverApps = echoServer.Install (second.Get (1));
1.39 serverApps.Start (Seconds (1.0));
1.40 serverApps.Stop (Seconds (10.0));
1.41
1.42 - UdpEchoClientHelper echoClient (firstInterfaces.GetAddress (0), 9);
1.43 + UdpEchoClientHelper echoClient (secondInterfaces.GetAddress (1), 9);
1.44 echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
1.45 echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
1.46 - echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
1.47 + echoClient.SetAttribute ("PacketSize", UintegerValue (512));
1.48
1.49 - ApplicationContainer clientApps = echoClient.Install (second.Get (1));
1.50 + ApplicationContainer clientApps = echoClient.Install (first.Get (0));
1.51 clientApps.Start (Seconds (2.0));
1.52 clientApps.Stop (Seconds (10.0));
1.53
1.54 OnOffHelper onOff ( "ns3::TcpSocketFactory",
1.55 - Address (InetSocketAddress ("10.1.1.1", port)));
1.56 + Address (InetSocketAddress ("192.168.1.1", port)));
1.57 onOff.SetAttribute ("MaxBytes", UintegerValue (512));
1.58
1.59 ApplicationContainer onOffApp = onOff.Install (second.Get (1));
1.60
1.61 PacketSinkHelper packetSink ( "ns3::TcpSocketFactory",
1.62 - Address (InetSocketAddress ("10.1.1.1", port)));
1.63 + Address (InetSocketAddress ("192.168.1.1", port)));
1.64
1.65 ApplicationContainer packetSinkApp = packetSink.Install (first.Get (0));
1.66
1.67 - packetSinkApp.Start (Seconds (2.0));
1.68 + /*packetSinkApp.Start (Seconds (2.0));
1.69 packetSinkApp.Stop (Seconds (4.0));
1.70
1.71 onOffApp.Start (Seconds (3.0));
1.72 - onOffApp.Stop (Seconds (4.0));
1.73 + onOffApp.Stop (Seconds (4.0));*/
1.74
1.75 /*ApplicationContainer pingApp = ping.Install (first.Get (0));
1.76 pingApp.Start (Seconds (3.0));