Ipv4GlobalRoutingHelper helper;
Ptr<OutputStreamWrapper> stream = Create<OutputStreamWrapper> ("ArpCacheEntries", std::ios::out);
helper.PrintNeighborCacheAllEvery (Seconds (1), stream);
/* 1
n6-----n4
2| | 1
| 4 |
n0-------n1------n2-------n3
5 \ / 2
2 \ / 2
n5
*/
int main (int argc, char *argv[])
{
uint32_t ecmpMode = 0;
CommandLine cmd;
cmd.AddValue ("EcmpMode", "Ecmp Mode: (0 none, 1 random, 2 flow)", ecmpMode);
cmd.Parse (argc, argv);
switch (ecmpMode)
{
case 0:
break; //no ECMP
case 1:
Config::SetDefault ("ns3::Ipv4GlobalRouting::RandomEcmpRouting", BooleanValue (true));
break;
case 2:
Config::SetDefault ("ns3::Ipv4GlobalRouting::FlowEcmpRouting", BooleanValue (true));
break;
default:
NS_FATAL_ERROR ("Illegal command value for EcmpMode: " << ecmpMode);
break;
}
NS_LOG_INFO ("Create nodes.");
int n = 7;
NodeContainer c;
c.Create (n);
NodeContainer n0n1 = NodeContainer (c.Get (0), c.Get (1));
NodeContainer n1n2 = NodeContainer (c.Get (1), c.Get (2));
NodeContainer n2n3 = NodeContainer (c.Get (2), c.Get (3));
NodeContainer n2n4 = NodeContainer (c.Get (2), c.Get (4));
NodeContainer n1n6 = NodeContainer (c.Get (1), c.Get (6));
NodeContainer n4n6 = NodeContainer (c.Get (4), c.Get (6));
NodeContainer n1n5 = NodeContainer (c.Get (1), c.Get (5));
NodeContainer n2n5 = NodeContainer (c.Get (2), c.Get (5));
InternetStackHelper internet;
internet.Install (c);
NS_LOG_INFO ("Create channels.");
PointToPointHelper p2p;
p2p.SetDeviceAttribute ("DataRate", StringValue ("500kbps"));
p2p.SetChannelAttribute ("Delay", StringValue ("1ms"));
NetDeviceContainer d0d1 = p2p.Install (n0n1);
NetDeviceContainer d1d2 = p2p.Install (n1n2);
NetDeviceContainer d2d3 = p2p.Install (n2n3);
NetDeviceContainer d1d6 = p2p.Install (n1n6);
NetDeviceContainer d4d6 = p2p.Install (n4n6);
NetDeviceContainer d2d4 = p2p.Install (n2n4);
NetDeviceContainer d1d5 = p2p.Install (n1n5);
NetDeviceContainer d2d5 = p2p.Install (n2n5);
Ipv4AddressHelper ipv4;
ipv4.SetBase ("10.0.1.0", "255.255.255.0");
Ipv4InterfaceContainer i01 = ipv4.Assign (d0d1);
i01.SetMetric(0,5);
i01.SetMetric(1,5);
ipv4.SetBase ("10.2.3.0", "255.255.255.0");
Ipv4InterfaceContainer i23 = ipv4.Assign (d2d3);
i23.SetMetric(0,2);
i23.SetMetric(1,2);
ipv4.SetBase ("10.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer i12 = ipv4.Assign (d1d2);
i12.SetMetric(0,4);
i12.SetMetric(1,4);
ipv4.SetBase ("10.2.4.0", "255.255.255.0");
Ipv4InterfaceContainer i24 = ipv4.Assign (d2d4);
i24.SetMetric(0,1);
i24.SetMetric(1,1);
ipv4.SetBase ("10.1.6.0", "255.255.255.0");
Ipv4InterfaceContainer i16 = ipv4.Assign (d1d6);
i16.SetMetric(0,2);
i16.SetMetric(1,2);
ipv4.SetBase ("10.4.6.0", "255.255.255.0");
Ipv4InterfaceContainer i46 = ipv4.Assign (d4d6);
i46.SetMetric(0,1);
i46.SetMetric(1,1);
ipv4.SetBase ("10.1.5.0", "255.255.255.0");
Ipv4InterfaceContainer i15 = ipv4.Assign (d1d5);
i15.SetMetric(0,2);
i15.SetMetric(1,2);
ipv4.SetBase ("10.2.5.0", "255.255.255.0");
Ipv4InterfaceContainer i25 = ipv4.Assign (d2d5);
i25.SetMetric(0,2);
i25.SetMetric(1,2);
NS_LOG_INFO ("Populate routing tables.");
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
NS_LOG_INFO ("Create Applications.");
uint16_t port = 9;
OnOffHelper onoff ("ns3::UdpSocketFactory",InetSocketAddress (Ipv4Address ("10.2.3.2"), port));
onoff.SetConstantRate (DataRate ("100kbps"));
onoff.SetAttribute ("PacketSize", UintegerValue (500));
ApplicationContainer apps;
for (uint32_t i = 0; i < 3; i++){
apps.Add (onoff.Install (c.Get (0)));}
apps.Start (Seconds (1.0));
apps.Stop (Seconds (10));
PacketSinkHelper sink ("ns3::UdpSocketFactory",Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
sink.Install (c.Get (3));
Ipv4GlobalRoutingHelper helper3;
Ptr<OutputStreamWrapper> stream2 = Create<OutputStreamWrapper> ("ArpCacheEntries", std::ios::out);
helper3.PrintNeighborCacheAllEvery (Seconds (1), stream2);
AnimationInterface anim ("ecmp_routing_multi_topo.xml");
anim.SetConstantPosition(c.Get(0),0.0,3.0);
anim.SetConstantPosition(c.Get(1),2.0,3.0);
anim.SetConstantPosition(c.Get(2),6.0,3.0);
anim.SetConstantPosition(c.Get(3),8.0,3.0);
anim.SetConstantPosition(c.Get(4),5.0,1.0);
anim.SetConstantPosition(c.Get(5),4.0,5.0);
anim.SetConstantPosition(c.Get(6),3.0,1.0);
anim.EnablePacketMetadata (true);
Simulator::Stop (Seconds(10));
Simulator::Run ();
Simulator::Destroy ();
}
bool
PointToPointNetDevice::NeedsArp (void) const
{
NS_LOG_FUNCTION (this);
return false;
}
...