--- a/examples/netfilter-example.cc Thu Aug 06 11:16:51 2009 +0600
+++ b/examples/netfilter-example.cc Thu Aug 06 11:34:29 2009 +0600
@@ -21,6 +21,7 @@
#include "ns3/global-route-manager.h"
#include "ns3/on-off-helper.h"
#include "ns3/v4ping-helper.h"
+#include "ns3/ipv4-l3-protocol.h"
using namespace ns3;
@@ -61,45 +62,54 @@
stack.Install (second.Get(1));
Ipv4AddressHelper address1;
- address1.SetBase ("10.1.1.0", "255.255.255.0");
+ address1.SetBase ("192.168.1.0", "255.255.255.0");
Ipv4AddressHelper address2;
- address2.SetBase ("10.2.2.0", "255.255.255.0");
+ address2.SetBase ("203.82.48.0", "255.255.255.0");
Ipv4InterfaceContainer firstInterfaces = address1.Assign (devices1);
- Ipv4InterfaceContainer rightInterfaces = address2.Assign (devices2);
+ Ipv4InterfaceContainer secondInterfaces = address2.Assign (devices2);
+
+ Ptr <Ipv4> ipv4 = first.Get (1)->GetObject<Ipv4> ();
+ std::cout << "Number of interfaces on node " << first.Get (1)->GetId () << ": " << ipv4->GetNInterfaces () << std::endl;
+
+ Ptr <Ipv4L3Protocol> ipv4L3 = DynamicCast <Ipv4L3Protocol>(first.Get (1)->GetObject<Ipv4> ());
+ Ipv4Netfilter *netfilter = ipv4L3->GetNetfilter ();
+ netfilter->EnableNat ();
+ std::cout << "Adding rule at node " << first.Get (1)->GetId () << ", device " << first.Get (1)->GetDevice (1)->GetIfIndex () << std::endl;
+ netfilter->AddNatRule ( NatRule (Ipv4Address ("192.168.1.1"), Ipv4Address ("203.82.48.1"), first.Get (1)->GetDevice (1)));
UdpEchoServerHelper echoServer (9);
- ApplicationContainer serverApps = echoServer.Install (first.Get (0));
+ ApplicationContainer serverApps = echoServer.Install (second.Get (1));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
- UdpEchoClientHelper echoClient (firstInterfaces.GetAddress (0), 9);
+ UdpEchoClientHelper echoClient (secondInterfaces.GetAddress (1), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
- echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
+ echoClient.SetAttribute ("PacketSize", UintegerValue (512));
- ApplicationContainer clientApps = echoClient.Install (second.Get (1));
+ ApplicationContainer clientApps = echoClient.Install (first.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
OnOffHelper onOff ( "ns3::TcpSocketFactory",
- Address (InetSocketAddress ("10.1.1.1", port)));
+ Address (InetSocketAddress ("192.168.1.1", port)));
onOff.SetAttribute ("MaxBytes", UintegerValue (512));
ApplicationContainer onOffApp = onOff.Install (second.Get (1));
PacketSinkHelper packetSink ( "ns3::TcpSocketFactory",
- Address (InetSocketAddress ("10.1.1.1", port)));
+ Address (InetSocketAddress ("192.168.1.1", port)));
ApplicationContainer packetSinkApp = packetSink.Install (first.Get (0));
- packetSinkApp.Start (Seconds (2.0));
+ /*packetSinkApp.Start (Seconds (2.0));
packetSinkApp.Stop (Seconds (4.0));
onOffApp.Start (Seconds (3.0));
- onOffApp.Stop (Seconds (4.0));
+ onOffApp.Stop (Seconds (4.0));*/
/*ApplicationContainer pingApp = ping.Install (first.Get (0));
pingApp.Start (Seconds (3.0));