PacketMultiplexer.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
  4. *
  5. * (c) ZeroTier, Inc.
  6. * https://www.zerotier.com/
  7. */
  8. #ifndef ZT_PACKET_MULTIPLEXER_HPP
  9. #define ZT_PACKET_MULTIPLEXER_HPP
  10. #include "../osdep/BlockingQueue.hpp"
  11. #include "MAC.hpp"
  12. #include "Mutex.hpp"
  13. #include "RuntimeEnvironment.hpp"
  14. #include <thread>
  15. #include <vector>
  16. namespace ZeroTier {
  17. struct PacketRecord {
  18. void* tPtr;
  19. uint64_t nwid;
  20. void** nuptr;
  21. uint64_t source;
  22. uint64_t dest;
  23. unsigned int etherType;
  24. unsigned int vlanId;
  25. uint8_t data[ZT_MAX_MTU];
  26. unsigned int len;
  27. unsigned int flowId;
  28. };
  29. class PacketMultiplexer {
  30. public:
  31. const RuntimeEnvironment* RR;
  32. PacketMultiplexer(const RuntimeEnvironment* renv);
  33. void setUpPostDecodeReceiveThreads(unsigned int concurrency, bool cpuPinningEnabled);
  34. void putFrame(void* tPtr, uint64_t nwid, void** nuptr, const MAC& source, const MAC& dest, unsigned int etherType, unsigned int vlanId, const void* data, unsigned int len, unsigned int flowId);
  35. std::vector<BlockingQueue<PacketRecord*>*> _rxPacketQueues;
  36. unsigned int _concurrency = 0;
  37. // pool
  38. std::vector<PacketRecord*> _rxPacketVector;
  39. std::vector<std::thread> _rxPacketThreads;
  40. Mutex _rxPacketVector_m, _rxPacketThreads_m;
  41. std::vector<std::thread> _rxThreads;
  42. bool _enabled = false;
  43. };
  44. } // namespace ZeroTier
  45. #endif // ZT_PACKET_MULTIPLEXER_HPP