mirror of
https://gitee.com/willfree/mlsr.git
synced 2026-06-15 20:04:48 +08:00
HelloProtocol.go
This commit is contained in:
+85
-31
@@ -8,6 +8,7 @@
|
||||
package hello
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
"minlib/component"
|
||||
"minlib/encoding"
|
||||
"minlib/logicface"
|
||||
@@ -32,8 +33,13 @@ type HelloProtocol struct {
|
||||
//RoutingTable
|
||||
lsdb.Lsdb
|
||||
scheduler *lsdb.Scheduler
|
||||
//SignatureInfo *component.SignatureInfo
|
||||
|
||||
}
|
||||
|
||||
//声明一个邻接列表
|
||||
var adjacentList *lsa.AdjLsaAdjacenctList
|
||||
|
||||
//
|
||||
// expressInterest
|
||||
// @Description:发送一个Hello兴趣包
|
||||
@@ -41,14 +47,14 @@ type HelloProtocol struct {
|
||||
// @param interestNamePrefix
|
||||
// @param seconds
|
||||
//
|
||||
func (h *HelloProtocol) expressInterest(interestNamePrefix *component.Identifier, seconds int) {
|
||||
var interest packet.Interest
|
||||
interest.SetName(interestNamePrefix)
|
||||
interest.SetInterestLifeTime(seconds)
|
||||
func (h *HelloProtocol) expressInterest(interestName *component.Identifier, seconds uint32) {
|
||||
logrus.Debug("Expressing Interest:%v", interestName)
|
||||
var interest *packet.Interest
|
||||
interest.SetName(interestName) //设置兴趣包的名字
|
||||
interest.SetInterestLifeTime(uint64(seconds)) //设置兴趣包的生命周期
|
||||
interest.SetMustBeRefresh(true)
|
||||
interest.SetCanBePrefix(true)
|
||||
h.face.SendInterest(&interest)
|
||||
|
||||
h.face.SendInterest(interest)
|
||||
}
|
||||
|
||||
//
|
||||
@@ -57,20 +63,33 @@ func (h *HelloProtocol) expressInterest(interestNamePrefix *component.Identifier
|
||||
// @receiver h
|
||||
// @param neighbor
|
||||
//
|
||||
func (h *HelloProtocol) sendHelloInterest(neighbor *lsa.AdjLsaAdjacenctList) {
|
||||
var number = neighbor.GetNumOfActiveNeighbor() + neighbor.GetNumOfActiveNeighbor()
|
||||
if number != 0 {
|
||||
for i := 0; i < number; i++ {
|
||||
var adjList = neighbor.GetAdjList()
|
||||
var interestName = adjList[i].GetNeighborRouterIdentifier()
|
||||
interestName.BuildIdentifierByString(MLSR_COMPONENT)
|
||||
interestName.BuildIdentifierByString(INFO_COMPONENT)
|
||||
//少一个添加commandname的
|
||||
h.expressInterest(interestName, h.mlsrConfig.LsaInterestLifetime)
|
||||
func (h *HelloProtocol) sendHelloInterest(neighbor *component.Identifier) {
|
||||
|
||||
}
|
||||
//声明一个邻居“对象”,输入其名称前缀获取它的邻接信息,adjacent的类型为*AdjLsaAdjacencyInfo
|
||||
adjacent, _ := adjacentList.GetAdjacency(neighbor)
|
||||
//判定邻接列表是否为空,若为空则返回
|
||||
if adjacentList.GetAdjList() == nil {
|
||||
return
|
||||
}
|
||||
//调度器
|
||||
if adjacent.LogicFaceId() != 0 {
|
||||
var interestName *component.Identifier
|
||||
//获取邻居路由器的名称前缀
|
||||
interestName = adjacent.GetNeighborRouterIdentifier()
|
||||
//假设本机是A,邻居是B
|
||||
//interestName格式:/<B路由器前缀>/MLSR/INFO/<A路由器的前缀>
|
||||
mlsr, _ := component.CreateIdentifierByString(MLSR_COMPONENT) //mlsr的类型是*component.Identifier
|
||||
info, _ := component.CreateIdentifierByString(INFO_COMPONENT)
|
||||
mlsr1, _ := mlsr.Get(0) //mlsr1的类型是*component.IdentifierComponent
|
||||
info1, _ := info.Get(0)
|
||||
thisRouterPrefix, _ := h.ThisRouterPrefix.Get(0)
|
||||
interestName.Append(mlsr1) //在兴趣包名字后面添加“MLSR”
|
||||
interestName.Append(info1) //在兴趣包名字后面添加“INFO”
|
||||
interestName.Append(thisRouterPrefix) //在兴趣包名字后面添加本路由器的前缀
|
||||
h.expressInterest(interestName, h.mlsrConfig.HelloTimeout) //将兴趣包传出去
|
||||
logrus.Debug("Sending Hello Interest:%v", interestName) //日志记录
|
||||
}
|
||||
//使用调度器循环调度上面事件,调度器里传入两个参数:一个是间隔时间,一个是event,意思是每隔HelloInterval时间就调用一次event事件
|
||||
//h.scheduler.scheduler(h.mlsrConfig.HelloInterval,{h.sendHelloInterest(this.neighbor)})
|
||||
}
|
||||
|
||||
//
|
||||
@@ -81,22 +100,57 @@ func (h *HelloProtocol) sendHelloInterest(neighbor *lsa.AdjLsaAdjacenctList) {
|
||||
// @param interest
|
||||
//
|
||||
func (h *HelloProtocol) processInterest(name *component.Identifier, interest *packet.Interest) {
|
||||
var neighbor *lsa.AdjLsaAdjacencyInfo
|
||||
var neighborList *lsa.AdjLsaAdjacenctList
|
||||
neighbor.WireDecode(interest.Raw())
|
||||
if neighborList.IsNeighbor(name) {
|
||||
var interestName *component.Identifier
|
||||
//假设本机是A,邻居是B
|
||||
//收到的interest name: /<A路由器前缀>/MLSR/INFO/<B路由器前缀>
|
||||
interestName = interest.GetName()
|
||||
logrus.Debug("Interest Recieved for name:v%", interestName)
|
||||
//判断收到的包是否符合格式
|
||||
is_info, _ := interestName.Get(-2)
|
||||
if is_info.ToUri() != INFO_COMPONENT {
|
||||
logrus.Debug("INFO_COMPONENT not found or interestName: v% "+
|
||||
"does not match expression", interestName)
|
||||
return
|
||||
}
|
||||
var neighbor *component.Identifier //B路由器名称前缀
|
||||
neighborPrefix, _ := interestName.Get(-1)
|
||||
neighbor.WireDecode(neighborPrefix.Raw())
|
||||
logrus.Debug("Neighbor: v%", neighbor)
|
||||
if adjacentList.IsNeighbor(neighbor) {
|
||||
var data *packet.Data
|
||||
data.SetName((interest.GetName()).AppendVersionNumber())
|
||||
data.SetFreshnessPeriod(uint64(time.Second * 10))
|
||||
h.keychain.SignData(data)
|
||||
h.face.SendData(data)
|
||||
if neighbor.Status == 0 {
|
||||
name.BuildIdentifierByString(MLSR_COMPONENT)
|
||||
name.BuildIdentifierByString(INFO_COMPONENT)
|
||||
//少一个添加commandname
|
||||
h.expressInterest(name, h.mlsrConfig.LsaInterestLifetime)
|
||||
dataName := interest.GetName()
|
||||
dataName.AppendVersionNumber(1)
|
||||
data.SetName(dataName)
|
||||
data.SetFreshnessPeriod(uint64(time.Second * 10)) //10 sec
|
||||
data.Payload.SetValue([]byte(INFO_COMPONENT))
|
||||
|
||||
h.keychain.SignData(data)
|
||||
|
||||
logrus.Debug("Sending out data for name:v%", interestName)
|
||||
|
||||
h.face.SendData(data)
|
||||
//为了优化响应链路恢复的时间,如果邻居当前是非活动状态,那么Hello协议将立即向邻居发送Hello Interest
|
||||
adjacent, _ := adjacentList.GetAdjacency(neighbor)
|
||||
if adjacent.Status == 0 { //邻居路由器的状态:未知-1、未激活0、激活1
|
||||
if adjacent.LogicFaceId() != 0 { //邻居有face我们才能做
|
||||
var interestName *component.Identifier
|
||||
//获取邻居路由器的名称前缀
|
||||
interestName = adjacent.GetNeighborRouterIdentifier()
|
||||
//假设本机是A,邻居是B
|
||||
//interestName格式:/<B路由器前缀>/MLSR/INFO/<A路由器的前缀>
|
||||
mlsr, _ := component.CreateIdentifierByString(MLSR_COMPONENT) //mlsr的类型是*component.Identifier
|
||||
info, _ := component.CreateIdentifierByString(INFO_COMPONENT)
|
||||
mlsr1, _ := mlsr.Get(0) //mlsr1的类型是*component.IdentifierComponent
|
||||
info1, _ := info.Get(0)
|
||||
thisRouterPrefix, _ := h.ThisRouterPrefix.Get(0)
|
||||
interestName.Append(mlsr1) //在兴趣包名字后面添加“MLSR”
|
||||
interestName.Append(info1) //在兴趣包名字后面添加“INFO”
|
||||
interestName.Append(thisRouterPrefix) //在兴趣包名字后面添加本路由器的前缀
|
||||
h.expressInterest(interestName, h.mlsrConfig.HelloTimeout) //将兴趣包传出去
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+29
-32
@@ -12,7 +12,6 @@ import (
|
||||
"bytes"
|
||||
"minlib/component"
|
||||
"minlib/packet"
|
||||
"mlsr/common"
|
||||
"mlsr/communication"
|
||||
"mlsr/lsa"
|
||||
"mlsr/lsdb/LsaContainer"
|
||||
@@ -21,14 +20,13 @@ import (
|
||||
|
||||
// Lsdb更新状态
|
||||
const (
|
||||
INSTALLED = 0 // 已安装
|
||||
UPDATED = 1 // 已更新
|
||||
REMOVED = -1 // 已移除
|
||||
INSTALLED = 0 // 已安装
|
||||
UPDATED = 1 // 已更新
|
||||
REMOVED = -1 // 已移除
|
||||
)
|
||||
|
||||
type Lsdb struct {
|
||||
// 配置参数
|
||||
mlsrConfig *common.MlsrConfig
|
||||
|
||||
// 同步协议配置项
|
||||
sync *communication.SyncLogicHandler
|
||||
@@ -36,22 +34,22 @@ type Lsdb struct {
|
||||
// LSA容器
|
||||
lsaContainer *LsaContainer.LsaContainer
|
||||
|
||||
lsaRefreshTime *time.Duration // lsa刷新时间
|
||||
adjLsaBuildInterval *time.Duration // 邻接LSA构建间隔
|
||||
thisRouterPrefix *component.Identifier // 当前路由器的标识
|
||||
lsaRefreshTime *time.Duration // lsa刷新时间
|
||||
adjLsaBuildInterval *time.Duration // 邻接LSA构建间隔
|
||||
ThisRouterPrefix *component.Identifier // 当前路由器的标识
|
||||
|
||||
// 任务调度器
|
||||
scheduler *Scheduler
|
||||
|
||||
// 将LSA的名称从sync映射到其已知的最高序列号;
|
||||
// 用于阻止MLSR尝试获取过时的LSA
|
||||
highestSeqNo map[*component.Identifier] uint64
|
||||
highestSeqNo map[*component.Identifier]uint64
|
||||
|
||||
// 不同类型lsa的序列号管理器
|
||||
sequencingManager *SequencingManager
|
||||
|
||||
isBuildAdjLsaScheduled bool // 是否安排构建邻接LSA
|
||||
adjBuildCount uint64 // 邻接LSA的构建的统计数目
|
||||
isBuildAdjLsaScheduled bool // 是否安排构建邻接LSA
|
||||
adjBuildCount uint64 // 邻接LSA的构建的统计数目
|
||||
}
|
||||
|
||||
//
|
||||
@@ -62,7 +60,7 @@ type Lsdb struct {
|
||||
// @param lsaType
|
||||
// @return bool
|
||||
//
|
||||
func (l *Lsdb) DoesLsaExist(routerIdentifier *component.Identifier,lsaType int) bool {
|
||||
func (l *Lsdb) DoesLsaExist(routerIdentifier *component.Identifier, lsaType int) bool {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
@@ -88,7 +86,7 @@ func (l *Lsdb) BuildAndInstallOwnCoordinateLsa() {
|
||||
// @Description: 安排LSA的构建
|
||||
// @receiver l
|
||||
//
|
||||
func (l *Lsdb) ScheduleAdjLsaBuild() {
|
||||
func (l *Lsdb) ScheduleAdjLsaBuild() {
|
||||
}
|
||||
|
||||
//
|
||||
@@ -102,10 +100,10 @@ func (l *Lsdb) ScheduleAdjLsaBuild() {
|
||||
// @receiver l
|
||||
// @param interest
|
||||
//
|
||||
func (l *Lsdb) ProcessInterest(interest *packet.Interest) {
|
||||
func (l *Lsdb) ProcessInterest(interest *packet.Interest) {
|
||||
}
|
||||
|
||||
func (l *Lsdb) ProcessGPPkt(pkt *packet.GPPkt) {
|
||||
func (l *Lsdb) ProcessGPPkt(pkt *packet.GPPkt) {
|
||||
}
|
||||
|
||||
//
|
||||
@@ -152,22 +150,22 @@ func (l *Lsdb) FindLsa(routerIdentifier *component.Identifier,
|
||||
// @return bool
|
||||
//
|
||||
func (l *Lsdb) IsLsaNew(routerIdentifier *component.Identifier,
|
||||
lsaType lsa.LsaType,seqNo uint64) bool {
|
||||
lsa := l.FindLsa(routerIdentifier,lsaType)
|
||||
if lsa.GetSeqNo() >= seqNo{
|
||||
lsaType lsa.LsaType, seqNo uint64) bool {
|
||||
lsa := l.FindLsa(routerIdentifier, lsaType)
|
||||
if lsa.GetSeqNo() >= seqNo {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (l *Lsdb) InstallLsa(lsa lsa.ILsa) {
|
||||
func (l *Lsdb) InstallLsa(lsa lsa.ILsa) {
|
||||
}
|
||||
|
||||
func (l* Lsdb) RemoveLsa(routerIdentifier *component.Identifier,
|
||||
func (l *Lsdb) RemoveLsa(routerIdentifier *component.Identifier,
|
||||
lsaType lsa.LsaType) {
|
||||
}
|
||||
|
||||
func (l* Lsdb) RemoveLsaByContainerIndex(index int) {
|
||||
func (l *Lsdb) RemoveLsaByContainerIndex(index int) {
|
||||
}
|
||||
|
||||
//
|
||||
@@ -176,7 +174,7 @@ func (l* Lsdb) RemoveLsaByContainerIndex(index int) {
|
||||
// 只有当路由器的所有邻居状态是已知的时,才可以构建它的邻接LSA。
|
||||
// @receiver l
|
||||
//
|
||||
func (l *Lsdb) BuildAdjLsa() {
|
||||
func (l *Lsdb) BuildAdjLsa() {
|
||||
}
|
||||
|
||||
//
|
||||
@@ -184,7 +182,7 @@ func (l *Lsdb) BuildAdjLsa() {
|
||||
// @Description: 为当前路由器构建并安装一个邻接LSA
|
||||
// @receiver l
|
||||
//
|
||||
func (l *Lsdb) BuildAndInstallOwnAdjLsa() {
|
||||
func (l *Lsdb) BuildAndInstallOwnAdjLsa() {
|
||||
}
|
||||
|
||||
//
|
||||
@@ -192,19 +190,19 @@ func (l *Lsdb) BuildAndInstallOwnAdjLsa() {
|
||||
// @Description: 在调度器中安排一个刷新或过期事件
|
||||
// @receiver l
|
||||
//
|
||||
func (l *Lsdb) ScheduleLsaExpiration(lsa lsa.ILsa,duration *time.Duration) {
|
||||
func (l *Lsdb) ScheduleLsaExpiration(lsa lsa.ILsa, duration *time.Duration) {
|
||||
|
||||
}
|
||||
|
||||
func (l* Lsdb) ExpireOrRefreshLsa(lsa lsa.ILsa) {
|
||||
func (l *Lsdb) ExpireOrRefreshLsa(lsa lsa.ILsa) {
|
||||
}
|
||||
|
||||
func (l *Lsdb) ProcessInterestForLsa(interest *packet.Interest,
|
||||
originRouterIdentifier *component.Identifier,lsaType lsa.LsaType,seqNo uint64) {
|
||||
originRouterIdentifier *component.Identifier, lsaType lsa.LsaType, seqNo uint64) {
|
||||
}
|
||||
|
||||
func (l *Lsdb) ExpressInterest(interestName *component.Identifier,
|
||||
timeOut uint32,deadline *time.Time) {
|
||||
timeOut uint32, deadline *time.Time) {
|
||||
}
|
||||
|
||||
//
|
||||
@@ -219,9 +217,9 @@ func (l *Lsdb) ExpressInterest(interestName *component.Identifier,
|
||||
// @param lsaName
|
||||
// @param seqNo
|
||||
//
|
||||
func (l *Lsdb) OnFetchLsaError(errorCode uint32,msg string,
|
||||
interestName *component.Identifier,retransmitNo uint32,
|
||||
deadline *time.Time,lsaName *component.Identifier,seqNo uint64) {
|
||||
func (l *Lsdb) OnFetchLsaError(errorCode uint32, msg string,
|
||||
interestName *component.Identifier, retransmitNo uint32,
|
||||
deadline *time.Time, lsaName *component.Identifier, seqNo uint64) {
|
||||
}
|
||||
|
||||
//
|
||||
@@ -233,11 +231,10 @@ func (l *Lsdb) OnFetchLsaError(errorCode uint32,msg string,
|
||||
// @param buffer
|
||||
// @param interestName
|
||||
//
|
||||
func (l *Lsdb) AfterFetchLsa(buffer bytes.Buffer,interestName *component.Identifier) {
|
||||
func (l *Lsdb) AfterFetchLsa(buffer bytes.Buffer, interestName *component.Identifier) {
|
||||
}
|
||||
|
||||
func (l *Lsdb) getLsaExpirationTimePoint() time.Time {
|
||||
// todo
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
NFD RIB Command Processor
|
||||
Reference in New Issue
Block a user