375 { |
375 { |
376 if (this->GetObject<Ipv6L3Protocol> () != 0) |
376 if (this->GetObject<Ipv6L3Protocol> () != 0) |
377 { |
377 { |
378 NS_LOG_LOGIC (" No Ipv4 endpoints matched on TcpL4Protocol, trying Ipv6 "<<this); |
378 NS_LOG_LOGIC (" No Ipv4 endpoints matched on TcpL4Protocol, trying Ipv6 "<<this); |
379 Ptr<Ipv6Interface> fakeInterface; |
379 Ptr<Ipv6Interface> fakeInterface; |
|
380 Ipv6Header ipv6Header; |
380 Ipv6Address src = Ipv6Address::MakeIpv4MappedAddress (ipHeader.GetSource ()); |
381 Ipv6Address src = Ipv6Address::MakeIpv4MappedAddress (ipHeader.GetSource ()); |
381 Ipv6Address dst = Ipv6Address::MakeIpv4MappedAddress (ipHeader.GetDestination ()); |
382 Ipv6Address dst = Ipv6Address::MakeIpv4MappedAddress (ipHeader.GetDestination ()); |
382 return (this->Receive (packet, src, dst, fakeInterface)); |
383 ipv6Header.SetSourceAddress (src); |
|
384 ipv6Header.SetDestinationAddress (dst); |
|
385 return (this->Receive (packet, ipv6Header, fakeInterface)); |
383 } |
386 } |
384 |
387 |
385 NS_LOG_LOGIC (" No endpoints matched on TcpL4Protocol "<<this); |
388 NS_LOG_LOGIC (" No endpoints matched on TcpL4Protocol "<<this); |
386 std::ostringstream oss; |
389 std::ostringstream oss; |
387 oss<<" destination IP: "; |
390 oss<<" destination IP: "; |
425 return IpL4Protocol::RX_OK; |
428 return IpL4Protocol::RX_OK; |
426 } |
429 } |
427 |
430 |
428 enum IpL4Protocol::RxStatus |
431 enum IpL4Protocol::RxStatus |
429 TcpL4Protocol::Receive (Ptr<Packet> packet, |
432 TcpL4Protocol::Receive (Ptr<Packet> packet, |
430 Ipv6Address &src, |
433 Ipv6Header const &ipHeader, |
431 Ipv6Address &dst, |
|
432 Ptr<Ipv6Interface> interface) |
434 Ptr<Ipv6Interface> interface) |
433 { |
435 { |
434 NS_LOG_FUNCTION (this << packet << src << dst); |
436 NS_LOG_FUNCTION (this << packet << ipHeader.GetSourceAddress () << ipHeader.GetDestinationAddress ()); |
435 |
437 |
436 TcpHeader tcpHeader; |
438 TcpHeader tcpHeader; |
437 |
439 |
438 // If we are receving a v4-mapped packet, we will re-calculate the TCP checksum |
440 // If we are receving a v4-mapped packet, we will re-calculate the TCP checksum |
439 // Is it worth checking every received "v6" packet to see if it is v4-mapped in |
441 // Is it worth checking every received "v6" packet to see if it is v4-mapped in |
440 // order to avoid re-calculating TCP checksums for v4-mapped packets? |
442 // order to avoid re-calculating TCP checksums for v4-mapped packets? |
441 |
443 |
442 if(Node::ChecksumEnabled ()) |
444 if(Node::ChecksumEnabled ()) |
443 { |
445 { |
444 tcpHeader.EnableChecksums (); |
446 tcpHeader.EnableChecksums (); |
445 tcpHeader.InitializeChecksum (src, dst, PROT_NUMBER); |
447 tcpHeader.InitializeChecksum (ipHeader.GetSourceAddress (), ipHeader.GetDestinationAddress (), PROT_NUMBER); |
446 } |
448 } |
447 |
449 |
448 packet->PeekHeader (tcpHeader); |
450 packet->PeekHeader (tcpHeader); |
449 |
451 |
450 NS_LOG_LOGIC ("TcpL4Protocol " << this |
452 NS_LOG_LOGIC ("TcpL4Protocol " << this |
459 return IpL4Protocol::RX_CSUM_FAILED; |
461 return IpL4Protocol::RX_CSUM_FAILED; |
460 } |
462 } |
461 |
463 |
462 NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" received a packet"); |
464 NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" received a packet"); |
463 Ipv6EndPointDemux::EndPoints endPoints = |
465 Ipv6EndPointDemux::EndPoints endPoints = |
464 m_endPoints6->Lookup (dst, tcpHeader.GetDestinationPort (), |
466 m_endPoints6->Lookup (ipHeader.GetDestinationAddress (), tcpHeader.GetDestinationPort (), |
465 src, tcpHeader.GetSourcePort (),interface); |
467 ipHeader.GetSourceAddress (), tcpHeader.GetSourcePort (),interface); |
466 if (endPoints.empty ()) |
468 if (endPoints.empty ()) |
467 { |
469 { |
468 NS_LOG_LOGIC (" No IPv6 endpoints matched on TcpL4Protocol "<<this); |
470 NS_LOG_LOGIC (" No IPv6 endpoints matched on TcpL4Protocol "<<this); |
469 std::ostringstream oss; |
471 std::ostringstream oss; |
470 oss<<" destination IP: "; |
472 oss<<" destination IP: "; |
471 dst.Print (oss); |
473 (ipHeader.GetDestinationAddress ()).Print (oss); |
472 oss<<" destination port: "<< tcpHeader.GetDestinationPort ()<<" source IP: "; |
474 oss<<" destination port: "<< tcpHeader.GetDestinationPort ()<<" source IP: "; |
473 src.Print (oss); |
475 (ipHeader.GetSourceAddress ()).Print (oss); |
474 oss<<" source port: "<<tcpHeader.GetSourcePort (); |
476 oss<<" source port: "<<tcpHeader.GetSourcePort (); |
475 NS_LOG_LOGIC (oss.str ()); |
477 NS_LOG_LOGIC (oss.str ()); |
476 |
478 |
477 if (!(tcpHeader.GetFlags () & TcpHeader::RST)) |
479 if (!(tcpHeader.GetFlags () & TcpHeader::RST)) |
478 { |
480 { |
491 header.SetSequenceNumber (SequenceNumber32 (0)); |
493 header.SetSequenceNumber (SequenceNumber32 (0)); |
492 header.SetAckNumber (header.GetSequenceNumber () + SequenceNumber32 (1)); |
494 header.SetAckNumber (header.GetSequenceNumber () + SequenceNumber32 (1)); |
493 } |
495 } |
494 header.SetSourcePort (tcpHeader.GetDestinationPort ()); |
496 header.SetSourcePort (tcpHeader.GetDestinationPort ()); |
495 header.SetDestinationPort (tcpHeader.GetSourcePort ()); |
497 header.SetDestinationPort (tcpHeader.GetSourcePort ()); |
496 SendPacket (rstPacket, header, dst, src); |
498 SendPacket (rstPacket, header, ipHeader.GetDestinationAddress (), ipHeader.GetSourceAddress ()); |
497 return IpL4Protocol::RX_ENDPOINT_CLOSED; |
499 return IpL4Protocol::RX_ENDPOINT_CLOSED; |
498 } |
500 } |
499 else |
501 else |
500 { |
502 { |
501 return IpL4Protocol::RX_ENDPOINT_CLOSED; |
503 return IpL4Protocol::RX_ENDPOINT_CLOSED; |
502 } |
504 } |
503 } |
505 } |
504 NS_ASSERT_MSG (endPoints.size () == 1, "Demux returned more than one endpoint"); |
506 NS_ASSERT_MSG (endPoints.size () == 1, "Demux returned more than one endpoint"); |
505 NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" forwarding up to endpoint/socket"); |
507 NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" forwarding up to endpoint/socket"); |
506 (*endPoints.begin ())->ForwardUp (packet, src, dst, tcpHeader.GetSourcePort ()); |
508 (*endPoints.begin ())->ForwardUp (packet, ipHeader, tcpHeader.GetSourcePort ()); |
507 return IpL4Protocol::RX_OK; |
509 return IpL4Protocol::RX_OK; |
508 } |
510 } |
509 |
511 |
510 void |
512 void |
511 TcpL4Protocol::Send (Ptr<Packet> packet, |
513 TcpL4Protocol::Send (Ptr<Packet> packet, |