33 template <
class Controller>
34 prefix_ senf::emu::detail::TunnelIOHelper<Controller>::TunnelIOHelper(TunnelControllerBase & ctrl, TunnelInterfaceNet<Controller>
const & tif)
35 : ctrl_(ctrl), tunnelIface_(tif)
38 template <
class Controller>
39 prefix_ typename senf::emu::detail::TunnelIOHelper<Controller>::PacketType senf::emu::detail::TunnelIOHelper<Controller>::operator()(Handle & handle)
41 auto pkt (ctrl_.readPacket(handle));
52 template <
class Controller>
53 prefix_ bool senf::emu::detail::TunnelIOHelper<Controller>::operator()(Handle & handle, PacketType
const & packet)
55 if (
SENF_LIKELY(packet.size() <= tunnelIface_.mtu() + 18))
65 template <
class Controller>
66 prefix_ senf::emu::detail::TunnelInterfaceNet<Controller>::TunnelInterfaceNet(
typename Controller::Interface & interface)
68 source(socket, TunnelIOHelper<Controller>(tunnelCtrl, *
this)), sink(socket, TunnelIOHelper<Controller>(tunnelCtrl, *
this)),
69 netOutput(source.output), netInput(sink.input), mtu_(1500u), maxBurst_(48), promisc_(
false), annotationMode_(
false)
73 template <
class Controller>
77 source.handle(socket);
78 source.maxBurst(maxBurst_);
82 template <
class Controller>
83 prefix_ unsigned senf::emu::detail::TunnelInterfaceNet<Controller>::rcvBuf()
86 return socket.protocol().rcvbuf();
90 template <
class Controller>
91 prefix_ void senf::emu::detail::TunnelInterfaceNet<Controller>::rcvBuf(
unsigned rcvbuf)
94 socket.protocol().rcvbuf(rcvbuf);
97 template <
class Controller>
98 prefix_ unsigned senf::emu::detail::TunnelInterfaceNet<Controller>::sndBuf()
101 return socket.protocol().sndbuf();
105 template <
class Controller>
106 prefix_ void senf::emu::detail::TunnelInterfaceNet<Controller>::sndBuf(
unsigned sndbuf)
109 socket.protocol().sndbuf(sndbuf);
112 template <
class Controller>
113 prefix_ unsigned senf::emu::detail::TunnelInterfaceNet<Controller>::mtu()
119 template <
class Controller>
120 prefix_ void senf::emu::detail::TunnelInterfaceNet<Controller>::mtu(
unsigned v)
127 template <
class Controller>
128 prefix_ unsigned senf::emu::detail::TunnelInterfaceNet<Controller>::maxBurst()
131 return source.maxBurst();
134 template <
class Controller>
135 prefix_ void senf::emu::detail::TunnelInterfaceNet<Controller>::maxBurst(
unsigned v)
138 source.maxBurst(maxBurst_);
141 template <
class Controller>
142 prefix_ void senf::emu::detail::TunnelInterfaceNet<Controller>::_promisc(
bool p)
147 template <
class Controller>
148 prefix_ bool senf::emu::detail::TunnelInterfaceNet<Controller>::_promisc()
154 template <
class Controller>
155 prefix_ void senf::emu::detail::TunnelInterfaceNet<Controller>::_annotationMode(
bool a)
160 template <
class Controller>
161 prefix_ bool senf::emu::detail::TunnelInterfaceNet<Controller>::_annotationMode()
164 return annotationMode_;
172 struct DisableInterfaceGuard
175 : iface_ (iface), enabled_ (iface_.enabled())
176 {
if (enabled_) iface_.disable(); }
178 ~DisableInterfaceGuard()
179 {
if (enabled_) iface_.enable(); }
186 namespace senf {
namespace emu {
namespace tunnel {
190 template <
class Output,
class Input>
195 id_(ifaceIdFactory_->getId()), isUp_(false), dev_(
"NetEMU-P2PTunnel")
200 namespace fty = console::factory;
202 .
add(
"timeout", fty::Command(
205 .
add(
"timeout", fty::Command(
212 .
add(
"address", fty::Command(
220 ifaceIdFactory_->releaseId(
id());
250 return socketAddress_;
266 return ifaceIdFactory_;
271 DisableInterfaceGuard guard (*
this);
272 ifaceIdFactory_->releaseId( id_);
273 ifaceIdFactory_ = factory;
275 id( ifaceIdFactory_->getId());
283 prefix_ bool senf::emu::TunnelInterfaceBase::v_enabled()
291 DisableInterfaceGuard guard (*
this);
292 ifaceIdFactory_->releaseId( id_);
307 prefix_ void senf::emu::TunnelInterfaceBase::v_mcDrop(
MACAddress const & address)
312 prefix_ boost::uint8_t senf::emu::TunnelInterfaceBase::v_linkTypeId()
318 prefix_ std::string
const & senf::emu::TunnelInterfaceBase::v_device()
334 : detail::TunnelServerInterfaceNet( *this),
336 sndBufSize_(96*1024), rcvBufSize_(384*1024)
338 namespace fty = console::factory;
340 .
add(
"sndBuf", fty::Command(
342 .doc(
"set the send socket buffer size in bytes"));
344 .
add(
"sndBuf", fty::Command(
346 .doc(
"get the send socket buffer size in bytes"));
348 .
add(
"rcvBuf", fty::Command(
350 .doc(
"set the receive socket buffer size in bytes"));
352 .
add(
"rcvBuf", fty::Command(
354 .doc(
"get the receive socket buffer size in bytes"));
356 .
add(
"fragmentationThreshold", fty::Command(
358 .doc(
"set the fragmentationThreshold for the specified client in bytes"));
360 .
add(
"fragmentationThreshold", fty::Command(
362 .doc(
"get the fragmentationThreshold for the specified client in bytes"));
364 .
add(
"maxBurst", fty::Command(
366 .doc(
"set the maxBurst limit when receiving packets"));
368 .
add(
"maxBurst", fty::Command(
370 .doc(
"get the maxBurst limit when receiving packets"));
373 prefix_ void senf::emu::TunnelServerInterface::v_enable()
377 socket.blocking(
false);
378 socket.protocol().mtuDiscovery(IP_PMTUDISC_DONT);
380 assignSocket( socket);
385 prefix_ void senf::emu::TunnelServerInterface::v_disable()
388 tunnelCtrl.terminateAllClients( sink.handle());
395 return tunnelCtrl.capacity(client, direction);
412 sndBufSize_ =
std::max(sndbuf, 2048u);
413 TunnelInterfaceNet::sndBuf( sndBufSize_);
419 return sndBufSize_ = TunnelInterfaceNet::sndBuf();
425 rcvBufSize_ =
std::max(rcvbuf, 4096u);
426 TunnelInterfaceNet::rcvBuf( rcvBufSize_);
432 return rcvBufSize_ = TunnelInterfaceNet::rcvBuf();
435 prefix_ unsigned senf::emu::TunnelServerInterface::v_mtu()
438 return TunnelInterfaceNet::mtu();
441 prefix_ void senf::emu::TunnelServerInterface::v_mtu(
unsigned v)
443 TunnelInterfaceNet::mtu(v);
449 return TunnelInterfaceNet::maxBurst();
454 TunnelInterfaceNet::maxBurst(v);
457 prefix_ void senf::emu::TunnelServerInterface::v_promisc(
bool p)
459 TunnelInterfaceNet::_promisc(p);
462 prefix_ bool senf::emu::TunnelServerInterface::v_promisc()
465 return TunnelInterfaceNet::_promisc();
468 prefix_ void senf::emu::TunnelServerInterface::v_annotationMode(
bool a)
470 TunnelInterfaceNet::_annotationMode(a);
473 prefix_ bool senf::emu::TunnelServerInterface::v_annotationMode()
476 return TunnelInterfaceNet::_annotationMode();
489 : detail::TunnelClientInterfaceNet( *this),
491 sndBufSize_(96*1024), rcvBufSize_(384*1024)
493 namespace fty = console::factory;
497 .
add(
"serverAddress", fty::Command(
500 .
add(
"serverAddress", fty::Command(
503 .
add(
"serverAddress", fty::Command(
506 .
add(
"capacity", fty::Variable(capacity_));
509 .
add(
"sndBuf", fty::Command(
511 .doc(
"set the send socket buffer size in bytes"));
513 .
add(
"sndBuf", fty::Command(
515 .doc(
"get the send socket buffer size in bytes"));
517 .
add(
"rcvBuf", fty::Command(
519 .doc(
"set the receive socket buffer size in bytes"));
521 .
add(
"rcvBuf", fty::Command(
523 .doc(
"get the receive socket buffer size in bytes"));
525 .
add(
"fragmentationThreshold", fty::Command(
527 .doc(
"set the fragmentationThreshold for this tunnel in bytes"));
529 .
add(
"fragmentationThreshold", fty::Command(
531 .doc(
"get the fragmentationThreshold for this tunnel in bytes"));
533 .
add(
"maxBurst", fty::Command(
535 .doc(
"set the maxBurst limit when receiving packets"));
537 .
add(
"maxBurst", fty::Command(
539 .doc(
"get the maxBurst limit when receiving packets"));
545 prefix_ void senf::emu::TunnelClientInterface::v_enable()
550 socket.blocking(
false);
551 socket.protocol().mtuDiscovery(IP_PMTUDISC_DONT);
553 assignSocket(socket);
559 prefix_ void senf::emu::TunnelClientInterface::v_disable()
573 tunnelCtrl.serverAddress( address);
579 return tunnelCtrl.serverAddress();
585 return tunnelCtrl.established();
591 tunnel::Capacity::const_iterator i (capacity_.find(direction));
592 return i != capacity_.end() ? i->second : 0u;
597 capacity_[direction] = cap;
615 sndBufSize_ =
std::max(sndbuf, 2048u);
616 TunnelInterfaceNet::sndBuf( sndBufSize_);
622 return sndBufSize_ = TunnelInterfaceNet::sndBuf();
628 rcvBufSize_ =
std::max(rcvbuf, 4096u);
629 TunnelInterfaceNet::rcvBuf( rcvBufSize_);
635 return rcvBufSize_ = TunnelInterfaceNet::rcvBuf();
638 prefix_ unsigned senf::emu::TunnelClientInterface::v_mtu()
641 return TunnelInterfaceNet::mtu();
644 prefix_ void senf::emu::TunnelClientInterface::v_mtu(
unsigned v)
646 TunnelInterfaceNet::mtu(v);
652 return TunnelInterfaceNet::maxBurst();
657 TunnelInterfaceNet::maxBurst(v);
660 prefix_ void senf::emu::TunnelClientInterface::v_promisc(
bool p)
662 TunnelInterfaceNet::_promisc(p);
665 prefix_ bool senf::emu::TunnelClientInterface::v_promisc()
668 return TunnelInterfaceNet::_promisc();
671 prefix_ void senf::emu::TunnelClientInterface::v_annotationMode(
bool a)
673 TunnelInterfaceNet::_annotationMode(a);
676 prefix_ bool senf::emu::TunnelClientInterface::v_annotationMode()
679 return TunnelInterfaceNet::_annotationMode();
TunnelControlPacket public header.
TunnelClientInterface(INet6SocketAddress const &address)
unsigned capacity(tunnel::CapacityDirection direction) const
config::time_type clock_type
static MACAddress const None
senf::ppi::QueueingAlgorithm & qAlgorithm() const
unsigned capacity(MACAddress const &client, tunnel::CapacityDirection direction) const
#define SENF_MEMBINDFNP(ret, cls, fn, args)
ClockService::clock_type timeout() const
INet6SocketAddress const & address() const
ProtocolClientSocketHandle< UDPv6SocketProtocol > UDPv6ClientSocketHandle
EthernetPacket prependAnnotationsPacket(Packet const &pkt, MACAddress const &src_=senf::MACAddress::None, MACAddress const &dst_=senf::MACAddress::Broadcast)
TunnelServerInterface(INet6SocketAddress const &address)
std::unique_ptr< QueueingAlgorithm > ptr
console::DirectoryNode & consoleDir() const
Access interface console directory.
static INet6Address from_inet4address(INet4Address const &addr)
void dumpInfo(std::ostream &os)
NodeType & add(std::string const &name, boost::shared_ptr< NodeType > node)
detail::TunnelControllerBase & tunnelCtrlBase()
unsigned fragmentationThreshold() const
unsigned maxBurst() const
MACAddress const & id() const
Get interface MAC Address.
unsigned maxBurst() const
INet6SocketAddress const & serverAddress() const
unsigned fragmentationCount()
ppi::QueueingAlgorithm & qAlgorithm() const
SENF_CONSOLE_REGISTER_ENUM(CapacityDirection,(FromClientToServer)(FromServerToClient))
ClockService::clock_type timeout() const
unsigned fragmentationThreshold(MACAddress const &client) const
boost::shared_ptr< InterfaceIdFactoryBase > ifaceIdFactory()
TunnelInterface public header.
TunnelInterfaceBase(Output &output, Input &input, detail::TunnelControllerBase &ctrlBase, INet6SocketAddress const &address)
ConcretePacket< EthernetPacketType > EthernetPacket
virtual ~TunnelInterfaceBase()
AnnotationsPacket public header.
INet4Address address() const