From aaafd6d4d593d5411d452b944d919745a4f202f1 Mon Sep 17 00:00:00 2001 From: changtengfei Date: Mon, 5 Nov 2018 12:01:22 +0100 Subject: [PATCH 01/20] FW-782. add automous rx cell for each motes. --- openstack/02b-MAChigh/msf.c | 33 +++++++++++++++++++++++++++++++++ openstack/02b-MAChigh/msf.h | 3 +++ projects/python/SConscript.env | 2 ++ 3 files changed, 38 insertions(+) diff --git a/openstack/02b-MAChigh/msf.c b/openstack/02b-MAChigh/msf.c index f0f13d321c..f8b061b34b 100644 --- a/openstack/02b-MAChigh/msf.c +++ b/openstack/02b-MAChigh/msf.c @@ -37,6 +37,7 @@ void msf_housekeeping(void); //=========================== public ========================================== void msf_init(void) { + memset(&msf_vars,0,sizeof(msf_vars_t)); msf_vars.numAppPacketsPerSlotFrame = 0; sixtop_setSFcallback( @@ -45,6 +46,15 @@ void msf_init(void) { (sixtop_sf_translatemetadata)msf_translateMetadata, (sixtop_sf_handle_callback)msf_handleRCError ); + + schedule_addActiveSlot( + msf_hashFunction_getSlotoffset(), // slot offset + CELLTYPE_RX, // type of slot + FALSE, // shared? + msf_hashFunction_getChanneloffset(), // channel offset + idmanager_getMyID(ADDR_64B) // neighbor + ); + msf_vars.housekeepingTimerId = opentimers_create(TIMER_GENERAL_PURPOSE); msf_vars.housekeepingPeriod = HOUSEKEEPING_PERIOD; opentimers_scheduleIn( @@ -171,6 +181,8 @@ void msf_timer_housekeeping_cb(opentimers_id_t id){ opentimers_updateDuration(msf_vars.housekeepingTimerId, newDuration); } +//=========================== tasks ============================================ + void msf_timer_housekeeping_task(void){ msf_housekeeping(); @@ -387,4 +399,25 @@ void msf_housekeeping(void){ 0 // list command maximum celllist (not used) ); } +} + +uint16_t msf_hashFunction_getSlotoffset(void){ + + uint16_t moteId; + + moteId = 256*idmanager_getMyID(ADDR_64B)->addr_64b[6]+\ + idmanager_getMyID(ADDR_64B)->addr_64b[7]; + + return SCHEDULE_MINIMAL_6TISCH_ACTIVE_CELLS + \ + (moteId%(SLOTFRAME_LENGTH-SCHEDULE_MINIMAL_6TISCH_ACTIVE_CELLS)); +} + +uint8_t msf_hashFunction_getChanneloffset(void){ + + uint16_t moteId; + + moteId = 256*idmanager_getMyID(ADDR_64B)->addr_64b[6]+\ + idmanager_getMyID(ADDR_64B)->addr_64b[7]; + + return moteId%NUM_CHANNELS; } \ No newline at end of file diff --git a/openstack/02b-MAChigh/msf.h b/openstack/02b-MAChigh/msf.h index 12cf0b1eaa..e1d6b51d34 100644 --- a/openstack/02b-MAChigh/msf.h +++ b/openstack/02b-MAChigh/msf.h @@ -60,6 +60,9 @@ void msf_updateCellsPassed(open_addr_t* neighbor); void msf_updateCellsUsed(open_addr_t* neighbor); // called by icmpv6rpl, where parent changed void msf_trigger6pClear(open_addr_t* neighbor); + +uint16_t msf_hashFunction_getSlotoffset(void); +uint8_t msf_hashFunction_getChanneloffset(void); /** \} \} diff --git a/projects/python/SConscript.env b/projects/python/SConscript.env index 59d49e3a6d..90a592323f 100644 --- a/projects/python/SConscript.env +++ b/projects/python/SConscript.env @@ -651,6 +651,8 @@ functionsToChange = [ 'msf_trigger6pClear', 'msf_updateCellsPassed', 'msf_updateCellsUsed', + 'msf_hashFunction_getSlotoffset', + 'msf_hashFunction_getChanneloffset', # sixtop 'sixtop_init', 'sixtop_setKaPeriod', From 04311eae009f7651093cacb877502c68d8f155ca Mon Sep 17 00:00:00 2001 From: changtengfei Date: Mon, 5 Nov 2018 16:18:08 +0100 Subject: [PATCH 02/20] FW-782. add autonomous tx cell when new neighbor is found and remove the cell when neighbor is removed. --- openstack/02b-MAChigh/msf.c | 18 +-- openstack/02b-MAChigh/msf.h | 4 +- openstack/02b-MAChigh/neighbors.c | 213 ++++++++++++++++-------------- 3 files changed, 121 insertions(+), 114 deletions(-) diff --git a/openstack/02b-MAChigh/msf.c b/openstack/02b-MAChigh/msf.c index f8b061b34b..44ccf310cb 100644 --- a/openstack/02b-MAChigh/msf.c +++ b/openstack/02b-MAChigh/msf.c @@ -48,10 +48,10 @@ void msf_init(void) { ); schedule_addActiveSlot( - msf_hashFunction_getSlotoffset(), // slot offset + msf_hashFunction_getSlotoffset(256*idmanager_getMyID(ADDR_64B)->addr_64b[6]+idmanager_getMyID(ADDR_64B)->addr_64b[7]), // slot offset CELLTYPE_RX, // type of slot FALSE, // shared? - msf_hashFunction_getChanneloffset(), // channel offset + msf_hashFunction_getChanneloffset(256*idmanager_getMyID(ADDR_64B)->addr_64b[6]+idmanager_getMyID(ADDR_64B)->addr_64b[7]), // channel offset idmanager_getMyID(ADDR_64B) // neighbor ); @@ -401,23 +401,13 @@ void msf_housekeeping(void){ } } -uint16_t msf_hashFunction_getSlotoffset(void){ - - uint16_t moteId; - - moteId = 256*idmanager_getMyID(ADDR_64B)->addr_64b[6]+\ - idmanager_getMyID(ADDR_64B)->addr_64b[7]; +uint16_t msf_hashFunction_getSlotoffset(uint16_t moteId){ return SCHEDULE_MINIMAL_6TISCH_ACTIVE_CELLS + \ (moteId%(SLOTFRAME_LENGTH-SCHEDULE_MINIMAL_6TISCH_ACTIVE_CELLS)); } -uint8_t msf_hashFunction_getChanneloffset(void){ - - uint16_t moteId; - - moteId = 256*idmanager_getMyID(ADDR_64B)->addr_64b[6]+\ - idmanager_getMyID(ADDR_64B)->addr_64b[7]; +uint8_t msf_hashFunction_getChanneloffset(uint16_t moteId){ return moteId%NUM_CHANNELS; } \ No newline at end of file diff --git a/openstack/02b-MAChigh/msf.h b/openstack/02b-MAChigh/msf.h index e1d6b51d34..642e5470e5 100644 --- a/openstack/02b-MAChigh/msf.h +++ b/openstack/02b-MAChigh/msf.h @@ -61,8 +61,8 @@ void msf_updateCellsUsed(open_addr_t* neighbor); // called by icmpv6rpl, where parent changed void msf_trigger6pClear(open_addr_t* neighbor); -uint16_t msf_hashFunction_getSlotoffset(void); -uint8_t msf_hashFunction_getChanneloffset(void); +uint16_t msf_hashFunction_getSlotoffset(uint16_t moteId); +uint8_t msf_hashFunction_getChanneloffset(uint16_t moteId); /** \} \} diff --git a/openstack/02b-MAChigh/neighbors.c b/openstack/02b-MAChigh/neighbors.c index d17c8eb080..02f7146c76 100644 --- a/openstack/02b-MAChigh/neighbors.c +++ b/openstack/02b-MAChigh/neighbors.c @@ -35,11 +35,11 @@ bool isThisRowMatching( \brief Initializes this module. */ void neighbors_init(void) { - + // clear module variables memset(&neighbors_vars,0,sizeof(neighbors_vars_t)); // The .used fields get reset to FALSE by this memset. - + } //===== getters @@ -52,7 +52,7 @@ void neighbors_init(void) { uint8_t neighbors_getNumNeighbors(void) { uint8_t i; uint8_t returnVal; - + returnVal=0; for (i=0;itype) { case ADDR_128B: @@ -178,7 +178,7 @@ bool neighbors_isStableNeighbor(open_addr_t* address) { (errorparameter_t)0); return returnVal; } - + // iterate through neighbor table for (i=0;itype) { case ADDR_64B: break; @@ -225,7 +225,7 @@ bool neighbors_isInsecureNeighbor(open_addr_t* address) { (errorparameter_t)0); return returnVal; } - + // iterate through neighbor table for (i=0;i= icmpv6rpl_getMyDAGrank()) { + neighbors_vars.neighbors[index].DAGrank >= icmpv6rpl_getMyDAGrank()) { returnVal = TRUE; } else { returnVal = FALSE; } - + return returnVal; } bool neighbors_reachedMinimalTransmission(uint8_t index){ bool returnVal; - + if ( neighbors_vars.neighbors[index].used == TRUE && neighbors_vars.neighbors[index].numTx > MINIMAL_NUM_TX @@ -268,7 +268,7 @@ bool neighbors_reachedMinimalTransmission(uint8_t index){ } else { returnVal = FALSE; } - + return returnVal; } @@ -303,15 +303,15 @@ void neighbors_indicateRx(open_addr_t* l2_src, bool insecure) { uint8_t i; bool newNeighbor; - + // update existing neighbor newNeighbor = TRUE; for (i=0;iBADNEIGHBORMAXRSSI) { @@ -346,12 +346,12 @@ void neighbors_indicateRx(open_addr_t* l2_src, neighbors_vars.neighbors[i].switchStabilityCounter=0; } } - + // stop looping break; } } - + // register new neighbor if (newNeighbor==TRUE) { registerNewNeighbor(l2_src, rssi, asnTs, joinPrioPresent, joinPrio, insecure); @@ -387,25 +387,25 @@ void neighbors_indicateTx( if (packetfunctions_isBroadcastMulticast(l2_dest)==TRUE) { return; } - + // loop through neighbor table for (i=0;i(0xff-numTxAttempts)) { neighbors_vars.neighbors[i].numWraps++; //counting the number of times that tx wraps. neighbors_vars.neighbors[i].numTx/=2; neighbors_vars.neighbors[i].numTxACK/=2; } // update statistics - neighbors_vars.neighbors[i].numTx += numTxAttempts; - + neighbors_vars.neighbors[i].numTx += numTxAttempts; + if (was_finally_acked==TRUE) { neighbors_vars.neighbors[i].numTxACK++; memcpy(&neighbors_vars.neighbors[i].asn,asnTs,sizeof(asn_t)); } - + // numTx and numTxAck changed,, update my rank icmpv6rpl_updateMyDAGrankAndParentSelection(); break; @@ -455,7 +455,7 @@ bool neighbors_getNeighborEui64(open_addr_t* address, uint8_t addr_type, uint8_ openserial_printCritical(COMPONENT_NEIGHBORS,ERR_WRONG_ADDR_TYPE, (errorparameter_t)addr_type, (errorparameter_t)1); - break; + break; } return ReturnVal; } @@ -488,7 +488,7 @@ void neighbors_decreaseBackoff(open_addr_t* address){ bool neighbors_backoffHitZero(open_addr_t* address){ uint8_t i; bool returnVal; - + returnVal = FALSE; for (i=0;i DEFAULTLINKCOST){ @@ -572,7 +572,7 @@ uint16_t neighbors_getLinkMetric(uint8_t index) { } else { rankIncrease = (uint16_t)(rankIncreaseIntermediary >> 10); } - + if ( rankIncrease>(3*DEFAULTLINKCOST-2)*MINHOPRANKINCREASE && neighbors_vars.neighbors[index].numTx > MINIMAL_NUM_TX @@ -601,7 +601,7 @@ void neighbors_removeOld(void) { ) { return; } - + // remove old neighbor for (i=0;itype!=ADDR_64B) { - openserial_printCritical(COMPONENT_NEIGHBORS,ERR_WRONG_ADDR_TYPE, + uint8_t i; + uint16_t slotoffset; + uint8_t channeloffset; + + // filter errors + if (address->type!=ADDR_64B) { + openserial_printCritical(COMPONENT_NEIGHBORS,ERR_WRONG_ADDR_TYPE, (errorparameter_t)address->type, (errorparameter_t)2); - return; - } - // add this neighbor - if (isNeighbor(address)==FALSE) { - i=0; - while(iaddr_64b[6]+address->addr_64b[7]); + channeloffset = msf_hashFunction_getChanneloffset(256*address->addr_64b[6]+address->addr_64b[7]); + schedule_addActiveSlot( + slotoffset, // slot offset + CELLTYPE_TX, // type of slot + TRUE, // shared? + channeloffset, // channel offset + address // neighbor + ); break; } - // add this neighbor - neighbors_vars.neighbors[i].used = TRUE; - neighbors_vars.neighbors[i].insecure = insecure; - // neighbors_vars.neighbors[i].stableNeighbor = FALSE; - // Note: all new neighbors are consider stable - neighbors_vars.neighbors[i].stableNeighbor = TRUE; - neighbors_vars.neighbors[i].switchStabilityCounter = 0; - memcpy(&neighbors_vars.neighbors[i].addr_64b,address,sizeof(open_addr_t)); - neighbors_vars.neighbors[i].DAGrank = DEFAULTDAGRANK; - // since we don't have a DAG rank at this point, no need to call for routing table update - neighbors_vars.neighbors[i].rssi = rssi; - neighbors_vars.neighbors[i].numRx = 1; - neighbors_vars.neighbors[i].numTx = 0; - neighbors_vars.neighbors[i].numTxACK = 0; - memcpy(&neighbors_vars.neighbors[i].asn,asnTimestamp,sizeof(asn_t)); - neighbors_vars.neighbors[i].backoffExponenton = MINBE-1;; - neighbors_vars.neighbors[i].backoff = 0; - //update jp - if (joinPrioPresent==TRUE){ - neighbors_vars.neighbors[i].joinPrio=joinPrio; - } - - break; - } - i++; - } - if (i==MAXNUMNEIGHBORS) { - openserial_printError(COMPONENT_NEIGHBORS,ERR_NEIGHBORS_FULL, + i++; + } + if (i==MAXNUMNEIGHBORS) { + openserial_printError(COMPONENT_NEIGHBORS,ERR_NEIGHBORS_FULL, (errorparameter_t)MAXNUMNEIGHBORS, (errorparameter_t)0); - return; - } - } + return; + } + } } bool isNeighbor(open_addr_t* neighbor) { @@ -714,25 +725,31 @@ bool isNeighbor(open_addr_t* neighbor) { } void removeNeighbor(uint8_t neighborIndex) { - neighbors_vars.neighbors[neighborIndex].used = FALSE; - neighbors_vars.neighbors[neighborIndex].parentPreference = 0; - neighbors_vars.neighbors[neighborIndex].stableNeighbor = FALSE; - neighbors_vars.neighbors[neighborIndex].switchStabilityCounter = 0; - //neighbors_vars.neighbors[neighborIndex].addr_16b.type = ADDR_NONE; // to save RAM - neighbors_vars.neighbors[neighborIndex].addr_64b.type = ADDR_NONE; - //neighbors_vars.neighbors[neighborIndex].addr_128b.type = ADDR_NONE; // to save RAM - neighbors_vars.neighbors[neighborIndex].DAGrank = DEFAULTDAGRANK; - neighbors_vars.neighbors[neighborIndex].rssi = 0; - neighbors_vars.neighbors[neighborIndex].numRx = 0; - neighbors_vars.neighbors[neighborIndex].numTx = 0; - neighbors_vars.neighbors[neighborIndex].numTxACK = 0; - neighbors_vars.neighbors[neighborIndex].asn.bytes0and1 = 0; - neighbors_vars.neighbors[neighborIndex].asn.bytes2and3 = 0; - neighbors_vars.neighbors[neighborIndex].asn.byte4 = 0; - neighbors_vars.neighbors[neighborIndex].f6PNORES = FALSE; - neighbors_vars.neighbors[neighborIndex].sequenceNumber = 0; - neighbors_vars.neighbors[neighborIndex].backoffExponenton = MINBE-1;; - neighbors_vars.neighbors[neighborIndex].backoff = 0; + uint16_t slotoffset; + + neighbors_vars.neighbors[neighborIndex].used = FALSE; + neighbors_vars.neighbors[neighborIndex].parentPreference = 0; + neighbors_vars.neighbors[neighborIndex].stableNeighbor = FALSE; + neighbors_vars.neighbors[neighborIndex].switchStabilityCounter = 0; + neighbors_vars.neighbors[neighborIndex].DAGrank = DEFAULTDAGRANK; + neighbors_vars.neighbors[neighborIndex].rssi = 0; + neighbors_vars.neighbors[neighborIndex].numRx = 0; + neighbors_vars.neighbors[neighborIndex].numTx = 0; + neighbors_vars.neighbors[neighborIndex].numTxACK = 0; + neighbors_vars.neighbors[neighborIndex].asn.bytes0and1 = 0; + neighbors_vars.neighbors[neighborIndex].asn.bytes2and3 = 0; + neighbors_vars.neighbors[neighborIndex].asn.byte4 = 0; + neighbors_vars.neighbors[neighborIndex].f6PNORES = FALSE; + neighbors_vars.neighbors[neighborIndex].sequenceNumber = 0; + neighbors_vars.neighbors[neighborIndex].backoffExponenton = MINBE-1;; + neighbors_vars.neighbors[neighborIndex].backoff = 0; + + slotoffset = msf_hashFunction_getSlotoffset(256*neighbors_vars.neighbors[neighborIndex].addr_64b.addr_64b[6]+neighbors_vars.neighbors[neighborIndex].addr_64b.addr_64b[7]); + schedule_removeActiveSlot( + slotoffset, // slot offset + &(neighbors_vars.neighbors[neighborIndex].addr_64b) // neighbor + ); + neighbors_vars.neighbors[neighborIndex].addr_64b.type = ADDR_NONE; } //=========================== helpers ========================================= From 05288ad46eab6dd7dbf523461b9083c443098bff Mon Sep 17 00:00:00 2001 From: changtengfei Date: Mon, 5 Nov 2018 16:19:18 +0100 Subject: [PATCH 03/20] FW-782. increase the number of timers supported. --- drivers/common/openserial.c | 7 +++---- drivers/common/openserial.h | 1 + drivers/common/opentimers.h | 2 +- openapps/cjoin/cjoin.c | 5 ++--- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/common/openserial.c b/drivers/common/openserial.c index 78924b2a15..3ac340449d 100644 --- a/drivers/common/openserial.c +++ b/drivers/common/openserial.c @@ -99,7 +99,8 @@ void openserial_init(void) { openserial_vars.outputBufIdxW = 0; openserial_vars.fBusyFlushing = FALSE; - openserial_vars.debugPrint_timerId = opentimers_create(TIMER_GENERAL_PURPOSE); + openserial_vars.reset_timerId = opentimers_create(TIMER_GENERAL_PURPOSE); + openserial_vars.debugPrint_timerId = opentimers_create(TIMER_GENERAL_PURPOSE); opentimers_scheduleIn( openserial_vars.debugPrint_timerId, DEBUGPRINT_PERIOD, @@ -189,17 +190,15 @@ owerror_t openserial_printCritical( errorparameter_t arg1, errorparameter_t arg2 ) { - opentimers_id_t id; uint32_t reference; // blink error LED, this is serious leds_error_blink(); // schedule for the mote to reboot in 10s - id = opentimers_create(TIMER_GENERAL_PURPOSE); reference = opentimers_getValue(); opentimers_scheduleAbsolute( - id, // timerId + openserial_vars.reset_timerId, // timerId 10000, // duration reference, // reference TIME_MS, // timetype diff --git a/drivers/common/openserial.h b/drivers/common/openserial.h index b7693cb493..8fa3eb1ca6 100644 --- a/drivers/common/openserial.h +++ b/drivers/common/openserial.h @@ -101,6 +101,7 @@ typedef struct { uint8_t ctsStateChanged; uint8_t debugPrintCounter; openserial_rsvpt* registeredCmd; + uint8_t reset_timerId; uint8_t debugPrint_timerId; // input uint8_t inputBuf[SERIAL_INPUT_BUFFER_SIZE]; diff --git a/drivers/common/opentimers.h b/drivers/common/opentimers.h index e1ff2e57ca..415c67fbb0 100644 --- a/drivers/common/opentimers.h +++ b/drivers/common/opentimers.h @@ -19,7 +19,7 @@ //=========================== define ========================================== /// Maximum number of timers that can run concurrently -#define MAX_NUM_TIMERS 10 +#define MAX_NUM_TIMERS 15 #define MAX_TICKS_IN_SINGLE_CLOCK (uint32_t)(((PORT_TIMER_WIDTH)0xFFFFFFFF)>>1) #define ERROR_NO_AVAILABLE_ENTRIES 255 #define MAX_DURATION_ISR 33 // 33@32768Hz = 1ms diff --git a/openapps/cjoin/cjoin.c b/openapps/cjoin/cjoin.c index f3fc8e228a..0bb241f947 100644 --- a/openapps/cjoin/cjoin.c +++ b/openapps/cjoin/cjoin.c @@ -210,7 +210,6 @@ void cjoin_task_cb(void) { // init the security context only here in order to use the latest joinKey // that may be set over the serial // cjoin_init_security_context(); - cjoin_sendJoinRequest(joinProxy); return; @@ -249,6 +248,7 @@ owerror_t cjoin_sendJoinRequest(open_addr_t* joinProxy) { ); return E_FAIL; } + // take ownership over that packet pkt->creator = COMPONENT_CJOIN; pkt->owner = COMPONENT_CJOIN; @@ -292,7 +292,6 @@ owerror_t cjoin_sendJoinRequest(open_addr_t* joinProxy) { payload_len = cojp_cbor_encode_join_request_object(tmp, &join_request); packetfunctions_reserveHeaderSize(pkt, payload_len); memcpy(pkt->payload, tmp, payload_len); - // send outcome = opencoap_send( pkt, @@ -310,7 +309,7 @@ owerror_t cjoin_sendJoinRequest(open_addr_t* joinProxy) { return E_FAIL; } - return E_SUCCESS; + return E_SUCCESS; } bool cjoin_getIsJoined(void) { From 64c2fdc109d76d724400c860280b9d6bac2a7b17 Mon Sep 17 00:00:00 2001 From: changtengfei Date: Mon, 5 Nov 2018 22:46:53 +0100 Subject: [PATCH 04/20] FW-782. don't remove the autonomous cell. --- openstack/02b-MAChigh/msf.c | 6 +----- openstack/02b-MAChigh/msf.h | 2 +- openstack/02b-MAChigh/schedule.c | 27 ++++++++++++++++++++++++--- openstack/02b-MAChigh/schedule.h | 1 + projects/python/SConscript.env | 1 + 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/openstack/02b-MAChigh/msf.c b/openstack/02b-MAChigh/msf.c index 44ccf310cb..51e8e281c4 100644 --- a/openstack/02b-MAChigh/msf.c +++ b/openstack/02b-MAChigh/msf.c @@ -99,7 +99,7 @@ void msf_updateCellsUsed(open_addr_t* neighbor){ void msf_trigger6pClear(open_addr_t* neighbor){ - if (schedule_hasDedicatedCellToNeighbor(neighbor)>0){ + if (schedule_hasNonSharedDedicatedCellToNeighbor(neighbor)>0){ sixtop_request( IANA_6TOP_CMD_CLEAR, // code neighbor, // neighbor @@ -368,10 +368,6 @@ void msf_housekeeping(void){ if (foundNeighbor==FALSE) { return; } - if (schedule_getNumberOfDedicatedCells(&parentNeighbor)==0){ - msf_trigger6pAdd(); - return; - } if (msf_vars.waitretry){ return; diff --git a/openstack/02b-MAChigh/msf.h b/openstack/02b-MAChigh/msf.h index 642e5470e5..af896a906e 100644 --- a/openstack/02b-MAChigh/msf.h +++ b/openstack/02b-MAChigh/msf.h @@ -13,7 +13,7 @@ //=========================== define ========================================== #define IANA_6TISCH_SFID_MSF 0 -#define CELLOPTIONS_MSF CELLOPTIONS_TX | CELLOPTIONS_RX | CELLOPTIONS_SHARED +#define CELLOPTIONS_MSF CELLOPTIONS_TX #define NUMCELLS_MSF 1 #define MAX_NUMCELLS 16 diff --git a/openstack/02b-MAChigh/schedule.c b/openstack/02b-MAChigh/schedule.c index b0768ef0d6..e0f098d9d8 100644 --- a/openstack/02b-MAChigh/schedule.c +++ b/openstack/02b-MAChigh/schedule.c @@ -519,7 +519,7 @@ uint8_t schedule_getNumberOfDedicatedCells(open_addr_t* neighbor){ } open_addr_t* schedule_getNonParentNeighborWithDedicatedCells(open_addr_t* neighbor){ - uint8_t i; + uint8_t i; INTERRUPT_DECLARATION(); DISABLE_INTERRUPTS(); @@ -532,9 +532,9 @@ open_addr_t* schedule_getNonParentNeighborWithDedicatedCells(open_addr_t* neighb return &schedule_vars.scheduleBuf[i].neighbor; } } - + ENABLE_INTERRUPTS(); - + return NULL; } @@ -634,6 +634,27 @@ bool schedule_hasDedicatedCellToNeighbor(open_addr_t* neighbor){ return FALSE; } +bool schedule_hasNonSharedDedicatedCellToNeighbor(open_addr_t* neighbor){ + uint8_t i; + + INTERRUPT_DECLARATION(); + DISABLE_INTERRUPTS(); + + for(i=0;i Date: Tue, 6 Nov 2018 16:15:35 +0100 Subject: [PATCH 05/20] FW-782. increase the backoff exponent and maxmium number of tries. --- openstack/02a-MAClow/IEEE802154E.h | 2 +- openstack/02b-MAChigh/schedule.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/openstack/02a-MAClow/IEEE802154E.h b/openstack/02a-MAClow/IEEE802154E.h index a8f48e78f3..dc30ec6a77 100644 --- a/openstack/02a-MAClow/IEEE802154E.h +++ b/openstack/02a-MAClow/IEEE802154E.h @@ -38,7 +38,7 @@ static const uint8_t ebIEsBytestream[] = { #define EB_IE_LEN 28 #define NUM_CHANNELS 16 // number of channels to channel hop on -#define TXRETRIES 3 // number of MAC retries before declaring failed +#define TXRETRIES 7 // number of MAC retries before declaring failed #define TX_POWER 31 // 1=-25dBm, 31=0dBm (max value) #define RESYNCHRONIZATIONGUARD 5 // in 32kHz ticks. min distance to the end of the slot to successfully synchronize #define US_PER_TICK 30 // number of us per 32kHz clock tick diff --git a/openstack/02b-MAChigh/schedule.h b/openstack/02b-MAChigh/schedule.h index 862be76eb9..4d274cac6b 100644 --- a/openstack/02b-MAChigh/schedule.h +++ b/openstack/02b-MAChigh/schedule.h @@ -60,14 +60,14 @@ Backoff is used only in slots that are marked as shared in the schedule. When not shared, the mote assumes that schedule is collision-free, and therefore does not use any backoff mechanism when a transmission fails. */ -#define MINBE 2 +#define MINBE 2 // the standard compliant range of MAXBE is 0-MAXBE /** \brief Maximum backoff exponent. See MINBE for an explanation of backoff. */ -#define MAXBE 4 +#define MAXBE 8 // the standard compliant range of MAXBE is 3-8 /** \brief a threshold used for triggering the maintaining process.uint: percent From 6ece5f32efd08c276e6ee82f9c226aa14e0624db Mon Sep 17 00:00:00 2001 From: changtengfei Date: Tue, 6 Nov 2018 18:03:31 +0100 Subject: [PATCH 06/20] FW-782. just reserve autonomous cell to parent. --- openstack/02b-MAChigh/neighbors.c | 42 ++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/openstack/02b-MAChigh/neighbors.c b/openstack/02b-MAChigh/neighbors.c index 02f7146c76..904993cae6 100644 --- a/openstack/02b-MAChigh/neighbors.c +++ b/openstack/02b-MAChigh/neighbors.c @@ -532,7 +532,34 @@ void neighbors_setNeighborNoResource(open_addr_t* address){ } void neighbors_setPreferredParent(uint8_t index, bool isPreferred){ + + uint16_t moteId; + neighbors_vars.neighbors[index].parentPreference = isPreferred; + + moteId = 256*neighbors_vars.neighbors[index].addr_64b.addr_64b[6]+\ + neighbors_vars.neighbors[index].addr_64b.addr_64b[7]; + slotoffset = msf_hashFunction_getSlotoffset(moteId); + channeloffset = msf_hashFunction_getChanneloffset(moteId); + + if (isPreferred){ + // the neighbor is selected as parent + // reserve the autonomous cell to this neighbor + schedule_addActiveSlot( + slotoffset, // slot offset + CELLTYPE_TX, // type of slot + TRUE, // shared? + channeloffset, // channel offset + &(neighbors_vars.neighbors[index].addr_64b) // neighbor + ); + } else { + // the neighbor is de-selected as parent + // remove the autonomous cell to this neighbor + schedule_removeActiveSlot( + slotoffset, // slot offset + &(neighbors_vars.neighbors[index].addr_64b) // neighbor + ); + } } //===== managing routing info @@ -692,15 +719,6 @@ void registerNewNeighbor(open_addr_t* address, if (joinPrioPresent==TRUE){ neighbors_vars.neighbors[i].joinPrio=joinPrio; } - slotoffset = msf_hashFunction_getSlotoffset(256*address->addr_64b[6]+address->addr_64b[7]); - channeloffset = msf_hashFunction_getChanneloffset(256*address->addr_64b[6]+address->addr_64b[7]); - schedule_addActiveSlot( - slotoffset, // slot offset - CELLTYPE_TX, // type of slot - TRUE, // shared? - channeloffset, // channel offset - address // neighbor - ); break; } i++; @@ -743,12 +761,6 @@ void removeNeighbor(uint8_t neighborIndex) { neighbors_vars.neighbors[neighborIndex].sequenceNumber = 0; neighbors_vars.neighbors[neighborIndex].backoffExponenton = MINBE-1;; neighbors_vars.neighbors[neighborIndex].backoff = 0; - - slotoffset = msf_hashFunction_getSlotoffset(256*neighbors_vars.neighbors[neighborIndex].addr_64b.addr_64b[6]+neighbors_vars.neighbors[neighborIndex].addr_64b.addr_64b[7]); - schedule_removeActiveSlot( - slotoffset, // slot offset - &(neighbors_vars.neighbors[neighborIndex].addr_64b) // neighbor - ); neighbors_vars.neighbors[neighborIndex].addr_64b.type = ADDR_NONE; } From e89b92b21c74c47ed19a3ce4de3b277e666e363f Mon Sep 17 00:00:00 2001 From: changtengfei Date: Tue, 6 Nov 2018 18:05:33 +0100 Subject: [PATCH 07/20] FW-782. fixed. --- openstack/02b-MAChigh/neighbors.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openstack/02b-MAChigh/neighbors.c b/openstack/02b-MAChigh/neighbors.c index 904993cae6..fe19c35e26 100644 --- a/openstack/02b-MAChigh/neighbors.c +++ b/openstack/02b-MAChigh/neighbors.c @@ -534,6 +534,8 @@ void neighbors_setNeighborNoResource(open_addr_t* address){ void neighbors_setPreferredParent(uint8_t index, bool isPreferred){ uint16_t moteId; + uint16_t slotoffset; + uint8_t channeloffset; neighbors_vars.neighbors[index].parentPreference = isPreferred; From 797d7e9583f204926b4f067872e117dfb9edc1f1 Mon Sep 17 00:00:00 2001 From: changtengfei Date: Tue, 6 Nov 2018 18:06:56 +0100 Subject: [PATCH 08/20] FW-782. fix the warning. --- openstack/02b-MAChigh/neighbors.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/openstack/02b-MAChigh/neighbors.c b/openstack/02b-MAChigh/neighbors.c index fe19c35e26..cfdf92b059 100644 --- a/openstack/02b-MAChigh/neighbors.c +++ b/openstack/02b-MAChigh/neighbors.c @@ -682,8 +682,6 @@ void registerNewNeighbor(open_addr_t* address, uint8_t joinPrio, bool insecure) { uint8_t i; - uint16_t slotoffset; - uint8_t channeloffset; // filter errors if (address->type!=ADDR_64B) { @@ -745,8 +743,6 @@ bool isNeighbor(open_addr_t* neighbor) { } void removeNeighbor(uint8_t neighborIndex) { - uint16_t slotoffset; - neighbors_vars.neighbors[neighborIndex].used = FALSE; neighbors_vars.neighbors[neighborIndex].parentPreference = 0; neighbors_vars.neighbors[neighborIndex].stableNeighbor = FALSE; From 27504b4993d5852068168ea97849663a8d3cd36f Mon Sep 17 00:00:00 2001 From: changtengfei Date: Tue, 6 Nov 2018 18:47:25 +0100 Subject: [PATCH 09/20] FW-782. remove cell only when it exist. --- openstack/02b-MAChigh/neighbors.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/openstack/02b-MAChigh/neighbors.c b/openstack/02b-MAChigh/neighbors.c index cfdf92b059..7b16d49264 100644 --- a/openstack/02b-MAChigh/neighbors.c +++ b/openstack/02b-MAChigh/neighbors.c @@ -557,10 +557,12 @@ void neighbors_setPreferredParent(uint8_t index, bool isPreferred){ } else { // the neighbor is de-selected as parent // remove the autonomous cell to this neighbor - schedule_removeActiveSlot( - slotoffset, // slot offset - &(neighbors_vars.neighbors[index].addr_64b) // neighbor - ); + if (schedule_hasDedicatedCellToNeighbor(&(neighbors_vars.neighbors[index].addr_64b))){ + schedule_removeActiveSlot( + slotoffset, // slot offset + &(neighbors_vars.neighbors[index].addr_64b) // neighbor + ); + } } } From d56a6d9de5f04fb93a74a6fe1a1c0d962d798bd2 Mon Sep 17 00:00:00 2001 From: changtengfei Date: Tue, 6 Nov 2018 21:29:16 +0100 Subject: [PATCH 10/20] FW-782. regulate the traffic on different cells and update functions names. --- openstack/02a-MAClow/IEEE802154E.c | 43 +++++++++++++------------ openstack/02b-MAChigh/msf.c | 11 +++++-- openstack/02b-MAChigh/neighbors.c | 6 ++-- openstack/02b-MAChigh/schedule.c | 51 ++++++++++++++++-------------- openstack/02b-MAChigh/schedule.h | 8 ++--- openstack/02b-MAChigh/sixtop.c | 6 ++-- openstack/cross-layers/openqueue.c | 37 ++++++++++++++++++---- openstack/cross-layers/openqueue.h | 3 +- projects/python/SConscript.env | 11 ++++--- 9 files changed, 106 insertions(+), 70 deletions(-) diff --git a/openstack/02a-MAClow/IEEE802154E.c b/openstack/02a-MAClow/IEEE802154E.c index 35b1995732..e518f1f984 100644 --- a/openstack/02a-MAClow/IEEE802154E.c +++ b/openstack/02a-MAClow/IEEE802154E.c @@ -952,13 +952,20 @@ port_INLINE void activity_ti1ORri1(void) { // check whether we can send if (schedule_getOkToSend()) { if (packetfunctions_isBroadcastMulticast(&neighbor)==FALSE){ - // this is a dedicated cell - ieee154e_vars.dataToSend = openqueue_macGetDedicatedPacket(&neighbor); - // update numcellpassed and numcellused on dedicated cell - if (ieee154e_vars.dataToSend!=NULL) { - msf_updateCellsUsed(&neighbor); + + if (schedule_getShared()){ + // this is an autonomous Tx cell + ieee154e_vars.dataToSend = openqueue_macGet6PandJoinPacket(&neighbor); + } else { + // this is a managed Tx cell + ieee154e_vars.dataToSend = openqueue_macGetNonJoinIPv6Packet(&neighbor); + + // update numcellpassed and numcellused on managed Tx cell + if (ieee154e_vars.dataToSend!=NULL) { + msf_updateCellsUsed(&neighbor); + } + msf_updateCellsPassed(&neighbor); } - msf_updateCellsPassed(&neighbor); } else { // this is minimal cell ieee154e_vars.dataToSend = openqueue_macGetDataPacket(&neighbor); @@ -969,20 +976,14 @@ port_INLINE void activity_ti1ORri1(void) { } else { // there is a packet to send if ( - schedule_hasDedicatedCellToNeighbor(&ieee154e_vars.dataToSend->l2_nextORpreviousHop) + schedule_hasAutonomousTxCellToNeighbor(&ieee154e_vars.dataToSend->l2_nextORpreviousHop) ) { - // allow sixtop response with SEQNUM_ERR return code send on minimal cell - if ( - ieee154e_vars.dataToSend->creator!=COMPONENT_SIXTOP_RES || - ieee154e_vars.dataToSend->l2_sixtop_returnCode != IANA_6TOP_RC_SEQNUM_ERR - ) { - // leave the packet to be sent on dedicated cell and pick up a broadcast packet. - ieee154e_vars.dataToSend = openqueue_macGetDIOPacket(); - if (ieee154e_vars.dataToSend==NULL){ - couldSendEB=TRUE; - // look for an EB packet in the queue - ieee154e_vars.dataToSend = openqueue_macGetEBPacket(); - } + // leave the packet to be sent on autonomous Tx Cell cell and pick up a broadcast packet. + ieee154e_vars.dataToSend = openqueue_macGetDIOPacket(); + if (ieee154e_vars.dataToSend==NULL){ + couldSendEB=TRUE; + // look for an EB packet in the queue + ieee154e_vars.dataToSend = openqueue_macGetEBPacket(); } } } @@ -1920,7 +1921,7 @@ port_INLINE void activity_ri5(PORT_TIMER_WIDTH capturedTime) { } else { // synchronize to the received packet if I'm not a DAGroot and this is my preferred parent // or in case I'm in the middle of the join process when parent is not yet selected - // or in case I don't have a dedicated cell to my parent yet + // or in case I don't have an autonomous Tx cell cell to my parent yet if ( idmanager_getIsDAGroot() == FALSE && ( @@ -1929,7 +1930,7 @@ port_INLINE void activity_ri5(PORT_TIMER_WIDTH capturedTime) { icmpv6rpl_getPreferredParentEui64(&addressToWrite) == FALSE || ( icmpv6rpl_getPreferredParentEui64(&addressToWrite) && - schedule_hasDedicatedCellToNeighbor(&addressToWrite)== FALSE + schedule_hasAutonomousTxCellToNeighbor(&addressToWrite)== FALSE ) ) ) { diff --git a/openstack/02b-MAChigh/msf.c b/openstack/02b-MAChigh/msf.c index 51e8e281c4..7305be1cc9 100644 --- a/openstack/02b-MAChigh/msf.c +++ b/openstack/02b-MAChigh/msf.c @@ -99,7 +99,7 @@ void msf_updateCellsUsed(open_addr_t* neighbor){ void msf_trigger6pClear(open_addr_t* neighbor){ - if (schedule_hasNonSharedDedicatedCellToNeighbor(neighbor)>0){ + if (schedule_hasManagedTxCellToNeighbor(neighbor)){ sixtop_request( IANA_6TOP_CMD_CLEAR, // code neighbor, // neighbor @@ -269,8 +269,8 @@ void msf_trigger6pDelete(void){ return; } - if (schedule_getNumberOfDedicatedCells(&neighbor)<=1){ - // at least one dedicated cell presents + if (schedule_getNumberOfManagedTxCells(&neighbor)<=1){ + // at least one managed Tx cell presents return; } @@ -369,6 +369,11 @@ void msf_housekeeping(void){ return; } + if (schedule_getNumberOfManagedTxCells(&parentNeighbor)==0){ + msf_trigger6pAdd(); + return; + } + if (msf_vars.waitretry){ return; } diff --git a/openstack/02b-MAChigh/neighbors.c b/openstack/02b-MAChigh/neighbors.c index 7b16d49264..fb2ea20396 100644 --- a/openstack/02b-MAChigh/neighbors.c +++ b/openstack/02b-MAChigh/neighbors.c @@ -557,7 +557,7 @@ void neighbors_setPreferredParent(uint8_t index, bool isPreferred){ } else { // the neighbor is de-selected as parent // remove the autonomous cell to this neighbor - if (schedule_hasDedicatedCellToNeighbor(&(neighbors_vars.neighbors[index].addr_64b))){ + if (schedule_hasAutonomousTxCellToNeighbor(&(neighbors_vars.neighbors[index].addr_64b))){ schedule_removeActiveSlot( slotoffset, // slot offset &(neighbors_vars.neighbors[index].addr_64b) // neighbor @@ -627,7 +627,7 @@ void neighbors_removeOld(void) { icmpv6rpl_getPreferredParentEui64(&addressToWrite) == FALSE || ( icmpv6rpl_getPreferredParentEui64(&addressToWrite) && - schedule_hasDedicatedCellToNeighbor(&addressToWrite)== FALSE + schedule_hasAutonomousTxCellToNeighbor(&addressToWrite)== FALSE ) ) { return; @@ -749,6 +749,7 @@ void removeNeighbor(uint8_t neighborIndex) { neighbors_vars.neighbors[neighborIndex].parentPreference = 0; neighbors_vars.neighbors[neighborIndex].stableNeighbor = FALSE; neighbors_vars.neighbors[neighborIndex].switchStabilityCounter = 0; + neighbors_vars.neighbors[neighborIndex].addr_64b.type = ADDR_NONE; neighbors_vars.neighbors[neighborIndex].DAGrank = DEFAULTDAGRANK; neighbors_vars.neighbors[neighborIndex].rssi = 0; neighbors_vars.neighbors[neighborIndex].numRx = 0; @@ -761,7 +762,6 @@ void removeNeighbor(uint8_t neighborIndex) { neighbors_vars.neighbors[neighborIndex].sequenceNumber = 0; neighbors_vars.neighbors[neighborIndex].backoffExponenton = MINBE-1;; neighbors_vars.neighbors[neighborIndex].backoff = 0; - neighbors_vars.neighbors[neighborIndex].addr_64b.type = ADDR_NONE; } //=========================== helpers ========================================= diff --git a/openstack/02b-MAChigh/schedule.c b/openstack/02b-MAChigh/schedule.c index e0f098d9d8..2cdfc2aa8f 100644 --- a/openstack/02b-MAChigh/schedule.c +++ b/openstack/02b-MAChigh/schedule.c @@ -497,7 +497,7 @@ uint8_t schedule_getNumberOfFreeEntries(){ return counter; } -uint8_t schedule_getNumberOfDedicatedCells(open_addr_t* neighbor){ +uint8_t schedule_getNumberOfManagedTxCells(open_addr_t* neighbor){ uint8_t i; uint8_t counter; @@ -507,6 +507,8 @@ uint8_t schedule_getNumberOfDedicatedCells(open_addr_t* neighbor){ counter = 0; for(i=0;ishared; + + ENABLE_INTERRUPTS(); + + return returnVal; +} + /** \brief Get the neighbor associated wit the current schedule entry. diff --git a/openstack/02b-MAChigh/schedule.h b/openstack/02b-MAChigh/schedule.h index 4d274cac6b..8591c34b04 100644 --- a/openstack/02b-MAChigh/schedule.h +++ b/openstack/02b-MAChigh/schedule.h @@ -180,12 +180,11 @@ void schedule_removeAllCells( open_addr_t* previousHop ); uint8_t schedule_getNumberOfFreeEntries(void); -uint8_t schedule_getNumberOfDedicatedCells(open_addr_t* neighbor); +uint8_t schedule_getNumberOfManagedTxCells(open_addr_t* neighbor); bool schedule_isNumTxWrapped(open_addr_t* neighbor); bool schedule_getCellsToBeRelocated(open_addr_t* neighbor, cellInfo_ht* celllist); -bool schedule_hasDedicatedCellToNeighbor(open_addr_t* neighbor); -bool schedule_hasNonSharedDedicatedCellToNeighbor(open_addr_t* neighbor); -open_addr_t* schedule_getNonParentNeighborWithDedicatedCells(open_addr_t* neighbor); +bool schedule_hasAutonomousTxCellToNeighbor(open_addr_t* neighbor); +bool schedule_hasManagedTxCellToNeighbor(open_addr_t* neighbor); // from IEEE802154E void schedule_syncSlotOffset(slotOffset_t targetSlotOffset); @@ -193,6 +192,7 @@ void schedule_advanceSlot(void); slotOffset_t schedule_getNextActiveSlotOffset(void); frameLength_t schedule_getFrameLength(void); cellType_t schedule_getType(void); +bool schedule_getShared(void); void schedule_getNeighbor(open_addr_t* addrToWrite); channelOffset_t schedule_getChannelOffset(void); bool schedule_getOkToSend(void); diff --git a/openstack/02b-MAChigh/sixtop.c b/openstack/02b-MAChigh/sixtop.c index 462de3f0ad..8c2f082d50 100644 --- a/openstack/02b-MAChigh/sixtop.c +++ b/openstack/02b-MAChigh/sixtop.c @@ -362,7 +362,7 @@ owerror_t sixtop_send(OpenQueueEntry_t *msg) { icmpv6rpl_getPreferredParentEui64(&addressToWrite) == FALSE || ( icmpv6rpl_getPreferredParentEui64(&addressToWrite) && - schedule_hasDedicatedCellToNeighbor(&addressToWrite)== FALSE + schedule_hasAutonomousTxCellToNeighbor(&addressToWrite)== FALSE ) ) ) @@ -716,7 +716,7 @@ port_INLINE void sixtop_sendEB(void) { icmpv6rpl_getPreferredParentEui64(&addressToWrite) == FALSE || ( icmpv6rpl_getPreferredParentEui64(&addressToWrite) && - schedule_hasDedicatedCellToNeighbor(&addressToWrite) == FALSE + schedule_hasAutonomousTxCellToNeighbor(&addressToWrite) == FALSE ) ) ){ @@ -844,7 +844,7 @@ port_INLINE void sixtop_sendKA(void) { return; } - if (schedule_hasDedicatedCellToNeighbor(kaNeighAddr) == FALSE){ + if (schedule_hasAutonomousTxCellToNeighbor(kaNeighAddr) == FALSE){ // delete packets genereted by this module (EB and KA) from openqueue openqueue_removeAllCreatedBy(COMPONENT_SIXTOP); diff --git a/openstack/cross-layers/openqueue.c b/openstack/cross-layers/openqueue.c index 2235df7c82..a5d859d10b 100644 --- a/openstack/cross-layers/openqueue.c +++ b/openstack/cross-layers/openqueue.c @@ -290,7 +290,7 @@ OpenQueueEntry_t* openqueue_macGetDIOPacket(){ return NULL; } -OpenQueueEntry_t* openqueue_macGetDedicatedPacket(open_addr_t* toNeighbor){ +OpenQueueEntry_t* openqueue_macGetNonJoinIPv6Packet(open_addr_t* toNeighbor){ uint8_t i; uint8_t packet_index; INTERRUPT_DECLARATION(); @@ -304,11 +304,9 @@ OpenQueueEntry_t* openqueue_macGetDedicatedPacket(open_addr_t* toNeighbor){ ( toNeighbor->type==ADDR_64B && packetfunctions_sameAddress(toNeighbor,&openqueue_vars.queue[i].l2_nextORpreviousHop) - ) && // sixtop response with SEQNUM_ERR will fail on dedicated cell since schedule inconsistency. - ( - openqueue_vars.queue[i].creator != COMPONENT_SIXTOP_RES || - openqueue_vars.queue[i].l2_sixtop_returnCode != IANA_6TOP_RC_SEQNUM_ERR - ) + ) && + openqueue_vars.queue[i].creator >= COMPONENT_OPENBRIDGE && + openqueue_vars.queue[i].creator != COMPONENT_CJOIN ){ if (packet_index==QUEUELENGTH){ packet_index = i; @@ -329,6 +327,33 @@ OpenQueueEntry_t* openqueue_macGetDedicatedPacket(open_addr_t* toNeighbor){ } } +OpenQueueEntry_t* openqueue_macGet6PandJoinPacket(open_addr_t* toNeighbor){ + uint8_t i; + INTERRUPT_DECLARATION(); + DISABLE_INTERRUPTS(); + + // first to look the sixtop RES packet + for (i=0;itype==ADDR_64B && + packetfunctions_sameAddress(toNeighbor,&openqueue_vars.queue[i].l2_nextORpreviousHop) + ) && + ( + openqueue_vars.queue[i].creator == COMPONENT_SIXTOP_RES || + openqueue_vars.queue[i].creator == COMPONENT_CJOIN + ) + ){ + ENABLE_INTERRUPTS(); + return &openqueue_vars.queue[i]; + } + } + + ENABLE_INTERRUPTS(); + return NULL; +} + //=========================== private ========================================= diff --git a/openstack/cross-layers/openqueue.h b/openstack/cross-layers/openqueue.h index 5d6172ba2f..9696738d17 100644 --- a/openstack/cross-layers/openqueue.h +++ b/openstack/cross-layers/openqueue.h @@ -45,7 +45,8 @@ OpenQueueEntry_t* openqueue_sixtopGetReceivedPacket(void); OpenQueueEntry_t* openqueue_macGetDataPacket(open_addr_t* toNeighbor); OpenQueueEntry_t* openqueue_macGetEBPacket(void); OpenQueueEntry_t* openqueue_macGetDIOPacket(void); -OpenQueueEntry_t* openqueue_macGetDedicatedPacket(open_addr_t* toNeighbor); +OpenQueueEntry_t* openqueue_macGetNonJoinIPv6Packet(open_addr_t* toNeighbor); +OpenQueueEntry_t* openqueue_macGet6PandJoinPacket(open_addr_t* toNeighbor); /** \} \} diff --git a/projects/python/SConscript.env b/projects/python/SConscript.env index 1af860d8ec..40c5dac3b1 100644 --- a/projects/python/SConscript.env +++ b/projects/python/SConscript.env @@ -617,6 +617,7 @@ functionsToChange = [ 'schedule_getNextActiveSlotOffset', 'schedule_getFrameLength', 'schedule_getType', + 'schedule_getShared', 'schedule_getNeighbor', 'schedule_getChannelOffset', 'schedule_getOkToSend', @@ -625,10 +626,9 @@ functionsToChange = [ 'schedule_indicateTx', 'schedule_resetEntry', 'schedule_getNumberOfFreeEntries', - 'schedule_getNumberOfDedicatedCells', - 'schedule_getNonParentNeighborWithDedicatedCells', - 'schedule_hasDedicatedCellToNeighbor', - 'schedule_hasNonSharedDedicatedCellToNeighbor', + 'schedule_getNumberOfManagedTxCells', + 'schedule_hasAutonomousTxCellToNeighbor', + 'schedule_hasManagedTxCellToNeighbor', 'schedule_isNumTxWrapped', 'schedule_getCellsToBeRelocated', 'schedule_getOneCellAfterOffset', @@ -817,7 +817,8 @@ functionsToChange = [ 'openqueue_macGetEBPacket', 'openqueue_reset_entry', 'openqueue_macGetDIOPacket', - 'openqueue_macGetDedicatedPacket', + 'openqueue_macGetNonJoinIPv6Packet', + 'openqueue_macGet6PandJoinPacket', # openrandom 'openrandom_init', 'openrandom_get16b', From c08238b1f0988da77ae3fa6ecd8da78a1614629c Mon Sep 17 00:00:00 2001 From: changtengfei Date: Tue, 6 Nov 2018 21:54:25 +0100 Subject: [PATCH 11/20] FW-782. reserve downstream autonomous cell. --- openstack/02b-MAChigh/neighbors.c | 16 +++++++++++++++- openstack/02b-MAChigh/sixtop.c | 27 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/openstack/02b-MAChigh/neighbors.c b/openstack/02b-MAChigh/neighbors.c index fb2ea20396..5b55390178 100644 --- a/openstack/02b-MAChigh/neighbors.c +++ b/openstack/02b-MAChigh/neighbors.c @@ -745,11 +745,13 @@ bool isNeighbor(open_addr_t* neighbor) { } void removeNeighbor(uint8_t neighborIndex) { + + uint16_t moteId, slotoffset; + neighbors_vars.neighbors[neighborIndex].used = FALSE; neighbors_vars.neighbors[neighborIndex].parentPreference = 0; neighbors_vars.neighbors[neighborIndex].stableNeighbor = FALSE; neighbors_vars.neighbors[neighborIndex].switchStabilityCounter = 0; - neighbors_vars.neighbors[neighborIndex].addr_64b.type = ADDR_NONE; neighbors_vars.neighbors[neighborIndex].DAGrank = DEFAULTDAGRANK; neighbors_vars.neighbors[neighborIndex].rssi = 0; neighbors_vars.neighbors[neighborIndex].numRx = 0; @@ -762,6 +764,18 @@ void removeNeighbor(uint8_t neighborIndex) { neighbors_vars.neighbors[neighborIndex].sequenceNumber = 0; neighbors_vars.neighbors[neighborIndex].backoffExponenton = MINBE-1;; neighbors_vars.neighbors[neighborIndex].backoff = 0; + + if (schedule_hasAutonomousTxCellToNeighbor(&(neighbors_vars.neighbors[neighborIndex].addr_64b))){ + moteId = 256*neighbors_vars.neighbors[neighborIndex].addr_64b.addr_64b[6]+\ + neighbors_vars.neighbors[neighborIndex].addr_64b.addr_64b[7]; + slotoffset = msf_hashFunction_getSlotoffset(moteId); + schedule_removeActiveSlot( + slotoffset, // slot offset + &(neighbors_vars.neighbors[neighborIndex].addr_64b) // neighbor + ); + } + + neighbors_vars.neighbors[neighborIndex].addr_64b.type = ADDR_NONE; } //=========================== helpers ========================================= diff --git a/openstack/02b-MAChigh/sixtop.c b/openstack/02b-MAChigh/sixtop.c index 8c2f082d50..7badac3734 100644 --- a/openstack/02b-MAChigh/sixtop.c +++ b/openstack/02b-MAChigh/sixtop.c @@ -15,6 +15,7 @@ #include "IEEE802154_security.h" #include "idmanager.h" #include "schedule.h" +#include "msf.h" //=========================== define ========================================== @@ -351,6 +352,8 @@ owerror_t sixtop_request( owerror_t sixtop_send(OpenQueueEntry_t *msg) { + uint16_t slotoffset, moteId; + uint8_t channeloffset; open_addr_t addressToWrite; if ( @@ -370,6 +373,30 @@ owerror_t sixtop_send(OpenQueueEntry_t *msg) { return E_FAIL; } + if ( + idmanager_getIsDAGroot() == TRUE || + ( + idmanager_getIsDAGroot() == FALSE && + icmpv6rpl_getPreferredParentEui64(&addressToWrite) && + packetfunctions_sameAddress(&addressToWrite, &msg->l2_nextORpreviousHop)== FALSE + ) + ) { + if (schedule_hasAutonomousTxCellToNeighbor(&msg->l2_nextORpreviousHop)==FALSE){ + moteId = 256*msg->l2_nextORpreviousHop.addr_64b[6]+\ + msg->l2_nextORpreviousHop.addr_64b[7]; + slotoffset = msf_hashFunction_getSlotoffset(moteId); + channeloffset = msf_hashFunction_getChanneloffset(moteId); + schedule_addActiveSlot( + slotoffset, // slot offset + CELLTYPE_TX, // type of slot + TRUE, // shared? + channeloffset, // channel offset + &(msg->l2_nextORpreviousHop) // neighbor + ); + } + } + + // set metadata msg->owner = COMPONENT_SIXTOP; msg->l2_frameType = IEEE154_TYPE_DATA; From 9e637776d37b130aabdfa540aa9d64464457967d Mon Sep 17 00:00:00 2001 From: changtengfei Date: Wed, 7 Nov 2018 01:46:43 +0100 Subject: [PATCH 12/20] FW-782. update ka period and DESYNCTIMEOUT. --- openstack/02a-MAClow/IEEE802154E.c | 6 +++++- openstack/02a-MAClow/IEEE802154E.h | 4 ++-- openstack/02b-MAChigh/schedule.c | 1 + openstack/cross-layers/openqueue.c | 18 ++++++++++++++++++ openstack/cross-layers/openqueue.h | 1 + projects/python/SConscript.env | 1 + 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/openstack/02a-MAClow/IEEE802154E.c b/openstack/02a-MAClow/IEEE802154E.c index e518f1f984..574f798c2f 100644 --- a/openstack/02a-MAClow/IEEE802154E.c +++ b/openstack/02a-MAClow/IEEE802154E.c @@ -960,6 +960,10 @@ port_INLINE void activity_ti1ORri1(void) { // this is a managed Tx cell ieee154e_vars.dataToSend = openqueue_macGetNonJoinIPv6Packet(&neighbor); + if (ieee154e_vars.dataToSend == NULL){ + ieee154e_vars.dataToSend = openqueue_macGetKaPacket(&neighbor); + } + // update numcellpassed and numcellused on managed Tx cell if (ieee154e_vars.dataToSend!=NULL) { msf_updateCellsUsed(&neighbor); @@ -1930,7 +1934,7 @@ port_INLINE void activity_ri5(PORT_TIMER_WIDTH capturedTime) { icmpv6rpl_getPreferredParentEui64(&addressToWrite) == FALSE || ( icmpv6rpl_getPreferredParentEui64(&addressToWrite) && - schedule_hasAutonomousTxCellToNeighbor(&addressToWrite)== FALSE + schedule_hasManagedTxCellToNeighbor(&addressToWrite)== FALSE ) ) ) { diff --git a/openstack/02a-MAClow/IEEE802154E.h b/openstack/02a-MAClow/IEEE802154E.h index dc30ec6a77..bb92b0274f 100644 --- a/openstack/02a-MAClow/IEEE802154E.h +++ b/openstack/02a-MAClow/IEEE802154E.h @@ -42,8 +42,8 @@ static const uint8_t ebIEsBytestream[] = { #define TX_POWER 31 // 1=-25dBm, 31=0dBm (max value) #define RESYNCHRONIZATIONGUARD 5 // in 32kHz ticks. min distance to the end of the slot to successfully synchronize #define US_PER_TICK 30 // number of us per 32kHz clock tick -#define MAXKAPERIOD 1000 // in slots: 2000@15ms per slot -> ~30 seconds. Max value used by adaptive synchronization. -#define DESYNCTIMEOUT 2333 // in slots: 2333@15ms per slot -> ~35 seconds. A larger DESYNCTIMEOUT is needed if using a larger KATIMEOUT. +#define MAXKAPERIOD 1000 // in slots: 1500@20ms per slot -> ~30 seconds. Max value used by adaptive synchronization. +#define DESYNCTIMEOUT 1750 // in slots: 1750@20ms per slot -> ~35 seconds. A larger DESYNCTIMEOUT is needed if using a larger KATIMEOUT. #define LIMITLARGETIMECORRECTION 5 // threshold number of ticks to declare a timeCorrection "large" #define LENGTH_IEEE154_MAX 128 // max length of a valid radio packet #define DUTY_CYCLE_WINDOW_LIMIT (0xFFFFFFFF>>1) // limit of the dutycycle window diff --git a/openstack/02b-MAChigh/schedule.c b/openstack/02b-MAChigh/schedule.c index 2cdfc2aa8f..38e54a0608 100644 --- a/openstack/02b-MAChigh/schedule.c +++ b/openstack/02b-MAChigh/schedule.c @@ -627,6 +627,7 @@ bool schedule_hasManagedTxCellToNeighbor(open_addr_t* neighbor){ for(i=0;itype==ADDR_64B && + packetfunctions_sameAddress(toNeighbor,&openqueue_vars.queue[i].l2_nextORpreviousHop) + ) { + ENABLE_INTERRUPTS(); + return &openqueue_vars.queue[i]; + } + } + ENABLE_INTERRUPTS(); + return NULL; +} + OpenQueueEntry_t* openqueue_macGetDIOPacket(){ uint8_t i; INTERRUPT_DECLARATION(); diff --git a/openstack/cross-layers/openqueue.h b/openstack/cross-layers/openqueue.h index 9696738d17..ce49368662 100644 --- a/openstack/cross-layers/openqueue.h +++ b/openstack/cross-layers/openqueue.h @@ -44,6 +44,7 @@ OpenQueueEntry_t* openqueue_sixtopGetReceivedPacket(void); // called by IEEE80215E OpenQueueEntry_t* openqueue_macGetDataPacket(open_addr_t* toNeighbor); OpenQueueEntry_t* openqueue_macGetEBPacket(void); +OpenQueueEntry_t* openqueue_macGetKaPacket(open_addr_t* toNeighbor); OpenQueueEntry_t* openqueue_macGetDIOPacket(void); OpenQueueEntry_t* openqueue_macGetNonJoinIPv6Packet(open_addr_t* toNeighbor); OpenQueueEntry_t* openqueue_macGet6PandJoinPacket(open_addr_t* toNeighbor); diff --git a/projects/python/SConscript.env b/projects/python/SConscript.env index 40c5dac3b1..d64b12b2cc 100644 --- a/projects/python/SConscript.env +++ b/projects/python/SConscript.env @@ -815,6 +815,7 @@ functionsToChange = [ 'openqueue_sixtopGetReceivedPacket', 'openqueue_macGetDataPacket', 'openqueue_macGetEBPacket', + 'openqueue_macGetKaPacket', 'openqueue_reset_entry', 'openqueue_macGetDIOPacket', 'openqueue_macGetNonJoinIPv6Packet', From d820701bdf5f6437709516dec7626b1a761fcf85 Mon Sep 17 00:00:00 2001 From: changtengfei Date: Wed, 7 Nov 2018 13:18:33 +0100 Subject: [PATCH 13/20] FW-782. change retries to 3 and maxbe to 5. --- openstack/02a-MAClow/IEEE802154E.h | 2 +- openstack/02b-MAChigh/schedule.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/openstack/02a-MAClow/IEEE802154E.h b/openstack/02a-MAClow/IEEE802154E.h index bb92b0274f..9e224537eb 100644 --- a/openstack/02a-MAClow/IEEE802154E.h +++ b/openstack/02a-MAClow/IEEE802154E.h @@ -38,7 +38,7 @@ static const uint8_t ebIEsBytestream[] = { #define EB_IE_LEN 28 #define NUM_CHANNELS 16 // number of channels to channel hop on -#define TXRETRIES 7 // number of MAC retries before declaring failed +#define TXRETRIES 3 // number of MAC retries before declaring failed #define TX_POWER 31 // 1=-25dBm, 31=0dBm (max value) #define RESYNCHRONIZATIONGUARD 5 // in 32kHz ticks. min distance to the end of the slot to successfully synchronize #define US_PER_TICK 30 // number of us per 32kHz clock tick diff --git a/openstack/02b-MAChigh/schedule.h b/openstack/02b-MAChigh/schedule.h index 8591c34b04..a752efcba1 100644 --- a/openstack/02b-MAChigh/schedule.h +++ b/openstack/02b-MAChigh/schedule.h @@ -67,7 +67,7 @@ does not use any backoff mechanism when a transmission fails. See MINBE for an explanation of backoff. */ -#define MAXBE 8 // the standard compliant range of MAXBE is 3-8 +#define MAXBE 5 // the standard compliant range of MAXBE is 3-8 /** \brief a threshold used for triggering the maintaining process.uint: percent From 17b07ef0bb461657950a73dba771c6e0f53fc9d0 Mon Sep 17 00:00:00 2001 From: changtengfei Date: Wed, 7 Nov 2018 15:02:35 +0100 Subject: [PATCH 14/20] FW-782. don't send any packet before having a managed cell. --- openstack/02b-MAChigh/schedule.c | 2 +- openstack/03b-IPv6/icmpv6rpl.c | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/openstack/02b-MAChigh/schedule.c b/openstack/02b-MAChigh/schedule.c index 38e54a0608..eecf76af65 100644 --- a/openstack/02b-MAChigh/schedule.c +++ b/openstack/02b-MAChigh/schedule.c @@ -726,7 +726,7 @@ cellType_t schedule_getType(void) { \returns The isShared of the current schedule entry. */ bool schedule_getShared(void) { - cellType_t returnVal; + bool returnVal; INTERRUPT_DECLARATION(); DISABLE_INTERRUPTS(); diff --git a/openstack/03b-IPv6/icmpv6rpl.c b/openstack/03b-IPv6/icmpv6rpl.c index 64419c34cf..8f935cbf69 100644 --- a/openstack/03b-IPv6/icmpv6rpl.c +++ b/openstack/03b-IPv6/icmpv6rpl.c @@ -639,7 +639,11 @@ void icmpv6rpl_timer_DIO_task(void) { \brief Prepare and a send a RPL DIO. */ void sendDIO(void) { + OpenQueueEntry_t* msg; + open_addr_t addressToWrite; + + memset(&addressToWrite,0,sizeof(open_addr_t)); // stop if I'm not sync'ed if (ieee154e_isSynch()==FALSE) { @@ -660,6 +664,26 @@ void sendDIO(void) { return; } + if ( + idmanager_getIsDAGroot() == FALSE && + ( + icmpv6rpl_getPreferredParentEui64(&addressToWrite) == FALSE || + ( + icmpv6rpl_getPreferredParentEui64(&addressToWrite) && + schedule_hasManagedTxCellToNeighbor(&addressToWrite) == FALSE + ) + ) + ){ + // delete packets genereted by this module (EB and KA) from openqueue + openqueue_removeAllCreatedBy(COMPONENT_ICMPv6RPL); + + // I'm not busy sending a DIO/DAO + icmpv6rpl_vars.busySendingDIO = FALSE; + icmpv6rpl_vars.busySendingDAO = FALSE; + + return; + } + // do not send DIO if I'm already busy sending if (icmpv6rpl_vars.busySendingDIO==TRUE) { return; @@ -790,6 +814,8 @@ void sendDAO(void) { open_addr_t address; open_addr_t* prefix; + memset(&address,0,sizeof(open_addr_t)); + if (ieee154e_isSynch()==FALSE) { // I'm not sync'ed @@ -814,6 +840,25 @@ void sendDAO(void) { return; } + if ( + icmpv6rpl_getPreferredParentEui64(&address) == FALSE || + ( + icmpv6rpl_getPreferredParentEui64(&address) && + schedule_hasManagedTxCellToNeighbor(&address) == FALSE + ) + ){ + // delete packets genereted by this module (EB and KA) from openqueue + openqueue_removeAllCreatedBy(COMPONENT_ICMPv6RPL); + + // I'm not busy sending a DIO/DAO + icmpv6rpl_vars.busySendingDIO = FALSE; + icmpv6rpl_vars.busySendingDAO = FALSE; + + return; + } + + memset(&address,0,sizeof(open_addr_t)); + // dont' send a DAO if you're still busy sending the previous one if (icmpv6rpl_vars.busySendingDAO==TRUE) { return; From 7a587919da0ba8ae1a06ec3d1b0f8e3108621cd1 Mon Sep 17 00:00:00 2001 From: changtengfei Date: Wed, 7 Nov 2018 15:35:57 +0100 Subject: [PATCH 15/20] FW-782. EB can be transmitted to help other motes for synchronizing. --- openstack/02b-MAChigh/sixtop.c | 44 +--------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/openstack/02b-MAChigh/sixtop.c b/openstack/02b-MAChigh/sixtop.c index 7badac3734..ee0415c54b 100644 --- a/openstack/02b-MAChigh/sixtop.c +++ b/openstack/02b-MAChigh/sixtop.c @@ -373,28 +373,6 @@ owerror_t sixtop_send(OpenQueueEntry_t *msg) { return E_FAIL; } - if ( - idmanager_getIsDAGroot() == TRUE || - ( - idmanager_getIsDAGroot() == FALSE && - icmpv6rpl_getPreferredParentEui64(&addressToWrite) && - packetfunctions_sameAddress(&addressToWrite, &msg->l2_nextORpreviousHop)== FALSE - ) - ) { - if (schedule_hasAutonomousTxCellToNeighbor(&msg->l2_nextORpreviousHop)==FALSE){ - moteId = 256*msg->l2_nextORpreviousHop.addr_64b[6]+\ - msg->l2_nextORpreviousHop.addr_64b[7]; - slotoffset = msf_hashFunction_getSlotoffset(moteId); - channeloffset = msf_hashFunction_getChanneloffset(moteId); - schedule_addActiveSlot( - slotoffset, // slot offset - CELLTYPE_TX, // type of slot - TRUE, // shared? - channeloffset, // channel offset - &(msg->l2_nextORpreviousHop) // neighbor - ); - } - } // set metadata @@ -737,26 +715,6 @@ port_INLINE void sixtop_sendEB(void) { return; } - if ( - idmanager_getIsDAGroot() == FALSE && - ( - icmpv6rpl_getPreferredParentEui64(&addressToWrite) == FALSE || - ( - icmpv6rpl_getPreferredParentEui64(&addressToWrite) && - schedule_hasAutonomousTxCellToNeighbor(&addressToWrite) == FALSE - ) - ) - ){ - // delete packets genereted by this module (EB and KA) from openqueue - openqueue_removeAllCreatedBy(COMPONENT_SIXTOP); - - // I'm not busy sending an EB or KA - sixtop_vars.busySendingEB = FALSE; - sixtop_vars.busySendingKA = FALSE; - - return; - } - if (sixtop_vars.busySendingEB==TRUE) { // don't continue if I'm still sending a previous EB return; @@ -871,7 +829,7 @@ port_INLINE void sixtop_sendKA(void) { return; } - if (schedule_hasAutonomousTxCellToNeighbor(kaNeighAddr) == FALSE){ + if (schedule_hasManagedTxCellToNeighbor(kaNeighAddr) == FALSE){ // delete packets genereted by this module (EB and KA) from openqueue openqueue_removeAllCreatedBy(COMPONENT_SIXTOP); From eb87c9455b75b9922eba917ba7b1997016fe8948 Mon Sep 17 00:00:00 2001 From: changtengfei Date: Wed, 7 Nov 2018 21:07:52 +0100 Subject: [PATCH 16/20] FW-782. fix the way to get nexthop address. --- openstack/03b-IPv6/forwarding.c | 87 +++++++++++++++++---------------- 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/openstack/03b-IPv6/forwarding.c b/openstack/03b-IPv6/forwarding.c index b5b2c482c2..12c8512de9 100644 --- a/openstack/03b-IPv6/forwarding.c +++ b/openstack/03b-IPv6/forwarding.c @@ -285,7 +285,7 @@ void forwarding_receive( // take ownership msg->owner = COMPONENT_FORWARDING; - + // determine L4 protocol // get information from ipv6_header @@ -295,7 +295,7 @@ void forwarding_receive( // populate packets metadata with L3 information memcpy(&(msg->l3_destinationAdd),&ipv6_inner_header->dest, sizeof(open_addr_t)); memcpy(&(msg->l3_sourceAdd), &ipv6_inner_header->src, sizeof(open_addr_t)); - + if ( ( idmanager_isMyAddress(&(msg->l3_destinationAdd)) @@ -443,7 +443,6 @@ void forwarding_receive( */ void forwarding_getNextHop(open_addr_t* destination128b, open_addr_t* addressToWrite64b) { uint8_t i; - open_addr_t temp_prefix64btoWrite; if (packetfunctions_isBroadcastMulticast(destination128b)) { // IP destination is broadcast, send to 0xffffffffffffffff @@ -451,9 +450,6 @@ void forwarding_getNextHop(open_addr_t* destination128b, open_addr_t* addressToW for (i=0;i<8;i++) { addressToWrite64b->addr_64b[i] = 0xff; } - } else if (neighbors_isStableNeighbor(destination128b)) { - // IP destination is 1-hop neighbor, send directly - packetfunctions_ip128bToMac64b(destination128b,&temp_prefix64btoWrite,addressToWrite64b); } else { // destination is remote, send to preferred parent icmpv6rpl_getPreferredParentEui64(addressToWrite64b); @@ -472,47 +468,56 @@ void forwarding_getNextHop(open_addr_t* destination128b, open_addr_t* addressToW (PCKTSEND), or forwarded (PCKTFORWARD). */ owerror_t forwarding_send_internal_RoutingTable( - OpenQueueEntry_t* msg, - ipv6_header_iht* ipv6_outer_header, - ipv6_header_iht* ipv6_inner_header, - rpl_option_ht* rpl_option, + OpenQueueEntry_t* msg, + ipv6_header_iht* ipv6_outer_header, + ipv6_header_iht* ipv6_inner_header, + rpl_option_ht* rpl_option, #ifdef DEADLINE_OPTION_ENABLED - deadline_option_ht* deadline_option, + deadline_option_ht* deadline_option, #endif - uint32_t* flow_label, - uint8_t fw_SendOrfw_Rcv - ) { - - // retrieve the next hop from the routing table - forwarding_getNextHop(&(msg->l3_destinationAdd),&(msg->l2_nextORpreviousHop)); - if (msg->l2_nextORpreviousHop.type==ADDR_NONE) { - openserial_printError( - COMPONENT_FORWARDING, - ERR_NO_NEXTHOP, - (errorparameter_t)0, - (errorparameter_t)0 - ); - return E_FAIL; - } + uint32_t* flow_label, + uint8_t fw_SendOrfw_Rcv +) { - if (ipv6_outer_header->src.type != ADDR_NONE){ - packetfunctions_tossHeader(msg,ipv6_outer_header->header_length); - } + open_addr_t temp_prefix64btoWrite; - // send to next lower layer - return iphc_sendFromForwarding( - msg, - ipv6_outer_header, - ipv6_inner_header, - rpl_option, + // retrieve the next hop from the routing table + if (msg->creator==COMPONENT_CJOIN){ + if (neighbors_isStableNeighbor(&(msg->l3_destinationAdd))) { + // IP destination is 1-hop neighbor, send directly + packetfunctions_ip128bToMac64b(&(msg->l3_destinationAdd),&temp_prefix64btoWrite,&(msg->l2_nextORpreviousHop)); + } + } else { + forwarding_getNextHop(&(msg->l3_destinationAdd),&(msg->l2_nextORpreviousHop)); + } + if (msg->l2_nextORpreviousHop.type==ADDR_NONE) { + openserial_printError( + COMPONENT_FORWARDING, + ERR_NO_NEXTHOP, + (errorparameter_t)0, + (errorparameter_t)0 + ); + return E_FAIL; + } + + if (ipv6_outer_header->src.type != ADDR_NONE){ + packetfunctions_tossHeader(msg,ipv6_outer_header->header_length); + } + + // send to next lower layer + return iphc_sendFromForwarding( + msg, + ipv6_outer_header, + ipv6_inner_header, + rpl_option, #ifdef DEADLINE_OPTION_ENABLED - deadline_option, + deadline_option, #endif - flow_label, - NULL, // no rh3 - 0, - fw_SendOrfw_Rcv - ); + flow_label, + NULL, // no rh3 + 0, + fw_SendOrfw_Rcv + ); } /** From c758dc2f8cadd08604aed0fc2ba60c1728e8ee8c Mon Sep 17 00:00:00 2001 From: changtengfei Date: Wed, 7 Nov 2018 21:12:06 +0100 Subject: [PATCH 17/20] FW-782. use txrx autonomous unicast to neighbor(parent) and anycast for rx and downstream traffic. --- openstack/02a-MAClow/IEEE802154E.c | 30 ++++++--------- openstack/02b-MAChigh/msf.c | 9 ++++- openstack/02b-MAChigh/neighbors.c | 24 ++++++------ openstack/02b-MAChigh/schedule.c | 8 ++-- openstack/02b-MAChigh/sixtop.c | 2 +- openstack/cross-layers/openqueue.c | 60 +++++++++++++++--------------- openstack/cross-layers/openqueue.h | 2 +- projects/python/SConscript.env | 4 +- 8 files changed, 66 insertions(+), 73 deletions(-) diff --git a/openstack/02a-MAClow/IEEE802154E.c b/openstack/02a-MAClow/IEEE802154E.c index 574f798c2f..aaabc497cc 100644 --- a/openstack/02a-MAClow/IEEE802154E.c +++ b/openstack/02a-MAClow/IEEE802154E.c @@ -954,7 +954,7 @@ port_INLINE void activity_ti1ORri1(void) { if (packetfunctions_isBroadcastMulticast(&neighbor)==FALSE){ if (schedule_getShared()){ - // this is an autonomous Tx cell + // this is an autonomous TxRx cell (unicast) ieee154e_vars.dataToSend = openqueue_macGet6PandJoinPacket(&neighbor); } else { // this is a managed Tx cell @@ -971,25 +971,17 @@ port_INLINE void activity_ti1ORri1(void) { msf_updateCellsPassed(&neighbor); } } else { - // this is minimal cell - ieee154e_vars.dataToSend = openqueue_macGetDataPacket(&neighbor); - if ((ieee154e_vars.dataToSend==NULL) && (cellType==CELLTYPE_TXRX)) { - couldSendEB=TRUE; - // look for an EB packet in the queue - ieee154e_vars.dataToSend = openqueue_macGetEBPacket(); - } else { - // there is a packet to send - if ( - schedule_hasAutonomousTxCellToNeighbor(&ieee154e_vars.dataToSend->l2_nextORpreviousHop) - ) { - // leave the packet to be sent on autonomous Tx Cell cell and pick up a broadcast packet. - ieee154e_vars.dataToSend = openqueue_macGetDIOPacket(); - if (ieee154e_vars.dataToSend==NULL){ - couldSendEB=TRUE; - // look for an EB packet in the queue - ieee154e_vars.dataToSend = openqueue_macGetEBPacket(); - } + if (schedule_getShared()) { + // this is minimal cell + ieee154e_vars.dataToSend = openqueue_macGetDIOPacket(); + if (ieee154e_vars.dataToSend==NULL){ + couldSendEB=TRUE; + // look for an EB packet in the queue + ieee154e_vars.dataToSend = openqueue_macGetEBPacket(); } + } else { + // this is autonomous TXRX cell (anycast) + ieee154e_vars.dataToSend = openqueue_macGetDownStreamPacket(&neighbor); } } } diff --git a/openstack/02b-MAChigh/msf.c b/openstack/02b-MAChigh/msf.c index 7305be1cc9..9ecf487d9b 100644 --- a/openstack/02b-MAChigh/msf.c +++ b/openstack/02b-MAChigh/msf.c @@ -9,6 +9,7 @@ #include "idmanager.h" #include "icmpv6rpl.h" #include "IEEE802154E.h" +#include "openqueue.h" //=========================== definition ===================================== @@ -38,6 +39,8 @@ void msf_housekeeping(void); void msf_init(void) { + open_addr_t temp_neighbor; + memset(&msf_vars,0,sizeof(msf_vars_t)); msf_vars.numAppPacketsPerSlotFrame = 0; sixtop_setSFcallback( @@ -47,12 +50,14 @@ void msf_init(void) { (sixtop_sf_handle_callback)msf_handleRCError ); + memset(&temp_neighbor,0,sizeof(temp_neighbor)); + temp_neighbor.type = ADDR_ANYCAST; schedule_addActiveSlot( msf_hashFunction_getSlotoffset(256*idmanager_getMyID(ADDR_64B)->addr_64b[6]+idmanager_getMyID(ADDR_64B)->addr_64b[7]), // slot offset - CELLTYPE_RX, // type of slot + CELLTYPE_TXRX, // type of slot FALSE, // shared? msf_hashFunction_getChanneloffset(256*idmanager_getMyID(ADDR_64B)->addr_64b[6]+idmanager_getMyID(ADDR_64B)->addr_64b[7]), // channel offset - idmanager_getMyID(ADDR_64B) // neighbor + &temp_neighbor // neighbor ); msf_vars.housekeepingTimerId = opentimers_create(TIMER_GENERAL_PURPOSE); diff --git a/openstack/02b-MAChigh/neighbors.c b/openstack/02b-MAChigh/neighbors.c index 5b55390178..33d7be80aa 100644 --- a/openstack/02b-MAChigh/neighbors.c +++ b/openstack/02b-MAChigh/neighbors.c @@ -549,7 +549,7 @@ void neighbors_setPreferredParent(uint8_t index, bool isPreferred){ // reserve the autonomous cell to this neighbor schedule_addActiveSlot( slotoffset, // slot offset - CELLTYPE_TX, // type of slot + CELLTYPE_TXRX, // type of slot TRUE, // shared? channeloffset, // channel offset &(neighbors_vars.neighbors[index].addr_64b) // neighbor @@ -557,7 +557,7 @@ void neighbors_setPreferredParent(uint8_t index, bool isPreferred){ } else { // the neighbor is de-selected as parent // remove the autonomous cell to this neighbor - if (schedule_hasAutonomousTxCellToNeighbor(&(neighbors_vars.neighbors[index].addr_64b))){ + if (schedule_hasAutonomousTxRxCellUnicast(&(neighbors_vars.neighbors[index].addr_64b))){ schedule_removeActiveSlot( slotoffset, // slot offset &(neighbors_vars.neighbors[index].addr_64b) // neighbor @@ -627,7 +627,7 @@ void neighbors_removeOld(void) { icmpv6rpl_getPreferredParentEui64(&addressToWrite) == FALSE || ( icmpv6rpl_getPreferredParentEui64(&addressToWrite) && - schedule_hasAutonomousTxCellToNeighbor(&addressToWrite)== FALSE + schedule_hasAutonomousTxRxCellUnicast(&addressToWrite)== FALSE ) ) { return; @@ -638,19 +638,17 @@ void neighbors_removeOld(void) { if (neighbors_vars.neighbors[i].used==1) { timeSinceHeard = ieee154e_asnDiff(&neighbors_vars.neighbors[i].asn); if (timeSinceHeard>DESYNCTIMEOUT) { - msf_trigger6pClear(&neighbors_vars.neighbors[i].addr_64b); - haveParent = icmpv6rpl_getPreferredParentIndex(&j); - if (haveParent && (i==j)) { // this is our preferred parent, carefully! - icmpv6rpl_killPreferredParent(); - icmpv6rpl_updateMyDAGrankAndParentSelection(); - } - // keep the NORES neighbor in the table if ( neighbors_vars.neighbors[i].f6PNORES == FALSE && neighbors_vars.neighbors[i].inBlacklist == FALSE ){ removeNeighbor(i); } + haveParent = icmpv6rpl_getPreferredParentIndex(&j); + if (haveParent && (i==j)) { // this is our preferred parent, carefully! + icmpv6rpl_killPreferredParent(); + icmpv6rpl_updateMyDAGrankAndParentSelection(); + } } } } @@ -697,7 +695,7 @@ void registerNewNeighbor(open_addr_t* address, i=0; while(itype==ADDR_64B && packetfunctions_sameAddress(toNeighbor,&openqueue_vars.queue[i].l2_nextORpreviousHop) ) || toNeighbor->type==ADDR_ANYCAST - ) + ) && + openqueue_vars.queue[i].l2_sixtop_messageType == SIXTOP_CELL_RESPONSE ){ ENABLE_INTERRUPTS(); return &openqueue_vars.queue[i]; } } - if (toNeighbor->type==ADDR_64B) { - // a neighbor is specified, look for a packet unicast to that neigbhbor - for (i=0;itype==ADDR_ANYCAST) { - // anycast case: look for a packet which is either not created by RES - // or an KA (created by RES, but not broadcast) - for (i=0;itype==ADDR_64B) { + // a neighbor is specified, look for a packet unicast to that neigbhbor + for (i=0;itype==ADDR_ANYCAST) { + // anycast case: look for a packet which is either from openbridge or forwarding component by source routing (ToDo) + for (i=0;i Date: Wed, 7 Nov 2018 22:22:42 +0100 Subject: [PATCH 18/20] FW-782. configuration that works for opentestbed deployment. --- openstack/02b-MAChigh/neighbors.h | 10 +++++----- openstack/02b-MAChigh/schedule.h | 8 +++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/openstack/02b-MAChigh/neighbors.h b/openstack/02b-MAChigh/neighbors.h index afd35770ee..40bfd499e4 100644 --- a/openstack/02b-MAChigh/neighbors.h +++ b/openstack/02b-MAChigh/neighbors.h @@ -13,10 +13,10 @@ //=========================== define ========================================== #define MAXPREFERENCE 2 -#define BADNEIGHBORMAXRSSI -80 //dBm -#define GOODNEIGHBORMINRSSI -90 //dBm +#define BADNEIGHBORMAXRSSI -70 //dBm +#define GOODNEIGHBORMINRSSI -80 //dBm #define SWITCHSTABILITYTHRESHOLD 3 -#define DEFAULTLINKCOST 4 // this value has too be no greater than 6, when MAXEB is 4 and MAXRETRIES is 4 +#define DEFAULTLINKCOST 8 // this value has too be no greater than 6, when MAXEB is 4 and MAXRETRIES is 4 #define MINIMAL_NUM_TX 16 #define MAXDAGRANK 0xffff @@ -38,12 +38,12 @@ typedef struct { int8_t rssi; uint8_t parentPreference; dagrank_t DAGrank; - uint16_t asn; + uint16_t asn; } netDebugNeigborEntry_t; END_PACK //=========================== module variables ================================ - + typedef struct { neighborRow_t neighbors[MAXNUMNEIGHBORS]; dagrank_t myDAGrank; diff --git a/openstack/02b-MAChigh/schedule.h b/openstack/02b-MAChigh/schedule.h index a752efcba1..d8c81fd815 100644 --- a/openstack/02b-MAChigh/schedule.h +++ b/openstack/02b-MAChigh/schedule.h @@ -26,8 +26,6 @@ The superframe reappears over time and can be arbitrarily long. #define SCHEDULE_MINIMAL_6TISCH_DEFAULT_SLOTFRAME_HANDLE 0 //id of slotframe #define SCHEDULE_MINIMAL_6TISCH_DEFAULT_SLOTFRAME_NUMBER 1 //1 slotframe by default. -#define NUMSERIALRX 3 - /* NUMSLOTSOFF is the max number of cells that the mote can add into schedule, besides 6TISCH_ACTIVE_CELLS and NUMSERIALRX Cell. Initially those cells are @@ -39,7 +37,7 @@ The superframe reappears over time and can be arbitrarily long. for serial port to transmit data to dagroot. */ -#define NUMSLOTSOFF 10 +#define NUMSLOTSOFF 20 /** \brief Maximum number of active slots in a superframe. @@ -51,7 +49,7 @@ in that table; a slot is "active" when it is not of type CELLTYPE_OFF. Set this number to the exact number of active slots you are planning on having in your schedule, so not to waste RAM. */ -#define MAXACTIVESLOTS 11 +#define MAXACTIVESLOTS SCHEDULE_MINIMAL_6TISCH_ACTIVE_CELLS+NUMSLOTSOFF /** \brief Minimum backoff exponent. @@ -183,7 +181,7 @@ uint8_t schedule_getNumberOfFreeEntries(void); uint8_t schedule_getNumberOfManagedTxCells(open_addr_t* neighbor); bool schedule_isNumTxWrapped(open_addr_t* neighbor); bool schedule_getCellsToBeRelocated(open_addr_t* neighbor, cellInfo_ht* celllist); -bool schedule_hasAutonomousTxCellToNeighbor(open_addr_t* neighbor); +bool schedule_hasAutonomousTxRxCellUnicast(open_addr_t* neighbor); bool schedule_hasManagedTxCellToNeighbor(open_addr_t* neighbor); // from IEEE802154E From 451569015f3094d9b5cb9b3f18e32efbcfc982a5 Mon Sep 17 00:00:00 2001 From: changtengfei Date: Wed, 7 Nov 2018 22:33:36 +0100 Subject: [PATCH 19/20] FW-782. Fix the warning and macpong projects. --- openstack/02b-MAChigh/sixtop.c | 2 -- projects/common/03oos_macpong/03oos_macpong.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/openstack/02b-MAChigh/sixtop.c b/openstack/02b-MAChigh/sixtop.c index 4ef595d7fe..0af3d27999 100644 --- a/openstack/02b-MAChigh/sixtop.c +++ b/openstack/02b-MAChigh/sixtop.c @@ -352,8 +352,6 @@ owerror_t sixtop_request( owerror_t sixtop_send(OpenQueueEntry_t *msg) { - uint16_t slotoffset, moteId; - uint8_t channeloffset; open_addr_t addressToWrite; if ( diff --git a/projects/common/03oos_macpong/03oos_macpong.c b/projects/common/03oos_macpong/03oos_macpong.c index 4b74aabb16..10fcf7e201 100644 --- a/projects/common/03oos_macpong/03oos_macpong.c +++ b/projects/common/03oos_macpong/03oos_macpong.c @@ -67,7 +67,7 @@ void macpong_initSend(opentimers_id_t id) { } if (ieee154e_isSynch()==TRUE && neighbors_getNumNeighbors()==1) { neighbors_getNeighborEui64(&temp,ADDR_64B,0); - if (schedule_hasDedicatedCellToNeighbor(&temp)){ + if (schedule_hasManagedTxCellToNeighbor(&temp)){ if (timeToSend){ // send packet macpong_send(0); From f37b5fa632eeeb09d2eacacb5ef89c82bb09747c Mon Sep 17 00:00:00 2001 From: changtengfei Date: Wed, 7 Nov 2018 22:36:12 +0100 Subject: [PATCH 20/20] FW-782. update version number. --- inc/opendefs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/opendefs.h b/inc/opendefs.h index 69d4fd0a8f..f0d48745d4 100644 --- a/inc/opendefs.h +++ b/inc/opendefs.h @@ -21,8 +21,8 @@ static const uint8_t infoStackName[] = "OpenWSN "; #define OPENWSN_VERSION_MAJOR 1 -#define OPENWSN_VERSION_MINOR 21 -#define OPENWSN_VERSION_PATCH 4 +#define OPENWSN_VERSION_MINOR 22 +#define OPENWSN_VERSION_PATCH 0 #ifndef TRUE #define TRUE 1