1
0
mirror of https://gitee.com/willfree/mlsr.git synced 2026-06-07 03:09:27 +08:00

补充链路状态路由表计算器ing

This commit is contained in:
free will
2022-05-12 12:29:58 +08:00
parent 2966fa3a42
commit dd97958537
@@ -51,7 +51,11 @@ const (
//
func (c *LinkStateRoutingTableCalculator) CalculatePath(routerMap *RouterMap,
rTable *route.RoutingTable,mConfig *common.MlsrConfig,lsdb *lsdb.Lsdb) {
c.allocateAdjMatrix()
c.initMatrix()
_ = c.makeAdjMatrix(lsdb, routerMap)
// 从配置文件中获取源路由器前缀,并根据routerMap获取其映射号
sourceRouter := routerMap.GetMappingNoByRouterName(mConfig)
}
//
@@ -160,32 +164,79 @@ func (c *LinkStateRoutingTableCalculator) isNotExplored(
func (c *LinkStateRoutingTableCalculator) addAllLsNextHopsToRoutingTable(
adjs *lsa.AdjLsaAdjacenctList,rTable *route.RoutingTable,
rMap *RouterMap,sourceRouter int) {
// 对于我们有的每个路由器
for i := 0; i < c.m_nRouters; i++ {
if i!= sourceRouter{
// 获取算法确定的下一跳
nextHopRouter:=c.getLsNextHop(i,sourceRouter)
// 需要该路由器不至于没有对应的下一跳
if nextHopRouter!= NO_NEXT_HOP{
// 获取链路开销
routeCost := c.m_distance[i]
// 根据map获取该路由器的真实名称
nextHopRouterName,b := rMap.GetRouterNameByMappingNo(nextHopRouter)
if b{
// 根据本地邻接LSA列表,获取该下一跳路由器所对应的face
nextHopFaces := adjs.FindAdjacencyByRouterIdentifier(nextHopRouterName)
// todo 将下一跳加入路由表
}
}
}
}
}
//
// getLsNextHop
// @Description: 决定一个目的地的下一跳
// @Description: 决定到目的路由器的下一跳路由器
// @receiver c
// @param dest 我们想要确定其下一跳的路由器
// @param source 来确定下一跳路径的路由器
// @param dest 想要确定的目的路由器
// @param source 路由器
//
func (c *LinkStateRoutingTableCalculator) getLsNextHop(dest int,source int) int {
nextHop := NO_NEXT_HOP
// source的父节点是空节点,故遍历到source或某个断点,就停止循环
for c.m_parent[dest] != EMPTY_PARENT {
nextHop = dest
dest = c.m_parent[dest]
}
if dest != source{
nextHop = NO_NEXT_HOP
}
return nextHop
}
//
// allocateParent
// @Description: 分配内存
// @receiver c
//
func (c *LinkStateRoutingTableCalculator) allocateParent() {
c.m_parent = make([]int,c.m_nRouters)
}
//
// allocateDistance
// @Description: 分配内存
// @receiver c
//
func (c *LinkStateRoutingTableCalculator) allocateDistance() {
c.m_distance = make([]uint64,c.m_nRouters)
}
//
// freeParent
// @Description: 释放内存
// @receiver c
//
func (c *LinkStateRoutingTableCalculator) freeParent() {
// 依靠golang的gc机制
}
//
// freeDistance
// @Description: 释放内存
// @receiver c
//
func (c *LinkStateRoutingTableCalculator) freeDistance() {
// 依靠golang的gc机制
}