1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 /* 3 * Copyright (c) 2007-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 #ifndef IPV6_END_POINT_DEMUX_H 22 #define IPV6_END_POINT_DEMUX_H 23 24 #include <stdint.h> 25 #include <list> 26 #include "ns3/ipv6-address.h" 27 #include "ipv6-interface.h" 28 29 namespace ns3 { 30 31 class Ipv6EndPoint; 32 33 /** 34 * \ingroup ipv6 35 * 36 * \brief Demultiplexer for end points. 37 */ 38 class Ipv6EndPointDemux 39 { 40 public: 41 /** 42 * \brief Container of the IPv6 endpoints. 43 */ 44 typedef std::list<Ipv6EndPoint *>EndPoints; 45 46 /** 47 * \brief Iterator to the container of the IPv6 endpoints. 48 */ 49 typedef std::list<Ipv6EndPoint *>::iterator EndPointsI; 50 51 Ipv6EndPointDemux (); 52 ~Ipv6EndPointDemux (); 53 54 /** 55 * \brief Lookup for port local. 56 * \param port port to test 57 * \return true if a port local is in EndPoints, false otherwise 58 */ 59 bool LookupPortLocal (uint16_t port); 60 61 /** 62 * \brief Lookup for address and port. 63 * \param boundNetDevice Bound NetDevice (if any) 64 * \param addr address to test 65 * \param port port to test 66 * \return true if there is a match in EndPoints, false otherwise 67 */ 68 bool LookupLocal (Ptr<NetDevice> boundNetDevice, Ipv6Address addr, uint16_t port); 69 70 /** 71 * \brief lookup for a match with all the parameters. 72 * 73 * The function will return a list of most-matching EndPoints, in this order: 74 * -# Full match 75 * -# All but local address 76 * -# Only local port and local address match 77 * -# Only local port match 78 * 79 * EndPoint with disabled Rx are skipped. 80 * 81 * \param dst destination address to test 82 * \param dport destination port to test 83 * \param src source address to test 84 * \param sport source port to test 85 * \param incomingInterface the incoming interface 86 * \return list of IPv6EndPoints (could be 0 element) 87 */ 88 EndPoints Lookup (Ipv6Address dst, uint16_t dport, Ipv6Address src, uint16_t sport, Ptr<Ipv6Interface> incomingInterface); 89 90 /** 91 * \brief Simple lookup for a four-tuple match. 92 * \param dst destination address to test 93 * \param dport destination port to test 94 * \param src source address to test 95 * \param sport source port to test 96 * \return match or 0 if not found 97 */ 98 Ipv6EndPoint* SimpleLookup (Ipv6Address dst, uint16_t dport, Ipv6Address src, uint16_t sport); 99 100 /** 101 * \brief Allocate a Ipv6EndPoint. 102 * \return an empty Ipv6EndPoint instance 103 */ 104 Ipv6EndPoint * Allocate (void); 105 106 /** 107 * \brief Allocate a Ipv6EndPoint. 108 * \param address IPv6 address 109 * \return an Ipv6EndPoint instance 110 */ 111 Ipv6EndPoint * Allocate (Ipv6Address address); 112 113 /** 114 * \brief Allocate a Ipv6EndPoint. 115 * \param boundNetDevice Bound NetDevice (if any) 116 * \param port local port 117 * \return an Ipv6EndPoint instance 118 */ 119 Ipv6EndPoint * Allocate (Ptr<NetDevice> boundNetDevice, uint16_t port); 120 121 /** 122 * \brief Allocate a Ipv6EndPoint. 123 * \param boundNetDevice Bound NetDevice (if any) 124 * \param address local address 125 * \param port local port 126 * \return an Ipv6EndPoint instance 127 */ 128 Ipv6EndPoint * Allocate (Ptr<NetDevice> boundNetDevice, Ipv6Address address, uint16_t port); 129 130 /** 131 * \brief Allocate a Ipv6EndPoint. 132 * \param boundNetDevice Bound NetDevice (if any) 133 * \param localAddress local address 134 * \param localPort local port 135 * \param peerAddress peer address 136 * \param peerPort peer port 137 * \return an Ipv6EndPoint instance 138 */ 139 Ipv6EndPoint * Allocate (Ptr<NetDevice> boundNetDevice, 140 Ipv6Address localAddress, uint16_t localPort, 141 Ipv6Address peerAddress, uint16_t peerPort); 142 143 /** 144 * \brief Remove a end point. 145 * \param endPoint the end point to remove 146 */ 147 void DeAllocate (Ipv6EndPoint *endPoint); 148 149 /** 150 * \brief Get the entire list of end points registered. 151 * \return list of Ipv6EndPoint 152 */ 153 EndPoints GetEndPoints () const; 154 155 private: 156 /** 157 * \brief Allocate a ephemeral port. 158 * \return a port 159 */ 160 uint16_t AllocateEphemeralPort (); 161 162 /** 163 * \brief The ephemeral port. 164 */ 165 uint16_t m_ephemeral; 166 167 /** 168 * \brief The first ephemeral port. 169 */ 170 uint16_t m_portFirst; 171 172 /** 173 * \brief The last ephemeral port. 174 */ 175 uint16_t m_portLast; 176 177 /** 178 * \brief A list of IPv6 end points. 179 */ 180 EndPoints m_endPoints; 181 }; 182 183 } /* namespace ns3 */ 184 185 #endif /* IPV6_END_POINT_DEMUX_H */ 186 187