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"
31 #include "ns3/mac16-address.h"
32 #include "ns3/mac64-address.h"
48 #define IPV6_MIN_MTU 1280
62 .AddConstructor<Ipv6L3Protocol> ()
63 .AddAttribute (
"DefaultTtl",
"The TTL value set by default on all outgoing packets generated on this node.",
66 MakeUintegerChecker<uint8_t> ())
67 .AddAttribute (
"DefaultTclass",
"The TCLASS value set by default on all outgoing packets generated on this node.",
70 MakeUintegerChecker<uint8_t> ())
71 .AddAttribute (
"InterfaceList",
"The set of IPv6 interfaces associated to this IPv6 stack.",
74 MakeObjectVectorChecker<Ipv6Interface> ())
75 .AddAttribute (
"SendIcmpv6Redirect",
"Send the ICMPv6 Redirect when appropriate.",
79 MakeBooleanChecker ())
80 .AddTraceSource (
"Tx",
"Send IPv6 packet to outgoing interface.",
82 .AddTraceSource (
"Rx",
"Receive IPv6 packet from incoming interface.",
84 .AddTraceSource (
"Drop",
"Drop IPv6 packet",
130 (*it)->StopValidTimer ();
131 (*it)->StopPreferredTimer ();
162 interface->SetNode (
m_node);
163 interface->SetDevice (device);
208 uint32_t max = (*it)->GetNAddresses ();
210 for (j = 0; j < max; j++)
212 if ((*it)->GetAddress (j).GetAddress () ==
address)
230 for (j = 0; j < (*it)->GetNAddresses (); j++)
232 if ((*it)->GetAddress (j).GetAddress ().CombinePrefix (mask) == address.
CombinePrefix (mask))
255 if ((*it)->GetDevice () == device)
266 NS_LOG_FUNCTION (
this << interface << network << mask << (uint32_t)flags << validTime << preferredTime);
271 if (flags & (1 << 6))
288 NS_FATAL_ERROR (
"Unknown method to make autoconfigured address for this kind of device.");
295 if ((*it)->GetInterface () ==
interface && (*it)->GetPrefix () == network && (*it)->GetMask () == mask)
297 (*it)->StopPreferredTimer ();
298 (*it)->StopValidTimer ();
299 (*it)->StartPreferredTimer ();
311 if (!defaultRouter.
IsAny())
346 NS_FATAL_ERROR (
"Unknown method to make autoconfigured address for this kind of device.");
350 for (i = 0; i < max; i++)
362 if ((*it)->GetInterface () ==
interface && (*it)->GetPrefix () == network && (*it)->GetMask () == mask)
479 return interface->
IsUp ();
526 device = CreateObject<LoopbackNetDevice> ();
530 interface->SetDevice (device);
531 interface->SetNode (
m_node);
533 interface->AddAddress (ifaceAddr);
550 NS_LOG_LOGIC (
"Forwarding state: " << interface->IsForwarding ());
551 return interface->IsForwarding ();
568 (*it)->SetForwarding (forward);
608 Ptr<Node> node = this->GetObject<Node> ();
645 if ((*i)->GetProtocolNumber () == protocolNumber)
705 NS_LOG_FUNCTION (
this << packet << source << destination << (uint32_t)protocol << route);
734 NS_LOG_LOGIC (
"Ipv6L3Protocol::Send case 1: passed in with a route");
743 NS_LOG_LOGIC (
"Ipv6L3Protocol::Send case 1: probably sent to machine on same IPv6 network");
751 NS_LOG_LOGIC (
"Ipv6L3Protocol::Send case 3: passed in with no route " << destination);
786 NS_LOG_FUNCTION (
this << device << p << protocol << from << to << packetType);
788 uint32_t
interface = 0;
796 if (ipv6Interface->
GetDevice () == device)
798 if (ipv6Interface->
IsUp ())
805 NS_LOG_LOGIC (
"Dropping received packet-- interface is down");
807 packet->RemoveHeader (hdr);
816 packet->RemoveHeader (hdr);
834 bool isDropped =
false;
838 ipv6Extension = ipv6ExtensionDemux->GetExtension (nextHeader);
857 NS_LOG_WARN (
"No route found for forwarding packet. Drop.");
877 NS_LOG_LOGIC (
"Send via NetDevice ifIndex " << dev->GetIfIndex () <<
" Ipv6InterfaceIndex " << interface);
880 std::list<Ptr<Packet> > fragments;
886 targetMtu = dev->GetMtu ();
889 if (packet->
GetSize () > targetMtu + 40)
911 icmpv6->SendErrorTooBig (packet, ipHeader.
GetSourceAddress (), dev->GetMtu ());
923 ipv6Fragment->
GetFragments (packet, targetMtu, fragments);
928 if (outInterface->
IsUp ())
930 NS_LOG_LOGIC (
"Send to gateway " << route->GetGateway ());
932 if (fragments.size () != 0)
934 std::ostringstream oss;
937 for (
std::list<
Ptr<Packet> >::const_iterator it = fragments.begin (); it != fragments.end (); it++)
940 outInterface->
Send (*it, route->GetGateway ());
947 outInterface->
Send (packet, route->GetGateway ());
952 NS_LOG_LOGIC (
"Dropping-- outgoing interface is down: " << route->GetGateway ());
958 if (outInterface->
IsUp ())
962 if (fragments.size () != 0)
964 std::ostringstream oss;
967 for (
std::list<
Ptr<Packet> >::const_iterator it = fragments.begin (); it != fragments.end (); it++)
996 NS_LOG_WARN (
"Received a packet for 2001:db8::/32 (documentation class). Drop.");
1048 if (target.
IsAny ())
1056 if (icmpv6->Lookup (target, rtentry->GetOutputDevice (), 0, &hardwareTarget))
1058 icmpv6->SendRedirection (copy, linkLocal, src, target, dst, hardwareTarget);
1062 icmpv6->SendRedirection (copy, linkLocal, src, target, dst,
Address ());
1074 std::map<uint32_t, uint32_t> ttlMap = mrtentry->GetOutputTtlMap ();
1075 std::map<uint32_t, uint32_t>::iterator mapIter;
1077 for (mapIter = ttlMap.begin (); mapIter != ttlMap.end (); mapIter++)
1079 uint32_t interfaceId = mapIter->first;
1090 NS_LOG_LOGIC (
"Forward multicast via interface " << interfaceId);
1111 uint8_t nextHeaderPosition = 0;
1112 bool isDropped =
false;
1122 NS_LOG_WARN(
"Double Ipv6Header::IPV6_EXT_HOP_BY_HOP in packet, dropping packet");
1131 ipv6Extension = ipv6ExtensionDemux->GetExtension (nextHeader);
1135 uint8_t nextHeaderStep = 0;
1136 uint8_t curHeader = nextHeader;
1137 nextHeaderStep = ipv6Extension->Process (p, nextHeaderPosition, ip, dst, &nextHeader, isDropped);
1138 nextHeaderPosition += nextHeaderStep;
1145 "Zero-size IPv6 Option Header, aborting" << *packet );
1158 if (nextHeaderPosition == 0)
1199 while (ipv6Extension);
1205 NS_LOG_LOGIC (
"Route input failure-- dropping packet to " << ipHeader <<
" with errno " << sockErrno);
1211 NS_LOG_FUNCTION (
this << src << dst << (uint32_t)protocol << (uint32_t)payloadSize << (uint32_t)ttl << (uint32_t)tclass);
1226 ipv6ExtensionDemux->SetNode (
m_node);
1229 hopbyhopExtension->SetNode (
m_node);
1231 destinationExtension->SetNode (
m_node);
1233 fragmentExtension->SetNode (
m_node);
1239 ipv6ExtensionDemux->Insert (hopbyhopExtension);
1240 ipv6ExtensionDemux->Insert (destinationExtension);
1241 ipv6ExtensionDemux->Insert (fragmentExtension);
1242 ipv6ExtensionDemux->Insert (routingExtension);
1247 routingExtensionDemux->SetNode (
m_node);
1249 looseRoutingExtension->SetNode (
m_node);
1250 routingExtensionDemux->Insert (looseRoutingExtension);
1259 ipv6OptionDemux->SetNode (
m_node);
1262 pad1Option->SetNode (
m_node);
1264 padnOption->SetNode (
m_node);
1266 jumbogramOption->SetNode (
m_node);
1268 routerAlertOption->SetNode (
m_node);
1270 ipv6OptionDemux->Insert (pad1Option);
1271 ipv6OptionDemux->Insert (padnOption);
1272 ipv6OptionDemux->Insert (jumbogramOption);
1273 ipv6OptionDemux->Insert (routerAlertOption);