PacketMultiplexer.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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;
  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. unsigned int _rxThreadCount;
  43. bool _enabled;
  44. };
  45. } // namespace ZeroTier
  46. #endif // ZT_PACKET_MULTIPLEXER_HPP