23 #include "ns3/uinteger.h"
24 #include "ns3/vector.h"
25 #include "ns3/boolean.h"
26 #include "ns3/callback.h"
27 #include "ns3/trace-source-accessor.h"
28 #include "ns3/object-vector.h"
29 #include "ns3/ipv6-routing-protocol.h"
30 #include "ns3/ipv6-route.h"
57 .AddConstructor<Ipv6L3Protocol> ()
58 .AddAttribute (
"DefaultTtl",
"The TTL value set by default on all outgoing packets generated on this node.",
61 MakeUintegerChecker<uint8_t> ())
62 .AddAttribute (
"InterfaceList",
"The set of IPv6 interfaces associated to this IPv6 stack.",
65 MakeObjectVectorChecker<Ipv6Interface> ())
66 .AddAttribute (
"SendIcmpv6Redirect",
"Send the ICMPv6 Redirect when appropriate.",
70 MakeBooleanChecker ())
71 .AddTraceSource (
"Tx",
"Send IPv6 packet to outgoing interface.",
73 .AddTraceSource (
"Rx",
"Receive IPv6 packet from incoming interface.",
75 .AddTraceSource (
"Drop",
"Drop IPv6 packet",
120 (*it)->StopValidTimer ();
121 (*it)->StopPreferredTimer ();
151 interface->SetNode (
m_node);
152 interface->SetDevice (device);
197 uint32_t max = (*it)->GetNAddresses ();
199 for (j = 0; j < max; j++)
201 if ((*it)->GetAddress (j).GetAddress () == address)
219 for (j = 0; j < (*it)->GetNAddresses (); j++)
221 if ((*it)->GetAddress (j).GetAddress ().CombinePrefix (mask) == address.
CombinePrefix (mask))
244 if ((*it)->GetDevice () == device)
255 NS_LOG_FUNCTION (
this << interface << network << mask << (uint32_t)flags << validTime << preferredTime);
260 if (flags & (1 << 6))
269 NS_FATAL_ERROR (
"Unknown method to make autoconfigured address for this kind of device.");
276 if ((*it)->GetInterface () ==
interface && (*it)->GetPrefix () == network && (*it)->GetMask () == mask)
278 (*it)->StopPreferredTimer ();
279 (*it)->StopValidTimer ();
280 (*it)->StartPreferredTimer ();
310 for (i = 0; i < max; i++)
322 if ((*it)->GetInterface () ==
interface && (*it)->GetPrefix () == network && (*it)->GetMask () == mask)
402 return interface->
IsUp ();
449 device = CreateObject<LoopbackNetDevice> ();
453 interface->SetDevice (device);
454 interface->SetNode (
m_node);
456 interface->AddAddress (ifaceAddr);
473 NS_LOG_LOGIC (
"Forwarding state: " << interface->IsForwarding ());
474 return interface->IsForwarding ();
491 (*it)->SetForwarding (forward);
519 Ptr<Node> node = this->GetObject<Node> ();
556 if ((*i)->GetProtocolNumber () == protocolNumber)
610 NS_LOG_FUNCTION (
this << packet << source << destination << (uint32_t)protocol << route);
630 NS_LOG_LOGIC (
"Ipv6L3Protocol::Send case 1: passed in with a route");
639 NS_LOG_LOGIC (
"Ipv6L3Protocol::Send case 1: probably sent to machine on same IPv6 network");
647 NS_LOG_LOGIC (
"Ipv6L3Protocol::Send case 3: passed in with no route " << destination);
682 NS_LOG_FUNCTION (
this << device << p << protocol << from << to << packetType);
684 uint32_t
interface = 0;
692 if (ipv6Interface->
GetDevice () == device)
694 if (ipv6Interface->
IsUp ())
701 NS_LOG_LOGIC (
"Dropping received packet-- interface is down");
703 packet->RemoveHeader (hdr);
712 packet->RemoveHeader (hdr);
730 bool isDropped =
false;
734 ipv6Extension = ipv6ExtensionDemux->GetExtension (nextHeader);
753 NS_LOG_WARN (
"No route found for forwarding packet. Drop.");
773 NS_LOG_LOGIC (
"Send via NetDevice ifIndex " << dev->GetIfIndex () <<
" Ipv6InterfaceIndex " << interface);
776 std::list<Ptr<Packet> > fragments;
778 if (packet->
GetSize () > (size_t)(dev->GetMtu () + 40))
787 icmpv6->SendErrorTooBig (packet, ipHeader.
GetSourceAddress (), dev->GetMtu ());
803 if (outInterface->
IsUp ())
805 NS_LOG_LOGIC (
"Send to gateway " << route->GetGateway ());
807 if (fragments.size () != 0)
809 std::ostringstream oss;
812 for (
std::list<
Ptr<Packet> >::const_iterator it = fragments.begin (); it != fragments.end (); it++)
815 outInterface->
Send (*it, route->GetGateway ());
822 outInterface->
Send (packet, route->GetGateway ());
827 NS_LOG_LOGIC (
"Dropping-- outgoing interface is down: " << route->GetGateway ());
833 if (outInterface->
IsUp ())
837 if (fragments.size () != 0)
839 std::ostringstream oss;
842 for (
std::list<
Ptr<Packet> >::const_iterator it = fragments.begin (); it != fragments.end (); it++)
871 ipHeader.SetHopLimit (ipHeader.GetHopLimit () - 1);
873 if (ipHeader.GetSourceAddress ().IsLinkLocal ())
879 if (ipHeader.GetHopLimit () == 0)
885 && ipHeader.GetDestinationAddress ().IsMulticast () ==
false)
919 if (icmpv6->Lookup (target, rtentry->GetOutputDevice (), 0, &hardwareTarget))
921 icmpv6->SendRedirection (copy, src, target, dst, hardwareTarget);
925 icmpv6->SendRedirection (copy, src, target, dst,
Address ());
937 std::map<uint32_t, uint32_t> ttlMap = mrtentry->GetOutputTtlMap ();
938 std::map<uint32_t, uint32_t>::iterator mapIter;
940 for (mapIter = ttlMap.begin (); mapIter != ttlMap.end (); mapIter++)
942 uint32_t interfaceId = mapIter->first;
953 NS_LOG_LOGIC (
"Forward multicast via interface " << interfaceId);
974 uint8_t nextHeaderPosition = 0;
975 bool isDropped =
false;
983 nextHeaderPosition = buf[1];
985 NS_ASSERT_MSG (nextHeaderPosition != 0,
"Zero-size IPv6 Option Header, aborting");
992 ipv6Extension = ipv6ExtensionDemux->GetExtension (nextHeader);
996 uint8_t nextHeaderStep = 0;
997 uint8_t curHeader = nextHeader;
998 nextHeaderStep = ipv6Extension->Process (p, nextHeaderPosition, ip, dst, &nextHeader, isDropped);
999 nextHeaderPosition += nextHeaderStep;
1006 "Zero-size IPv6 Option Header, aborting" << *packet );
1019 if (nextHeaderPosition == 0)
1060 while (ipv6Extension);
1066 NS_LOG_LOGIC (
"Route input failure-- dropping packet to " << ipHeader <<
" with errno " << sockErrno);
1072 NS_LOG_FUNCTION (
this << src << dst << (uint32_t)protocol << (uint32_t)payloadSize << (uint32_t)ttl);
1086 ipv6ExtensionDemux->SetNode (
m_node);
1089 hopbyhopExtension->SetNode (
m_node);
1091 destinationExtension->SetNode (
m_node);
1093 fragmentExtension->SetNode (
m_node);
1099 ipv6ExtensionDemux->Insert (hopbyhopExtension);
1100 ipv6ExtensionDemux->Insert (destinationExtension);
1101 ipv6ExtensionDemux->Insert (fragmentExtension);
1102 ipv6ExtensionDemux->Insert (routingExtension);
1107 routingExtensionDemux->SetNode (
m_node);
1109 looseRoutingExtension->SetNode (
m_node);
1110 routingExtensionDemux->Insert (looseRoutingExtension);
1119 ipv6OptionDemux->SetNode (
m_node);
1122 pad1Option->SetNode (
m_node);
1124 padnOption->SetNode (
m_node);
1126 jumbogramOption->SetNode (
m_node);
1128 routerAlertOption->SetNode (
m_node);
1130 ipv6OptionDemux->Insert (pad1Option);
1131 ipv6OptionDemux->Insert (padnOption);
1132 ipv6OptionDemux->Insert (jumbogramOption);
1133 ipv6OptionDemux->Insert (routerAlertOption);