448 |
448 |
449 You can see that the CSMA channel is a broadcast medium and so all of the |
449 You can see that the CSMA channel is a broadcast medium and so all of the |
450 devices see the ARP requests involved in the packet exchange. The remaining |
450 devices see the ARP requests involved in the packet exchange. The remaining |
451 pcap trace will be identical to this one. |
451 pcap trace will be identical to this one. |
452 |
452 |
|
453 Finally, recall that we added the ability to control the number of CSMA devices |
|
454 in the simulation by command line argument. You can change this argument in |
|
455 the same way as when we looked at changing the number of packets echoed in the |
|
456 @code{first.cc} example. Try setting the number of ``extra'' devices to four: |
|
457 |
|
458 @verbatim |
|
459 ~/repos/ns-3-dev > ./waf --run "scratch/second --nCsma=4" |
|
460 Entering directory `/home/craigdo/repos/ns-3-dev/build' |
|
461 Compilation finished successfully |
|
462 Sent 1024 bytes to 10.1.2.5 |
|
463 Received 1024 bytes from 10.1.1.1 |
|
464 Received 1024 bytes from 10.1.2.5 |
|
465 ~/repos/ns-3-dev > |
|
466 @end verbatim |
|
467 |
|
468 Notice that the echo server has now been relocated to the last of the CSMA |
|
469 nodes, which is 10.1.2.5 instead of the default case, 10.1.2.4. You can |
|
470 increase the number to your hearts content, but remember that you will get a |
|
471 pcap trace file for every node in the simulation. One thing you can do to |
|
472 keep from getting all of those pcap traces with nothing but ARP exchanges in |
|
473 them is to be more specific about which nodes and devices you want to trace. |
|
474 |
|
475 Let's take a look at @code{scratch/second.cc} and be more specific about which |
|
476 nodes and devices we want to trace. The file we provide uses the |
|
477 @code{EnablePcapAll} methods of the helpers to enable pcap on all devices. |
|
478 We want to use the more specific method, @code{EnablePcap}, which takes |
|
479 a node number and device number as parameters. Go ahead and replace the |
|
480 @code{EnablePcapAll} calls with the calls below. |
|
481 |
|
482 @verbatim |
|
483 PointToPointHelper::EnablePcap ("second", p2pNodes.Get (0)->GetId (), 0); |
|
484 CsmaHelper::EnablePcap ("second", csmaNodes.Get (nCsma)->GetId (), 0); |
|
485 @end verbatim |
|
486 |
|
487 We know that we want to create a pcap file with the base name "second" and |
|
488 we also know that the device of interest in both cases is going to be zero, |
|
489 so those parameters are not really interesting. In order to get the node |
|
490 number, you have two choices: first, nodes are numbered in a monotonically |
|
491 increasing fashion starting from zero in the order in which you created them. |
|
492 One way to get a node number to pass to the helper is to figure this number |
|
493 out ``manually.'' If you take a look at the network topology illustration at |
|
494 the beginning of the file, you can see that the last CSMA node is going to be |
|
495 node number code{nCsma + 1}. This can become annoyingly difficult in larger |
|
496 simulations. An alternate way, which we use here, is to realize that the |
|
497 @code{NodeContainer}s contain pointers to ns-3 @code{Node} Objects. The |
|
498 @code{Node} Object has a method called @code{GetId} which will return that |
|
499 node's ID. Let's go take a look at the Doxygen for the @code{Node} and locate |
|
500 that method, which is further down in the code than we've seen so far. |
|
501 |
|
502 Go to the Doxygen documentation for your release (recall that you can find it |
|
503 on the project web site). You can get to the @code{Node} documentation by |
|
504 looking through at the ``Classes'' tab in and scrolling down to |
|
505 @code{ns3::Node} in the list. Select @code{ns3::Node} and you will be taken |
|
506 to the documentation for the @code{Node} class. If you now scroll down to the |
|
507 @code{GetId} method and select it, you will be taken to the detailed |
|
508 documentation for the method. Using the @code{GetId} method can make |
|
509 determining node numbers much easier in complex topologies. |
|
510 |
|
511 Now that we have got some trace filtering in place, it is reasonable to start |
|
512 increasing the number of CSMA devices in our simulation. If you run the |
|
513 simulation setting @code{nCsma} to 100, you will see the following: |
|
514 |
|
515 @verbatim |
|
516 ~/repos/ns-3-dev > ./waf --run "scratch/second --nCsma=100" |
|
517 Entering directory `/home/craigdo/repos/ns-3-dev/build' |
|
518 Compilation finished successfully |
|
519 Sent 1024 bytes to 10.1.2.101 |
|
520 Received 1024 bytes from 10.1.1.1 |
|
521 Received 1024 bytes from 10.1.2.101 |
|
522 ~/repos/ns-3-dev > |
|
523 @end verbatim |
|
524 |
|
525 Note that the echo server is now located at 10.1.2.101 which corresponds to |
|
526 100 ``extra'' CSMA nodes with the echo server on the last one. If you list |
|
527 the pcap files in the top level directory, |
|
528 |
|
529 @verbatim |
|
530 ~/repos/ns-3-dev > ls *.pcap |
|
531 second-0-0.pcap second-101-0.pcap |
|
532 ~/repos/ns-3-dev > |
|
533 @end verbatim |
|
534 |
|
535 you will see that we have, in fact, only created two trace files. The trace |
|
536 file @code{second-0-0.pcap} is the ``leftmost'' point-to-point device which is |
|
537 the echo packet source. The file @code{second-101-0.pcap} corresponds to the |
|
538 rightmost CSMA device which is where the echo server resides. |
|
539 |
|
540 |
|
541 |
|
542 |
|
543 |