diff --git a/src/routing/static-router.cc b/src/routing/static-router.cc index 48a697a5e..b1a470feb 100644 --- a/src/routing/static-router.cc +++ b/src/routing/static-router.cc @@ -38,32 +38,24 @@ StaticRouterLSA::StaticRouterLSA() StaticRouterLSA::StaticRouterLSA (StaticRouterLSA& lsa) : m_linkStateId(lsa.m_linkStateId), m_advertisingRtr(lsa.m_advertisingRtr) { - NS_DEBUG("StaticRouterLSA Copy Constructor"); - NS_ASSERT_MSG(IsEmpty(), "The LSA must be empty before copy"); - - for ( ListOfLinkRecords_t::iterator i = lsa.m_linkRecords.begin (); - i != lsa.m_linkRecords.end (); - i++) - { - StaticRouterLinkRecord *pSrc = *i; - StaticRouterLinkRecord *pDst = new StaticRouterLinkRecord; - pDst->m_linkId = pSrc->m_linkId; - pDst->m_linkData = pSrc->m_linkData; - pDst->m_linkType = pSrc->m_linkType; - m_linkRecords.push_back(pDst); - pDst = 0; - } + NS_ASSERT_MSG(IsEmpty(), "The LSA must be empty in its constructor!"); + CopyLinkRecords (lsa); } StaticRouterLSA& StaticRouterLSA::operator= (StaticRouterLSA& lsa) { - NS_DEBUG("StaticRouterLSA Operator ="); - NS_ASSERT_MSG(IsEmpty(), "The LSA must be empty before assignment"); - m_linkStateId = lsa.m_linkStateId; m_advertisingRtr = lsa.m_advertisingRtr; + ClearLinkRecords (); + CopyLinkRecords (lsa); + return *this; +} + + void +StaticRouterLSA::CopyLinkRecords (StaticRouterLSA& lsa) +{ for ( ListOfLinkRecords_t::iterator i = lsa.m_linkRecords.begin (); i != lsa.m_linkRecords.end (); i++) @@ -76,8 +68,6 @@ StaticRouterLSA::operator= (StaticRouterLSA& lsa) m_linkRecords.push_back(pDst); pDst = 0; } - - return *this; } StaticRouterLSA::~StaticRouterLSA() diff --git a/src/routing/static-router.h b/src/routing/static-router.h index f3273c311..d65e4e165 100644 --- a/src/routing/static-router.h +++ b/src/routing/static-router.h @@ -115,6 +115,15 @@ public: * @returns Reference to the overwritten LSA. */ StaticRouterLSA& operator= (StaticRouterLSA& lsa); + /** + * Copy any Static Router Link Records in a given Static Router Link + * State Advertisement to the current LSA. Existing Link Records are not + * deleted -- this is a concatenation of Link Records. + * + * @see ClearLinkRecords () + * @param lsa The LSA to copy the Link Records from. + */ + void CopyLinkRecords (StaticRouterLSA& lsa); /** * Add a given Static Router Link Record to a given Static Router Link * State Advertisement.