Files
kunlun/plc/cvg/rt/inc/cvg_rt_internal.h
2024-09-28 14:24:04 +08:00

1014 lines
38 KiB
C
Executable File

/****************************************************************************
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
be copied by any method or incorporated into another program without
the express written consent of Aerospace C.Power. This Information or any portion
thereof remains the property of Aerospace C.Power. The Information contained herein
is believed to be accurate and Aerospace C.Power assumes no responsibility or
liability for its use in any way and conveys no license or title under
any patent or copyright and makes no representation or warranty that this
Information is free from patent or copyright infringement.
****************************************************************************/
#ifndef CVG_RT_INTERNAL_H
#define CVG_RT_INTERNAL_H
/* os shim includes */
#include "os_types.h"
#include "os_timer.h"
/* common includes */
#include "iot_pkt_api.h"
#include "iot_config.h"
/* public api includes */
#include "plc_utils.h"
#include "plc_protocol.h"
#include "plc_fr.h"
#include "mac_bcm_api.h"
#include "plc_mme_heart_beat.h"
/* cvg module internal includes */
#include "cvg.h"
#include "cvg_bitmap.h"
#ifdef __cplusplus
extern "C" {
#endif
/* route entry array index to tei conversion */
#define CVG_RT_IDX_TO_TEI(__rt_idx) ((tei_t)((__rt_idx) + PLC_TEI_FIRST))
/* tei to route entry array index conversion */
#define CVG_RT_TEI_TO_IDX(__tei) ((__tei) - PLC_TEI_FIRST)
/* for our own device, route period left time is always count down from start
* of the route period to end of the route period. route period left time won't
* be 0 anyway. for HS device, route period left time will be set to 0 in the
* last several beacon periods and the first several beacon periods of each
* route period. this value define how many beacon periods we have to set
* route period left time to 0 in the start and end of each route period to
* resolve IOP issue with HS.
*
* note that for the first route period of route period increased case, HS will
* reuse left route period and discovery node list send interval of previous
* route period which is smaller. although it's not a good idea to set left
* route period to 0 for the first several beacon periods of the route period
* for such case, HS do so.
*
* for the first route period of route period decreased case, HS will reuse
* left route period and discovery node list send interval of previous route
* period which is larger. although it's not a good idea to set left route
* period to 0 for the first several beacon periods of the route period for
* such case, HS do so.
*
* note that ES device has similar behavior except that discovery node list
* send interval of previous route period won't be used.
*
* unit is 1 beacon period.
*/
#define CVG_RT_RP_MARK_0_DUR 2
/* this value define how many beacon periods we have to stop send discovery
* node list mme in the start and end of each route period to make sure route
* period is aligned and traffic success ratio calculation is accurate.
* unit is 1 beacon period.
*/
#define CVG_RT_RP_GUARD_DUR (CVG_RT_RP_MARK_0_DUR)
/* number of discover node list mme should be sent in each route period.
* according to smart grid spec, discover period is same as route period.
* if use beacon for channel evaluation disallowed, this value will be doubled.
*/
#define CVG_DIS_MME_PER_PERIOD 10
/* define supported maximum hops for dynamic route recovery support.
* set this value carefully to avoid broadcast packet flooding.
*/
#define CVG_RT_MAX_RECOVER_HOP 3
/* define supported maximum route recovery process initiated by local device
* in parallel
*/
#define CVG_RT_MAX_RECOVER_REQ 2
/* define supported maximum route recovery process forwarded by local device
* in parallel
*/
#define CVG_RT_MAX_RECOVER_FWD 4
/* define supported maximum route recovery process responded by local device
* in parallel
*/
#define CVG_RT_MAX_RECOVER_RSP 4
/* define supported maximum next hop candidate while sending route response
* back
*/
#define CVG_RT_MAX_RECOVER_CANDIDATE 10
/* define local device initiated route recovery request life time.
* total time include:
* 1. route recovery request broadcast to destination
* 2. destination spend CVG_RT_RECOVER_CAND_COLLECT_DUR +
* CVG_RT_RECOVER_LINK_CONF_DUR time for candidate selection.
* 3. each hop of route recovery response forwarder requires
* CVG_RT_RECOVER_LINK_CONF_DUR time for candidate selection.
* unit is 1 beacon period.
*/
#define CVG_RT_RECOVER_REQ_LIFE_TIME 10
/* define local device spend how much time to wait for route recovery response
* before clean up pending route recovery request. this value must be larger
* than CVG_RT_RECOVER_CAND_COLLECT_DUR + CVG_RT_RECOVER_LINK_CONF_DUR because
* final destination requires that long time to collect enough info.
* in addition, each hop requires CVG_RT_RECOVER_LINK_CONF_DUR time to select
* next hop while forwarding route recovery response back.
* unit is 1 beacon period.
*/
#define CVG_RT_RECOVER_FWD_WAIT_RSP_DUR 10
/* define local device spend how much time to collect candidate before send
* link confirm response. unit is 1 beacon period.
*/
#define CVG_RT_RECOVER_CAND_COLLECT_DUR 2
/* define local device spend how much time to wait for link confirm response
* before send route recovery response back. unit is 1 beacon period.
*/
#define CVG_RT_RECOVER_LINK_CONF_DUR 2
/* define local device spend how much time to wait for route recovery ack
* before clean up pending route recovery request. this value should be larger
* enough as each hop requires CVG_RT_RECOVER_LINK_CONF_DUR to select next hop
* while forwarding route recovery response back.
* unit is 1 beacon period.
*/
#define CVG_RT_RECOVER_ACK_DUR 10
/* define when to trigger the link confirm request for local device targeted
* route recovery request. when a local device targeted recovery request life
* time reach this value, local device will trigger link confirm request to
* identify the right way to send route recovery response back.
* unit is 1 beacon period.
*/
#define CVG_RT_RECOVER_RSP_CONF_TIME 3
/* route period timer state */
#define CVG_RT_RP_S_STOP 0 /* timer stopped */
#define CVG_RT_RP_S_START_PARTIAL 1 /* run in partial route period */
#define CVG_RT_RP_S_START_FULL 2 /* run in full route period */
/* routing entry definitions */
#define CVG_RT_ENT_F_D (0x01) /* down link direction */
#define CVG_RT_ENT_F_S (0x02) /* same level */
#define CVG_RT_ENT_F_U (0x03) /* up link direction */
/* below flags are only available for up link direction case */
#define CVG_RT_ENT_F_U_ERR (0x01) /* error */
#define CVG_RT_ENT_F_U_SL (0x02) /* same level */
#define CVG_RT_ENT_F_U_UL (0x03) /* upper level */
#define CVG_RT_ENT_F_U_MP (0x04) /* main proxy */
#define CVG_RT_ENT_F_U_UUL (0x05) /* upper upper level */
/* define route recovery forwarding sta state */
/* invalid state */
#define CVG_RT_RECOVER_FWD_S_INVAL 0
/* route recovery request has been forwarded and waiting for route
* recovery response.
*/
#define CVG_RT_RECOVER_FWD_S_FWD_REQ 1
/* route recovery response received and link confirm request has been
* sent. waiting for link confirm response.
*/
#define CVG_RT_RECOVER_FWD_S_SEND_LINK_CNF 2
/* link confirm response received and route recovery response has been
* fowarded. waiting for route recovery ack.
*/
#define CVG_RT_RECOVER_FWD_S_FWD_RSP 3
/* define route recovery targeting sta state */
/* invalid state */
#define CVG_RT_RECOVER_RSP_S_INVAL 0
/* route recovery request has been received and waiting for enough time
* to collect link confirm request candidate.
*/
#define CVG_RT_RECOVER_RSP_S_RECV_REQ 1
/* link confirm request has been sent and waiting for link confirm response. */
#define CVG_RT_RECOVER_RSP_S_SEND_LINK_CNF 2
/* link confirm response received and route recovery response has been sent.
* waiting for route recovery ack.
*/
#define CVG_RT_RECOVER_RSP_S_SEND_RSP 3
/* define the rank from which the cco/pco role candidate start to take higher
* priority this value must be equal or smaller than CANDIDATE_PROXY_COUNT.
*/
#define CVG_RT_STA_PROXY_WEIGHT_RANK 3
/* if traffice success ratio with cco/pco role candidate is euqal or higher
* than this value, skip CVG_RT_STA_PROXY_WEIGHT_RANK check while choose
* candidate proxy.
*/
#define CVG_RT_STA_PROXY_TF_SR_RANK 65
/* after associated with a network, sta device should at least collect how
* many consecutive route periods before start to roam. uint is 1 route period.
*/
#define CVG_RT_STA_ROAM_LEARNING_CNT 2
/* peer reachable inactive count threshold. if peer inactive count larger than
* this value, always treat the remote peer as unreachable.
*/
#define CVG_RT_REACHABLE_INACTIVE_TH 2
/* peer selected as candidate pco inactive count threshold. if peer inactive
* count larger than this value, always treat the remote peer as bad candidate
* proxy.
*/
#define CVG_RT_CAND_PCO_INACTIVE_TH 4
/* define proxy roaming gap. if the new proxy is better enough than current
* proxy, then roaming to the new proxy.
* new_proxy_score > (cur_proxy_score + roaming_gap)
* the smaller the gap, the easier to roaming to a better proxy.
*/
#if HW_PLATFORM == HW_PLATFORM_SIMU
#define CVG_RT_STA_ROAMING_GAP_H 29
#define CVG_RT_STA_ROAMING_GAP_L 14
#else
#define CVG_RT_STA_ROAMING_GAP_H 39
#define CVG_RT_STA_ROAMING_GAP_L 24
#endif
/* if traffic success ratio with proxy lower than this value, local device will
* start to use CVG_RT_STA_ROAMING_GAP_L while selecting candidate pco.
* otherwise, CVG_RT_STA_ROAMING_GAP_H will be used.
*/
#define CVG_RT_STA_PROXY_GOOD_TF_SR_TH 9
/* if traffic success ratio with cco higher than this value, local device will
* start to use CVG_RT_CCO_PHASE_GAP_OTHER while selecting logical phase.
* otherwise, CVG_RT_CCO_PHASE_GAP_OWN_H or CVG_RT_CCO_PHASE_GAP_OWN_L will be
* used.
*/
#define CVG_RT_CCO_PHASE_CHECK_TF_SR_TH 70
/* define level 1 device switch phase gap. if the new phase is better enough
* than current phase, then switch to the new phase.
* new_phase_score > (cur_phase_score + phase_gap)
* the smaller the gap, the easier to switch the phase.
*/
#if HW_PLATFORM == HW_PLATFORM_SIMU
#define CVG_RT_CCO_PHASE_GAP_OTHER 0
#else
#define CVG_RT_CCO_PHASE_GAP_OTHER 5
#endif
#define CVG_RT_CCO_PHASE_GAP_OWN_H (CVG_RT_CCO_PHASE_GAP_OTHER + 10)
#define CVG_RT_CCO_PHASE_GAP_OWN_L (CVG_RT_CCO_PHASE_GAP_OTHER + 5)
/* define 1 level corresponding to how many score while calculating path
* score. for (level - base_level) <= CVG_RT_LEVEL_HIGH_TH, CVG_RT_LEVEL_SCORE_L
* will take effect. Otherwise, CVG_RT_LEVEL_SCORE_H will take effect. The
* purpose is to try to minimize the topo tree depth while giving enough
* flexibility for candidate pco selection.
*/
#define CVG_RT_LEVEL_HIGH_TH 1
#if HW_PLATFORM == HW_PLATFORM_SIMU
#define CVG_RT_LEVEL_SCORE_H 16
#define CVG_RT_LEVEL_SCORE_L 16
#else
#define CVG_RT_LEVEL_SCORE_H 36
#define CVG_RT_LEVEL_SCORE_L 16
#endif
/* define if level 1 sta has good traffic success ratio with cco to not
* try to roam to other pco.
*/
#define CVG_RT_STA_CCO_GOOD_TF_SR_TH 30
#define CVG_RT_STA_CCO_GOOD_TX_SR_TH 50
#define CVG_RT_STA_CCO_GOOD_RX_SR_TH 50
/* define if level 2 - 15 sta has good traffic success ratio with main proxy
* path to not try to roam to other pco with equal or higher level.
*/
#define CVG_RT_STA_PCO_GOOD_TF_SR_TH 40
#define CVG_RT_STA_PCO_GOOD_TX_SR_TH 60
#define CVG_RT_STA_PCO_GOOD_RX_SR_TH 60
/* define good cand proxy rx snr threshold */
#define CVG_RT_STA_PCO_GOOD_RX_SNR_TH -5
/* define if level 2 - 15 sta has good traffic success ratio with main proxy
* path to try to clamber to lower level pco which has even slower score
* compared with current pco.
*/
#define CVG_RT_STA_CLAMBER_TF_SR_TH 60
/* define good clamber target threshold */
#define CVG_RT_STA_CLAMBER_TARGET_TF_SR_TH 50
/* if hplc traffic success ratio with unknown link peer better than this value,
* local device will use CVG_RT_STA_UNKNOWN_LINK_GAP_H. otherwise,
* CVG_RT_STA_UNKNOWN_LINK_GAP_L will used.
*/
#define CVG_RT_STA_UNKNOWN_LINK_TF_SR_L_TH 40
/* if hplc traffic success ratio with unknown link peer better than this value,
* local device will directly select hplc link.
*/
#define CVG_RT_STA_UNKNOWN_LINK_TF_SR_H_TH 70
/* define evaluate unknown link gap.
* rf_score > (hplc_score + unknown_link_gap)
*/
#define CVG_RT_STA_UNKNOWN_LINK_GAP_H 39
#define CVG_RT_STA_UNKNOWN_LINK_GAP_L 24
/* define 1 rf hop corresponding to how many score while calculating path
* score. for rf_hop <= CVG_RT_RF_HOP_HIGH_TH, CVG_RT_RF_HOP_SCORE_L
* will take effect. otherwise, CVG_RT_RF_HOP_SCORE_H will take effect. The
* purpose is to try to minimize the topo tree depth while giving enough
* flexibility for candidate pco selection.
*/
#define CVG_RT_RF_HOP_HIGH_TH 1
#define CVG_RT_RF_HOP_SCORE_H 144
#define CVG_RT_RF_HOP_SCORE_L 32
/* define sta proxy comparison method.
* single link proxy mode, select the best one of the two links as the
* communication link. dual link proxy mode, both links will be used as the
* communication link.
*/
#define CVG_RT_STA_PCO_CMP_MODE_SINGLE 0
#define CVG_RT_STA_PCO_CMP_MODE_DOUBLE 1
/* if rf traffice success ratio with cco/pco role candidate is euqal or higher
* than this value, skip CVG_RT_STA_PROXY_WEIGHT_RANK check while choose
* candidate proxy.
*/
#define CVG_RT_RF_STA_PROXY_TF_SR_RANK 65
/* peer selected as candidate pco inactive count threshold. if peer rf inactive
* count larger than this value, always treat the remote peer as bad candidate
* proxy.
*/
#define CVG_RT_RF_CAND_PCO_INACTIVE_TH 8
/* define rf proxy roaming gap. if the new proxy is better enough than current
* proxy, then roaming to the new proxy.
* new_proxy_score > (cur_proxy_score + roaming_gap)
* the smaller the gap, the easier to roaming to a better proxy.
*/
#if HW_PLATFORM == HW_PLATFORM_SIMU
#define CVG_RT_RF_STA_ROAMING_GAP_H 29
#define CVG_RT_RF_STA_ROAMING_GAP_L 14
#else
#define CVG_RT_RF_STA_ROAMING_GAP_H 39
#define CVG_RT_RF_STA_ROAMING_GAP_L 24
#endif
/* if rf traffic success ratio with proxy lower than this value, local device will
* start to use CVG_RT_RF_STA_ROAMING_GAP_L while selecting candidate pco.
* otherwise, CVG_RT_RF_STA_ROAMING_GAP_H will be used.
*/
#define CVG_RT_RF_STA_PROXY_GOOD_TF_SR_TH 9
/* define if level 1 sta has good rf traffic success ratio with cco to not
* try to roam to other pco.
*/
#define CVG_RT_RF_STA_CCO_GOOD_TF_SR_TH 30
#define CVG_RT_RF_STA_CCO_GOOD_TX_SR_TH 50
#define CVG_RT_RF_STA_CCO_GOOD_RX_SR_TH 50
/* define if level 2 - 15 sta has good rf traffic success ratio with main proxy
* path to not try to roam to other pco with equal or higher level.
*/
#define CVG_RT_RF_STA_PCO_GOOD_TF_SR_TH 40
#define CVG_RT_RF_STA_PCO_GOOD_TX_SR_TH 60
#define CVG_RT_RF_STA_PCO_GOOD_RX_SR_TH 60
/* define if level 2 - 15 sta has good rf traffic success ratio with main proxy
* path to try to clamber to lower level pco which has even slower score
* compared with current pco.
*/
#define CVG_RT_RF_STA_CLAMBER_TF_SR_TH 60
/* define rf good clamber target threshold */
#define CVG_RT_RF_STA_CLAMBER_TARGET_TF_SR_TH 50
/* peer rf reachable inactive count threshold. if peer inactive count larger
* than this value, always treat the remote peer as unreachable.
*/
#define CVG_RT_RF_REACHABLE_INACTIVE_TH 2
#if PLC_SUPPORT_CCO_ROLE == 0
#pragma pack(push)
#pragma pack(1)
#endif
/* routing table entry */
typedef struct _cvg_rt_ent {
/* path serial number for the target */
uint32_t path_sn;
/* tei of next hop to reach the target */
uint32_t next_hop :12,
/* tei of next hop backup to reach the target. this is generated
* through route recovery process only.
*/
next_hop_backup :12,
/* link direction flag, see CVG_RT_ENT_F_XXX */
dir_flag :2,
/* up link type flag, see CVG_RT_ENT_F_U_XXX */
up_flag :3,
/* next hop link type, see PLC_LINK_TYPE_XXX */
link :2,
/* reserved for future */
rsvd :1;
} cvg_rt_ent_t;
#if PLC_SUPPORT_CCO_ROLE == 0
#pragma pack(pop)
#endif
/* route recovery request */
typedef struct _cvg_rt_recover_req {
/* route request sequence number */
uint32_t req_sn;
/* life count, the unit is 1 beacon period */
uint8_t life_cnt;
/* tei of the request destination */
tei_t dest_tei;
/* packet that trigger the route request */
iot_pkt_t *pkt;
} cvg_rt_recover_req_t;
typedef struct _cvg_rt_recover_candidate {
/* tei of the candidate */
tei_t sta;
/* flag to mark if link confirm response received from the candidate */
uint8_t link_cnf_rsp :1,
/* flag to mark if received path_opt_flag is true from the candidate */
path_opt_flag :1,
/* reserved for future */
rsvd :6;
/* traffic success ratio with the candidate */
uint8_t tf_sr;
/* rx snr from the candidate */
int8_t rx_snr;
/* tx snr to the candidate */
int8_t tx_snr;
} cvg_rt_recover_candidate_t;
/* route recovery forwarding status */
typedef struct _cvg_rt_recover_fwd {
/* route request sequence number */
uint32_t req_sn;
/* route recovery request initiator */
tei_t init_tei;
/* current route recovery process state. see CVG_RT_RECOVER_FWD_S_XXX */
uint8_t state;
/* life count of forwarded request in current state. when state changed,
* the value will be reset to 0. the unit is 1 beacon period.
*/
uint8_t life_cnt;
/* available next hop count */
uint8_t next_hop_cnt;
/* packet that trigger the route response */
iot_pkt_t *rsp_pkt;
/* next hop candidate list for route reponse candidate, the smaller the
* index, the better the candidate.
*/
cvg_rt_recover_candidate_t next_hop[CVG_RT_MAX_RECOVER_CANDIDATE];
} cvg_rt_recover_fwd_t;
/* route recovery responding status */
typedef struct _cvg_rt_recover_rsp {
/* route request sequence number */
uint32_t req_sn;
/* route recovery request initiator */
tei_t init_tei;
/* current route recovery process state. see CVG_RT_RECOVER_RSP_S_XXX */
uint8_t state;
/* life count, the unit is 1 beacon period */
uint8_t life_cnt;
/* available next hop count */
uint8_t next_hop_cnt;
/* next hop candidate list for route reponse candidate, the smaller the
* index, the better the candidate.
*/
cvg_rt_recover_candidate_t next_hop[CVG_RT_MAX_RECOVER_CANDIDATE];
} cvg_rt_recover_rsp_t;
/* the common route threshold data used for select better proxy */
typedef struct _cvg_rt_th_comm_data {
/* define sta proxy traffic success ratio threshold */
uint8_t sta_proxy_good_tf_sr_th;
/* define proxy roaming gap. if the new proxy is better enough than current
* proxy, then roaming to the new proxy.
* new_proxy_score > (cur_proxy_score + roaming_gap)
* the smaller the gap, the easier to roaming to a better proxy.
* if traffic success ratio with proxy lower than sta_proxy_good_tf_sr_th,
* local device will start to use sta_roaming_gap_l while selecting
* candidate pco. otherwise, sta_roaming_gap_h will be used.
*/
uint8_t sta_roaming_gap_h;
uint8_t sta_roaming_gap_l;
/* see CVG_RT_STA_CCO_GOOD_XXX */
uint8_t cco_good_tf_sr_th;
uint8_t cco_good_tx_sr_th;
uint8_t cco_good_rx_sr_th;
/* see CVG_RT_STA_PCO_GOOD_XXX */
uint8_t pco_good_tf_sr_th;
uint8_t pco_good_tx_sr_th;
uint8_t pco_good_rx_sr_th;
/* see CVG_RT_STA_CLAMBER_TF_SR_TH */
uint8_t clamber_tf_sr_th;
/* see CVG_RT_STA_CLAMBER_TARGET_TF_SR_TH */
uint8_t clamber_target_tf_sr_th;
/* see CVG_RT_STA_PROXY_TF_SR_RANK */
uint8_t proxy_tf_sr_rank;
} cvg_rt_th_comm_data_t;
/* the rf route threshold data used for select better proxy */
typedef struct _cvg_rt_th_data {
/* hplc route threshold data */
cvg_rt_th_comm_data_t hplc;
/* rf route threshold data */
cvg_rt_th_comm_data_t rf;
/* define the rank from which the cco/pco role candidate start to take
* higher priority, this value must be equal or smaller than
* CANDIDATE_PROXY_COUNT.
*/
uint8_t sta_proxy_weight_rank :4,
/* for (level - base_level) <= level_score_high_th, level_score_l
* will take effect. Otherwise, level_score_h will take effect. The
* purpose is to try to minimize the topo tree depth while giving enough
* flexibility for candidate pco selection.
*/
level_score_h_th :4;
/* define cco phase traffic success ratio threshold */
uint8_t cco_phase_check_tf_sr_th;
/* define level 1 device switch phase gap. if the new phase is better enough
* than current phase, then switch to the new phase.
* new_phase_score > (cur_phase_score + phase_gap)
* the smaller the gap, the easier to switch the phase.
* if traffic success ratio with cco higher than cco_phase_check_tf_sr_th,
* local device will start to use cco_phase_gap_other while selecting
* logical phase. if traffic success ratio with cco lower than
* sta_proxy_good_tf_sr_th, use cco_phase_gap_own_l, otherwise
* cco_phase_gap_own_h will be used.
*/
uint8_t cco_phase_gap_own_h;
uint8_t cco_phase_gap_own_l;
uint8_t cco_phase_gap_other;
/* define 1 level corresponding to how many score while calculating path
* score.
*/
uint8_t level_score_h;
uint8_t level_score_l;
/* see CVG_RT_STA_ROAM_LEARNING_CNT */
uint8_t roam_learn_cnt;
/* for rf_hop <= hop_score_h_th, hop_score_l
* will take effect. Otherwise, rf_hop_score_h will take effect. The
* purpose is to try to minimize the topo tree depth while giving enough
* flexibility for candidate pco selection.
*/
uint8_t rf_hop_score_h_th;
/* see CVG_RT_RF_HOP_SCORE_XXX */
uint8_t rf_hop_score_h;
uint8_t rf_hop_score_l;
/* proxy compare method, see CVG_RT_STA_PCO_CMP_MODE_XXX */
uint8_t proxy_cmp_mode;
} cvg_rt_th_data_t;
/* per sta role vdev route module descriptor */
typedef struct _cvg_rt_vdev_sta {
/* gathered heart beat info */
cvg_tei_map_t gather_hb_info;
/* route parameter from cco without any modification */
mac_bc_rt_param_t rp;
/* biggest left route period delta in current route period. unit is 1s */
int32_t left_period_delta;
/* tei of the first STA sending heart beat mme */
tei_t first_hb_sta_tei;
/* tei of the STA discover most STAs */
tei_t max_disc_sta_tei;
/* number of STA discovered by max_dis_sta_tei */
uint16_t max_disc_sta_cnt;
/* route period resync count sync last route period done */
uint8_t rp_resync_cnt;
/* traffic success ratio reporting period is
* PLC_TF_SR_PERIOD_LIMIT(4) route periods.
* increase this count every route period
* and fire tf_sr_report_timeout when it reaches limitation.
*/
uint8_t route_period_cnt;
/* allowed to cco traffic success ratio. if local device found an route
* to cco with traffic success ratio equal or higher than this value,
* then the next hop of this route is a good candidate PCO for local device.
*/
uint8_t allowed_cco_tf_sr;
/* flag to mark if mme discovery node list use smaller payload */
uint8_t dis_node_list_small : 1,
/* reserved for future */
rsvd : 7;
/* proxy route to cco
* the better the candidate, the lower the array index.
*/
cvg_rt_ent_t proxy[CANDIDATE_PROXY_COUNT];
/* best route to cco
* the better the candidate, the lower the array index.
*/
cvg_rt_ent_t best_route[CANDIDATE_PROXY_COUNT];
/* local device initiated route recovery request */
cvg_rt_recover_req_t recover_req[CVG_RT_MAX_RECOVER_REQ];
/* local device forwarded route recovery request */
cvg_rt_recover_fwd_t recover_fwd[CVG_RT_MAX_RECOVER_FWD];
/* route recovery request which is searching local device */
cvg_rt_recover_rsp_t recover_rsp[CVG_RT_MAX_RECOVER_RSP];
/* initiated route recovery count */
uint32_t rc_req_cnt;
/* initiated route recovery success count */
uint32_t rc_req_ok_cnt;
/* initiated route recovery drop count */
uint32_t rc_req_drop_cnt;
/* forwarded route recovery count */
uint32_t rc_fwd_cnt;
/* responded route recovery count */
uint32_t rc_rsp_cnt;
/* account for pkt allocation failure for heart beat mme tx */
uint32_t no_msdu_hb_cnt;
/* the route threshold data */
cvg_rt_th_data_t th_data;
} cvg_rt_vdev_sta_t;
/* per cco role vdev route module descriptor */
typedef struct _cvg_rt_vdev_cco {
/* flag to mark if new route period started from next beacon period */
uint8_t new_rp;
/* route parameter of next route period */
mac_bc_rt_param_t next_rp;
} cvg_rt_vdev_cco_t;
/* per rf vdev route module descriptor */
typedef struct _cvg_rt_vdev_rf {
/* flag to mark if rf discovery node list mme tx requird */
uint8_t rf_dis_node_tx_req :1,
/* flag to mark if rf route period parameter updated */
rf_rp_updated :1,
/* rf tf_sr calculation period count, see CVG_RT_RF_SR_CALC_DUR */
rf_calc_cnt :3,
/* flag to mark if rf route period need be handled */
rf_rp_handled :1,
/* reserved for future */
rsvd :2;
/* rf discover list sequence number, value is 0 - 255 */
uint8_t rf_dis_seq;
/* rf route parameter */
mac_bc_rf_route_t rf_rp;
/* rf discover node mme sent timer interval. unit is 1ms */
uint32_t rf_dis_node_interval;
/* length of the rf discover node mme template. include both reserved head
* room and data room.
*/
uint32_t rf_dis_node_temp_len;
/* rf discover period count */
uint32_t rf_dis_period_cnt;
/* rf discover node mme template */
iot_pkt_t *rf_dis_node_temp;
/* rf discover node mme timer */
timer_id_t rf_dis_node_timer;
} cvg_rt_vdev_rf_t;
/* per vdev route module descriptor */
typedef struct _cvg_rt_vdev {
/* pointer of cvg vdev */
cvg_vdev_t *vdev;
/* route parameter */
mac_bc_rt_param_t rp;
/* route parameter for beacon update place holder */
union {
mac_bc_rt_param_t rp_sg;
mac_bc_rt_param_spg_t rp_spg;
} rp_tmp;
/* current route period start time, the reference clock is local time
* since boot up.
*/
uint64_t rp_start_time;
/* route period timer status. see CVG_RT_RP_STATE_XXX */
uint8_t rp_state;
/* flag to mark if discovery node list mme tx requird */
uint8_t dis_node_tx_req :1,
/* flag to mark if current network cco support 3 phase traffic success
* ratio calculation.
*/
cco_3_phase_tf_sr :1,
/* reserved for future */
rsvd :6;
/* discover node mme sent in last discover period */
uint8_t dis_node_prev_cnt;
/* beacon sent in last discover period */
uint8_t bc_tx_prev_cnt;
/* discover node mme sent in current discover period */
uint8_t dis_node_curr_cnt;
/* beacon sent in current discover period */
uint8_t bc_tx_curr_cnt;
/* max number of discover node mme allowed in current route period */
uint8_t dis_node_max_cnt;
/* discover node mme sent timer interval. unit is 1ms */
uint32_t dis_node_interval;
/* discover node mme timer */
timer_id_t dis_node_timer;
/* discover node mme template */
iot_pkt_t *dis_node_temp;
/* length of the discover node mme template. include both reserved head
* room and data room.
*/
uint32_t dis_node_temp_len;
/* route period timer */
timer_id_t route_timer;
/* partial route period timer. we may split route period into multiple
* piece to increase the abnormal status detection accuracy.
*/
timer_id_t rp_partial_timer;
/* define interval of each partial route period timer. unit is 1ms. */
uint32_t rp_partial_dur;
/* define how many partial rp left for current route period */
uint8_t rp_partial_left;
/* flag to mark if route period parameter updated */
uint8_t rp_updated :1,
/* flag to mark if route period need be handled */
rp_handled :1,
/* reserved for future */
rsvd1 :6;
/* number of unreachable direct peer in last route period.
* for cco role device, only level 1 sta are calculated.
* for sta role device, all directly seen sta are calculated.
*/
uint16_t unreachable_d_peer_cnt;
/* number of all directly seen peer in last route period.
* for cco role device, only level 1 sta are calculated.
* for sta role device, all directly seen sta are calculated.
*/
uint16_t d_peer_cnt;
/* account for pkt allocation failure for discovery node list mme tx */
uint32_t no_msdu_dis_cnt;
/* statistics for next hop check */
uint32_t next_hop_req_cnt;
uint32_t next_hop_main_cnt;
uint32_t next_hop_best_rt_cnt;
uint32_t next_hop_cand_rt_cnt;
uint32_t next_hop_backup_cnt;
uint32_t next_hop_fail_cnt;
/* route table */
cvg_rt_ent_t table[PLC_TEI_MAX_NUM];
/* per rf vdev route data structure */
cvg_rt_vdev_rf_t *rf_rt;
/* per vdev type data structure */
union {
cvg_rt_vdev_sta_t sta;
cvg_rt_vdev_cco_t cco;
} desc;
} cvg_rt_vdev_t;
#if PLC_SUPPORT_CCO_ROLE
#if HPLC_RF_SUPPORT
/*
* cvg_rt_reset_cco_rf_vdev() - rf rt cco vdev reset function
* @rt: rt vdev pointer
* @cfg: pointer of vdev configuration
*/
void cvg_rt_reset_cco_rf_vdev(cvg_rt_vdev_t *rt, cvg_vdev_cfg_t *cfg);
#else /* HPLC_RF_SUPPORT */
#define cvg_rt_reset_cco_rf_vdev(rt, cfg)
#endif /* HPLC_RF_SUPPORT */
/*
* cvg_rt_reset_cco_vdev() - rt cco vdev reset function
* @rt: rt vdev pointer
* @cfg: pointer of vdev configuration
*/
void cvg_rt_reset_cco_vdev(cvg_rt_vdev_t *rt, cvg_vdev_cfg_t *cfg);
/*
* cvg_rt_init_cco_vdev() - rt cco vdev init function
* @rt: rt vdev pointer
* @cfg: pointer of vdev configuration
*
* return:
* 0 -- for success case
* otherwise -- error code
*/
uint32_t cvg_rt_init_cco_vdev(cvg_rt_vdev_t *rt, cvg_vdev_cfg_t *cfg);
/*
* cvg_rt_deinit_cco_vdev() - rt cco vdev deinit function
* @rt: rt vdev pointer
*/
void cvg_rt_deinit_cco_vdev(cvg_rt_vdev_t *rt);
/*
* @brief cvg_rt_cco_heart_beat_rx() - rt cco vdev heart beat rx handling
* function
* @param vdev: cvg vdev pointer
* @param bm: bitmap containing discovered STAs
* @param bm_size: bitmap size in byte
*/
void cvg_rt_cco_heart_beat_rx(cvg_vdev_t *vdev, uint8_t *bm, uint16_t bm_size);
#else /* PLC_SUPPORT_CCO_ROLE */
#define cvg_rt_reset_cco_vdev(rt, cfg)
#define cvg_rt_init_cco_vdev(rt, cfg) (ERR_NOSUPP)
#define cvg_rt_deinit_cco_vdev(rt)
#define cvg_rt_cco_heart_beat_rx(vdev, bm, bm_size)
#endif /* PLC_SUPPORT_CCO_ROLE */
#if PLC_SUPPORT_STA_ROLE
/*
* cvg_rt_reset_sta_vdev() - rt sta vdev reset function
* @rt: rt vdev pointer
* @cfg: pointer of vdev configuration
*/
void cvg_rt_reset_sta_vdev(cvg_rt_vdev_t *rt, cvg_vdev_cfg_t *cfg);
/*
* cvg_rt_init_sta_vdev() - rt sta vdev init function
* @rt: rt vdev pointer
* @cfg: pointer of vdev configuration
*
* return:
* 0 -- for success case
* otherwise -- error code
*/
uint32_t cvg_rt_init_sta_vdev(cvg_rt_vdev_t *rt, cvg_vdev_cfg_t *cfg);
/*
* cvg_rt_deinit_sta_vdev() - rt sta vdev deinit function
* @rt: rt vdev pointer
*/
void cvg_rt_deinit_sta_vdev(cvg_rt_vdev_t *rt);
/*
* @brief cvg_rt_sta_heart_beat_rx() - rt sta vdev heart beat rx handling
* function
* @param vdev: cvg vdev pointer
* @param bm: bitmap containing discovered STAs
* @param bm_size: bitmap size in byte
* @param org_sta: tei of first STA sends heart beat
* @param max_dl_size: item count in the max discovery list
*/
void cvg_rt_sta_heart_beat_rx(cvg_vdev_t *vdev, uint8_t *bm, uint16_t bm_size,
tei_t org_sta, uint32_t max_dl_size);
/**
* @brief cvg_rt_sta_get_cand_rt() - get the candidate route entry list
* @param vdev: pointer to vdev
* @param rt_ent: pointer to buffer to receive the route entry list. this
* buffer must large enough to save CANDIDATE_PROXY_COUNT
* of route entry.
* @param ent_cnt: route entry list max count.
* @return number of avaible route entry in the list. should be no
* larger than CANDIDATE_PROXY_COUNT.
*/
uint8_t cvg_rt_sta_get_cand_rt(cvg_vdev_t *vdev, cvg_rt_ent_t rt_ent[],
uint8_t ent_cnt);
/**
* @brief cvg_rt_sta_calc_path_score() - calculate path score for given
* settings
* @param snr: snr of the path
* @param tf_sr: traffic success ratio of the path
*
* @retrun calculated path score
*/
uint32_t cvg_rt_sta_calc_path_score(int32_t snr, uint8_t tf_sr);
#else /* PLC_SUPPORT_STA_ROLE */
#define cvg_rt_reset_sta_vdev(rt, cfg)
#define cvg_rt_init_sta_vdev(rt, cfg) (ERR_NOSUPP)
#define cvg_rt_deinit_sta_vdev(rt)
#define cvg_rt_sta_heart_beat_rx(vdev, bm, bm_size, org_sta, max_dl_size)
#define cvg_rt_sta_get_cand_rt(vdev, rt_ent, ent_cnt) (0)
#endif /* PLC_SUPPORT_STA_ROLE */
/**
* @brief cvg_rt_get_rt_type() -- get route type of the route entry
* @param vdev: pointer to vdev
* @param ent: routing table entry
* @return route type, see PLC_RT_TYPE_XXX
*/
uint8_t cvg_rt_get_rt_type(cvg_rt_ent_t *ent);
/**
* @brief cvg_rt_calc_peer_tf_sr() - calculate accumulated traffic
* success ratio according the tf_sr history in previous
* route period
* @param peer: pointer to peer
* @param tx_sr: tx traffic success ratio
* @param rx_sr: rx traffic success ratio
*/
void cvg_rt_calc_peer_tf_sr(cvg_peer_info_t *peer, uint8_t tx_sr,
uint8_t rx_sr);
/**
* @brief cvg_rt_clean_dis_info() - clean discovery node list information
* @param vdev: pointer to vdev
* @param rt: rt vdev pointer
*/
void cvg_rt_clean_dis_info(cvg_vdev_t *vdev, cvg_rt_vdev_t *rt);
/**
* @brief cvg_rt_calc_dis_tf_sr() - calculate traffic success ratio according
* discovery node list packet information.
* @param vdev: pointer to vdev
* @param sta: the STA sending this discover node list
* @param bm: bitmap of discover node list
* @param bm_size: size of bitmap
* @param sta_cnt_info: discover node list count information
* @param sta_cnt: number of STA in discover list
* @param min_tf_sr: minimal traffic success rate
* @param dnl_send_cnt: discover node list sent in last route period
* @param partial_rp: flag to mark if previous route period is a partial
* route period
* @param phase_s: send phase of this discovery node list mme frame
*/
void cvg_rt_calc_dis_tf_sr(cvg_vdev_t *vdev, tei_t sta, uint8_t *bm,
uint16_t bm_size, uint8_t *sta_cnt_info, uint16_t sta_cnt,
uint8_t min_tf_sr, uint16_t dnl_send_cnt, uint8_t partial_rp,
uint8_t phase_s);
/**
* @brief cvg_rt_calc_dis_node_interval() - calculate the discovery node list
* mme sent interval accordingly to cco requirement.
* the unit is 1ms for both input and output.
* @param rt: rt vdev pointer
* @param dis_period: discovery node list mme sent period
* @param bc_period: beacon period
* @retval recommented discovery node list send interval. unit 1ms.
*/
uint32_t cvg_rt_calc_dis_node_interval(cvg_rt_vdev_t *rt,
uint32_t dis_period, uint32_t bc_period);
/**
* @brief cvg_rt_calc_rp_left_time() - calculate current route period left time
* @param rt: rt vdev pointer
* @retval remaining time to the end of current route period. unit is 1s.
*/
uint16_t cvg_rt_calc_rp_left_time(cvg_rt_vdev_t *rt);
/**
* @brief cvg_rt_check_peer_per_rp() - check traffic success ratio of remote
* peer success ratio according the tf_sr history in
* previous route period
* @param rt: rt vdev pointerr
* @param peer: pointer to peer
* @param tf_sr: traffic success ratio
*/
void cvg_rt_check_peer_per_rp(cvg_rt_vdev_t *rt,
cvg_peer_info_t *peer);
/*
* @brief cvg_rt_update_rp() - update route period parameters
* @vdev: pointer to vdev
* @rp: route parameters to be updated
* @tx_req: flag to mark if discovery node list mme tx required or not
* @retval: ERR_OK - for success case, otherwise -- error code
*/
uint32_t cvg_rt_update_rp(cvg_vdev_t *vdev, mac_bc_rt_param_t *rp,
uint8_t tx_req);
/*
* @brief cvg_rt_set_rt_dir_flag() - set route table link direct flag
* @param _dir_flag_: link direct flag, see CVG_RT_ENT_F_XXX
*/
#define cvg_rt_set_rt_dir_flag(ent, _dir_flag_) \
do { \
(ent)->dir_flag = (_dir_flag_); \
(ent)->up_flag = 0; \
} while(0)
#ifdef __cplusplus
}
#endif
#endif /* CVG_RT_INTERNAL_H */