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> |
| 19 | */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 20 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 21 | #include "ccnx-l3-protocol.h" |
| 22 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 23 | #include "ns3/packet.h" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 24 | #include "ns3/node.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 25 | #include "ns3/log.h" |
| 26 | #include "ns3/callback.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 27 | #include "ns3/uinteger.h" |
| 28 | #include "ns3/trace-source-accessor.h" |
| 29 | #include "ns3/object-vector.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 30 | #include "ns3/boolean.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 31 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 32 | #include "ns3/ccnx-header-helper.h" |
| 33 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 34 | #include "ccnx-face.h" |
| 35 | #include "ccnx-route.h" |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 36 | #include "ccnx-forwarding-strategy.h" |
| 37 | #include "ccnx-interest-header.h" |
| 38 | #include "ccnx-content-object-header.h" |
| 39 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 40 | #include <boost/foreach.hpp> |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 41 | |
| 42 | NS_LOG_COMPONENT_DEFINE ("CcnxL3Protocol"); |
| 43 | |
| 44 | namespace ns3 { |
| 45 | |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 46 | const uint16_t CcnxL3Protocol::ETHERNET_FRAME_TYPE = 0x7777; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 47 | |
| 48 | NS_OBJECT_ENSURE_REGISTERED (CcnxL3Protocol); |
| 49 | |
| 50 | TypeId |
| 51 | CcnxL3Protocol::GetTypeId (void) |
| 52 | { |
| 53 | static TypeId tid = TypeId ("ns3::CcnxL3Protocol") |
| 54 | .SetParent<Ccnx> () |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 55 | .SetGroupName ("Ccnx") |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 56 | .AddConstructor<CcnxL3Protocol> () |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 57 | // .AddTraceSource ("Tx", "Send ccnx packet to outgoing interface.", |
| 58 | // MakeTraceSourceAccessor (&CcnxL3Protocol::m_txTrace)) |
| 59 | // .AddTraceSource ("Rx", "Receive ccnx packet from incoming interface.", |
| 60 | // MakeTraceSourceAccessor (&CcnxL3Protocol::m_rxTrace)) |
| 61 | // .AddTraceSource ("Drop", "Drop ccnx packet", |
| 62 | // MakeTraceSourceAccessor (&CcnxL3Protocol::m_dropTrace)) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 63 | .AddAttribute ("InterfaceList", "The set of Ccnx interfaces associated to this Ccnx stack.", |
| 64 | ObjectVectorValue (), |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 65 | MakeObjectVectorAccessor (&CcnxL3Protocol::m_faces), |
| 66 | MakeObjectVectorChecker<CcnxFace> ()) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 67 | |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 68 | // .AddTraceSource ("SendOutgoing", "A newly-generated packet by this node is about to be queued for transmission", |
| 69 | // MakeTraceSourceAccessor (&CcnxL3Protocol::m_sendOutgoingTrace)) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 70 | |
| 71 | ; |
| 72 | return tid; |
| 73 | } |
| 74 | |
| 75 | CcnxL3Protocol::CcnxL3Protocol() |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 76 | : m_faceCounter (0) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 77 | { |
| 78 | NS_LOG_FUNCTION (this); |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame^] | 79 | |
| 80 | m_rit = CreateObject<CcnxRit> (); |
| 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 | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /* |
| 97 | * This method is called by AddAgregate and completes the aggregation |
| 98 | * by setting the node in the ccnx stack |
| 99 | */ |
| 100 | void |
| 101 | CcnxL3Protocol::NotifyNewAggregate () |
| 102 | { |
| 103 | if (m_node == 0) |
| 104 | { |
| 105 | Ptr<Node>node = this->GetObject<Node>(); |
| 106 | // verify that it's a valid node and that |
| 107 | // the node has not been set before |
| 108 | if (node != 0) |
| 109 | { |
| 110 | this->SetNode (node); |
| 111 | } |
| 112 | } |
| 113 | Object::NotifyNewAggregate (); |
| 114 | } |
| 115 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 116 | void |
| 117 | CcnxL3Protocol::DoDispose (void) |
| 118 | { |
| 119 | NS_LOG_FUNCTION (this); |
| 120 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 121 | for (CcnxFaceList::iterator i = m_faces.begin (); i != m_faces.end (); ++i) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 122 | { |
| 123 | *i = 0; |
| 124 | } |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 125 | m_faces.clear (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 126 | m_node = 0; |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 127 | // m_forwardingStrategy = 0; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 128 | Object::DoDispose (); |
| 129 | } |
| 130 | |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 131 | void |
| 132 | CcnxL3Protocol::SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy) |
| 133 | { |
| 134 | NS_LOG_FUNCTION (this); |
| 135 | m_forwardingStrategy = forwardingStrategy; |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame^] | 136 | // m_forwardingStrategy->SetCcnx (this); |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | Ptr<CcnxForwardingStrategy> |
| 140 | CcnxL3Protocol::GetForwardingStrategy (void) const |
| 141 | { |
| 142 | return m_forwardingStrategy; |
| 143 | } |
| 144 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 145 | uint32_t |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 146 | CcnxL3Protocol::AddFace (const Ptr<CcnxFace> &face) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 147 | { |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 148 | NS_LOG_FUNCTION (this << &face); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 149 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 150 | face->SetNode (m_node); |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 151 | 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] | 152 | |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 153 | // ask face to register in lower-layer stack |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 154 | face->RegisterProtocolHandler (MakeCallback (&CcnxL3Protocol::Receive, this)); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 155 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 156 | m_faces.push_back (face); |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 157 | m_faceCounter ++; |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 158 | return face->GetId (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 161 | Ptr<CcnxFace> |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 162 | CcnxL3Protocol::GetFace (uint32_t index) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 163 | { |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 164 | 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] | 165 | { |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 166 | if (face->GetId () == index) |
| 167 | return face; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 168 | } |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | uint32_t |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 173 | CcnxL3Protocol::GetNFaces (void) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 174 | { |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 175 | return m_faces.size (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame^] | 178 | void |
| 179 | CcnxL3Protocol::TransmittedDataTrace (Ptr<Packet> packet, |
| 180 | ContentObjectSource type, |
| 181 | Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face) |
| 182 | { |
| 183 | // a "small" inefficiency for logging purposes |
| 184 | Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> (); |
| 185 | static CcnxContentObjectTail tail; |
| 186 | packet->RemoveHeader (*header); |
| 187 | packet->RemoveTrailer (tail); |
| 188 | |
| 189 | m_transmittedDataTrace (header, packet/*payload*/, type, ccnx, face); |
| 190 | |
| 191 | packet->AddHeader (*header); |
| 192 | packet->AddTrailer (tail); |
| 193 | } |
| 194 | |
| 195 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 196 | // Callback from lower layer |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 197 | void |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 198 | CcnxL3Protocol::Receive (const Ptr<CcnxFace> &face, const Ptr<const Packet> &p) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 199 | { |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 200 | if (face->IsUp ()) |
| 201 | { |
| 202 | NS_LOG_LOGIC ("Dropping received packet -- interface is down"); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 203 | // m_dropTrace (p, INTERFACE_DOWN, m_node->GetObject<Ccnx> ()/*this*/, face); |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 204 | return; |
| 205 | } |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 206 | 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] | 207 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 208 | 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] | 209 | try |
| 210 | { |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 211 | CcnxHeaderHelper::Type type = CcnxHeaderHelper::CreateCorrectCcnxHeader (p); |
| 212 | switch (type) |
| 213 | { |
| 214 | case CcnxHeaderHelper::INTEREST: |
| 215 | { |
| 216 | Ptr<CcnxInterestHeader> header = Create<CcnxInterestHeader> (); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 217 | |
| 218 | // Deserialization. Exception may be thrown |
| 219 | packet->RemoveHeader (*header); |
| 220 | NS_ASSERT_MSG (packet->GetSize () == 0, "Payload of Interests should be zero"); |
| 221 | |
| 222 | OnInterest (face, header, p/*original packet*/); |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 223 | break; |
| 224 | } |
| 225 | case CcnxHeaderHelper::CONTENT_OBJECT: |
| 226 | { |
| 227 | Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> (); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 228 | |
| 229 | static CcnxContentObjectTail contentObjectTrailer; //there is no data in this object |
| 230 | |
| 231 | // Deserialization. Exception may be thrown |
| 232 | packet->RemoveHeader (*header); |
| 233 | packet->RemoveTrailer (contentObjectTrailer); |
| 234 | |
| 235 | OnData (face, header, packet/*payload*/, p/*original packet*/); |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 236 | break; |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | // exception will be thrown if packet is not recognized |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 241 | } |
| 242 | catch (CcnxUnknownHeaderException) |
| 243 | { |
| 244 | NS_ASSERT_MSG (false, "Unknown CCNx header. Should not happen"); |
| 245 | } |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 246 | } |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 247 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 248 | // Processing Interests |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 249 | void CcnxL3Protocol::OnInterest (const Ptr<CcnxFace> &incomingFace, |
| 250 | Ptr<CcnxInterestHeader> &header, |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 251 | const Ptr<const Packet> &packet) |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 252 | { |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 253 | NS_LOG_LOGIC ("Receiving interest from " << &incomingFace); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 254 | m_receivedInterestsTrace (header, m_node->GetObject<Ccnx> ()/*this*/, incomingFace); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 255 | |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame^] | 256 | if (m_rit->WasRecentlySatisfied (*header)) |
| 257 | { |
| 258 | m_droppedInterestsTrace (header, NDN_DUPLICATE_INTEREST, |
| 259 | m_node->GetObject<Ccnx> ()/*this*/, incomingFace); |
| 260 | // loop? |
| 261 | return; |
| 262 | } |
| 263 | m_rit->SetRecentlySatisfied (*header); |
| 264 | |
| 265 | Ptr<Packet> contentObject = m_contentStore->Lookup (header); |
| 266 | if (contentObject != 0) |
| 267 | { |
| 268 | TransmittedDataTrace (contentObject, CACHED, |
| 269 | m_node->GetObject<Ccnx> ()/*this*/, incomingFace); |
| 270 | incomingFace->Send (contentObject); |
| 271 | return; |
| 272 | } |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 273 | |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame^] | 274 | CcnxPitEntry pitEntry = m_pit->Lookup (*header); |
| 275 | |
| 276 | CcnxPitEntryIncomingFaceContainer::type::iterator inFace = pitEntry.m_incoming.find (incomingFace); |
| 277 | CcnxPitEntryOutgoingFaceContainer::type::iterator outFace = pitEntry.m_outgoing.find (incomingFace); |
| 278 | |
| 279 | // suppress interest if |
| 280 | if (pitEntry.m_incoming.size () == 0 || // new PIT entry |
| 281 | inFace ==pitEntry.m_incoming.end ()) // existing entry, but interest received via different face |
| 282 | { |
| 283 | m_droppedInterestsTrace (header, NDN_SUPPRESSED_INTEREST, |
| 284 | m_node->GetObject<Ccnx> ()/*this*/, incomingFace); |
| 285 | return; |
| 286 | } |
| 287 | |
| 288 | NS_ASSERT_MSG (m_forwardingStrategy != 0, "Need a forwarding protocol object to process packets"); |
| 289 | |
| 290 | /*bool propagated = */m_forwardingStrategy-> |
| 291 | PropagateInterest (incomingFace, header, packet, |
| 292 | MakeCallback (&CcnxL3Protocol::SendInterest, this) |
| 293 | ); |
| 294 | |
| 295 | // // If interest wasn't propagated further (probably, a limit is reached), |
| 296 | // // prune and delete PIT entry if there are no outstanding interests. |
| 297 | // // Stop processing otherwise. |
| 298 | // if( !propagated && pitEntry.numberOfPromisingInterests()==0 ) |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 299 | // { |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame^] | 300 | // // printf( "Node %d. Pruning after unsuccessful try to forward an interest\n", _node->nodeId ); |
| 301 | |
| 302 | // BOOST_FOREACH (const CcnxPitEntryIncomingFace face, pitEntry.m_incoming) |
| 303 | // { |
| 304 | // // send prune |
| 305 | // } |
| 306 | // m_pit->erase (m_pit->iterator_to (pitEntry)); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 307 | // } |
| 308 | } |
| 309 | |
| 310 | // Processing ContentObjects |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 311 | void CcnxL3Protocol::OnData (const Ptr<CcnxFace> &incomingFace, |
| 312 | Ptr<CcnxContentObjectHeader> &header, |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 313 | Ptr<Packet> &payload, |
| 314 | const Ptr<const Packet> &packet) |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 315 | { |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 316 | |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 317 | NS_LOG_LOGIC ("Receiving contentObject from " << &incomingFace); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 318 | m_receivedDataTrace (header, payload, m_node->GetObject<Ccnx> ()/*this*/, incomingFace); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 319 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 320 | // 1. Lookup PIT entry |
| 321 | try |
| 322 | { |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame^] | 323 | const CcnxPitEntry &pitEntry = m_pit->Lookup (*header); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 324 | |
| 325 | // Note that with MultiIndex we need to modify entries indirectly |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 326 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 327 | // Update metric status for the incoming interface in the corresponding FIB entry |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame^] | 328 | m_pit->modify (m_pit->iterator_to (pitEntry), |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 329 | CcnxPitEntry::UpdateFibStatus (incomingFace, CcnxFibFaceMetric::NDN_FIB_GREEN)); |
| 330 | |
| 331 | // Add or update entry in the content store |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame^] | 332 | m_contentStore->Add (header, payload); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 333 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 334 | CcnxPitEntryOutgoingFaceContainer::type::iterator |
| 335 | out = pitEntry.m_outgoing.find (incomingFace); |
| 336 | |
| 337 | // If we have sent interest for this data via this face, then update stats. |
| 338 | if (out != pitEntry.m_outgoing.end ()) |
| 339 | { |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame^] | 340 | m_pit->modify (m_pit->iterator_to (pitEntry), CcnxPitEntry::EstimateRttAndRemoveFace(out)); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 341 | // face will be removed in the above call |
| 342 | } |
| 343 | else |
| 344 | { |
| 345 | NS_LOG_WARN ("Node "<< m_node->GetId() << |
| 346 | ". PIT entry for "<< header->GetName ()<<" is valid, " |
| 347 | "but outgoing entry for interface "<< incomingFace <<" doesn't exist\n"); |
| 348 | } |
| 349 | |
| 350 | //satisfy all pending incoming Interests |
| 351 | BOOST_FOREACH (const CcnxPitEntryIncomingFace &interest, pitEntry.m_incoming) |
| 352 | { |
| 353 | if (interest.m_face == incomingFace) continue; |
| 354 | |
| 355 | // may not work either because of 'const' thing |
| 356 | interest.m_face->Send (packet->Copy ()); // unfortunately, we have to copy packet... |
| 357 | m_transmittedDataTrace (header, payload, FORWARDED, m_node->GetObject<Ccnx> (), interest.m_face); |
| 358 | } |
| 359 | |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame^] | 360 | 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] | 361 | |
| 362 | if( pitEntry.m_outgoing.size()==0 ) // remove PIT when all outgoing interests are "satisfied" |
| 363 | { |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame^] | 364 | m_pit->erase (m_pit->iterator_to (pitEntry)); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | } |
| 368 | catch (CcnxPitEntryNotFound) |
| 369 | { |
| 370 | // 2. Drop data packet if PIT entry is not found |
| 371 | // (unsolicited data packets should not "poison" content store) |
| 372 | |
| 373 | //drop dulicated or not requested data packet |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame^] | 374 | m_droppedDataTrace (header, payload, NDN_UNSOLICITED_DATA, m_node->GetObject<Ccnx> (), incomingFace); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 375 | return; // do not process unsoliced data packets |
| 376 | } |
| 377 | } |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 378 | |
| 379 | void |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame^] | 380 | CcnxL3Protocol::SendInterest (const Ptr<CcnxFace> &face, |
| 381 | const Ptr<CcnxInterestHeader> &header, |
| 382 | const Ptr<Packet> &packet) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 383 | { |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame^] | 384 | NS_LOG_FUNCTION (this << "packet: " << &packet << ", face: "<< &face); |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 385 | NS_ASSERT_MSG (face != 0, "Face should never be NULL"); |
| 386 | |
| 387 | if (face->IsUp ()) |
| 388 | { |
| 389 | NS_LOG_LOGIC ("Sending via face " << &face); // |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame^] | 390 | m_transmittedInterestsTrace (header, m_node->GetObject<Ccnx> (), face); |
| 391 | face->Send (packet); |
| 392 | } |
| 393 | else |
| 394 | { |
| 395 | NS_LOG_LOGIC ("Dropping -- outgoing interface is down: " << &face); |
| 396 | m_droppedInterestsTrace (header, INTERFACE_DOWN, m_node->GetObject<Ccnx> (), face); |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | void |
| 401 | CcnxL3Protocol::SendContentObject (const Ptr<CcnxFace> &face, |
| 402 | const Ptr<CcnxContentObjectHeader> &header, |
| 403 | const Ptr<Packet> &packet) |
| 404 | { |
| 405 | NS_LOG_FUNCTION (this << "packet: " << &packet << ", face: "<< &face); |
| 406 | NS_ASSERT_MSG (face != 0, "Face should never be NULL"); |
| 407 | |
| 408 | NS_ASSERT_MSG (false, "Should not be called for now"); |
| 409 | |
| 410 | if (face->IsUp ()) |
| 411 | { |
| 412 | NS_LOG_LOGIC ("Sending via face " << &face); // |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 413 | // m_txTrace (packet, m_node->GetObject<Ccnx> (), face); |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 414 | face->Send (packet); |
| 415 | } |
| 416 | else |
| 417 | { |
| 418 | NS_LOG_LOGIC ("Dropping -- outgoing interface is down: " << &face); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 419 | // m_dropTrace (packet, INTERFACE_DOWN, m_node->GetObject<Ccnx> (), face); |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 420 | } |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 423 | } //namespace ns3 |