156 already have one node in the CSMA network -- the one that will have both a |
156 already have one node in the CSMA network -- the one that will have both a |
157 point-to-point and CSMA net device, the number of ``extra'' nodes means the |
157 point-to-point and CSMA net device, the number of ``extra'' nodes means the |
158 number nodes you desire in the CSMA section minus one. |
158 number nodes you desire in the CSMA section minus one. |
159 |
159 |
160 The next bit of code should be quite familiar by now. We instantiate a |
160 The next bit of code should be quite familiar by now. We instantiate a |
161 @code{PointToPointHelper} and set the associated default attributes so that |
161 @code{PointToPointHelper} and set the associated default @code{Attributes} so |
162 we create a five megabit per second transmitter on devices created using the |
162 that we create a five megabit per second transmitter on devices created using |
163 helper and a two millisecond delay on channels created by the helper. |
163 the helper and a two millisecond delay on channels created by the helper. |
164 |
164 |
165 @verbatim |
165 @verbatim |
166 PointToPointHelper pointToPoint; |
166 PointToPointHelper pointToPoint; |
167 pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); |
167 pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); |
168 pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); |
168 pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); |
177 |
177 |
178 We mentioned above that you were going to see a helper for CSMA devices and |
178 We mentioned above that you were going to see a helper for CSMA devices and |
179 channels, and the next lines introduce them. The @code{CsmaHelper} works just |
179 channels, and the next lines introduce them. The @code{CsmaHelper} works just |
180 like a @code{PointToPointHelper}, but it creates and connects CSMA devices and |
180 like a @code{PointToPointHelper}, but it creates and connects CSMA devices and |
181 channels. In the case of a CSMA device and channel pair, notice that the data |
181 channels. In the case of a CSMA device and channel pair, notice that the data |
182 rate is specified by a @emph{channel} attribute instead of a device attribute. |
182 rate is specified by a @emph{channel} @code{Attribute} instead of a device |
183 This is because a real CSMA network does not allow one to mix, for example, |
183 @code{Attribute}. This is because a real CSMA network does not allow one to mix, |
184 10Base-T and 100Base-T devices on a given channel. We first set the data rate |
184 for example, 10Base-T and 100Base-T devices on a given channel. We first set |
185 to 100 megabits per second, and then set the speed-of-light delay of the channel |
185 the data rate to 100 megabits per second, and then set the speed-of-light delay |
186 to 6560 nano-seconds (arbitrarily chosen as 1 nanosecond per foot over a 100 |
186 of the channel to 6560 nano-seconds (arbitrarily chosen as 1 nanosecond per foot |
187 meter segment). Notice that you can set an attribute using its native data |
187 over a 100 meter segment). Notice that you can set an @code{Attribute} using |
188 type. |
188 its native data type. |
189 |
189 |
190 @verbatim |
190 @verbatim |
191 CsmaHelper csma; |
191 CsmaHelper csma; |
192 csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps")); |
192 csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps")); |
193 csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560))); |
193 csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560))); |
250 @code{first.cc} but we are going to instantiate the server on one of the |
250 @code{first.cc} but we are going to instantiate the server on one of the |
251 nodes that has a CSMA node and the client on the node having only a |
251 nodes that has a CSMA node and the client on the node having only a |
252 point-to-point device. |
252 point-to-point device. |
253 |
253 |
254 First, we set up the echo server. We create a @code{UdpEchoServerHelper} and |
254 First, we set up the echo server. We create a @code{UdpEchoServerHelper} and |
255 provide a required attribute value to the constructor which is the server port |
255 provide a required @code{Attribute} value to the constructor which is the server |
256 number. Recall that this port can be changed later using the |
256 port number. Recall that this port can be changed later using the |
257 @code{SetAttribute} method if desired, but we require it to be provided to |
257 @code{SetAttribute} method if desired, but we require it to be provided to |
258 the constructor. |
258 the constructor. |
259 |
259 |
260 @verbatim |
260 @verbatim |
261 UdpEchoServerHelper echoServer (9); |
261 UdpEchoServerHelper echoServer (9); |
274 if we create @code{nCsma} ``extra'' nodes the last one will be at index |
274 if we create @code{nCsma} ``extra'' nodes the last one will be at index |
275 @code{nCsma}. You see this exhibited in the @code{Get} of the first line of |
275 @code{nCsma}. You see this exhibited in the @code{Get} of the first line of |
276 code. |
276 code. |
277 |
277 |
278 The client application is set up exactly as we did in the @code{first.cc} |
278 The client application is set up exactly as we did in the @code{first.cc} |
279 example script. Again, we provide required attributes to the |
279 example script. Again, we provide required @code{Attributes} to the |
280 @code{UdpEchoClientHelper} in the constructor (in this case the remote address |
280 @code{UdpEchoClientHelper} in the constructor (in this case the remote address |
281 and port). We tell the client to send packets to the server we just installed |
281 and port). We tell the client to send packets to the server we just installed |
282 on the last of the ``extra'' CSMA nodes. We install the client on the |
282 on the last of the ``extra'' CSMA nodes. We install the client on the |
283 leftmost point-to-point node seen in the topology illustration. |
283 leftmost point-to-point node seen in the topology illustration. |
284 |
284 |
778 NodeContainer p2pNodes; |
778 NodeContainer p2pNodes; |
779 p2pNodes.Create (2); |
779 p2pNodes.Create (2); |
780 @end verbatim |
780 @end verbatim |
781 |
781 |
782 Next, we see an old friend. We instantiate a @code{PointToPointHelper} and |
782 Next, we see an old friend. We instantiate a @code{PointToPointHelper} and |
783 set the associated default attributes so that we create a five megabit per |
783 set the associated default @code{Attributes} so that we create a five megabit |
784 second transmitter on devices created using the helper and a two millisecond |
784 per second transmitter on devices created using the helper and a two millisecond |
785 delay on channels created by the helper. We then @code{Intall} the devices |
785 delay on channels created by the helper. We then @code{Intall} the devices |
786 on the nodes and the channel between them. |
786 on the nodes and the channel between them. |
787 |
787 |
788 @verbatim |
788 @verbatim |
789 PointToPointHelper pointToPoint; |
789 PointToPointHelper pointToPoint; |
807 from the point-to-point node container and adds it to the container of nodes |
807 from the point-to-point node container and adds it to the container of nodes |
808 that will get CSMA devices. The node in question is going to end up with a |
808 that will get CSMA devices. The node in question is going to end up with a |
809 point-to-point device and a CSMA device. We then create a number of ``extra'' |
809 point-to-point device and a CSMA device. We then create a number of ``extra'' |
810 nodes that compose the remainder of the CSMA network. |
810 nodes that compose the remainder of the CSMA network. |
811 |
811 |
812 We then instantiate a @code{CsmaHelper} and set its attributes as we did in |
812 We then instantiate a @code{CsmaHelper} and set its @code{Attributes} as we did |
813 the previous example. We create a @code{NetDeviceContainer} to keep track of |
813 in the previous example. We create a @code{NetDeviceContainer} to keep track of |
814 the created CSMA net devices and then we @code{Install} CSMA devices on the |
814 the created CSMA net devices and then we @code{Install} CSMA devices on the |
815 selected nodes. |
815 selected nodes. |
816 |
816 |
817 @verbatim |
817 @verbatim |
818 CsmaHelper csma; |
818 CsmaHelper csma; |
880 This code first creates an 802.11 service set identifier (SSID) object that |
880 This code first creates an 802.11 service set identifier (SSID) object that |
881 will be used to set the value of the ``Ssid'' @code{Attribute} of the MAC |
881 will be used to set the value of the ``Ssid'' @code{Attribute} of the MAC |
882 layer implementation. The particular kind of MAC layer is specified by |
882 layer implementation. The particular kind of MAC layer is specified by |
883 @code{Attribute} as being of the "ns3::NqstaWifiMac" type. This means that |
883 @code{Attribute} as being of the "ns3::NqstaWifiMac" type. This means that |
884 the MAC will use a ``non-QoS station'' (nqsta) state machine. Finally, the |
884 the MAC will use a ``non-QoS station'' (nqsta) state machine. Finally, the |
885 ``ActiveProbing'' attribute is set to false. This means that probe requests |
885 ``ActiveProbing'' @code{Attribute} is set to false. This means that probe |
886 will not be sent by MACs created by this helper. |
886 requests will not be sent by MACs created by this helper. |
887 |
887 |
888 Once all the station-specific parameters are fully configured, both at the |
888 Once all the station-specific parameters are fully configured, both at the |
889 MAC and PHY layers, we can invoke our now-familiar @code{Install} method to |
889 MAC and PHY layers, we can invoke our now-familiar @code{Install} method to |
890 create the wifi devices of these stations: |
890 create the wifi devices of these stations: |
891 |
891 |
906 "BeaconInterval", TimeValue (Seconds (2.5))); |
906 "BeaconInterval", TimeValue (Seconds (2.5))); |
907 @end verbatim |
907 @end verbatim |
908 |
908 |
909 In this case, the @code{WifiHelper} is going to create MAC layers of the |
909 In this case, the @code{WifiHelper} is going to create MAC layers of the |
910 ``ns3::NqapWifiMac'' (Non-Qos Access Point) type. We set the |
910 ``ns3::NqapWifiMac'' (Non-Qos Access Point) type. We set the |
911 ``BeaconGeneration'' attribute to true and also set an interval between |
911 ``BeaconGeneration'' @code{Attribute} to true and also set an interval between |
912 beacons of 2.5 seconds. |
912 beacons of 2.5 seconds. |
913 |
913 |
914 The next lines create the single AP which shares the same set of PHY-level |
914 The next lines create the single AP which shares the same set of PHY-level |
915 attributes (and channel) as the stations: |
915 @code{Attributes} (and channel) as the stations: |
916 |
916 |
917 @verbatim |
917 @verbatim |
918 NetDeviceContainer apDevices; |
918 NetDeviceContainer apDevices; |
919 apDevices = wifi.Install (phy, wifiApNode); |
919 apDevices = wifi.Install (phy, wifiApNode); |
920 @end verbatim |
920 @end verbatim |
921 |
921 |
922 Now, we are going to add mobility models. We want the STA nodes to be mobile, |
922 Now, we are going to add mobility models. We want the STA nodes to be mobile, |
923 wandering around inside a bounding box, and we want to make the AP node |
923 wandering around inside a bounding box, and we want to make the AP node |
924 stationary. We use the @code{MobilityHelper} to make this easy for us. |
924 stationary. We use the @code{MobilityHelper} to make this easy for us. |
925 First, we instantiate a @code{MobilityHelper} object and set some attributes |
925 First, we instantiate a @code{MobilityHelper} object and set some |
926 controlling the ``position allocator'' functionality. |
926 @code{Attributes} controlling the ``position allocator'' functionality. |
927 |
927 |
928 @verbatim |
928 @verbatim |
929 MobilityHelper mobility; |
929 MobilityHelper mobility; |
930 |
930 |
931 mobility.SetPositionAllocator ("ns3::GridPositionAllocator", |
931 mobility.SetPositionAllocator ("ns3::GridPositionAllocator", |
1327 which you can find in the ``Modules'' tab. |
1327 which you can find in the ``Modules'' tab. |
1328 Under the ``core'' section, you will find a link to ``The list of all trace |
1328 Under the ``core'' section, you will find a link to ``The list of all trace |
1329 sources.'' You may find it interesting to try and hook some of these |
1329 sources.'' You may find it interesting to try and hook some of these |
1330 traces yourself. Additionally in the ``Modules'' documentation, there is |
1330 traces yourself. Additionally in the ``Modules'' documentation, there is |
1331 a link to ``The list of all attributes.'' You can set the default value of |
1331 a link to ``The list of all attributes.'' You can set the default value of |
1332 any of these attributes via the command line as we have previously discussed. |
1332 any of these @code{Attributes} via the command line as we have previously |
|
1333 discussed. |
1333 |
1334 |
1334 We have just scratched the surface of @command{ns-3} in this tutorial, but we |
1335 We have just scratched the surface of @command{ns-3} in this tutorial, but we |
1335 hope we have covered enough to get you started doing useful work. |
1336 hope we have covered enough to get you started doing useful work. |
1336 |
1337 |
1337 -- The @command{ns-3} development team. |
1338 -- The @command{ns-3} development team. |