examples/csma-multicast.cc
changeset 1432 3aef7d7a71c2
parent 1430 25fa26a6533e
child 1433 a6fb891b59fd
equal deleted inserted replaced
1431:3760d52ef5d1 1432:3aef7d7a71c2
    63 int 
    63 int 
    64 main (int argc, char *argv[])
    64 main (int argc, char *argv[])
    65 {
    65 {
    66   // Users may find it convenient to turn on explicit debugging
    66   // Users may find it convenient to turn on explicit debugging
    67   // for selected modules; the below lines suggest how to do this
    67   // for selected modules; the below lines suggest how to do this
    68 #if 0 
    68 #if 0
    69   DebugComponentEnable("Me");
    69   DebugComponentEnable("Me");
    70   DebugComponentEnable("Object");
    70   DebugComponentEnable("Object");
    71   DebugComponentEnable("Queue");
    71   DebugComponentEnable("Queue");
    72   DebugComponentEnable("DropTailQueue");
    72   DebugComponentEnable("DropTailQueue");
    73   DebugComponentEnable("Channel");
    73   DebugComponentEnable("Channel");
    85   DebugComponentEnable("ArpIpv4Interface");
    85   DebugComponentEnable("ArpIpv4Interface");
    86   DebugComponentEnable("Ipv4LoopbackInterface");
    86   DebugComponentEnable("Ipv4LoopbackInterface");
    87 #endif
    87 #endif
    88 
    88 
    89   DebugComponentEnable("Me");
    89   DebugComponentEnable("Me");
    90   DebugComponentEnable("OnOffApplication");
    90   DebugComponentEnable("CsmaChannel");
    91   DebugComponentEnable("UdpSocket");
    91   DebugComponentEnable("CsmaNetDevice");
    92   DebugComponentEnable("UdpL4Protocol");
    92   DebugComponentEnable("UdpL4Protocol");
    93   DebugComponentEnable("Ipv4L3Protocol");
       
    94   DebugComponentEnable("Ipv4StaticRouting");
       
    95   DebugComponentEnable("CsmaNetDevice");
       
    96   DebugComponentEnable("CsmaChannel");
       
    97   DebugComponentEnable("Ipv4Interface");
       
    98   DebugComponentEnable("ArpIpv4Interface");
       
    99   DebugComponentEnable("Ipv4LoopbackInterface");
       
   100 
    93 
   101   // Set up some default values for the simulation.  Use the Bind()
    94   // Set up some default values for the simulation.  Use the Bind()
   102   // technique to tell the system what subclass of Queue to use,
    95   // technique to tell the system what subclass of Queue to use,
   103   // and what the queue limit is
    96   // and what the queue limit is
   104 
    97 
   123   Ptr<CsmaChannel> channel0 = 
   116   Ptr<CsmaChannel> channel0 = 
   124     CsmaTopology::CreateCsmaChannel(
   117     CsmaTopology::CreateCsmaChannel(
   125       DataRate(5000000), MilliSeconds(2));
   118       DataRate(5000000), MilliSeconds(2));
   126 
   119 
   127   NS_DEBUG("Build Topology.");
   120   NS_DEBUG("Build Topology.");
   128   uint32_t n0ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n0, channel0, 
   121   uint32_t netDeviceNumberNode0 = CsmaIpv4Topology::AddIpv4CsmaNode (n0, 
   129                                          Eui48Address("10:54:23:54:23:50"));
   122     channel0, Eui48Address("10:54:23:54:23:50"));
   130   uint32_t n1ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n1, channel0,
   123   uint32_t netDeviceNumberNode1 = CsmaIpv4Topology::AddIpv4CsmaNode (n1, 
   131                                          Eui48Address("10:54:23:54:23:51"));
   124     channel0, Eui48Address("10:54:23:54:23:51"));
   132   uint32_t n2ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n2, channel0,
   125   uint32_t netDeviceNumberNode2 = CsmaIpv4Topology::AddIpv4CsmaNode (n2, 
   133                                          Eui48Address("10:54:23:54:23:52"));
   126     channel0, Eui48Address("10:54:23:54:23:52"));
   134   uint32_t n3ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n3, channel0,
   127   uint32_t netDeviceNumberNode3 = CsmaIpv4Topology::AddIpv4CsmaNode (n3, 
   135                                          Eui48Address("10:54:23:54:23:53"));
   128     channel0, Eui48Address("10:54:23:54:23:53"));
       
   129 
       
   130   NS_DEBUG ("netDeviceNumberNode0 = " << netDeviceNumberNode0);
       
   131   NS_DEBUG ("netDeviceNumberNode1 = " << netDeviceNumberNode1);
       
   132   NS_DEBUG ("netDeviceNumberNode2 = " << netDeviceNumberNode2);
       
   133   NS_DEBUG ("netDeviceNumberNode3 = " << netDeviceNumberNode3);
   136 
   134 
   137   // Later, we add IP addresses.  
   135   // Later, we add IP addresses.  
   138   NS_DEBUG("Assign IP Addresses.");
   136   NS_DEBUG("Assign IP Addresses.");
   139 
   137   // XXX BUGBUG
   140   CsmaIpv4Topology::AddIpv4Address (
   138   // Need a better way to get the interface index.  The point-to-point topology
   141       n0, n0ifIndex, Ipv4Address("10.1.1.1"), Ipv4Mask("255.255.255.0"));
   139   // as implemented can't return the index since it creates interfaces on both
   142 
   140   // sides (i.e., AddIpv4Addresses, not AddIpv4Address).  Need a method on
   143   CsmaIpv4Topology::AddIpv4Address (
   141   // Ipv4 to find the interface index corresponding to a given ipv4 address.
   144       n1, n1ifIndex, Ipv4Address("10.1.1.2"), Ipv4Mask("255.255.255.0"));
   142   uint32_t ifIndexNode0 = CsmaIpv4Topology::AddIpv4Address (n0, 
   145 
   143     netDeviceNumberNode0, Ipv4Address ("10.1.1.1"), 
   146   CsmaIpv4Topology::AddIpv4Address (
   144     Ipv4Mask ("255.255.255.0"));
   147       n2, n2ifIndex, Ipv4Address("10.1.1.3"), Ipv4Mask("255.255.255.0"));
   145 
       
   146   uint32_t ifIndexNode1 = CsmaIpv4Topology::AddIpv4Address (n1, 
       
   147     netDeviceNumberNode1, Ipv4Address ("10.1.1.2"), 
       
   148     Ipv4Mask ("255.255.255.0"));
       
   149 
       
   150   uint32_t ifIndexNode2 = CsmaIpv4Topology::AddIpv4Address (n2, 
       
   151     netDeviceNumberNode2, Ipv4Address ("10.1.1.3"), 
       
   152     Ipv4Mask ("255.255.255.0"));
   148   
   153   
   149   CsmaIpv4Topology::AddIpv4Address (
   154   uint32_t ifIndexNode3 = CsmaIpv4Topology::AddIpv4Address (n3, 
   150       n3, n3ifIndex, Ipv4Address("10.1.1.4"), Ipv4Mask("255.255.255.0"));
   155     netDeviceNumberNode3, Ipv4Address ("10.1.1.4"), 
       
   156     Ipv4Mask ("255.255.255.0"));
       
   157 
       
   158   NS_DEBUG ("ifIndexNode0 = " << ifIndexNode0);
       
   159   NS_DEBUG ("ifIndexNode1 = " << ifIndexNode1);
       
   160   NS_DEBUG ("ifIndexNode2 = " << ifIndexNode2);
       
   161   NS_DEBUG ("ifIndexNode3 = " << ifIndexNode3);
   151 
   162 
   152   // Configure multicasting
   163   // Configure multicasting
   153   NS_DEBUG("Configure multicasting.");
   164   NS_DEBUG("Configure multicasting.");
   154   Ipv4Address multicastSource ("10.1.1.1");
   165   Ipv4Address multicastSource ("10.1.1.1");
   155   Ipv4Address multicastGroup ("225.0.0.0");
   166   Ipv4Address multicastGroup ("225.0.0.0");
   156 
   167 
   157   Ptr<Ipv4> ipv4;
   168   Ptr<Ipv4> ipv4;
   158   ipv4 = n0->QueryInterface<Ipv4> (Ipv4::iid);
   169   ipv4 = n0->QueryInterface<Ipv4> (Ipv4::iid);
   159 
   170 
   160   std::vector<uint32_t> outputInterfaces (1);
   171   std::vector<uint32_t> outputInterfaces (1);
   161   outputInterfaces[0] = n0ifIndex;
   172   outputInterfaces[0] = ifIndexNode0;
   162 
   173 
   163   ipv4->AddMulticastRoute (multicastSource, multicastGroup, 0, 
   174   ipv4->AddMulticastRoute (multicastSource, multicastGroup, 0, 
   164     outputInterfaces);
   175     outputInterfaces);
   165 
   176 
   166   ipv4 = n1->QueryInterface<Ipv4> (Ipv4::iid);
   177   ipv4 = n1->QueryInterface<Ipv4> (Ipv4::iid);
   167   ipv4->JoinMulticastGroup (multicastSource, multicastGroup);
   178   //  ipv4->JoinMulticastGroup (multicastSource, multicastGroup);
   168 
   179 
   169   ipv4 = n2->QueryInterface<Ipv4> (Ipv4::iid);
   180   ipv4 = n2->QueryInterface<Ipv4> (Ipv4::iid);
   170   ipv4->JoinMulticastGroup (multicastSource, multicastGroup);
   181   //  ipv4->JoinMulticastGroup (multicastSource, multicastGroup);
   171 
   182 
   172   ipv4 = n3->QueryInterface<Ipv4> (Ipv4::iid);
   183   ipv4 = n3->QueryInterface<Ipv4> (Ipv4::iid);
   173   ipv4->JoinMulticastGroup (multicastSource, multicastGroup);
   184   //  ipv4->JoinMulticastGroup (multicastSource, multicastGroup);
   174 
   185 
   175   // Create the OnOff application to send UDP datagrams of size
   186   // Create the OnOff application to send UDP datagrams
   176   // 210 bytes at a rate of 448 Kb/s
       
   177   // from n0 to the multicast group
   187   // from n0 to the multicast group
   178   NS_DEBUG("Create Applications.");
   188   NS_DEBUG("Create Applications.");
   179   Ptr<OnOffApplication> ooff = Create<OnOffApplication> (
   189   Ptr<OnOffApplication> ooff = Create<OnOffApplication> (
   180     n0, 
   190     n0, 
   181     InetSocketAddress (multicastGroup, 80), 
   191     InetSocketAddress (multicastGroup, 80), 
   182     "Udp",
   192     "Udp",
   183     ConstantVariable(1), 
   193     ConstantVariable(1), 
   184     ConstantVariable(0));
   194     ConstantVariable(0),
       
   195     DataRate ("128b/s"),
       
   196     128);
   185   // Start the application
   197   // Start the application
   186   ooff->Start(Seconds(1.0));
   198   ooff->Start(Seconds(1.));
   187   ooff->Stop (Seconds(10.0));
   199   ooff->Stop (Seconds(10.));
   188 
   200 
   189   // Configure tracing of all enqueue, dequeue, and NetDevice receive events
   201   // Configure tracing of all enqueue, dequeue, and NetDevice receive events
   190   // Trace output will be sent to the csma-one-subnet.tr file
   202   // Trace output will be sent to the csma-one-subnet.tr file
   191   NS_DEBUG("Configure Tracing.");
   203   NS_DEBUG("Configure Tracing.");
   192   AsciiTrace asciitrace ("csma-multicast.tr");
   204   AsciiTrace asciitrace ("csma-multicast.tr");