OLD | NEW |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2005 INRIA | 3 * Copyright (c) 2005 INRIA |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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 | 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 | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * | 17 * |
18 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> | 18 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
19 */ | 19 */ |
20 | 20 |
21 #include "ns3/log.h" | 21 #include "ns3/log.h" |
22 #include "ns3/assert.h" | 22 #include "ns3/assert.h" |
23 #include "ns3/packet.h" | 23 #include "ns3/packet.h" |
24 #include "ns3/node.h" | 24 #include "ns3/node.h" |
25 #include "ns3/boolean.h" | 25 #include "ns3/boolean.h" |
26 #include "ns3/object-vector.h" | 26 #include "ns3/object-vector.h" |
| 27 #include "ns3/ipv6.h" |
27 #include "ns3/ipv4-route.h" | 28 #include "ns3/ipv4-route.h" |
| 29 #include "ns3/ipv6-route.h" |
| 30 #include "ns3/ipv6-header.h" |
28 | 31 |
29 #include "udp-l4-protocol.h" | 32 #include "udp-l4-protocol.h" |
30 #include "udp-header.h" | 33 #include "udp-header.h" |
31 #include "udp-socket-factory-impl.h" | 34 #include "udp-socket-factory-impl.h" |
32 #include "ipv4-end-point-demux.h" | 35 #include "ipv4-end-point-demux.h" |
33 #include "ipv4-end-point.h" | 36 #include "ipv4-end-point.h" |
| 37 #include "ipv6-end-point-demux.h" |
| 38 #include "ipv6-end-point.h" |
34 #include "ipv4-l3-protocol.h" | 39 #include "ipv4-l3-protocol.h" |
| 40 #include "ipv6-l3-protocol.h" |
35 #include "udp-socket-impl.h" | 41 #include "udp-socket-impl.h" |
36 | 42 |
37 NS_LOG_COMPONENT_DEFINE ("UdpL4Protocol"); | 43 NS_LOG_COMPONENT_DEFINE ("UdpL4Protocol"); |
38 | 44 |
39 namespace ns3 { | 45 namespace ns3 { |
40 | 46 |
41 NS_OBJECT_ENSURE_REGISTERED (UdpL4Protocol); | 47 NS_OBJECT_ENSURE_REGISTERED (UdpL4Protocol); |
42 | 48 |
43 /* see http://www.iana.org/assignments/protocol-numbers */ | 49 /* see http://www.iana.org/assignments/protocol-numbers */ |
44 const uint8_t UdpL4Protocol::PROT_NUMBER = 17; | 50 const uint8_t UdpL4Protocol::PROT_NUMBER = 17; |
45 | 51 |
46 TypeId· | 52 TypeId· |
47 UdpL4Protocol::GetTypeId (void) | 53 UdpL4Protocol::GetTypeId (void) |
48 { | 54 { |
49 static TypeId tid = TypeId ("ns3::UdpL4Protocol") | 55 static TypeId tid = TypeId ("ns3::UdpL4Protocol") |
50 .SetParent<Ipv4L4Protocol> () | 56 .SetParent<IpL4Protocol> () |
51 .AddConstructor<UdpL4Protocol> () | 57 .AddConstructor<UdpL4Protocol> () |
52 .AddAttribute ("SocketList", "The list of sockets associated to this protoco
l.", | 58 .AddAttribute ("SocketList", "The list of sockets associated to this protoco
l.", |
53 ObjectVectorValue (), | 59 ObjectVectorValue (), |
54 MakeObjectVectorAccessor (&UdpL4Protocol::m_sockets), | 60 MakeObjectVectorAccessor (&UdpL4Protocol::m_sockets), |
55 MakeObjectVectorChecker<UdpSocketImpl> ()) | 61 MakeObjectVectorChecker<UdpSocketImpl> ()) |
56 ; | 62 ; |
57 return tid; | 63 return tid; |
58 } | 64 } |
59 | 65 |
60 UdpL4Protocol::UdpL4Protocol () | 66 UdpL4Protocol::UdpL4Protocol () |
61 : m_endPoints (new Ipv4EndPointDemux ()) | 67 : m_endPoints (new Ipv4EndPointDemux ()), m_endPoints6 (new Ipv6EndPointDemux
()) |
62 { | 68 { |
63 NS_LOG_FUNCTION_NOARGS (); | 69 NS_LOG_FUNCTION_NOARGS (); |
64 } | 70 } |
65 | 71 |
66 UdpL4Protocol::~UdpL4Protocol () | 72 UdpL4Protocol::~UdpL4Protocol () |
67 { | 73 { |
68 NS_LOG_FUNCTION_NOARGS (); | 74 NS_LOG_FUNCTION_NOARGS (); |
69 } | 75 } |
70 | 76 |
71 void· | 77 void· |
72 UdpL4Protocol::SetNode (Ptr<Node> node) | 78 UdpL4Protocol::SetNode (Ptr<Node> node) |
73 { | 79 { |
74 m_node = node; | 80 m_node = node; |
75 } | 81 } |
76 | 82 |
77 /* | 83 /* |
78 * This method is called by AddAgregate and completes the aggregation | 84 * This method is called by AddAgregate and completes the aggregation |
79 * by setting the node in the udp stack and link it to the ipv4 object | 85 * by setting the node in the udp stack and link it to the ipv4 object |
80 * present in the node along with the socket factory | 86 * present in the node along with the socket factory |
81 */ | 87 */ |
82 void | 88 void |
83 UdpL4Protocol::NotifyNewAggregate () | 89 UdpL4Protocol::NotifyNewAggregate () |
84 { | 90 { |
| 91 Ptr<Node> node = this->GetObject<Node> (); |
| 92 Ptr<Ipv4> ipv4 = this->GetObject<Ipv4> (); |
| 93 Ptr<Ipv6L3Protocol> ipv6 = node->GetObject<Ipv6L3Protocol> (); |
| 94 |
85 if (m_node == 0) | 95 if (m_node == 0) |
86 { | 96 { |
87 Ptr<Node> node = this->GetObject<Node> (); | 97 if ((node != 0) && (ipv4 != 0 || ipv6 != 0)) |
88 if (node != 0) | |
89 { | 98 { |
90 Ptr<Ipv4> ipv4 = this->GetObject<Ipv4> (); | 99 this->SetNode (node); |
91 if (ipv4 != 0) | 100 Ptr<UdpSocketFactoryImpl> udpFactory = CreateObject<UdpSocketFactoryIm
pl> (); |
92 { | 101 udpFactory->SetUdp (this); |
93 this->SetNode (node); | 102 node->AggregateObject (udpFactory); |
94 ipv4->Insert (this); | |
95 Ptr<UdpSocketFactoryImpl> udpFactory = CreateObject<UdpSocketFacto
ryImpl> (); | |
96 udpFactory->SetUdp (this); | |
97 node->AggregateObject (udpFactory); | |
98 this->SetDownTarget (MakeCallback (&Ipv4::Send, ipv4)); | |
99 } | |
100 } | 103 } |
101 } | 104 } |
| 105 ·· |
| 106 // We set at least one of our 2 down targets to the IPv4/IPv6 send |
| 107 // functions. Since these functions have different prototypes, we |
| 108 // need to keep track of whether we are connected to an IPv4 or |
| 109 // IPv6 lower layer and call the appropriate one. |
| 110 ·· |
| 111 if (ipv4 != 0) |
| 112 { |
| 113 ipv4->Insert (this); |
| 114 this->SetDownTarget (MakeCallback (&Ipv4::Send, ipv4)); |
| 115 } |
| 116 if (ipv6 != 0) |
| 117 { |
| 118 ipv6->Insert (this); |
| 119 this->SetDownTarget6 (MakeCallback (&Ipv6L3Protocol::Send, ipv6)); |
| 120 } |
102 Object::NotifyNewAggregate (); | 121 Object::NotifyNewAggregate (); |
103 } | 122 } |
104 | 123 |
105 int· | 124 int· |
106 UdpL4Protocol::GetProtocolNumber (void) const | 125 UdpL4Protocol::GetProtocolNumber (void) const |
107 { | 126 { |
108 return PROT_NUMBER; | 127 return PROT_NUMBER; |
109 } | 128 } |
110 | 129 |
111 | 130 |
112 void | 131 void |
113 UdpL4Protocol::DoDispose (void) | 132 UdpL4Protocol::DoDispose (void) |
114 { | 133 { |
115 NS_LOG_FUNCTION_NOARGS (); | 134 NS_LOG_FUNCTION_NOARGS (); |
116 for (std::vector<Ptr<UdpSocketImpl> >::iterator i = m_sockets.begin (); i != m
_sockets.end (); i++) | 135 for (std::vector<Ptr<UdpSocketImpl> >::iterator i = m_sockets.begin (); i != m
_sockets.end (); i++) |
117 { | 136 { |
118 *i = 0; | 137 *i = 0; |
119 } | 138 } |
120 m_sockets.clear (); | 139 m_sockets.clear (); |
121 | 140 |
122 if (m_endPoints != 0) | 141 if (m_endPoints != 0) |
123 { | 142 { |
124 delete m_endPoints; | 143 delete m_endPoints; |
125 m_endPoints = 0; | 144 m_endPoints = 0; |
126 } | 145 } |
| 146 if (m_endPoints6 != 0) |
| 147 { |
| 148 delete m_endPoints6; |
| 149 m_endPoints6 = 0; |
| 150 } |
127 m_node = 0; | 151 m_node = 0; |
128 m_downTarget.Nullify (); | 152 m_downTarget.Nullify (); |
| 153 m_downTarget6.Nullify (); |
129 /* | 154 /* |
130 = MakeNullCallback<void,Ptr<Packet>, Ipv4Address, Ipv4Address, uint8_t, Ptr<Ipv
4Route> > (); | 155 = MakeNullCallback<void,Ptr<Packet>, Ipv4Address, Ipv4Address, uint8_t, Ptr<Ipv
4Route> > (); |
131 */ | 156 */ |
132 Ipv4L4Protocol::DoDispose (); | 157 IpL4Protocol::DoDispose (); |
133 } | 158 } |
134 | 159 |
135 Ptr<Socket> | 160 Ptr<Socket> |
136 UdpL4Protocol::CreateSocket (void) | 161 UdpL4Protocol::CreateSocket (void) |
137 { | 162 { |
138 NS_LOG_FUNCTION_NOARGS (); | 163 NS_LOG_FUNCTION_NOARGS (); |
139 Ptr<UdpSocketImpl> socket = CreateObject<UdpSocketImpl> (); | 164 Ptr<UdpSocketImpl> socket = CreateObject<UdpSocketImpl> (); |
140 socket->SetNode (m_node); | 165 socket->SetNode (m_node); |
141 socket->SetUdp (this); | 166 socket->SetUdp (this); |
142 m_sockets.push_back (socket); | 167 m_sockets.push_back (socket); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 peerAddress, peerPort); | 204 peerAddress, peerPort); |
180 } | 205 } |
181 | 206 |
182 void· | 207 void· |
183 UdpL4Protocol::DeAllocate (Ipv4EndPoint *endPoint) | 208 UdpL4Protocol::DeAllocate (Ipv4EndPoint *endPoint) |
184 { | 209 { |
185 NS_LOG_FUNCTION (this << endPoint); | 210 NS_LOG_FUNCTION (this << endPoint); |
186 m_endPoints->DeAllocate (endPoint); | 211 m_endPoints->DeAllocate (endPoint); |
187 } | 212 } |
188 | 213 |
| 214 Ipv6EndPoint * |
| 215 UdpL4Protocol::Allocate6 (void) |
| 216 { |
| 217 NS_LOG_FUNCTION_NOARGS (); |
| 218 return m_endPoints6->Allocate (); |
| 219 } |
| 220 |
| 221 Ipv6EndPoint * |
| 222 UdpL4Protocol::Allocate6 (Ipv6Address address) |
| 223 { |
| 224 NS_LOG_FUNCTION (this << address); |
| 225 return m_endPoints6->Allocate (address); |
| 226 } |
| 227 |
| 228 Ipv6EndPoint * |
| 229 UdpL4Protocol::Allocate6 (uint16_t port) |
| 230 { |
| 231 NS_LOG_FUNCTION (this << port); |
| 232 return m_endPoints6->Allocate (port); |
| 233 } |
| 234 |
| 235 Ipv6EndPoint * |
| 236 UdpL4Protocol::Allocate6 (Ipv6Address address, uint16_t port) |
| 237 { |
| 238 NS_LOG_FUNCTION (this << address << port); |
| 239 return m_endPoints6->Allocate (address, port); |
| 240 } |
| 241 Ipv6EndPoint * |
| 242 UdpL4Protocol::Allocate6 (Ipv6Address localAddress, uint16_t localPort, |
| 243 Ipv6Address peerAddress, uint16_t peerPort) |
| 244 { |
| 245 NS_LOG_FUNCTION (this << localAddress << localPort << peerAddress << peerPort)
; |
| 246 return m_endPoints6->Allocate (localAddress, localPort, |
| 247 peerAddress, peerPort); |
| 248 } |
| 249 |
| 250 void· |
| 251 UdpL4Protocol::DeAllocate (Ipv6EndPoint *endPoint) |
| 252 { |
| 253 NS_LOG_FUNCTION (this << endPoint); |
| 254 m_endPoints6->DeAllocate (endPoint); |
| 255 } |
| 256 |
189 void· | 257 void· |
190 UdpL4Protocol::ReceiveIcmp (Ipv4Address icmpSource, uint8_t icmpTtl, | 258 UdpL4Protocol::ReceiveIcmp (Ipv4Address icmpSource, uint8_t icmpTtl, |
191 uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInf
o, | 259 uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInf
o, |
192 Ipv4Address payloadSource,Ipv4Address payloadDestina
tion, | 260 Ipv4Address payloadSource,Ipv4Address payloadDestina
tion, |
193 const uint8_t payload[8]) | 261 const uint8_t payload[8]) |
194 { | 262 { |
195 NS_LOG_FUNCTION (this << icmpSource << icmpTtl << icmpType << icmpCode << icmp
Info· | 263 NS_LOG_FUNCTION (this << icmpSource << icmpTtl << icmpType << icmpCode << icmp
Info· |
196 << payloadSource << payloadDestination); | 264 << payloadSource << payloadDestination); |
197 uint16_t src, dst; | 265 uint16_t src, dst; |
198 src = payload[0] << 8; | 266 src = payload[0] << 8; |
199 src |= payload[1]; | 267 src |= payload[1]; |
200 dst = payload[2] << 8; | 268 dst = payload[2] << 8; |
201 dst |= payload[3]; | 269 dst |= payload[3]; |
202 | 270 |
203 Ipv4EndPoint *endPoint = m_endPoints->SimpleLookup (payloadSource, src, payloa
dDestination, dst); | 271 Ipv4EndPoint *endPoint = m_endPoints->SimpleLookup (payloadSource, src, payloa
dDestination, dst); |
204 if (endPoint != 0) | 272 if (endPoint != 0) |
205 { | 273 { |
206 endPoint->ForwardIcmp (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo); | 274 endPoint->ForwardIcmp (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo); |
207 } | 275 } |
208 else | 276 else |
209 { | 277 { |
210 NS_LOG_DEBUG ("no endpoint found source=" << payloadSource << | 278 NS_LOG_DEBUG ("no endpoint found source=" << payloadSource << |
211 ", destination="<<payloadDestination<< | 279 ", destination="<<payloadDestination<< |
212 ", src=" << src << ", dst=" << dst); | 280 ", src=" << src << ", dst=" << dst); |
213 } | 281 } |
214 } | 282 } |
215 | 283 |
216 enum Ipv4L4Protocol::RxStatus | 284 void· |
| 285 UdpL4Protocol::ReceiveIcmp (Ipv6Address icmpSource, uint8_t icmpTtl, |
| 286 uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInf
o, |
| 287 Ipv6Address payloadSource,Ipv6Address payloadDestina
tion, |
| 288 const uint8_t payload[8]) |
| 289 { |
| 290 NS_LOG_FUNCTION (this << icmpSource << icmpTtl << icmpType << icmpCode << icmp
Info· |
| 291 << payloadSource << payloadDestination); |
| 292 uint16_t src, dst; |
| 293 src = payload[0] << 8; |
| 294 src |= payload[1]; |
| 295 dst = payload[2] << 8; |
| 296 dst |= payload[3]; |
| 297 |
| 298 Ipv6EndPoint *endPoint = m_endPoints6->SimpleLookup (payloadSource, src, paylo
adDestination, dst); |
| 299 if (endPoint != 0) |
| 300 { |
| 301 endPoint->ForwardIcmp (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo); |
| 302 } |
| 303 else |
| 304 { |
| 305 NS_LOG_DEBUG ("no endpoint found source=" << payloadSource << |
| 306 ", destination="<<payloadDestination<< |
| 307 ", src=" << src << ", dst=" << dst); |
| 308 } |
| 309 } |
| 310 |
| 311 enum IpL4Protocol::RxStatus |
217 UdpL4Protocol::Receive (Ptr<Packet> packet, | 312 UdpL4Protocol::Receive (Ptr<Packet> packet, |
218 Ipv4Header const &header, | 313 Ipv4Header const &header, |
219 Ptr<Ipv4Interface> interface) | 314 Ptr<Ipv4Interface> interface) |
220 { | 315 { |
221 NS_LOG_FUNCTION (this << packet << header); | 316 NS_LOG_FUNCTION (this << packet << header); |
222 UdpHeader udpHeader; | 317 UdpHeader udpHeader; |
223 if(Node::ChecksumEnabled ()) | 318 if(Node::ChecksumEnabled ()) |
224 { | 319 { |
225 udpHeader.EnableChecksums (); | 320 udpHeader.EnableChecksums (); |
226 } | 321 } |
227 | 322 |
228 udpHeader.InitializeChecksum (header.GetSource (), header.GetDestination (), P
ROT_NUMBER); | 323 udpHeader.InitializeChecksum (header.GetSource (), header.GetDestination (), P
ROT_NUMBER); |
229 | 324 |
230 packet->RemoveHeader (udpHeader); | 325 // We only peek at the header for now (instead of removing it) so that it will
be intact |
| 326 // if we have to pass it to a IPv6 endpoint via: |
| 327 //· |
| 328 // UdpL4Protocol::Receive (Ptr<Packet> packet, Ipv6Address &src, Ipv6Address
&dst, ...) |
| 329 |
| 330 packet->PeekHeader (udpHeader); |
231 | 331 |
232 if(!udpHeader.IsChecksumOk ()) | 332 if(!udpHeader.IsChecksumOk ()) |
233 { | 333 { |
234 NS_LOG_INFO ("Bad checksum : dropping packet!"); | 334 NS_LOG_INFO ("Bad checksum : dropping packet!"); |
235 return Ipv4L4Protocol::RX_CSUM_FAILED; | 335 return IpL4Protocol::RX_CSUM_FAILED; |
236 } | 336 } |
237 | 337 |
238 NS_LOG_DEBUG ("Looking up dst " << header.GetDestination () << " port " << udp
Header.GetDestinationPort ());· | 338 NS_LOG_DEBUG ("Looking up dst " << header.GetDestination () << " port " << udp
Header.GetDestinationPort ());· |
239 Ipv4EndPointDemux::EndPoints endPoints = | 339 Ipv4EndPointDemux::EndPoints endPoints = |
240 m_endPoints->Lookup (header.GetDestination (), udpHeader.GetDestinationPort
(), | 340 m_endPoints->Lookup (header.GetDestination (), udpHeader.GetDestinationPort
(), |
241 header.GetSource (), udpHeader.GetSourcePort (), interf
ace); | 341 header.GetSource (), udpHeader.GetSourcePort (), interf
ace); |
242 if (endPoints.empty ()) | 342 if (endPoints.empty ()) |
243 { | 343 { |
| 344 if (this->GetObject<Ipv6L3Protocol> () != 0) |
| 345 { |
| 346 NS_LOG_LOGIC (" No Ipv4 endpoints matched on UdpL4Protocol, trying Ip
v6 "<<this); |
| 347 Ptr<Ipv6Interface> fakeInterface; |
| 348 Ipv6Address src = Ipv6Address::MakeIpv4MappedAddress (header.GetSource
()); |
| 349 Ipv6Address dst = Ipv6Address::MakeIpv4MappedAddress (header.GetDestin
ation ()); |
| 350 return (this->Receive (packet, src, dst, fakeInterface)); |
| 351 } |
| 352 |
244 NS_LOG_LOGIC ("RX_ENDPOINT_UNREACH"); | 353 NS_LOG_LOGIC ("RX_ENDPOINT_UNREACH"); |
245 return Ipv4L4Protocol::RX_ENDPOINT_UNREACH; | 354 return IpL4Protocol::RX_ENDPOINT_UNREACH; |
246 } | 355 } |
| 356 |
| 357 packet->RemoveHeader(udpHeader); |
247 for (Ipv4EndPointDemux::EndPointsI endPoint = endPoints.begin (); | 358 for (Ipv4EndPointDemux::EndPointsI endPoint = endPoints.begin (); |
248 endPoint != endPoints.end (); endPoint++) | 359 endPoint != endPoints.end (); endPoint++) |
249 { | 360 { |
250 (*endPoint)->ForwardUp (packet->Copy (), header, udpHeader.GetSourcePort (
),· | 361 (*endPoint)->ForwardUp (packet->Copy (), header, udpHeader.GetSourcePort (
),· |
251 interface); | 362 interface); |
252 } | 363 } |
253 return Ipv4L4Protocol::RX_OK; | 364 return IpL4Protocol::RX_OK; |
| 365 } |
| 366 |
| 367 enum IpL4Protocol::RxStatus |
| 368 UdpL4Protocol::Receive (Ptr<Packet> packet, |
| 369 Ipv6Address &src, |
| 370 Ipv6Address &dst, |
| 371 Ptr<Ipv6Interface> interface) |
| 372 { |
| 373 NS_LOG_FUNCTION (this << packet << src << dst); |
| 374 UdpHeader udpHeader; |
| 375 if(Node::ChecksumEnabled ()) |
| 376 { |
| 377 udpHeader.EnableChecksums (); |
| 378 } |
| 379 |
| 380 udpHeader.InitializeChecksum (src, dst, PROT_NUMBER); |
| 381 |
| 382 packet->RemoveHeader (udpHeader); |
| 383 |
| 384 if(!udpHeader.IsChecksumOk () && !src.IsIpv4MappedAddress ()) |
| 385 { |
| 386 NS_LOG_INFO ("Bad checksum : dropping packet!"); |
| 387 return IpL4Protocol::RX_CSUM_FAILED; |
| 388 } |
| 389 |
| 390 NS_LOG_DEBUG ("Looking up dst " << dst << " port " << udpHeader.GetDestination
Port ());· |
| 391 Ipv6EndPointDemux::EndPoints endPoints = |
| 392 m_endPoints6->Lookup (dst, udpHeader.GetDestinationPort (), |
| 393 src, udpHeader.GetSourcePort (), interface); |
| 394 if (endPoints.empty ()) |
| 395 { |
| 396 NS_LOG_LOGIC ("RX_ENDPOINT_UNREACH"); |
| 397 return IpL4Protocol::RX_ENDPOINT_UNREACH; |
| 398 } |
| 399 for (Ipv6EndPointDemux::EndPointsI endPoint = endPoints.begin (); |
| 400 endPoint != endPoints.end (); endPoint++) |
| 401 { |
| 402 (*endPoint)->ForwardUp (packet->Copy (), src, dst, udpHeader.GetSourcePort
()); |
| 403 } |
| 404 return IpL4Protocol::RX_OK; |
254 } | 405 } |
255 | 406 |
256 void | 407 void |
257 UdpL4Protocol::Send (Ptr<Packet> packet,· | 408 UdpL4Protocol::Send (Ptr<Packet> packet,· |
258 Ipv4Address saddr, Ipv4Address daddr,· | 409 Ipv4Address saddr, Ipv4Address daddr,· |
259 uint16_t sport, uint16_t dport) | 410 uint16_t sport, uint16_t dport) |
260 { | 411 { |
261 NS_LOG_FUNCTION (this << packet << saddr << daddr << sport << dport); | 412 NS_LOG_FUNCTION (this << packet << saddr << daddr << sport << dport); |
262 | 413 |
263 UdpHeader udpHeader; | 414 UdpHeader udpHeader; |
(...skipping 29 matching lines...) Expand all Loading... |
293 } | 444 } |
294 udpHeader.SetDestinationPort (dport); | 445 udpHeader.SetDestinationPort (dport); |
295 udpHeader.SetSourcePort (sport); | 446 udpHeader.SetSourcePort (sport); |
296 | 447 |
297 packet->AddHeader (udpHeader); | 448 packet->AddHeader (udpHeader); |
298 | 449 |
299 m_downTarget (packet, saddr, daddr, PROT_NUMBER, route); | 450 m_downTarget (packet, saddr, daddr, PROT_NUMBER, route); |
300 } | 451 } |
301 | 452 |
302 void | 453 void |
303 UdpL4Protocol::SetDownTarget (Ipv4L4Protocol::DownTargetCallback callback) | 454 UdpL4Protocol::Send (Ptr<Packet> packet, |
| 455 Ipv6Address saddr, Ipv6Address daddr, |
| 456 uint16_t sport, uint16_t dport) |
| 457 { |
| 458 NS_LOG_FUNCTION (this << packet << saddr << daddr << sport << dport); |
| 459 |
| 460 UdpHeader udpHeader; |
| 461 if(Node::ChecksumEnabled ()) |
| 462 { |
| 463 udpHeader.EnableChecksums (); |
| 464 udpHeader.InitializeChecksum (saddr, |
| 465 daddr, |
| 466 PROT_NUMBER); |
| 467 } |
| 468 udpHeader.SetDestinationPort (dport); |
| 469 udpHeader.SetSourcePort (sport); |
| 470 |
| 471 packet->AddHeader (udpHeader); |
| 472 |
| 473 m_downTarget6 (packet, saddr, daddr, PROT_NUMBER, 0); |
| 474 } |
| 475 |
| 476 void |
| 477 UdpL4Protocol::Send (Ptr<Packet> packet, |
| 478 Ipv6Address saddr, Ipv6Address daddr, |
| 479 uint16_t sport, uint16_t dport, Ptr<Ipv6Route> route) |
| 480 { |
| 481 NS_LOG_FUNCTION (this << packet << saddr << daddr << sport << dport << route); |
| 482 |
| 483 UdpHeader udpHeader; |
| 484 if(Node::ChecksumEnabled ()) |
| 485 { |
| 486 udpHeader.EnableChecksums (); |
| 487 udpHeader.InitializeChecksum (saddr, |
| 488 daddr, |
| 489 PROT_NUMBER); |
| 490 } |
| 491 udpHeader.SetDestinationPort (dport); |
| 492 udpHeader.SetSourcePort (sport); |
| 493 |
| 494 packet->AddHeader (udpHeader); |
| 495 |
| 496 m_downTarget6 (packet, saddr, daddr, PROT_NUMBER, route); |
| 497 } |
| 498 |
| 499 void |
| 500 UdpL4Protocol::SetDownTarget (IpL4Protocol::DownTargetCallback callback) |
304 { | 501 { |
305 m_downTarget = callback; | 502 m_downTarget = callback; |
306 } | 503 } |
307 | 504 |
308 Ipv4L4Protocol::DownTargetCallback | 505 IpL4Protocol::DownTargetCallback |
309 UdpL4Protocol::GetDownTarget (void) const | 506 UdpL4Protocol::GetDownTarget (void) const |
310 { | 507 { |
311 return m_downTarget; | 508 return m_downTarget; |
312 } | 509 } |
313 | 510 |
| 511 void |
| 512 UdpL4Protocol::SetDownTarget6 (IpL4Protocol::DownTargetCallback6 callback) |
| 513 { |
| 514 m_downTarget6 = callback; |
| 515 } |
| 516 |
| 517 IpL4Protocol::DownTargetCallback6 |
| 518 UdpL4Protocol::GetDownTarget6 (void) const |
| 519 { |
| 520 return m_downTarget6; |
| 521 } |
| 522 |
314 } // namespace ns3 | 523 } // namespace ns3 |
315 | 524 |
OLD | NEW |