A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv4-end-point-demux.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005 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@sophia.inria.fr>
18 */
19
20#ifndef IPV4_END_POINT_DEMUX_H
21#define IPV4_END_POINT_DEMUX_H
22
23#include "ipv4-interface.h"
24
25#include "ns3/ipv4-address.h"
26
27#include <list>
28#include <stdint.h>
29
30namespace ns3
31{
32
33class Ipv4EndPoint;
34
35/**
36 * \ingroup ipv4
37 *
38 * \brief Demultiplexes packets to various transport layer endpoints
39 *
40 * This class serves as a lookup table to match partial or full information
41 * about a four-tuple to an ns3::Ipv4EndPoint. It internally contains a list
42 * of endpoints, and has APIs to add and find endpoints in this demux. This
43 * code is shared in common to TCP and UDP protocols in ns3. This demux
44 * sits between ns3's layer four and the socket layer
45 */
46
48{
49 public:
50 /**
51 * \brief Container of the IPv4 endpoints.
52 */
53 typedef std::list<Ipv4EndPoint*> EndPoints;
54
55 /**
56 * \brief Iterator to the container of the IPv4 endpoints.
57 */
58 typedef std::list<Ipv4EndPoint*>::iterator EndPointsI;
59
62
63 /**
64 * \brief Get the entire list of end points registered.
65 * \return list of Ipv4EndPoint
66 */
68
69 /**
70 * \brief Lookup for port local.
71 * \param port port to test
72 * \return true if a port local is in EndPoints, false otherwise
73 */
74 bool LookupPortLocal(uint16_t port);
75
76 /**
77 * \brief Lookup for address and port.
78 * \param boundNetDevice Bound NetDevice (if any)
79 * \param addr address to test
80 * \param port port to test
81 * \return true if there is a match in EndPoints, false otherwise
82 */
83 bool LookupLocal(Ptr<NetDevice> boundNetDevice, Ipv4Address addr, uint16_t port);
84
85 /**
86 * \brief lookup for a match with all the parameters.
87 *
88 * The function will return a list of most-matching EndPoints, in this order:
89 * -# Full match
90 * -# All but local address
91 * -# Only local port and local address match
92 * -# Only local port match
93 *
94 * EndPoint with disabled Rx are skipped.
95 *
96 * \param daddr destination address to test
97 * \param dport destination port to test
98 * \param saddr source address to test
99 * \param sport source port to test
100 * \param incomingInterface the incoming interface
101 * \return list of IPv4EndPoints (could be 0 element)
102 */
104 uint16_t dport,
105 Ipv4Address saddr,
106 uint16_t sport,
107 Ptr<Ipv4Interface> incomingInterface);
108
109 /**
110 * \brief simple lookup for a match with all the parameters.
111 * \param daddr destination address to test
112 * \param dport destination port to test
113 * \param saddr source address to test
114 * \param sport source port to test
115 * \return IPv4EndPoint (0 if not found)
116 */
118 uint16_t dport,
119 Ipv4Address saddr,
120 uint16_t sport);
121
122 /**
123 * \brief Allocate a Ipv4EndPoint.
124 * \return an empty Ipv4EndPoint instance
125 */
127
128 /**
129 * \brief Allocate a Ipv4EndPoint.
130 * \param address IPv4 address
131 * \return an Ipv4EndPoint instance
132 */
134
135 /**
136 * \brief Allocate a Ipv4EndPoint.
137 * \param boundNetDevice Bound NetDevice (if any)
138 * \param port local port
139 * \return an Ipv4EndPoint instance
140 */
141 Ipv4EndPoint* Allocate(Ptr<NetDevice> boundNetDevice, uint16_t port);
142
143 /**
144 * \brief Allocate a Ipv4EndPoint.
145 * \param boundNetDevice Bound NetDevice (if any)
146 * \param address local address
147 * \param port local port
148 * \return an Ipv4EndPoint instance
149 */
150 Ipv4EndPoint* Allocate(Ptr<NetDevice> boundNetDevice, Ipv4Address address, uint16_t port);
151
152 /**
153 * \brief Allocate a Ipv4EndPoint.
154 * \param boundNetDevice Bound NetDevice (if any)
155 * \param localAddress local address
156 * \param localPort local port
157 * \param peerAddress peer address
158 * \param peerPort peer port
159 * \return an Ipv4EndPoint instance
160 */
161 Ipv4EndPoint* Allocate(Ptr<NetDevice> boundNetDevice,
162 Ipv4Address localAddress,
163 uint16_t localPort,
164 Ipv4Address peerAddress,
165 uint16_t peerPort);
166
167 /**
168 * \brief Remove a end point.
169 * \param endPoint the end point to remove
170 */
171 void DeAllocate(Ipv4EndPoint* endPoint);
172
173 private:
174 /**
175 * \brief Allocate an ephemeral port.
176 * \returns the ephemeral port
177 */
178 uint16_t AllocateEphemeralPort();
179
180 /**
181 * \brief The ephemeral port.
182 */
183 uint16_t m_ephemeral;
184
185 /**
186 * \brief The last ephemeral port.
187 */
188 uint16_t m_portLast;
189
190 /**
191 * \brief The first ephemeral port.
192 */
193 uint16_t m_portFirst;
194
195 /**
196 * \brief A list of IPv4 end points.
197 */
199};
200
201} // namespace ns3
202
203#endif /* IPV4_END_POINTS_H */
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Demultiplexes packets to various transport layer endpoints.
uint16_t m_portFirst
The first ephemeral port.
std::list< Ipv4EndPoint * >::iterator EndPointsI
Iterator to the container of the IPv4 endpoints.
uint16_t AllocateEphemeralPort()
Allocate an ephemeral port.
EndPoints m_endPoints
A list of IPv4 end points.
uint16_t m_portLast
The last ephemeral port.
Ipv4EndPoint * SimpleLookup(Ipv4Address daddr, uint16_t dport, Ipv4Address saddr, uint16_t sport)
simple lookup for a match with all the parameters.
bool LookupLocal(Ptr< NetDevice > boundNetDevice, Ipv4Address addr, uint16_t port)
Lookup for address and port.
EndPoints GetAllEndPoints()
Get the entire list of end points registered.
uint16_t m_ephemeral
The ephemeral port.
EndPoints Lookup(Ipv4Address daddr, uint16_t dport, Ipv4Address saddr, uint16_t sport, Ptr< Ipv4Interface > incomingInterface)
lookup for a match with all the parameters.
bool LookupPortLocal(uint16_t port)
Lookup for port local.
void DeAllocate(Ipv4EndPoint *endPoint)
Remove a end point.
Ipv4EndPoint * Allocate()
Allocate a Ipv4EndPoint.
std::list< Ipv4EndPoint * > EndPoints
Container of the IPv4 endpoints.
A representation of an internet endpoint/connection.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
uint16_t port
Definition: dsdv-manet.cc:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.