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> |
| 29 | namespace ll = boost::lambda; |
| 30 | |
| 31 | NS_LOG_COMPONENT_DEFINE ("CcnxPitEntry"); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 32 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 33 | namespace ns3 |
| 34 | { |
| 35 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 36 | CcnxPitEntry::CcnxPitEntry (Ptr<CcnxNameComponents> prefix, |
| 37 | const Time &expireTime, |
| 38 | const CcnxFibEntry &fibEntry) |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 39 | : m_prefix (prefix) |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 40 | , m_fibEntry (fibEntry) |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 41 | , m_expireTime (expireTime) |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 42 | , m_timerExpired (false) |
| 43 | , m_counterExpirations (0) |
| 44 | { |
| 45 | } |
| 46 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 47 | CcnxPitEntryIncomingFaceContainer::type::iterator |
| 48 | CcnxPitEntry::AddIncoming (Ptr<CcnxFace> face) |
| 49 | { |
| 50 | std::pair<CcnxPitEntryIncomingFaceContainer::type::iterator,bool> ret = |
| 51 | m_incoming.insert (CcnxPitEntryIncomingFace (face)); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 52 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 53 | NS_ASSERT_MSG (ret.second, "Something is wrong"); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 54 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 55 | return ret.first; |
| 56 | } |
| 57 | |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 58 | void |
| 59 | CcnxPitEntry::RemoveIncoming (Ptr<CcnxFace> face) |
| 60 | { |
| 61 | m_incoming.erase (face); |
| 62 | } |
| 63 | |
| 64 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 65 | CcnxPitEntryOutgoingFaceContainer::type::iterator |
| 66 | CcnxPitEntry::AddOutgoing (Ptr<CcnxFace> face) |
| 67 | { |
| 68 | std::pair<CcnxPitEntryOutgoingFaceContainer::type::iterator,bool> ret = |
| 69 | m_outgoing.insert (CcnxPitEntryOutgoingFace (face)); |
| 70 | |
| 71 | NS_ASSERT_MSG (ret.second, "Something is wrong"); |
| 72 | |
| 73 | return ret.first; |
| 74 | } |
| 75 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 76 | void |
| 77 | CcnxPitEntry::RemoveAllReferencesToFace (Ptr<CcnxFace> face) |
| 78 | { |
| 79 | CcnxPitEntryIncomingFaceContainer::type::iterator incoming = |
| 80 | m_incoming.find (face); |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 81 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 82 | if (incoming != m_incoming.end ()) |
| 83 | m_incoming.erase (incoming); |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 84 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 85 | CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing = |
| 86 | m_outgoing.find (face); |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 87 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 88 | if (outgoing != m_outgoing.end ()) |
| 89 | m_outgoing.erase (outgoing); |
| 90 | } |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 91 | |
Alexander Afanasyev | 5a59507 | 2011-11-25 14:49:07 -0800 | [diff] [blame^] | 92 | void |
| 93 | CcnxPitEntry::SetWaitingInVain (CcnxPitEntryOutgoingFaceContainer::type::iterator face) |
| 94 | { |
| 95 | m_outgoing.modify (face, |
| 96 | (&ll::_1)->*&CcnxPitEntryOutgoingFace::m_waitingInVain = true); |
| 97 | } |
| 98 | |
| 99 | bool |
| 100 | CcnxPitEntry::AreAllOutgoingInVain () const |
| 101 | { |
| 102 | bool inVain = true; |
| 103 | std::for_each (m_outgoing.begin (), m_outgoing.end (), |
| 104 | ll::var(inVain) &= (&ll::_1)->*&CcnxPitEntryOutgoingFace::m_waitingInVain); |
| 105 | |
| 106 | NS_LOG_DEBUG ("inVain " << inVain); |
| 107 | return inVain; |
| 108 | } |
| 109 | |
| 110 | |
| 111 | } |