Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openstack/03b-IPv6/icmpv6rp: some cleanups #524

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions openstack/02a-MAClow/IEEE802154.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "idmanager.h"
#include "openserial.h"
#include "topology.h"
#include "icmpv6rpl.h"
#include "IEEE802154_security.h"

//=========================== define ==========================================
Expand Down
1 change: 1 addition & 0 deletions openstack/02a-MAClow/IEEE802154E.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "debugpins.h"
#include "sixtop.h"
#include "adaptive_sync.h"
#include "icmpv6rpl.h"
#include "sctimer.h"
#include "openrandom.h"
#include "msf.h"
Expand Down
58 changes: 14 additions & 44 deletions openstack/02b-MAChigh/neighbors.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,26 @@ dagrank_t neighbors_getNeighborRank(uint8_t index) {
return neighbors_vars.neighbors[index].DAGrank;
}

int8_t neighbors_getRssi(uint8_t index) {
int8_t neighbors_getRssi(uint8_t index)
{
return neighbors_vars.neighbors[index].rssi;
}

uint8_t neighbors_getNumTx(uint8_t index) {
uint8_t neighbors_getNumTx(uint8_t index)
{
return neighbors_vars.neighbors[index].numTx;
}

uint8_t neighbors_getNumTxACK(uint8_t index)
{
return neighbors_vars.neighbors[index].numTxACK;
}

uint8_t neighbors_getNumRx(uint8_t index)
{
return neighbors_vars.neighbors[index].numRx;
}

/**
\brief Find neighbor to which to send KA.

Expand Down Expand Up @@ -556,48 +568,6 @@ void neighbors_setPreferredParent(uint8_t index, bool isPreferred) {
neighbors_vars.neighbors[index].parentPreference = isPreferred;
}

//===== managing routing info

/**
\brief return the link cost to a neighbor, expressed as a rank increase from this neighbor to this node

This really belongs to icmpv6rpl but it would require a much more complex interface to the neighbor table
*/

uint16_t neighbors_getLinkMetric(uint8_t index) {
uint16_t rankIncrease;
uint32_t rankIncreaseIntermediary; // stores intermediary results of rankIncrease calculation

// we assume that this neighbor has already been checked for being in use
// calculate link cost to this neighbor
if (neighbors_vars.neighbors[index].numTxACK == 0) {
if (neighbors_vars.neighbors[index].numTx > DEFAULTLINKCOST) {
if (neighbors_vars.neighbors[index].numTx < MINIMAL_NUM_TX) {
rankIncrease = (3 * neighbors_vars.neighbors[index].numTx - 2) * MINHOPRANKINCREASE;
} else {
rankIncrease = 65535;
}
} else {
rankIncrease = (3 * DEFAULTLINKCOST - 2) * MINHOPRANKINCREASE;
}
} else {
//6TiSCH minimal draft using OF0 for rank computation: ((3*numTx/numTxAck)-2)*minHopRankIncrease
// numTx is on 8 bits, so scaling up 10 bits won't lead to saturation
// but this <<10 followed by >>10 does not provide any benefit either. Result is the same.
rankIncreaseIntermediary = (((uint32_t) neighbors_vars.neighbors[index].numTx) << 10);
rankIncreaseIntermediary = (3 * rankIncreaseIntermediary * MINHOPRANKINCREASE) /
((uint32_t) neighbors_vars.neighbors[index].numTxACK);
rankIncreaseIntermediary = rankIncreaseIntermediary - ((uint32_t)(2 * MINHOPRANKINCREASE) << 10);
// this could still overflow for numTx large and numTxAck small, Casting to 16 bits will yiel the least significant bits
if (rankIncreaseIntermediary >= (65536 << 10)) {
rankIncrease = 65535;
} else {
rankIncrease = (uint16_t)(rankIncreaseIntermediary >> 10);
}
}
return rankIncrease;
}

//===== maintenance

void neighbors_removeOld(void) {
Expand Down
13 changes: 6 additions & 7 deletions openstack/02b-MAChigh/neighbors.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
#endif
#define MINIMAL_NUM_TX 16

#define MAXDAGRANK 0xffff
#define DEFAULTDAGRANK MAXDAGRANK
#define MINHOPRANKINCREASE 256 // default value in RPL and Minimal 6TiSCH draft
#define DAGMAXRANKINCREASE 768 // per RFC6550 https://tools.ietf.org/html/rfc6550#section-8.2.2.4 point 3

#define DEFAULTJOINPRIORITY 0xff

//=========================== typedef =========================================
Expand Down Expand Up @@ -66,12 +61,16 @@ typedef struct {
void neighbors_init(void);

// getters
uint8_t neighbors_getNumTxACK(uint8_t index);

uint8_t neighbors_getNumTx(uint8_t index);

uint8_t neighbors_getNumRx(uint8_t index);

dagrank_t neighbors_getNeighborRank(uint8_t index);

uint8_t neighbors_getNumNeighbors(void);

uint16_t neighbors_getLinkMetric(uint8_t index);

open_addr_t* neighbors_getKANeighbor(uint16_t kaPeriod);

open_addr_t* neighbors_getJoinProxy(void);
Expand Down
19 changes: 1 addition & 18 deletions openstack/02b-MAChigh/sixtop.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,23 +531,6 @@ void task_sixtopNotifReceive(void) {
debugPrint_* functions are used by the openserial module to continuously print
status information about several modules in the OpenWSN stack.

\returns TRUE if this function printed something, FALSE otherwise.
*/
bool debugPrint_myDAGrank(void) {
uint16_t output;

output = 0;
output = icmpv6rpl_getMyDAGrank();
openserial_printStatus(STATUS_DAGRANK, (uint8_t * ) & output, sizeof(uint16_t));
return TRUE;
}

/**
\brief Trigger this module to print status information, over serial.

debugPrint_* functions are used by the openserial module to continuously print
status information about several modules in the OpenWSN stack.

\returns TRUE if this function printed something, FALSE otherwise.
*/
bool debugPrint_kaPeriod(void) {
Expand Down Expand Up @@ -706,7 +689,7 @@ port_INLINE void sixtop_sendEB(void) {
(ieee154e_isSynch() == FALSE) ||
(IEEE802154_security_isConfigured() == FALSE) ||
(icmpv6rpl_getMyDAGrank() == DEFAULTDAGRANK) ||
icmpv6rpl_daoSent() == FALSE) {
(icmpv6rpl_isReachable() == FALSE)) {
// I'm not sync'ed, or did not join, or did not acquire a DAGrank or did not send out a DAO
// before starting to advertize the network, we need to make sure that we are reachable downwards,
// thus, the condition if DAO was sent
Expand Down
2 changes: 0 additions & 2 deletions openstack/02b-MAChigh/sixtop.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ void task_sixtopNotifSendDone(void);
void task_sixtopNotifReceive(void);

// debugging
bool debugPrint_myDAGrank(void);

bool debugPrint_kaPeriod(void);

/**
Expand Down
78 changes: 72 additions & 6 deletions openstack/03b-IPv6/icmpv6rpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ void icmpv6rpl_timer_DAO_task(void);

void sendDAO(void);

// Algorithm related
uint16_t icmpv6rpl_getLinkMetric(uint8_t index);

//=========================== public ==========================================

/**
Expand All @@ -57,7 +60,7 @@ void icmpv6rpl_init(void) {

//=== routing
icmpv6rpl_vars.haveParent = FALSE;
icmpv6rpl_vars.daoSent = FALSE;
icmpv6rpl_vars.isReachable = FALSE;

if (idmanager_getIsDAGroot() == TRUE) {
icmpv6rpl_vars.myDAGrank = MINHOPRANKINCREASE;
Expand Down Expand Up @@ -389,7 +392,7 @@ void icmpv6rpl_updateMyDAGrankAndParentSelection(void) {
// I havn't enough transmission to my parent, don't update.
return;
}
rankIncrease = neighbors_getLinkMetric(icmpv6rpl_vars.ParentIndex);
rankIncrease = icmpv6rpl_getLinkMetric(icmpv6rpl_vars.ParentIndex);
neighborRank = neighbors_getNeighborRank(icmpv6rpl_vars.ParentIndex);
tentativeDAGrank = (uint32_t) neighborRank + rankIncrease;
if (tentativeDAGrank > 65535) {
Expand All @@ -413,7 +416,7 @@ void icmpv6rpl_updateMyDAGrankAndParentSelection(void) {
continue;
}
// get link cost to this neighbor
rankIncrease = neighbors_getLinkMetric(i);
rankIncrease = icmpv6rpl_getLinkMetric(i);
// get this neighbor's advertized rank
neighborRank = neighbors_getNeighborRank(i);
// if this neighbor has unknown/infinite rank, pass on it
Expand Down Expand Up @@ -1033,15 +1036,78 @@ void sendDAO(void) {
//===== send
if (icmpv6_send(msg) == E_SUCCESS) {
icmpv6rpl_vars.busySendingDAO = TRUE;
icmpv6rpl_vars.daoSent = TRUE;
icmpv6rpl_vars.isReachable = TRUE;
} else {
openqueue_freePacketBuffer(msg);
}
}

bool icmpv6rpl_daoSent(void) {
bool icmpv6rpl_isReachable(void)
{
if (idmanager_getIsDAGroot() == TRUE) {
return TRUE;
}
return icmpv6rpl_vars.daoSent;
return icmpv6rpl_vars.isReachable;
}

//===== managing routing info

/**
\brief return the link cost to a neighbor, expressed as a rank increase from this neighbor to this node

This really belongs to icmpv6rpl but it would require a much more complex interface to the neighbor table
*/

uint16_t icmpv6rpl_getLinkMetric(uint8_t index) {
uint16_t rankIncrease;
uint32_t rankIncreaseIntermediary; // stores intermediary results of rankIncrease calculation

// we assume that this neighbor has already been checked for being in use
// calculate link cost to this neighbor
if (neighbors_getNumTxACK(index) == 0) {
if (neighbors_getNumTx(index) > DEFAULTLINKCOST) {
if (neighbors_getNumTx(index) < MINIMAL_NUM_TX) {
rankIncrease = (3 * neighbors_getNumTx(index) - 2) * MINHOPRANKINCREASE;
} else {
rankIncrease = 65535;
}
} else {
rankIncrease = (3 * DEFAULTLINKCOST - 2) * MINHOPRANKINCREASE;
}
} else {
//6TiSCH minimal draft using OF0 for rank computation: ((3*numTx/numTxAck)-2)*minHopRankIncrease
// numTx is on 8 bits, so scaling up 10 bits won't lead to saturation
// but this <<10 followed by >>10 does not provide any benefit either. Result is the same.
rankIncreaseIntermediary = (((uint32_t) neighbors_getNumTx(index)) << 10);
rankIncreaseIntermediary = (3 * rankIncreaseIntermediary * MINHOPRANKINCREASE) /
((uint32_t) neighbors_getNumTxACK(index));
rankIncreaseIntermediary = rankIncreaseIntermediary - ((uint32_t)(2 * MINHOPRANKINCREASE) << 10);
// this could still overflow for numTx large and numTxAck small, Casting to 16 bits will yiel the least significant bits
if (rankIncreaseIntermediary >= (65536 << 10)) {
rankIncrease = 65535;
} else {
rankIncrease = (uint16_t)(rankIncreaseIntermediary >> 10);
}
}
return rankIncrease;
}

//======= debugging

/**
\brief Trigger this module to print status information, over serial.

debugPrint_* functions are used by the openserial module to continuously print
status information about several modules in the OpenWSN stack.

\returns TRUE if this function printed something, FALSE otherwise.
*/
bool debugPrint_myDAGrank(void) {
uint16_t output;

output = 0;
output = icmpv6rpl_getMyDAGrank();
openserial_printStatus(STATUS_DAGRANK, (uint8_t * ) & output, sizeof(uint16_t));
return TRUE;
}

11 changes: 9 additions & 2 deletions openstack/03b-IPv6/icmpv6rpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ enum {
OPTION_TRANSIT_INFORMATION_TYPE = 0x06,
};

#define MAXDAGRANK 0xffff
#define DEFAULTDAGRANK MAXDAGRANK
#define MINHOPRANKINCREASE 256 // default value in RPL and Minimal 6TiSCH draft
#define DAGMAXRANKINCREASE 768 // per RFC6550 https://tools.ietf.org/html/rfc6550#section-8.2.2.4 point 3

//=========================== static ==========================================

/**
Expand Down Expand Up @@ -198,12 +203,12 @@ typedef struct {
dagrank_t lowestRankInHistory; ///< lowest Rank that the node has advertised
uint16_t rankIncrease; ///< the cost of the link to the parent, in units of rank
bool haveParent; ///< this router has a route to DAG root
bool isReachable; ///< this router is reachable
uint8_t ParentIndex; ///< index of Parent in neighbor table (iff haveParent==TRUE)
// actually only here for debug
icmpv6rpl_dio_ht *incomingDio; ///< keep it global to be able to debug correctly.
icmpv6rpl_pio_t *incomingPio; ///< pio structure incoming
icmpv6rpl_config_ht *incomingConf; ///< configuration incoming
bool daoSent;
} icmpv6rpl_vars_t;


Expand Down Expand Up @@ -238,8 +243,10 @@ void icmpv6rpl_updateMyDAGrankAndParentSelection(void);

void icmpv6rpl_indicateRxDIO(OpenQueueEntry_t *msg);

bool icmpv6rpl_daoSent(void);
void icmpv6rpl_setReachable(bool reachable);

// debugging
bool debugPrint_myDAGrank(void);

/**
\}
Expand Down
1 change: 1 addition & 0 deletions openstack/cross-layers/idmanager.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "neighbors.h"
#include "schedule.h"
#include "IEEE802154_security.h"
#include "icmpv6rpl.h"

//=========================== variables =======================================

Expand Down
4 changes: 0 additions & 4 deletions projects/common/03oos_macpong/03oos_macpong.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,6 @@ dagrank_t icmpv6rpl_getMyDAGrank(void) {
return 0;
}

bool icmpv6rpl_daoSent(void) {
return TRUE;
}

void icmpv6rpl_setMyDAGrank(dagrank_t rank) { return; }

void icmpv6rpl_updateMyDAGrankAndParentSelection(void) { return; }
Expand Down
2 changes: 1 addition & 1 deletion projects/python/SConscript.env
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,6 @@ functionsToChange = [
'neighbors_init',
'neighbors_getNeighborRank',
'neighbors_getNumNeighbors',
'neighbors_getLinkMetric',
'neighbors_getKANeighbor',
'neighbors_getJoinProxy',
'neighbors_getSequenceNumber',
Expand Down Expand Up @@ -731,6 +730,7 @@ functionsToChange = [
'icmpv6rpl_getRPLDODAGid',
'icmpv6rpl_sendDone',
'icmpv6rpl_receive',
'icmpv6rpl_getLinkMetric',
'icmpv6rpl_getPreferredParentIndex',
'icmpv6rpl_getPreferredParentEui64',
'icmpv6rpl_isPreferredParent',
Expand Down