mirror of
https://gitee.com/willfree/mlsr.git
synced 2026-10-04 19:42:02 +08:00
105 lines
3.2 KiB
Go
105 lines
3.2 KiB
Go
// Package hello
|
|
// @Author: Pei Xinyuan
|
|
// @Description:
|
|
// @Version: 0.1.0
|
|
// @Date: 2022/7/14 14:49
|
|
// @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
|
//
|
|
|
|
package hello
|
|
|
|
import (
|
|
common2 "minlib/common"
|
|
"minlib/component"
|
|
"minlib/logicface"
|
|
"minlib/packet"
|
|
"minlib/security"
|
|
"mlsr/common"
|
|
"mlsr/lsa"
|
|
"mlsr/lsdb"
|
|
"mlsr/route"
|
|
)
|
|
|
|
// 用于hello兴趣包的名称的组件
|
|
const INFO_COMPONENT = "INFO"
|
|
const MLSR_COMPONENT = "mlsr"
|
|
|
|
// 正常收到数据包的触发函数
|
|
type DataCallback = func(interest *packet.Interest, data *packet.Data)
|
|
|
|
// 收到NACK的触发函数
|
|
type NackCallback = func(interest *packet.Interest, nack *packet.Nack)
|
|
|
|
// 超时未响应的触发函数
|
|
type TimeoutCallback = func(interest *packet.Interest)
|
|
|
|
//type OptionalNack = *packet.Nack
|
|
|
|
type HelloProtocol struct {
|
|
m_face *logicface.LogicFace
|
|
m_scheduler *lsdb.MlsrScheduler
|
|
m_keychain *security.KeyChain
|
|
mlsrConfig *common.MlsrConfig
|
|
m_routingTable *route.RoutingTable
|
|
m_lsdb *lsdb.Lsdb
|
|
m_adjacencyList *lsa.AdjLsaAdjacenctList
|
|
|
|
// 收包池
|
|
receivePacketQue chan *packet.Interest // 从其它路由器收包后,放入该队列
|
|
state bool // 程序生成状态, true 为正常运行, false 为关闭状态
|
|
}
|
|
|
|
//
|
|
// Init
|
|
// @Description: Hello协议-初始化
|
|
// @receiver hp
|
|
// @param face
|
|
// @param scheduler
|
|
// @param keychain
|
|
// @param mlsrConfig
|
|
// @param routingTable
|
|
// @param mlsdb
|
|
//
|
|
func (hp *HelloProtocol) Init(face *logicface.LogicFace,
|
|
scheduler *lsdb.MlsrScheduler,
|
|
keychain *security.KeyChain, mlsrConfig *common.MlsrConfig,
|
|
routingTable *route.RoutingTable, mlsdb *lsdb.Lsdb) {
|
|
hp.m_face = face
|
|
hp.m_scheduler = scheduler
|
|
hp.m_keychain = keychain
|
|
hp.mlsrConfig = mlsrConfig
|
|
hp.m_routingTable = routingTable
|
|
hp.m_lsdb = mlsdb
|
|
hp.m_adjacencyList = mlsrConfig.GetAdjacencys()
|
|
|
|
// todo mlsr大联调时应取消以下代码的注释
|
|
// 构造接收hello兴趣包的前缀
|
|
name, err := component.CreateIdentifierByString(
|
|
hp.mlsrConfig.GetRouterPrefix().ToUri() + "/" + MLSR_COMPONENT + "/" + INFO_COMPONENT)
|
|
if err != nil {
|
|
common2.LogFatal("HelloProtocol Setting interest filter for Hello interest error, interest generate wrong.")
|
|
return
|
|
}
|
|
// 设置监听前缀
|
|
err = hp.m_face.RegisterIdentifier(name, 3000)
|
|
if err != nil {
|
|
common2.LogFatal("HelloProtocol Setting interest filter for Hello interest error, identifier register wrong.")
|
|
return
|
|
}
|
|
// 开一个线程去接收前缀为hello协议所监听前缀的兴趣包,并进行处理
|
|
hp.receivePacketQue = make(chan *packet.Interest, 1000)
|
|
hp.state = true
|
|
// 启动处理接收到的包的协程
|
|
go hp.dealWithRecvPktRoutine()
|
|
// 启动从客户端接收包的协程
|
|
go hp.recvPacketFromClientRoutine()
|
|
}
|
|
|
|
func (hp *HelloProtocol) expressInterest(interestName *component.Identifier, seconds uint32) {
|
|
common2.LogDebug("HelloProtocol Expressing Interest: " + interestName.ToUri())
|
|
interest := packet.NewInterest()
|
|
interest.SetName(interestName)
|
|
interest.SetInterestLifeTime(2000)
|
|
// todo 这里需要实现的是,将兴趣包通过face发出,并对超时、nack、正常应答三种情况进行处理
|
|
}
|