1 /* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef SPUNGE_H 17 #define SPUNGE_H 18 #include "sockets.h" 19 #include "dympool.h" 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 #define UDP_HASH_TABLE_SIZE 128 26 27 #define FILLP_ETH_DEVICE_SIZE 16 28 29 #define FILLP_MAC_ADDRESS_SIZE 6 30 31 #define FILLP_INST_UNSEND_BOX_NUM 1 32 33 #define FILLP_INST_WIFI_INFO_NUM 4 34 35 #define FILLP_EPOLL_ITEM_INIT_NUM 5 36 #define FILLP_MSG_ITEM_INIT_NUM 10 37 #define FILLP_CONN_ITEM_INIT_NUM 5 38 39 struct SpungeResConf { 40 FILLP_UINT maxInstNum; 41 FILLP_UINT maxSockNum; 42 FILLP_UINT maxTimerItemNum; 43 FILLP_UINT maxMsgItemNum; 44 FILLP_UINT maxConnNum; 45 FILLP_UINT maxEpollItemNum; 46 FILLP_UINT maxEpollEventNum; 47 }; 48 49 struct SpungePcbList { 50 struct Hlist list; 51 }; 52 53 struct SpungePcbRes { 54 struct SpungePcbList list; 55 }; 56 57 struct SpungePcbhashbucket { 58 struct Hlist list; 59 }; 60 61 struct SpungeServerRateControlItem { 62 FILLP_INT totalWeight; 63 FILLP_UINT32 maxRate; 64 }; 65 66 struct SpungeServerRateControl { 67 FILLP_LLONG lastControlTime; 68 FILLP_INT connectionNum; 69 FILLP_CHAR pad[4]; 70 struct SpungeServerRateControlItem send; 71 struct SpungeServerRateControlItem recv; 72 }; 73 74 struct SpungeTokenBucke { 75 FILLP_LLONG lastTime; 76 FILLP_UINT32 rate; /* kpbs */ 77 FILLP_UINT32 tokenCount; /* bytes */ 78 FILLP_UINT32 maxPktSize; /* bytes */ 79 FILLP_ULLONG waitPktCount; /* pkt */ 80 struct Hlist tbFpcbLists; 81 struct HlistNode *fpcbCur; 82 struct SpungeInstance *inst; 83 struct FillpTimingWheelTimerNode tockenTimerNode; 84 }; 85 86 struct SpungeInstance { 87 FILLP_LLONG curTime; 88 FILLP_LLONG minSendInterval; 89 FillpQueue *msgBox; 90 DympoolType *msgPool; 91 struct ThreadParam mainThreadParam; 92 struct SpungePcbList pcbList; /* Recrd all connections */ 93 struct Hlist osSockist; 94 struct SpungeServerRateControl rateControl; 95 struct FillpTimingWheel timingWheel; 96 FillpQueue *unsendBox[FILLP_INST_UNSEND_BOX_NUM]; 97 SYS_ARCH_SEM threadSem; /* Used when do send */ 98 FILLP_BOOL thresdSemInited; 99 struct FillpPcbItem **unsendItem; 100 struct Hlist sendPcbList; 101 102 FILLP_INT instIndex; 103 FILLP_UINT netMask; 104 FILLP_BOOL hasInited; 105 FILLP_BOOL waitTobeCoreKilled; 106 FILLP_UINT8 srcMac[FILLP_MAC_ADDRESS_SIZE]; 107 FILLP_UINT8 destMac[FILLP_MAC_ADDRESS_SIZE]; 108 FILLP_UINT8 cleanseDataCtr; 109 FILLP_UINT8 pad[1]; 110 111 FillpMacInfo macInfo; 112 113 struct FillpTimingWheelTimerNode macTimerNode; 114 struct FillpTimingWheelTimerNode fairTimerNode; 115 FILLP_CHAR *tmpBuf[FILLP_VLEN]; 116 struct SpungePcb tempSpcb; 117 struct SpungeTokenBucke stb; 118 SysArchAtomic msgUsingCount; 119 }; 120 121 void SpinstAddToPcbList(struct SpungeInstance *inst, struct HlistNode *node); 122 void SpinstDeleteFromPcbList(struct SpungeInstance *inst, struct HlistNode *node); 123 124 struct Spunge { 125 struct SpungeResConf resConf; 126 FILLP_UINT insNum; 127 FILLP_BOOL hasInited; 128 FILLP_BOOL hasDeinitBlked; 129 FILLP_UINT8 traceFlag; 130 FILLP_UINT8 pad; 131 void *traceHandle; 132 struct FtSocketTable *sockTable; /* alloc socket source */ 133 DympoolType *netPool; 134 135 DympoolType *epitemPool; /* epitem */ 136 DympoolType *eventpollPool; /* eventpoll */ 137 138 struct SpungeInstance *instPool; 139 }; 140 141 extern struct Spunge *g_spunge; 142 #define SPUNGE_GET_CUR_INSTANCE() (&g_spunge->instPool[0]) 143 144 #ifdef FILLP_LINUX 145 extern FILLP_CHAR *g_ethdevice; 146 #endif 147 #define SPUNGE_STACK_VALID (g_spunge && g_spunge->hasInited) 148 149 void SpungeEpollEventCallback(struct FtSocket *sock, FILLP_INT event, FILLP_INT count); 150 void SpungeEpollAppRecvOne(struct FtSocket *sock); 151 152 void SockSetOsSocket(struct FtSocket *ftSock, struct SockOsSocket *osSock); 153 154 #ifdef __cplusplus 155 } 156 #endif 157 158 #endif