mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
ba3088c4bd
into separate patch files
431 lines
14 KiB
Diff
431 lines
14 KiB
Diff
*** stock_iot-lab_M3/openwsn/02b-MAChigh/neighbors.c Thu Apr 24 11:01:36 2014
|
|
--- riot-openwsn-wip/openwsn/02b-MAChigh/neighbors.c Thu Apr 24 16:55:54 2014
|
|
***************
|
|
*** 8,20 ****
|
|
|
|
//=========================== variables =======================================
|
|
|
|
- typedef struct {
|
|
- neighborRow_t neighbors[MAXNUMNEIGHBORS];
|
|
- dagrank_t myDAGrank;
|
|
- uint8_t debugRow;
|
|
- icmpv6rpl_dio_ht* dio; //keep it global to be able to debug correctly.
|
|
- } neighbors_vars_t;
|
|
-
|
|
neighbors_vars_t neighbors_vars;
|
|
|
|
//=========================== prototypes ======================================
|
|
--- 8,13 ----
|
|
***************
|
|
*** 22,28 ****
|
|
void registerNewNeighbor(
|
|
open_addr_t* neighborID,
|
|
int8_t rssi,
|
|
! asn_t* asnTimestamp
|
|
);
|
|
bool isNeighbor(open_addr_t* neighbor);
|
|
void removeNeighbor(uint8_t neighborIndex);
|
|
--- 15,23 ----
|
|
void registerNewNeighbor(
|
|
open_addr_t* neighborID,
|
|
int8_t rssi,
|
|
! asn_t* asnTimestamp,
|
|
! bool joinPrioPresent,
|
|
! uint8_t joinPrio
|
|
);
|
|
bool isNeighbor(open_addr_t* neighbor);
|
|
void removeNeighbor(uint8_t neighborIndex);
|
|
***************
|
|
*** 36,42 ****
|
|
/**
|
|
\brief Initializes this module.
|
|
*/
|
|
! void neighbors_init() {
|
|
|
|
// clear module variables
|
|
memset(&neighbors_vars,0,sizeof(neighbors_vars_t));
|
|
--- 31,37 ----
|
|
/**
|
|
\brief Initializes this module.
|
|
*/
|
|
! void neighbors_init(void) {
|
|
|
|
// clear module variables
|
|
memset(&neighbors_vars,0,sizeof(neighbors_vars_t));
|
|
***************
|
|
*** 56,62 ****
|
|
|
|
\returns This mote's current DAG rank.
|
|
*/
|
|
! dagrank_t neighbors_getMyDAGrank() {
|
|
return neighbors_vars.myDAGrank;
|
|
}
|
|
|
|
--- 51,57 ----
|
|
|
|
\returns This mote's current DAG rank.
|
|
*/
|
|
! dagrank_t neighbors_getMyDAGrank(void) {
|
|
return neighbors_vars.myDAGrank;
|
|
}
|
|
|
|
***************
|
|
*** 65,71 ****
|
|
|
|
\returns The number of neighbors this mote's currently knows of.
|
|
*/
|
|
! uint8_t neighbors_getNumNeighbors() {
|
|
uint8_t i;
|
|
uint8_t returnVal;
|
|
|
|
--- 60,66 ----
|
|
|
|
\returns The number of neighbors this mote's currently knows of.
|
|
*/
|
|
! uint8_t neighbors_getNumNeighbors(void) {
|
|
uint8_t i;
|
|
uint8_t returnVal;
|
|
|
|
***************
|
|
*** 81,87 ****
|
|
/**
|
|
\brief Retrieve my preferred parent's EUI64 address.
|
|
|
|
! \param [out] addressToWrite Where to write the preferred parent's address to.
|
|
*/
|
|
bool neighbors_getPreferredParentEui64(open_addr_t* addressToWrite) {
|
|
uint8_t i;
|
|
--- 76,82 ----
|
|
/**
|
|
\brief Retrieve my preferred parent's EUI64 address.
|
|
|
|
! \param[out] addressToWrite Where to write the preferred parent's address to.
|
|
*/
|
|
bool neighbors_getPreferredParentEui64(open_addr_t* addressToWrite) {
|
|
uint8_t i;
|
|
***************
|
|
*** 140,146 ****
|
|
|
|
\returns A pointer to the neighbor's address, or NULL if no KA is needed.
|
|
*/
|
|
! open_addr_t* neighbors_getKANeighbor() {
|
|
uint8_t i;
|
|
uint16_t timeSinceHeard;
|
|
open_addr_t* addrPreferred;
|
|
--- 135,141 ----
|
|
|
|
\returns A pointer to the neighbor's address, or NULL if no KA is needed.
|
|
*/
|
|
! open_addr_t* neighbors_getKANeighbor(void) {
|
|
uint8_t i;
|
|
uint16_t timeSinceHeard;
|
|
open_addr_t* addrPreferred;
|
|
***************
|
|
*** 185,191 ****
|
|
/**
|
|
\brief Indicate whether some neighbor is a stable neighbor
|
|
|
|
! \param address [in] The address of the neighbor, a full 128-bit IPv6 addres.
|
|
|
|
\returns TRUE if that neighbor is stable, FALSE otherwise.
|
|
*/
|
|
--- 180,186 ----
|
|
/**
|
|
\brief Indicate whether some neighbor is a stable neighbor
|
|
|
|
! \param[in] address The address of the neighbor, a full 128-bit IPv6 addres.
|
|
|
|
\returns TRUE if that neighbor is stable, FALSE otherwise.
|
|
*/
|
|
***************
|
|
*** 224,230 ****
|
|
/**
|
|
\brief Indicate whether some neighbor is a preferred neighbor.
|
|
|
|
! \param address [in] The EUI64 address of the neighbor.
|
|
|
|
\returns TRUE if that neighbor is preferred, FALSE otherwise.
|
|
*/
|
|
--- 219,225 ----
|
|
/**
|
|
\brief Indicate whether some neighbor is a preferred neighbor.
|
|
|
|
! \param[in] address The EUI64 address of the neighbor.
|
|
|
|
\returns TRUE if that neighbor is preferred, FALSE otherwise.
|
|
*/
|
|
***************
|
|
*** 253,259 ****
|
|
/**
|
|
\brief Indicate whether some neighbor has a lower DAG rank that me.
|
|
|
|
! \param index [in] The index of that neighbor in the neighbor table.
|
|
|
|
\returns TRUE if that neighbor has a lower DAG rank than me, FALSE otherwise.
|
|
*/
|
|
--- 248,254 ----
|
|
/**
|
|
\brief Indicate whether some neighbor has a lower DAG rank that me.
|
|
|
|
! \param[in] index The index of that neighbor in the neighbor table.
|
|
|
|
\returns TRUE if that neighbor has a lower DAG rank than me, FALSE otherwise.
|
|
*/
|
|
***************
|
|
*** 274,280 ****
|
|
/**
|
|
\brief Indicate whether some neighbor has a lower DAG rank that me.
|
|
|
|
! \param index [in] The index of that neighbor in the neighbor table.
|
|
|
|
\returns TRUE if that neighbor has a lower DAG rank than me, FALSE otherwise.
|
|
*/
|
|
--- 269,275 ----
|
|
/**
|
|
\brief Indicate whether some neighbor has a lower DAG rank that me.
|
|
|
|
! \param[in] index The index of that neighbor in the neighbor table.
|
|
|
|
\returns TRUE if that neighbor has a lower DAG rank than me, FALSE otherwise.
|
|
*/
|
|
***************
|
|
*** 306,319 ****
|
|
- stableNeighbor
|
|
- switchStabilityCounter
|
|
|
|
! \param l2_src [in] MAC source address of the packet, i.e. the neighbor who sent
|
|
! the packet just received.
|
|
! \param rssi [in] RSSI with which this packet was received.
|
|
! \param asnTs [in] ASN at which this packet was received.
|
|
*/
|
|
void neighbors_indicateRx(open_addr_t* l2_src,
|
|
int8_t rssi,
|
|
! asn_t* asnTs) {
|
|
uint8_t i;
|
|
bool newNeighbor;
|
|
|
|
--- 301,316 ----
|
|
- stableNeighbor
|
|
- switchStabilityCounter
|
|
|
|
! \param[in] l2_src MAC source address of the packet, i.e. the neighbor who sent
|
|
! the packet just received.
|
|
! \param[in] rssi RSSI with which this packet was received.
|
|
! \param[in] asnTs ASN at which this packet was received.
|
|
*/
|
|
void neighbors_indicateRx(open_addr_t* l2_src,
|
|
int8_t rssi,
|
|
! asn_t* asnTs,
|
|
! bool joinPrioPresent,
|
|
! uint8_t joinPrio) {
|
|
uint8_t i;
|
|
bool newNeighbor;
|
|
|
|
***************
|
|
*** 329,334 ****
|
|
--- 326,335 ----
|
|
neighbors_vars.neighbors[i].numRx++;
|
|
neighbors_vars.neighbors[i].rssi=rssi;
|
|
memcpy(&neighbors_vars.neighbors[i].asn,asnTs,sizeof(asn_t));
|
|
+ //update jp
|
|
+ if (joinPrioPresent==TRUE){
|
|
+ neighbors_vars.neighbors[i].joinPrio=joinPrio;
|
|
+ }
|
|
|
|
// update stableNeighbor, switchStabilityCounter
|
|
if (neighbors_vars.neighbors[i].stableNeighbor==FALSE) {
|
|
***************
|
|
*** 360,366 ****
|
|
|
|
// register new neighbor
|
|
if (newNeighbor==TRUE) {
|
|
! registerNewNeighbor(l2_src, rssi, asnTs);
|
|
}
|
|
}
|
|
|
|
--- 361,367 ----
|
|
|
|
// register new neighbor
|
|
if (newNeighbor==TRUE) {
|
|
! registerNewNeighbor(l2_src, rssi, asnTs, joinPrioPresent,joinPrio);
|
|
}
|
|
}
|
|
|
|
***************
|
|
*** 375,386 ****
|
|
- numTxACK
|
|
- asn
|
|
|
|
! \param l2_dest [in] MAC destination address of the packet, i.e. the neighbor
|
|
! who I just sent the packet to.
|
|
! \param numTxAttempts [in] Number of transmission attempts to this neighbor.
|
|
! \param was_finally_acked [in] TRUE iff the packet was ACK'ed by the neighbor
|
|
! on final transmission attempt.
|
|
! \param asnTs [in] ASN of the last transmission attempt.
|
|
*/
|
|
void neighbors_indicateTx(open_addr_t* l2_dest,
|
|
uint8_t numTxAttempts,
|
|
--- 376,387 ----
|
|
- numTxACK
|
|
- asn
|
|
|
|
! \param[in] l2_dest MAC destination address of the packet, i.e. the neighbor
|
|
! who I just sent the packet to.
|
|
! \param[in] numTxAttempts Number of transmission attempts to this neighbor.
|
|
! \param[in] was_finally_acked TRUE iff the packet was ACK'ed by the neighbor
|
|
! on final transmission attempt.
|
|
! \param[in] asnTs ASN of the last transmission attempt.
|
|
*/
|
|
void neighbors_indicateTx(open_addr_t* l2_dest,
|
|
uint8_t numTxAttempts,
|
|
***************
|
|
*** 423,430 ****
|
|
The fields which are updated are:
|
|
- DAGrank
|
|
|
|
! \param msg [in] The received message with msg->payload pointing to the DIO
|
|
! header.
|
|
*/
|
|
void neighbors_indicateRxDIO(OpenQueueEntry_t* msg) {
|
|
uint8_t i;
|
|
--- 424,431 ----
|
|
The fields which are updated are:
|
|
- DAGrank
|
|
|
|
! \param[in] msg The received message with msg->payload pointing to the DIO
|
|
! header.
|
|
*/
|
|
void neighbors_indicateRxDIO(OpenQueueEntry_t* msg) {
|
|
uint8_t i;
|
|
***************
|
|
*** 438,448 ****
|
|
for (i=0;i<MAXNUMNEIGHBORS;i++) {
|
|
if (isThisRowMatching(&(msg->l2_nextORpreviousHop),i)) {
|
|
if (
|
|
! neighbors_vars.dio->rank>neighbors_vars.neighbors[i].DAGrank &&
|
|
! neighbors_vars.dio->rank - neighbors_vars.neighbors[i].DAGrank>DEFAULTLINKCOST
|
|
) {
|
|
// the new DAGrank looks suspiciously high, only increment a bit
|
|
! neighbors_vars.neighbors[i].DAGrank += DEFAULTLINKCOST;
|
|
openserial_printError(COMPONENT_NEIGHBORS,ERR_LARGE_DAGRANK,
|
|
(errorparameter_t)neighbors_vars.dio->rank,
|
|
(errorparameter_t)neighbors_vars.neighbors[i].DAGrank);
|
|
--- 439,449 ----
|
|
for (i=0;i<MAXNUMNEIGHBORS;i++) {
|
|
if (isThisRowMatching(&(msg->l2_nextORpreviousHop),i)) {
|
|
if (
|
|
! neighbors_vars.dio->rank > neighbors_vars.neighbors[i].DAGrank &&
|
|
! neighbors_vars.dio->rank - neighbors_vars.neighbors[i].DAGrank >(DEFAULTLINKCOST*2*MINHOPRANKINCREASE)
|
|
) {
|
|
// the new DAGrank looks suspiciously high, only increment a bit
|
|
! neighbors_vars.neighbors[i].DAGrank += (DEFAULTLINKCOST*2*MINHOPRANKINCREASE);
|
|
openserial_printError(COMPONENT_NEIGHBORS,ERR_LARGE_DAGRANK,
|
|
(errorparameter_t)neighbors_vars.dio->rank,
|
|
(errorparameter_t)neighbors_vars.neighbors[i].DAGrank);
|
|
***************
|
|
*** 490,498 ****
|
|
very low DAGrank, I may want to change by routing parent.
|
|
- I became a DAGroot, so my DAGrank should be 0.
|
|
*/
|
|
! void neighbors_updateMyDAGrankAndNeighborPreference() {
|
|
uint8_t i;
|
|
! uint8_t linkCost;
|
|
uint32_t tentativeDAGrank; // 32-bit since is used to sum
|
|
uint8_t prefParentIdx;
|
|
bool prefParentFound;
|
|
--- 491,499 ----
|
|
very low DAGrank, I may want to change by routing parent.
|
|
- I became a DAGroot, so my DAGrank should be 0.
|
|
*/
|
|
! void neighbors_updateMyDAGrankAndNeighborPreference(void) {
|
|
uint8_t i;
|
|
! uint16_t rankIncrease;
|
|
uint32_t tentativeDAGrank; // 32-bit since is used to sum
|
|
uint8_t prefParentIdx;
|
|
bool prefParentFound;
|
|
***************
|
|
*** 517,527 ****
|
|
neighbors_vars.neighbors[i].parentPreference=0;
|
|
// calculate link cost to this neighbor
|
|
if (neighbors_vars.neighbors[i].numTxACK==0) {
|
|
! linkCost = DEFAULTLINKCOST;
|
|
} else {
|
|
! linkCost = (uint8_t)((((float)neighbors_vars.neighbors[i].numTx)/((float)neighbors_vars.neighbors[i].numTxACK))*10.0);
|
|
}
|
|
! tentativeDAGrank = neighbors_vars.neighbors[i].DAGrank+linkCost;
|
|
if ( tentativeDAGrank<neighbors_vars.myDAGrank &&
|
|
tentativeDAGrank<MAXDAGRANK) {
|
|
// found better parent, lower my DAGrank
|
|
--- 518,529 ----
|
|
neighbors_vars.neighbors[i].parentPreference=0;
|
|
// calculate link cost to this neighbor
|
|
if (neighbors_vars.neighbors[i].numTxACK==0) {
|
|
! rankIncrease = DEFAULTLINKCOST*2*MINHOPRANKINCREASE;
|
|
} else {
|
|
! //6TiSCH minimal draft using OF0 for rank computation
|
|
! rankIncrease = (uint16_t)((((float)neighbors_vars.neighbors[i].numTx)/((float)neighbors_vars.neighbors[i].numTxACK))*2*MINHOPRANKINCREASE);
|
|
}
|
|
! tentativeDAGrank = neighbors_vars.neighbors[i].DAGrank+rankIncrease;
|
|
if ( tentativeDAGrank<neighbors_vars.myDAGrank &&
|
|
tentativeDAGrank<MAXDAGRANK) {
|
|
// found better parent, lower my DAGrank
|
|
***************
|
|
*** 550,556 ****
|
|
|
|
\returns TRUE if this function printed something, FALSE otherwise.
|
|
*/
|
|
! bool debugPrint_neighbors() {
|
|
debugNeighborEntry_t temp;
|
|
neighbors_vars.debugRow=(neighbors_vars.debugRow+1)%MAXNUMNEIGHBORS;
|
|
temp.row=neighbors_vars.debugRow;
|
|
--- 552,558 ----
|
|
|
|
\returns TRUE if this function printed something, FALSE otherwise.
|
|
*/
|
|
! bool debugPrint_neighbors(void) {
|
|
debugNeighborEntry_t temp;
|
|
neighbors_vars.debugRow=(neighbors_vars.debugRow+1)%MAXNUMNEIGHBORS;
|
|
temp.row=neighbors_vars.debugRow;
|
|
***************
|
|
*** 584,590 ****
|
|
|
|
void registerNewNeighbor(open_addr_t* address,
|
|
int8_t rssi,
|
|
! asn_t* asnTimestamp) {
|
|
uint8_t i,j;
|
|
bool iHaveAPreferedParent;
|
|
// filter errors
|
|
--- 586,594 ----
|
|
|
|
void registerNewNeighbor(open_addr_t* address,
|
|
int8_t rssi,
|
|
! asn_t* asnTimestamp,
|
|
! bool joinPrioPresent,
|
|
! uint8_t joinPrio) {
|
|
uint8_t i,j;
|
|
bool iHaveAPreferedParent;
|
|
// filter errors
|
|
***************
|
|
*** 613,619 ****
|
|
neighbors_vars.neighbors[i].numTx = 0;
|
|
neighbors_vars.neighbors[i].numTxACK = 0;
|
|
memcpy(&neighbors_vars.neighbors[i].asn,asnTimestamp,sizeof(asn_t));
|
|
! // do I already have a preferred parent ?
|
|
iHaveAPreferedParent = FALSE;
|
|
for (j=0;j<MAXNUMNEIGHBORS;j++) {
|
|
if (neighbors_vars.neighbors[j].parentPreference==MAXPREFERENCE) {
|
|
--- 617,629 ----
|
|
neighbors_vars.neighbors[i].numTx = 0;
|
|
neighbors_vars.neighbors[i].numTxACK = 0;
|
|
memcpy(&neighbors_vars.neighbors[i].asn,asnTimestamp,sizeof(asn_t));
|
|
! //update jp
|
|
! if (joinPrioPresent==TRUE){
|
|
! neighbors_vars.neighbors[i].joinPrio=joinPrio;
|
|
! }
|
|
!
|
|
!
|
|
! // do I already have a preferred parent ? -- TODO change to use JP
|
|
iHaveAPreferedParent = FALSE;
|
|
for (j=0;j<MAXNUMNEIGHBORS;j++) {
|
|
if (neighbors_vars.neighbors[j].parentPreference==MAXPREFERENCE) {
|