PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/examples/ipv6/loose-routing-ipv6.cc

https://github.com/scarletttu/ns-3-codel-dev
C++ | 171 lines | 106 code | 23 blank | 42 comment | 0 complexity | 729b2584175bab4033a76fbbf6a8d638 MD5 | raw file
Possible License(s): GPL-2.0
  1. /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
  2. /*
  3. * Copyright (c) 2009 Strasbourg University
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation;
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. * Author: David Gross <gdavid.devel@gmail.com>
  19. */
  20. // Network topology
  21. // //
  22. // //
  23. // // +------------+
  24. // // +------------+ |---| Router 1 |---|
  25. // // | Host 0 |--| | [------------] |
  26. // // [------------] | | |
  27. // // | +------------+ |
  28. // // +--| | +------------+
  29. // // | Router 0 | | Router 2 |
  30. // // +--| | [------------]
  31. // // | [------------] |
  32. // // +------------+ | | |
  33. // // | Host 1 |--| | +------------+ |
  34. // // [------------] |---| Router 3 |---|
  35. // // [------------]
  36. // //
  37. // //
  38. // // - Tracing of queues and packet receptions to file "loose-routing-ipv6.tr"
  39. #include <fstream>
  40. #include "ns3/core-module.h"
  41. #include "ns3/internet-module.h"
  42. #include "ns3/csma-module.h"
  43. #include "ns3/applications-module.h"
  44. #include "ns3/ipv6-header.h"
  45. using namespace ns3;
  46. NS_LOG_COMPONENT_DEFINE ("LooseRoutingIpv6Example");
  47. int main (int argc, char **argv)
  48. {
  49. #if 0
  50. LogComponentEnable ("Ipv6ExtensionLooseRouting", LOG_LEVEL_ALL);
  51. LogComponentEnable ("Ipv6Extension", LOG_LEVEL_ALL);
  52. LogComponentEnable ("Ipv6L3Protocol", LOG_LEVEL_ALL);
  53. LogComponentEnable ("Ipv6StaticRouting", LOG_LEVEL_ALL);
  54. LogComponentEnable ("Ipv6Interface", LOG_LEVEL_ALL);
  55. LogComponentEnable ("Ipv6Interface", LOG_LEVEL_ALL);
  56. LogComponentEnable ("NdiscCache", LOG_LEVEL_ALL);
  57. #endif
  58. CommandLine cmd;
  59. cmd.Parse (argc, argv);
  60. NS_LOG_INFO ("Create nodes.");
  61. Ptr<Node> h0 = CreateObject<Node> ();
  62. Ptr<Node> h1 = CreateObject<Node> ();
  63. Ptr<Node> r0 = CreateObject<Node> ();
  64. Ptr<Node> r1 = CreateObject<Node> ();
  65. Ptr<Node> r2 = CreateObject<Node> ();
  66. Ptr<Node> r3 = CreateObject<Node> ();
  67. NodeContainer net1 (h0, r0);
  68. NodeContainer net2 (h1, r0);
  69. NodeContainer net3 (r0, r1);
  70. NodeContainer net4 (r1, r2);
  71. NodeContainer net5 (r2, r3);
  72. NodeContainer net6 (r3, r0);
  73. NodeContainer all;
  74. all.Add (h0);
  75. all.Add (h1);
  76. all.Add (r0);
  77. all.Add (r1);
  78. all.Add (r2);
  79. all.Add (r3);
  80. NS_LOG_INFO ("Create IPv6 Internet Stack");
  81. InternetStackHelper internetv6;
  82. internetv6.Install (all);
  83. NS_LOG_INFO ("Create channels.");
  84. CsmaHelper csma;
  85. csma.SetDeviceAttribute ("Mtu", UintegerValue (1500));
  86. csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
  87. csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
  88. NetDeviceContainer d1 = csma.Install (net1);
  89. NetDeviceContainer d2 = csma.Install (net2);
  90. NetDeviceContainer d3 = csma.Install (net3);
  91. NetDeviceContainer d4 = csma.Install (net4);
  92. NetDeviceContainer d5 = csma.Install (net5);
  93. NetDeviceContainer d6 = csma.Install (net6);
  94. NS_LOG_INFO ("Create networks and assign IPv6 Addresses.");
  95. Ipv6AddressHelper ipv6;
  96. ipv6.NewNetwork (Ipv6Address ("2001:1::"), 64);
  97. Ipv6InterfaceContainer i1 = ipv6.Assign (d1);
  98. i1.SetRouter (1, true);
  99. ipv6.NewNetwork (Ipv6Address ("2001:2::"), 64);
  100. Ipv6InterfaceContainer i2 = ipv6.Assign (d2);
  101. i2.SetRouter (1, true);
  102. ipv6.NewNetwork (Ipv6Address ("2001:3::"), 64);
  103. Ipv6InterfaceContainer i3 = ipv6.Assign (d3);
  104. i3.SetRouter (0, true);
  105. i3.SetRouter (1, true);
  106. ipv6.NewNetwork (Ipv6Address ("2001:4::"), 64);
  107. Ipv6InterfaceContainer i4 = ipv6.Assign (d4);
  108. i4.SetRouter (0, true);
  109. i4.SetRouter (1, true);
  110. ipv6.NewNetwork (Ipv6Address ("2001:5::"), 64);
  111. Ipv6InterfaceContainer i5 = ipv6.Assign (d5);
  112. i5.SetRouter (0, true);
  113. i5.SetRouter (1, true);
  114. ipv6.NewNetwork (Ipv6Address ("2001:6::"), 64);
  115. Ipv6InterfaceContainer i6 = ipv6.Assign (d6);
  116. i6.SetRouter (0, true);
  117. i6.SetRouter (1, true);
  118. NS_LOG_INFO ("Create Applications.");
  119. /**
  120. * ICMPv6 Echo from h0 to h1 port 7
  121. */
  122. uint32_t packetSize = 1024;
  123. uint32_t maxPacketCount = 1;
  124. Time interPacketInterval = Seconds (1.0);
  125. std::vector<Ipv6Address> routersAddress;
  126. routersAddress.push_back (i3.GetAddress (1, 1));
  127. routersAddress.push_back (i4.GetAddress (1, 1));
  128. routersAddress.push_back (i5.GetAddress (1, 1));
  129. routersAddress.push_back (i6.GetAddress (1, 1));
  130. routersAddress.push_back (i2.GetAddress (0, 1));
  131. Ping6Helper client;
  132. /* remote address is first routers in RH0 => source routing */
  133. client.SetRemote (i1.GetAddress (1, 1));
  134. client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
  135. client.SetAttribute ("Interval", TimeValue (interPacketInterval));
  136. client.SetAttribute ("PacketSize", UintegerValue (packetSize));
  137. client.SetRoutersAddress (routersAddress);
  138. ApplicationContainer apps = client.Install (h0);
  139. apps.Start (Seconds (1.0));
  140. apps.Stop (Seconds (10.0));
  141. AsciiTraceHelper ascii;
  142. csma.EnableAsciiAll (ascii.CreateFileStream ("loose-routing-ipv6.tr"));
  143. csma.EnablePcapAll ("loose-routing-ipv6", true);
  144. NS_LOG_INFO ("Run Simulation.");
  145. Simulator::Run ();
  146. Simulator::Destroy ();
  147. NS_LOG_INFO ("Done.");
  148. }