blob: 348f01bb4336e24569ff4ef5dfa7ee05a877f4f0 [file] [log] [blame]
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -07001/* -*- 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 Afanasyev78cf0c92011-09-01 19:57:14 -070025#include "ns3/simulator.h"
Alexander Afanasyev5a595072011-11-25 14:49:07 -080026#include "ns3/log.h"
27
28#include <boost/lambda/lambda.hpp>
29namespace ll = boost::lambda;
30
31NS_LOG_COMPONENT_DEFINE ("CcnxPitEntry");
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070032
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070033namespace ns3
34{
35
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080036CcnxPitEntry::CcnxPitEntry (Ptr<CcnxNameComponents> prefix,
37 const Time &expireTime,
38 const CcnxFibEntry &fibEntry)
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070039 : m_prefix (prefix)
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070040 , m_fibEntry (fibEntry)
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080041 , m_expireTime (expireTime)
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070042 , m_timerExpired (false)
43 , m_counterExpirations (0)
44{
45}
46
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080047CcnxPitEntryIncomingFaceContainer::type::iterator
48CcnxPitEntry::AddIncoming (Ptr<CcnxFace> face)
49{
50 std::pair<CcnxPitEntryIncomingFaceContainer::type::iterator,bool> ret =
51 m_incoming.insert (CcnxPitEntryIncomingFace (face));
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080052
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080053 NS_ASSERT_MSG (ret.second, "Something is wrong");
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080054
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080055 return ret.first;
56}
57
Alexander Afanasyev9d313d42011-11-25 13:36:15 -080058void
59CcnxPitEntry::RemoveIncoming (Ptr<CcnxFace> face)
60{
61 m_incoming.erase (face);
62}
63
64
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080065CcnxPitEntryOutgoingFaceContainer::type::iterator
66CcnxPitEntry::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 Afanasyev09c7deb2011-11-23 14:50:10 -080076void
77CcnxPitEntry::RemoveAllReferencesToFace (Ptr<CcnxFace> face)
78{
79 CcnxPitEntryIncomingFaceContainer::type::iterator incoming =
80 m_incoming.find (face);
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070081
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080082 if (incoming != m_incoming.end ())
83 m_incoming.erase (incoming);
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070084
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080085 CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing =
86 m_outgoing.find (face);
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070087
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080088 if (outgoing != m_outgoing.end ())
89 m_outgoing.erase (outgoing);
90}
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070091
Alexander Afanasyev5a595072011-11-25 14:49:07 -080092void
93CcnxPitEntry::SetWaitingInVain (CcnxPitEntryOutgoingFaceContainer::type::iterator face)
94{
95 m_outgoing.modify (face,
96 (&ll::_1)->*&CcnxPitEntryOutgoingFace::m_waitingInVain = true);
97}
98
99bool
100CcnxPitEntry::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
Alexander Afanasyeva7a2b8b2011-11-28 18:19:09 -0800110bool
111CcnxPitEntry::AreTherePromisingOutgoingFacesExcept (Ptr<CcnxFace> face) const
112{
113 bool inVain = true;
114 std::for_each (m_outgoing.begin (), m_outgoing.end (),
115 ll::var(inVain) &=
116 ((&ll::_1)->*&CcnxPitEntryOutgoingFace::m_face == face ||
117 (&ll::_1)->*&CcnxPitEntryOutgoingFace::m_waitingInVain));
118
119 return !inVain;
120}
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800121
122}