# An In-Network Cooperative Storage Schema Based on Neighbor Offloading in a Programmable Data Plane
## 4 In-Network Cooperative Storage Mechanism
### Cooperative Storage Strategy  
Many load-balancing strategies have been proposed in academia and industry, such as the round robin strategy, random strategy, hash strategy, or weight-based strategy [37], and traffic splitting in programmable switches [38; 39; 40; 41]. The round robin strategy distributes traffic equally among the instances by forwarding traffic to each instance in turn. The random strategy will select a random instance to forward traffic. The hash strategy will compute the hash value x of a field, such as the source IP or destination IP, compute index y as \(\times\) mod K (the count of instances), then obtain the corresponding target based on y in K targets. Traffic splitting in programmable switches mainly focuses on the weight approximation using flow table entries, but is still subject to flow-based traffic and does not consider how to obtain the weight. The strategies above do not consider the weight of targets and will cause load unbalancing if flow-based splitting is used. We consider the weight-based strategy and compute the relative weight in Equation (5).  
\[\text{relativeWeight(n)}=\mathit{weight(n)}\Big{/}\sum_{1}^{N}\mathit{weight(n)} \tag{5}\]  
According to the relative weight ratio of K nodes, we calculate the number of nodes corresponding to the constraint of storage space having a length under \(M\) (each index occupies 2 bytes) in Equation (6).  
\[\text{Count(n)}=floor(\mathit{relativeWeight(n)}*M/2) \tag{6}\]  
Then, two linear storage spaces are constructed separately for storing the index of targets and targets' IPs. Linear Storage Space 1 is used to store the index of the neighbors' IP, which is stored in Linear Storage Space 2. The flow entries will match the L bits of the ID's suffix; then, the actions are executed to determine whether it is in the cooperative state. If this is the case, the corresponding index x is searched for in Linear Storage Space 1 based on the value of the L bits of the ID's suffix; the target IP in Linear Storage Space 2 is obtained with the value of index x as the index in Linear Storage Space 2; and the \"Forwarding to neighbor\" action is executed. Figure 5 shows a simple example.  
However, the ping-pong loops problem may exist. When a producer P1 begins to store chunks, the corresponding in-network storage service node A enters the load balancing state, and may offload a portion of the chunks to its neighbor B according the load balancing rules. Immediately afterwards, the in-network storage service B receives the data storage from another producer P2. Assuming that A is also a neighbor of B, B also enters the cooperative state after calculating the normalized value of its weight. A portion of the chunks may be offloaded to A according the offloading rules in B. After A receives these chunks, they may be offloaded to B according to A's offloading rules, and a loop occurs. To avoid ping-pong loop problems, the input port avoidance mechanism is adopted. The input port avoidance mechanism is used to exclude the input port of the packet and to prevent forwarding to the input port where the packet comes. It is currently considered that the chunk data can only be offloaded once, before waiting to be stored locally or forwarded to a unified flood discharge area in the cloud. The detailed algorithm is described in Algorithm 2.  
Figure 5: The load balancing strategy procedure.