join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
DhcpTest Class Reference

Class used to test the DHCP API. More...

Inheritance diagram for DhcpTest:
Collaboration diagram for DhcpTest:

Public Member Functions

void SetUp () override
 set up the test fixture, the server answers every client message.
 
void TearDown () override
 tear down the test fixture.
 

Static Public Member Functions

static void SetUpTestCase ()
 set up test case.
 
static void TearDownTestCase ()
 tear down test case.
 

Protected Types

enum  Behaviour {
  Normal , Refuse , Silent , WrongType ,
  NoType
}
 how the server answers. More...
 

Protected Member Functions

void onDiscover (const DhcpPacket &request)
 answer a discover with an offer.
 
void onRequest (const DhcpPacket &request)
 answer a request with an acknowledgement, or refuse it.
 
void onRelease (const DhcpPacket &request)
 note that a release was received.
 
void onDecline (const DhcpPacket &request)
 note that a decline was received.
 
void onInform (const DhcpPacket &request)
 answer an inform with the parameters, without a lease.
 
void received (uint8_t type)
 record the type of the last message the server received.
 
bool awaits (uint8_t type, std::chrono::milliseconds timeout=std::chrono::seconds(2))
 wait for the server to receive a message of the given type.
 

Static Protected Member Functions

static DhcpOption settings ()
 get the options the server advertises.
 
static void checkSettings (const DhcpPacket &packet)
 check that a message carries the settings the server advertises.
 
static DhcpPacket requestOf (uint8_t type)
 build a message the way a client sends one.
 
static std::string frameOf (const DhcpPacket &packet)
 frame a message the way the wire carries it.
 
static void inject (const std::string &wire)
 put raw bytes on the wire, bypassing the library.
 

Protected Attributes

Behaviour _behaviour = Normal
 how the server answers.
 
uint16_t _secs = 0
 elapsed time the last discover reported.
 
uint8_t _last = 0
 type of the last message received.
 
Condition _cond
 last message notification.
 
Mutex _mutex
 last message protection mutex.
 
Dhcp::Server _dhcp {_device}
 server under test, declared last so that it stops before the state its listener uses.
 

Static Protected Attributes

static const std::string _device = "dhcp0"
 interface both peers are bound to.
 
static const std::string _bare = "dhcp1"
 interface that owns no address.
 
static const std::string _mac = "4e:ed:ed:ee:59:db"
 hardware address of that interface.
 
static const std::string _server = "192.168.24.100"
 address of the server.
 
static const std::string _lease = "192.168.24.110"
 address the server hands out.
 

Detailed Description

Class used to test the DHCP API.

Member Enumeration Documentation

◆ Behaviour

enum DhcpTest::Behaviour
protected

how the server answers.

Enumerator
Normal 

answer the way a server should.

Refuse 

refuse every request.

Silent 

refuse every request without giving a reason.

WrongType 

answer a discover with a type the client does not expect.

NoType 

answer a discover without a message type at all.

Member Function Documentation

◆ awaits()

bool DhcpTest::awaits ( uint8_t type,
std::chrono::milliseconds timeout = std::chrono::seconds (2) )
inlineprotected

wait for the server to receive a message of the given type.

Parameters
typemessage type.
timeoutwait timeout.
Returns
true if it was received, false if it timed out.

◆ checkSettings()

static void DhcpTest::checkSettings ( const DhcpPacket & packet)
inlinestaticprotected

check that a message carries the settings the server advertises.

Parameters
packetmessage to check.

◆ frameOf()

static std::string DhcpTest::frameOf ( const DhcpPacket & packet)
inlinestaticprotected

frame a message the way the wire carries it.

Parameters
packetmessage to frame.
Returns
the frame.

◆ inject()

static void DhcpTest::inject ( const std::string & wire)
inlinestaticprotected

put raw bytes on the wire, bypassing the library.

Parameters
wirebytes to write.

◆ onDecline()

void DhcpTest::onDecline ( const DhcpPacket & request)
inlineprotected

note that a decline was received.

Parameters
requestmessage received.

◆ onDiscover()

void DhcpTest::onDiscover ( const DhcpPacket & request)
inlineprotected

answer a discover with an offer.

Parameters
requestmessage received.

◆ onInform()

void DhcpTest::onInform ( const DhcpPacket & request)
inlineprotected

answer an inform with the parameters, without a lease.

Parameters
requestmessage received.

◆ onRelease()

void DhcpTest::onRelease ( const DhcpPacket & request)
inlineprotected

note that a release was received.

Parameters
requestmessage received.

◆ onRequest()

void DhcpTest::onRequest ( const DhcpPacket & request)
inlineprotected

answer a request with an acknowledgement, or refuse it.

Parameters
requestmessage received.

◆ received()

void DhcpTest::received ( uint8_t type)
inlineprotected

record the type of the last message the server received.

Parameters
typemessage type.

◆ requestOf()

static DhcpPacket DhcpTest::requestOf ( uint8_t type)
inlinestaticprotected

build a message the way a client sends one.

Parameters
typemessage type.
Returns
the message.

◆ settings()

static DhcpOption DhcpTest::settings ( )
inlinestaticprotected

get the options the server advertises.

Returns
the options.

◆ SetUp()

void DhcpTest::SetUp ( )
inlineoverride

set up the test fixture, the server answers every client message.

◆ SetUpTestCase()

static void DhcpTest::SetUpTestCase ( )
inlinestatic

set up test case.

◆ TearDown()

void DhcpTest::TearDown ( )
inlineoverride

tear down the test fixture.

◆ TearDownTestCase()

static void DhcpTest::TearDownTestCase ( )
inlinestatic

tear down test case.

Member Data Documentation

◆ _bare

const std::string DhcpTest::_bare = "dhcp1"
staticprotected

interface that owns no address.

◆ _behaviour

Behaviour DhcpTest::_behaviour = Normal
protected

how the server answers.

◆ _cond

Condition DhcpTest::_cond
protected

last message notification.

◆ _device

const std::string DhcpTest::_device = "dhcp0"
staticprotected

interface both peers are bound to.

◆ _dhcp

Dhcp::Server DhcpTest::_dhcp {_device}
protected

server under test, declared last so that it stops before the state its listener uses.

◆ _last

uint8_t DhcpTest::_last = 0
protected

type of the last message received.

◆ _lease

const std::string DhcpTest::_lease = "192.168.24.110"
staticprotected

address the server hands out.

◆ _mac

const std::string DhcpTest::_mac = "4e:ed:ed:ee:59:db"
staticprotected

hardware address of that interface.

◆ _mutex

Mutex DhcpTest::_mutex
protected

last message protection mutex.

◆ _secs

uint16_t DhcpTest::_secs = 0
protected

elapsed time the last discover reported.

◆ _server

const std::string DhcpTest::_server = "192.168.24.100"
staticprotected

address of the server.


The documentation for this class was generated from the following file: