feature:support resource query before build link

Signed-off-by: zhanghaowen <zhanghaowen12@huawei.com>
This commit is contained in:
zhanghaowen 2023-10-24 11:47:05 +08:00
parent d3a0a2e25b
commit be25990f96
10 changed files with 447 additions and 16 deletions

View File

@ -396,4 +396,14 @@ bool SoftBusIsWifiTripleMode(void)
char* SoftBusGetWifiInterfaceCoexistCap(void)
{
return NULL;
}
bool SoftBusIsWifiActive(void)
{
int wifiState = IsWifiActive();
LNN_LOGI(LNN_STATE, "wifi state %d", wifiState);
if (wifiState == WIFI_STA_ACTIVE) {
return true;
}
return false;
}

View File

@ -98,3 +98,8 @@ char* SoftBusGetWifiInterfaceCoexistCap(void)
{
return NULL;
}
bool SoftBusIsWifiActive(void)
{
return true;
}

View File

@ -150,6 +150,7 @@ int32_t SoftBusGetCurrentGroup(SoftBusWifiP2pGroupInfo *groupInfo);
bool SoftBusHasWifiDirectCapability(void);
bool SoftBusIsWifiTripleMode(void);
char* SoftBusGetWifiInterfaceCoexistCap(void);
bool SoftBusIsWifiActive(void);
#ifdef __cplusplus
}

View File

@ -43,6 +43,7 @@ if (dsoftbus_feature_lnn_net) {
"$core_lane_hub_path/lane_manager/src/lnn_lane_common.c",
"$core_lane_hub_path/lane_manager/src/lnn_lane_model.c",
"$core_lane_hub_path/lane_manager/src/lnn_lane_select.c",
"$core_lane_hub_path/lane_manager/src/lnn_lane_query.c",
"$core_lane_hub_path/lane_manager/src/lnn_select_rule.c",
"$core_lane_hub_path/lane_manager/src/lnn_trans_lane.c",
]

View File

@ -40,6 +40,7 @@ typedef enum {
LANE_BLE_REUSE,
LANE_COC,
LANE_COC_DIRECT,
LANE_HML,
LANE_LINK_TYPE_BUTT,
} LaneLinkType;
@ -88,6 +89,7 @@ typedef struct {
uint16_t protocol;
char localIp[IP_LEN];
char peerIp[IP_LEN];
uint16_t port;
} P2pConnInfo;
typedef struct {
@ -130,7 +132,6 @@ typedef enum {
typedef struct {
char networkId[NETWORK_ID_BUF_LEN];
LaneTransType transType;
uint32_t expectedBw;
} LaneQueryInfo;
typedef struct {
@ -138,18 +139,26 @@ typedef struct {
LaneLinkType linkType[LANE_LINK_TYPE_BUTT];
} LanePreferredLinkList;
typedef struct {
uint32_t minBW;
uint32_t maxLaneLatency;
uint32_t minLaneLatency;
} QosInfo;
typedef struct {
char networkId[NETWORK_ID_BUF_LEN];
char peerBleMac[MAX_MAC_LEN];
//'psm' is valid only when 'expectedlink' contains 'LANE_COC'
int32_t psm;
QosInfo qosRequire;
LaneTransType transType;
uint32_t expectedBw;
int32_t pid;
LanePreferredLinkList expectedLink;
bool networkDelegate;
bool p2pOnly;
ProtocolType acceptableProtocols;
int32_t pid;
//OldInfo
char peerBleMac[MAX_MAC_LEN];
//'psm' is valid only when 'expectedlink' contains 'LANE_COC'
int32_t psm;
uint32_t expectedBw;
LanePreferredLinkList expectedLink;
} TransOption;
typedef struct {
@ -159,7 +168,16 @@ typedef struct {
} requestInfo;
} LaneRequestOption;
QueryResult LnnQueryLaneResource(const LaneQueryInfo *queryInfo);
typedef struct {
int32_t (*lnnQueryLaneResource)(const LaneQueryInfo *queryInfo, const QosInfo *qosInfo);
uint32_t (*applyLaneId)(LaneType type);
int32_t (*lnnRequestLane)(uint32_t laneId, const LaneRequestOption *request, const ILaneListener *listener);
int32_t (*lnnFreeLane)(uint32_t laneId);
} LnnLaneManager;
LnnLaneManager* GetLaneManager(void);
int32_t LnnQueryLaneResource(const LaneQueryInfo *queryInfo, const QosInfo *qosInfo);
uint32_t ApplyLaneId(LaneType type);
int32_t LnnRequestLane(uint32_t laneId, const LaneRequestOption *request, const ILaneListener *listener);
int32_t LnnFreeLane(uint32_t laneId);

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef LNN_LANE_QUERY_H
#define LNN_LANE_QUERY_H
#include "lnn_lane_interface.h"
#ifdef __cplusplus
extern "C" {
#endif
int32_t QueryLaneResource(const LaneQueryInfo *queryInfo, const QosInfo *qosInfo);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -18,14 +18,17 @@
#include <securec.h>
#include <string.h>
#include "anonymizer.h"
#include "common_list.h"
#include "lnn_async_callback_utils.h"
#include "lnn_distributed_net_ledger.h"
#include "lnn_lane_assign.h"
#include "lnn_lane_common.h"
#include "lnn_lane_def.h"
#include "lnn_lane_interface.h"
#include "lnn_lane_link.h"
#include "lnn_lane_model.h"
#include "lnn_lane_query.h"
#include "lnn_lane_score.h"
#include "lnn_lane_select.h"
#include "lnn_trans_lane.h"
@ -310,12 +313,21 @@ int32_t LnnFreeLane(uint32_t laneId)
return SOFTBUS_OK;
}
QueryResult LnnQueryLaneResource(const LaneQueryInfo *queryInfo)
int32_t LnnQueryLaneResource(const LaneQueryInfo *queryInfo, const QosInfo *qosInfo)
{
if (queryInfo == NULL) {
return QUERY_RESULT_REQUEST_ILLEGAL;
if (queryInfo == NULL || qosInfo == NULL) {
LNN_LOGE(LNN_LANE, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
return QUERY_RESULT_OK;
if (!LnnGetOnlineStateById(queryInfo->networkId, CATEGORY_NETWORK_ID)) {
char *anonyNetworkId = NULL;
Anonymize(queryInfo->networkId, &anonyNetworkId);
LNN_LOGE(LNN_LANE, "device not online, cancel query peerNetworkId:%s", anonyNetworkId);
AnonymizeFree(anonyNetworkId);
return SOFTBUS_NETWORK_NODE_OFFLINE;
}
return QueryLaneResource(queryInfo, qosInfo);
}
static void LaneInitChannelRatingDelay(void *para)

View File

@ -0,0 +1,346 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "lnn_lane_query.h"
#include <securec.h>
#include "bus_center_info_key.h"
#include "bus_center_manager.h"
#include "lnn_feature_capability.h"
#include "lnn_local_net_ledger.h"
#include "lnn_log.h"
#include "lnn_lane_link.h"
#include "softbus_bus_center.h"
#include "softbus_errcode.h"
#include "softbus_log_old.h"
#include "softbus_wifi_api_adapter.h"
#include "wifi_direct_manager.h"
#define QOS_MIN_BANDWIDTH (500 * 1024)
#define QOS_P2P_ONLY_BANDWIDTH (160 * 1024 * 1024)
typedef struct {
bool available;
int32_t (*QueryLink)(const char *networkId);
} LinkState;
static void GetFileLaneLink(LaneLinkType *linkList, uint32_t *listNum, bool isHighBand)
{
linkList[(*listNum)++] = LANE_HML;
linkList[(*listNum)++] = LANE_WLAN_5G;
linkList[(*listNum)++] = LANE_WLAN_2P4G;
linkList[(*listNum)++] = LANE_P2P;
if (!isHighBand) {
linkList[(*listNum)++] = LANE_BR;
}
}
static void GetStreamLaneLink(LaneLinkType *linkList, uint32_t *listNum, bool isHighBand)
{
linkList[(*listNum)++] = LANE_HML;
linkList[(*listNum)++] = LANE_WLAN_5G;
linkList[(*listNum)++] = LANE_WLAN_2P4G;
linkList[(*listNum)++] = LANE_P2P;
}
static void GetMsgLaneLink(LaneLinkType *linkList, uint32_t *listNum, bool isHighBand)
{
linkList[(*listNum)++] = LANE_HML;
linkList[(*listNum)++] = LANE_WLAN_5G;
linkList[(*listNum)++] = LANE_WLAN_2P4G;
linkList[(*listNum)++] = LANE_P2P;
if (!isHighBand) {
linkList[(*listNum)++] = LANE_BLE;
linkList[(*listNum)++] = LANE_BR;
}
}
static void GetBytesLaneLink(LaneLinkType *linkList, uint32_t *listNum, bool isHighBand)
{
linkList[(*listNum)++] = LANE_HML;
linkList[(*listNum)++] = LANE_WLAN_5G;
linkList[(*listNum)++] = LANE_WLAN_2P4G;
linkList[(*listNum)++] = LANE_P2P;
if (!isHighBand) {
linkList[(*listNum)++] = LANE_BLE;
linkList[(*listNum)++] = LANE_BR;
}
}
static int32_t GetLaneResource(LaneTransType transType, LaneLinkType *optLink, uint32_t *linkNum,
bool isHighBand)
{
LaneLinkType defaultLink[LANE_LINK_TYPE_BUTT];
(void)memset_s(defaultLink, sizeof(defaultLink), -1, sizeof(defaultLink));
uint32_t optLinkMaxNum = *linkNum;
uint32_t index = 0;
switch (transType) {
case LANE_T_MSG:
GetMsgLaneLink(defaultLink, &index, isHighBand);
break;
case LANE_T_BYTE:
GetBytesLaneLink(defaultLink, &index, isHighBand);
break;
case LANE_T_FILE:
GetFileLaneLink(defaultLink, &index, isHighBand);
break;
case LANE_T_RAW_STREAM:
case LANE_T_COMMON_VIDEO:
case LANE_T_COMMON_VOICE:
GetStreamLaneLink(defaultLink, &index, isHighBand);
break;
default:
LNN_LOGE(LNN_LANE, "lane type=%d is not supported", transType);
return SOFTBUS_ERR;
}
*linkNum = 0;
if (memcpy_s(optLink, optLinkMaxNum * sizeof(LaneLinkType), defaultLink, sizeof(defaultLink)) != EOK) {
LNN_LOGE(LNN_LANE, "memcpy default linkList to optinal fail");
return SOFTBUS_MEM_ERR;
}
*linkNum = index;
return SOFTBUS_OK;
}
static bool GetNetCap(const char *networkId, int32_t *local, int32_t *remote)
{
int32_t ret = LnnGetLocalNumInfo(NUM_KEY_NET_CAP, local);
if (ret != SOFTBUS_OK || *local < 0) {
LNN_LOGE(LNN_LANE, "LnnGetLocalNumInfo err, ret = %d, local = %d", ret, *local);
return false;
}
ret = LnnGetRemoteNumInfo(networkId, NUM_KEY_NET_CAP, remote);
if (ret != SOFTBUS_OK || *remote < 0) {
LNN_LOGE(LNN_LANE, "LnnGetRemoteNumInfo err, ret = %d, remote = %d", ret, *remote);
return false;
}
return true;
}
static int32_t BrLinkState(const char *networkId)
{
int32_t local, remote;
if (!GetNetCap(networkId, &local, &remote)) {
LNN_LOGE(LNN_LANE, "GetNetCap error");
return SOFTBUS_ERR;
}
if (!(local & (1 << BIT_BR))) {
LNN_LOGE(LNN_LANE, "local bluetooth close, local=%d", local);
return SOFTBUS_BLUETOOTH_OFF;
}
if (!(remote & (1 << BIT_BR))) {
LNN_LOGE(LNN_LANE, "remote bluetooth close, remote=%d", remote);
return SOFTBUS_BLUETOOTH_OFF;
}
LNN_LOGI(LNN_LANE, "br link ok, local=%d, remote=%d", local, remote);
return SOFTBUS_OK;
}
static int32_t BleLinkState(const char *networkId)
{
int32_t local, remote;
if (!GetNetCap(networkId, &local, &remote)) {
LNN_LOGE(LNN_LANE, "GetNetCap error");
return SOFTBUS_ERR;
}
if (!(local & (1 << BIT_BLE))) {
LNN_LOGE(LNN_LANE, "local bluetooth close, local=%d", local);
return SOFTBUS_BLUETOOTH_OFF;
}
if (!(remote & (1 << BIT_BLE))) {
LNN_LOGE(LNN_LANE, "remote bluetooth close, remote=%d", remote);
return SOFTBUS_BLUETOOTH_OFF;
}
LNN_LOGI(LNN_LANE, "ble link ok, local=%d, remote=%d", local, remote);
return SOFTBUS_OK;
}
static int32_t WlanLinkState(const char *networkId)
{
int32_t local, remote;
if (!SoftBusIsWifiActive()) {
return SOFTBUS_WIFI_OFF;
}
if (!GetNetCap(networkId, &local, &remote)) {
LNN_LOGE(LNN_LANE, "GetNetCap error");
return SOFTBUS_ERR;
}
if (!(local & (1 << BIT_WIFI))) {
LNN_LOGE(LNN_LANE, "local wifi close, local=%d", local);
return SOFTBUS_WIFI_DISCONNECT;
}
if (!(remote & (1 << BIT_WIFI))) {
LNN_LOGE(LNN_LANE, "remote wifi close, remote=%d", remote);
return SOFTBUS_WIFI_DISCONNECT;
}
LNN_LOGI(LNN_LANE, "wifi link ok, local=%d, remote=%d", local, remote);
return SOFTBUS_OK;
}
static int32_t P2pLinkState(const char *networkId)
{
if (!SoftBusIsWifiActive()) {
return SOFTBUS_WIFI_OFF;
}
int32_t local, remote;
if (!GetNetCap(networkId, &local, &remote)) {
LNN_LOGE(LNN_LANE, "GetNetCap error");
return SOFTBUS_ERR;
}
if (((local & (1 << BIT_WIFI_P2P)) == 0) || ((remote & (1 << BIT_WIFI_P2P)) == 0)) {
LNN_LOGE(LNN_LANE, "p2p capa disable, local=%d, remote=%d", local, remote);
return SOFTBUS_P2P_NOT_SUPPORT;
}
int32_t ret = GetWifiDirectManager()->prejudgeAvailability(networkId, WIFI_DIRECT_CONNECT_TYPE_P2P);
if (ret == V1_ERROR_GC_CONNECTED_TO_ANOTHER_DEVICE) {
return SOFTBUS_P2P_ROLE_CONFLICT;
}
return ret;
}
static int32_t HmlLinkState(const char *networkId)
{
if (!SoftBusIsWifiActive()) {
return SOFTBUS_WIFI_OFF;
}
uint64_t feature = LnnGetFeatureCapabilty();
if (!IsFeatureSupport(feature, BIT_WIFI_DIRECT_TLV_NEGOTIATION)) {
LNN_LOGE(LNN_LANE, "local feature not supported");
return SOFTBUS_HML_NOT_SUPPORT;
}
bool result = false;
if (LnnGetRemoteBoolInfo(networkId, BOOL_KEY_TLV_NEGOTIATION, &result) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get remote feature failed");
return SOFTBUS_ERR;
}
if (!result) {
LNN_LOGE(LNN_LANE, "remote feature not supported");
return SOFTBUS_HML_NOT_SUPPORT;
}
int32_t ret = GetWifiDirectManager()->prejudgeAvailability(networkId, WIFI_DIRECT_CONNECT_TYPE_HML);
if (ret == ERROR_LOCAL_THREE_VAP_CONFLICT) {
return SOFTBUS_HML_THREE_VAP_CONFLIC;
}
return ret;
}
static LinkState g_linkState[LANE_LINK_TYPE_BUTT] = {
[LANE_BR] = {true, BrLinkState},
[LANE_BLE] = { true, BleLinkState},
[LANE_WLAN_2P4G] = { true, WlanLinkState},
[LANE_WLAN_5G] = { true, WlanLinkState},
[LANE_P2P] = { true, P2pLinkState},
[LANE_HML] = { true, HmlLinkState},
};
static int32_t IsValidLaneLink(const char *networkId, LaneLinkType linkType)
{
if ((linkType < 0) || (linkType >= LANE_LINK_TYPE_BUTT)) {
LNN_LOGE(LNN_LANE, "invalid linkType=%d", linkType);
return SOFTBUS_INVALID_PARAM;
}
if (!g_linkState[linkType].available) {
LNN_LOGE(LNN_LANE, "invalid QueryLink, linkType=%d", linkType);
return SOFTBUS_ERR;
}
if (g_linkState[linkType].QueryLink == NULL) {
LNN_LOGE(LNN_LANE, "invalid QueryLink, linkType=%d", linkType);
return SOFTBUS_ERR;
}
return g_linkState[linkType].QueryLink(networkId);
}
static bool isHighRequire(const QosInfo *qosInfo, bool *isHighBand)
{
if (qosInfo->minBW > QOS_MIN_BANDWIDTH) {
*isHighBand = true;
return true;
} else {
*isHighBand = false;
return true;
}
return false;
}
static int32_t QueryByRequireLink(const LaneQueryInfo *queryInfo, const QosInfo *qosInfo)
{
if (qosInfo->minBW == QOS_P2P_ONLY_BANDWIDTH) {
return IsValidLaneLink(queryInfo->networkId, LANE_P2P);
}
bool isHighBand = false;
if (!isHighRequire(qosInfo, &isHighBand)) {
LNN_LOGE(LNN_LANE, "set param failed");
return SOFTBUS_ERR;
}
LaneLinkType optLink[LANE_LINK_TYPE_BUTT];
(void)memset_s(optLink, sizeof(optLink), 0, sizeof(optLink));
uint32_t linkNum = LANE_LINK_TYPE_BUTT;
int32_t ret = SOFTBUS_ERR;
if (GetLaneResource(queryInfo->transType, optLink, &linkNum, isHighBand) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get defaultLinkList fail");
return ret;
}
for (uint32_t i = 0; i < linkNum; i++) {
ret = IsValidLaneLink(queryInfo->networkId, optLink[i]);
if (ret == SOFTBUS_OK) {
LNN_LOGI(LNN_LANE, "high require get enable Link, linktype=%d", optLink[i]);
return ret;
}
}
return ret;
}
static int32_t QueryByDefaultLink(const LaneQueryInfo *queryInfo)
{
LaneLinkType optLink[LANE_LINK_TYPE_BUTT];
(void)memset_s(optLink, sizeof(optLink), 0, sizeof(optLink));
uint32_t linkNum = LANE_LINK_TYPE_BUTT;
if (GetLaneResource(queryInfo->transType, optLink, &linkNum, false) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get defaultLinkList fail");
return SOFTBUS_ERR;
}
int32_t ret = SOFTBUS_ERR;
for (uint32_t i = 0; i < linkNum; i++) {
ret = IsValidLaneLink(queryInfo->networkId, optLink[i]);
if (ret == SOFTBUS_OK) {
LNN_LOGI(LNN_LANE, "default get enable Link, linktype=%d", optLink[i]);
return ret;
}
}
return ret;
}
int32_t QueryLaneResource(const LaneQueryInfo *queryInfo, const QosInfo *qosInfo)
{
if (queryInfo == NULL || qosInfo == NULL) {
LNN_LOGE(LNN_LANE, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
int32_t ret = SOFTBUS_ERR;
if (qosInfo->minBW > 0) {
LNN_LOGI(LNN_LANE, "Query lane by prefer linklist, transType=%d, minBW=%d",
queryInfo->transType, qosInfo->minBW);
ret = QueryByRequireLink(queryInfo, qosInfo);
} else {
LNN_LOGI(LNN_LANE, "Query lane by default linklist, transType=%d", queryInfo->transType);
ret = QueryByDefaultLink(queryInfo);
}
return ret;
}

View File

@ -375,6 +375,13 @@ enum SoftBusErrNo {
/* errno begin: 0xF0800000 */
SOFTBUS_PUBLIC_ERR_BASE = (-13000),
SOFTBUS_BLUETOOTH_OFF,
SOFTBUS_WIFI_OFF,
SOFTBUS_WIFI_DISCONNECT,
SOFTBUS_P2P_NOT_SUPPORT,
SOFTBUS_HML_NOT_SUPPORT,
SOFTBUS_P2P_ROLE_CONFLICT,
SOFTBUS_HML_THREE_VAP_CONFLIC,
/* internal error */
SOFTBUS_ERR = (-1),

View File

@ -539,13 +539,14 @@ HWTEST_F(LNNLaneMockTest, LNN_SELECT_LANE_002, TestSize.Level1)
*/
HWTEST_F(LNNLaneMockTest, LNN_LANE_QUERY_001, TestSize.Level1)
{
QueryResult ret = LnnQueryLaneResource(nullptr);
EXPECT_EQ(ret, QUERY_RESULT_REQUEST_ILLEGAL);
QosInfo qosInfo = {0};
int32_t ret = LnnQueryLaneResource(nullptr, &qosInfo);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
LaneQueryInfo query;
query.transType = LANE_T_BYTE;
ret = LnnQueryLaneResource((const LaneQueryInfo *)&query);
EXPECT_EQ(ret, QUERY_RESULT_OK);
ret = LnnQueryLaneResource((const LaneQueryInfo *)&query, &qosInfo);
EXPECT_NE(ret, SOFTBUS_OK);
}
/*