diff --git a/common/MlsrConfigParameters.go b/common/MlsrConfigParameters.go index a00a23d..76d1d8c 100644 --- a/common/MlsrConfigParameters.go +++ b/common/MlsrConfigParameters.go @@ -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 { diff --git a/hello/HelloProtocol.go b/hello/HelloProtocol.go index e4db88b..44b6c79 100644 --- a/hello/HelloProtocol.go +++ b/hello/HelloProtocol.go @@ -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: //NLSR/INFO/ + 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) +}