修改配置管理器中关于邻接列表和名称列表的读取;增加支持邻接列表判断当前邻接列表对周围路由器的探测结果;实现LSDB中构建邻接LSA的功能

This commit is contained in:
free will committed 2022-06-03 21:59:11 +08:00
1 parent aa5018cf9d
commit 4592b554ed
6 files changed
+238 -103

No files matched your search

+57 -18
View File
@@ -47,6 +47,11 @@ type MlsrConfigParameters struct {
// 时间:FIB更新
m_RoutingCalcInterval time.Duration
// 邻接信息列表
m_adjl *lsa.AdjLsaAdjacenctList
// 命名前缀列表
m_npl *lsa.NameLsaNamePrefixList
}
// MlsrConfig初始化
@@ -58,6 +63,9 @@ func (mcp *MlsrConfigParameters) Init(config *MlsrConfig) {
_ = mcp.buildRouterAndSyncUserPrefix()
// 构建时间间隔
mcp.genDurations()
// 构建邻接表和名称前缀表
mcp.InitAdjacencyList()
mcp.InitNamePrefixList()
}
//
@@ -360,13 +368,12 @@ func (mcp *MlsrConfigParameters) GetMaxFacesPerPrefix() int {
}
//
// GetAdjacencyList
// @Description: 从配置文件中获取邻接信息列表
// InitAdjacencyList
// @Description: 从配置文件中初始化邻接信息列表
// @receiver mcp
// @return []*lsa.AdjLsaAdjacencyInfo
//
func (mcp *MlsrConfigParameters) GetAdjacencyList() []*lsa.AdjLsaAdjacencyInfo {
adjInfos := []*lsa.AdjLsaAdjacencyInfo{}
func (mcp *MlsrConfigParameters) InitAdjacencyList() {
mcp.m_adjl = new(lsa.AdjLsaAdjacenctList)
neighborConfigs := mcp.mlsrconf.neighbors
for i := 0; i < len(neighborConfigs); i++ {
// 根据配置文件构造每条邻接链路信息
@@ -385,19 +392,12 @@ func (mcp *MlsrConfigParameters) GetAdjacencyList() []*lsa.AdjLsaAdjacencyInfo {
faceId.SetLogicFaceId(0)
adjInfo := lsa.NewAdjLsaAdjacencyInfo(linkCost, faceUri, faceId, iden, 0, lsa.STATUS_INACTIVE)
// 加入信息列表
adjInfos = append(adjInfos, adjInfo)
mcp.m_adjl.Insert(adjInfo)
}
return adjInfos
}
//
// GetNamePrefixList
// @Description: 从配置文件中获取名称前缀信息列表
// @receiver mcp
// @return []*lsa.NameLsaNamePrefixInfo
//
func (mcp *MlsrConfigParameters) GetNamePrefixList() []*lsa.NameLsaNamePrefixInfo {
infos := []*lsa.NameLsaNamePrefixInfo{}
func (mcp *MlsrConfigParameters) InitNamePrefixList() {
mcp.m_npl = new(lsa.NameLsaNamePrefixList)
// 从配置文件读取广播前缀
adverPrefixs := mcp.mlsrconf.AdvertisingConfig.Prefixs
for i := 0; i < len(adverPrefixs); i++ {
@@ -410,10 +410,49 @@ func (mcp *MlsrConfigParameters) GetNamePrefixList() []*lsa.NameLsaNamePrefixInf
}
namePrefixInfo.NamePrefix = iden
namePrefixInfo.InsertSource("")
// 将该名称前缀信息加入切片
infos = append(infos, namePrefixInfo)
// 将该名称前缀信息加入列表
mcp.m_npl.InsertNamePrefixInfo(namePrefixInfo)
}
return infos
}
//
// GetAdjacencyList
// @Description: 从配置文件中获取邻接信息列表
// @receiver mcp
// @return []*lsa.AdjLsaAdjacencyInfo
//
func (mcp *MlsrConfigParameters) GetAdjacencyList() []*lsa.AdjLsaAdjacencyInfo {
return mcp.m_adjl.GetAdjList()
}
//
// GetAdjacencys
// @Description: 获取整体的邻接信息
// @receiver mcp
// @return *lsa.AdjLsaAdjacenctList
//
func (mcp *MlsrConfigParameters) GetAdjacencys() *lsa.AdjLsaAdjacenctList {
return mcp.m_adjl
}
//
// GetNamePrefixList
// @Description: 从配置文件中获取名称前缀信息列表
// @receiver mcp
// @return []*lsa.NameLsaNamePrefixInfo
//
func (mcp *MlsrConfigParameters) GetNamePrefixList() []*lsa.NameLsaNamePrefixInfo {
return mcp.m_npl.GetNamePrefixList()
}
//
// GetNamePrefixs
// @Description: 获取整体的名称前缀信息
// @receiver mcp
// @return *lsa.NameLsaNamePrefixList
//
func (mcp *MlsrConfigParameters) GetNamePrefixs() *lsa.NameLsaNamePrefixList {
return mcp.m_npl
}
func (mcp *MlsrConfigParameters) GetKeyChain() {
+82 -78
View File
@@ -58,7 +58,7 @@ func (l *AdjLsaAdjacenctList) ToString() string {
resString += "[ "
for i := 0; i < l.Size(); i++ {
resString += l.GetAdjList()[i].ToString()
if i < (l.Size()-1){
if i < (l.Size() - 1) {
resString += ", "
}
}
@@ -74,8 +74,8 @@ func (l *AdjLsaAdjacenctList) ToString() string {
// @return bool
//
func (l *AdjLsaAdjacenctList) IsNeighbor(routerIdentifier *component.Identifier) bool {
for i:=0; i<len(l.lsaAdjacencys); i++ {
if l.lsaAdjacencys[i].lsaNeighborRouterIdentifier.ToUri()==routerIdentifier.ToUri(){
for i := 0; i < len(l.lsaAdjacencys); i++ {
if l.lsaAdjacencys[i].lsaNeighborRouterIdentifier.ToUri() == routerIdentifier.ToUri() {
return true
}
}
@@ -91,13 +91,13 @@ func (l *AdjLsaAdjacenctList) IsNeighbor(routerIdentifier *component.Identifier)
// @return int
// @return error
//
func (l *AdjLsaAdjacenctList) findIndexByRouterIdentifier(routerIdentifier *component.Identifier) (int,error) {
for i:=0; i<len(l.lsaAdjacencys); i++ {
if l.lsaAdjacencys[i].lsaNeighborRouterIdentifier.ToUri()==routerIdentifier.ToUri(){
return i,nil
func (l *AdjLsaAdjacenctList) findIndexByRouterIdentifier(routerIdentifier *component.Identifier) (int, error) {
for i := 0; i < len(l.lsaAdjacencys); i++ {
if l.lsaAdjacencys[i].lsaNeighborRouterIdentifier.ToUri() == routerIdentifier.ToUri() {
return i, nil
}
}
return -1,errors.New("no found the identifier")
return -1, errors.New("no found the identifier")
}
//
@@ -109,9 +109,9 @@ func (l *AdjLsaAdjacenctList) findIndexByRouterIdentifier(routerIdentifier *comp
// @return error
//
func (l *AdjLsaAdjacenctList) IncrementTimedOutInterestCount(routerIdentifier *component.Identifier) error {
if index,err:=l.findIndexByRouterIdentifier(routerIdentifier);err!=nil{
if index, err := l.findIndexByRouterIdentifier(routerIdentifier); err != nil {
return err
}else{
} else {
l.lsaAdjacencys[index].InterestTimedOutNo++
return nil
}
@@ -127,10 +127,10 @@ func (l *AdjLsaAdjacenctList) IncrementTimedOutInterestCount(routerIdentifier *c
// @return error
//
func (l *AdjLsaAdjacenctList) SetTimedOutInterestCount(routerIdentifier *component.Identifier, count uint32) error {
if index,err:=l.findIndexByRouterIdentifier(routerIdentifier);err!=nil{
if index, err := l.findIndexByRouterIdentifier(routerIdentifier); err != nil {
return err
}else{
l.lsaAdjacencys[index].InterestTimedOutNo=count
} else {
l.lsaAdjacencys[index].InterestTimedOutNo = count
return nil
}
}
@@ -143,11 +143,11 @@ func (l *AdjLsaAdjacenctList) SetTimedOutInterestCount(routerIdentifier *compone
// @return uint32
// @return error
//
func (l *AdjLsaAdjacenctList) GetTimedOutInterestCount(routerIdentifier *component.Identifier) (uint32,error) {
if index,err:=l.findIndexByRouterIdentifier(routerIdentifier);err!=nil{
return 0,err
}else{
return l.lsaAdjacencys[index].InterestTimedOutNo,nil
func (l *AdjLsaAdjacenctList) GetTimedOutInterestCount(routerIdentifier *component.Identifier) (uint32, error) {
if index, err := l.findIndexByRouterIdentifier(routerIdentifier); err != nil {
return 0, err
} else {
return l.lsaAdjacencys[index].InterestTimedOutNo, nil
}
}
@@ -159,11 +159,11 @@ func (l *AdjLsaAdjacenctList) GetTimedOutInterestCount(routerIdentifier *compone
// @return int
// @return error
//
func (l *AdjLsaAdjacenctList) GetStatusOfNeighbor(routerIdentifier *component.Identifier) (int,error) {
if index,err:=l.findIndexByRouterIdentifier(routerIdentifier);err!=nil{
return -2,err
}else{
return l.lsaAdjacencys[index].Status,nil
func (l *AdjLsaAdjacenctList) GetStatusOfNeighbor(routerIdentifier *component.Identifier) (int, error) {
if index, err := l.findIndexByRouterIdentifier(routerIdentifier); err != nil {
return -2, err
} else {
return l.lsaAdjacencys[index].Status, nil
}
}
@@ -175,35 +175,39 @@ func (l *AdjLsaAdjacenctList) GetStatusOfNeighbor(routerIdentifier *component.Id
// @param status
// @return error
//
func (l *AdjLsaAdjacenctList) SetStatusOfNeighbor(routerIdentifier *component.Identifier,status int) error {
if index,err:=l.findIndexByRouterIdentifier(routerIdentifier);err!=nil{
func (l *AdjLsaAdjacenctList) SetStatusOfNeighbor(routerIdentifier *component.Identifier, status int) error {
if index, err := l.findIndexByRouterIdentifier(routerIdentifier); err != nil {
return err
}else{
l.lsaAdjacencys[index].Status=status
} else {
l.lsaAdjacencys[index].Status = status
return nil
}
}
//
// isAdjLsaBuildable
// @Description: 当所有邻居的状态可知时,此表可用于构建邻接LSA。
// 当邻居状态是ACTIVE或INACTIVE时,就表示此邻居状态可知;
// 当一个邻居还在被联络,即在发送hello兴趣包给它时,则此邻居状态为UNKNOWN。
// 在Nlsr中,本函数的代码实现与代码注释不一致,后面可以进一步研究其原因,甚至可以提交issue给nlsr项目组。
// @Description: 判断邻接LSA是否要被再次构建
// @receiver l
// @param interestRetryNo 联系邻居的hello兴趣包的最大重传次数
// @return bool 此邻接表的实体对象是否能够用于构建一个邻接LSA
//
func (l *AdjLsaAdjacenctList) IsAdjLsaBuildable(interestRetryNo uint32) bool {
for i:=0; i<len(l.lsaAdjacencys); i++ {
switch l.lsaAdjacencys[i].Status{
case STATUS_UNKNOWN:
if l.lsaAdjacencys[i].InterestTimedOutNo<interestRetryNo{
return false
}
nTimedOutNeighbors := 0
for i := 0; i < len(l.lsaAdjacencys); i++ {
if l.lsaAdjacencys[i].Status == STATUS_ACTIVE {
// 有已经知道在激活状态的邻居,则将其安装到LSDB
return true
} else if l.lsaAdjacencys[i].InterestTimedOutNo >= interestRetryNo {
// 如果邻居全部都没有激活,且兴趣包尝试次数超出最大值,就删掉本机的邻接LSA
nTimedOutNeighbors++
}
}
return true
if nTimedOutNeighbors == len(l.lsaAdjacencys) {
return true
} else {
// 既没有激活邻居,又还在尝试查看邻居情况,则继续安排构建邻接LSA
return false
}
}
//
@@ -214,11 +218,11 @@ func (l *AdjLsaAdjacenctList) IsAdjLsaBuildable(interestRetryNo uint32) bool {
// @return *AdjLsaAdjacencyInfo
// @return error
//
func (l *AdjLsaAdjacenctList) GetAdjacency(routerIdentifier *component.Identifier) (*AdjLsaAdjacencyInfo,error){
if index,err:=l.findIndexByRouterIdentifier(routerIdentifier);err!=nil{
return nil,err
}else{
return l.lsaAdjacencys[index],nil
func (l *AdjLsaAdjacenctList) GetAdjacency(routerIdentifier *component.Identifier) (*AdjLsaAdjacencyInfo, error) {
if index, err := l.findIndexByRouterIdentifier(routerIdentifier); err != nil {
return nil, err
} else {
return l.lsaAdjacencys[index], nil
}
}
@@ -229,9 +233,9 @@ func (l *AdjLsaAdjacenctList) GetAdjacency(routerIdentifier *component.Identifie
// @return int
//
func (l *AdjLsaAdjacenctList) GetNumOfActiveNeighbor() int {
numbers:=0
for i:=0; i<len(l.lsaAdjacencys); i++ {
switch l.lsaAdjacencys[i].Status{
numbers := 0
for i := 0; i < len(l.lsaAdjacencys); i++ {
switch l.lsaAdjacencys[i].Status {
case STATUS_ACTIVE:
numbers++
}
@@ -246,9 +250,9 @@ func (l *AdjLsaAdjacenctList) GetNumOfActiveNeighbor() int {
// @return int
//
func (l *AdjLsaAdjacenctList) GetNumOfINActiveNeighbor() int {
numbers:=0
for i:=0; i<len(l.lsaAdjacencys); i++ {
switch l.lsaAdjacencys[i].Status{
numbers := 0
for i := 0; i < len(l.lsaAdjacencys); i++ {
switch l.lsaAdjacencys[i].Status {
case STATUS_INACTIVE:
numbers++
}
@@ -263,9 +267,9 @@ func (l *AdjLsaAdjacenctList) GetNumOfINActiveNeighbor() int {
// @return int
//
func (l *AdjLsaAdjacenctList) GetNumOfUnknownNeighbor() int {
numbers:=0
for i:=0; i<len(l.lsaAdjacencys); i++ {
switch l.lsaAdjacencys[i].Status{
numbers := 0
for i := 0; i < len(l.lsaAdjacencys); i++ {
switch l.lsaAdjacencys[i].Status {
case STATUS_UNKNOWN:
numbers++
}
@@ -288,8 +292,8 @@ func (l *AdjLsaAdjacenctList) Size() int {
// @Description: 清空所有邻接信息
// @receiver l
//
func (l *AdjLsaAdjacenctList) Reset() {
l.lsaAdjacencys=[]*AdjLsaAdjacencyInfo{}
func (l *AdjLsaAdjacenctList) Reset() {
l.lsaAdjacencys = []*AdjLsaAdjacencyInfo{}
}
//
@@ -304,17 +308,17 @@ func (l *AdjLsaAdjacenctList) Reset() {
//
func (l *AdjLsaAdjacenctList) FindAdjacencysByRouterIdentifier(routerIdentifier *component.Identifier) []*AdjLsaAdjacencyInfo {
var infos []*AdjLsaAdjacencyInfo
for i:=0; i<len(l.lsaAdjacencys); i++ {
if l.lsaAdjacencys[i].lsaNeighborRouterIdentifier.ToUri()==routerIdentifier.ToUri(){
infos=append(infos,l.lsaAdjacencys[i])
for i := 0; i < len(l.lsaAdjacencys); i++ {
if l.lsaAdjacencys[i].lsaNeighborRouterIdentifier.ToUri() == routerIdentifier.ToUri() {
infos = append(infos, l.lsaAdjacencys[i])
}
}
return infos
}
func (l *AdjLsaAdjacenctList) FindAdjacencyByRouterIdentifier(routerIdentifier *component.Identifier) *AdjLsaAdjacencyInfo {
for i:=0; i<len(l.lsaAdjacencys); i++ {
if l.lsaAdjacencys[i].lsaNeighborRouterIdentifier.ToUri()==routerIdentifier.ToUri(){
for i := 0; i < len(l.lsaAdjacencys); i++ {
if l.lsaAdjacencys[i].lsaNeighborRouterIdentifier.ToUri() == routerIdentifier.ToUri() {
return l.lsaAdjacencys[i]
}
}
@@ -330,9 +334,9 @@ func (l *AdjLsaAdjacenctList) FindAdjacencyByRouterIdentifier(routerIdentifier *
//
func (l *AdjLsaAdjacenctList) FindAdjacencyByLogicFaceId(id *AdjLsaLogicFaceId) []*AdjLsaAdjacencyInfo {
var infos []*AdjLsaAdjacencyInfo
for i:=0; i<len(l.lsaAdjacencys); i++ {
if l.lsaAdjacencys[i].LogicFaceId()==id.Value(){
infos=append(infos,l.lsaAdjacencys[i])
for i := 0; i < len(l.lsaAdjacencys); i++ {
if l.lsaAdjacencys[i].LogicFaceId() == id.Value() {
infos = append(infos, l.lsaAdjacencys[i])
}
}
return infos
@@ -347,21 +351,21 @@ func (l *AdjLsaAdjacenctList) FindAdjacencyByLogicFaceId(id *AdjLsaLogicFaceId)
//
func (l *AdjLsaAdjacenctList) FindAdjacencyByLogicFaceUri(uri *AdjLsaLogicFaceUri) []*AdjLsaAdjacencyInfo {
var infos []*AdjLsaAdjacencyInfo
for i:=0; i<len(l.lsaAdjacencys); i++ {
if l.lsaAdjacencys[i].AdjLsaLogicFaceUri.Value()==uri.Value(){
infos=append(infos,l.lsaAdjacencys[i])
for i := 0; i < len(l.lsaAdjacencys); i++ {
if l.lsaAdjacencys[i].AdjLsaLogicFaceUri.Value() == uri.Value() {
infos = append(infos, l.lsaAdjacencys[i])
}
}
return infos
}
func (l *AdjLsaAdjacenctList) getLogicFaceId(uri *AdjLsaLogicFaceUri) (uint64,error) {
for i:=0; i<len(l.lsaAdjacencys); i++ {
if l.lsaAdjacencys[i].AdjLsaLogicFaceUri.Value()==uri.Value(){
return l.lsaAdjacencys[i].AdjLsaLogicFaceId.Value(),nil
func (l *AdjLsaAdjacenctList) getLogicFaceId(uri *AdjLsaLogicFaceUri) (uint64, error) {
for i := 0; i < len(l.lsaAdjacencys); i++ {
if l.lsaAdjacencys[i].AdjLsaLogicFaceUri.Value() == uri.Value() {
return l.lsaAdjacencys[i].AdjLsaLogicFaceId.Value(), nil
}
}
return 0,errors.New("not found the AdjLsaLogicFaceUri in the list")
return 0, errors.New("not found the AdjLsaLogicFaceUri in the list")
}
//
@@ -372,19 +376,19 @@ func (l *AdjLsaAdjacenctList) getLogicFaceId(uri *AdjLsaLogicFaceUri) (uint64,er
// @return int
// @return error
//
func (l *AdjLsaAdjacenctList) WireEncode(encoder *encoding.Encoder) (int,error) {
func (l *AdjLsaAdjacenctList) WireEncode(encoder *encoding.Encoder) (int, error) {
// 判断列表长度,为0则抛出错误
if len(l.lsaAdjacencys)==0 {
return 0,errors.New("Invalid AdjLsaAdjacencyList, expect at least one AdjLsaAdjacencyInfo!")
if len(l.lsaAdjacencys) == 0 {
return 0, errors.New("Invalid AdjLsaAdjacencyList, expect at least one AdjLsaAdjacencyInfo!")
}
totalLength := 0
// 编码 TLV-VALUE
// 反向遍历,可以保证解码的时候正向输出
for i:=len(l.lsaAdjacencys)-1; i>=0; i-- {
if l.lsaAdjacencys[i]==nil {
for i := len(l.lsaAdjacencys) - 1; i >= 0; i-- {
if l.lsaAdjacencys[i] == nil {
continue
}
tmpLen,err := l.lsaAdjacencys[i].WireEncode(encoder)
tmpLen, err := l.lsaAdjacencys[i].WireEncode(encoder)
if err != nil {
return 0, err
}
@@ -405,7 +409,7 @@ func (l *AdjLsaAdjacenctList) WireEncode(encoder *encoding.Encoder) (int,error)
}
totalLength += tmpLen
return totalLength,nil
return totalLength, nil
}
//
@@ -436,4 +440,4 @@ func (l *AdjLsaAdjacenctList) WireDecode(block *encoding.Block) error {
}
l.lsaAdjacencys = adjacencyContainer
return nil
}
}
+10
View File
@@ -22,6 +22,16 @@ type NameLsaNamePrefixList struct {
lsaNamePrefixs LsaNamePrefixContainer
}
//
// GetNamePrefixList
// @Description: 获取名称前缀列表
// @receiver l
// @return []*NameLsaNamePrefixInfo
//
func (l *NameLsaNamePrefixList) GetNamePrefixList() []*NameLsaNamePrefixInfo {
return l.lsaNamePrefixs
}
//
// InsertNamePrefixList
// @Description: 插入一张名称前缀信息列表
@@ -154,6 +154,14 @@ func (bdb *LsaContainer_BuntDB) Exists(lsa lsa.ILsa) bool {
return false
}
//
// ExistsRouterNameAndType
// @Description: 判断是否存在某个lsa
// @receiver bdb
// @param routerIdentifier
// @param lsaType
// @return bool
//
func (bdb *LsaContainer_BuntDB) ExistsRouterNameAndType(routerIdentifier *component.Identifier, lsaType lsa.LsaType) bool {
errRes := bdb.db.View(func(tx *buntdb.Tx) error {
// 获取key
@@ -210,7 +218,7 @@ func (bdb *LsaContainer_BuntDB) Emplace(lsa lsa.ILsa) error {
//
// Erase
// @Description: 删除一个lsa:根据routerIdentifier和lsaType
// @Description: 删除一个lsa
// @receiver bdb
// @param lsa
//
@@ -223,6 +231,24 @@ func (bdb *LsaContainer_BuntDB) EraseLsa(lsa lsa.ILsa) error {
return err
}
//
// EraseLsaByNameAndType
// @Description: 删除一个lsa:根据routerIdentifier和lsaType
// @receiver bdb
// @param routerIdentifier
// @param lsaType
// @return error
//
func (bdb *LsaContainer_BuntDB) EraseLsaByNameAndType(routerIdentifier *component.Identifier,
lsaType lsa.LsaType) error {
key := getKeyFromNameAndType(routerIdentifier, lsaType)
err := bdb.EraseLsaByKey(key)
if err != nil {
common2.LogError("buntdb EraseLsa error, because of ", err.Error())
}
return err
}
//
// EraseLsaByKey
// @Description: 删除一个lsa,根据其在db中的key
+60 -4
View File
@@ -136,6 +136,7 @@ func (l *Lsdb) BuildAndInstallOwnNameLsa() {
l.sequencingManager.IncreaseNameLsaSeq()
// todo: 使用sync通知路由更新
// m_sync.publishRoutingUpdate(Lsa::Type::NAME, m_sequencingManager.getNameLsaSeq());
// 安装lsa到LSDB
l.InstallLsa(nlsa)
@@ -147,7 +148,7 @@ func (l *Lsdb) BuildAndInstallOwnNameLsa() {
// @receiver l
//
func (l *Lsdb) BuildAndInstallOwnCoordinateLsa() {
// todo
// todo:坐标计算预留接口
}
//
@@ -176,7 +177,8 @@ func (l *Lsdb) ScheduleAdjLsaBuild() {
//
// ProcessInterest
// @Description: 处理兴趣包。类似NDN的拉式传输。
// @Description:收到一个兴趣包,根据兴趣包名称,查找LSA并返回。
// 处理兴趣包。类似NDN的拉式传输。
// 在NLSR的设计中,由于对兴趣包进行了进一步的分段,因此有以下两种兴趣包:
//* 1) 需要从segment fetcher中查找的兴趣包:
//* /localhop/<network>/nlsr/LSA/<site>/<router>/<lsaType>/<seqNo>
@@ -188,6 +190,10 @@ func (l *Lsdb) ScheduleAdjLsaBuild() {
func (l *Lsdb) ProcessInterest(interest *packet.Interest) {
}
func (l Lsdb) processInterestForLsa() bool {
return true
}
func (l *Lsdb) ProcessGPPkt(pkt *packet.GPPkt) {
}
@@ -301,10 +307,24 @@ func (l *Lsdb) RemoveLsa(lsa lsa.ILsa) {
common2.LogError("")
return
}
common2.LogDebug("Removing LSA: ", lsa.ToString())
common2.LogDebug("Removed LSA: ", lsa.ToString())
}
func (l *Lsdb) RemoveLsaByContainerIndex(index int) {
//
// RemoveLsaByNameAndType
// @Description: 删除lsa
// @receiver l
// @param routerIdentifier
// @param lsaType
//
func (l *Lsdb) RemoveLsaByNameAndType(routerIdentifier *component.Identifier,
lsaType lsa.LsaType) {
err := l.LsaContainer.EraseLsaByNameAndType(routerIdentifier, lsaType)
if err != nil {
common2.LogError("")
return
}
common2.LogDebug("Removed LSA: ", routerIdentifier.ToUri())
}
//
@@ -314,6 +334,42 @@ func (l *Lsdb) RemoveLsaByContainerIndex(index int) {
// @receiver l
//
func (l *Lsdb) BuildAdjLsa() {
common2.LogDebug("buildAdjLsa called")
// 构建邻接lsa的任务启动,那么安排构建就变为false
l.isBuildAdjLsaScheduled = false
// 根据配置文件中邻接表的状态,执行不同的动作
if l.mlsrConfig.GetAdjacencys().IsAdjLsaBuildable(uint32(l.mlsrConfig.GetHelloRetries())) {
// 只有在有计划的情况下才执行adjLsa构建
adjBuildCountCache := l.adjBuildCount
if adjBuildCountCache > 0 {
// 只有有安排时,构建邻接lsa
if l.mlsrConfig.GetAdjacencys().GetNumOfActiveNeighbor() > 0 {
// 有激活状态的邻居,则安装邻接LSA
common2.LogDebug("Building and installing own Adj LSA")
l.BuildAndInstallOwnAdjLsa()
} else {
// 我们没有活跃的邻居,这意味着没有人可以穿过我们。
// 因此,请删除LSDB中的条目。这会阻止此路由器刷新LSA,最终导致其他路由器也将其删除。
common2.LogDebug("Removing own Adj LSA; no ACTIVE neighbors")
l.RemoveLsaByNameAndType(l.thisRouterPrefix, lsa.LsaADJACENCYType)
}
// 如果在构建adj LSA的过程中,FIB必须等待兴趣响应,
// 那么计划的adj LSA构建的数量可能会发生变化,因此我们不应该只将其设置为0。
l.adjBuildCount = l.adjBuildCount - adjBuildCountCache
}
} else {
// 我们仍在等待了解某个邻居的邻接状态,因此请安排稍后的构建(当有望完成时)
l.isBuildAdjLsaScheduled = true
scheTime := l.mlsrConfig.GetHelloTimeout() * time.Duration(l.mlsrConfig.GetHelloRetries())
job, err := l.scheduler.ScheduleTaskAfterDuration(scheTime, 1).Do(l.BuildAdjLsa)
job.LimitRunsTo(1)
l.scheduler.StartAsync()
if err != nil {
common2.LogError("Scheduling BuildAdjLsa error, ", err.Error())
}
}
}
//
+2 -2
View File
@@ -70,7 +70,7 @@ func (c *LinkStateRoutingTableCalculator) CalculatePath(routerMap *RouterMap,
// 在单路径的情况下,我们可以简单地运行Dijkstra算法。
c.doDijkstraPathCalculation(sourceRouter)
// 将新的下一跳通知路由表。// todo: 注意,当前版本中,本机的邻接信息是从配置文件中读取出来的。
rs, ns := c.addAllLsNextHopsToRoutingTable(mConfig.GetAdjacencyList(), routerMap, sourceRouter)
rs, ns := c.addAllLsNextHopsToRoutingTable(mConfig.GetAdjacencys(), routerMap, sourceRouter)
return rs, ns, nil
} else {
// 多路径计算
@@ -87,7 +87,7 @@ func (c *LinkStateRoutingTableCalculator) CalculatePath(routerMap *RouterMap,
// 以当前邻居为起点,执行Dijkstra算法。
c.doDijkstraPathCalculation(sourceRouter)
// 用计算结果更新路由表。
rs, ns := c.addAllLsNextHopsToRoutingTable(mConfig.GetAdjacencyList(), routerMap, sourceRouter)
rs, ns := c.addAllLsNextHopsToRoutingTable(mConfig.GetAdjacencys(), routerMap, sourceRouter)
routers = append(routers, rs...)
nexthops = append(nexthops, ns...)
}