17 #ifndef HH_SENF_Ext_NetEmu_P2PTunnel_TunnelController_ 18 #define HH_SENF_Ext_NetEmu_P2PTunnel_TunnelController_ 1 21 #include <boost/multi_index_container.hpp> 22 #include <boost/multi_index/ordered_index.hpp> 37 class TunnelInterfaceBase;
38 class TunnelServerInterface;
39 class TunnelClientInterface;
46 typedef std::map<CapacityDirection, unsigned>
Capacity;
70 void dump(std::ostream & os)
const;
71 std::string
dump()
const;
78 static const unsigned TunnelOverhead = 46u;
83 PacketType readPacket(Handle & handle);
84 bool writePacket(Handle & handle, PacketType packet);
92 void dumpInfo(std::ostream & os);
94 unsigned fragmentationCount();
101 void do_sendPkt(Handle & handle,
senf::EthernetPacket & pkt, std::pair<senf::INet6SocketAddress,unsigned>
const & txInfo);
103 void flushQueue(Handle & handle);
106 void sendCtrlPacket(Handle & handle,
MACAddress const & dstMAC, boost::uint8_t code);
110 virtual std::pair<INet6SocketAddress,unsigned> v_getTxInfo(
Packet const & eth)
const = 0;
115 virtual bool v_writePacket(Handle & handle, PacketType & packet) = 0;
116 virtual void v_dumpInfo(std::ostream & os)
const = 0;
117 virtual void v_timeoutChanged() {};
121 boost::scoped_ptr<ppi::QueueingAlgorithm> qAlgo_;
138 void terminateAllClients(
Handle handle);
141 unsigned fragmentationThreshold(
MACAddress const & clientAddr)
const;
142 void fragmentationThreshold(
MACAddress const & clientAddr,
unsigned mtu);
146 std::pair<INet6SocketAddress,unsigned> v_getTxInfo(
Packet const & eth)
const override;
152 void v_dumpInfo(std::ostream & os)
const override;
153 void sendSetupRequest();
154 void processTimeout();
166 unsigned fragmentationThreshold;
170 client.txSeqNo = (client.txSeqNo + 1) % 0x20000;
183 client.rxSeqNo = seqno;
189 : fragmentationThreshold(_fragmentationThreshold) {} ;
191 client.fragmentationThreshold = fragmentationThreshold;
196 client.lastSeen = scheduler::now();
202 : inetAddr(_inetAddr) {}
204 client.inetAddr = inetAddr;
211 : direction(_direction), capacity(_capacity) {}
213 client.capacity[direction] = capacity;
218 : macAddr(_macAddr), inetAddr(_inetAddr),
lastSeen(scheduler::now()), txSeqNo(0), rxSeqNo(0xffffffff), reSyncs(0),
219 fragmentationThreshold(1280u) {}
222 struct ByLastSeen {};
223 struct ByINetAddr {};
226 :
public boost::multi_index::indexed_by<
227 boost::multi_index::ordered_non_unique<
228 boost::multi_index::tag<ByLastSeen>,
229 BOOST_MULTI_INDEX_MEMBER(TunnelClient, ClockService::clock_type, lastSeen)>,
230 boost::multi_index::ordered_unique<
231 boost::multi_index::tag<ByMACAddr>,
232 BOOST_MULTI_INDEX_MEMBER(TunnelClient, MACAddress, macAddr)>,
233 boost::multi_index::ordered_unique<
234 boost::multi_index::tag<ByINetAddr>,
235 BOOST_MULTI_INDEX_MEMBER(TunnelClient, INet6SocketAddress, inetAddr)> >
238 typedef boost::multi_index_container<TunnelClient, ClientIndexes> Clients;
244 Clients_by_lastSeen & clients_by_lastSeen_;
245 Clients_by_macAddr & clients_by_macAddr_;
246 Clients_by_inetAddr & clients_by_inetAddr_;
261 bool established()
const;
267 unsigned fragmentationThreshold()
const;
268 void fragmentationThreshold(
unsigned mtu);
272 std::pair<INet6SocketAddress,unsigned> v_getTxInfo(
Packet const & eth)
const override;
278 void v_dumpInfo(std::ostream & os)
const override;
279 void v_timeoutChanged()
override;
280 void sendSetupRequest();
281 void processTimeout();
292 unsigned fragmentationThreshold_;
293 unsigned setupRequests_;
config::time_type clock_type
virtual ~TunnelControllerBase()
std::map< CapacityDirection, unsigned > Capacity
virtual ~TunnelServerController()
void operator()(TunnelClient &client)
INet6SocketAddress inetAddr
void operator()(TunnelClient &client)
updateRxSeqNo(unsigned _seqno)
void operator()(TunnelClient &client)
ProtocolClientSocketHandle< UDPv6SocketProtocol > UDPv6ClientSocketHandle
void operator()(TunnelClient &client)
updateFragmentationThreshold(unsigned _fragmentationThreshold)
unsigned fragmentationThreshold
std::unique_ptr< QueueingAlgorithm > ptr
senf::ClockService::clock_type tstamp
updateInetAddr(INet6SocketAddress const &_inetAddr)
void dump(std::ostream &os, DirectoryNode &dir=root())
void operator()(TunnelClient &client)
TunnelServerInterface Interface
SENF_PACKET_FWD_DECL(TunnelCtrlPacket)
senf::Detail::DifferenceSigned seqNoDiff_
UDPv6ClientSocketHandle Handle
virtual ~TunnelClientController()
updateCapacity(tunnel::CapacityDirection _direction, unsigned _capacity)
ConcretePacket< TunnelCtrlPacketType > TunnelCtrlPacket
EthernetPacket PacketType
void operator()(TunnelClient &client)
tunnel::CapacityDirection direction
TunnelClientInterface Interface
ConcretePacket< EthernetPacketType > EthernetPacket
senf::ConcretePacket< TunnelHeaderPacketType > TunnelHeaderPacket
void operator()(TunnelClient &client)