mirror of
https://gitee.com/willfree/mlsr.git
synced 2026-06-03 15:56:13 +08:00
测试基本通过:RoutingTablePoolEntry & NamePrefixTableEntry
This commit is contained in:
@@ -21,7 +21,7 @@ type NamePrefixTableEntry struct {
|
||||
// 名称前缀
|
||||
m_namePrefix *component.Identifier
|
||||
|
||||
// 保存路由表池项的切片。切片真好用。
|
||||
// 保存路由表池项的切片。go语言切片真好用。
|
||||
// 这是因为,由于支持网内缓存,一个名称前缀可能对应多个路由器标识符。
|
||||
// 名称前缀标项,和路由表项,是多对多的关系。
|
||||
m_rteList []*RoutingTablePoolEntry
|
||||
@@ -29,6 +29,32 @@ type NamePrefixTableEntry struct {
|
||||
NextHopList
|
||||
}
|
||||
|
||||
//
|
||||
// ToString
|
||||
// @Description: 转string,用于测试
|
||||
// @receiver e
|
||||
//
|
||||
func (e *NamePrefixTableEntry) ToString() string {
|
||||
str := "-------名称前缀表项 Start:" + e.m_namePrefix.ToUri() + "------------\n"
|
||||
for i := 0; i < len(e.m_rteList); i++ {
|
||||
str += e.m_rteList[i].ToString()
|
||||
}
|
||||
str += "下一跳列表:\n"
|
||||
str += e.NextHopList.ToString()
|
||||
str += "-------名称前缀表项 End :" + e.m_namePrefix.ToUri() + "------------\n"
|
||||
return str
|
||||
}
|
||||
|
||||
//
|
||||
// Init
|
||||
// @Description: 初始化参数
|
||||
// @receiver e
|
||||
// @param namePrefix
|
||||
//
|
||||
func (e *NamePrefixTableEntry) Init(namePrefix *component.Identifier) {
|
||||
e.m_namePrefix = namePrefix
|
||||
}
|
||||
|
||||
//
|
||||
// GetNamePrefix
|
||||
// @Description: 获取所表示的名称前缀
|
||||
|
||||
@@ -8,8 +8,51 @@
|
||||
|
||||
package route
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"fmt"
|
||||
"minlib/component"
|
||||
"testing"
|
||||
)
|
||||
|
||||
//
|
||||
// TestNamePrefixTable_AddEntry
|
||||
// @Description: 名称前缀表,增加条目
|
||||
// @param t
|
||||
//
|
||||
func TestNamePrefixTable_AddEntry(t *testing.T) {
|
||||
// 第一个RTPE
|
||||
iden, _ := component.CreateIdentifierByString("/RouterC")
|
||||
rtpe := new(RoutingTablePoolEntry)
|
||||
rtpe.InitDest(iden, 123)
|
||||
hop := new(NextHop)
|
||||
hop.Init("tcp://1.1.1.1", 1)
|
||||
rtpe.AddNextHop(hop)
|
||||
|
||||
}
|
||||
// 名称前缀
|
||||
namePrefix, _ := component.CreateIdentifierByString("/pku/pdf")
|
||||
npte := new(NamePrefixTableEntry)
|
||||
npte.Init(namePrefix)
|
||||
// 打印该名称前缀
|
||||
fmt.Println("名称前缀: ", npte.GetNamePrefix().ToUri())
|
||||
|
||||
// 增加rtpe
|
||||
npte.AddRoutingTableEntry(rtpe)
|
||||
fmt.Println(npte.ToString())
|
||||
|
||||
// 第二个rtpe
|
||||
iden2, _ := component.CreateIdentifierByString("/RouterB")
|
||||
rtpe2 := new(RoutingTablePoolEntry)
|
||||
rtpe2.InitDest(iden2, 12)
|
||||
hop2 := new(NextHop)
|
||||
hop2.Init("tcp://1.1.1.0", 1)
|
||||
rtpe2.AddNextHop(hop2)
|
||||
npte.AddRoutingTableEntry(rtpe2)
|
||||
|
||||
// 生成下一跳列表
|
||||
npte.GenerateNhlfromRteList()
|
||||
fmt.Println(npte.ToString())
|
||||
|
||||
// 删除某个rtpe
|
||||
npte.RemoveRoutingTableEntry(rtpe2)
|
||||
fmt.Println(npte.ToString())
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ package route
|
||||
|
||||
import (
|
||||
"minlib/component"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
//
|
||||
@@ -23,6 +24,26 @@ type RoutingTablePoolEntry struct {
|
||||
m_useCount uint64 // 记录本条目被多少条名称前缀所使用
|
||||
}
|
||||
|
||||
//
|
||||
// ToString
|
||||
// @Description: 转string,用于测试
|
||||
// @receiver pe
|
||||
// @return string
|
||||
//
|
||||
func (pe *RoutingTablePoolEntry) ToString() string {
|
||||
str := "-------RoutingTablePoolEntry Start--------\n"
|
||||
str += "use Count: " + strconv.FormatUint(pe.m_useCount, 10) + "\n"
|
||||
str += pe.RoutingTableEntry.ToString()
|
||||
str += "entries len: " + strconv.Itoa(len(pe.NamePrefixTableEntries)) + "\n"
|
||||
str += "NamePrefixTableEntries: "
|
||||
for prefix, _ := range pe.NamePrefixTableEntries {
|
||||
str += prefix + " "
|
||||
}
|
||||
str += "\n"
|
||||
str += "-------RoutingTablePoolEntry End --------\n"
|
||||
return str
|
||||
}
|
||||
|
||||
//
|
||||
// Init
|
||||
// @Description: 初始化目的路由器
|
||||
|
||||
@@ -43,3 +43,27 @@ func TestRoutingTablePoolEntry_InitDest(t *testing.T) {
|
||||
fmt.Println(rtpe.m_useCount)
|
||||
fmt.Println(rtpe.m_destination.ToUri())
|
||||
}
|
||||
|
||||
//
|
||||
// TestRoutingTablePoolEntry_IsEqual
|
||||
// @Description: 测试两个rtpe是否相等
|
||||
// @param t
|
||||
//
|
||||
func TestRoutingTablePoolEntry_IsEqual(t *testing.T) {
|
||||
// 第一个
|
||||
iden, _ := component.CreateIdentifierByString("/ifIhaveAnotherChance")
|
||||
rtpe := new(RoutingTablePoolEntry)
|
||||
rtpe.InitDest(iden, 123)
|
||||
hop := new(NextHop)
|
||||
hop.Init("/f", 1)
|
||||
rtpe.AddNextHop(hop)
|
||||
|
||||
iden2, _ := component.CreateIdentifierByString("/ifIhaveAnotherChance")
|
||||
rtpe2 := new(RoutingTablePoolEntry)
|
||||
rtpe2.InitDest(iden2, 123)
|
||||
hop2 := new(NextHop)
|
||||
hop2.Init("/f", 2)
|
||||
rtpe2.AddNextHop(hop2)
|
||||
|
||||
fmt.Println("是否相等: ", rtpe.IsEqual(rtpe2))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user