1060ff233Sopenharmony_ci/* 2060ff233Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 3060ff233Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4060ff233Sopenharmony_ci * you may not use this file except in compliance with the License. 5060ff233Sopenharmony_ci * You may obtain a copy of the License at 6060ff233Sopenharmony_ci * 7060ff233Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8060ff233Sopenharmony_ci * 9060ff233Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10060ff233Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11060ff233Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12060ff233Sopenharmony_ci * See the License for the specific language governing permissions and 13060ff233Sopenharmony_ci * limitations under the License. 14060ff233Sopenharmony_ci */ 15060ff233Sopenharmony_ci 16060ff233Sopenharmony_ci#ifndef SPUNGE_H 17060ff233Sopenharmony_ci#define SPUNGE_H 18060ff233Sopenharmony_ci#include "sockets.h" 19060ff233Sopenharmony_ci#include "lf_ring.h" 20060ff233Sopenharmony_ci#include "queue.h" 21060ff233Sopenharmony_ci#include "hlist.h" 22060ff233Sopenharmony_ci#include "log.h" 23060ff233Sopenharmony_ci#include "dympool.h" 24060ff233Sopenharmony_ci#include "fillp_cookie.h" 25060ff233Sopenharmony_ci 26060ff233Sopenharmony_ci#ifdef __cplusplus 27060ff233Sopenharmony_ciextern "C" { 28060ff233Sopenharmony_ci#endif 29060ff233Sopenharmony_ci 30060ff233Sopenharmony_ci#define UDP_HASH_TABLE_SIZE 128 31060ff233Sopenharmony_ci 32060ff233Sopenharmony_ci#define FILLP_ETH_DEVICE_SIZE 16 33060ff233Sopenharmony_ci 34060ff233Sopenharmony_ci#define FILLP_MAC_ADDRESS_SIZE 6 35060ff233Sopenharmony_ci 36060ff233Sopenharmony_ci#define FILLP_INST_UNSEND_BOX_NUM 1 37060ff233Sopenharmony_ci 38060ff233Sopenharmony_ci#define FILLP_INST_WIFI_INFO_NUM 4 39060ff233Sopenharmony_ci 40060ff233Sopenharmony_ci#define FILLP_EPOLL_ITEM_INIT_NUM 5 41060ff233Sopenharmony_ci#define FILLP_MSG_ITEM_INIT_NUM 10 42060ff233Sopenharmony_ci#define FILLP_CONN_ITEM_INIT_NUM 5 43060ff233Sopenharmony_ci 44060ff233Sopenharmony_cistruct SpungeResConf { 45060ff233Sopenharmony_ci FILLP_UINT maxInstNum; 46060ff233Sopenharmony_ci FILLP_UINT maxSockNum; 47060ff233Sopenharmony_ci FILLP_UINT maxTimerItemNum; 48060ff233Sopenharmony_ci FILLP_UINT maxMsgItemNum; 49060ff233Sopenharmony_ci FILLP_UINT maxConnNum; 50060ff233Sopenharmony_ci FILLP_UINT maxEpollItemNum; 51060ff233Sopenharmony_ci FILLP_UINT maxEpollEventNum; 52060ff233Sopenharmony_ci}; 53060ff233Sopenharmony_ci 54060ff233Sopenharmony_cistruct SpungePcbList { 55060ff233Sopenharmony_ci struct Hlist list; 56060ff233Sopenharmony_ci}; 57060ff233Sopenharmony_ci 58060ff233Sopenharmony_cistruct SpungePcbRes { 59060ff233Sopenharmony_ci struct SpungePcbList list; 60060ff233Sopenharmony_ci}; 61060ff233Sopenharmony_ci 62060ff233Sopenharmony_cistruct SpungePcbhashbucket { 63060ff233Sopenharmony_ci struct Hlist list; 64060ff233Sopenharmony_ci}; 65060ff233Sopenharmony_ci 66060ff233Sopenharmony_cistruct SpungeServerRateControlItem { 67060ff233Sopenharmony_ci FILLP_INT totalWeight; 68060ff233Sopenharmony_ci FILLP_UINT32 maxRate; 69060ff233Sopenharmony_ci}; 70060ff233Sopenharmony_ci 71060ff233Sopenharmony_cistruct SpungeServerRateControl { 72060ff233Sopenharmony_ci FILLP_LLONG lastControlTime; 73060ff233Sopenharmony_ci FILLP_INT connectionNum; 74060ff233Sopenharmony_ci FILLP_CHAR pad[4]; 75060ff233Sopenharmony_ci struct SpungeServerRateControlItem send; 76060ff233Sopenharmony_ci struct SpungeServerRateControlItem recv; 77060ff233Sopenharmony_ci}; 78060ff233Sopenharmony_ci 79060ff233Sopenharmony_cistruct SpungeTokenBucke { 80060ff233Sopenharmony_ci FILLP_LLONG lastTime; 81060ff233Sopenharmony_ci FILLP_UINT32 rate; /* kpbs */ 82060ff233Sopenharmony_ci FILLP_UINT32 tokenCount; /* bytes */ 83060ff233Sopenharmony_ci FILLP_UINT32 maxPktSize; /* bytes */ 84060ff233Sopenharmony_ci FILLP_ULLONG waitPktCount; /* pkt */ 85060ff233Sopenharmony_ci struct Hlist tbFpcbLists; 86060ff233Sopenharmony_ci struct HlistNode *fpcbCur; 87060ff233Sopenharmony_ci struct SpungeInstance *inst; 88060ff233Sopenharmony_ci struct FillpTimingWheelTimerNode tockenTimerNode; 89060ff233Sopenharmony_ci}; 90060ff233Sopenharmony_ci 91060ff233Sopenharmony_cistruct SpungeInstance { 92060ff233Sopenharmony_ci FILLP_LLONG curTime; 93060ff233Sopenharmony_ci FILLP_LLONG minSendInterval; 94060ff233Sopenharmony_ci FillpQueue *msgBox; 95060ff233Sopenharmony_ci DympoolType *msgPool; 96060ff233Sopenharmony_ci struct ThreadParam mainThreadParam; 97060ff233Sopenharmony_ci struct SpungePcbList pcbList; /* Recrd all connections */ 98060ff233Sopenharmony_ci struct Hlist osSockist; 99060ff233Sopenharmony_ci struct SpungeServerRateControl rateControl; 100060ff233Sopenharmony_ci struct FillpTimingWheel timingWheel; 101060ff233Sopenharmony_ci FillpQueue *unsendBox[FILLP_INST_UNSEND_BOX_NUM]; 102060ff233Sopenharmony_ci SYS_ARCH_SEM threadSem; /* Used when do send */ 103060ff233Sopenharmony_ci FILLP_BOOL thresdSemInited; 104060ff233Sopenharmony_ci struct FillpPcbItem **unsendItem; 105060ff233Sopenharmony_ci struct Hlist sendPcbList; 106060ff233Sopenharmony_ci 107060ff233Sopenharmony_ci FILLP_INT instIndex; 108060ff233Sopenharmony_ci FILLP_UINT netMask; 109060ff233Sopenharmony_ci FILLP_BOOL hasInited; 110060ff233Sopenharmony_ci FILLP_BOOL waitTobeCoreKilled; 111060ff233Sopenharmony_ci FILLP_UINT8 srcMac[FILLP_MAC_ADDRESS_SIZE]; 112060ff233Sopenharmony_ci FILLP_UINT8 destMac[FILLP_MAC_ADDRESS_SIZE]; 113060ff233Sopenharmony_ci FILLP_UINT8 cleanseDataCtr; 114060ff233Sopenharmony_ci FILLP_UINT8 pad[1]; 115060ff233Sopenharmony_ci 116060ff233Sopenharmony_ci FillpMacInfo macInfo; 117060ff233Sopenharmony_ci 118060ff233Sopenharmony_ci struct FillpTimingWheelTimerNode macTimerNode; 119060ff233Sopenharmony_ci struct FillpTimingWheelTimerNode fairTimerNode; 120060ff233Sopenharmony_ci FILLP_CHAR *tmpBuf[FILLP_VLEN]; 121060ff233Sopenharmony_ci struct SpungePcb tempSpcb; 122060ff233Sopenharmony_ci struct SpungeTokenBucke stb; 123060ff233Sopenharmony_ci SysArchAtomic msgUsingCount; 124060ff233Sopenharmony_ci}; 125060ff233Sopenharmony_ci 126060ff233Sopenharmony_civoid SpinstAddToPcbList(struct SpungeInstance *inst, struct HlistNode *node); 127060ff233Sopenharmony_civoid SpinstDeleteFromPcbList(struct SpungeInstance *inst, struct HlistNode *node); 128060ff233Sopenharmony_ci 129060ff233Sopenharmony_cistruct Spunge { 130060ff233Sopenharmony_ci struct SpungeResConf resConf; 131060ff233Sopenharmony_ci FILLP_UINT insNum; 132060ff233Sopenharmony_ci FILLP_BOOL hasInited; 133060ff233Sopenharmony_ci FILLP_BOOL hasDeinitBlked; 134060ff233Sopenharmony_ci FILLP_UINT8 traceFlag; 135060ff233Sopenharmony_ci FILLP_UINT8 pad; 136060ff233Sopenharmony_ci void *traceHandle; 137060ff233Sopenharmony_ci struct FtSocketTable *sockTable; /* alloc socket source */ 138060ff233Sopenharmony_ci DympoolType *netPool; 139060ff233Sopenharmony_ci 140060ff233Sopenharmony_ci DympoolType *epitemPool; /* epitem */ 141060ff233Sopenharmony_ci DympoolType *eventpollPool; /* eventpoll */ 142060ff233Sopenharmony_ci 143060ff233Sopenharmony_ci struct SpungeInstance *instPool; 144060ff233Sopenharmony_ci}; 145060ff233Sopenharmony_ci 146060ff233Sopenharmony_ciextern struct Spunge *g_spunge; 147060ff233Sopenharmony_ci#define SPUNGE_GET_CUR_INSTANCE() (&g_spunge->instPool[0]) 148060ff233Sopenharmony_ci 149060ff233Sopenharmony_ci#ifdef FILLP_LINUX 150060ff233Sopenharmony_ciextern FILLP_CHAR *g_ethdevice; 151060ff233Sopenharmony_ci#endif 152060ff233Sopenharmony_ci#define SPUNGE_STACK_VALID (g_spunge && g_spunge->hasInited) 153060ff233Sopenharmony_ci 154060ff233Sopenharmony_civoid SpungeEpollEventCallback(struct FtSocket *sock, FILLP_INT event, FILLP_INT count); 155060ff233Sopenharmony_civoid SpungeEpollAppRecvOne(struct FtSocket *sock); 156060ff233Sopenharmony_ci 157060ff233Sopenharmony_civoid SockSetOsSocket(struct FtSocket *ftSock, struct SockOsSocket *osSock); 158060ff233Sopenharmony_ci 159060ff233Sopenharmony_ci#ifdef __cplusplus 160060ff233Sopenharmony_ci} 161060ff233Sopenharmony_ci#endif 162060ff233Sopenharmony_ci 163060ff233Sopenharmony_ci#endif