ns-allinone-2.35/ns-2.35/linkstate/ls.cc
bool LsRouting::receiveTopo(int neighborId, LsMessage * msgPtr)
{
	// TODO
	bool changed = false;
	// send Ack 
	sendAck(neighborId, LS_MSG_TPMACK, neighborId, 
		msgPtr->sequenceNumber_);
	// check if it's a new message
	if (!tpmHistory_.isNewMessage(*msgPtr))
		return false;

	if (msgPtr->topoPtr_ == NULL)
		return false;
	// Compare with my own database
	for (LsTopoMap::const_iterator recItr = msgPtr->topoPtr_->begin();
	     recItr != msgPtr->topoPtr_->end(); recItr++) {

		if ((*recItr).first == myNodeId_)
			// Don't need peer to tell me my own link state 
			continue; 
		// find my own record of the LSA of the node being examined
		LsLinkStateList* myRecord = 
			linkStateDatabase_.findPtr((*recItr).first);

		if ((myRecord == NULL) || // we don't have it
		    myRecord->empty() ||
		    // or we have an older record
		    ((*(myRecord->begin())).sequenceNumber_ <
		     (*((*recItr).second.begin())).sequenceNumber_) ||
		    ((*(myRecord->begin())).sequenceNumber_ - 
		     (*((*recItr).second.begin())).sequenceNumber_ > 
		     LS_WRAPAROUND_THRESHOLD)) {

			// Update our database
			changed = true;
			if (myRecord == NULL)
				linkStateDatabase_.insert((*recItr).first, 
							 (*recItr).second);
			else 
				*myRecord = (*recItr).second ;
			// Regenerate the LSA message and send to my peers, 
			// except the sender of the topo and the 
			// originator of the LSA
			regenAndSend (/* to except */neighborId, 
				      /* originator */(*recItr).first, 
				      /* the linkstateList */(*recItr).second);
		}
	}
	if (changed)
		computeRoutes();
	// if anything relevant has changed, recompute routes
	return changed;
}
// After a link comes up, receive Topology update from the 
// corresponding neighbor
After a link comes up, receive Topology update from the
corresponding neighbor
After a link comes up receive Topology update from the corresponding neighbor
bool LsRouting::receiveTopo(int neighborId, LsMessage * msgPtr)
{
	bool changed = false;
	sendAck(neighborId, LS_MSG_TPMACK, neighborId, 
		msgPtr->sequenceNumber_);
	if (!tpmHistory_.isNewMessage(*msgPtr))
		return false;
	if (msgPtr->topoPtr_ == NULL)
		return false;
	for (LsTopoMap::const_iterator recItr = msgPtr->topoPtr_->begin();
	     recItr != msgPtr->topoPtr_->end(); recItr++) {
		if ((*recItr).first == myNodeId_)
			continue; 
		LsLinkStateList* myRecord = 
			linkStateDatabase_.findPtr((*recItr).first);
		if ((myRecord == NULL) || 
		    myRecord->empty() ||
		    ((*(myRecord->begin())).sequenceNumber_ <
		     (*((*recItr).second.begin())).sequenceNumber_) ||
		    ((*(myRecord->begin())).sequenceNumber_ - 
		     (*((*recItr).second.begin())).sequenceNumber_ > 
		     LS_WRAPAROUND_THRESHOLD)) {
			changed = true;
			if (myRecord == NULL)
				linkStateDatabase_.insert((*recItr).first, 
							 (*recItr).second);
			else 
				*myRecord = (*recItr).second ;
			regenAndSend (neighborId, 
				      (*recItr).first, 
				      (*recItr).second);
		}
	}
	if (changed)
		computeRoutes();
	return changed;
}
bool LsRouting :: receiveTopo ( int neighborId , LsMessage * msgPtr ) { bool changed = false ; sendAck ( neighborId , LS_MSG_TPMACK , neighborId , msgPtr -> sequenceNumber_ ) ; if ( ! tpmHistory_ . isNewMessage ( * msgPtr ) ) return false ; if ( msgPtr -> topoPtr_ == NULL ) return false ; for ( LsTopoMap :: const_iterator recItr = msgPtr -> topoPtr_ -> begin ( ) ; recItr != msgPtr -> topoPtr_ -> end ( ) ; recItr ++ ) { if ( ( * recItr ) . first == myNodeId_ ) continue ; LsLinkStateList * myRecord = linkStateDatabase_ . findPtr ( ( * recItr ) . first ) ; if ( ( myRecord == NULL ) || myRecord -> empty ( ) || ( ( * ( myRecord -> begin ( ) ) ) . sequenceNumber_ < ( * ( ( * recItr ) . second . begin ( ) ) ) . sequenceNumber_ ) || ( ( * ( myRecord -> begin ( ) ) ) . sequenceNumber_ - ( * ( ( * recItr ) . second . begin ( ) ) ) . sequenceNumber_ > LS_WRAPAROUND_THRESHOLD ) ) { changed = true ; if ( myRecord == NULL ) linkStateDatabase_ . insert ( ( * recItr ) . first , ( * recItr ) . second ) ; else * myRecord = ( * recItr ) . second ; regenAndSend ( neighborId , ( * recItr ) . first , ( * recItr ) . second ) ; } } if ( changed ) computeRoutes ( ) ; return changed ; }
After a link comes up, receive Topology update from the
corresponding neighbor
After a link comes up receive Topology update from the corresponding neighbor
// TODO // send Ack  // check if it's a new message // Compare with my own database // Don't need peer to tell me my own link state  // find my own record of the LSA of the node being examined // we don't have it // or we have an older record // Update our database // Regenerate the LSA message and send to my peers,  // except the sender of the topo and the  // originator of the LSA /* to except */ /* originator */ /* the linkstateList */ // if anything relevant has changed, recompute routes