# A Replica-Selection Algorithm Based on Transmission Completion Time Estimation in ICN
## 4 Algorithm Description
### Overview of TCTE Algorithm
If it does not exist, the replica selection is performed. First, it retrieves the ID of the NDC from the REQ packet, and then  
Figure 3: Schematic diagram of replica selection. obtains the NA list \(NAList\) of the replica node from the ENRS according to the ID. If the \(NAList\) is not empty, it selects the replica node with the smallest RTT to forward the REQ, saves the \(NAList\), and marks that replica selection needs to be re-selected. If \(NAList\) is empty, it continues to obtain the \(NAList\) of the replica node from GNR. Then, it selects the nearest replica node to forward REQ, and saves the selection result in the replica-selection completed list. ```
Input:\(REQ\) Output:\(NA\)
1:\(NA=GetNA\)\(\mathit{Herm}\)ReplicaSelectionCompleteList(\(REQ\))
2:if\(NA!=NULL\)then
3:return\(NA\)
4:else
5:\(EID=\mathit{GetEID}(REQ)\)
6:\(NAList=\mathit{GetNameResolutionFromEnRS}(EID)\)
7:if\(\mathit{NAList}!=NULL\)then
8:\(Reselection=true\)
9:\(NA=\mathit{FindMinRTTNA}(NAList)\)
10:\(\mathit{SaveNAList}(NAList,REQ,Reselection)\)
11:else
12:\(NAList=\mathit{GetNameResolutionFromGNR}(EID)\)
13:if\(NAList!=NULL\)then
14:\(NA=\mathit{FindNearestNA}(NAList)\)
15:endif
16:\(\mathit{SaveToReplicaSelectionCompleteList}(REQ,NA)\)
17:endif
18:endif
19:return\(NA\)
```  
**Algorithm 1**Operation of the TCTE algorithm when receiving an REQ packet  
Algorithm 2 is the operation when TCTE receives the DATA packet. When receiving the DATA packet, TCTE will check whether it needs to re-select the replica node. If it is necessary to re-select the replica node, TCTE will take out the previously saved \(NAList\) and obtain the \(ChunkSize\) from the DATA packet, then calculate the estimated value of the transmission completion time of the replica node in the \(NAList\) according to the status information of the replica node, and select the replica node with the smallest value and save it in the replica-selection completed list. ```
Input:\(DATA\) Output:\(NULL\)
1:if\(is\)Reselection(\(DATA\))then
2:\(NAList=\mathit{GetNAList}(DATA)\)
3:\(ChunkSize=\mathit{GetChunkSize}(DATA)\)
4:\(T_{min}=MaxVal\)
5:for\(NA_{tmp}\) in \(NAList\)then
6:\(T_{tmp}=\mathit{EstimatedTransmissionCompletionTime}(NA_{tmp},ChunkSize)\)
7:if\(T_{min}>T_{tmp}\)then
8:\(NA=NA_{tmp}\)
9:\(T_{min}=T_{tmp}\)
10:endif
11:endfor
12:\(SaveToReplicaSelectionCompleteList}(DATA,NA)\)
13:endif
14:return
```  
**Algorithm 2**Operation of the TCTE algorithm when receiving a DATA packet  
Algorithm 3 is the operation when TCTE receives the DATA packet. When receiving the DATA packet, TCTE will check whether it needs to re-select the replica node. If it is necessary to re-select the replica node, TCTE will take out the previously saved \(NAList\) and obtain the \(ChunkSize\) from the DATA packet, then calculate the estimated value of the transmission completion time of the replica node in the \(NAList\) according to the status information of the replica node, and select the replica node with the smallest value and save it in the replica-selection completed list. Algorithm 2 is the operation when TCTE receives the DATA packet. When receiving the DATA packet, TCTE will check whether it needs to re-select the replica node. If it is necessary to re-select the replica node, TCTE will take out the previously saved \(NAList\) and obtain the \(ChunkSize\) from the DATA packet, then calculate the estimated value of the transmission completion time of the replica node in the \(NAList\) according to the status information of the replica node, and select the replica node with the smallest value and save it in the replica-selection completed list.