mirror of
https://gitee.com/willfree/mlsr.git
synced 2026-06-03 15:56:13 +08:00
新建路由表池条目、名称前缀表条目、名称前缀表三个结构体,并实现路由表池条目
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
// Package route
|
||||
// @Author: Wang Feng
|
||||
// @Description:
|
||||
// @Version: 0.1.0
|
||||
// @Date: 2022/6/10 11:16
|
||||
// @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
//
|
||||
|
||||
package route
|
||||
|
||||
import (
|
||||
"container/list"
|
||||
"minlib/component"
|
||||
)
|
||||
|
||||
//
|
||||
// NamePrefixTable
|
||||
// @Description: 名称前缀表
|
||||
//
|
||||
type NamePrefixTable struct {
|
||||
// 路由表池:存储“目的路由器标识->RTPE”的映射
|
||||
// 相当于存储了所有拥有前缀的路由表项,并包含每个路由表项对应的前缀列表信息,以及该前缀列表长度useCount
|
||||
m_rtpool map[*component.Identifier]*RoutingTablePoolEntry
|
||||
// 名称前缀表项列表
|
||||
nptEntryList list.List
|
||||
// 该名称前缀表所属的本机路由器标识
|
||||
m_ownRouterName *component.Identifier
|
||||
// 路由表。包含路由计算器计算出来的每个路由表标识及其对应的下一跳列表
|
||||
m_routingTable *RoutingTable
|
||||
// todo fib
|
||||
}
|
||||
@@ -8,9 +8,29 @@
|
||||
|
||||
package route
|
||||
|
||||
import "minlib/component"
|
||||
import (
|
||||
"container/list"
|
||||
"minlib/component"
|
||||
)
|
||||
|
||||
//
|
||||
// NamePrefixTableEntry
|
||||
// @Description: 名称前缀表项
|
||||
//
|
||||
type NamePrefixTableEntry struct {
|
||||
// 名称前缀
|
||||
m_namePrefix *component.Identifier
|
||||
|
||||
// 保存路由表池项列表。
|
||||
// 这是因为,由于支持网内缓存,一个名称前缀可能对应多个路由器标识符。
|
||||
// 名称前缀标项,和路由表项,是多对多的关系。
|
||||
m_rteList list.List
|
||||
// 下一跳列表
|
||||
NextHopList
|
||||
}
|
||||
|
||||
func (e *NamePrefixTableEntry) TestList() {
|
||||
e.m_rteList.Init()
|
||||
rtpe := new(RoutingTablePoolEntry)
|
||||
e.m_rteList.PushBack(rtpe)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
// Package route
|
||||
// @Author: Wang Feng
|
||||
// @Description:
|
||||
// @Version: 0.1.0
|
||||
// @Date: 2022/6/10 11:02
|
||||
// @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
//
|
||||
|
||||
package route
|
||||
|
||||
import (
|
||||
"minlib/component"
|
||||
)
|
||||
|
||||
//
|
||||
// RoutingTablePoolEntry
|
||||
// @Description: 路由表池条目。
|
||||
//
|
||||
type RoutingTablePoolEntry struct {
|
||||
RoutingTableEntry
|
||||
// 记录使用本池条目的所有名称前缀
|
||||
NamePrefixTableEntries map[*component.Identifier]*NamePrefixTableEntry
|
||||
m_useCount uint64 // 记录本条目被多少条名称前缀所使用
|
||||
}
|
||||
|
||||
//
|
||||
// Init
|
||||
// @Description: 初始化目的路由器
|
||||
// @receiver pe
|
||||
// @param dest
|
||||
//
|
||||
func (pe *RoutingTablePoolEntry) Init(dest *component.Identifier) {
|
||||
pe.m_destination = dest
|
||||
pe.m_useCount = 1
|
||||
}
|
||||
|
||||
//
|
||||
// InitRTE
|
||||
// @Description: 初始化路由表项和使用数
|
||||
// @receiver pe
|
||||
// @param rte
|
||||
// @param useCount
|
||||
//
|
||||
func (pe *RoutingTablePoolEntry) InitRTE(rte *RoutingTableEntry, useCount uint64) {
|
||||
pe.m_destination = rte.m_destination
|
||||
pe.nextHops = rte.GetNextHops()
|
||||
pe.m_useCount = useCount
|
||||
}
|
||||
|
||||
//
|
||||
// InitDest
|
||||
// @Description: 初始化目的路由器和使用数
|
||||
// @receiver pe
|
||||
// @param dest
|
||||
// @param useCount
|
||||
//
|
||||
func (pe *RoutingTablePoolEntry) InitDest(dest *component.Identifier, useCount uint64) {
|
||||
pe.m_destination = dest
|
||||
pe.m_useCount = useCount
|
||||
}
|
||||
|
||||
//
|
||||
// GetUseCount
|
||||
// @Description: 获取使用数
|
||||
// @receiver pe
|
||||
// @return uint64
|
||||
//
|
||||
func (pe *RoutingTablePoolEntry) GetUseCount() uint64 {
|
||||
return pe.m_useCount
|
||||
}
|
||||
|
||||
//
|
||||
// IncrementUseCount
|
||||
// @Description: 使用数加一,并返回
|
||||
// @receiver pe
|
||||
// @return uint64
|
||||
//
|
||||
func (pe *RoutingTablePoolEntry) IncrementUseCount() uint64 {
|
||||
pe.m_useCount++
|
||||
return pe.m_useCount
|
||||
}
|
||||
|
||||
//
|
||||
// DecrementUseCount
|
||||
// @Description: 使用数减一,并返回
|
||||
// @receiver pe
|
||||
// @return uint64
|
||||
//
|
||||
func (pe *RoutingTablePoolEntry) DecrementUseCount() uint64 {
|
||||
if pe.m_useCount != 0 {
|
||||
pe.m_useCount--
|
||||
return pe.m_useCount
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
//
|
||||
// SetNexthopList
|
||||
// @Description: 设置下一跳列表
|
||||
// @receiver pe
|
||||
// @param list
|
||||
//
|
||||
func (pe *RoutingTablePoolEntry) SetNexthopList(list NextHopList) {
|
||||
pe.NextHopList = list
|
||||
}
|
||||
Reference in New Issue
Block a user