17 #include <linux/sockios.h> 18 #include <linux/filter.h> 29 prefix_ senf::emu::detail::TAPEthernetInterfaceNet::TAPEthernetInterfaceNet(std::string
const & device)
31 dev_(device), ctrl_(device),
32 annotatorRx_(true, false, ctrl_.hardwareAddress()), annotatorTx_(false, false),
33 netOutput (annotatorRx_.output), netInput (annotatorTx_.input)
35 socket.blocking(
false);
37 senf::ppi::connect(source.output, annotatorRx_.input);
38 senf::ppi::connect(annotatorTx_.output, sink.input);
41 prefix_ void senf::emu::detail::TAPEthernetInterfaceNet::assignSockets(
bool on)
44 source.handle(socket);
56 struct DisableInterfaceGuard
59 : iface_ (iface), enabled_ (iface_.enabled())
60 {
if (enabled_) iface_.disable(); }
62 ~DisableInterfaceGuard()
63 {
if (enabled_) iface_.enable(); }
71 : TAPEthernetInterfaceNet(device),
73 pvid_(
VLanId::None), accessMode_(false)
78 namespace fty = console::factory;
81 .
add(
"mmapStats", fty::Command(&TAPEthernetInterface::dumpMmapStats,
this)
82 .doc(
"dumps and resets the socket's RX/TX statistics"));
84 .
add(
"maxBurst", fty::Command(
86 .doc(
"set max burst rate"));
88 .
add(
"maxBurst", fty::Command(
90 .doc(
"get max burst rate"));
92 .
add(
"pvid", fty::Command(
94 .doc(
"enables filtering for a specific PVID (VLAN ID must be 0...4095)"));
96 .
add(
"pvid", fty::Command(
98 .doc(
"report the currently configured PVID (-1 means none)"));
103 annotatorRx_.id(
id());
129 TAPEthernetInterfaceNet::assignSockets(
true);
138 TAPEthernetInterfaceNet::assignSockets(
false);
141 prefix_ bool senf::emu::TAPEthernetInterface::v_enabled()
149 DisableInterfaceGuard guard (*
this);
150 ctrl_.hardwareAddress(mac);
151 annotatorRx_.id(mac);
157 return ctrl_.hardwareAddress();
160 prefix_ bool senf::emu::TAPEthernetInterface::v_promisc()
163 return ctrl_.promisc();
166 prefix_ void senf::emu::TAPEthernetInterface::v_promisc(
bool p)
171 prefix_ bool senf::emu::TAPEthernetInterface::v_annotationMode()
174 return annotatorRx_.annotate();
177 prefix_ void senf::emu::TAPEthernetInterface::v_annotationMode(
bool a)
179 annotatorRx_.annotate(a);
193 prefix_ void senf::emu::TAPEthernetInterface::v_mcAdd(
MACAddress const & address)
198 prefix_ void senf::emu::TAPEthernetInterface::v_mcDrop(
MACAddress const & address)
204 prefix_ void senf::emu::TAPEthernetInterface::v_flushRxQueues()
206 TAPEthernetInterfaceNet::source.flush();
211 if (!accessMode and p.
stag())
215 accessMode_ = accessMode;
219 annotatorRx_.insertTag(pvid_);
220 annotatorTx_.removeTag(pvid_);
222 annotatorRx_.removeTag(pvid_);
223 annotatorTx_.insertTag(pvid_);
226 annotatorRx_.clearTag();
227 annotatorTx_.clearTag();
235 return TAPEthernetInterfaceNet::annotatorRx_.vlanMismatch();
240 return TAPEthernetInterfaceNet::annotatorTx_.vlanMismatch();
246 return source.maxBurst();
251 source.maxBurst(maxBurst);
254 prefix_ void senf::emu::TAPEthernetInterface::dumpMmapStats(std::ostream & os)
256 if (TAPEthernetInterfaceNet::socket.valid()) {
257 os <<
"Socket acvtive (fd=" << socket.protocol().fd() <<
", available " << socket.protocol().available() <<
"), RxStats: ";
258 source.rxStats().dump(os); os <<
" TxStats: "; sink.txStats().dump(os); os << std::endl;
260 os <<
"Socket closed. Not stats available." << std::endl;
std::string const & v_device() const override
Hardware Ethernet Interface.
#define SENF_MEMBINDFNP(ret, cls, fn, args)
bool enabled() const
true, if interface enabled
std::uint32_t vlanMismatchTx()
TAPEthernetInterface public header.
console::DirectoryNode & consoleDir() const
Access interface console directory.
std::string const & device() const
NodeType & add(std::string const &name, boost::shared_ptr< NodeType > node)
virtual void v_disable() override
Called to disable interface.
ProtocolClientSocketHandle< TapSocketProtocol > TapSocketHandle
std::uint32_t vlanMismatchRx()
console::DirectoryNode & interfaceDir()
virtual void v_enable() override
Called to enable interface.
TAPEthernetInterface(std::string const &name)
virtual unsigned v_mtu() const override
Called to get interface MTU.
VLanId const & pvid() const
unsigned maxBurst() const