PageRenderTime 57ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/src/internet/helper/ipv6-interface-container.cc

https://github.com/scarletttu/ns-3-codel-dev
C++ | 121 lines | 81 code | 20 blank | 20 comment | 6 complexity | 0f2657cd2beeb2eee08da355475fa38a MD5 | raw file
Possible License(s): GPL-2.0
  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. #include "ns3/node-list.h"
  21. #include "ns3/names.h"
  22. #include "ipv6-interface-container.h"
  23. #include "ns3/ipv6-static-routing-helper.h"
  24. namespace ns3
  25. {
  26. Ipv6InterfaceContainer::Ipv6InterfaceContainer ()
  27. {
  28. }
  29. Ipv6InterfaceContainer::Iterator
  30. Ipv6InterfaceContainer::Begin (void) const
  31. {
  32. return m_interfaces.begin ();
  33. }
  34. Ipv6InterfaceContainer::Iterator
  35. Ipv6InterfaceContainer::End (void) const
  36. {
  37. return m_interfaces.end ();
  38. }
  39. uint32_t Ipv6InterfaceContainer::GetN () const
  40. {
  41. return m_interfaces.size ();
  42. }
  43. uint32_t Ipv6InterfaceContainer::GetInterfaceIndex (uint32_t i) const
  44. {
  45. return m_interfaces[i].second;
  46. }
  47. Ipv6Address Ipv6InterfaceContainer::GetAddress (uint32_t i, uint32_t j) const
  48. {
  49. Ptr<Ipv6> ipv6 = m_interfaces[i].first;
  50. uint32_t interface = m_interfaces[i].second;
  51. return ipv6->GetAddress (interface, j).GetAddress ();
  52. }
  53. void Ipv6InterfaceContainer::Add (Ptr<Ipv6> ipv6, uint32_t interface)
  54. {
  55. m_interfaces.push_back (std::make_pair (ipv6, interface));
  56. }
  57. void Ipv6InterfaceContainer::Add (std::string ipv6Name, uint32_t interface)
  58. {
  59. Ptr<Ipv6> ipv6 = Names::Find<Ipv6> (ipv6Name);
  60. m_interfaces.push_back (std::make_pair (ipv6, interface));
  61. }
  62. void Ipv6InterfaceContainer::Add (Ipv6InterfaceContainer& c)
  63. {
  64. for (InterfaceVector::const_iterator it = c.m_interfaces.begin (); it != c.m_interfaces.end (); it++)
  65. {
  66. m_interfaces.push_back (*it);
  67. }
  68. }
  69. void Ipv6InterfaceContainer::SetRouter (uint32_t i, bool router)
  70. {
  71. Ptr<Ipv6> ipv6 = m_interfaces[i].first;
  72. ipv6->SetForwarding (m_interfaces[i].second, router);
  73. if (router)
  74. {
  75. uint32_t other;
  76. /* assume first global address is index 1 (0 is link-local) */
  77. Ipv6Address routerAddress = ipv6->GetAddress (m_interfaces[i].second, 1).GetAddress ();
  78. for (other = 0; other < m_interfaces.size (); other++)
  79. {
  80. if (other != i)
  81. {
  82. Ptr<Ipv6StaticRouting> routing = 0;
  83. Ipv6StaticRoutingHelper routingHelper;
  84. ipv6 = m_interfaces[other].first;
  85. routing = routingHelper.GetStaticRouting (ipv6);
  86. routing->SetDefaultRoute (routerAddress, m_interfaces[other].second);
  87. }
  88. }
  89. }
  90. }
  91. void Ipv6InterfaceContainer::SetDefaultRoute (uint32_t i, uint32_t router)
  92. {
  93. Ptr<Ipv6> ipv6 = m_interfaces[i].first;
  94. Ptr<Ipv6> ipv6Router = m_interfaces[router].first;
  95. Ipv6Address routerAddress = ipv6Router->GetAddress (m_interfaces[router].second, 1).GetAddress ();
  96. Ptr<Ipv6StaticRouting> routing = 0;
  97. Ipv6StaticRoutingHelper routingHelper;
  98. routing = routingHelper.GetStaticRouting (ipv6);
  99. routing->SetDefaultRoute (routerAddress, m_interfaces[i].second);
  100. }
  101. } /* namespace ns3 */