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/net-device.h" |
| 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 | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 41 | #include <boost/foreach.hpp> |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 42 | |
| 43 | NS_LOG_COMPONENT_DEFINE ("CcnxL3Protocol"); |
| 44 | |
| 45 | namespace ns3 { |
| 46 | |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 47 | const uint16_t CcnxL3Protocol::ETHERNET_FRAME_TYPE = 0x7777; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 48 | |
| 49 | NS_OBJECT_ENSURE_REGISTERED (CcnxL3Protocol); |
| 50 | |
| 51 | TypeId |
| 52 | CcnxL3Protocol::GetTypeId (void) |
| 53 | { |
| 54 | static TypeId tid = TypeId ("ns3::CcnxL3Protocol") |
| 55 | .SetParent<Ccnx> () |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 56 | .SetGroupName ("Ccnx") |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 57 | .AddConstructor<CcnxL3Protocol> () |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 58 | // .AddTraceSource ("Tx", "Send ccnx packet to outgoing interface.", |
| 59 | // MakeTraceSourceAccessor (&CcnxL3Protocol::m_txTrace)) |
| 60 | // .AddTraceSource ("Rx", "Receive ccnx packet from incoming interface.", |
| 61 | // MakeTraceSourceAccessor (&CcnxL3Protocol::m_rxTrace)) |
| 62 | // .AddTraceSource ("Drop", "Drop ccnx packet", |
| 63 | // MakeTraceSourceAccessor (&CcnxL3Protocol::m_dropTrace)) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 64 | .AddAttribute ("InterfaceList", "The set of Ccnx interfaces associated to this Ccnx stack.", |
| 65 | ObjectVectorValue (), |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 66 | MakeObjectVectorAccessor (&CcnxL3Protocol::m_faces), |
| 67 | MakeObjectVectorChecker<CcnxFace> ()) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 68 | |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 69 | // .AddTraceSource ("SendOutgoing", "A newly-generated packet by this node is about to be queued for transmission", |
| 70 | // MakeTraceSourceAccessor (&CcnxL3Protocol::m_sendOutgoingTrace)) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 71 | |
| 72 | ; |
| 73 | return tid; |
| 74 | } |
| 75 | |
| 76 | CcnxL3Protocol::CcnxL3Protocol() |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 77 | : m_faceCounter (0) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 78 | { |
| 79 | NS_LOG_FUNCTION (this); |
| 80 | } |
| 81 | |
| 82 | CcnxL3Protocol::~CcnxL3Protocol () |
| 83 | { |
| 84 | NS_LOG_FUNCTION (this); |
| 85 | } |
| 86 | |
| 87 | void |
| 88 | CcnxL3Protocol::SetNode (Ptr<Node> node) |
| 89 | { |
| 90 | m_node = node; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /* |
| 94 | * This method is called by AddAgregate and completes the aggregation |
| 95 | * by setting the node in the ccnx stack |
| 96 | */ |
| 97 | void |
| 98 | CcnxL3Protocol::NotifyNewAggregate () |
| 99 | { |
| 100 | if (m_node == 0) |
| 101 | { |
| 102 | Ptr<Node>node = this->GetObject<Node>(); |
| 103 | // verify that it's a valid node and that |
| 104 | // the node has not been set before |
| 105 | if (node != 0) |
| 106 | { |
| 107 | this->SetNode (node); |
| 108 | } |
| 109 | } |
| 110 | Object::NotifyNewAggregate (); |
| 111 | } |
| 112 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 113 | void |
| 114 | CcnxL3Protocol::DoDispose (void) |
| 115 | { |
| 116 | NS_LOG_FUNCTION (this); |
| 117 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 118 | for (CcnxFaceList::iterator i = m_faces.begin (); i != m_faces.end (); ++i) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 119 | { |
| 120 | *i = 0; |
| 121 | } |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 122 | m_faces.clear (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 123 | m_node = 0; |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 124 | // m_forwardingStrategy = 0; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 125 | Object::DoDispose (); |
| 126 | } |
| 127 | |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 128 | void |
| 129 | CcnxL3Protocol::SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy) |
| 130 | { |
| 131 | NS_LOG_FUNCTION (this); |
| 132 | m_forwardingStrategy = forwardingStrategy; |
| 133 | m_forwardingStrategy->SetCcnx (this); |
| 134 | } |
| 135 | |
| 136 | Ptr<CcnxForwardingStrategy> |
| 137 | CcnxL3Protocol::GetForwardingStrategy (void) const |
| 138 | { |
| 139 | return m_forwardingStrategy; |
| 140 | } |
| 141 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 142 | uint32_t |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 143 | CcnxL3Protocol::AddFace (const Ptr<CcnxFace> &face) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 144 | { |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 145 | NS_LOG_FUNCTION (this << &face); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 146 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 147 | face->SetNode (m_node); |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 148 | 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] | 149 | |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 150 | // ask face to register in lower-layer stack |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 151 | face->RegisterProtocolHandler (MakeCallback (&CcnxL3Protocol::Receive, this)); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 152 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 153 | m_faces.push_back (face); |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 154 | m_faceCounter ++; |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 155 | return face->GetId (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 158 | Ptr<CcnxFace> |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 159 | CcnxL3Protocol::GetFace (uint32_t index) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 160 | { |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 161 | 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] | 162 | { |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 163 | if (face->GetId () == index) |
| 164 | return face; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 165 | } |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | uint32_t |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 170 | CcnxL3Protocol::GetNFaces (void) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 171 | { |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 172 | return m_faces.size (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 175 | // Callback from lower layer |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 176 | void |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 177 | CcnxL3Protocol::Receive (const Ptr<CcnxFace> &face, const Ptr<const Packet> &p) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 178 | { |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 179 | if (face->IsUp ()) |
| 180 | { |
| 181 | NS_LOG_LOGIC ("Dropping received packet -- interface is down"); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame^] | 182 | // m_dropTrace (p, INTERFACE_DOWN, m_node->GetObject<Ccnx> ()/*this*/, face); |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 183 | return; |
| 184 | } |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 185 | 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] | 186 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 187 | 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] | 188 | try |
| 189 | { |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 190 | CcnxHeaderHelper::Type type = CcnxHeaderHelper::CreateCorrectCcnxHeader (p); |
| 191 | switch (type) |
| 192 | { |
| 193 | case CcnxHeaderHelper::INTEREST: |
| 194 | { |
| 195 | Ptr<CcnxInterestHeader> header = Create<CcnxInterestHeader> (); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame^] | 196 | |
| 197 | // Deserialization. Exception may be thrown |
| 198 | packet->RemoveHeader (*header); |
| 199 | NS_ASSERT_MSG (packet->GetSize () == 0, "Payload of Interests should be zero"); |
| 200 | |
| 201 | OnInterest (face, header, p/*original packet*/); |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 202 | break; |
| 203 | } |
| 204 | case CcnxHeaderHelper::CONTENT_OBJECT: |
| 205 | { |
| 206 | Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> (); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame^] | 207 | |
| 208 | static CcnxContentObjectTail contentObjectTrailer; //there is no data in this object |
| 209 | |
| 210 | // Deserialization. Exception may be thrown |
| 211 | packet->RemoveHeader (*header); |
| 212 | packet->RemoveTrailer (contentObjectTrailer); |
| 213 | |
| 214 | OnData (face, header, packet/*payload*/, p/*original packet*/); |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 215 | break; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | // exception will be thrown if packet is not recognized |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 220 | } |
| 221 | catch (CcnxUnknownHeaderException) |
| 222 | { |
| 223 | NS_ASSERT_MSG (false, "Unknown CCNx header. Should not happen"); |
| 224 | } |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 225 | } |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 226 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 227 | // Processing Interests |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 228 | void CcnxL3Protocol::OnInterest (const Ptr<CcnxFace> &incomingFace, |
| 229 | Ptr<CcnxInterestHeader> &header, |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame^] | 230 | const Ptr<const Packet> &packet) |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 231 | { |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 232 | NS_LOG_LOGIC ("Receiving interest from " << &incomingFace); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame^] | 233 | m_receivedInterestsTrace (header, m_node->GetObject<Ccnx> ()/*this*/, incomingFace); |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 234 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 235 | |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 236 | /// \todo Processing of Interest packets |
| 237 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 238 | // NS_ASSERT_MSG (m_forwardingStrategy != 0, "Need a forwarding protocol object to process packets"); |
| 239 | // if (!m_forwardingStrategy->RouteInput (packet, incomingFace, |
| 240 | // MakeCallback (&CcnxL3Protocol::Send, this), |
| 241 | // MakeCallback (&CcnxL3Protocol::RouteInputError, this) |
| 242 | // )) |
| 243 | // { |
| 244 | // NS_LOG_WARN ("No route found for forwarding packet. Drop."); |
| 245 | // m_dropTrace (packet, DROP_NO_ROUTE, m_node->GetObject<Ccnx> (), incomingFace); |
| 246 | // } |
| 247 | } |
| 248 | |
| 249 | // Processing ContentObjects |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 250 | void CcnxL3Protocol::OnData (const Ptr<CcnxFace> &incomingFace, |
| 251 | Ptr<CcnxContentObjectHeader> &header, |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame^] | 252 | Ptr<Packet> &payload, |
| 253 | const Ptr<const Packet> &packet) |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 254 | { |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 255 | |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 256 | NS_LOG_LOGIC ("Receiving contentObject from " << &incomingFace); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame^] | 257 | m_receivedDataTrace (header, payload, m_node->GetObject<Ccnx> ()/*this*/, incomingFace); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 258 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame^] | 259 | // 1. Lookup PIT entry |
| 260 | try |
| 261 | { |
| 262 | const CcnxPitEntry &pitEntry = m_pit.Lookup (*header); |
| 263 | |
| 264 | // Note that with MultiIndex we need to modify entries indirectly |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 265 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame^] | 266 | // Update metric status for the incoming interface in the corresponding FIB entry |
| 267 | m_pit.modify (m_pit.iterator_to (pitEntry), |
| 268 | CcnxPitEntry::UpdateFibStatus (incomingFace, CcnxFibFaceMetric::NDN_FIB_GREEN)); |
| 269 | |
| 270 | // Add or update entry in the content store |
| 271 | m_contentStore.Add (header, payload); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 272 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame^] | 273 | CcnxPitEntryOutgoingFaceContainer::type::iterator |
| 274 | out = pitEntry.m_outgoing.find (incomingFace); |
| 275 | |
| 276 | // If we have sent interest for this data via this face, then update stats. |
| 277 | if (out != pitEntry.m_outgoing.end ()) |
| 278 | { |
| 279 | m_pit.modify (m_pit.iterator_to (pitEntry), CcnxPitEntry::EstimateRttAndRemoveFace(out)); |
| 280 | // face will be removed in the above call |
| 281 | } |
| 282 | else |
| 283 | { |
| 284 | NS_LOG_WARN ("Node "<< m_node->GetId() << |
| 285 | ". PIT entry for "<< header->GetName ()<<" is valid, " |
| 286 | "but outgoing entry for interface "<< incomingFace <<" doesn't exist\n"); |
| 287 | } |
| 288 | |
| 289 | //satisfy all pending incoming Interests |
| 290 | BOOST_FOREACH (const CcnxPitEntryIncomingFace &interest, pitEntry.m_incoming) |
| 291 | { |
| 292 | if (interest.m_face == incomingFace) continue; |
| 293 | |
| 294 | // may not work either because of 'const' thing |
| 295 | interest.m_face->Send (packet->Copy ()); // unfortunately, we have to copy packet... |
| 296 | m_transmittedDataTrace (header, payload, FORWARDED, m_node->GetObject<Ccnx> (), interest.m_face); |
| 297 | } |
| 298 | |
| 299 | m_pit.modify (m_pit.iterator_to (pitEntry), CcnxPitEntry::ClearIncoming()); // satisfy all incoming interests |
| 300 | |
| 301 | if( pitEntry.m_outgoing.size()==0 ) // remove PIT when all outgoing interests are "satisfied" |
| 302 | { |
| 303 | m_pit.erase (m_pit.iterator_to (pitEntry)); |
| 304 | } |
| 305 | |
| 306 | } |
| 307 | catch (CcnxPitEntryNotFound) |
| 308 | { |
| 309 | // 2. Drop data packet if PIT entry is not found |
| 310 | // (unsolicited data packets should not "poison" content store) |
| 311 | |
| 312 | //drop dulicated or not requested data packet |
| 313 | m_droppeddDataTrace (header, payload, NDN_UNSOLICITED_DATA, m_node->GetObject<Ccnx> (), incomingFace); |
| 314 | return; // do not process unsoliced data packets |
| 315 | } |
| 316 | } |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 317 | |
| 318 | void |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 319 | CcnxL3Protocol::Send (const Ptr<CcnxFace> &face, const Ptr<Packet> &packet) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 320 | { |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 321 | NS_LOG_FUNCTION (this << "packet: " << &packet << ", face: "<< &face); // |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 322 | |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 323 | NS_ASSERT_MSG (face != 0, "Face should never be NULL"); |
| 324 | |
| 325 | if (face->IsUp ()) |
| 326 | { |
| 327 | NS_LOG_LOGIC ("Sending via face " << &face); // |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 328 | // m_txTrace (packet, m_node->GetObject<Ccnx> (), face); |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 329 | face->Send (packet); |
| 330 | } |
| 331 | else |
| 332 | { |
| 333 | NS_LOG_LOGIC ("Dropping -- outgoing interface is down: " << &face); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame^] | 334 | // m_dropTrace (packet, INTERFACE_DOWN, m_node->GetObject<Ccnx> (), face); |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 335 | } |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 339 | } //namespace ns3 |