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 (
"DefaultTclass",
"The TCLASS value set by default on all outgoing packets generated on this node.",
65 MakeUintegerChecker<uint8_t> ())
66 .AddAttribute (
"InterfaceList",
"The set of IPv6 interfaces associated to this IPv6 stack.",
69 MakeObjectVectorChecker<Ipv6Interface> ())
70 .AddAttribute (
"SendIcmpv6Redirect",
"Send the ICMPv6 Redirect when appropriate.",
74 MakeBooleanChecker ())
75 .AddTraceSource (
"Tx",
"Send IPv6 packet to outgoing interface.",
77 .AddTraceSource (
"Rx",
"Receive IPv6 packet from incoming interface.",
79 .AddTraceSource (
"Drop",
"Drop IPv6 packet",
124 (*it)->StopValidTimer ();
125 (*it)->StopPreferredTimer ();
155 interface->SetNode (
m_node);
156 interface->SetDevice (device);
201 uint32_t max = (*it)->GetNAddresses ();
203 for (j = 0; j < max; j++)
205 if ((*it)->GetAddress (j).GetAddress () == address)
223 for (j = 0; j < (*it)->GetNAddresses (); j++)
225 if ((*it)->GetAddress (j).GetAddress ().CombinePrefix (mask) == address.
CombinePrefix (mask))
248 if ((*it)->GetDevice () == device)
259 NS_LOG_FUNCTION (
this << interface << network << mask << (uint32_t)flags << validTime << preferredTime);
264 if (flags & (1 << 6))
273 NS_FATAL_ERROR (
"Unknown method to make autoconfigured address for this kind of device.");
280 if ((*it)->GetInterface () ==
interface && (*it)->GetPrefix () == network && (*it)->GetMask () == mask)
282 (*it)->StopPreferredTimer ();
283 (*it)->StopValidTimer ();
284 (*it)->StartPreferredTimer ();
314 for (i = 0; i < max; i++)
326 if ((*it)->GetInterface () ==
interface && (*it)->GetPrefix () == network && (*it)->GetMask () == mask)
406 return interface->
IsUp ();
453 device = CreateObject<LoopbackNetDevice> ();
457 interface->SetDevice (device);
458 interface->SetNode (
m_node);
460 interface->AddAddress (ifaceAddr);
477 NS_LOG_LOGIC (
"Forwarding state: " << interface->IsForwarding ());
478 return interface->IsForwarding ();
495 (*it)->SetForwarding (forward);
523 Ptr<Node> node = this->GetObject<Node> ();
560 if ((*i)->GetProtocolNumber () == protocolNumber)
620 NS_LOG_FUNCTION (
this << packet << source << destination << (uint32_t)protocol << route);
649 NS_LOG_LOGIC (
"Ipv6L3Protocol::Send case 1: passed in with a route");
658 NS_LOG_LOGIC (
"Ipv6L3Protocol::Send case 1: probably sent to machine on same IPv6 network");
666 NS_LOG_LOGIC (
"Ipv6L3Protocol::Send case 3: passed in with no route " << destination);
701 NS_LOG_FUNCTION (
this << device << p << protocol << from << to << packetType);
703 uint32_t
interface = 0;
711 if (ipv6Interface->
GetDevice () == device)
713 if (ipv6Interface->
IsUp ())
720 NS_LOG_LOGIC (
"Dropping received packet-- interface is down");
722 packet->RemoveHeader (hdr);
731 packet->RemoveHeader (hdr);
749 bool isDropped =
false;
753 ipv6Extension = ipv6ExtensionDemux->GetExtension (nextHeader);
772 NS_LOG_WARN (
"No route found for forwarding packet. Drop.");
792 NS_LOG_LOGIC (
"Send via NetDevice ifIndex " << dev->GetIfIndex () <<
" Ipv6InterfaceIndex " << interface);
795 std::list<Ptr<Packet> > fragments;
797 if (packet->
GetSize () > (size_t)(dev->GetMtu () + 40))
806 icmpv6->SendErrorTooBig (packet, ipHeader.
GetSourceAddress (), dev->GetMtu ());
822 if (outInterface->
IsUp ())
824 NS_LOG_LOGIC (
"Send to gateway " << route->GetGateway ());
826 if (fragments.size () != 0)
828 std::ostringstream oss;
831 for (
std::list<
Ptr<Packet> >::const_iterator it = fragments.begin (); it != fragments.end (); it++)
834 outInterface->
Send (*it, route->GetGateway ());
841 outInterface->
Send (packet, route->GetGateway ());
846 NS_LOG_LOGIC (
"Dropping-- outgoing interface is down: " << route->GetGateway ());
852 if (outInterface->
IsUp ())
856 if (fragments.size () != 0)
858 std::ostringstream oss;
861 for (
std::list<
Ptr<Packet> >::const_iterator it = fragments.begin (); it != fragments.end (); it++)
890 ipHeader.SetHopLimit (ipHeader.GetHopLimit () - 1);
892 if (ipHeader.GetSourceAddress ().IsLinkLocal ())
898 if (ipHeader.GetHopLimit () == 0)
904 && ipHeader.GetDestinationAddress ().IsMulticast () ==
false)
938 if (icmpv6->Lookup (target, rtentry->GetOutputDevice (), 0, &hardwareTarget))
940 icmpv6->SendRedirection (copy, src, target, dst, hardwareTarget);
944 icmpv6->SendRedirection (copy, src, target, dst,
Address ());
956 std::map<uint32_t, uint32_t> ttlMap = mrtentry->GetOutputTtlMap ();
957 std::map<uint32_t, uint32_t>::iterator mapIter;
959 for (mapIter = ttlMap.begin (); mapIter != ttlMap.end (); mapIter++)
961 uint32_t interfaceId = mapIter->first;
972 NS_LOG_LOGIC (
"Forward multicast via interface " << interfaceId);
993 uint8_t nextHeaderPosition = 0;
994 bool isDropped =
false;
1001 nextHeader = buf[0];
1002 nextHeaderPosition = buf[1];
1004 NS_ASSERT_MSG (nextHeaderPosition != 0,
"Zero-size IPv6 Option Header, aborting");
1011 ipv6Extension = ipv6ExtensionDemux->GetExtension (nextHeader);
1015 uint8_t nextHeaderStep = 0;
1016 uint8_t curHeader = nextHeader;
1017 nextHeaderStep = ipv6Extension->Process (p, nextHeaderPosition, ip, dst, &nextHeader, isDropped);
1018 nextHeaderPosition += nextHeaderStep;
1025 "Zero-size IPv6 Option Header, aborting" << *packet );
1038 if (nextHeaderPosition == 0)
1079 while (ipv6Extension);
1085 NS_LOG_LOGIC (
"Route input failure-- dropping packet to " << ipHeader <<
" with errno " << sockErrno);
1091 NS_LOG_FUNCTION (
this << src << dst << (uint32_t)protocol << (uint32_t)payloadSize << (uint32_t)ttl << (uint32_t)tclass);
1106 ipv6ExtensionDemux->SetNode (
m_node);
1109 hopbyhopExtension->SetNode (
m_node);
1111 destinationExtension->SetNode (
m_node);
1113 fragmentExtension->SetNode (
m_node);
1119 ipv6ExtensionDemux->Insert (hopbyhopExtension);
1120 ipv6ExtensionDemux->Insert (destinationExtension);
1121 ipv6ExtensionDemux->Insert (fragmentExtension);
1122 ipv6ExtensionDemux->Insert (routingExtension);
1127 routingExtensionDemux->SetNode (
m_node);
1129 looseRoutingExtension->SetNode (
m_node);
1130 routingExtensionDemux->Insert (looseRoutingExtension);
1139 ipv6OptionDemux->SetNode (
m_node);
1142 pad1Option->SetNode (
m_node);
1144 padnOption->SetNode (
m_node);
1146 jumbogramOption->SetNode (
m_node);
1148 routerAlertOption->SetNode (
m_node);
1150 ipv6OptionDemux->Insert (pad1Option);
1151 ipv6OptionDemux->Insert (padnOption);
1152 ipv6OptionDemux->Insert (jumbogramOption);
1153 ipv6OptionDemux->Insert (routerAlertOption);