Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -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-impl.h" |
| 22 | #include "ns3/log.h" |
| 23 | #include "ns3/string.h" |
| 24 | #include "ns3/uinteger.h" |
| 25 | #include "ns3/simulator.h" |
| 26 | #include "ccnx-interest-header.h" |
| 27 | #include "ccnx-content-object-header.h" |
| 28 | |
| 29 | #include <boost/lambda/bind.hpp> |
| 30 | #include <boost/lambda/lambda.hpp> |
| 31 | |
| 32 | NS_LOG_COMPONENT_DEFINE ("CcnxPitImpl"); |
| 33 | |
| 34 | using namespace boost::tuples; |
| 35 | using namespace boost; |
| 36 | namespace ll = boost::lambda; |
| 37 | |
| 38 | namespace ns3 { |
| 39 | |
| 40 | NS_OBJECT_ENSURE_REGISTERED (CcnxPitImpl); |
| 41 | |
| 42 | TypeId |
| 43 | CcnxPitImpl::GetTypeId () |
| 44 | { |
| 45 | static TypeId tid = TypeId ("ns3::CcnxPit") |
| 46 | .SetGroupName ("Ccnx") |
| 47 | .SetParent<CcnxPit> () |
| 48 | .AddConstructor<CcnxPitImpl> () |
| 49 | .AddAttribute ("MaxSize", |
| 50 | "Set maximum number of entries in PIT. If 0, limit is not enforced", |
| 51 | StringValue ("0"), |
| 52 | MakeUintegerAccessor (&CcnxPitImpl::GetMaxSize, &CcnxPitImpl::SetMaxSize), |
| 53 | MakeUintegerChecker<uint32_t> ()) |
| 54 | ; |
| 55 | |
| 56 | return tid; |
| 57 | } |
| 58 | |
| 59 | CcnxPitImpl::CcnxPitImpl () |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | CcnxPitImpl::~CcnxPitImpl () |
| 64 | { |
| 65 | } |
| 66 | |
| 67 | uint32_t |
| 68 | CcnxPitImpl::GetMaxSize () const |
| 69 | { |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | void |
| 74 | CcnxPitImpl::SetMaxSize (uint32_t maxSize) |
| 75 | { |
| 76 | } |
| 77 | |
| 78 | void |
| 79 | CcnxPitImpl::NotifyNewAggregate () |
| 80 | { |
| 81 | if (m_fib == 0) |
| 82 | { |
| 83 | m_fib = GetObject<CcnxFib> (); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | void |
| 88 | CcnxPitImpl::DoDispose () |
| 89 | { |
| 90 | // clear (); |
| 91 | } |
| 92 | |
| 93 | void |
| 94 | CcnxPitImpl::DoCleanExpired () |
| 95 | { |
| 96 | // NS_LOG_LOGIC ("Cleaning PIT. Total: " << size ()); |
| 97 | Time now = Simulator::Now (); |
| 98 | |
| 99 | // // uint32_t count = 0; |
| 100 | // while (!empty ()) |
| 101 | // { |
| 102 | // CcnxPit::index<i_timestamp>::type::iterator entry = get<i_timestamp> ().begin (); |
| 103 | // if (entry->GetExpireTime () <= now) // is the record stale? |
| 104 | // { |
| 105 | // get<i_timestamp> ().erase (entry); |
| 106 | // // count ++; |
| 107 | // } |
| 108 | // else |
| 109 | // break; // nothing else to do. All later records will not be stale |
| 110 | // } |
| 111 | } |
| 112 | |
| 113 | Ptr<CcnxPitEntry> |
| 114 | CcnxPitImpl::Lookup (const CcnxContentObjectHeader &header) const |
| 115 | { |
| 116 | return 0; |
| 117 | // iterator entry = end (); |
| 118 | |
| 119 | // // do the longest prefix match |
| 120 | // const CcnxNameComponents &name = header.GetName (); |
| 121 | // for (size_t componentsCount = name.GetComponents ().size ()+1; |
| 122 | // componentsCount > 0; |
| 123 | // componentsCount--) |
| 124 | // { |
| 125 | // CcnxNameComponents subPrefix (name.GetSubComponents (componentsCount-1)); |
| 126 | |
| 127 | // entry = get<i_prefix> ().find (subPrefix); |
| 128 | // if (entry != end()) |
| 129 | // return entry; |
| 130 | // } |
| 131 | |
| 132 | // return end (); |
| 133 | } |
| 134 | |
| 135 | Ptr<CcnxPitEntry> |
| 136 | CcnxPitImpl::Lookup (const CcnxInterestHeader &header) |
| 137 | { |
| 138 | return 0; |
| 139 | // NS_LOG_FUNCTION (header.GetName ()); |
| 140 | // NS_ASSERT_MSG (m_fib != 0, "FIB should be set"); |
| 141 | |
| 142 | // iterator entry = get<i_prefix> ().find (header.GetName ()); |
| 143 | // if (entry == end ()) |
| 144 | // return end (); |
| 145 | |
| 146 | // return entry; |
| 147 | } |
| 148 | |
| 149 | bool |
| 150 | CcnxPitImpl::CheckIfDuplicate (Ptr<CcnxPitEntry> entry, const CcnxInterestHeader &header) |
| 151 | { |
| 152 | // if (!entry->IsNonceSeen (header.GetNonce ())) |
| 153 | // { |
| 154 | // modify (entry, |
| 155 | // boost::bind(&CcnxPitEntry::AddSeenNonce, ll::_1, header.GetNonce ())); |
| 156 | // return false; |
| 157 | // } |
| 158 | // else |
| 159 | // return true; |
| 160 | return false; |
| 161 | } |
| 162 | |
| 163 | Ptr<CcnxPitEntry> |
| 164 | CcnxPitImpl::Create (const CcnxInterestHeader &header) |
| 165 | { |
| 166 | // NS_ASSERT_MSG (get<i_prefix> ().find (header.GetName ()) == end (), |
| 167 | // "Entry already exists, Create must not be called!!!"); |
| 168 | |
| 169 | // if (m_maxSize > 0 && |
| 170 | // size () >= m_maxSize) |
| 171 | // { |
| 172 | // // remove old record |
| 173 | // get<i_timestamp> ().erase (get<i_timestamp> ().begin ()); |
| 174 | // } |
| 175 | |
| 176 | // Ptr<CcnxFibEntry> fibEntry = m_fib->LongestPrefixMatch (header); |
| 177 | // // NS_ASSERT_MSG (fibEntry != m_fib->m_fib.end (), |
| 178 | // // "There should be at least default route set" << " Prefix = "<<header.GetName() << "NodeID == " << m_fib->GetObject<Node>()->GetId() << "\n" << *m_fib); |
| 179 | |
| 180 | // return insert (end (), |
| 181 | // CcnxPitEntry (ns3::Create<CcnxNameComponents> (header.GetName ()), |
| 182 | // header.GetInterestLifetime ().IsZero ()?m_PitEntryDefaultLifetime |
| 183 | // : header.GetInterestLifetime (), |
| 184 | // fibEntry)); |
| 185 | return 0; |
| 186 | } |
| 187 | |
| 188 | |
| 189 | void |
| 190 | CcnxPitImpl::MarkErased (Ptr<CcnxPitEntry> entry) |
| 191 | { |
| 192 | // modify (entry, |
| 193 | // ll::bind (&CcnxPitEntry::SetExpireTime, ll::_1, |
| 194 | // Simulator::Now () + m_PitEntryPruningTimout)); |
| 195 | } |
| 196 | |
| 197 | |
| 198 | void |
| 199 | CcnxPitImpl::Print (std::ostream& os) const |
| 200 | { |
| 201 | os << "Should be implemented soon\n"; |
| 202 | // BOOST_FOREACH (const CcnxPitEntry &entry, pit) |
| 203 | // { |
| 204 | // if (entry.m_incoming.size () == 0 && entry.m_outgoing.size () == 0) |
| 205 | // continue; // these are stale to-be-removed records, so there is no need to print them out |
| 206 | |
| 207 | // os << entry << std::endl; |
| 208 | // } |
| 209 | } |
| 210 | |
| 211 | } // namespace ns3 |