A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ipv4-l3-click-protocol.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 //
3 // Copyright (c) 2006 Georgia Tech Research Corporation
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License version 2 as
7 // published by the Free Software Foundation;
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 //
18 // Author: George F. Riley <riley@ece.gatech.edu>
19 // Author: Lalith Suresh <suresh.lalith@gmail.com>
20 //
21 
22 #ifndef IPV4_L3_CLICK_PROTOCOL_H
23 #define IPV4_L3_CLICK_PROTOCOL_H
24 
25 #include "ns3/ipv4.h"
26 #include "ns3/net-device.h"
27 #include "ns3/packet.h"
28 #include "ns3/ipv4-routing-protocol.h"
29 #include "ns3/traced-callback.h"
30 #include "ns3/ipv4-interface.h"
31 #include "ns3/log.h"
32 
33 namespace ns3 {
34 
35 class Packet;
36 class NetDevice;
37 class Ipv4Interface;
38 class Ipv4Address;
39 class Ipv4Header;
40 class Ipv4RoutingTableEntry;
41 class Ipv4Route;
42 class Node;
43 class Socket;
44 class Ipv4RawSocketImpl;
45 class IpL4Protocol;
46 class Icmpv4L4Protocol;
47 
61 class Ipv4L3ClickProtocol : public Ipv4
62 {
63 #ifdef NS3_CLICK
64 public:
65  static TypeId GetTypeId (void);
66 
70  static const uint16_t PROT_NUMBER;
71 
73  virtual ~Ipv4L3ClickProtocol ();
74 
85  void Insert (Ptr<IpL4Protocol> protocol);
86 
95  Ptr<IpL4Protocol> GetProtocol (int protocolNumber) const;
96 
103  void SetDefaultTtl (uint8_t ttl);
104 
115  void Send (Ptr<Packet> packet, Ipv4Address source,
116  Ipv4Address destination, uint8_t protocol, Ptr<Ipv4Route> route);
117 
126  void SendWithHeader (Ptr<Packet> packet, Ipv4Header ipHeader, Ptr<Ipv4Route> route);
127 
135  void SendDown (Ptr<Packet> packet, int ifid);
136 
146  void Receive ( Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from,
147  const Address &to, NetDevice::PacketType packetType);
148 
155  void LocalDeliver (Ptr<const Packet> p, Ipv4Header const&ip, uint32_t iif);
156 
162  Ptr<Ipv4Interface> GetInterface (uint32_t i) const;
163 
169  uint32_t AddIpv4Interface (Ptr<Ipv4Interface> interface);
170 
175  void SetNode (Ptr<Node> node);
176 
181  Ptr<Icmpv4L4Protocol> GetIcmp (void) const;
182 
186  void SetupLoopback (void);
187 
193 
198  void DeleteRawSocket (Ptr<Socket> socket);
199 
200  // functions defined in base class Ipv4
201  void SetRoutingProtocol (Ptr<Ipv4RoutingProtocol> routingProtocol);
203 
204  Ptr<NetDevice> GetNetDevice (uint32_t i);
205 
206  uint32_t AddInterface (Ptr<NetDevice> device);
207  uint32_t GetNInterfaces (void) const;
208 
209  int32_t GetInterfaceForAddress (Ipv4Address addr) const;
210  int32_t GetInterfaceForPrefix (Ipv4Address addr, Ipv4Mask mask) const;
211  int32_t GetInterfaceForDevice (Ptr<const NetDevice> device) const;
212  bool IsDestinationAddress (Ipv4Address address, uint32_t iif) const;
213 
214  bool AddAddress (uint32_t i, Ipv4InterfaceAddress address);
215  Ipv4InterfaceAddress GetAddress (uint32_t interfaceIndex, uint32_t addressIndex) const;
216  uint32_t GetNAddresses (uint32_t interface) const;
217  bool RemoveAddress (uint32_t interfaceIndex, uint32_t addressIndex);
220 
221  void SetMetric (uint32_t i, uint16_t metric);
222  uint16_t GetMetric (uint32_t i) const;
223  uint16_t GetMtu (uint32_t i) const;
224  bool IsUp (uint32_t i) const;
225  void SetUp (uint32_t i);
226  void SetDown (uint32_t i);
227  bool IsForwarding (uint32_t i) const;
228  void SetForwarding (uint32_t i, bool val);
229  void SetPromisc (uint32_t i);
230 protected:
231  virtual void DoDispose (void);
236  virtual void NotifyNewAggregate ();
237 
238 private:
239  Ipv4Header BuildHeader (
240  Ipv4Address source,
241  Ipv4Address destination,
242  uint8_t protocol,
243  uint16_t payloadSize,
244  uint8_t ttl,
245  bool mayFragment);
246 
247  virtual void SetIpForward (bool forward);
248  virtual bool GetIpForward (void) const;
249  virtual void SetWeakEsModel (bool model);
250  virtual bool GetWeakEsModel (void) const;
251 
252  typedef std::vector<Ptr<Ipv4Interface> > Ipv4InterfaceList;
253  typedef std::list<Ptr<Ipv4RawSocketImpl> > SocketList;
254  typedef std::list<Ptr<IpL4Protocol> > L4List_t;
255 
256  Ptr<Ipv4RoutingProtocol> m_routingProtocol;
257  bool m_ipForward;
258  bool m_weakEsModel;
259  L4List_t m_protocols;
260  Ipv4InterfaceList m_interfaces;
261  uint8_t m_defaultTtl;
262  uint16_t m_identification;
263 
264  Ptr<Node> m_node;
265 
266  TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_sendOutgoingTrace;
267  TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_unicastForwardTrace;
268  TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_localDeliverTrace;
269 
270  SocketList m_sockets;
271 
272  std::vector<bool> m_promiscDeviceList;
273 
274 #endif /* NS3_CLICK */
275 };
276 
277 } // namespace ns3
278 
279 #endif /* IPV4_L3_CLICK_ROUTING_H */