Browse Source

src: Change adjacency status from uint32_t to enum

refs: #1946

Change-Id: Ic1abd2610061860d0ac183074395a1d3796e870a
pull/4/head
Vince Lehman 11 years ago
parent
commit
cb76aded0a
  1. 38
      src/adjacency-list.cpp
  2. 8
      src/adjacency-list.hpp
  3. 6
      src/adjacent.cpp
  4. 20
      src/adjacent.hpp
  5. 2
      src/conf-file-processor.cpp
  6. 24
      src/hello-protocol.cpp
  7. 4
      src/lsa.cpp
  8. 6
      tests/test-adjacency-list.cpp

38
src/adjacency-list.cpp

@ -61,15 +61,18 @@ AdjacencyList::addAdjacents(AdjacencyList& adl)
}
}
int32_t
AdjacencyList::updateAdjacentStatus(const ndn::Name& adjName, int32_t s)
bool
AdjacencyList::updateAdjacentStatus(const ndn::Name& adjName, Adjacent::Status s)
{
std::list<Adjacent>::iterator it = find(adjName);
if (it == m_adjList.end()) {
return -1;
return false;
}
else {
it->setStatus(s);
return true;
}
(*it).setStatus(s);
return 0;
}
Adjacent
@ -163,22 +166,25 @@ AdjacencyList::getTimedOutInterestCount(const ndn::Name& neighbor)
return (*it).getInterestTimedOutNo();
}
uint32_t
Adjacent::Status
AdjacencyList::getStatusOfNeighbor(const ndn::Name& neighbor)
{
std::list<Adjacent>::iterator it = find(neighbor);
if (it == m_adjList.end()) {
return -1;
return Adjacent::STATUS_UNKNOWN;
}
else {
return it->getStatus();
}
return (*it).getStatus();
}
void
AdjacencyList::setStatusOfNeighbor(const ndn::Name& neighbor, int32_t status)
AdjacencyList::setStatusOfNeighbor(const ndn::Name& neighbor, Adjacent::Status status)
{
std::list<Adjacent>::iterator it = find(neighbor);
if (it != m_adjList.end()) {
(*it).setStatus(status);
it->setStatus(status);
}
}
@ -192,9 +198,9 @@ bool
AdjacencyList::isAdjLsaBuildable(Nlsr& pnlsr)
{
uint32_t nbrCount = 0;
for (std::list<Adjacent>::iterator it = m_adjList.begin();
it != m_adjList.end() ; it++) {
if (((*it).getStatus() == 1)) {
for (std::list<Adjacent>::iterator it = m_adjList.begin(); it != m_adjList.end() ; it++) {
if (it->getStatus() == Adjacent::STATUS_ACTIVE) {
nbrCount++;
}
else {
@ -214,9 +220,9 @@ int32_t
AdjacencyList::getNumOfActiveNeighbor()
{
int32_t actNbrCount = 0;
for (std::list<Adjacent>::iterator it = m_adjList.begin();
it != m_adjList.end(); it++) {
if (((*it).getStatus() == 1)) {
for (std::list<Adjacent>::iterator it = m_adjList.begin(); it != m_adjList.end(); it++) {
if (it->getStatus() == Adjacent::STATUS_ACTIVE) {
actNbrCount++;
}
}

8
src/adjacency-list.hpp

@ -42,8 +42,8 @@ public:
int32_t
insert(Adjacent& adjacent);
int32_t
updateAdjacentStatus(const ndn::Name& adjName, int32_t s);
bool
updateAdjacentStatus(const ndn::Name& adjName, Adjacent::Status s);
int32_t
updateAdjacentLinkCost(const ndn::Name& adjName, double lc);
@ -60,11 +60,11 @@ public:
int32_t
getTimedOutInterestCount(const ndn::Name& neighbor);
uint32_t
Adjacent::Status
getStatusOfNeighbor(const ndn::Name& neighbor);
void
setStatusOfNeighbor(const ndn::Name& neighbor, int32_t status);
setStatusOfNeighbor(const ndn::Name& neighbor, Adjacent::Status status);
void
setTimedOutInterestCount(const ndn::Name& neighbor, uint32_t count);

6
src/adjacent.cpp

@ -41,7 +41,7 @@ Adjacent::Adjacent()
: m_name()
, m_connectingFaceUri()
, m_linkCost(DEFAULT_LINK_COST)
, m_status(ADJACENT_STATUS_INACTIVE)
, m_status(STATUS_INACTIVE)
, m_interestTimedOutNo(0)
, m_faceId(0)
{
@ -51,14 +51,14 @@ Adjacent::Adjacent(const ndn::Name& an)
: m_name(an)
, m_connectingFaceUri()
, m_linkCost(DEFAULT_LINK_COST)
, m_status(ADJACENT_STATUS_INACTIVE)
, m_status(STATUS_INACTIVE)
, m_interestTimedOutNo(0)
, m_faceId(0)
{
}
Adjacent::Adjacent(const ndn::Name& an, const std::string& cfu, double lc,
uint32_t s, uint32_t iton, uint64_t faceId)
Status s, uint32_t iton, uint64_t faceId)
: m_name(an)
, m_connectingFaceUri(cfu)
, m_linkCost(lc)

20
src/adjacent.hpp

@ -30,21 +30,23 @@
namespace nlsr {
enum {
ADJACENT_STATUS_INACTIVE = 0,
ADJACENT_STATUS_ACTIVE = 1
};
class Adjacent
{
public:
enum Status
{
STATUS_UNKNOWN = -1,
STATUS_INACTIVE = 0,
STATUS_ACTIVE = 1
};
Adjacent();
Adjacent(const ndn::Name& an);
Adjacent(const ndn::Name& an, const std::string& cfu, double lc,
uint32_t s, uint32_t iton, uint64_t faceId);
Status s, uint32_t iton, uint64_t faceId);
const ndn::Name&
getName() const
@ -83,14 +85,14 @@ public:
m_linkCost = lc;
}
uint32_t
Status
getStatus() const
{
return m_status;
}
void
setStatus(uint32_t s)
setStatus(Status s)
{
m_status = s;
}
@ -150,7 +152,7 @@ private:
ndn::Name m_name;
std::string m_connectingFaceUri;
double m_linkCost;
uint32_t m_status;
Status m_status;
uint32_t m_interestTimedOutNo;
uint64_t m_faceId;
};

2
src/conf-file-processor.cpp

@ -338,7 +338,7 @@ ConfFileProcessor::processConfSectionNeighbors(const ConfigSection& section)
Adjacent::DEFAULT_LINK_COST);
ndn::Name neighborName(name);
if (!neighborName.empty()) {
Adjacent adj(name, faceUri, linkCost, ADJACENT_STATUS_INACTIVE, 0, 0);
Adjacent adj(name, faceUri, linkCost, Adjacent::STATUS_INACTIVE, 0, 0);
m_nlsr.getAdjacencyList().insert(adj);
}
else {

24
src/hello-protocol.cpp

@ -102,7 +102,7 @@ HelloProtocol::processInterest(const ndn::Name& name,
_LOG_DEBUG("Sending out data for name: " << interest.getName());
m_nlsr.getNlsrFace().put(*data);
Adjacent *adjacent = m_nlsr.getAdjacencyList().findAdjacent(neighbor);
if (adjacent->getStatus() == 0) {
if (adjacent->getStatus() == Adjacent::STATUS_INACTIVE) {
if(adjacent->getFaceId() != 0){
/* interest name: /<neighbor>/NLSR/INFO/<router> */
ndn::Name interestName(neighbor);
@ -132,7 +132,9 @@ HelloProtocol::processInterestTimedOut(const ndn::Interest& interest)
ndn::Name neighbor = interestName.getPrefix(-3);
_LOG_DEBUG("Neighbor: " << neighbor);
m_nlsr.getAdjacencyList().incrementTimedOutInterestCount(neighbor);
int status = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
Adjacent::Status status = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
uint32_t infoIntTimedOutCount =
m_nlsr.getAdjacencyList().getTimedOutInterestCount(neighbor);
_LOG_DEBUG("Status: " << status);
@ -146,9 +148,9 @@ HelloProtocol::processInterestTimedOut(const ndn::Interest& interest)
expressInterest(interestName,
m_nlsr.getConfParameter().getInterestResendTime());
}
else if ((status == 1) &&
else if ((status == Adjacent::STATUS_ACTIVE) &&
(infoIntTimedOutCount == m_nlsr.getConfParameter().getInterestRetryNumber())) {
m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, 0);
m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, Adjacent::STATUS_INACTIVE);
m_nlsr.incrementAdjBuildCount();
if (m_nlsr.getIsBuildAdjLsaSheduled() == false) {
_LOG_DEBUG("Scheduling scheduledAdjLsaBuild");
@ -184,10 +186,12 @@ HelloProtocol::onContentValidated(const ndn::shared_ptr<const ndn::Data>& data)
_LOG_DEBUG("Data validation successful for INFO(name): " << dataName);
if (dataName.get(-3).toUri() == INFO_COMPONENT) {
ndn::Name neighbor = dataName.getPrefix(-4);
int oldStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, 1);
Adjacent::Status oldStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, Adjacent::STATUS_ACTIVE);
m_nlsr.getAdjacencyList().setTimedOutInterestCount(neighbor, 0);
int newStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
Adjacent::Status newStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
_LOG_DEBUG("Neighbor : " << neighbor);
_LOG_DEBUG("Old Status: " << oldStatus << " New Status: " << newStatus);
// change in Adjacency list
@ -272,12 +276,12 @@ HelloProtocol::onRegistrationFailure(uint32_t code, const std::string& error,
Adjacent *adjacent = m_nlsr.getAdjacencyList().findAdjacent(name);
if (adjacent != 0) {
adjacent->setInterestTimedOutNo(adjacent->getInterestTimedOutNo() + 1);
int status = adjacent->getStatus();
Adjacent::Status status = adjacent->getStatus();
uint32_t infoIntTimedOutCount = adjacent->getInterestTimedOutNo();
if (infoIntTimedOutCount == m_nlsr.getConfParameter().getInterestRetryNumber()) {
if ( status == 1) {
adjacent->setStatus(0);
if (status == Adjacent::STATUS_ACTIVE) {
adjacent->setStatus(Adjacent::STATUS_INACTIVE);
}
m_nlsr.incrementAdjBuildCount();
if (m_nlsr.getIsBuildAdjLsaSheduled() == false) {

4
src/lsa.cpp

@ -218,7 +218,7 @@ AdjLsa::AdjLsa(const ndn::Name& origR, const string& lst, uint32_t lsn,
m_noLink = nl;
std::list<Adjacent> al = adl.getAdjList();
for (std::list<Adjacent>::iterator it = al.begin(); it != al.end(); it++) {
if ((*it).getStatus() == 1) {
if (it->getStatus() == Adjacent::STATUS_ACTIVE) {
addAdjacent((*it));
}
}
@ -286,7 +286,7 @@ AdjLsa::initializeFromContent(const std::string& content)
ndn::Name adjName(*tok_iter++);
std::string connectingFaceUri(*tok_iter++);
double linkCost = boost::lexical_cast<double>(*tok_iter++);
Adjacent adjacent(adjName, connectingFaceUri, linkCost, 0, 0, 0);
Adjacent adjacent(adjName, connectingFaceUri, linkCost, Adjacent::STATUS_INACTIVE, 0, 0);
addAdjacent(adjacent);
}
catch (std::exception& e) {

6
tests/test-adjacency-list.cpp

@ -57,10 +57,10 @@ BOOST_AUTO_TEST_CASE(AdjacenctListBasic)
BOOST_CHECK_EQUAL(adjacentList1.isNeighbor("adjacent"), false);
string n1 = "testname";
BOOST_CHECK_EQUAL(adjacentList1.getStatusOfNeighbor(n1), (uint32_t)0);
BOOST_CHECK_EQUAL(adjacentList1.getStatusOfNeighbor(n1), Adjacent::STATUS_INACTIVE);
adjacentList1.setStatusOfNeighbor(n1, 1);
BOOST_CHECK_EQUAL(adjacentList1.getStatusOfNeighbor(n1), (uint32_t)1);
adjacentList1.setStatusOfNeighbor(n1, Adjacent::STATUS_ACTIVE);
BOOST_CHECK_EQUAL(adjacentList1.getStatusOfNeighbor(n1), Adjacent::STATUS_ACTIVE);
}
BOOST_AUTO_TEST_SUITE_END()

Loading…
Cancel
Save