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 PCB_H
17 #define PCB_H
18
19 #include "fillp/fillp_pcb.h"
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25
26 /* Implementing Fair Bandwidth sharing among sockets */
27 struct SpungePcbRateControlItem {
28 FILLP_UINT32 curMaxRateLimitation;
29 FILLP_INT weight;
30 };
31
32 struct SpungePcbRateControl {
33 struct SpungePcbRateControlItem send;
34 struct SpungePcbRateControlItem recv;
35 };
36
37 #ifndef IFNAMESIZE
38 #define IFNAMESIZE 64
39 #endif
40 struct SpungePcb {
41 struct HlistNode udpNode;
42 struct HlistNode hashNode;
43 struct FillpPcb fpcb;
44
45 void *conn;
46
47 /* Implementing Fair Bandwidth sharing among sockets */
48 struct SpungePcbRateControl rateControl;
49
50 struct sockaddr_in6 localAddr;
51 struct sockaddr_in6 remoteAddr;
52
53 FILLP_INT localPort;
54 FILLP_UINT16 addrType;
55 FILLP_UINT16 addrLen;
56
57 FILLP_CHAR devName[IFNAMESIZE];
58 FILLP_INT ifIndex;
59 };
60
SpungePcbListNodeEntry(struct HlistNode * node)61 static __inline struct SpungePcb *SpungePcbListNodeEntry(struct HlistNode *node)
62 {
63 return (struct SpungePcb *)((char *)(node) - (uintptr_t)(&(((struct SpungePcb *)0)->udpNode)));
64 }
65
SpungePcbHashNodeEntry(struct HlistNode * node)66 static __inline struct SpungePcb *SpungePcbHashNodeEntry(struct HlistNode *node)
67 {
68 return (struct SpungePcb *)((char *)(node) - (uintptr_t)(&(((struct SpungePcb *)0)->hashNode)));
69 }
70
71 void SpcbAddPcbToSpinst(struct SpungeInstance *inst, struct SpungePcb *pcb);
72 void SpcbDeleteFromSpinst(struct SpungeInstance *inst, struct SpungePcb *pcb);
73
74
75 struct SpungePcb *SpungePcbNew(void *argConn, struct SpungeInstance *inst);
76
77 void SpungePcbRemove(struct SpungePcb *pcb);
78
79 void SpungePcbSetSendCacheSize(struct SpungePcb *pcb, FILLP_UINT32 cahceSize);
80 void SpungePcbSetRecvCacheSize(struct SpungePcb *pcb, FILLP_UINT32 cahceSize);
81 void SpungePcbSetPktSize(struct SpungePcb *pcb, FILLP_UINT32 pktSize);
82 void SpungePcbSetOppositeRate(struct SpungePcb *pcb, FILLP_UINT32 rate);
83 void SpungePcbSetSlowStart(struct SpungePcb *pcb, FILLP_BOOL slowStart);
84 void SpungePcbSetPackInterval(struct SpungePcb *pcb, FILLP_UINT32 interval);
85 void SpungePcbSetAddrType(struct SpungePcb *pcb, FILLP_UINT16 addrType);
86 void SpungePcbSetLocalPort(struct SpungePcb *pcb, FILLP_INT port);
87 void SpungePcbSetDirectlySend(struct SpungePcb *pcb, FILLP_INT directlySend);
88
89 #ifdef __cplusplus
90 }
91 #endif
92
93 #endif /* PCB_H */
94