akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 1 | #include <iostream> |
| 2 | #include <string> |
| 3 | #include <cmath> |
| 4 | #include <limits> |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 5 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 6 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 7 | #include "adjacent.hpp" |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame^] | 8 | #include "logger.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 9 | |
| 10 | namespace nlsr { |
| 11 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame^] | 12 | INIT_LOGGER("Adjacent"); |
| 13 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 14 | using namespace std; |
| 15 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 16 | const float Adjacent::DEFAULT_LINK_COST = 10.0; |
| 17 | |
| 18 | Adjacent::Adjacent() |
| 19 | : m_name() |
| 20 | , m_connectingFaceUri() |
| 21 | , m_linkCost(DEFAULT_LINK_COST) |
| 22 | , m_status(ADJACENT_STATUS_INACTIVE) |
| 23 | , m_interestTimedOutNo(0) |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | Adjacent::Adjacent(const ndn::Name& an) |
| 28 | : m_name(an) |
| 29 | , m_connectingFaceUri() |
| 30 | , m_linkCost(DEFAULT_LINK_COST) |
| 31 | , m_status(ADJACENT_STATUS_INACTIVE) |
| 32 | , m_interestTimedOutNo(0) |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | Adjacent::Adjacent(const ndn::Name& an, const std::string& cfu, double lc, |
| 37 | uint32_t s, uint32_t iton) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 38 | { |
| 39 | m_name = an; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 40 | m_connectingFaceUri = cfu; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 41 | m_linkCost = lc; |
| 42 | m_status = s; |
| 43 | m_interestTimedOutNo = iton; |
| 44 | } |
| 45 | |
| 46 | bool |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 47 | Adjacent::operator==(const Adjacent& adjacent) const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 48 | { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 49 | return (m_name == adjacent.getName()) && |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 50 | (m_connectingFaceUri == adjacent.getConnectingFaceUri()) && |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 51 | (std::abs(m_linkCost - adjacent.getLinkCost()) < |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 52 | std::numeric_limits<double>::epsilon()) ; |
| 53 | } |
| 54 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 55 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 56 | Adjacent::compare(const ndn::Name& adjacencyName) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 57 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 58 | return m_name == adjacencyName; |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 59 | } |
| 60 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame^] | 61 | void |
| 62 | Adjacent::writeLog() |
| 63 | { |
| 64 | _LOG_DEBUG("Adjacent : " << m_name); |
| 65 | _LOG_DEBUG("Connecting FaceUri: " << m_connectingFaceUri); |
| 66 | _LOG_DEBUG("Link Cost: " << m_linkCost); |
| 67 | _LOG_DEBUG("Status: " << m_status); |
| 68 | _LOG_DEBUG("Interest Timed out: " << m_interestTimedOutNo); |
| 69 | } |
| 70 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 71 | std::ostream& |
| 72 | operator<<(std::ostream& os, const Adjacent& adj) |
| 73 | { |
| 74 | os << "Adjacent : " << adj.getName() << endl; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 75 | os << "Connecting FaceUri: " << adj.getConnectingFaceUri() << endl; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 76 | os << "Link Cost: " << adj.getLinkCost() << endl; |
| 77 | os << "Status: " << adj.getStatus() << endl; |
| 78 | os << "Interest Timed out: " << adj.getInterestTimedOutNo() << endl; |
| 79 | return os; |
| 80 | } |
| 81 | |
| 82 | } //namespace nlsr |