A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ipv6-interface-container.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008-2009 Strasbourg University
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: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
19  */
20 
21 #include "ns3/node-list.h"
22 #include "ns3/names.h"
23 
24 #include "ipv6-interface-container.h"
25 #include "ns3/ipv6-static-routing-helper.h"
26 
27 namespace ns3
28 {
29 
31 {
32 }
33 
34 Ipv6InterfaceContainer::Iterator
36 {
37  return m_interfaces.begin ();
38 }
39 
40 Ipv6InterfaceContainer::Iterator
42 {
43  return m_interfaces.end ();
44 }
45 
47 {
48  return m_interfaces.size ();
49 }
50 
51 uint32_t Ipv6InterfaceContainer::GetInterfaceIndex (uint32_t i) const
52 {
53  return m_interfaces[i].second;
54 }
55 
56 Ipv6Address Ipv6InterfaceContainer::GetAddress (uint32_t i, uint32_t j) const
57 {
58  Ptr<Ipv6> ipv6 = m_interfaces[i].first;
59  uint32_t interface = m_interfaces[i].second;
60  return ipv6->GetAddress (interface, j).GetAddress ();
61 }
62 
63 void Ipv6InterfaceContainer::Add (Ptr<Ipv6> ipv6, uint32_t interface)
64 {
65  m_interfaces.push_back (std::make_pair (ipv6, interface));
66 }
67 
68 void Ipv6InterfaceContainer::Add (std::string ipv6Name, uint32_t interface)
69 {
70  Ptr<Ipv6> ipv6 = Names::Find<Ipv6> (ipv6Name);
71  m_interfaces.push_back (std::make_pair (ipv6, interface));
72 }
73 
75 {
76  for (InterfaceVector::const_iterator it = c.m_interfaces.begin (); it != c.m_interfaces.end (); it++)
77  {
78  m_interfaces.push_back (*it);
79  }
80 }
81 
82 void Ipv6InterfaceContainer::SetRouter (uint32_t i, bool router)
83 {
84  Ptr<Ipv6> ipv6 = m_interfaces[i].first;
85  ipv6->SetForwarding (m_interfaces[i].second, router);
86 
87  if (router)
88  {
89  uint32_t other;
90  /* assume first global address is index 1 (0 is link-local) */
91  Ipv6Address routerAddress = ipv6->GetAddress (m_interfaces[i].second, 1).GetAddress ();
92 
93  for (other = 0; other < m_interfaces.size (); other++)
94  {
95  if (other != i)
96  {
97  Ptr<Ipv6StaticRouting> routing = 0;
98  Ipv6StaticRoutingHelper routingHelper;
99 
100  ipv6 = m_interfaces[other].first;
101  routing = routingHelper.GetStaticRouting (ipv6);
102  routing->SetDefaultRoute (routerAddress, m_interfaces[other].second);
103  }
104  }
105  }
106 }
107 
108 void Ipv6InterfaceContainer::SetDefaultRoute (uint32_t i, uint32_t router)
109 {
110  Ptr<Ipv6> ipv6 = m_interfaces[i].first;
111  Ptr<Ipv6> ipv6Router = m_interfaces[router].first;
112  Ipv6Address routerAddress = ipv6Router->GetAddress (m_interfaces[router].second, 1).GetAddress ();
113  Ptr<Ipv6StaticRouting> routing = 0;
114  Ipv6StaticRoutingHelper routingHelper;
115 
116  routing = routingHelper.GetStaticRouting (ipv6);
117  routing->SetDefaultRoute (routerAddress, m_interfaces[i].second);
118 }
119 
120 } /* namespace ns3 */
121 
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
Keep track of a set of IPv6 interfaces.
void Add(Ptr< Ipv6 > ipv6, uint32_t interface)
Add a couple IPv6/interface.
Ptr< Ipv6StaticRouting > GetStaticRouting(Ptr< Ipv6 > ipv6) const
Get Ipv6StaticRouting pointer from IPv6 stack.
InterfaceVector m_interfaces
List of IPv6 stack and interfaces index.
uint32_t GetInterfaceIndex(uint32_t i) const
Get the interface index for the specified node index.
void SetDefaultRoute(uint32_t i, uint32_t router)
Set the default route for the specified index.
void SetRouter(uint32_t i, bool router)
Set the state of the stack (act as a router or not) for the specified index.
Helper class that adds ns3::Ipv6StaticRouting objects.
Describes an IPv6 address.
Definition: ipv6-address.h:44
Iterator Begin(void) const
Get an iterator which refers to the first pair in the container.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.