重写hello:实现发送hello兴趣包的函数

This commit is contained in:
free will committed 2022-07-14 23:46:28 +08:00
1 parent c2c9b7cf2c
commit d109b3dc07
2 files changed
+46 -4

No files matched your search

+2 -2
View File
@@ -359,8 +359,8 @@ func (mcp *MlsrConfigParameters) GetInterestResendTime() uint32 {
return mcp.mlsrconf.HelloTimeout
}
func (mcp *MlsrConfigParameters) GetInfoInterestInterval() {
// todo
func (mcp *MlsrConfigParameters) GetInfoInterestInterval() time.Duration {
return mcp.m_helloInterval
}
func (mcp *MlsrConfigParameters) GetMaxFacesPerPrefix() int {
+44 -2
View File
@@ -95,10 +95,52 @@ func (hp *HelloProtocol) Init(face *logicface.LogicFace,
go hp.recvPacketFromClientRoutine()
}
func (hp *HelloProtocol) expressInterest(interestName *component.Identifier, seconds uint32) {
//
// expressInterest
// @Description: 根据传入的兴趣包名称和兴趣包过期时间,构建兴趣包,并发出去
// @receiver hp
// @param interestName
// @param _millseconds
//
func (hp *HelloProtocol) expressInterest(interestName *component.Identifier, _millseconds uint32) {
common2.LogDebug("HelloProtocol Expressing Interest: " + interestName.ToUri())
interest := packet.NewInterest()
interest.SetName(interestName)
interest.SetInterestLifeTime(2000)
interest.SetInterestLifeTime(uint64(_millseconds))
// todo 这里需要实现的是,将兴趣包通过face发出,并对超时、nack、正常应答三种情况进行处理
}
//
// SendHelloInterest
// @Description: 向指定邻居路由器发送hello探测包
// @receiver hp
// @param neighbor
//
func (hp *HelloProtocol) SendHelloInterest(neighbor *component.Identifier) {
// 查找关于某个邻居路由器的邻接信息
adjInfo := hp.m_adjacencyList.FindAdjacencyByRouterIdentifier(neighbor)
// 如果没有找到,则不做处理
if adjInfo == nil {
return
}
// 如果找到了,且有对应的faceID,则发送一个hello探测包
if adjInfo.LogicFaceId() != 0 {
// interest name: /<neighbor>/NLSR/INFO/<router>
name, err := component.CreateIdentifierByString(adjInfo.GetNeighborRouterIdentifier().ToString() +
"/" + MLSR_COMPONENT + "/" + INFO_COMPONENT +
"/" + GetSinglePrefixForHelloProtocol(hp.mlsrConfig.GetRouterPrefix()))
if err != nil {
common2.LogDebug("HelloProtocol SendHelloInterest error, hello name create wrong.")
return
}
// 将data发出去
hp.expressInterest(name, hp.mlsrConfig.GetInterestResendTime())
common2.LogDebug("Sending HELLO interest: " + name.ToUri())
}
// 安排按照配置文件中的时间,若干秒后【默认一分钟】发送下一个hello兴趣包
hp.m_scheduler.ScheduleTaskAfterDuration(hp.mlsrConfig.GetInfoInterestInterval(), 1).
Do(hp.SendHelloInterest, neighbor)
}