src/helper/static-multicast-route-helper.cc
changeset 4472 e20a31541404
parent 4471 ef1730710767
child 4473 39ac17168023
equal deleted inserted replaced
4471:ef1730710767 4472:e20a31541404
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
       
     2 /*
       
     3  * Copyright (c) 2008 University of Washington
       
     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: Tom Henderson <tomhend@u.washington.edu>
       
    19  */
       
    20 
       
    21 #include <vector>
       
    22 #include "ns3/ptr.h"
       
    23 #include "ns3/assert.h"
       
    24 #include "ns3/ipv4-address.h"
       
    25 #include "ns3/ipv4.h"
       
    26 #include "ns3/names.h"
       
    27 #include "static-multicast-route-helper.h"
       
    28 
       
    29 namespace ns3 {
       
    30 
       
    31 StaticMulticastRouteHelper::StaticMulticastRouteHelper ()
       
    32 {
       
    33 }
       
    34 
       
    35 void  
       
    36 StaticMulticastRouteHelper::AddMulticastRoute (
       
    37   Ptr<Node> n,
       
    38   Ipv4Address source, 
       
    39   Ipv4Address group,  
       
    40   Ptr<NetDevice> input, 
       
    41   NetDeviceContainer output)
       
    42 {
       
    43   Ptr<Ipv4> ipv4 = n->GetObject<Ipv4> ();
       
    44 
       
    45   // We need to convert the NetDeviceContainer to an array of interface
       
    46   std::vector<uint32_t> outputInterfaces;
       
    47   for (NetDeviceContainer::Iterator i = output.Begin (); i != output.End (); ++i)
       
    48     {
       
    49       Ptr<NetDevice> nd = *i;
       
    50       uint32_t ointerface = ipv4->FindInterfaceForDevice (nd);
       
    51       outputInterfaces.push_back(ointerface);
       
    52     }
       
    53   uint32_t iinterface = ipv4->FindInterfaceForDevice (input);
       
    54   ipv4->AddMulticastRoute (source, group, iinterface, outputInterfaces);
       
    55 }
       
    56 
       
    57 void  
       
    58 StaticMulticastRouteHelper::AddMulticastRoute (
       
    59   Ptr<Node> n,
       
    60   Ipv4Address source, 
       
    61   Ipv4Address group,  
       
    62   std::string inputName, 
       
    63   NetDeviceContainer output)
       
    64 {
       
    65   Ptr<NetDevice> input = Names::Find<NetDevice> (inputName);
       
    66   AddMulticastRoute (n, source, group, input, output);
       
    67 }
       
    68 
       
    69 void  
       
    70 StaticMulticastRouteHelper::AddMulticastRoute (
       
    71   std::string nName,
       
    72   Ipv4Address source, 
       
    73   Ipv4Address group,  
       
    74   Ptr<NetDevice> input, 
       
    75   NetDeviceContainer output)
       
    76 {
       
    77   Ptr<Node> n = Names::Find<Node> (nName);
       
    78   AddMulticastRoute (n, source, group, input, output);
       
    79 }
       
    80 
       
    81 void  
       
    82 StaticMulticastRouteHelper::AddMulticastRoute (
       
    83   std::string nName,
       
    84   Ipv4Address source, 
       
    85   Ipv4Address group,  
       
    86   std::string inputName, 
       
    87   NetDeviceContainer output)
       
    88 {
       
    89   Ptr<NetDevice> input = Names::Find<NetDevice> (inputName);
       
    90   Ptr<Node> n = Names::Find<Node> (nName);
       
    91   AddMulticastRoute (n, source, group, input, output);
       
    92 }
       
    93 
       
    94 void
       
    95 StaticMulticastRouteHelper::SetDefaultMulticastRoute (
       
    96   Ptr<Node> n, 
       
    97   Ptr<NetDevice> nd)
       
    98 {
       
    99   Ptr<Ipv4> ipv4 = n->GetObject<Ipv4> ();
       
   100   uint32_t interfaceSrc = ipv4->FindInterfaceForDevice (nd);
       
   101   ipv4->SetDefaultMulticastRoute (interfaceSrc);
       
   102 }
       
   103 
       
   104 void
       
   105 StaticMulticastRouteHelper::SetDefaultMulticastRoute (
       
   106   Ptr<Node> n, 
       
   107   std::string ndName)
       
   108 {
       
   109   Ptr<NetDevice> nd = Names::Find<NetDevice> (ndName);
       
   110   SetDefaultMulticastRoute (n, nd);
       
   111 }
       
   112 
       
   113 void
       
   114 StaticMulticastRouteHelper::SetDefaultMulticastRoute (
       
   115   std::string nName, 
       
   116   Ptr<NetDevice> nd)
       
   117 {
       
   118   Ptr<Node> n = Names::Find<Node> (nName);
       
   119   SetDefaultMulticastRoute (n, nd);
       
   120 }
       
   121 
       
   122 void
       
   123 StaticMulticastRouteHelper::SetDefaultMulticastRoute (
       
   124   std::string nName, 
       
   125   std::string ndName)
       
   126 {
       
   127   Ptr<Node> n = Names::Find<Node> (nName);
       
   128   Ptr<NetDevice> nd = Names::Find<NetDevice> (ndName);
       
   129   SetDefaultMulticastRoute (n, nd);
       
   130 }
       
   131 
       
   132 void
       
   133 StaticMulticastRouteHelper::JoinMulticastGroup (
       
   134   Ptr<Node> n, 
       
   135   Ipv4Address source, 
       
   136   Ipv4Address group)
       
   137 {
       
   138   Ptr<Ipv4> ipv4 = n->GetObject<Ipv4> ();
       
   139   ipv4->JoinMulticastGroup (source, group);
       
   140 }
       
   141 
       
   142 void
       
   143 StaticMulticastRouteHelper::JoinMulticastGroup (
       
   144   std::string nName, 
       
   145   Ipv4Address source, 
       
   146   Ipv4Address group)
       
   147 {
       
   148   Ptr<Node> n = Names::Find<Node> (nName);
       
   149   JoinMulticastGroup (n, source, group);
       
   150 }
       
   151 
       
   152 } // namespace ns3
       
   153