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