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