00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef IPV4_L3_PROTOCOL_H
00022 #define IPV4_L3_PROTOCOL_H
00023
00024 #include <list>
00025 #include <stdint.h>
00026 #include "ns3/ipv4-address.h"
00027 #include "ns3/ptr.h"
00028 #include "ns3/net-device.h"
00029 #include "ns3/ipv4.h"
00030 #include "ns3/traced-callback.h"
00031 #include "ns3/ipv4-header.h"
00032 #include "ipv4-static-routing.h"
00033
00034 namespace ns3 {
00035
00036 class Packet;
00037 class NetDevice;
00038 class Ipv4Interface;
00039 class Ipv4Address;
00040 class Ipv4Header;
00041 class Ipv4Route;
00042 class Node;
00043 class Socket;
00044 class Ipv4RawSocketImpl;
00045 class Ipv4L4Protocol;
00046 class Ipv4L4Protocol;
00047 class Icmpv4L4Protocol;
00048
00049
00050
00051
00052
00053
00054
00055
00056 class Ipv4L3Protocol : public Object
00057 {
00058 public:
00059 static TypeId GetTypeId (void);
00060 static const uint16_t PROT_NUMBER;
00061
00062 Ipv4L3Protocol();
00063 virtual ~Ipv4L3Protocol ();
00064
00065 void SetNode (Ptr<Node> node);
00066
00067 Ptr<Socket> CreateRawSocket (void);
00068 void DeleteRawSocket (Ptr<Socket> socket);
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 void Insert(Ptr<Ipv4L4Protocol> protocol);
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 Ptr<Ipv4L4Protocol> GetProtocol(int protocolNumber) const;
00091
00092
00093
00094
00095
00096
00097 void Remove (Ptr<Ipv4L4Protocol> protocol);
00098
00099
00100
00101
00102
00103
00104
00105 void SetDefaultTtl (uint8_t ttl);
00106
00107
00108
00109
00110
00111
00112
00113
00114 Ptr<Ipv4Interface> FindInterfaceForDevice (Ptr<const NetDevice> device);
00115
00116
00117
00118
00119
00120
00121
00122
00123 void Receive( Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from,
00124 const Address &to, NetDevice::PacketType packetType);
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 void Send (Ptr<Packet> packet, Ipv4Address source,
00136 Ipv4Address destination, uint8_t protocol);
00137
00138
00139
00140 void AddHostRouteTo (Ipv4Address dest,
00141 Ipv4Address nextHop,
00142 uint32_t interface);
00143 void AddHostRouteTo (Ipv4Address dest,
00144 uint32_t interface);
00145
00146 void AddNetworkRouteTo (Ipv4Address network,
00147 Ipv4Mask networkMask,
00148 Ipv4Address nextHop,
00149 uint32_t interface);
00150 void AddNetworkRouteTo (Ipv4Address network,
00151 Ipv4Mask networkMask,
00152 uint32_t interface);
00153 void SetDefaultRoute (Ipv4Address nextHop,
00154 uint32_t interface);
00155
00156 void Lookup (Ipv4Header const &ipHeader,
00157 Ptr<Packet> packet,
00158 Ipv4RoutingProtocol::RouteReplyCallback routeReply);
00159
00160 uint32_t GetNRoutes (void);
00161 Ipv4Route *GetRoute (uint32_t i);
00162 void RemoveRoute (uint32_t i);
00163
00164 void AddMulticastRoute (Ipv4Address origin,
00165 Ipv4Address group,
00166 uint32_t inputInterface,
00167 std::vector<uint32_t> outputInterfaces);
00168
00169 void SetDefaultMulticastRoute (uint32_t onputInterface);
00170
00171 uint32_t GetNMulticastRoutes (void) const;
00172 Ipv4MulticastRoute *GetMulticastRoute (uint32_t i) const;
00173
00174 void RemoveMulticastRoute (Ipv4Address origin,
00175 Ipv4Address group,
00176 uint32_t inputInterface);
00177 void RemoveMulticastRoute (uint32_t i);
00178
00179 uint32_t AddInterface (Ptr<NetDevice> device);
00180 Ptr<Ipv4Interface> GetInterface (uint32_t i) const;
00181 uint32_t GetNInterfaces (void) const;
00182
00183 uint32_t FindInterfaceForAddr (Ipv4Address addr) const;
00184 uint32_t FindInterfaceForAddr (Ipv4Address addr, Ipv4Mask mask) const;
00185 int32_t FindInterfaceIndexForDevice (Ptr<NetDevice> device) const;
00186
00187 void JoinMulticastGroup (Ipv4Address origin, Ipv4Address group);
00188 void LeaveMulticastGroup (Ipv4Address origin, Ipv4Address group);
00189
00190 void SetAddress (uint32_t i, Ipv4Address address);
00191 void SetNetworkMask (uint32_t i, Ipv4Mask mask);
00192 Ipv4Mask GetNetworkMask (uint32_t t) const;
00193 Ipv4Address GetAddress (uint32_t i) const;
00194 void SetMetric (uint32_t i, uint16_t metric);
00195 uint16_t GetMetric (uint32_t i) const;
00196 bool GetIfIndexForDestination (Ipv4Address destination,
00197 uint32_t& ifIndex) const;
00198 uint16_t GetMtu (uint32_t i) const;
00199 bool IsUp (uint32_t i) const;
00200 void SetUp (uint32_t i);
00201 void SetDown (uint32_t i);
00202
00203 void AddRoutingProtocol (Ptr<Ipv4RoutingProtocol> routingProtocol,
00204 int priority);
00205
00206 protected:
00207
00208 virtual void DoDispose (void);
00209
00210 private:
00211 Ipv4L3Protocol(const Ipv4L3Protocol &);
00212 Ipv4L3Protocol &operator = (const Ipv4L3Protocol &);
00213 void Lookup (uint32_t ifIndex,
00214 Ipv4Header const &ipHeader,
00215 Ptr<Packet> packet,
00216 Ipv4RoutingProtocol::RouteReplyCallback routeReply);
00217
00218 void SendRealOut (bool found,
00219 Ipv4Route const &route,
00220 Ptr<Packet> packet,
00221 Ipv4Header const &ipHeader);
00222 bool Forwarding (uint32_t ifIndex,
00223 Ptr<Packet> packet,
00224 Ipv4Header &ipHeader,
00225 Ptr<NetDevice> device);
00226 void ForwardUp (Ptr<Packet> p, Ipv4Header const&ip, Ptr<Ipv4Interface> incomingInterface);
00227 uint32_t AddIpv4Interface (Ptr<Ipv4Interface> interface);
00228 void SetupLoopback (void);
00229 Ptr<Icmpv4L4Protocol> GetIcmp (void) const;
00230 bool IsUnicast (Ipv4Address ad, Ipv4Mask interfaceMask) const;
00231 void DoForward (uint32_t ifIndex,
00232 Ptr<Packet> packet,
00233 Ipv4Header ipHeader);
00234
00235
00236 typedef std::list<Ptr<Ipv4Interface> > Ipv4InterfaceList;
00237 typedef std::list<std::pair<Ipv4Address, Ipv4Address> > Ipv4MulticastGroupList;
00238 typedef std::list< std::pair< int, Ptr<Ipv4RoutingProtocol> > > Ipv4RoutingProtocolList;
00239 typedef std::list<Ptr<Ipv4RawSocketImpl> > SocketList;
00240 typedef std::list<Ptr<Ipv4L4Protocol> > L4List_t;
00241
00242 L4List_t m_protocols;
00243 Ipv4InterfaceList m_interfaces;
00244 uint32_t m_nInterfaces;
00245 uint8_t m_defaultTtl;
00246 bool m_calcChecksum;
00247 uint16_t m_identification;
00248 Ptr<Node> m_node;
00249 TracedCallback<Ptr<const Packet>, uint32_t> m_txTrace;
00250 TracedCallback<Ptr<const Packet>, uint32_t> m_rxTrace;
00251 TracedCallback<Ptr<const Packet> > m_dropTrace;
00252
00253 Ipv4RoutingProtocolList m_routingProtocols;
00254
00255 Ptr<Ipv4StaticRouting> m_staticRouting;
00256 Ipv4MulticastGroupList m_multicastGroups;
00257
00258 SocketList m_sockets;
00259 };
00260
00261 }
00262
00263 #endif