OLD | NEW |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * This program is free software; you can redistribute it and/or modify | 3 * This program is free software; you can redistribute it and/or modify |
4 * it under the terms of the GNU General Public License version 2 as | 4 * it under the terms of the GNU General Public License version 2 as |
5 * published by the Free Software Foundation; | 5 * published by the Free Software Foundation; |
6 * | 6 * |
7 * This program is distributed in the hope that it will be useful, | 7 * This program is distributed in the hope that it will be useful, |
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 * GNU General Public License for more details. | 10 * GNU General Public License for more details. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (137)); | 49 Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (137)); |
50 | 50 |
51 // ??? try and stick 15kb/s into the data rate | 51 // ??? try and stick 15kb/s into the data rate |
52 Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("14kb/s"))
; | 52 Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("14kb/s"))
; |
53 | 53 |
54 // | 54 // |
55 // Default number of nodes in the star. Overridable by command line argument. | 55 // Default number of nodes in the star. Overridable by command line argument. |
56 // | 56 // |
57 uint32_t nSpokes = 8; | 57 uint32_t nSpokes = 8; |
58 std::string animFile = "star-animation.xml"; | 58 std::string animFile = "star-animation.xml"; |
| 59 uint8_t useIpv6 = 0; |
| 60 Ipv6Address ipv6AddressBase = Ipv6Address("2001::"); |
| 61 Ipv6Prefix ipv6AddressPrefix = Ipv6Prefix(64); |
59 | 62 |
60 CommandLine cmd; | 63 CommandLine cmd; |
61 cmd.AddValue ("nSpokes", "Number of spoke nodes to place in the star", nSpokes
); | 64 cmd.AddValue ("nSpokes", "Number of spoke nodes to place in the star", nSpokes
); |
62 cmd.AddValue ("animFile", "File Name for Animation Output", animFile); | 65 cmd.AddValue ("animFile", "File Name for Animation Output", animFile); |
| 66 cmd.AddValue ("useIpv6", "use Ipv6", useIpv6); |
63 | 67 |
64 cmd.Parse (argc, argv); | 68 cmd.Parse (argc, argv); |
65 | 69 |
66 NS_LOG_INFO ("Build star topology."); | 70 NS_LOG_INFO ("Build star topology."); |
67 PointToPointHelper pointToPoint; | 71 PointToPointHelper pointToPoint; |
68 pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); | 72 pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); |
69 pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); | 73 pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); |
70 PointToPointStarHelper star (nSpokes, pointToPoint); | 74 PointToPointStarHelper star (nSpokes, pointToPoint); |
71 | 75 |
72 NS_LOG_INFO ("Install internet stack on all nodes."); | 76 NS_LOG_INFO ("Install internet stack on all nodes."); |
73 InternetStackHelper internet; | 77 InternetStackHelper internet; |
74 star.InstallStack (internet); | 78 star.InstallStack (internet); |
75 | 79 |
76 NS_LOG_INFO ("Assign IP Addresses."); | 80 NS_LOG_INFO ("Assign IP Addresses."); |
77 star.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0")); | 81 if (useIpv6 == 0) |
| 82 { |
| 83 star.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"))
; |
| 84 } |
| 85 else |
| 86 { |
| 87 star.AssignIpv6Addresses (ipv6AddressBase, ipv6AddressPrefix); |
| 88 } |
78 | 89 |
79 NS_LOG_INFO ("Create applications."); | 90 NS_LOG_INFO ("Create applications."); |
80 // | 91 // |
81 // Create a packet sink on the star "hub" to receive packets. | 92 // Create a packet sink on the star "hub" to receive packets. |
82 //· | 93 //· |
83 uint16_t port = 50000; | 94 uint16_t port = 50000; |
84 Address hubLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)); | 95 Address hubLocalAddress; |
| 96 if (useIpv6 == 0) |
| 97 { |
| 98 hubLocalAddress = InetSocketAddress (Ipv4Address::GetAny (), port); |
| 99 } |
| 100 else |
| 101 { |
| 102 hubLocalAddress = Inet6SocketAddress (Ipv6Address::GetAny (), port); |
| 103 } |
85 PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", hubLocalAddress); | 104 PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", hubLocalAddress); |
86 ApplicationContainer hubApp = packetSinkHelper.Install (star.GetHub ()); | 105 ApplicationContainer hubApp = packetSinkHelper.Install (star.GetHub ()); |
87 hubApp.Start (Seconds (1.0)); | 106 hubApp.Start (Seconds (1.0)); |
88 hubApp.Stop (Seconds (10.0)); | 107 hubApp.Stop (Seconds (10.0)); |
89 | 108 |
90 // | 109 // |
91 // Create OnOff applications to send TCP to the hub, one on each spoke node. | 110 // Create OnOff applications to send TCP to the hub, one on each spoke node. |
92 // | 111 // |
93 OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ()); | 112 OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ()); |
94 onOffHelper.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))
); | 113 onOffHelper.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))
); |
95 onOffHelper.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)
)); | 114 onOffHelper.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)
)); |
96 | 115 |
97 ApplicationContainer spokeApps; | 116 ApplicationContainer spokeApps; |
98 | 117 |
99 for (uint32_t i = 0; i < star.SpokeCount (); ++i) | 118 for (uint32_t i = 0; i < star.SpokeCount (); ++i) |
100 { | 119 { |
101 AddressValue remoteAddress (InetSocketAddress (star.GetHubIpv4Address (i),
port)); | 120 AddressValue remoteAddress; |
| 121 if (useIpv6 == 0) |
| 122 { |
| 123 remoteAddress = AddressValue(InetSocketAddress (star.GetHubIpv4Address
(i), port)); |
| 124 } |
| 125 else |
| 126 { |
| 127 remoteAddress = AddressValue(Inet6SocketAddress (star.GetHubIpv6Addres
s (i), port)); |
| 128 } |
102 onOffHelper.SetAttribute ("Remote", remoteAddress); | 129 onOffHelper.SetAttribute ("Remote", remoteAddress); |
103 spokeApps.Add (onOffHelper.Install (star.GetSpokeNode (i))); | 130 spokeApps.Add (onOffHelper.Install (star.GetSpokeNode (i))); |
104 } | 131 } |
105 spokeApps.Start (Seconds (1.0)); | 132 spokeApps.Start (Seconds (1.0)); |
106 spokeApps.Stop (Seconds (10.0)); | 133 spokeApps.Stop (Seconds (10.0)); |
107 | 134 |
108 NS_LOG_INFO ("Enable static global routing."); | 135 NS_LOG_INFO ("Enable static global routing."); |
109 // | 136 // |
110 // Turn on global static routing so we can actually be routed across the star. | 137 // Turn on global static routing so we can actually be routed across the star. |
111 // | 138 // |
112 Ipv4GlobalRoutingHelper::PopulateRoutingTables (); | 139 if (useIpv6 == 0) |
| 140 { |
| 141 Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
| 142 } |
113 | 143 |
114 // Set the bounding box for animation | 144 // Set the bounding box for animation |
115 star.BoundingBox (1, 1, 100, 100); | 145 star.BoundingBox (1, 1, 100, 100); |
116 | 146 |
117 // Create the animation object and configure for specified output | 147 // Create the animation object and configure for specified output |
118 AnimationInterface anim (animFile); | 148 AnimationInterface anim (animFile); |
119 | 149 |
120 NS_LOG_INFO ("Run Simulation."); | 150 NS_LOG_INFO ("Run Simulation."); |
121 Simulator::Run (); | 151 Simulator::Run (); |
122 Simulator::Destroy (); | 152 Simulator::Destroy (); |
123 NS_LOG_INFO ("Done."); | 153 NS_LOG_INFO ("Done."); |
124 | 154 |
125 return 0; | 155 return 0; |
126 } | 156 } |
OLD | NEW |