From d109b3dc074e0eb7ac9fb9c6ac50ccc2f0f48bca Mon Sep 17 00:00:00 2001 From: free will <2647778488@qq.com> Date: Thu, 14 Jul 2022 23:46:28 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99hello=EF=BC=9A=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E5=8F=91=E9=80=81hello=E5=85=B4=E8=B6=A3=E5=8C=85?= =?UTF-8?q?=E7=9A=84=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/MlsrConfigParameters.go | 4 +-- hello/HelloProtocol.go | 46 ++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) 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) +}