mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 20:43:44 +02:00
Prep for real tests like alltoall.
This commit is contained in:
parent
a75a7547b4
commit
8672ca9cf8
4 changed files with 40 additions and 14 deletions
|
@ -42,8 +42,6 @@
|
||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
static Mutex printLock;
|
|
||||||
|
|
||||||
TestEthernetTap::TestEthernetTap(
|
TestEthernetTap::TestEthernetTap(
|
||||||
TestEthernetTapFactory *parent,
|
TestEthernetTapFactory *parent,
|
||||||
const MAC &mac,
|
const MAC &mac,
|
||||||
|
@ -55,6 +53,7 @@ TestEthernetTap::TestEthernetTap(
|
||||||
void (*handler)(void *,const MAC &,const MAC &,unsigned int,const Buffer<4096> &),
|
void (*handler)(void *,const MAC &,const MAC &,unsigned int,const Buffer<4096> &),
|
||||||
void *arg) :
|
void *arg) :
|
||||||
EthernetTap("TestEthernetTap",mac,mtu,metric),
|
EthernetTap("TestEthernetTap",mac,mtu,metric),
|
||||||
|
_nwid(nwid),
|
||||||
_parent(parent),
|
_parent(parent),
|
||||||
_handler(handler),
|
_handler(handler),
|
||||||
_arg(arg),
|
_arg(arg),
|
||||||
|
@ -114,9 +113,8 @@ std::set<InetAddress> TestEthernetTap::ips() const
|
||||||
|
|
||||||
void TestEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
|
void TestEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
|
||||||
{
|
{
|
||||||
Mutex::Lock _l(printLock);
|
Mutex::Lock _l(_gq_m);
|
||||||
fprintf(stdout,"[%s] %s << %s %.4x %s"ZT_EOL_S,_dev.c_str(),to.toString().c_str(),from.toString().c_str(),etherType,std::string((const char *)data,len).c_str());
|
_gq.push_back(TestFrame(from,to,data,etherType,len));
|
||||||
fflush(stdout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string TestEthernetTap::deviceName() const
|
std::string TestEthernetTap::deviceName() const
|
||||||
|
@ -144,12 +142,6 @@ bool TestEthernetTap::injectPacketFromHost(const MAC &from,const MAC &to,unsigne
|
||||||
}
|
}
|
||||||
_pq_c.signal();
|
_pq_c.signal();
|
||||||
|
|
||||||
{
|
|
||||||
Mutex::Lock _l(printLock);
|
|
||||||
fprintf(stdout,"[%s] %s >> %s %.4x %s"ZT_EOL_S,_dev.c_str(),from.toString().c_str(),to.toString().c_str(),etherType,std::string((const char *)data,len).c_str());
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ class TestEthernetTap : public EthernetTap
|
||||||
{
|
{
|
||||||
friend class SharedPtr<TestEthernetTap>;
|
friend class SharedPtr<TestEthernetTap>;
|
||||||
|
|
||||||
private:
|
public:
|
||||||
struct TestFrame
|
struct TestFrame
|
||||||
{
|
{
|
||||||
TestFrame() : from(),to(),etherType(0),len(0) {}
|
TestFrame() : from(),to(),etherType(0),len(0) {}
|
||||||
|
@ -79,7 +79,6 @@ private:
|
||||||
char data[4096];
|
char data[4096];
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
|
||||||
TestEthernetTap(
|
TestEthernetTap(
|
||||||
TestEthernetTapFactory *parent,
|
TestEthernetTapFactory *parent,
|
||||||
const MAC &mac,
|
const MAC &mac,
|
||||||
|
@ -104,10 +103,22 @@ public:
|
||||||
virtual bool updateMulticastGroups(std::set<MulticastGroup> &groups);
|
virtual bool updateMulticastGroups(std::set<MulticastGroup> &groups);
|
||||||
virtual bool injectPacketFromHost(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len);
|
virtual bool injectPacketFromHost(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len);
|
||||||
|
|
||||||
|
inline uint64_t nwid() const { return _nwid; }
|
||||||
|
|
||||||
|
// Get things that have been put() and empty queue
|
||||||
|
inline void get(std::vector<TestFrame> &v,bool clearQueue = true)
|
||||||
|
{
|
||||||
|
Mutex::Lock _l(_gq_m);
|
||||||
|
v = _gq;
|
||||||
|
if (clearQueue)
|
||||||
|
_gq.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void threadMain()
|
void threadMain()
|
||||||
throw();
|
throw();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
uint64_t _nwid;
|
||||||
TestEthernetTapFactory *_parent;
|
TestEthernetTapFactory *_parent;
|
||||||
|
|
||||||
void (*_handler)(void *,const MAC &,const MAC &,unsigned int,const Buffer<4096> &);
|
void (*_handler)(void *,const MAC &,const MAC &,unsigned int,const Buffer<4096> &);
|
||||||
|
@ -120,6 +131,9 @@ private:
|
||||||
Mutex _pq_m;
|
Mutex _pq_m;
|
||||||
Condition _pq_c;
|
Condition _pq_c;
|
||||||
|
|
||||||
|
std::vector< TestFrame > _gq;
|
||||||
|
Mutex _gq_m;
|
||||||
|
|
||||||
AtomicCounter __refCount;
|
AtomicCounter __refCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,10 @@ EthernetTap *TestEthernetTapFactory::open(
|
||||||
Mutex::Lock _l(_tapsByMac_m);
|
Mutex::Lock _l(_tapsByMac_m);
|
||||||
_tapsByMac[mac] = tap;
|
_tapsByMac[mac] = tap;
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
Mutex::Lock _l(_tapsByNwid_m);
|
||||||
|
_tapsByNwid[nwid] = tap;
|
||||||
|
}
|
||||||
return tap.ptr();
|
return tap.ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,6 +77,10 @@ void TestEthernetTapFactory::close(EthernetTap *tap,bool destroyPersistentDevice
|
||||||
Mutex::Lock _l(_tapsByMac_m);
|
Mutex::Lock _l(_tapsByMac_m);
|
||||||
_tapsByMac.erase(tapp->mac());
|
_tapsByMac.erase(tapp->mac());
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
Mutex::Lock _l(_tapsByNwid_m);
|
||||||
|
_tapsByNwid.erase(tapp->nwid());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ZeroTier
|
} // namespace ZeroTier
|
||||||
|
|
|
@ -68,13 +68,25 @@ public:
|
||||||
return t->second;
|
return t->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline SharedPtr<TestEthernetTap> getByNwid(uint64_t nwid) const
|
||||||
|
{
|
||||||
|
Mutex::Lock _l(_tapsByNwid_m);
|
||||||
|
std::map< uint64_t,SharedPtr<TestEthernetTap> >::const_iterator t(_tapsByNwid.find(nwid));
|
||||||
|
if (t == _tapsByNwid.end())
|
||||||
|
return SharedPtr<TestEthernetTap>();
|
||||||
|
return t->second;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::set< SharedPtr<TestEthernetTap> > _taps;
|
std::set< SharedPtr<TestEthernetTap> > _taps;
|
||||||
Mutex _taps_m;
|
Mutex _taps_m;
|
||||||
|
|
||||||
std::map<MAC,SharedPtr<TestEthernetTap> > _tapsByMac;
|
std::map< MAC,SharedPtr<TestEthernetTap> > _tapsByMac;
|
||||||
Mutex _tapsByMac_m;
|
Mutex _tapsByMac_m;
|
||||||
|
|
||||||
|
std::map< uint64_t,SharedPtr<TestEthernetTap> > _tapsByNwid;
|
||||||
|
Mutex _tapsByNwid_m;
|
||||||
|
|
||||||
CMWC4096 _prng;
|
CMWC4096 _prng;
|
||||||
Mutex _prng_m;
|
Mutex _prng_m;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue