|
1 // -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- |
|
2 // |
|
3 // Copyright (c) 2006 Georgia Tech Research Corporation |
|
4 // All rights reserved. |
|
5 // |
|
6 // This program is free software; you can redistribute it and/or modify |
|
7 // it under the terms of the GNU General Public License version 2 as |
|
8 // published by the Free Software Foundation; |
|
9 // |
|
10 // This program is distributed in the hope that it will be useful, |
|
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 // GNU General Public License for more details. |
|
14 // |
|
15 // You should have received a copy of the GNU General Public License |
|
16 // along with this program; if not, write to the Free Software |
|
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 // |
|
19 // Author: George F. Riley<riley@ece.gatech.edu> |
|
20 // |
|
21 |
|
22 #ifndef IPV4_L3_PROTOCOL_H |
|
23 #define IPV4_L3_PROTOCOL_H |
|
24 |
|
25 #include <list> |
|
26 #include <stdint.h> |
|
27 #include "l3-protocol.h" |
|
28 #include "ipv4-address.h" |
|
29 |
|
30 namespace ns3 { |
|
31 |
|
32 class Packet; |
|
33 class NetDevice; |
|
34 class Ipv4Interface; |
|
35 class Ipv4Address; |
|
36 class Ipv4Header; |
|
37 class Ipv4Route; |
|
38 class Node; |
|
39 |
|
40 |
|
41 /** |
|
42 * ::Send is always defined in subclasses. |
|
43 */ |
|
44 class Ipv4L3Protocol : public L3Protocol { |
|
45 public: |
|
46 Ipv4L3Protocol(); |
|
47 Ipv4L3Protocol(Ipv4L3Protocol const &o); |
|
48 virtual ~Ipv4L3Protocol (); |
|
49 |
|
50 void SetDefaultTtl (uint8_t ttl); |
|
51 |
|
52 /* add route to host dest through host nextHop |
|
53 * on interface. |
|
54 */ |
|
55 void AddHostRouteTo (Ipv4Address dest, |
|
56 Ipv4Address nextHop, |
|
57 uint32_t interface); |
|
58 /* add route to host dest on interface. |
|
59 */ |
|
60 void AddHostRouteTo (Ipv4Address dest, |
|
61 uint32_t interface); |
|
62 /* add route to network dest with netmask |
|
63 * through host nextHop on interface |
|
64 */ |
|
65 void AddNetworkRouteTo (Ipv4Address network, |
|
66 Ipv4Mask networkMask, |
|
67 Ipv4Address nextHop, |
|
68 uint32_t interface); |
|
69 /* add route to network dest with netmask |
|
70 * on interface |
|
71 */ |
|
72 void AddNetworkRouteTo (Ipv4Address network, |
|
73 Ipv4Mask networkMask, |
|
74 uint32_t interface); |
|
75 /* set the default route to host nextHop on |
|
76 * interface. |
|
77 */ |
|
78 void SetDefaultRoute (Ipv4Address nextHop, |
|
79 uint32_t interface); |
|
80 |
|
81 Ipv4Route *Lookup (Ipv4Address dest); |
|
82 |
|
83 uint32_t GetNRoutes (void); |
|
84 Ipv4Route *GetRoute (uint32_t i); |
|
85 void RemoveRoute (uint32_t i); |
|
86 |
|
87 uint32_t AddInterface (Ipv4Interface *interface); |
|
88 Ipv4Interface * GetInterface (uint32_t i); |
|
89 uint32_t GetNInterfaces (void) const; |
|
90 |
|
91 |
|
92 virtual Ipv4L3Protocol* Copy() const; |
|
93 /** |
|
94 * Lower layer calls this method after calling L3Demux::Lookup |
|
95 * The ARP subclass needs to know from which NetDevice this |
|
96 * packet is coming to: |
|
97 * - implement a per-NetDevice ARP cache |
|
98 * - send back arp replies on the right device |
|
99 */ |
|
100 virtual void Receive(Packet& p, NetDevice &device); |
|
101 |
|
102 private: |
|
103 void Send (Packet const &packet, Ipv4Address source, |
|
104 Ipv4Address destination, uint8_t protocol); |
|
105 void SendRealOut (Packet const &packet, Ipv4Header const &ip, Ipv4Route const &route); |
|
106 bool Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice &device); |
|
107 void ForwardUp (Packet p, Ipv4Header const&ip); |
|
108 |
|
109 typedef std::list<Ipv4Interface*> Ipv4InterfaceList; |
|
110 typedef std::list<Ipv4Route *> HostRoutes; |
|
111 typedef std::list<Ipv4Route *>::const_iterator HostRoutesCI; |
|
112 typedef std::list<Ipv4Route *>::iterator HostRoutesI; |
|
113 typedef std::list<Ipv4Route *> NetworkRoutes; |
|
114 typedef std::list<Ipv4Route *>::const_iterator NetworkRoutesCI; |
|
115 typedef std::list<Ipv4Route *>::iterator NetworkRoutesI; |
|
116 |
|
117 Ipv4InterfaceList m_interfaces; |
|
118 uint32_t m_nInterfaces; |
|
119 uint8_t m_defaultTtl; |
|
120 uint16_t m_identification; |
|
121 HostRoutes m_hostRoutes; |
|
122 NetworkRoutes m_networkRoutes; |
|
123 Ipv4Route *m_defaultRoute; |
|
124 Node *m_node; |
|
125 }; |
|
126 |
|
127 } // Namespace ns3 |
|
128 |
|
129 #endif |