Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #include "ccnx-pit-entry.h" |
| 22 | #include "ccnx-name-components.h" |
| 23 | #include "ccnx-fib.h" |
| 24 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 25 | #include "ns3/simulator.h" |
Alexander Afanasyev | 5a59507 | 2011-11-25 14:49:07 -0800 | [diff] [blame] | 26 | #include "ns3/log.h" |
| 27 | |
| 28 | #include <boost/lambda/lambda.hpp> |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame^] | 29 | #include <boost/lambda/bind.hpp> |
Alexander Afanasyev | 5a59507 | 2011-11-25 14:49:07 -0800 | [diff] [blame] | 30 | namespace ll = boost::lambda; |
| 31 | |
| 32 | NS_LOG_COMPONENT_DEFINE ("CcnxPitEntry"); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 33 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 34 | namespace ns3 |
| 35 | { |
| 36 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 37 | CcnxPitEntry::CcnxPitEntry (Ptr<CcnxNameComponents> prefix, |
| 38 | const Time &expireTime, |
| 39 | const CcnxFibEntry &fibEntry) |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 40 | : m_prefix (prefix) |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 41 | , m_fibEntry (fibEntry) |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame^] | 42 | , m_expireTime (Simulator::Now () + expireTime) |
| 43 | // , m_timerExpired (false) |
| 44 | // , m_counterExpirations (0) |
| 45 | , m_maxRetxCount (0) |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 46 | { |
| 47 | } |
| 48 | |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame^] | 49 | void |
| 50 | CcnxPitEntry::UpdateLifetime (const Time &offsetTime) |
| 51 | { |
| 52 | Time newExpireTime = Simulator::Now () + offsetTime; |
| 53 | if (newExpireTime > m_expireTime) |
| 54 | m_expireTime = newExpireTime; |
| 55 | } |
| 56 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 57 | CcnxPitEntryIncomingFaceContainer::type::iterator |
| 58 | CcnxPitEntry::AddIncoming (Ptr<CcnxFace> face) |
| 59 | { |
| 60 | std::pair<CcnxPitEntryIncomingFaceContainer::type::iterator,bool> ret = |
| 61 | m_incoming.insert (CcnxPitEntryIncomingFace (face)); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 62 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 63 | NS_ASSERT_MSG (ret.second, "Something is wrong"); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 64 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 65 | return ret.first; |
| 66 | } |
| 67 | |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 68 | void |
| 69 | CcnxPitEntry::RemoveIncoming (Ptr<CcnxFace> face) |
| 70 | { |
| 71 | m_incoming.erase (face); |
| 72 | } |
| 73 | |
| 74 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 75 | CcnxPitEntryOutgoingFaceContainer::type::iterator |
| 76 | CcnxPitEntry::AddOutgoing (Ptr<CcnxFace> face) |
| 77 | { |
| 78 | std::pair<CcnxPitEntryOutgoingFaceContainer::type::iterator,bool> ret = |
| 79 | m_outgoing.insert (CcnxPitEntryOutgoingFace (face)); |
| 80 | |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame^] | 81 | if (!ret.second) |
| 82 | { // outgoing face already exists |
| 83 | m_outgoing.modify (ret.first, |
| 84 | ll::bind (&CcnxPitEntryOutgoingFace::UpdateOnRetransmit, ll::_1)); |
| 85 | } |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 86 | |
| 87 | return ret.first; |
| 88 | } |
| 89 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 90 | void |
| 91 | CcnxPitEntry::RemoveAllReferencesToFace (Ptr<CcnxFace> face) |
| 92 | { |
| 93 | CcnxPitEntryIncomingFaceContainer::type::iterator incoming = |
| 94 | m_incoming.find (face); |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 95 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 96 | if (incoming != m_incoming.end ()) |
| 97 | m_incoming.erase (incoming); |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 98 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 99 | CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing = |
| 100 | m_outgoing.find (face); |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 101 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 102 | if (outgoing != m_outgoing.end ()) |
| 103 | m_outgoing.erase (outgoing); |
| 104 | } |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 105 | |
Alexander Afanasyev | 5a59507 | 2011-11-25 14:49:07 -0800 | [diff] [blame] | 106 | void |
| 107 | CcnxPitEntry::SetWaitingInVain (CcnxPitEntryOutgoingFaceContainer::type::iterator face) |
| 108 | { |
| 109 | m_outgoing.modify (face, |
| 110 | (&ll::_1)->*&CcnxPitEntryOutgoingFace::m_waitingInVain = true); |
| 111 | } |
| 112 | |
| 113 | bool |
| 114 | CcnxPitEntry::AreAllOutgoingInVain () const |
| 115 | { |
| 116 | bool inVain = true; |
| 117 | std::for_each (m_outgoing.begin (), m_outgoing.end (), |
| 118 | ll::var(inVain) &= (&ll::_1)->*&CcnxPitEntryOutgoingFace::m_waitingInVain); |
| 119 | |
| 120 | NS_LOG_DEBUG ("inVain " << inVain); |
| 121 | return inVain; |
| 122 | } |
| 123 | |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 124 | bool |
| 125 | CcnxPitEntry::AreTherePromisingOutgoingFacesExcept (Ptr<CcnxFace> face) const |
| 126 | { |
| 127 | bool inVain = true; |
| 128 | std::for_each (m_outgoing.begin (), m_outgoing.end (), |
| 129 | ll::var(inVain) &= |
| 130 | ((&ll::_1)->*&CcnxPitEntryOutgoingFace::m_face == face || |
| 131 | (&ll::_1)->*&CcnxPitEntryOutgoingFace::m_waitingInVain)); |
| 132 | |
| 133 | return !inVain; |
| 134 | } |
Alexander Afanasyev | 5a59507 | 2011-11-25 14:49:07 -0800 | [diff] [blame] | 135 | |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame^] | 136 | void |
| 137 | CcnxPitEntry::IncreaseAllowedRetxCount () |
| 138 | { |
| 139 | m_maxRetxCount++; |
| 140 | } |
| 141 | |
Alexander Afanasyev | 5a59507 | 2011-11-25 14:49:07 -0800 | [diff] [blame] | 142 | } |