mirror of
https://gitee.com/willfree/mlsr.git
synced 2026-06-05 23:59:29 +08:00
add: face通知流处理流程
This commit is contained in:
+79
-10
@@ -50,7 +50,8 @@ type Mlsr struct {
|
||||
m_controller *mgmt.MIRController
|
||||
m_faceDatasetController *mgmt.MIRController
|
||||
|
||||
// todo face通知流
|
||||
// face通知流
|
||||
m_faceEventMonitor *logicface.FaceEventMonitor
|
||||
}
|
||||
|
||||
// Init
|
||||
@@ -153,7 +154,7 @@ func (m *Mlsr) Init(face *logicface.DummyClientLogicFace, scheduler *lsdb.MlsrSc
|
||||
var ok bool
|
||||
if i[2] != nil {
|
||||
originRouter, ok = i[2].(*component.Identifier)
|
||||
if !ok {
|
||||
if !ok || originRouter == nil {
|
||||
common2.LogError("originRouter conversion failed.")
|
||||
return
|
||||
}
|
||||
@@ -175,7 +176,7 @@ func (m *Mlsr) Init(face *logicface.DummyClientLogicFace, scheduler *lsdb.MlsrSc
|
||||
|
||||
if i[0] != nil {
|
||||
name, ok = i[0].(*component.Identifier)
|
||||
if !ok {
|
||||
if !ok || name == nil {
|
||||
common2.LogError("originRouter conversion failed.")
|
||||
return
|
||||
}
|
||||
@@ -192,6 +193,30 @@ func (m *Mlsr) Init(face *logicface.DummyClientLogicFace, scheduler *lsdb.MlsrSc
|
||||
common2.LogFatal("设置组播策略失败:", err)
|
||||
}
|
||||
|
||||
// face通知流监听器
|
||||
if m.m_faceEventMonitor, err = logicface.NewFaceEventMonitor(uint64(confParam.GetSyncInterestLifetime())); err != nil {
|
||||
common2.LogFatal("设置通知流监听器失败:", err)
|
||||
}
|
||||
m.m_faceEventMonitor.OnNotification.Connect(func(i ...interface{}) {
|
||||
if i == nil || len(i) < 1 {
|
||||
common2.LogError("invalid arg list")
|
||||
return
|
||||
}
|
||||
|
||||
var notification *mgmt.LogicFaceEventNotification
|
||||
var ok bool
|
||||
|
||||
if i[0] != nil {
|
||||
notification, ok = i[0].(*mgmt.LogicFaceEventNotification)
|
||||
if !ok || notification == nil {
|
||||
common2.LogError("originRouter conversion failed.")
|
||||
return
|
||||
}
|
||||
}
|
||||
m.onFaceEventNotification(notification)
|
||||
})
|
||||
m.m_faceEventMonitor.Start()
|
||||
|
||||
// 管理用 Controller
|
||||
m.m_controller = mgmt.CreateMIRController(func() (mgmt.IMgmtLogicFace, error) {
|
||||
face := new(logicface.LogicFace)
|
||||
@@ -213,9 +238,6 @@ func (m *Mlsr) Init(face *logicface.DummyClientLogicFace, scheduler *lsdb.MlsrSc
|
||||
|
||||
// 拉取Face列表并初始化
|
||||
m.InitializeFaces(m.processFaceDataset, m.onFaceDatasetFetchTimeout)
|
||||
|
||||
// todo: face通知流
|
||||
|
||||
}
|
||||
|
||||
// RegisterStrategyForCerts
|
||||
@@ -247,13 +269,60 @@ func (m *Mlsr) RegisterPrefix(prefix *component.Identifier) {
|
||||
// 暂时不需要实现
|
||||
}
|
||||
|
||||
// InitializeFaces
|
||||
// @Description: 通过MIR的face列表初始化邻居节点
|
||||
// onFaceEventNotification
|
||||
// @Description: 处理MIR发来的Face通知
|
||||
// @receiver m
|
||||
// @param notification
|
||||
//
|
||||
func (m *Mlsr) onFaceEventNotification(notification interface{}) {
|
||||
panic("Implement me")
|
||||
func (m *Mlsr) onFaceEventNotification(notification *mgmt.LogicFaceEventNotification) {
|
||||
// 参数校验
|
||||
if notification == nil {
|
||||
common2.LogError("onFaceEventNotification: Invalid Arguments")
|
||||
return
|
||||
}
|
||||
|
||||
// 根据通知类型执行相应流程
|
||||
switch notification.LogicFaceEvent() {
|
||||
case uint64(mgmt.FACE_EVENT_DESTROYED):
|
||||
// 可能有路由节点退出自治域
|
||||
faceId := notification.ControlParameterLogicFaceId.Value()
|
||||
adjacents := m.m_adjacencyList.FindAdjacencyByLogicFaceId(faceId)
|
||||
|
||||
// 若adjacent不为空,则adjacent长度的一定为1(faceId和adjacentRouter是1比1)
|
||||
if len(adjacents) == 1 {
|
||||
adjacent := adjacents[0]
|
||||
common2.LogDebug("Face to ", adjacent.GetNeighborRouterIdentifier().ToUri(), " with face id: ", faceId, " destroyed.")
|
||||
|
||||
if adjacent.Status == lsa.STATUS_ACTIVE {
|
||||
// 更改邻接节点状态
|
||||
adjacent.Status = lsa.STATUS_INACTIVE
|
||||
adjacent.InterestTimedOutNo = uint32(m.m_confParam.GetHelloRetries())
|
||||
// todo: 双曲路由
|
||||
// 重新构建邻接LSA列表
|
||||
m.m_lsdb.ScheduleAdjLsaBuild()
|
||||
}
|
||||
} else {
|
||||
common2.LogInfo("onFaceEventNotification: Not my neighbor")
|
||||
}
|
||||
|
||||
case uint64(mgmt.FACE_EVENT_CREATED):
|
||||
// 可能有节点加入自治域
|
||||
faceUri := notification.ControlParameterRemoteUri.Value()
|
||||
faceId := notification.ControlParameterLogicFaceId.Value()
|
||||
|
||||
adjacents := m.m_adjacencyList.FindAdjacencyByLogicFaceUri(faceUri)
|
||||
if len(adjacents) == 1 && adjacents[0].AdjLsaLogicFaceId.Value() == 0 || adjacents[0].AdjLsaLogicFaceId.Value() != faceId {
|
||||
adjacent := adjacents[0]
|
||||
common2.LogDebug("Face creation event matches neighbor: ", adjacent.GetNeighborRouterIdentifier().ToUri(), " with new face id: ", faceId, " . Registering prefixes.")
|
||||
|
||||
adjacent.AdjLsaLogicFaceId.SetValue(faceId)
|
||||
m.registerAdjacencyPrefixes(adjacent)
|
||||
|
||||
// 在这里不触发路由计算,因为后续的Hello协议会触发
|
||||
} else {
|
||||
common2.LogInfo("onFaceEventNotification: Not my neighbor")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// InitializeFaces
|
||||
|
||||
Reference in New Issue
Block a user