diff --git a/lsdb/Lsdb.go b/lsdb/Lsdb.go index 8542a62..b71e65d 100644 --- a/lsdb/Lsdb.go +++ b/lsdb/Lsdb.go @@ -21,9 +21,9 @@ import ( // Lsdb更新状态 const ( - INSTALLED = 0 // 已安装 - UPDATED = 1 // 已更新 - REMOVED = -1 // 已移除 + INSTALLED = 0 // 已安装 + UPDATED = 1 // 已更新 + REMOVED = -1 // 已移除 ) type Lsdb struct { @@ -36,22 +36,22 @@ type Lsdb struct { // LSA容器 LsaContainer.LsaContainer - lsaRefreshTime *time.Duration // lsa刷新时间 - adjLsaBuildInterval *time.Duration // 邻接LSA构建间隔 - thisRouterPrefix *component.Identifier // 当前路由器的标识 + lsaRefreshTime *time.Duration // lsa刷新时间 + adjLsaBuildInterval *time.Duration // 邻接LSA构建间隔 + thisRouterPrefix *component.Identifier // 当前路由器的标识 // 任务调度器 - scheduler *Scheduler + scheduler *MlsrScheduler // 将LSA的名称从sync映射到其已知的最高序列号; // 用于阻止MLSR尝试获取过时的LSA - highestSeqNo map[*component.Identifier] uint64 + highestSeqNo map[*component.Identifier]uint64 // 不同类型lsa的序列号管理器 sequencingManager *SequencingManager - isBuildAdjLsaScheduled bool // 是否安排构建邻接LSA - adjBuildCount uint64 // 邻接LSA的构建的统计数目 + isBuildAdjLsaScheduled bool // 是否安排构建邻接LSA + adjBuildCount uint64 // 邻接LSA的构建的统计数目 } // @@ -62,7 +62,7 @@ type Lsdb struct { // @param lsaType // @return bool // -func (l *Lsdb) DoesLsaExist(routerIdentifier *component.Identifier,lsaType int) bool { +func (l *Lsdb) DoesLsaExist(routerIdentifier *component.Identifier, lsaType int) bool { panic("implement me") } @@ -88,7 +88,7 @@ func (l *Lsdb) BuildAndInstallOwnCoordinateLsa() { // @Description: 安排LSA的构建 // @receiver l // -func (l *Lsdb) ScheduleAdjLsaBuild() { +func (l *Lsdb) ScheduleAdjLsaBuild() { } // @@ -102,10 +102,10 @@ func (l *Lsdb) ScheduleAdjLsaBuild() { // @receiver l // @param interest // -func (l *Lsdb) ProcessInterest(interest *packet.Interest) { +func (l *Lsdb) ProcessInterest(interest *packet.Interest) { } -func (l *Lsdb) ProcessGPPkt(pkt *packet.GPPkt) { +func (l *Lsdb) ProcessGPPkt(pkt *packet.GPPkt) { } // @@ -152,22 +152,22 @@ func (l *Lsdb) FindLsa(routerIdentifier *component.Identifier, // @return bool // func (l *Lsdb) IsLsaNew(routerIdentifier *component.Identifier, - lsaType lsa.LsaType,seqNo uint64) bool { - lsa := l.FindLsa(routerIdentifier,lsaType) - if lsa.GetSeqNo() >= seqNo{ + lsaType lsa.LsaType, seqNo uint64) bool { + lsa := l.FindLsa(routerIdentifier, lsaType) + if lsa.GetSeqNo() >= seqNo { return false } return true } -func (l *Lsdb) InstallLsa(lsa lsa.ILsa) { +func (l *Lsdb) InstallLsa(lsa lsa.ILsa) { } -func (l* Lsdb) RemoveLsa(routerIdentifier *component.Identifier, +func (l *Lsdb) RemoveLsa(routerIdentifier *component.Identifier, lsaType lsa.LsaType) { } -func (l* Lsdb) RemoveLsaByContainerIndex(index int) { +func (l *Lsdb) RemoveLsaByContainerIndex(index int) { } // @@ -176,7 +176,7 @@ func (l* Lsdb) RemoveLsaByContainerIndex(index int) { // 只有当路由器的所有邻居状态是已知的时,才可以构建它的邻接LSA。 // @receiver l // -func (l *Lsdb) BuildAdjLsa() { +func (l *Lsdb) BuildAdjLsa() { } // @@ -184,7 +184,7 @@ func (l *Lsdb) BuildAdjLsa() { // @Description: 为当前路由器构建并安装一个邻接LSA // @receiver l // -func (l *Lsdb) BuildAndInstallOwnAdjLsa() { +func (l *Lsdb) BuildAndInstallOwnAdjLsa() { } // @@ -192,19 +192,19 @@ func (l *Lsdb) BuildAndInstallOwnAdjLsa() { // @Description: 在调度器中安排一个刷新或过期事件 // @receiver l // -func (l *Lsdb) ScheduleLsaExpiration(lsa lsa.ILsa,duration *time.Duration) { +func (l *Lsdb) ScheduleLsaExpiration(lsa lsa.ILsa, duration *time.Duration) { } -func (l* Lsdb) ExpireOrRefreshLsa(lsa lsa.ILsa) { +func (l *Lsdb) ExpireOrRefreshLsa(lsa lsa.ILsa) { } func (l *Lsdb) ProcessInterestForLsa(interest *packet.Interest, - originRouterIdentifier *component.Identifier,lsaType lsa.LsaType,seqNo uint64) { + originRouterIdentifier *component.Identifier, lsaType lsa.LsaType, seqNo uint64) { } func (l *Lsdb) ExpressInterest(interestName *component.Identifier, - timeOut uint32,deadline *time.Time) { + timeOut uint32, deadline *time.Time) { } // @@ -219,9 +219,9 @@ func (l *Lsdb) ExpressInterest(interestName *component.Identifier, // @param lsaName // @param seqNo // -func (l *Lsdb) OnFetchLsaError(errorCode uint32,msg string, - interestName *component.Identifier,retransmitNo uint32, - deadline *time.Time,lsaName *component.Identifier,seqNo uint64) { +func (l *Lsdb) OnFetchLsaError(errorCode uint32, msg string, + interestName *component.Identifier, retransmitNo uint32, + deadline *time.Time, lsaName *component.Identifier, seqNo uint64) { } // @@ -233,11 +233,10 @@ func (l *Lsdb) OnFetchLsaError(errorCode uint32,msg string, // @param buffer // @param interestName // -func (l *Lsdb) AfterFetchLsa(buffer bytes.Buffer,interestName *component.Identifier) { +func (l *Lsdb) AfterFetchLsa(buffer bytes.Buffer, interestName *component.Identifier) { } func (l *Lsdb) getLsaExpirationTimePoint() time.Time { // todo return time.Time{} } - diff --git a/route/RoutingTable.go b/route/RoutingTable.go index 75d908d..d458d9b 100644 --- a/route/RoutingTable.go +++ b/route/RoutingTable.go @@ -68,7 +68,10 @@ func (t *RoutingTable) Calculate() { t.m_isRoutingTableCalculating = false } else { // 安排指定时间之后执行一个路由计算 - t.ScheduleRoutingTableCalculation() + err := t.ScheduleRoutingTableCalculation() + if err != nil { + common2.LogFatal("Calculate error,Schedule RoutingTableCalculation error, ", err) + } } } @@ -80,11 +83,36 @@ func (t *RoutingTable) Calculate() { // @param hop 要添加到RTE的下一个跃点。 // func (t *RoutingTable) AddNextHop(destRouter *component.Identifier, hop *NextHop) { + common2.LogInfo("Adding " + hop.LogicFaceUri() + " for destination " + destRouter.ToUri()) + // 查找路由表项 + rte := t.FindRoutingTableEntry(destRouter) + // 如果没有这条表项,则构建并加入 + if rte == nil { + rte = new(RoutingTableEntry) + rte.AddNextHop(hop) + t.rTable = append(t.rTable, rte) + } else { + // 如果有,则直接编辑该条目,增加一个下一跳. + // todo: 这块需要测试,是否在go中可以直接根据引用进行表项的修改 + rte.AddNextHop(hop) + } } +// +// FindRoutingTableEntry +// @Description: 根据某个目的路由器,查找对应的路由表项 +// @receiver t +// @param destRouter +// @return *RoutingTableEntry +// func (t *RoutingTable) FindRoutingTableEntry(destRouter *component.Identifier) *RoutingTableEntry { - //todo + uri := destRouter.ToUri() + for i := 0; i < len(t.rTable); i++ { + if t.rTable[i].GetDestination().ToUri() == uri { + return t.rTable[i] + } + } return nil } @@ -95,7 +123,7 @@ func (t *RoutingTable) FindRoutingTableEntry(destRouter *component.Identifier) * // func (t *RoutingTable) ScheduleRoutingTableCalculation() error { if !t.m_isRouteCalculationScheduled { - common2.LogFatal("Scheduling routing table calculation in ", t.m_routingCalcInterval) + common2.LogInfo("Scheduling routing table calculation in ", t.m_routingCalcInterval) err := t.scheduler.ScheduleTaskAfterDuration(t.m_routingCalcInterval, t.Calculate) if err != nil { return err @@ -157,7 +185,7 @@ func (t *RoutingTable) calculateLsRoutingTable() { // @receiver t // func (t *RoutingTable) clearRoutingTable() { - + t.rTable = []*RoutingTableEntry{} } // diff --git a/route/RoutingTableEntry.go b/route/RoutingTableEntry.go index 67de72c..ddc8eb3 100644 --- a/route/RoutingTableEntry.go +++ b/route/RoutingTableEntry.go @@ -30,11 +30,11 @@ type RoutingTableEntry struct { // @return *RoutingTableEntry // @return error // -func NewRoutingTableEntry(dest *component.Identifier) (*RoutingTableEntry,error) { +func NewRoutingTableEntry(dest *component.Identifier) (*RoutingTableEntry, error) { // todo: 判断dest是否格式有效 rte := new(RoutingTableEntry) - rte.m_destination=dest - return rte,nil + rte.m_destination = dest + return rte, nil } // @@ -43,7 +43,7 @@ func NewRoutingTableEntry(dest *component.Identifier) (*RoutingTableEntry,error) // @receiver e // @return *component.Identifier // -func (e *RoutingTableEntry) GetDestination(dest *component.Identifier) *component.Identifier { +func (e *RoutingTableEntry) GetDestination() *component.Identifier { return e.m_destination } @@ -54,7 +54,7 @@ func (e *RoutingTableEntry) GetDestination(dest *component.Identifier) *componen // @param dest // func (e *RoutingTableEntry) SetDestination(dest *component.Identifier) { - e.m_destination=dest + e.m_destination = dest } // @@ -65,22 +65,22 @@ func (e *RoutingTableEntry) SetDestination(dest *component.Identifier) { // @return int // @return error // -func (e *RoutingTableEntry) WireEncode(encoder *encoding.Encoder) (int,error) { +func (e *RoutingTableEntry) WireEncode(encoder *encoding.Encoder) (int, error) { totalLength := 0 // TLV-Value - tmpLen,err := e.NextHopList.WireEncode(encoder) + tmpLen, err := e.NextHopList.WireEncode(encoder) if err != nil { return 0, err } totalLength += tmpLen - tmpLen,err = e.m_destination.WireEncode(encoder) + tmpLen, err = e.m_destination.WireEncode(encoder) if err != nil { return 0, err } totalLength += tmpLen // TLV-Length - tmpLen,err = encoder.PrependVarNumber(encoding.VlInt(totalLength)) + tmpLen, err = encoder.PrependVarNumber(encoding.VlInt(totalLength)) if err != nil { return 0, err } @@ -93,7 +93,7 @@ func (e *RoutingTableEntry) WireEncode(encoder *encoding.Encoder) (int,error) { } totalLength += tmpLen - return totalLength,nil + return totalLength, nil } // @@ -115,19 +115,19 @@ func (e *RoutingTableEntry) WireDecode(block *encoding.Block) error { } // 提取参数 - for _, parameter := range block.GetSubElements(){ + for _, parameter := range block.GetSubElements() { switch parameter.GetType() { case encoding.TlvIdentifier: - iden:=component.Identifier{} - if err:= iden.WireDecode(parameter); err != nil { + iden := component.Identifier{} + if err := iden.WireDecode(parameter); err != nil { return err } e.m_destination = &iden case extensions.TlvMlsrNextHopList: - if err:= e.NextHopList.WireDecode(parameter); err != nil { + if err := e.NextHopList.WireDecode(parameter); err != nil { return err } } } return nil -} \ No newline at end of file +}