A Discrete-Event Network Simulator
API
ipv4-interface-container.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Mathieu Lacage <mathieu.lacage@cutebugs.net>
18  */
19 
21 
22 #include "ns3/names.h"
23 #include "ns3/node-list.h"
24 
25 namespace ns3
26 {
27 
29 {
30 }
31 
32 void
34 {
35  for (auto i = other.m_interfaces.begin(); i != other.m_interfaces.end(); i++)
36  {
37  m_interfaces.push_back(*i);
38  }
39 }
40 
43 {
44  return m_interfaces.begin();
45 }
46 
49 {
50  return m_interfaces.end();
51 }
52 
53 uint32_t
55 {
56  return m_interfaces.size();
57 }
58 
60 Ipv4InterfaceContainer::GetAddress(uint32_t i, uint32_t j) const
61 {
62  Ptr<Ipv4> ipv4 = m_interfaces[i].first;
63  uint32_t interface = m_interfaces[i].second;
64  return ipv4->GetAddress(interface, j).GetLocal();
65 }
66 
67 void
68 Ipv4InterfaceContainer::SetMetric(uint32_t i, uint16_t metric)
69 {
70  Ptr<Ipv4> ipv4 = m_interfaces[i].first;
71  uint32_t interface = m_interfaces[i].second;
72  ipv4->SetMetric(interface, metric);
73 }
74 
75 void
77 {
78  m_interfaces.emplace_back(ipv4, interface);
79 }
80 
81 void
82 Ipv4InterfaceContainer::Add(std::pair<Ptr<Ipv4>, uint32_t> a)
83 {
84  Add(a.first, a.second);
85 }
86 
87 void
88 Ipv4InterfaceContainer::Add(std::string ipv4Name, uint32_t interface)
89 {
90  Ptr<Ipv4> ipv4 = Names::Find<Ipv4>(ipv4Name);
91  m_interfaces.emplace_back(ipv4, interface);
92 }
93 
94 std::pair<Ptr<Ipv4>, uint32_t>
95 Ipv4InterfaceContainer::Get(uint32_t i) const
96 {
97  return m_interfaces[i];
98 }
99 
100 } // namespace ns3
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
std::pair< Ptr< Ipv4 >, uint32_t > Get(uint32_t i) const
Get the std::pair of an Ptr<Ipv4> and interface stored at the location specified by the index.
void SetMetric(uint32_t i, uint16_t metric)
Set a metric for the given interface.
std::vector< std::pair< Ptr< Ipv4 >, uint32_t > >::const_iterator Iterator
Container Const Iterator for pairs of Ipv4 smart pointer / Interface Index.
InterfaceVector m_interfaces
List of IPv4 stack and interfaces index.
void Add(const Ipv4InterfaceContainer &other)
Concatenate the entries in the other container with ours.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Iterator Begin() const
Get an iterator which refers to the first pair in the container.
Ipv4InterfaceContainer()
Create an empty Ipv4InterfaceContainer.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Definition: second.py:1