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 | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 32 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 33 | #include "ns3/ccnx-header-helper.h" |
| 34 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 35 | #include "ccnx-face.h" |
| 36 | #include "ccnx-route.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 | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 44 | |
| 45 | NS_LOG_COMPONENT_DEFINE ("CcnxL3Protocol"); |
| 46 | |
| 47 | namespace ns3 { |
| 48 | |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 49 | const uint16_t CcnxL3Protocol::ETHERNET_FRAME_TYPE = 0x7777; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 50 | |
| 51 | NS_OBJECT_ENSURE_REGISTERED (CcnxL3Protocol); |
| 52 | |
| 53 | TypeId |
| 54 | CcnxL3Protocol::GetTypeId (void) |
| 55 | { |
| 56 | static TypeId tid = TypeId ("ns3::CcnxL3Protocol") |
| 57 | .SetParent<Ccnx> () |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 58 | .SetGroupName ("Ccnx") |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 59 | .AddConstructor<CcnxL3Protocol> () |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 60 | // .AddTraceSource ("Tx", "Send ccnx packet to outgoing interface.", |
| 61 | // MakeTraceSourceAccessor (&CcnxL3Protocol::m_txTrace)) |
| 62 | // .AddTraceSource ("Rx", "Receive ccnx packet from incoming interface.", |
| 63 | // MakeTraceSourceAccessor (&CcnxL3Protocol::m_rxTrace)) |
| 64 | // .AddTraceSource ("Drop", "Drop ccnx packet", |
| 65 | // MakeTraceSourceAccessor (&CcnxL3Protocol::m_dropTrace)) |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 66 | // .AddAttribute ("InterfaceList", "The set of Ccnx interfaces associated to this Ccnx stack.", |
| 67 | // ObjectVectorValue (), |
| 68 | // MakeObjectVectorAccessor (&CcnxL3Protocol::m_faces), |
| 69 | // MakeObjectVectorChecker<CcnxFace> ()) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 70 | |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 71 | // .AddTraceSource ("SendOutgoing", "A newly-generated packet by this node is about to be queued for transmission", |
| 72 | // MakeTraceSourceAccessor (&CcnxL3Protocol::m_sendOutgoingTrace)) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 73 | |
| 74 | ; |
| 75 | return tid; |
| 76 | } |
| 77 | |
| 78 | CcnxL3Protocol::CcnxL3Protocol() |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 79 | : m_faceCounter (0) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 80 | { |
| 81 | NS_LOG_FUNCTION (this); |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 82 | |
| 83 | m_rit = CreateObject<CcnxRit> (); |
| 84 | m_pit = CreateObject<CcnxPit> (); |
| 85 | m_contentStore = CreateObject<CcnxContentStore> (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | CcnxL3Protocol::~CcnxL3Protocol () |
| 89 | { |
| 90 | NS_LOG_FUNCTION (this); |
| 91 | } |
| 92 | |
| 93 | void |
| 94 | CcnxL3Protocol::SetNode (Ptr<Node> node) |
| 95 | { |
| 96 | m_node = node; |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 97 | m_fib = m_node->GetObject<CcnxFib> (); |
| 98 | NS_ASSERT_MSG (m_fib != 0, "FIB should be created and aggregated to a node before calling Ccnx::SetNode"); |
| 99 | |
| 100 | m_pit->SetFib (m_fib); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /* |
| 104 | * This method is called by AddAgregate and completes the aggregation |
| 105 | * by setting the node in the ccnx stack |
| 106 | */ |
| 107 | void |
| 108 | CcnxL3Protocol::NotifyNewAggregate () |
| 109 | { |
| 110 | if (m_node == 0) |
| 111 | { |
| 112 | Ptr<Node>node = this->GetObject<Node>(); |
| 113 | // verify that it's a valid node and that |
| 114 | // the node has not been set before |
| 115 | if (node != 0) |
| 116 | { |
| 117 | this->SetNode (node); |
| 118 | } |
| 119 | } |
| 120 | Object::NotifyNewAggregate (); |
| 121 | } |
| 122 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 123 | void |
| 124 | CcnxL3Protocol::DoDispose (void) |
| 125 | { |
| 126 | NS_LOG_FUNCTION (this); |
| 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_rit = 0; |
| 138 | m_pit = 0; |
| 139 | m_contentStore = 0; |
Alexander Afanasyev | 1825285 | 2011-11-21 13:35:31 -0800 | [diff] [blame^] | 140 | m_fib = 0; |
| 141 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 142 | // m_forwardingStrategy = 0; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 143 | Object::DoDispose (); |
| 144 | } |
| 145 | |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 146 | void |
| 147 | CcnxL3Protocol::SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy) |
| 148 | { |
| 149 | NS_LOG_FUNCTION (this); |
| 150 | m_forwardingStrategy = forwardingStrategy; |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 151 | // m_forwardingStrategy->SetCcnx (this); |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | Ptr<CcnxForwardingStrategy> |
| 155 | CcnxL3Protocol::GetForwardingStrategy (void) const |
| 156 | { |
| 157 | return m_forwardingStrategy; |
| 158 | } |
| 159 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 160 | uint32_t |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 161 | CcnxL3Protocol::AddFace (const Ptr<CcnxFace> &face) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 162 | { |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 163 | NS_LOG_FUNCTION (this << &face); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 164 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 165 | face->SetNode (m_node); |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 166 | 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] | 167 | |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 168 | // ask face to register in lower-layer stack |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 169 | face->RegisterProtocolHandler (MakeCallback (&CcnxL3Protocol::Receive, this)); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 170 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 171 | m_faces.push_back (face); |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 172 | m_faceCounter ++; |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 173 | return face->GetId (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 176 | void |
| 177 | CcnxL3Protocol::RemoveFace (Ptr<CcnxFace> face) |
| 178 | { |
| 179 | // ask face to register in lower-layer stack |
| 180 | face->RegisterProtocolHandler (MakeNullCallback<void,const Ptr<CcnxFace>&,const Ptr<const Packet>&> ()); |
| 181 | CcnxFaceList::iterator face_it = find (m_faces.begin(), m_faces.end(), face); |
| 182 | NS_ASSERT_MSG (face_it != m_faces.end (), "Attempt to remove face that doesn't exist"); |
| 183 | m_faces.erase (face_it); |
| 184 | } |
| 185 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 186 | Ptr<CcnxFace> |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 187 | CcnxL3Protocol::GetFace (uint32_t index) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 188 | { |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 189 | 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] | 190 | { |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 191 | if (face->GetId () == index) |
| 192 | return face; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 193 | } |
| 194 | return 0; |
| 195 | } |
| 196 | |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 197 | Ptr<CcnxFace> |
| 198 | CcnxL3Protocol::GetFaceByNetDevice (Ptr<NetDevice> netDevice) const |
| 199 | { |
| 200 | BOOST_FOREACH (const Ptr<CcnxFace> &face, m_faces) // this function is not supposed to be called often, so linear search is fine |
| 201 | { |
| 202 | Ptr<CcnxNetDeviceFace> netDeviceFace = DynamicCast<CcnxNetDeviceFace> (face); |
| 203 | if (netDeviceFace == 0) continue; |
| 204 | |
| 205 | if (netDeviceFace->GetNetDevice () == netDevice) |
| 206 | return face; |
| 207 | } |
| 208 | return 0; |
| 209 | } |
| 210 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 211 | uint32_t |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 212 | CcnxL3Protocol::GetNFaces (void) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 213 | { |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 214 | return m_faces.size (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 217 | void |
| 218 | CcnxL3Protocol::TransmittedDataTrace (Ptr<Packet> packet, |
| 219 | ContentObjectSource type, |
| 220 | Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face) |
| 221 | { |
| 222 | // a "small" inefficiency for logging purposes |
| 223 | Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> (); |
| 224 | static CcnxContentObjectTail tail; |
| 225 | packet->RemoveHeader (*header); |
| 226 | packet->RemoveTrailer (tail); |
| 227 | |
| 228 | m_transmittedDataTrace (header, packet/*payload*/, type, ccnx, face); |
| 229 | |
| 230 | packet->AddHeader (*header); |
| 231 | packet->AddTrailer (tail); |
| 232 | } |
| 233 | |
| 234 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 235 | // Callback from lower layer |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 236 | void |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 237 | CcnxL3Protocol::Receive (const Ptr<CcnxFace> &face, const Ptr<const Packet> &p) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 238 | { |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 239 | if (!face->IsUp ()) |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 240 | { |
| 241 | NS_LOG_LOGIC ("Dropping received packet -- interface is down"); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 242 | // m_dropTrace (p, INTERFACE_DOWN, m_node->GetObject<Ccnx> ()/*this*/, face); |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 243 | return; |
| 244 | } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 245 | 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] | 246 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 247 | 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] | 248 | try |
| 249 | { |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 250 | CcnxHeaderHelper::Type type = CcnxHeaderHelper::GetCcnxHeaderType (p); |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 251 | switch (type) |
| 252 | { |
| 253 | case CcnxHeaderHelper::INTEREST: |
| 254 | { |
| 255 | Ptr<CcnxInterestHeader> header = Create<CcnxInterestHeader> (); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 256 | |
| 257 | // Deserialization. Exception may be thrown |
| 258 | packet->RemoveHeader (*header); |
| 259 | NS_ASSERT_MSG (packet->GetSize () == 0, "Payload of Interests should be zero"); |
| 260 | |
| 261 | OnInterest (face, header, p/*original packet*/); |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 262 | break; |
| 263 | } |
| 264 | case CcnxHeaderHelper::CONTENT_OBJECT: |
| 265 | { |
| 266 | Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> (); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 267 | |
| 268 | static CcnxContentObjectTail contentObjectTrailer; //there is no data in this object |
| 269 | |
| 270 | // Deserialization. Exception may be thrown |
| 271 | packet->RemoveHeader (*header); |
| 272 | packet->RemoveTrailer (contentObjectTrailer); |
| 273 | |
| 274 | OnData (face, header, packet/*payload*/, p/*original packet*/); |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 275 | break; |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | // exception will be thrown if packet is not recognized |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 280 | } |
| 281 | catch (CcnxUnknownHeaderException) |
| 282 | { |
| 283 | NS_ASSERT_MSG (false, "Unknown CCNx header. Should not happen"); |
| 284 | } |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 285 | } |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 286 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 287 | // Processing Interests |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 288 | void CcnxL3Protocol::OnInterest (const Ptr<CcnxFace> &incomingFace, |
| 289 | Ptr<CcnxInterestHeader> &header, |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 290 | const Ptr<const Packet> &packet) |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 291 | { |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 292 | NS_LOG_LOGIC ("Receiving interest from " << &incomingFace); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 293 | m_receivedInterestsTrace (header, m_node->GetObject<Ccnx> (), incomingFace); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 294 | |
Ilya Moiseenko | d83eb0d | 2011-11-16 15:23:46 -0800 | [diff] [blame] | 295 | |
| 296 | if( header->IsNack () ) |
| 297 | { |
| 298 | NS_LOG_INFO("============"); |
| 299 | NS_LOG_INFO("NACK"); |
| 300 | NS_LOG_INFO("=========="); |
| 301 | /*if( header->IsCongested () == false ) |
| 302 | m_pit->LeakBucket(incomingFace,1); |
| 303 | |
| 304 | |
| 305 | m_droppedInterestsTrace (header, DROP_CONGESTION, |
| 306 | m_node->GetObject<Ccnx> (), incomingFace); |
| 307 | |
| 308 | m_pit->modify(pitEntry, CcnxPitEntry::DeleteOutgoing(incomingFace));*/ |
| 309 | } |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 314 | // Lookup of Pit and Fib entries for this Interest |
| 315 | CcnxFibEntryContainer::type::iterator fibEntry; |
| 316 | CcnxPitEntryContainer::type::iterator pitEntry = m_pit->Lookup (*header, fibEntry); |
| 317 | |
| 318 | // No matter is it duplicate or not, if it is a NACK message, remove all possible incoming |
| 319 | // entries for this interface (NACK means that neighbor gave up trying and there is no |
| 320 | // point of sending data in this direction) |
Ilya Moiseenko | b405d9b | 2011-10-28 16:23:11 -0700 | [diff] [blame] | 321 | NS_LOG_INFO("Before (header->IsNack()) && (pitEntry != m_pit->end ())"); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 322 | if ((header->IsNack()) && (pitEntry != m_pit->end ())) |
| 323 | { |
| 324 | //m_pit->erase (pitEntry); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 325 | NS_LOG_INFO("TRUE"); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 326 | m_pit->modify(pitEntry, CcnxPitEntry::DeleteIncoming(incomingFace)); |
| 327 | } |
| 328 | |
Ilya Moiseenko | b405d9b | 2011-10-28 16:23:11 -0700 | [diff] [blame] | 329 | NS_LOG_INFO("Before WasRecentlySatisfied"); |
Ilya Moiseenko | d83eb0d | 2011-11-16 15:23:46 -0800 | [diff] [blame] | 330 | /*if (m_rit->WasRecentlySatisfied (*header)) |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 331 | { |
| 332 | return; |
Ilya Moiseenko | d83eb0d | 2011-11-16 15:23:46 -0800 | [diff] [blame] | 333 | }*/ |
| 334 | if (m_rit->WasRecentlySatisfied (*header)) |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 335 | { |
Ilya Moiseenko | d83eb0d | 2011-11-16 15:23:46 -0800 | [diff] [blame] | 336 | NS_LOG_INFO("------------"); |
Ilya Moiseenko | b405d9b | 2011-10-28 16:23:11 -0700 | [diff] [blame] | 337 | NS_LOG_INFO("Entering WasRecentlySatisfied"); |
Ilya Moiseenko | d83eb0d | 2011-11-16 15:23:46 -0800 | [diff] [blame] | 338 | NS_LOG_INFO("------------"); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 339 | // duplicate interests (same nonce) from applications are just ignored |
| 340 | if (incomingFace->IsLocal() == true) |
| 341 | return; |
| 342 | |
| 343 | // Update metric status for the incoming interface in the corresponding FIB entry |
Ilya Moiseenko | d83eb0d | 2011-11-16 15:23:46 -0800 | [diff] [blame] | 344 | /*if (fibEntry != m_fib->end()) |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 345 | m_fib->modify (m_fib->iterator_to (pitEntry->m_fibEntry), |
| 346 | CcnxFibEntry::UpdateStatus(incomingFace, CcnxFibFaceMetric::NDN_FIB_YELLOW)); |
| 347 | |
| 348 | //Trace duplicate interest |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 349 | m_droppedInterestsTrace (header, NDN_DUPLICATE_INTEREST, |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 350 | m_node->GetObject<Ccnx> (), incomingFace); |
| 351 | |
| 352 | bool isMine = false; |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 353 | //TypeId tid = TypeId ("ns3::CcnxProducer"); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 354 | for(uint32_t i=0; i<m_node->GetNApplications();i++) |
| 355 | { |
| 356 | Ptr<Application> app = m_node->GetApplication(i); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 357 | NS_LOG_INFO("ApplicationName = " << app->GetTypeId().GetName()); |
| 358 | if(app->GetTypeId().GetName() == "ns3::CcnxProducer") |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 359 | { |
| 360 | if((DynamicCast<CcnxProducer>(app))->GetPrefix () == header->GetName ()) |
| 361 | { |
| 362 | isMine = true; |
| 363 | break; |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | Ptr<Packet> contentObject = m_contentStore->Lookup (header); |
| 369 | if ((isMine == true) || (contentObject != NULL)) |
| 370 | { |
| 371 | //never respond with NACK to NACK |
| 372 | if(header->IsNack () ) |
| 373 | return; |
| 374 | |
| 375 | // always return a duplicate packet |
| 376 | header->SetNack(true); |
| 377 | //Trace duplicate interest |
| 378 | m_droppedInterestsTrace (header, NDN_DUPLICATE_INTEREST, |
| 379 | m_node->GetObject<Ccnx> (), incomingFace); |
| 380 | |
| 381 | SendInterest(incomingFace, header, packet->Copy()); |
| 382 | |
| 383 | return; |
| 384 | } |
| 385 | |
| 386 | |
| 387 | // check PIT. or there is no outgoing entry for this interface, |
| 388 | // silently drop the duplicate packet |
| 389 | |
| 390 | // If no entry found, silently drop |
| 391 | if( pitEntry == m_pit->end() ) |
| 392 | return; |
| 393 | |
| 394 | // If PIT entry timed out, silently drop |
| 395 | if( pitEntry->m_timerExpired == true ) |
| 396 | return; |
| 397 | |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 398 | // loop? |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 399 | |
| 400 | // Check if there is no outgoing entry for the interface or different nonce |
| 401 | // (i.e., got a duplicate packet, but we haven't sent interest to this |
| 402 | // interface) |
| 403 | // |
| 404 | // This case means that there is a loop in the network. |
| 405 | // So, prune this link, but do not remove PIT entry |
| 406 | |
| 407 | // Alex, check this condition!! |
| 408 | if(pitEntry->m_outgoing.size () == 0) |
| 409 | { |
| 410 | //never respond with NACK to NACK |
| 411 | if(header->IsNack () ) |
| 412 | return; |
| 413 | |
| 414 | // always return a duplicate packet |
| 415 | header->SetNack(true); |
| 416 | //Trace duplicate interest |
| 417 | m_droppedInterestsTrace (header, NDN_DUPLICATE_INTEREST, |
| 418 | m_node->GetObject<Ccnx> (), incomingFace); |
| 419 | |
| 420 | SendInterest(incomingFace, header, packet->Copy()); |
| 421 | return; |
| 422 | } |
| 423 | |
| 424 | |
| 425 | // At this point: |
| 426 | // - there is a non-expired PIT entry, |
| 427 | // - there is an outgoing interest to the interface, and |
| 428 | // - a nonce in outgoing entry is equal to a nonce in the received duplicate packet |
| 429 | |
| 430 | // Should perform: |
| 431 | // Cleaning outgoing entry |
| 432 | // If there are no outgoing interests and available interfaces left (pe->availableInterfaces), |
| 433 | // prune all incoming interests, otherwise allow forwarding of the interest |
| 434 | if( header->IsNack () ) |
| 435 | { |
| 436 | if( header->IsCongested () == false ) |
| 437 | m_pit->LeakBucket(incomingFace,1); |
| 438 | |
| 439 | m_pit->modify(pitEntry, CcnxPitEntry::DeleteOutgoing(incomingFace)); |
| 440 | } |
| 441 | else |
| 442 | { |
| 443 | //poit->waitingInVain = true; |
| 444 | } |
| 445 | |
| 446 | |
| 447 | // prune all incoming interests |
| 448 | if((pitEntry->m_outgoing.size() ==0) && (pitEntry->m_fibEntry.m_faces.size() == 0)) |
| 449 | { |
| 450 | BOOST_FOREACH (const CcnxPitEntryIncomingFace face, pitEntry->m_incoming) |
| 451 | { |
| 452 | if(face.m_face->IsLocal() == false) |
| 453 | { |
| 454 | // check all entries if the name of RIT entry matches the name of interest |
| 455 | for (CcnxRitByNonce::type::iterator it = m_rit->begin(); it != m_rit->end(); it++) |
| 456 | { |
| 457 | if (it->m_prefix == pitEntry->GetPrefix() ) |
| 458 | { |
| 459 | |
| 460 | header->SetNonce(it->m_nonce); |
| 461 | header->SetNack(true); |
| 462 | SendInterest(face.m_face, header, packet->Copy()); |
| 463 | break; |
| 464 | } |
| 465 | } |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | // Finally, remote the PIT entry |
| 470 | m_pit->erase (pitEntry); |
| 471 | |
| 472 | return; // stop processing |
| 473 | } |
| 474 | |
| 475 | if(pitEntry->m_fibEntry.m_faces.size() == 0) |
Ilya Moiseenko | d83eb0d | 2011-11-16 15:23:46 -0800 | [diff] [blame] | 476 | return;*/ |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 477 | return; |
Ilya Moiseenko | d83eb0d | 2011-11-16 15:23:46 -0800 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 481 | |
| 482 | // Otherwise, |
| 483 | // propagate the interest |
| 484 | // |
| 485 | // method `propagateInterest' can/should try different interface |
| 486 | // from `availableInterfaces' list |
| 487 | |
Ilya Moiseenko | b405d9b | 2011-10-28 16:23:11 -0700 | [diff] [blame] | 488 | NS_LOG_INFO("Before SetRecentlySatisfied"); |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 489 | m_rit->SetRecentlySatisfied (*header); |
| 490 | |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 491 | NS_LOG_INFO("Cache Lookup for " << header->GetName()); |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 492 | Ptr<Packet> contentObject = m_contentStore->Lookup (header); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 493 | if (contentObject != NULL) |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 494 | { |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 495 | NS_LOG_INFO("Found in cache"); |
| 496 | |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 497 | TransmittedDataTrace (contentObject, CACHED, |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 498 | m_node->GetObject<Ccnx> (), incomingFace); |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 499 | incomingFace->Send (contentObject); |
| 500 | return; |
| 501 | } |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 502 | |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 503 | // Data is not in cache |
Ilya Moiseenko | b405d9b | 2011-10-28 16:23:11 -0700 | [diff] [blame] | 504 | NS_LOG_INFO("Before inFace and OutFace"); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 505 | CcnxPitEntryIncomingFaceContainer::type::iterator inFace = pitEntry->m_incoming.find (incomingFace); |
| 506 | CcnxPitEntryOutgoingFaceContainer::type::iterator outFace = pitEntry->m_outgoing.find (incomingFace); |
| 507 | |
Alexander Afanasyev | d02a5d6 | 2011-11-21 11:01:51 -0800 | [diff] [blame] | 508 | NS_LOG_INFO("Before (pitEntry != m_pit->end()) && (pitEntry->m_timerExpired == false)"); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 509 | if ((pitEntry != m_pit->end()) && (pitEntry->m_timerExpired == false)) |
| 510 | { |
Ilya Moiseenko | b405d9b | 2011-10-28 16:23:11 -0700 | [diff] [blame] | 511 | NS_LOG_INFO("Entering (pitEntry != m_pit->end()) && (pitEntry->m_timerExpired == false)"); |
| 512 | |
Alexander Afanasyev | d02a5d6 | 2011-11-21 11:01:51 -0800 | [diff] [blame] | 513 | if(inFace->m_face == 0) |
Ilya Moiseenko | b405d9b | 2011-10-28 16:23:11 -0700 | [diff] [blame] | 514 | NS_LOG_INFO("in face is null"); |
Alexander Afanasyev | d02a5d6 | 2011-11-21 11:01:51 -0800 | [diff] [blame] | 515 | if(outFace->m_face == 0) |
Ilya Moiseenko | b405d9b | 2011-10-28 16:23:11 -0700 | [diff] [blame] | 516 | NS_LOG_INFO("outface is null"); |
Ilya Moiseenko | d83eb0d | 2011-11-16 15:23:46 -0800 | [diff] [blame] | 517 | if(outFace == pitEntry->m_outgoing.end()) |
| 518 | NS_LOG_INFO("OUTFACE = END"); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 519 | |
| 520 | // If we're expecting data from the interface we got the interest from ("producer" asks us for "his own" data) |
| 521 | // Give up this interface, but keep a small hope when the returned packet doesn't have PRUNE status |
Ilya Moiseenko | d83eb0d | 2011-11-16 15:23:46 -0800 | [diff] [blame] | 522 | if(outFace != pitEntry->m_outgoing.end()) // this is correct |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 523 | { |
Ilya Moiseenko | b405d9b | 2011-10-28 16:23:11 -0700 | [diff] [blame] | 524 | NS_LOG_INFO("Entering outFace != pitEntry->m_outgoing.end()"); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 525 | if( header->IsCongested() == true ) |
| 526 | { |
Ilya Moiseenko | b405d9b | 2011-10-28 16:23:11 -0700 | [diff] [blame] | 527 | NS_LOG_INFO("Entering header->IsCongested() == true"); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 528 | m_pit->LeakBucket(incomingFace, 1); |
| 529 | m_pit->modify (pitEntry, CcnxPitEntry::DeleteOutgoing(outFace->m_face)); |
| 530 | } |
| 531 | //else |
| 532 | // poit->waitingInVain = true; |
| 533 | |
| 534 | // Update metric status for the incoming interface in the corresponding FIB entry |
| 535 | if(fibEntry != m_fib->end()) |
| 536 | m_fib->modify(m_fib->iterator_to (pitEntry->m_fibEntry), |
| 537 | CcnxFibEntry::UpdateStatus(incomingFace, CcnxFibFaceMetric::NDN_FIB_YELLOW)); |
| 538 | } |
| 539 | } |
| 540 | |
Ilya Moiseenko | b405d9b | 2011-10-28 16:23:11 -0700 | [diff] [blame] | 541 | NS_LOG_INFO("Before (pitEntry->m_outgoing.size() == 0) && (pitEntry->m_fibEntry.m_faces.size() == 0)"); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 542 | if((pitEntry->m_outgoing.size() == 0) && (pitEntry->m_fibEntry.m_faces.size() == 0)) |
| 543 | // prune all incoming interests |
| 544 | { |
| 545 | |
| 546 | for(CcnxPitEntryContainer::type::iterator iter = m_pit->begin(); |
| 547 | iter != m_pit->end(); |
| 548 | iter++) |
| 549 | { |
| 550 | /*for(CcnxPitEntryIncomingFaceContainer::type::iterator face = iter->m_incoming.begin(); |
| 551 | face != iter->m_incoming.end(); |
| 552 | face++)*/ |
| 553 | BOOST_FOREACH (const CcnxPitEntryIncomingFace face, iter->m_incoming) |
| 554 | { |
| 555 | if(face.m_face->IsLocal() == true) |
| 556 | { |
| 557 | //returnInterestToApp( pkt, -piit->interfaceIndex ); |
| 558 | //continue; |
| 559 | } |
| 560 | |
| 561 | // check all entries if the name of RIT entry matches the name of interest |
| 562 | for (CcnxRitByNonce::type::iterator it = m_rit->begin(); it != m_rit->end(); it++) |
| 563 | { |
| 564 | if (it->m_prefix == iter->GetPrefix() ) |
| 565 | { |
| 566 | header->SetNonce(it->m_nonce); |
| 567 | header->SetNack(true); |
| 568 | SendInterest(face.m_face, header, packet->Copy()); |
| 569 | } |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | } |
| 574 | |
| 575 | m_pit->erase(pitEntry); |
| 576 | |
| 577 | return; // there is nothing else to do |
| 578 | } |
| 579 | |
| 580 | // Suppress this interest only if we're still expecting data from some other interface |
| 581 | if( pitEntry->m_outgoing.size() > 0 ) |
| 582 | { |
| 583 | return; //ok. Now we can suppress this interest |
| 584 | } |
| 585 | |
| 586 | |
| 587 | // Prune and delete PIT entry if there are no available interfaces to propagate interest |
| 588 | if( pitEntry->m_fibEntry.m_faces.size() == 0) |
| 589 | { |
| 590 | //if no match is found in the FIB, drop packet |
| 591 | //printf( "Node %d: cannot process Interest packet %s (no interfaces left)\n", _node->nodeId, pkt->contentName ); |
| 592 | |
| 593 | if(incomingFace->IsLocal() == false) |
| 594 | { |
| 595 | header->SetNack(true); |
| 596 | m_droppedInterestsTrace (header, NDN_SUPPRESSED_INTEREST, |
| 597 | m_node->GetObject<Ccnx> (), incomingFace); |
| 598 | SendInterest(incomingFace, header, packet->Copy()); |
| 599 | } |
| 600 | |
| 601 | m_pit->erase(pitEntry); |
| 602 | |
| 603 | } |
| 604 | |
| 605 | |
| 606 | |
| 607 | // otherwise, try one of the available interfaces |
| 608 | |
| 609 | // suppress interest if |
| 610 | /*if (pitEntry->m_incoming.size () != 0 && // not a new PIT entry and |
| 611 | inFace != pitEntry->m_incoming.end ()) // existing entry, but interest received via different face |
| 612 | { |
| 613 | m_droppedInterestsTrace (header, NDN_SUPPRESSED_INTEREST, |
| 614 | m_node->GetObject<Ccnx> (), incomingFace); |
| 615 | return; |
| 616 | }*/ |
| 617 | |
| 618 | |
| 619 | //just in case of bug |
| 620 | header->SetNack(false); |
| 621 | header->SetCongested(false); |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 622 | |
Ilya Moiseenko | 00b3048 | 2011-11-15 17:58:00 -0800 | [diff] [blame] | 623 | NS_ASSERT_MSG (m_forwardingStrategy != 0, "Need a forwarding protocol object to process packets"); |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 624 | |
Ilya Moiseenko | 00b3048 | 2011-11-15 17:58:00 -0800 | [diff] [blame] | 625 | m_pit->modify (pitEntry, CcnxPitEntry::AddIncoming(incomingFace)); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 626 | |
Ilya Moiseenko | 00b3048 | 2011-11-15 17:58:00 -0800 | [diff] [blame] | 627 | bool propagated = m_forwardingStrategy-> |
| 628 | PropagateInterest (pitEntry, fibEntry,incomingFace, header, packet, |
| 629 | MakeCallback (&CcnxL3Protocol::SendInterest, this) |
| 630 | ); |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 631 | |
Ilya Moiseenko | 00b3048 | 2011-11-15 17:58:00 -0800 | [diff] [blame] | 632 | // If interest wasn't propagated further (probably, a limit is reached), |
| 633 | // prune and delete PIT entry if there are no outstanding interests. |
| 634 | // Stop processing otherwise. |
Ilya Moiseenko | d83eb0d | 2011-11-16 15:23:46 -0800 | [diff] [blame] | 635 | if( (!propagated) && (pitEntry->m_outgoing.size() == 0)) // this line works |
Ilya Moiseenko | 00b3048 | 2011-11-15 17:58:00 -0800 | [diff] [blame] | 636 | { |
| 637 | BOOST_FOREACH (const CcnxPitEntryIncomingFace face, pitEntry->m_incoming) |
| 638 | { |
| 639 | header->SetNack(true); |
| 640 | header->SetCongested(true); |
Ilya Moiseenko | d83eb0d | 2011-11-16 15:23:46 -0800 | [diff] [blame] | 641 | NS_LOG_INFO("Sending CONGESTION packet"); |
Ilya Moiseenko | 00b3048 | 2011-11-15 17:58:00 -0800 | [diff] [blame] | 642 | SendInterest (face.m_face, header, packet->Copy()); |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 643 | |
Ilya Moiseenko | 00b3048 | 2011-11-15 17:58:00 -0800 | [diff] [blame] | 644 | m_droppedInterestsTrace (header, DROP_CONGESTION, |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 645 | m_node->GetObject<Ccnx> (), incomingFace); |
Ilya Moiseenko | 00b3048 | 2011-11-15 17:58:00 -0800 | [diff] [blame] | 646 | } |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 647 | |
| 648 | m_pit->erase (pitEntry); |
Ilya Moiseenko | 00b3048 | 2011-11-15 17:58:00 -0800 | [diff] [blame] | 649 | } |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 650 | /*} |
| 651 | else |
| 652 | { |
| 653 | m_droppedInterestsTrace (header, NDN_PIT_TIMER_EXPIRED, |
| 654 | m_node->GetObject<Ccnx> (), incomingFace); |
| 655 | return; |
| 656 | }*/ |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | // Processing ContentObjects |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 660 | void CcnxL3Protocol::OnData (const Ptr<CcnxFace> &incomingFace, |
| 661 | Ptr<CcnxContentObjectHeader> &header, |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 662 | Ptr<Packet> &payload, |
| 663 | const Ptr<const Packet> &packet) |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 664 | { |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 665 | |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 666 | NS_LOG_LOGIC ("Receiving contentObject from " << &incomingFace); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 667 | m_receivedDataTrace (header, payload, m_node->GetObject<Ccnx> ()/*this*/, incomingFace); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 668 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 669 | // 1. Lookup PIT entry |
| 670 | try |
| 671 | { |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 672 | const CcnxPitEntry &pitEntry = m_pit->Lookup (*header); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 673 | |
| 674 | // Note that with MultiIndex we need to modify entries indirectly |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 675 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 676 | // Update metric status for the incoming interface in the corresponding FIB entry |
| 677 | m_fib->modify (m_fib->iterator_to (pitEntry.m_fibEntry), |
| 678 | CcnxFibEntry::UpdateStatus (incomingFace, CcnxFibFaceMetric::NDN_FIB_GREEN)); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 679 | |
| 680 | // Add or update entry in the content store |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 681 | NS_LOG_INFO("Cached " << header->GetName()); |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 682 | m_contentStore->Add (header, payload); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 683 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 684 | CcnxPitEntryOutgoingFaceContainer::type::iterator |
| 685 | out = pitEntry.m_outgoing.find (incomingFace); |
| 686 | |
| 687 | // If we have sent interest for this data via this face, then update stats. |
| 688 | if (out != pitEntry.m_outgoing.end ()) |
| 689 | { |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 690 | m_pit->modify (m_pit->iterator_to (pitEntry), |
| 691 | CcnxPitEntry::EstimateRttAndRemoveFace(out, m_fib)); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 692 | // face will be removed in the above call |
| 693 | } |
| 694 | else |
| 695 | { |
| 696 | NS_LOG_WARN ("Node "<< m_node->GetId() << |
| 697 | ". PIT entry for "<< header->GetName ()<<" is valid, " |
| 698 | "but outgoing entry for interface "<< incomingFace <<" doesn't exist\n"); |
| 699 | } |
| 700 | |
| 701 | //satisfy all pending incoming Interests |
| 702 | BOOST_FOREACH (const CcnxPitEntryIncomingFace &interest, pitEntry.m_incoming) |
| 703 | { |
| 704 | if (interest.m_face == incomingFace) continue; |
| 705 | |
| 706 | // may not work either because of 'const' thing |
| 707 | interest.m_face->Send (packet->Copy ()); // unfortunately, we have to copy packet... |
| 708 | m_transmittedDataTrace (header, payload, FORWARDED, m_node->GetObject<Ccnx> (), interest.m_face); |
| 709 | } |
| 710 | |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 711 | m_pit->modify (m_pit->iterator_to (pitEntry), CcnxPitEntry::ClearIncoming()); // satisfy all incoming interests |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 712 | |
| 713 | if( pitEntry.m_outgoing.size()==0 ) // remove PIT when all outgoing interests are "satisfied" |
| 714 | { |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 715 | m_pit->erase (m_pit->iterator_to (pitEntry)); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | } |
| 719 | catch (CcnxPitEntryNotFound) |
| 720 | { |
| 721 | // 2. Drop data packet if PIT entry is not found |
| 722 | // (unsolicited data packets should not "poison" content store) |
| 723 | |
| 724 | //drop dulicated or not requested data packet |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 725 | m_droppedDataTrace (header, payload, NDN_UNSOLICITED_DATA, m_node->GetObject<Ccnx> (), incomingFace); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 726 | return; // do not process unsoliced data packets |
| 727 | } |
| 728 | } |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 729 | |
| 730 | void |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 731 | CcnxL3Protocol::SendInterest (const Ptr<CcnxFace> &face, |
| 732 | const Ptr<CcnxInterestHeader> &header, |
| 733 | const Ptr<Packet> &packet) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 734 | { |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 735 | NS_LOG_FUNCTION (this << "packet: " << &packet << ", face: "<< &face); |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 736 | NS_ASSERT_MSG (face != 0, "Face should never be NULL"); |
| 737 | |
| 738 | if (face->IsUp ()) |
| 739 | { |
| 740 | NS_LOG_LOGIC ("Sending via face " << &face); // |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 741 | m_transmittedInterestsTrace (header, m_node->GetObject<Ccnx> (), face); |
| 742 | face->Send (packet); |
| 743 | } |
| 744 | else |
| 745 | { |
| 746 | NS_LOG_LOGIC ("Dropping -- outgoing interface is down: " << &face); |
| 747 | m_droppedInterestsTrace (header, INTERFACE_DOWN, m_node->GetObject<Ccnx> (), face); |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | void |
| 752 | CcnxL3Protocol::SendContentObject (const Ptr<CcnxFace> &face, |
| 753 | const Ptr<CcnxContentObjectHeader> &header, |
| 754 | const Ptr<Packet> &packet) |
| 755 | { |
| 756 | NS_LOG_FUNCTION (this << "packet: " << &packet << ", face: "<< &face); |
| 757 | NS_ASSERT_MSG (face != 0, "Face should never be NULL"); |
| 758 | |
| 759 | NS_ASSERT_MSG (false, "Should not be called for now"); |
| 760 | |
| 761 | if (face->IsUp ()) |
| 762 | { |
| 763 | NS_LOG_LOGIC ("Sending via face " << &face); // |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 764 | // m_txTrace (packet, m_node->GetObject<Ccnx> (), face); |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 765 | face->Send (packet); |
| 766 | } |
| 767 | else |
| 768 | { |
| 769 | NS_LOG_LOGIC ("Dropping -- outgoing interface is down: " << &face); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 770 | // m_dropTrace (packet, INTERFACE_DOWN, m_node->GetObject<Ccnx> (), face); |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 771 | } |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 772 | } |
| 773 | |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 774 | Ptr<CcnxPit> |
| 775 | CcnxL3Protocol::GetPit() |
| 776 | { |
| 777 | return m_pit; |
| 778 | } |
Ilya Moiseenko | d83eb0d | 2011-11-16 15:23:46 -0800 | [diff] [blame] | 779 | |
| 780 | void |
| 781 | CcnxL3Protocol::ScheduleLeakage() |
| 782 | { |
| 783 | m_pit->LeakBuckets(); |
| 784 | Time interval = MilliSeconds (NDN_INTEREST_RESET_PERIOD); |
| 785 | Simulator::Schedule (interval, &CcnxL3Protocol::ScheduleLeakage, this); |
| 786 | } |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 787 | } //namespace ns3 |