build target link issue

Signed-off-by: zhangjie1999 <zhangshaojie3@huawei.com>
This commit is contained in:
zhangjie1999 2024-05-23 11:02:04 +00:00
parent a50b64680e
commit 1323c60ec9
5 changed files with 184 additions and 5 deletions

View File

@ -31,6 +31,8 @@ typedef struct {
int32_t (*allocLaneByQos)(uint32_t laneHandle, const LaneAllocInfo *allocInfo, const LaneAllocListener *listener);
int32_t (*reallocLaneByQos)(uint32_t laneHandle, uint64_t laneId, const LaneAllocInfo *allocInfo,
const LaneAllocListener *listener);
int32_t (*allocTargetLane)(uint32_t laneHandle, const LaneAllocInfoExt *allocInfo,
const LaneAllocListener *listener);
int32_t (*cancelLane)(uint32_t laneHandle);
int32_t (*freeLane)(uint32_t laneHandle);
} LaneInterface;

View File

@ -69,6 +69,16 @@ typedef enum {
LANE_LINK_FAILED,
} LaneRequestFailReason;
typedef enum {
LANE_LINK_TYPE_WIFI_WLAN = 1,
LANE_LINK_TYPE_WIFI_P2P = 2,
LANE_LINK_TYPE_BR = 3,
LANE_LINK_TYPE_COC_DIRECT = 4,
LANE_LINK_TYPE_BLE_DIRECT = 5,
LANE_LINK_TYPE_HML = 6,
LANE_LINK_TYPE_MAX,
} LaneSpecifiedLink;
typedef struct {
char brMac[BT_MAC_LEN];
} BrConnInfo;
@ -186,6 +196,8 @@ typedef struct {
typedef struct {
char peerBleMac[MAX_MAC_LEN];
bool networkDelegate;
bool isSpecifiedLink;
LaneSpecifiedLink linkType;
} AllocExtendInfo;
typedef struct {
@ -198,12 +210,25 @@ typedef struct {
AllocExtendInfo extendInfo;
} LaneAllocInfo;
typedef struct {
char networkId[NETWORK_ID_BUF_LEN];
LaneTransType transType;
} LaneAllocCommInfo;
typedef struct {
LaneType type;
LaneAllocCommInfo commInfo;
LanePreferredLinkList linkList;
} LaneAllocInfoExt;
typedef struct {
int32_t (*lnnQueryLaneResource)(const LaneQueryInfo *queryInfo, const QosInfo *qosInfo);
uint32_t (*lnnGetLaneHandle)(LaneType type);
int32_t (*lnnAllocLane)(uint32_t laneHandle, const LaneAllocInfo *allocInfo, const LaneAllocListener *listener);
int32_t (*lnnReAllocLane)(uint32_t laneHandle, uint64_t laneId, const LaneAllocInfo *allocInfo,
const LaneAllocListener *listener);
int32_t (*lnnAllocTargetLane)(uint32_t laneHandle, const LaneAllocInfoExt *allocInfo,
const LaneAllocListener *listener);
int32_t (*lnnCancelLane)(uint32_t laneHandle);
int32_t (*lnnFreeLane)(uint32_t laneHandle);
int32_t (*registerLaneListener)(LaneType type, const LaneStatusListener *listener);

View File

@ -324,11 +324,11 @@ static int32_t LnnReAllocLane(uint32_t laneReqId, uint64_t laneId, const LaneAll
{
if (!AllocInfoCheck(allocInfo, listener)) {
LNN_LOGE(LNN_LANE, "lane realloc info invalid");
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
if (g_laneObject[allocInfo->type] == NULL) {
LNN_LOGE(LNN_LANE, "laneType is not supported. laneType=%{public}d", allocInfo->type);
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_NOT_INIT;
}
LNN_LOGI(LNN_LANE, "realloc lane enter, laneReqId=%{public}u, laneId=%{public}" PRIu64 ", laneType=%{public}d, "
"transType=%{public}d, minBW=%{public}u, maxLaneLatency=%{public}u, minLaneLatency=%{public}u",
@ -339,7 +339,29 @@ static int32_t LnnReAllocLane(uint32_t laneReqId, uint64_t laneId, const LaneAll
int32_t result = g_laneObject[allocInfo->type]->reallocLaneByQos(laneReqId, laneId, allocInfo, listener);
if (result != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "realloc lane fail, laneReqId=%{public}u, result=%{public}d", laneReqId, result);
return SOFTBUS_ERR;
return result;
}
return SOFTBUS_OK;
}
static int32_t LnnAllocTargetLane(uint32_t laneHandle, const LaneAllocInfoExt *allocInfo,
const LaneAllocListener *listener)
{
if (allocInfo == NULL || listener == NULL || laneHandle == INVALID_LANE_REQ_ID) {
return SOFTBUS_INVALID_PARAM;
}
if (allocInfo->type != LANE_TYPE_TRANS) {
return SOFTBUS_INVALID_PARAM;
}
LNN_LOGI(LNN_LANE, "targetLinkNum=%{public}u and first targetLinkType=%{public}d",
allocInfo->linkList.linkTypeNum, allocInfo->linkList.linkType[0]);
if (allocInfo->linkList.linkTypeNum >= LANE_LINK_TYPE_BUTT) {
return SOFTBUS_INVALID_PARAM;
}
int32_t result = g_laneObject[allocInfo->type]->allocTargetLane(laneHandle, allocInfo, listener);
if (result != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "alloc target lane fail, handle=%{public}u, result=%{public}d", laneHandle, result);
return result;
}
return SOFTBUS_OK;
}
@ -387,6 +409,7 @@ static LnnLaneManager g_LaneManager = {
.lnnGetLaneHandle = ApplyLaneReqId,
.lnnAllocLane = LnnAllocLane,
.lnnReAllocLane = LnnReAllocLane,
.lnnAllocTargetLane = LnnAllocTargetLane,
.lnnCancelLane = LnnCancelLane,
.lnnFreeLane = LnnFreeLink,
.registerLaneListener = RegisterLaneListener,

View File

@ -495,7 +495,7 @@ static void DecideOptimalLinks(const char *networkId, const LaneSelectParam *req
LNN_LOGI(LNN_LANE, "decide optimal links num=%{public}d", *linksNum);
}
static bool isLaneExist(LaneLinkType *linkList, LaneLinkType linkType)
static bool IsLaneExist(LaneLinkType *linkList, LaneLinkType linkType)
{
for (int i = 0; i < LANE_LINK_TYPE_BUTT; i++) {
if (linkList[i] == linkType) {
@ -515,7 +515,7 @@ static void DecideRetryLinks(const char *networkId, const LaneSelectParam *reque
break;
}
if (IsValidLane(networkId, g_retryLaneList[bandWidthType][i], request->transType) &&
!isLaneExist(linkList, g_retryLaneList[bandWidthType][i])) {
!IsLaneExist(linkList, g_retryLaneList[bandWidthType][i])) {
linkList[(*linksNum)++] = g_retryLaneList[bandWidthType][i];
LNN_LOGI(LNN_LANE, "decide retry linkType=%{public}d", g_retryLaneList[bandWidthType][i]);
}

View File

@ -483,12 +483,140 @@ static int32_t AllocValidLane(uint32_t laneReqId, uint64_t allocLaneId, const La
return SOFTBUS_OK;
}
static void DumpInputLinkList(const LanePreferredLinkList *linkInfo)
{
for (uint32_t i = 0; i < linkInfo->linkTypeNum; i++) {
LNN_LOGD(LNN_LANE, "priority=%{public}u, linkType=%{public}d", i, linkInfo->linkType[i]);
}
}
static int32_t LaneAllocInfoConvert(const LaneAllocInfoExt *allocInfoExt, LaneAllocInfo *allocInfo)
{
allocInfo->type = allocInfoExt->type;
allocInfo->transType = allocInfoExt->commInfo.transType;
if (strcpy_s(allocInfo->networkId, NETWORK_ID_BUF_LEN, allocInfoExt->commInfo.networkId) != EOK) {
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}
static int32_t BuildTargetLink(uint32_t laneHandle, const LaneAllocInfoExt *allocInfoExt,
const LaneAllocListener *listener)
{
LanePreferredLinkList *linkList = (LanePreferredLinkList *)SoftBusCalloc(sizeof(LanePreferredLinkList));
if (linkList == NULL) {
return SOFTBUS_MALLOC_ERR;
}
if (memcpy_s(linkList, sizeof(LanePreferredLinkList), &allocInfoExt->linkList,
sizeof(LanePreferredLinkList)) != EOK) {
SoftBusFree(linkList);
return SOFTBUS_MEM_ERR;
}
LaneAllocInfo allocInfo;
(void)memset_s(&allocInfo, sizeof(allocInfo), 0, sizeof(allocInfo));
int32_t ret = LaneAllocInfoConvert(allocInfoExt, &allocInfo);
if (ret != SOFTBUS_OK) {
SoftBusFree(linkList);
return ret;
}
TransReqInfo *newItem = CreateReqNodeWithQos(laneHandle, &allocInfo, listener);
if (newItem == NULL) {
SoftBusFree(linkList);
return SOFTBUS_MALLOC_ERR;
}
if (Lock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get lock fail");
SoftBusFree(newItem);
SoftBusFree(linkList);
return SOFTBUS_LOCK_ERR;
}
ListTailInsert(&g_requestList->list, &newItem->node);
g_requestList->cnt++;
Unlock();
ret = TriggerLinkWithQos(laneHandle, &allocInfo, linkList);
if (ret != SOFTBUS_OK) {
SoftBusFree(linkList);
DeleteRequestNode(laneHandle);
return ret;
}
return SOFTBUS_OK;
}
static int32_t AllocTargetLane(uint32_t laneHandle, const LaneAllocInfoExt *allocInfo,
const LaneAllocListener *listener)
{
if (laneHandle == INVALID_LANE_REQ_ID || allocInfo == NULL ||
allocInfo->type != LANE_TYPE_TRANS || listener == NULL) {
LNN_LOGE(LNN_LANE, "alloc targetLane param invalid");
return SOFTBUS_INVALID_PARAM;
}
if (allocInfo->linkList.linkTypeNum >= LANE_LINK_TYPE_BUTT) {
return SOFTBUS_INVALID_PARAM;
}
DumpInputLinkList((const LanePreferredLinkList *)&allocInfo->linkList);
return BuildTargetLink(laneHandle, allocInfo, listener);
}
static bool SpecifiedLinkConvert(LaneSpecifiedLink link, LanePreferredLinkList *preferLink)
{
uint32_t linkNum = 0;
switch (link) {
case LANE_LINK_TYPE_WIFI_WLAN:
preferLink->linkType[linkNum++] = LANE_WLAN_5G;
preferLink->linkType[linkNum++] = LANE_WLAN_2P4G;
break;
case LANE_LINK_TYPE_WIFI_P2P:
preferLink->linkType[linkNum++] = LANE_P2P;
break;
case LANE_LINK_TYPE_BR:
preferLink->linkType[linkNum++] = LANE_BR;
break;
case LANE_LINK_TYPE_COC_DIRECT:
preferLink->linkType[linkNum++] = LANE_COC_DIRECT;
break;
case LANE_LINK_TYPE_BLE_DIRECT:
preferLink->linkType[linkNum++] = LANE_BLE_DIRECT;
break;
case LANE_LINK_TYPE_HML:
preferLink->linkType[linkNum++] = LANE_HML;
break;
default:
LNN_LOGE(LNN_LANE, "unexpected link=%{public}d", link);
break;
}
if (linkNum == 0) {
return false;
}
preferLink->linkTypeNum = linkNum;
return true;
}
static int32_t ProcessSpecifiedLink(uint32_t laneHandle, const LaneAllocInfo *allocInfo,
const LaneAllocListener *listener)
{
LaneAllocInfoExt info;
(void)memset_s(&info, sizeof(info), 0, sizeof(info));
if (!SpecifiedLinkConvert(allocInfo->extendInfo.linkType, &info.linkList)) {
return SOFTBUS_LANE_SELECT_FAIL;
}
info.type = allocInfo->type;
info.commInfo.transType = allocInfo->transType;
if (strcpy_s(info.commInfo.networkId, NETWORK_ID_BUF_LEN, allocInfo->networkId) != EOK) {
return SOFTBUS_STRCPY_ERR;
}
return BuildTargetLink(laneHandle, &info, listener);
}
static int32_t AllocLaneByQos(uint32_t laneReqId, const LaneAllocInfo *allocInfo, const LaneAllocListener *listener)
{
if (laneReqId == INVALID_LANE_REQ_ID || allocInfo == NULL || allocInfo->type != LANE_TYPE_TRANS) {
LNN_LOGE(LNN_LANE, "AllocLane param invalid");
return SOFTBUS_INVALID_PARAM;
}
if (allocInfo->extendInfo.isSpecifiedLink) {
LNN_LOGW(LNN_LANE, "process specifiedLink, linkType=%{public}d", allocInfo->extendInfo.linkType);
return ProcessSpecifiedLink(laneReqId, allocInfo, listener);
}
int32_t ret = AllocValidLane(laneReqId, INVALID_LANE_ID, allocInfo, listener);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "alloc valid lane fail, laneReqId=%{public}u", laneReqId);
@ -1349,6 +1477,7 @@ static LaneInterface g_transLaneObject = {
.allocLane = Alloc,
.allocLaneByQos = AllocLaneByQos,
.reallocLaneByQos = ReallocLaneByQos,
.allocTargetLane = AllocTargetLane,
.cancelLane = CancelLane,
.freeLane = Free,
};