blob: b9cd3f5516d8c8ee6848a85502405e100e4d8175 [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>
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080029#include <boost/lambda/bind.hpp>
Alexander Afanasyev5a595072011-11-25 14:49:07 -080030namespace ll = boost::lambda;
31
32NS_LOG_COMPONENT_DEFINE ("CcnxPitEntry");
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070033
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070034namespace ns3
35{
36
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080037CcnxPitEntry::CcnxPitEntry (Ptr<CcnxNameComponents> prefix,
38 const Time &expireTime,
39 const CcnxFibEntry &fibEntry)
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070040 : m_prefix (prefix)
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070041 , m_fibEntry (fibEntry)
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080042 , m_expireTime (Simulator::Now () + expireTime)
43 // , m_timerExpired (false)
44 // , m_counterExpirations (0)
45 , m_maxRetxCount (0)
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070046{
47}
48
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080049void
Alexander Afanasyev1aeaf922012-04-23 13:48:09 -070050CcnxPitEntry::SetExpireTime (const Time &expireTime)
51{
52 NS_LOG_FUNCTION (expireTime);
53 m_expireTime = expireTime;
54}
55
56
57void
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080058CcnxPitEntry::UpdateLifetime (const Time &offsetTime)
59{
60 Time newExpireTime = Simulator::Now () + offsetTime;
61 if (newExpireTime > m_expireTime)
62 m_expireTime = newExpireTime;
Alexander Afanasyev1aeaf922012-04-23 13:48:09 -070063
64 NS_LOG_DEBUG ("Updated lifetime to " << m_expireTime.ToDouble (Time::S));
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080065}
66
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080067CcnxPitEntryIncomingFaceContainer::type::iterator
68CcnxPitEntry::AddIncoming (Ptr<CcnxFace> face)
69{
70 std::pair<CcnxPitEntryIncomingFaceContainer::type::iterator,bool> ret =
71 m_incoming.insert (CcnxPitEntryIncomingFace (face));
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080072
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080073 NS_ASSERT_MSG (ret.second, "Something is wrong");
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080074
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080075 return ret.first;
76}
77
Alexander Afanasyev9d313d42011-11-25 13:36:15 -080078void
79CcnxPitEntry::RemoveIncoming (Ptr<CcnxFace> face)
80{
81 m_incoming.erase (face);
82}
83
84
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080085CcnxPitEntryOutgoingFaceContainer::type::iterator
86CcnxPitEntry::AddOutgoing (Ptr<CcnxFace> face)
87{
88 std::pair<CcnxPitEntryOutgoingFaceContainer::type::iterator,bool> ret =
89 m_outgoing.insert (CcnxPitEntryOutgoingFace (face));
90
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080091 if (!ret.second)
92 { // outgoing face already exists
93 m_outgoing.modify (ret.first,
94 ll::bind (&CcnxPitEntryOutgoingFace::UpdateOnRetransmit, ll::_1));
95 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080096
97 return ret.first;
98}
99
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800100void
101CcnxPitEntry::RemoveAllReferencesToFace (Ptr<CcnxFace> face)
102{
103 CcnxPitEntryIncomingFaceContainer::type::iterator incoming =
104 m_incoming.find (face);
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700105
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800106 if (incoming != m_incoming.end ())
107 m_incoming.erase (incoming);
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700108
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800109 CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing =
110 m_outgoing.find (face);
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700111
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800112 if (outgoing != m_outgoing.end ())
113 m_outgoing.erase (outgoing);
114}
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700115
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800116void
117CcnxPitEntry::SetWaitingInVain (CcnxPitEntryOutgoingFaceContainer::type::iterator face)
118{
Alexander Afanasyev23d2b542011-12-07 18:54:46 -0800119 NS_LOG_DEBUG (boost::cref (*face->m_face));
120
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800121 m_outgoing.modify (face,
122 (&ll::_1)->*&CcnxPitEntryOutgoingFace::m_waitingInVain = true);
123}
124
125bool
126CcnxPitEntry::AreAllOutgoingInVain () const
127{
Alexander Afanasyev23d2b542011-12-07 18:54:46 -0800128 NS_LOG_DEBUG (m_outgoing.size ());
129
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800130 bool inVain = true;
131 std::for_each (m_outgoing.begin (), m_outgoing.end (),
132 ll::var(inVain) &= (&ll::_1)->*&CcnxPitEntryOutgoingFace::m_waitingInVain);
133
134 NS_LOG_DEBUG ("inVain " << inVain);
135 return inVain;
136}
137
Alexander Afanasyeva7a2b8b2011-11-28 18:19:09 -0800138bool
139CcnxPitEntry::AreTherePromisingOutgoingFacesExcept (Ptr<CcnxFace> face) const
140{
141 bool inVain = true;
142 std::for_each (m_outgoing.begin (), m_outgoing.end (),
143 ll::var(inVain) &=
144 ((&ll::_1)->*&CcnxPitEntryOutgoingFace::m_face == face ||
145 (&ll::_1)->*&CcnxPitEntryOutgoingFace::m_waitingInVain));
146
147 return !inVain;
148}
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800149
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800150void
151CcnxPitEntry::IncreaseAllowedRetxCount ()
152{
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800153 NS_LOG_ERROR (this);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800154 m_maxRetxCount++;
155}
156
Alexander Afanasyeva95b7392012-03-09 10:54:10 -0800157std::ostream& operator<< (std::ostream& os, const CcnxPitEntry &entry)
158{
159 os << "Prefix: " << *entry.m_prefix << "\n";
160 os << "In: ";
161 bool first = true;
162 BOOST_FOREACH (const CcnxPitEntryIncomingFace &face, entry.m_incoming)
163 {
164 if (!first)
165 os << ",";
166 else
167 first = false;
168
169 os << *face.m_face;
170 }
171
172 os << "\nOut: ";
173 first = true;
174 BOOST_FOREACH (const CcnxPitEntryOutgoingFace &face, entry.m_outgoing)
175 {
176 if (!first)
177 os << ",";
178 else
179 first = false;
180
181 os << *face.m_face;
182 }
183
184 return os;
185}
186
187
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800188}