blob: b9ca8d47d7aebfa98e1a71c2c77839e175fd6cc9 [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"
26
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070027namespace ns3
28{
29
30// struct SearchByFace
31// {
32// /**
33// * \brief To perform effective searches by CcnxFace
34// */
35// bool
36// operator() (const CcnxPitIncomingInterest &m, const Ptr<CcnxFace> &face) const
37// {
38// return *(m.m_face) < *face;
39// }
40
41// /**
42// * \brief To perform effective searches by CcnxFace
43// */
44// bool
45// operator() (const Ptr<CcnxFace> &face, const CcnxPitIncomingInterest &m) const
46// {
47// return *face < *(m.m_face);
48// }
49
50// /**
51// * \brief To perform effective searches by CcnxFace
52// */
53// bool
54// operator() (const CcnxPitOutgoingInterest &m, const Ptr<CcnxFace> &face) const
55// {
56// return *(m.m_face) < *face;
57// }
58
59// /**
60// * \brief To perform effective searches by CcnxFace
61// */
62// bool
63// operator() (const Ptr<CcnxFace> &face, const CcnxPitOutgoingInterest &m) const
64// {
65// return *face < *(m.m_face);
66// }
67// };
68
69
70CcnxPitEntry::CcnxPitEntry (Ptr<CcnxNameComponents> prefix)
71 : m_prefix (prefix)
72 , m_fib (0)
73 // , m_expireTime (?)
74 , m_timerExpired (false)
75 , m_counterExpirations (0)
76{
77}
78
79const CcnxNameComponents &
80CcnxPitEntry::GetPrefix () const
81{
82 return *m_prefix;
83}
84
85CcnxPitEntry::SetFibEntry::SetFibEntry (Ptr<CcnxFibEntry> fib)
86 : m_fib (fib)
87{
88}
89
90void
91CcnxPitEntry::SetFibEntry::operator() (CcnxPitEntry &entry)
92{
93 entry.m_fib = m_fib;
94}
95
96void
97CcnxPitEntry::AddIncoming::operator() (CcnxPitEntry &entry)
98{
99 entry.m_incoming.insert (CcnxPitEntryIncomingFace (m_face));
100}
101
102void
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700103CcnxPitEntry::DeleteIncoming::operator() (CcnxPitEntry &entry)
104{
105 entry.m_incoming.erase (m_face);
106}
107
108void
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700109CcnxPitEntry::AddOutgoing::operator() (CcnxPitEntry &entry)
110{
111 entry.m_outgoing.insert (CcnxPitEntryOutgoingFace (m_face));
112}
113
114void
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700115CcnxPitEntry::DeleteOutgoing::operator() (CcnxPitEntry &entry)
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700116{
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700117 entry.m_outgoing.erase (m_face);
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700118}
119
120void
121CcnxPitEntry::ClearIncoming::operator() (CcnxPitEntry &entry)
122{
123 entry.m_incoming.clear ();
124}
125
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700126CcnxPitEntry::UpdateFibStatus::UpdateFibStatus (Ptr<CcnxFace> face, CcnxFibFaceMetric::Status status)
127 : m_face (face)
128 , m_status (status)
129{
130}
131
132void
133CcnxPitEntry::UpdateFibStatus::operator() (CcnxPitEntry &entry)
134{
135 entry.m_fib->UpdateStatus (m_face, m_status);
136}
137
138void
139CcnxPitEntry::EstimateRttAndRemoveFace::operator() (CcnxPitEntry &entry)
140{
141 // similar to Karn's Algorithm, we don't use RTT measurements for retx packets
142 if (m_outFace->m_retxNum>0)
143 return;
144
145 CcnxFibFaceMetricContainer::type::iterator metric = entry.m_fib->m_faces.find (m_outFace->m_face);
146 NS_ASSERT_MSG (metric != entry.m_fib->m_faces.end (),
147 "Something wrong. Cannot find entry for the face in FIB");
148
149 Time rtt = Simulator::Now() - m_outFace->m_sendTime;
150 entry.m_fib->m_faces.modify (metric, CcnxFibFaceMetric::UpdateRtt (rtt));
151
152 entry.m_outgoing.erase (m_outFace);
153}
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700154
155}