CBS 1
CBS 1
CODE-
// Network topology
//
// SRC
// |<=== source network
// A-----B
// \ / \ all networks have cost 1, except
// \ / | for the direct link from C to D, which
// C / has cost 10
// |/
// |/
// D
// |<=== target network
// DST
//
// A, B, C and D are RIPng routers.
// A and D are configured with static addresses.
// SRC and DST will exchange packets.
//
// After about 3 seconds, the topology is built, and Echo Reply will be received.
// After 40 seconds, the link between B and D will break, causing a route failure.
// After 44 seconds from the failure, the routers will recovery from the failure.
// Split Horizoning should affect the recovery time, but it is not. See the manual
// for an explanation of this effect.
//
// If "showPings" is enabled, the user will see:
// 1) if the ping has been acknowledged
// 2) if a Destination Unreachable has been received by the sender
// 3) nothing, when the Echo Request has been received by the destination but
// the Echo Reply is unable to reach the sender.
// Examining the .pcap files with Wireshark can confirm this effect.
#include <fstream>
#include "ns3/core-module.h"
#include "ns3/internet-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-apps-module.h"
#include "ns3/ipv4-static-routing-helper.h"
#include "ns3/ipv4-routing-table-entry.h"
NS_LOG_COMPONENT_DEFINE ("RipSimpleRouting");
CommandLine cmd;
cmd.AddValue ("verbose", "turn on log components", verbose);
cmd.AddValue ("printRoutingTables", "Print routing tables at 30, 60 and 90 seconds",
printRoutingTables);
cmd.AddValue ("showPings", "Show Ping6 reception", showPings);
cmd.AddValue ("splitHorizonStrategy", "Split Horizon strategy to use (NoSplitHorizon,
SplitHorizon, PoisonReverse)", SplitHorizon);
cmd.Parse (argc, argv);
if (verbose)
{
LogComponentEnableAll (LogLevel (LOG_PREFIX_TIME | LOG_PREFIX_NODE));
LogComponentEnable ("RipSimpleRouting", LOG_LEVEL_INFO);
LogComponentEnable ("Rip", LOG_LEVEL_ALL);
LogComponentEnable ("Ipv4Interface", LOG_LEVEL_ALL);
LogComponentEnable ("Icmpv4L4Protocol", LOG_LEVEL_ALL);
LogComponentEnable ("Ipv4L3Protocol", LOG_LEVEL_ALL);
LogComponentEnable ("ArpCache", LOG_LEVEL_ALL);
LogComponentEnable ("V4Ping", LOG_LEVEL_ALL);
}
if (SplitHorizon == "NoSplitHorizon")
{
Config::SetDefault ("ns3::Rip::SplitHorizon", EnumValue (RipNg::NO_SPLIT_HORIZON));
}
else if (SplitHorizon == "SplitHorizon")
{
Config::SetDefault ("ns3::Rip::SplitHorizon", EnumValue (RipNg::SPLIT_HORIZON));
}
else
{
// Rule of thumb:
// Interfaces are added sequentially, starting from 0
// However, interface 0 is always the loopback...
ripRouting.ExcludeInterface (a, 1);
ripRouting.ExcludeInterface (d, 3);
Ipv4ListRoutingHelper listRH;
listRH.Add (ripRouting, 0);
// Ipv4StaticRoutingHelper staticRh;
// listRH.Add (staticRh, 5);
InternetStackHelper internet;
internet.SetIpv6StackInstall (false);
internet.SetRoutingHelper (listRH);
internet.Install (routers);
InternetStackHelper internetNodes;
internetNodes.SetIpv6StackInstall (false);
internetNodes.Install (nodes);
// Assign addresses.
// The source and destination networks have global addresses
// The "core" network just needs link-local addresses for routing.
// We assign global addresses to the routers as well to receive
// ICMPv6 errors.
NS_LOG_INFO ("Assign IPv4 Addresses.");
Ipv4AddressHelper ipv4;
Ptr<Ipv4StaticRouting> staticRouting;
if (printRoutingTables)
{
RipHelper routingHelper;
AsciiTraceHelper ascii;
csma.EnableAsciiAll (ascii.CreateFileStream ("rip-simple-routing.tr"));
csma.EnablePcapAll ("rip-simple-routing", true);
OUTPUT-
-40
-20
85.6
0 kb → 8
it/s → kbit/s 5.
← 85 46.40 60
.60 k kbit/s←
bit/s 7. 5.60 85 k
←280 .6 bit/
0 kb 0 s
it/ kb →
s it/s 85.60
→ kbit/s
← 85 →
.60 k
bit/s
20
40
-60 -40 -20 0 20 40 60