Files
mlsr/mlsrcmd/mlsr.go
T
2022-08-25 06:54:06 -07:00

142 lines
4.1 KiB
Go

// Package mlsrcmd
// @Author: Wang Feng
// @Description:
// @Version: 0.1.0
// @Date: 2022/7/21 21:11
// @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
//
package mlsrcmd
import (
common2 "minlib/common"
"minlib/component"
"minlib/logicface"
"minlib/security"
utils2 "minlib/utils"
"mlsr/common"
"mlsr/hello"
"mlsr/lsa"
"mlsr/lsdb"
"mlsr/mir"
"mlsr/route"
"mlsr/utils"
)
type Mlsr struct {
LOCALHOST_PREFIX *component.Identifier
m_face *logicface.DummyClientLogicFace
m_scheduler *lsdb.MlsrScheduler
m_confParam *common.MlsrConfig
m_adjacencyList *lsa.AdjLsaAdjacenctList
m_namePrefixList *lsa.NameLsaNamePrefixList
//std::vector<ndn::Name> m_strategySetOnRouters; todo 不同前缀使用不同转发策略
m_fibCaller *mir.FibCodeCaller
m_lsdb *lsdb.Lsdb
m_routingTable *route.RoutingTable
m_namePrefixTable *route.NamePrefixTable
m_helloProtocol *hello.HelloProtocol
// 用于异步事件触发的信号量接收器
m_onNewLsaConnection *utils2.Connection
m_onPrefixRegistrationSuccess *utils.SignalConnection
m_onInitialHelloDataValidated *utils.SignalConnection
}
//
// Init
// @Description: Mlsr初始化
// @receiver m
// @param face face
// @param scheduler
// @param passwd mir密码
// @param chain
// @param confParam
//
func (m *Mlsr) Init(face *logicface.DummyClientLogicFace, scheduler *lsdb.MlsrScheduler,
passwd string,
chain *security.KeyChain, confParam *common.MlsrConfig) {
common2.LogDebug("Initializing Mlsr")
// MLSR特有的本地前缀
nameIdentifier, err := component.CreateIdentifierByString("/localhost/nlsr")
if err != nil {
common2.LogFatal("mlsr identifier \"/localhost/nlsr\" create error, ", err)
}
m.LOCALHOST_PREFIX = nameIdentifier
m.m_face = face
m.m_scheduler = scheduler
m.m_confParam = confParam
m.m_adjacencyList = confParam.GetAdjacencys()
m.m_namePrefixList = confParam.GetNamePrefixs()
// fib修改器
m.m_fibCaller = new(mir.FibCodeCaller)
m.m_fibCaller.Init2(passwd, chain)
// lsdb
m.m_lsdb = new(lsdb.Lsdb)
m.m_lsdb.Init(m.m_confParam, m.m_scheduler, m.m_face)
// 路由表
m.m_routingTable = new(route.RoutingTable)
m.m_routingTable.Init(m.m_confParam, m.m_scheduler, m.m_lsdb)
// 名称前缀表
m.m_namePrefixTable = new(route.NamePrefixTable)
m.m_namePrefixTable.Init(m.m_confParam.GetRouterPrefix(), m.m_routingTable,
m.m_routingTable.AfterRoutingChange, m.m_lsdb.OnLsdbModified)
// hello协议
m.m_helloProtocol = new(hello.HelloProtocol)
m.m_helloProtocol.Init(m.m_face, m.m_scheduler, chain, m.m_confParam, m.m_routingTable, m.m_lsdb)
// NewLSAConnection
// sync := m.m_lsdb.GetSync()
// m.m_onNewLsaConnection = m.m_lsdb.
// 三个信号量接收器的触发 todo 还没实现的两个,一个与sync有关,一个与fib有关
// hello信号量接收器
bindHelloFunc := func(args ...interface{}) {
common2.LogInfo("Mlsr.bindHelloFunc")
// Hello协议收到有效Data包,解析其参数为邻居
neighbor := args[0].(*component.Identifier)
// 查看本机是否已知道此路由器
adjInfo := m.m_adjacencyList.FindAdjacencyByRouterIdentifier(neighbor)
if adjInfo != nil {
// todo: 在fib中注册该前缀
// m_fib.registerPrefix(m_confParam.getSyncPrefix(), it->getFaceUri(), it->getLinkCost(),
// ndn::time::milliseconds::max(), ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
}
}
m.m_onInitialHelloDataValidated = m.m_helloProtocol.OnInitialHelloDataValidated.Connect(bindHelloFunc)
}
//
// RegisterStrategyForCerts
// @Description: 为某个前缀设置转发策略
// @receiver m
// @param originRouter
//
func (m *Mlsr) RegisterStrategyForCerts(originRouter *component.Identifier) {
}
//
// AddDispatcherTopPrefix
// @Description: 注册TopPrefix todo 去学习一下MIR原理
// @receiver m
//
func (m *Mlsr) AddDispatcherTopPrefix() {
}
//
// RegisterPrefix
// @Description: 使用MLSR的LogicFace注册一个前缀
// @receiver m
// @param prefix
//
func (m *Mlsr) RegisterPrefix(prefix *component.Identifier) {
}