diff --git a/bsp/boards/python/openwsnmodule.c b/bsp/boards/python/openwsnmodule.c index bdfb507f7f..8b3547a41e 100644 --- a/bsp/boards/python/openwsnmodule.c +++ b/bsp/boards/python/openwsnmodule.c @@ -62,6 +62,7 @@ static PyObject* OpenMote_getState(OpenMote* self) { PyObject* tcp_vars; PyObject* neighbors_vars; PyObject* sixtop_vars; + PyObject* sf0_vars; PyObject* schedule_vars; PyObject* schedule_dbg; PyObject* ieee154e_vars; @@ -135,6 +136,11 @@ static PyObject* OpenMote_getState(OpenMote* self) { // TODO PyDict_SetItemString(returnVal, "sixtop_vars", sixtop_vars); + // sf0_vars + sf0_vars = PyDict_New(); + // TODO + PyDict_SetItemString(returnVal, "sf0_vars", sf0_vars); + // schedule_vars schedule_vars = PyDict_New(); // TODO diff --git a/bsp/boards/python/openwsnmodule_obj.h b/bsp/boards/python/openwsnmodule_obj.h index eccfcb84ad..cd96f07c07 100644 --- a/bsp/boards/python/openwsnmodule_obj.h +++ b/bsp/boards/python/openwsnmodule_obj.h @@ -20,6 +20,7 @@ #include "neighbors_obj.h" #include "processIE_obj.h" #include "sixtop_obj.h" +#include "sf0_obj.h" #include "schedule_obj.h" #include "icmpv6echo_obj.h" #include "icmpv6rpl_obj.h" @@ -222,6 +223,7 @@ struct OpenMote { sixtop_vars_t sixtop_vars; neighbors_vars_t neighbors_vars; schedule_vars_t schedule_vars; + sf0_vars_t sf0_vars; // l2a adaptive_sync_vars_t adaptive_sync_vars; ieee802154_security_vars_t ieee802154_security_vars; diff --git a/drivers/common/openserial.c b/drivers/common/openserial.c index 4df6216aa4..22794a9730 100644 --- a/drivers/common/openserial.c +++ b/drivers/common/openserial.c @@ -20,6 +20,7 @@ #include "openhdlc.h" #include "schedule.h" #include "icmpv6rpl.h" +#include "sf0.h" //=========================== variables ======================================= @@ -580,7 +581,7 @@ void openserial_goldenImageCommands(void){ break; } - sixtop_setHandler(SIX_HANDLER_OTF); + sixtop_setHandler(SIX_HANDLER_SF0); if ( ( commandId != COMMAND_SET_6P_ADD && @@ -620,6 +621,9 @@ void openserial_goldenImageCommands(void){ } } break; + case COMMAND_SET_SF0BANDWIDTH: + sf0_setSelfBandwidth(comandParam_8); + break; default: // wrong command ID break; diff --git a/drivers/common/openserial.h b/drivers/common/openserial.h index 9aaf5ce14e..54baab928c 100644 --- a/drivers/common/openserial.h +++ b/drivers/common/openserial.h @@ -76,7 +76,8 @@ enum { COMMAND_SET_6P_CLEAR = 13, COMMAND_SET_SLOTDURATION = 14, COMMAND_SET_6PRESPONSE_STATUS = 15, - COMMAND_MAX = 16, + COMMAND_SET_SF0BANDWIDTH = 16, + COMMAND_MAX = 17, }; //=========================== module variables ================================ diff --git a/kernel/scheduler.h b/kernel/scheduler.h index 7b7896a72f..9652d13446 100644 --- a/kernel/scheduler.h +++ b/kernel/scheduler.h @@ -23,7 +23,7 @@ typedef enum { TASKPRIO_TCP_TIMEOUT = 0x05, TASKPRIO_COAP = 0x06, TASKPRIO_ADAPTIVE_SYNC = 0x07, - TASKPRIO_OTF = 0x08, + TASKPRIO_SF0 = 0x08, // tasks trigger by other interrupts TASKPRIO_BUTTON = 0x09, TASKPRIO_SIXTOP_TIMEOUT = 0x0a, diff --git a/openapps/SConscript b/openapps/SConscript index efc2314836..1d7853e94c 100644 --- a/openapps/SConscript +++ b/openapps/SConscript @@ -32,6 +32,7 @@ defaultAppsInit = [ 'techo', 'uecho', 'rrt', + 'uinject', ] # additional apps the user wants to build diff --git a/openapps/c6t/c6t.c b/openapps/c6t/c6t.c index a65e01d5a1..f9c12e1040 100644 --- a/openapps/c6t/c6t.c +++ b/openapps/c6t/c6t.c @@ -89,7 +89,7 @@ owerror_t c6t_receive( break; } - sixtop_setHandler(SIX_HANDLER_OTF); + sixtop_setHandler(SIX_HANDLER_SF0); // call sixtop sixtop_request( IANA_6TOP_CMD_ADD, @@ -118,7 +118,7 @@ owerror_t c6t_receive( break; } - sixtop_setHandler(SIX_HANDLER_OTF); + sixtop_setHandler(SIX_HANDLER_SF0); // call sixtop sixtop_request( IANA_6TOP_CMD_DELETE, diff --git a/openapps/openapps.c b/openapps/openapps.c index d802900c5a..b1553b3327 100644 --- a/openapps/openapps.c +++ b/openapps/openapps.c @@ -40,6 +40,5 @@ void openapps_init(void) { // TCP techo_init(); // UDP - uecho_init(); - //uinject_init(); -} +// uecho_init(); +} \ No newline at end of file diff --git a/openapps/uinject/uinject.c b/openapps/uinject/uinject.c index c708dde43b..cb6d5bf653 100644 --- a/openapps/uinject/uinject.c +++ b/openapps/uinject/uinject.c @@ -9,6 +9,9 @@ #include "IEEE802154E.h" #include "idmanager.h" +#ifdef GOLDEN_IMAGE_ROOT +#define SLOTDURATION 10 // ms +#endif //=========================== variables ======================================= uinject_vars_t uinject_vars; @@ -30,9 +33,11 @@ void uinject_init() { // clear local variables memset(&uinject_vars,0,sizeof(uinject_vars_t)); + uinject_vars.period = UINJECT_PERIOD_MS; + // start periodic timer uinject_vars.timerId = opentimers_start( - UINJECT_PERIOD_MS, + uinject_vars.period, TIMER_PERIODIC,TIME_MS, uinject_timer_cb ); diff --git a/openapps/uinject/uinject.h b/openapps/uinject/uinject.h index cf30d04b60..f5772d90b9 100644 --- a/openapps/uinject/uinject.h +++ b/openapps/uinject/uinject.h @@ -21,6 +21,7 @@ typedef struct { opentimer_id_t timerId; ///< periodic timer which triggers transmission uint16_t counter; ///< incrementing counter which is written into the packet + uint16_t period; ///< uinject packet sending period> } uinject_vars_t; //=========================== prototypes ====================================== @@ -28,7 +29,6 @@ typedef struct { void uinject_init(void); void uinject_sendDone(OpenQueueEntry_t* msg, owerror_t error); void uinject_receive(OpenQueueEntry_t* msg); - /** \} \} diff --git a/openstack/02b-MAChigh/otf.c b/openstack/02b-MAChigh/otf.c deleted file mode 100644 index 5ca1934730..0000000000 --- a/openstack/02b-MAChigh/otf.c +++ /dev/null @@ -1,65 +0,0 @@ -#include "opendefs.h" -#include "otf.h" -#include "neighbors.h" -#include "sixtop.h" -#include "scheduler.h" - -//=========================== variables ======================================= - -//=========================== prototypes ====================================== - -void otf_addCell_task(void); -void otf_removeCell_task(void); - -//=========================== public ========================================== - -void otf_init(void) { -} - -void otf_notif_addedCell(void) { - scheduler_push_task(otf_addCell_task,TASKPRIO_OTF); -} - -void otf_notif_removedCell(void) { - scheduler_push_task(otf_removeCell_task,TASKPRIO_OTF); -} - -//=========================== private ========================================= - -void otf_addCell_task(void) { - open_addr_t neighbor; - bool foundNeighbor; - - // get preferred parent - foundNeighbor = neighbors_getPreferredParentEui64(&neighbor); - if (foundNeighbor==FALSE) { - return; - } - - sixtop_setHandler(SIX_HANDLER_OTF); - // call sixtop - sixtop_request( - IANA_6TOP_CMD_ADD, - &neighbor, - 1 - ); -} - -void otf_removeCell_task(void) { - open_addr_t neighbor; - bool foundNeighbor; - - // get preferred parent - foundNeighbor = neighbors_getPreferredParentEui64(&neighbor); - if (foundNeighbor==FALSE) { - return; - } - - sixtop_setHandler(SIX_HANDLER_OTF); - // call sixtop - sixtop_request( - IANA_6TOP_CMD_DELETE, - &neighbor, - 1 - ); -} \ No newline at end of file diff --git a/openstack/02b-MAChigh/otf.dox b/openstack/02b-MAChigh/otf.dox deleted file mode 100644 index 48c37b70ac..0000000000 --- a/openstack/02b-MAChigh/otf.dox +++ /dev/null @@ -1,10 +0,0 @@ -/** -\defgroup otf otf - -\brief Implementation of 6TiSCH On-the-Fly Scheduling. - -6top is defined in the following draft: -- http://tools.ietf.org/id/draft-dujovne-6tisch-on-the-fly-03.txt - -\author Thomas Watteyne , July 2014. -*/ \ No newline at end of file diff --git a/openstack/02b-MAChigh/schedule.c b/openstack/02b-MAChigh/schedule.c index d6555a1227..963953bc93 100644 --- a/openstack/02b-MAChigh/schedule.c +++ b/openstack/02b-MAChigh/schedule.c @@ -5,6 +5,7 @@ #include "packetfunctions.h" #include "sixtop.h" #include "idmanager.h" +#include "sf0.h" //=========================== variables ======================================= @@ -534,6 +535,28 @@ scheduleEntry_t* schedule_getCurrentScheduleEntry(){ return schedule_vars.currentScheduleEntry; } +//=== from otf +uint8_t schedule_getNumOfSlotsByType(cellType_t type){ + uint8_t returnVal; + scheduleEntry_t* scheduleWalker; + + INTERRUPT_DECLARATION(); + DISABLE_INTERRUPTS(); + + returnVal = 0; + scheduleWalker = schedule_vars.currentScheduleEntry; + do { + if(type == scheduleWalker->type){ + returnVal += 1; + } + scheduleWalker = scheduleWalker->next; + }while(scheduleWalker!=schedule_vars.currentScheduleEntry); + + ENABLE_INTERRUPTS(); + + return returnVal; +} + //=== from IEEE802154E: reading the schedule and updating statistics void schedule_syncSlotOffset(slotOffset_t targetSlotOffset) { @@ -555,7 +578,13 @@ void schedule_advanceSlot() { INTERRUPT_DECLARATION(); DISABLE_INTERRUPTS(); - +#ifdef GOLDEN_IMAGE_ROOT + if (schedule_vars.currentScheduleEntry->slotOffset >= ((scheduleEntry_t*)schedule_vars.currentScheduleEntry->next)->slotOffset + ) { + // one slotframe has elapsed + sf0_notifyNewSlotframe(); + } +#endif schedule_vars.currentScheduleEntry = schedule_vars.currentScheduleEntry->next; ENABLE_INTERRUPTS(); diff --git a/openstack/02b-MAChigh/schedule.h b/openstack/02b-MAChigh/schedule.h index bbf00727cd..5cca67c4af 100644 --- a/openstack/02b-MAChigh/schedule.h +++ b/openstack/02b-MAChigh/schedule.h @@ -17,7 +17,7 @@ The superframe repears over time and can be arbitrarly long. */ -#define SLOTFRAME_LENGTH 11 //should be 101 +#define SLOTFRAME_LENGTH 101 //should be 101 //draft-ietf-6tisch-minimal-06 #define SCHEDULE_MINIMAL_6TISCH_ACTIVE_CELLS 1 @@ -39,7 +39,7 @@ The superframe repears over time and can be arbitrarly long. for seiral port to tranmit data to dagroot. */ -#define NUMSLOTSOFF 3 +#define NUMSLOTSOFF 5 /** \brief Maximum number of active slots in a superframe. @@ -185,6 +185,7 @@ void schedule_removeAllCells( open_addr_t* previousHop ); scheduleEntry_t* schedule_getCurrentScheduleEntry(void); +uint8_t schedule_getNumOfSlotsByType(cellType_t type); // from IEEE802154E void schedule_syncSlotOffset(slotOffset_t targetSlotOffset); diff --git a/openstack/02b-MAChigh/sf0.c b/openstack/02b-MAChigh/sf0.c new file mode 100644 index 0000000000..2fef5ce5e5 --- /dev/null +++ b/openstack/02b-MAChigh/sf0.c @@ -0,0 +1,150 @@ +#include "opendefs.h" +#include "sf0.h" +#include "neighbors.h" +#include "sixtop.h" +#include "scheduler.h" +#include "schedule.h" +#include "idmanager.h" +#include "openapps.h" + +//=========================== definition ===================================== + +#define SF0THRESHOLD 2 + +//=========================== variables ======================================= + +sf0_vars_t sf0_vars; + +//=========================== prototypes ====================================== + +void sf0_addCell_task(void); +void sf0_removeCell_task(void); +void sf0_bandwidthEstimate_task(void); + +//=========================== public ========================================== + +void sf0_init(void) { + memset(&sf0_vars,0,sizeof(sf0_vars_t)); + sf0_vars.app_bandwidth = 0; // number of packet being sent per slotframe +} + +void sf0_notif_addedCell(void) { + scheduler_push_task(sf0_addCell_task,TASKPRIO_SF0); +} + +void sf0_notif_removedCell(void) { + scheduler_push_task(sf0_removeCell_task,TASKPRIO_SF0); +} + +// this function is called once per slotframe. +void sf0_notifyNewSlotframe(void) { + scheduler_push_task(sf0_bandwidthEstimate_task,TASKPRIO_SF0); +} + +//=========================== private ========================================= + +void sf0_addCell_task(void) { + open_addr_t neighbor; + bool foundNeighbor; + + // get preferred parent + foundNeighbor = neighbors_getPreferredParentEui64(&neighbor); + if (foundNeighbor==FALSE) { + return; + } + + sixtop_setHandler(SIX_HANDLER_SF0); + // call sixtop + sixtop_request( + IANA_6TOP_CMD_ADD, + &neighbor, + 1 + ); +} + +void sf0_removeCell_task(void) { + open_addr_t neighbor; + bool foundNeighbor; + + // get preferred parent + foundNeighbor = neighbors_getPreferredParentEui64(&neighbor); + if (foundNeighbor==FALSE) { + return; + } + + sixtop_setHandler(SIX_HANDLER_SF0); + // call sixtop + sixtop_request( + IANA_6TOP_CMD_DELETE, + &neighbor, + 1 + ); +} + +void sf0_bandwidthEstimate_task(void){ + open_addr_t neighbor; + bool foundNeighbor; + + int8_t bw_outgoing; + int8_t bw_incoming; + int8_t bw_self; + + // do not reserve cell proactively if I was dagroot + if (idmanager_getIsDAGroot()){ + return; + } + + // get preferred parent + foundNeighbor = neighbors_getPreferredParentEui64(&neighbor); + if (foundNeighbor==FALSE) { + return; + } + + sixtop_setHandler(SIX_HANDLER_SF0); + + // get bandwidth of outgoing, incoming and self. + // Here we just calcuate the estimated bandwidth for + // the application sending on dedicate cells(TX or Rx). + bw_outgoing = schedule_getNumOfSlotsByType(CELLTYPE_TX); + bw_incoming = schedule_getNumOfSlotsByType(CELLTYPE_RX); + /* + get self required bandwith, you can design your + application and assign bw_self accordingly. + for example: + bw_self = application_getBandwdith(app_name); + By default, it's set to zero. + */ +// bw_self = openapps_getBandwidth(COMPONENT_UINJECT); + bw_self = sf0_vars.app_bandwidth; + + // In SF0, scheduledCells = bw_outgoing + // requiredCells = bw_incoming + bw_self + + // when scheduledCells, July 2014. +*/ \ No newline at end of file diff --git a/openstack/02b-MAChigh/otf.h b/openstack/02b-MAChigh/sf0.h similarity index 53% rename from openstack/02b-MAChigh/otf.h rename to openstack/02b-MAChigh/sf0.h index f96ccd4a0b..e3dbd10884 100644 --- a/openstack/02b-MAChigh/otf.h +++ b/openstack/02b-MAChigh/sf0.h @@ -1,10 +1,10 @@ -#ifndef __OTF_H -#define __OTF_H +#ifndef __SF0_H +#define __SF0_H /** \addtogroup MAChigh \{ -\addtogroup otf +\addtogroup sf0 \{ */ @@ -14,16 +14,22 @@ //=========================== typedef ========================================= +typedef struct { + uint8_t app_bandwidth; +} sf0_vars_t; + //=========================== module variables ================================ //=========================== prototypes ====================================== // admin -void otf_init(void); +void sf0_init(void); // notification from sixtop -void otf_notif_addedCell(void); -void otf_notif_removedCell(void); - +void sf0_notif_addedCell(void); +void sf0_notif_removedCell(void); +// notification from schedule +void sf0_notifyNewSlotframe(void); +void sf0_setSelfBandwidth(uint8_t numPacketPerSlotframe); /** \} \} diff --git a/openstack/02b-MAChigh/sixtop.c b/openstack/02b-MAChigh/sixtop.c index 997f3e7f6e..f569b300df 100644 --- a/openstack/02b-MAChigh/sixtop.c +++ b/openstack/02b-MAChigh/sixtop.c @@ -5,7 +5,7 @@ #include "neighbors.h" #include "IEEE802154E.h" #include "iphc.h" -#include "otf.h" +#include "sf0.h" #include "packetfunctions.h" #include "openrandom.h" #include "scheduler.h" @@ -114,6 +114,7 @@ void sixtop_init() { sixtop_vars.kaPeriod = MAXKAPERIOD; sixtop_vars.ebPeriod = EBPERIOD; sixtop_vars.isResponseEnabled = TRUE; + sixtop_vars.handler = SIX_HANDLER_NONE; sixtop_vars.maintenanceTimerId = opentimers_start( sixtop_vars.periodMaintenance, @@ -1329,7 +1330,7 @@ bool sixtop_candidateAddCellList( } } - if (numCandCells $PROJ_DIR$\..\..\..\openstack\02b-MAChigh\neighbors.h - - $PROJ_DIR$\..\..\..\openstack\02b-MAChigh\otf.c - - - $PROJ_DIR$\..\..\..\openstack\02b-MAChigh\otf.h - $PROJ_DIR$\..\..\..\openstack\02b-MAChigh\processIE.c @@ -2514,6 +2508,12 @@ $PROJ_DIR$\..\..\..\openstack\02b-MAChigh\schedule.h + + $PROJ_DIR$\..\..\..\openstack\02b-MAChigh\sf0.c + + + $PROJ_DIR$\..\..\..\openstack\02b-MAChigh\sf0.h + $PROJ_DIR$\..\..\..\openstack\02b-MAChigh\sixtop.c diff --git a/projects/common/03oos_sniffer/03oos_sniffer.c b/projects/common/03oos_sniffer/03oos_sniffer.c index 426df7dca1..58cc9bb7c4 100644 --- a/projects/common/03oos_sniffer/03oos_sniffer.c +++ b/projects/common/03oos_sniffer/03oos_sniffer.c @@ -15,6 +15,7 @@ #include "sixtop.h" #include "processIE.h" #include "neighbors.h" +#include "sf0.h" //=========================== defines ========================================= @@ -181,6 +182,7 @@ void ieee154e_getAsn(uint8_t* array) {return;} void neighbors_updateMyDAGrankAndNeighborPreference(void) {return;} bool neighbors_getPreferredParentEui64(open_addr_t* neighbor){return TRUE;} void schedule_startDAGroot(void) {return;} +void sf0_setSelfBandwidth(uint8_t numPacketPerSlotFrame){return;} bool debugPrint_asn(void) {return TRUE;} bool debugPrint_isSync(void) {return TRUE;} diff --git a/projects/python/SConscript.env b/projects/python/SConscript.env index 0563d34cef..9906eb98f7 100644 --- a/projects/python/SConscript.env +++ b/projects/python/SConscript.env @@ -581,12 +581,16 @@ functionsToChange = [ 'schedule_indicateRx', 'schedule_indicateTx', 'schedule_resetEntry', - # otf - 'otf_init', - 'otf_notif_addedCell', - 'otf_notif_removedCell', - 'otf_addCell_task', - 'otf_removeCell_task', + 'schedule_getNumOfSlotsByType', + # sf0 + 'sf0_init', + 'sf0_notif_addedCell', + 'sf0_notif_removedCell', + 'sf0_addCell_task', + 'sf0_removeCell_task', + 'sf0_bandwidthEstimate_task', + 'sf0_notifyNewSlotframe', + 'sf0_setSelfBandwidth', # sixtop 'sixtop_init', 'sixtop_setKaPeriod', @@ -849,7 +853,7 @@ headerFiles = [ 'processIE', 'schedule', 'sixtop', - 'otf', + 'sf0', # 02.5-MPLS # TODO # 03a-IPHC