Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 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> |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 19 | * Ilya Moiseenko <iliamo@cs.ucla.edu> |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 20 | */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 21 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 22 | #include "ccnx-l3-protocol.h" |
| 23 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 24 | #include "ns3/packet.h" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 25 | #include "ns3/node.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 26 | #include "ns3/log.h" |
| 27 | #include "ns3/callback.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 28 | #include "ns3/uinteger.h" |
| 29 | #include "ns3/trace-source-accessor.h" |
| 30 | #include "ns3/object-vector.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 31 | #include "ns3/boolean.h" |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 32 | #include "ns3/string.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 33 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 34 | #include "ns3/ccnx-header-helper.h" |
| 35 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 36 | #include "ccnx-face.h" |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 37 | #include "ccnx-forwarding-strategy.h" |
| 38 | #include "ccnx-interest-header.h" |
| 39 | #include "ccnx-content-object-header.h" |
| 40 | |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 41 | #include "ccnx-net-device-face.h" |
| 42 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 43 | #include <boost/foreach.hpp> |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 44 | #include <boost/lambda/lambda.hpp> |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 45 | #include <boost/lambda/bind.hpp> |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 46 | |
| 47 | using namespace boost::tuples; |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 48 | namespace ll = boost::lambda; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 49 | |
| 50 | NS_LOG_COMPONENT_DEFINE ("CcnxL3Protocol"); |
| 51 | |
| 52 | namespace ns3 { |
| 53 | |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 54 | const uint16_t CcnxL3Protocol::ETHERNET_FRAME_TYPE = 0x7777; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 55 | |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 56 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 57 | NS_OBJECT_ENSURE_REGISTERED (CcnxL3Protocol); |
| 58 | |
| 59 | TypeId |
| 60 | CcnxL3Protocol::GetTypeId (void) |
| 61 | { |
| 62 | static TypeId tid = TypeId ("ns3::CcnxL3Protocol") |
| 63 | .SetParent<Ccnx> () |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 64 | .SetGroupName ("Ccnx") |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 65 | .AddConstructor<CcnxL3Protocol> () |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 66 | .AddAttribute ("BucketLeakInterval", |
| 67 | "Interval to leak buckets", |
| 68 | StringValue ("10ms"), |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 69 | MakeTimeAccessor (&CcnxL3Protocol::GetBucketLeakInterval, |
| 70 | &CcnxL3Protocol::SetBucketLeakInterval), |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 71 | MakeTimeChecker ()) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 72 | ; |
| 73 | return tid; |
| 74 | } |
| 75 | |
| 76 | CcnxL3Protocol::CcnxL3Protocol() |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 77 | : m_faceCounter (0) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 78 | { |
| 79 | NS_LOG_FUNCTION (this); |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 80 | |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 81 | m_pit = CreateObject<CcnxPit> (); |
| 82 | m_contentStore = CreateObject<CcnxContentStore> (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | CcnxL3Protocol::~CcnxL3Protocol () |
| 86 | { |
| 87 | NS_LOG_FUNCTION (this); |
| 88 | } |
| 89 | |
| 90 | void |
| 91 | CcnxL3Protocol::SetNode (Ptr<Node> node) |
| 92 | { |
| 93 | m_node = node; |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 94 | m_fib = m_node->GetObject<CcnxFib> (); |
| 95 | NS_ASSERT_MSG (m_fib != 0, "FIB should be created and aggregated to a node before calling Ccnx::SetNode"); |
| 96 | |
| 97 | m_pit->SetFib (m_fib); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | /* |
| 101 | * This method is called by AddAgregate and completes the aggregation |
| 102 | * by setting the node in the ccnx stack |
| 103 | */ |
| 104 | void |
| 105 | CcnxL3Protocol::NotifyNewAggregate () |
| 106 | { |
| 107 | if (m_node == 0) |
| 108 | { |
| 109 | Ptr<Node>node = this->GetObject<Node>(); |
| 110 | // verify that it's a valid node and that |
| 111 | // the node has not been set before |
| 112 | if (node != 0) |
| 113 | { |
| 114 | this->SetNode (node); |
| 115 | } |
| 116 | } |
| 117 | Object::NotifyNewAggregate (); |
| 118 | } |
| 119 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 120 | void |
| 121 | CcnxL3Protocol::DoDispose (void) |
| 122 | { |
| 123 | NS_LOG_FUNCTION (this); |
| 124 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 125 | if (m_bucketLeakEvent.IsRunning ()) |
| 126 | m_bucketLeakEvent.Cancel (); |
| 127 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 128 | for (CcnxFaceList::iterator i = m_faces.begin (); i != m_faces.end (); ++i) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 129 | { |
| 130 | *i = 0; |
| 131 | } |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 132 | m_faces.clear (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 133 | m_node = 0; |
Alexander Afanasyev | d02a5d6 | 2011-11-21 11:01:51 -0800 | [diff] [blame] | 134 | |
| 135 | // Force delete on objects |
Alexander Afanasyev | 1825285 | 2011-11-21 13:35:31 -0800 | [diff] [blame] | 136 | m_forwardingStrategy = 0; // there is a reference to PIT stored in here |
Alexander Afanasyev | d02a5d6 | 2011-11-21 11:01:51 -0800 | [diff] [blame] | 137 | m_pit = 0; |
| 138 | m_contentStore = 0; |
Alexander Afanasyev | 1825285 | 2011-11-21 13:35:31 -0800 | [diff] [blame] | 139 | m_fib = 0; |
| 140 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 141 | // m_forwardingStrategy = 0; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 142 | Object::DoDispose (); |
| 143 | } |
| 144 | |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 145 | void |
| 146 | CcnxL3Protocol::SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy) |
| 147 | { |
| 148 | NS_LOG_FUNCTION (this); |
| 149 | m_forwardingStrategy = forwardingStrategy; |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 150 | m_forwardingStrategy->SetPit (m_pit); |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | Ptr<CcnxForwardingStrategy> |
| 154 | CcnxL3Protocol::GetForwardingStrategy (void) const |
| 155 | { |
| 156 | return m_forwardingStrategy; |
| 157 | } |
| 158 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 159 | uint32_t |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 160 | CcnxL3Protocol::AddFace (const Ptr<CcnxFace> &face) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 161 | { |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 162 | NS_LOG_FUNCTION (this << &face); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 163 | |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 164 | face->SetId (m_faceCounter); // sets a unique ID of the face. This ID serves only informational purposes |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 165 | |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 166 | // ask face to register in lower-layer stack |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 167 | face->RegisterProtocolHandler (MakeCallback (&CcnxL3Protocol::Receive, this)); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 168 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 169 | m_faces.push_back (face); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 170 | m_faceCounter++; |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 171 | return face->GetId (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 174 | void |
| 175 | CcnxL3Protocol::RemoveFace (Ptr<CcnxFace> face) |
| 176 | { |
| 177 | // ask face to register in lower-layer stack |
| 178 | face->RegisterProtocolHandler (MakeNullCallback<void,const Ptr<CcnxFace>&,const Ptr<const Packet>&> ()); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 179 | |
| 180 | // just to be on a safe side. Do the process in two steps |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 181 | std::list<boost::reference_wrapper<const CcnxPitEntry> > entriesToRemoves; |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 182 | BOOST_FOREACH (const CcnxPitEntry &pitEntry, *m_pit) |
| 183 | { |
| 184 | m_pit->modify (m_pit->iterator_to (pitEntry), |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 185 | ll::bind (&CcnxPitEntry::RemoveAllReferencesToFace, ll::_1, face)); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 186 | |
| 187 | // If this face is the only for the associated FIB entry, then FIB entry will be removed soon. |
| 188 | // Thus, we have to remove the whole PIT entry |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 189 | if (pitEntry.m_fibEntry.m_faces.size () == 1 && |
| 190 | pitEntry.m_fibEntry.m_faces.begin ()->m_face == face) |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 191 | { |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 192 | entriesToRemoves.push_back (boost::cref (pitEntry)); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 193 | } |
| 194 | } |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 195 | BOOST_FOREACH (const CcnxPitEntry &removedEntry, entriesToRemoves) |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 196 | { |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 197 | m_pit->erase (m_pit->iterator_to (removedEntry)); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 198 | } |
| 199 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 200 | CcnxFaceList::iterator face_it = find (m_faces.begin(), m_faces.end(), face); |
| 201 | NS_ASSERT_MSG (face_it != m_faces.end (), "Attempt to remove face that doesn't exist"); |
| 202 | m_faces.erase (face_it); |
| 203 | } |
| 204 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 205 | Ptr<CcnxFace> |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 206 | CcnxL3Protocol::GetFace (uint32_t index) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 207 | { |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 208 | BOOST_FOREACH (const Ptr<CcnxFace> &face, m_faces) // this function is not supposed to be called often, so linear search is fine |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 209 | { |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 210 | if (face->GetId () == index) |
| 211 | return face; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 212 | } |
| 213 | return 0; |
| 214 | } |
| 215 | |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 216 | Ptr<CcnxFace> |
| 217 | CcnxL3Protocol::GetFaceByNetDevice (Ptr<NetDevice> netDevice) const |
| 218 | { |
| 219 | BOOST_FOREACH (const Ptr<CcnxFace> &face, m_faces) // this function is not supposed to be called often, so linear search is fine |
| 220 | { |
| 221 | Ptr<CcnxNetDeviceFace> netDeviceFace = DynamicCast<CcnxNetDeviceFace> (face); |
| 222 | if (netDeviceFace == 0) continue; |
| 223 | |
| 224 | if (netDeviceFace->GetNetDevice () == netDevice) |
| 225 | return face; |
| 226 | } |
| 227 | return 0; |
| 228 | } |
| 229 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 230 | uint32_t |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 231 | CcnxL3Protocol::GetNFaces (void) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 232 | { |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 233 | return m_faces.size (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 236 | // Callback from lower layer |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 237 | void |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 238 | CcnxL3Protocol::Receive (const Ptr<CcnxFace> &face, const Ptr<const Packet> &p) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 239 | { |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 240 | if (!face->IsUp ()) |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 241 | { |
| 242 | NS_LOG_LOGIC ("Dropping received packet -- interface is down"); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 243 | // m_dropTrace (p, INTERFACE_DOWN, m_node->GetObject<Ccnx> ()/*this*/, face); |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 244 | return; |
| 245 | } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 246 | NS_LOG_LOGIC ("Packet from face " << *face << " received on node " << m_node->GetId ()); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 247 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 248 | Ptr<Packet> packet = p->Copy (); // give upper layers a rw copy of the packet |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 249 | try |
| 250 | { |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 251 | CcnxHeaderHelper::Type type = CcnxHeaderHelper::GetCcnxHeaderType (p); |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 252 | switch (type) |
| 253 | { |
| 254 | case CcnxHeaderHelper::INTEREST: |
| 255 | { |
| 256 | Ptr<CcnxInterestHeader> header = Create<CcnxInterestHeader> (); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 257 | |
| 258 | // Deserialization. Exception may be thrown |
| 259 | packet->RemoveHeader (*header); |
| 260 | NS_ASSERT_MSG (packet->GetSize () == 0, "Payload of Interests should be zero"); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 261 | |
| 262 | if (header->GetNack () > 0) |
| 263 | OnNack (face, header, p/*original packet*/); |
| 264 | else |
| 265 | OnInterest (face, header, p/*original packet*/); |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 266 | break; |
| 267 | } |
| 268 | case CcnxHeaderHelper::CONTENT_OBJECT: |
| 269 | { |
| 270 | Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> (); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 271 | |
| 272 | static CcnxContentObjectTail contentObjectTrailer; //there is no data in this object |
| 273 | |
| 274 | // Deserialization. Exception may be thrown |
| 275 | packet->RemoveHeader (*header); |
| 276 | packet->RemoveTrailer (contentObjectTrailer); |
| 277 | |
| 278 | OnData (face, header, packet/*payload*/, p/*original packet*/); |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 279 | break; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | // exception will be thrown if packet is not recognized |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 284 | } |
| 285 | catch (CcnxUnknownHeaderException) |
| 286 | { |
| 287 | NS_ASSERT_MSG (false, "Unknown CCNx header. Should not happen"); |
| 288 | } |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 289 | } |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 290 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 291 | void |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 292 | CcnxL3Protocol::OnNack (const Ptr<CcnxFace> &incomingFace, |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 293 | Ptr<CcnxInterestHeader> &header, |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 294 | const Ptr<const Packet> &packet) |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 295 | { |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 296 | NS_LOG_FUNCTION (incomingFace << header << packet); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 297 | |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 298 | tuple<const CcnxPitEntry&,bool,bool> ret = m_pit->Lookup (*header); |
| 299 | CcnxPitEntry const& pitEntry = ret.get<0> (); |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 300 | bool isNew = ret.get<1> (); |
Alexander Afanasyev | e67a97f | 2011-11-29 14:28:59 -0800 | [diff] [blame] | 301 | bool isDuplicated = ret.get<2> (); |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 302 | |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 303 | // NS_ASSERT_MSG (isDuplicated, |
| 304 | // "NACK should be a duplicated interest"); |
Alexander Afanasyev | e67a97f | 2011-11-29 14:28:59 -0800 | [diff] [blame] | 305 | if (isNew || !isDuplicated) // potential flow |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 306 | { |
| 307 | // somebody is doing something bad |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 308 | return; |
| 309 | } |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 310 | |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 311 | // CcnxPitEntryIncomingFaceContainer::type::iterator inFace = pitEntry.m_incoming.find (incomingFace); |
| 312 | CcnxPitEntryOutgoingFaceContainer::type::iterator outFace = pitEntry.m_outgoing.find (incomingFace); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 313 | |
Alexander Afanasyev | e67a97f | 2011-11-29 14:28:59 -0800 | [diff] [blame] | 314 | if (outFace == pitEntry.m_outgoing.end ()) |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 315 | { |
Alexander Afanasyev | e67a97f | 2011-11-29 14:28:59 -0800 | [diff] [blame] | 316 | NS_ASSERT_MSG (false, |
| 317 | "Node " << GetObject<Node> ()->GetId () << ", outgoing entry should exist for face " << boost::cref(*incomingFace) << "\n" << |
| 318 | "size: " << pitEntry.m_outgoing.size ()); |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 319 | |
| 320 | return; |
| 321 | } |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 322 | |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 323 | // This was done in error. Never, never do anything, except normal leakage. This way we ensure that we will not have losses, |
| 324 | // at least when there is only one client |
| 325 | // |
| 326 | // incomingFace->LeakBucketByOnePacket (); |
Alexander Afanasyev | e67a97f | 2011-11-29 14:28:59 -0800 | [diff] [blame] | 327 | |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 328 | NS_LOG_ERROR ("Nack on " << boost::cref(*incomingFace)); |
| 329 | |
Alexander Afanasyev | 5a59507 | 2011-11-25 14:49:07 -0800 | [diff] [blame] | 330 | m_pit->modify (m_pit->iterator_to (pitEntry), |
| 331 | ll::bind (&CcnxPitEntry::SetWaitingInVain, ll::_1, outFace)); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 332 | |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 333 | // m_droppedInterestsTrace (header, DROP_CONGESTION, m_node->GetObject<Ccnx> (), incomingFace); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 334 | |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 335 | // If NACK is NACK_GIVEUP_PIT, then neighbor gave up trying to and removed it's PIT entry. |
| 336 | // So, if we had an incoming entry to this neighbor, then we can remove it now |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 337 | |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 338 | if (header->GetNack () == CcnxInterestHeader::NACK_GIVEUP_PIT) |
| 339 | { |
| 340 | m_pit->modify (m_pit->iterator_to (pitEntry), |
| 341 | ll::bind (&CcnxPitEntry::RemoveIncoming, ll::_1, incomingFace)); |
| 342 | } |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 343 | |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 344 | m_fib->m_fib.modify (m_fib->m_fib.iterator_to (pitEntry.m_fibEntry), |
| 345 | ll::bind (&CcnxFibEntry::UpdateStatus, |
| 346 | ll::_1, incomingFace, CcnxFibFaceMetric::NDN_FIB_YELLOW)); |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 347 | |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 348 | if (pitEntry.m_incoming.size () == 0) // interest was actually satisfied |
| 349 | { |
| 350 | // no need to do anything |
| 351 | return; |
| 352 | } |
| 353 | |
Alexander Afanasyev | e67a97f | 2011-11-29 14:28:59 -0800 | [diff] [blame] | 354 | if (!pitEntry.AreAllOutgoingInVain ()) // not all ougtoing are in vain |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 355 | { |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 356 | NS_LOG_DEBUG ("Not all outgoing are in vain"); |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 357 | // suppress |
| 358 | // Don't do anything, we are still expecting data from some other face |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 359 | return; |
| 360 | } |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 361 | |
| 362 | NS_ASSERT_MSG (m_forwardingStrategy != 0, "Need a forwarding protocol object to process packets"); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 363 | |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 364 | Ptr<Packet> nonNackInterest = Create<Packet> (); |
| 365 | header->SetNack (CcnxInterestHeader::NORMAL_INTEREST); |
| 366 | nonNackInterest->AddHeader (*header); |
| 367 | |
| 368 | bool propagated = m_forwardingStrategy-> |
| 369 | PropagateInterest (pitEntry, incomingFace, header, nonNackInterest); |
| 370 | |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 371 | // // ForwardingStrategy will try its best to forward packet to at least one interface. |
| 372 | // // If no interests was propagated, then there is not other option for forwarding or |
| 373 | // // ForwardingStrategy failed to find it. |
Alexander Afanasyev | e67a97f | 2011-11-29 14:28:59 -0800 | [diff] [blame] | 374 | if (!propagated) |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 375 | GiveUpInterest (pitEntry, header); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 376 | } |
| 377 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 378 | // Processing Interests |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 379 | // |
| 380 | // !!! Key point. |
| 381 | // !!! All interests should be answerred!!! Either later with data, immediately with data, or immediately with NACK |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 382 | void CcnxL3Protocol::OnInterest (const Ptr<CcnxFace> &incomingFace, |
| 383 | Ptr<CcnxInterestHeader> &header, |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 384 | const Ptr<const Packet> &packet) |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 385 | { |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 386 | NS_LOG_FUNCTION (incomingFace << header << packet); |
| 387 | // m_receivedInterestsTrace (header, m_node->GetObject<Ccnx> (), incomingFace); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 388 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 389 | // Lookup of Pit (and associated Fib) entry for this Interest |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 390 | tuple<const CcnxPitEntry&,bool,bool> ret = m_pit->Lookup (*header); |
| 391 | CcnxPitEntry const& pitEntry = ret.get<0> (); |
| 392 | // bool isNew = ret.get<1> (); |
| 393 | bool isDuplicated = ret.get<2> (); |
Ilya Moiseenko | d83eb0d | 2011-11-16 15:23:46 -0800 | [diff] [blame] | 394 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 395 | if (isDuplicated) |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 396 | { |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 397 | /** |
| 398 | * This condition will handle "routing" loops and also recently satisfied interests. |
| 399 | * Every time interest is satisfied, PIT entry (with empty incoming and outgoing faces) |
| 400 | * is kept for another small chunk of time. |
| 401 | */ |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 402 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 403 | // //Trace duplicate interest |
| 404 | // m_droppedInterestsTrace (header, NDN_DUPLICATE_INTEREST, m_node->GetObject<Ccnx> (), incomingFace); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 405 | |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 406 | NS_LOG_DEBUG ("Sending NACK_LOOP"); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 407 | header->SetNack (CcnxInterestHeader::NACK_LOOP); |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 408 | Ptr<Packet> nack = Create<Packet> (); |
| 409 | nack->AddHeader (*header); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 410 | |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 411 | incomingFace->Send (nack); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 412 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 413 | // //Trace duplicate interest |
| 414 | // m_droppedInterestsTrace (header, NDN_DUPLICATE_INTEREST, m_node->GetObject<Ccnx> (), incomingFace); |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 415 | return; |
| 416 | } |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 417 | |
| 418 | Ptr<Packet> contentObject; |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 419 | Ptr<const CcnxContentObjectHeader> contentObjectHeader; // unused for now |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 420 | tie (contentObject, contentObjectHeader) = m_contentStore->Lookup (header); |
| 421 | if (contentObject != 0) |
| 422 | { |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 423 | NS_ASSERT (contentObjectHeader != 0); |
| 424 | |
| 425 | NS_LOG_LOGIC("Found in cache"); |
| 426 | |
| 427 | // TransmittedDataTrace (contentObject, CACHED, |
| 428 | // m_node->GetObject<Ccnx> (), incomingFace); |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 429 | incomingFace->Send (contentObject); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 430 | |
| 431 | // Set pruning timout on PIT entry (instead of deleting the record) |
| 432 | m_pit->modify (m_pit->iterator_to (pitEntry), |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 433 | bind (&CcnxPitEntry::SetExpireTime, ll::_1, |
| 434 | Simulator::Now () + m_pit->GetPitEntryPruningTimeout ())); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 435 | return; |
| 436 | } |
| 437 | |
| 438 | // \todo Detect retransmissions. Not yet sure how... |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 439 | |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 440 | // Data is not in cache |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 441 | CcnxPitEntryIncomingFaceContainer::type::iterator inFace = pitEntry.m_incoming.find (incomingFace); |
| 442 | CcnxPitEntryOutgoingFaceContainer::type::iterator outFace = pitEntry.m_outgoing.find (incomingFace); |
| 443 | |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 444 | bool isRetransmitted = false; |
| 445 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 446 | if (inFace != pitEntry.m_incoming.end ()) |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 447 | { |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 448 | // CcnxPitEntryIncomingFace.m_arrivalTime keeps track arrival time of the first packet... why? |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 449 | |
| 450 | isRetransmitted = true; |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 451 | // this is almost definitely a retransmission. But should we trust the user on that? |
| 452 | } |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 453 | else |
| 454 | { |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 455 | m_pit->modify (m_pit->iterator_to (pitEntry), |
| 456 | ll::var(inFace) = ll::bind (&CcnxPitEntry::AddIncoming, ll::_1, incomingFace)); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 457 | } |
| 458 | |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 459 | // update PIT entry lifetime |
| 460 | m_pit->modify (m_pit->iterator_to (pitEntry), |
| 461 | ll::bind (&CcnxPitEntry::UpdateLifetime, ll::_1, |
| 462 | header->GetInterestLifetime ())); |
| 463 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 464 | if (outFace != pitEntry.m_outgoing.end ()) |
| 465 | { |
| 466 | // got a non-duplicate interest from the face we have sent interest to |
| 467 | // Probably, there is no point in waiting data from that face... Not sure yet |
| 468 | |
| 469 | // If we're expecting data from the interface we got the interest from ("producer" asks us for "his own" data) |
| 470 | // Mark interface YELLOW, but keep a small hope that data will come eventually. |
| 471 | |
| 472 | // ?? not sure if we need to do that ?? ... |
| 473 | |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 474 | m_fib->m_fib.modify(m_fib->m_fib.iterator_to (pitEntry.m_fibEntry), |
| 475 | ll::bind (&CcnxFibEntry::UpdateStatus, |
| 476 | ll::_1, incomingFace, CcnxFibFaceMetric::NDN_FIB_YELLOW)); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 477 | } |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 478 | |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 479 | if (!isRetransmitted && |
| 480 | pitEntry.AreTherePromisingOutgoingFacesExcept (incomingFace)) |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 481 | { // Suppress this interest if we're still expecting data from some other face |
| 482 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 483 | // We are already expecting data later in future. Suppress the interest |
| 484 | // m_droppedInterestsTrace (header, NDN_SUPPRESSED_INTEREST, m_node->GetObject<Ccnx> (), incomingFace); |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 485 | return; |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 486 | } |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 487 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 488 | ///////////////////////////////////////////////////////////////////// |
| 489 | // Propagate |
| 490 | ///////////////////////////////////////////////////////////////////// |
| 491 | |
| 492 | NS_ASSERT_MSG (m_forwardingStrategy != 0, "Need a forwarding protocol object to process packets"); |
| 493 | |
| 494 | bool propagated = m_forwardingStrategy-> |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 495 | PropagateInterest (pitEntry, incomingFace, header, packet); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 496 | |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 497 | if (isRetransmitted) //give another chance if retransmitted |
| 498 | { |
| 499 | // increase max number of allowed retransmissions |
| 500 | m_pit->modify (m_pit->iterator_to (pitEntry), |
| 501 | ll::bind (&CcnxPitEntry::IncreaseAllowedRetxCount, ll::_1)); |
| 502 | |
| 503 | // try again |
| 504 | propagated = m_forwardingStrategy-> |
| 505 | PropagateInterest (pitEntry, incomingFace, header, packet); |
| 506 | } |
| 507 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 508 | // ForwardingStrategy will try its best to forward packet to at least one interface. |
| 509 | // If no interests was propagated, then there is not other option for forwarding or |
| 510 | // ForwardingStrategy failed to find it. |
Alexander Afanasyev | e67a97f | 2011-11-29 14:28:59 -0800 | [diff] [blame] | 511 | if (!propagated) |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 512 | GiveUpInterest (pitEntry, header); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 515 | void |
| 516 | CcnxL3Protocol::GiveUpInterest (const CcnxPitEntry &pitEntry, |
| 517 | Ptr<CcnxInterestHeader> header) |
| 518 | { |
| 519 | Ptr<Packet> packet = Create<Packet> (); |
| 520 | header->SetNack (CcnxInterestHeader::NACK_GIVEUP_PIT); |
| 521 | packet->AddHeader (*header); |
| 522 | |
| 523 | BOOST_FOREACH (const CcnxPitEntryIncomingFace &incoming, pitEntry.m_incoming) |
| 524 | { |
| 525 | incoming.m_face->Send (packet->Copy ()); |
| 526 | |
| 527 | // m_droppedInterestsTrace (header, DROP_CONGESTION, |
| 528 | // m_node->GetObject<Ccnx> (), incomingFace); |
| 529 | } |
| 530 | // All incoming interests cannot be satisfied. Remove them |
| 531 | m_pit->modify (m_pit->iterator_to (pitEntry), |
| 532 | ll::bind (&CcnxPitEntry::ClearIncoming, ll::_1)); |
| 533 | |
| 534 | // Set pruning timout on PIT entry (instead of deleting the record) |
| 535 | m_pit->modify (m_pit->iterator_to (pitEntry), |
| 536 | ll::bind (&CcnxPitEntry::SetExpireTime, ll::_1, |
| 537 | Simulator::Now () + m_pit->GetPitEntryPruningTimeout ())); |
| 538 | } |
| 539 | |
| 540 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 541 | // Processing ContentObjects |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 542 | void |
| 543 | CcnxL3Protocol::OnData (const Ptr<CcnxFace> &incomingFace, |
| 544 | Ptr<CcnxContentObjectHeader> &header, |
| 545 | Ptr<Packet> &payload, |
| 546 | const Ptr<const Packet> &packet) |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 547 | { |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 548 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 549 | NS_LOG_FUNCTION (incomingFace << header << payload << packet); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 550 | // m_receivedDataTrace (header, payload, m_node->GetObject<Ccnx> ()/*this*/, incomingFace); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 551 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 552 | // 1. Lookup PIT entry |
| 553 | try |
| 554 | { |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 555 | const CcnxPitEntry &pitEntry = m_pit->Lookup (*header); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 556 | |
| 557 | // Note that with MultiIndex we need to modify entries indirectly |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 558 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 559 | CcnxPitEntryOutgoingFaceContainer::type::iterator out = pitEntry.m_outgoing.find (incomingFace); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 560 | |
| 561 | // If we have sent interest for this data via this face, then update stats. |
| 562 | if (out != pitEntry.m_outgoing.end ()) |
| 563 | { |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 564 | m_fib->m_fib.modify (m_fib->m_fib.iterator_to (pitEntry.m_fibEntry), |
| 565 | ll::bind (&CcnxFibEntry::UpdateFaceRtt, |
| 566 | ll::_1, |
| 567 | incomingFace, |
| 568 | Simulator::Now () - out->m_sendTime)); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 569 | } |
| 570 | else |
| 571 | { |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 572 | // Unsolicited data, but we're interested in it... should we get it? |
| 573 | // Potential hole for attacks |
| 574 | |
| 575 | NS_LOG_ERROR ("Node "<< m_node->GetId() << |
| 576 | ". PIT entry for "<< header->GetName ()<<" is valid, " |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 577 | "but outgoing entry for interface "<< boost::cref(*incomingFace) <<" doesn't exist\n"); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 578 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 579 | // ignore unsolicited data |
| 580 | return; |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 581 | } |
| 582 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 583 | // Update metric status for the incoming interface in the corresponding FIB entry |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 584 | m_fib->m_fib.modify (m_fib->m_fib.iterator_to (pitEntry.m_fibEntry), |
| 585 | ll::bind (&CcnxFibEntry::UpdateStatus, ll::_1, |
| 586 | incomingFace, CcnxFibFaceMetric::NDN_FIB_GREEN)); |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 587 | |
| 588 | // Add or update entry in the content store |
| 589 | m_contentStore->Add (header, payload); |
| 590 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 591 | //satisfy all pending incoming Interests |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 592 | BOOST_FOREACH (const CcnxPitEntryIncomingFace &incoming, pitEntry.m_incoming) |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 593 | { |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 594 | if (incoming.m_face != incomingFace) |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 595 | incoming.m_face->Send (packet->Copy ()); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 596 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 597 | // successfull forwarded data trace |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 598 | } |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 599 | // All incoming interests are satisfied. Remove them |
| 600 | m_pit->modify (m_pit->iterator_to (pitEntry), |
| 601 | ll::bind (&CcnxPitEntry::ClearIncoming, ll::_1)); |
| 602 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 603 | // Set pruning timout on PIT entry (instead of deleting the record) |
| 604 | m_pit->modify (m_pit->iterator_to (pitEntry), |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 605 | ll::bind (&CcnxPitEntry::SetExpireTime, ll::_1, |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 606 | Simulator::Now () + m_pit->GetPitEntryPruningTimeout ())); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 607 | } |
| 608 | catch (CcnxPitEntryNotFound) |
| 609 | { |
| 610 | // 2. Drop data packet if PIT entry is not found |
| 611 | // (unsolicited data packets should not "poison" content store) |
| 612 | |
| 613 | //drop dulicated or not requested data packet |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 614 | // m_droppedDataTrace (header, payload, NDN_UNSOLICITED_DATA, m_node->GetObject<Ccnx> (), incomingFace); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 615 | return; // do not process unsoliced data packets |
| 616 | } |
| 617 | } |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 618 | |
| 619 | void |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 620 | CcnxL3Protocol::SetBucketLeakInterval (Time interval) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 621 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 622 | m_bucketLeakInterval = interval; |
| 623 | |
| 624 | if (m_bucketLeakEvent.IsRunning ()) |
| 625 | m_bucketLeakEvent.Cancel (); |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 626 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 627 | m_bucketLeakEvent = Simulator::Schedule (m_bucketLeakInterval, |
| 628 | &CcnxL3Protocol::LeakBuckets, this); |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 629 | } |
| 630 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 631 | Time |
| 632 | CcnxL3Protocol::GetBucketLeakInterval () const |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 633 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 634 | return m_bucketLeakInterval; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 637 | void |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 638 | CcnxL3Protocol::LeakBuckets () |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 639 | { |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 640 | // NS_LOG_FUNCTION (this); |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 641 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 642 | BOOST_FOREACH (const Ptr<CcnxFace> &face, m_faces) |
| 643 | { |
| 644 | face->LeakBucket (m_bucketLeakInterval); |
| 645 | } |
| 646 | |
| 647 | m_bucketLeakEvent = Simulator::Schedule (m_bucketLeakInterval, |
Alexander Afanasyev | b5703a9 | 2011-11-25 16:46:15 -0800 | [diff] [blame] | 648 | &CcnxL3Protocol::LeakBuckets, |
| 649 | this); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 650 | } |
Ilya Moiseenko | d83eb0d | 2011-11-16 15:23:46 -0800 | [diff] [blame] | 651 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 652 | } //namespace ns3 |