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