1
0
mirror of https://gitee.com/willfree/mlsr.git synced 2026-06-15 20:44:48 +08:00
Files
mlsr/hello/HelloProtocol.go
T
2022-04-27 16:09:44 +08:00

116 lines
2.8 KiB
Go

//package hello
//@Author: Pei Xinyuan
//@Description:
//@Version: 0.1.0
//@Date: 2022/4/27 10:57:00
//@Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
package hello
import (
"minlib/component"
"minlib/encoding"
"minlib/logicface"
"minlib/packet"
"minlib/security"
"mlsr/common"
"mlsr/lsa"
"mlsr/lsdb"
"time"
)
//INIT_LOGGER(HelloProtocol)
const INFO_COMPONENT = "INFO"
const MLSR_COMPONENT = "MLSR"
type HelloProtocol struct {
encoding.SelfEncodingBase
mlsrConfig *common.MlsrConfig
face *logicface.LogicFace
keychain *security.KeyChain
//RoutingTable
lsdb.Lsdb
scheduler *lsdb.Scheduler
}
//
// expressInterest
// @Description:发送一个Hello兴趣包
// @receiver h
// @param interestNamePrefix
// @param seconds
//
func (h *HelloProtocol) expressInterest(interestNamePrefix *component.Identifier, seconds int) {
var interest packet.Interest
interest.SetName(interestNamePrefix)
interest.SetInterestLifeTime(seconds)
interest.SetMustBeRefresh(true)
interest.SetCanBePrefix(true)
h.face.SendInterest(&interest)
}
//
// sendHelloInterest
// @Description:发送Hello兴趣包给所有的邻居
// @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)
}
}
//调度器
}
//
// processInterest
// @Description: 处理来自邻居的Hello兴趣包
// @receiver h
// @param name
// @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 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)
}
}
}
//
// processInterestTimeOut
// @Description: 尝试通过hello协议重新联系邻居
// @receiver h
// @param interest
//
func (h *HelloProtocol) processInterestTimeOut(interest *packet.Interest) {
}
func (h *HelloProtocol) onContent(interest *packet.Interest, data *packet.Data) {
}