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 | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 13 | Adjacent::Adjacent(const ndn::Name& an, uint32_t cf, double lc, uint32_t s, |
| 14 | uint32_t iton) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 15 | { |
| 16 | m_name = an; |
| 17 | m_connectingFace = cf; |
| 18 | m_linkCost = lc; |
| 19 | m_status = s; |
| 20 | m_interestTimedOutNo = iton; |
| 21 | } |
| 22 | |
| 23 | bool |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 24 | Adjacent::operator==(const Adjacent& adjacent) const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 25 | { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 26 | return (m_name == adjacent.getName()) && |
| 27 | (m_connectingFace == adjacent.getConnectingFace()) && |
| 28 | (std::abs(m_linkCost - adjacent.getLinkCost()) < |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 29 | std::numeric_limits<double>::epsilon()) ; |
| 30 | } |
| 31 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 32 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 33 | Adjacent::compare(const ndn::Name& adjacencyName) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 34 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame^] | 35 | return m_name == adjacencyName; |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | std::ostream& |
| 39 | operator<<(std::ostream& os, const Adjacent& adj) |
| 40 | { |
| 41 | os << "Adjacent : " << adj.getName() << endl; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 42 | os << "Connecting Face: " << adj.getConnectingFace() << endl; |
| 43 | os << "Link Cost: " << adj.getLinkCost() << endl; |
| 44 | os << "Status: " << adj.getStatus() << endl; |
| 45 | os << "Interest Timed out: " << adj.getInterestTimedOutNo() << endl; |
| 46 | return os; |
| 47 | } |
| 48 | |
| 49 | } //namespace nlsr |