1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2004 Francisco J. Ros
4  * Copyright (c) 2007 INESC Porto
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  * Authors: Francisco J. Ros  <fjrm@dif.um.es>
20  *          Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
21  */
22 
23 
24 #ifndef OLSR_REPOSITORIES_H
25 #define OLSR_REPOSITORIES_H
26 
27 #include <set>
28 #include <vector>
29 
30 #include "ns3/ipv4-address.h"
31 #include "ns3/nstime.h"
32 
33 namespace ns3 {
34 namespace olsr {
35 
36 
37 /// \ingroup olsr
38 /// An Interface Association Tuple.
39 struct IfaceAssocTuple
40 {
41   /// Interface address of a node.
42   Ipv4Address ifaceAddr;
43   /// Main address of the node.
44   Ipv4Address mainAddr;
45   /// Time at which this tuple expires and must be removed.
46   Time time;
47 };
48 
49 static inline bool
50 operator == (const IfaceAssocTuple &a, const IfaceAssocTuple &b)
51 {
52   return (a.ifaceAddr == b.ifaceAddr
53           && a.mainAddr == b.mainAddr);
54 }
55 
56 static inline std::ostream&
57 operator << (std::ostream &os, const IfaceAssocTuple &tuple)
58 {
59   os << "IfaceAssocTuple(ifaceAddr=" << tuple.ifaceAddr
60      << ", mainAddr=" << tuple.mainAddr
61      << ", time=" << tuple.time << ")";
62   return os;
63 }
64 
65 /// \ingroup olsr
66 /// A Link Tuple.
67 struct LinkTuple
68 {
69   /// Interface address of the local node.
70   Ipv4Address localIfaceAddr;
71   /// Interface address of the neighbor node.
72   Ipv4Address neighborIfaceAddr;
73   /// The link is considered bidirectional until this time.
74   Time symTime;
75   /// The link is considered unidirectional until this time.
76   Time asymTime;
77   /// Time at which this tuple expires and must be removed.
78   Time time;
79 };
80 
81 static inline bool
82 operator == (const LinkTuple &a, const LinkTuple &b)
83 {
84   return (a.localIfaceAddr == b.localIfaceAddr
85           && a.neighborIfaceAddr == b.neighborIfaceAddr);
86 }
87 
88 static inline std::ostream&
89 operator << (std::ostream &os, const LinkTuple &tuple)
90 {
91   os << "LinkTuple(localIfaceAddr=" << tuple.localIfaceAddr
92      << ", neighborIfaceAddr=" << tuple.neighborIfaceAddr
93      << ", symTime=" << tuple.symTime
94      << ", asymTime=" << tuple.asymTime
95      << ", expTime=" << tuple.time
96      << ")";
97   return os;
98 }
99 
100 /// \ingroup olsr
101 /// A Neighbor Tuple.
102 struct NeighborTuple
103 {
104   /// Main address of a neighbor node.
105   Ipv4Address neighborMainAddr;
106   /// Status of the link (Symmetric or not Symmetric).
107   enum Status
108   {
109     STATUS_NOT_SYM = 0, // "not symmetric"
110     STATUS_SYM = 1, // "symmetric"
111   } status; //!< Status of the link.
112   /// A value between 0 and 7 specifying the node's willingness to carry traffic on behalf of other nodes.
113   uint8_t willingness;
114 };
115 
116 static inline bool
117 operator == (const NeighborTuple &a, const NeighborTuple &b)
118 {
119   return (a.neighborMainAddr == b.neighborMainAddr
120           && a.status == b.status
121           && a.willingness == b.willingness);
122 }
123 
124 static inline std::ostream&
125 operator << (std::ostream &os, const NeighborTuple &tuple)
126 {
127   os << "NeighborTuple(neighborMainAddr=" << tuple.neighborMainAddr
128      << ", status=" << (tuple.status == NeighborTuple::STATUS_SYM ? "SYM" : "NOT_SYM")
129      << ", willingness=" << (int) tuple.willingness << ")";
130   return os;
131 }
132 
133 /// \ingroup olsr
134 /// A 2-hop Tuple.
135 struct TwoHopNeighborTuple
136 {
137   /// Main address of a neighbor.
138   Ipv4Address neighborMainAddr;
139   /// Main address of a 2-hop neighbor with a symmetric link to nb_main_addr.
140   Ipv4Address twoHopNeighborAddr;
141   /// Time at which this tuple expires and must be removed.
142   Time expirationTime; // previously called 'time_'
143 };
144 
145 static inline std::ostream&
146 operator << (std::ostream &os, const TwoHopNeighborTuple &tuple)
147 {
148   os << "TwoHopNeighborTuple(neighborMainAddr=" << tuple.neighborMainAddr
149      << ", twoHopNeighborAddr=" << tuple.twoHopNeighborAddr
150      << ", expirationTime=" << tuple.expirationTime
151      << ")";
152   return os;
153 }
154 
155 static inline bool
156 operator == (const TwoHopNeighborTuple &a, const TwoHopNeighborTuple &b)
157 {
158   return (a.neighborMainAddr == b.neighborMainAddr
159           && a.twoHopNeighborAddr == b.twoHopNeighborAddr);
160 }
161 
162 /// \ingroup olsr
163 /// An MPR-Selector Tuple.
164 struct MprSelectorTuple
165 {
166   /// Main address of a node which have selected this node as a MPR.
167   Ipv4Address mainAddr;
168   /// Time at which this tuple expires and must be removed.
169   Time expirationTime; // previously called 'time_'
170 };
171 
172 static inline bool
173 operator == (const MprSelectorTuple &a, const MprSelectorTuple &b)
174 {
175   return (a.mainAddr == b.mainAddr);
176 }
177 
178 
179 // The type "list of interface addresses"
180 //typedef std::vector<nsaddr_t> addr_list_t;
181 
182 /// \ingroup olsr
183 /// A Duplicate Tuple
184 struct DuplicateTuple
185 {
186   /// Originator address of the message.
187   Ipv4Address address;
188   /// Message sequence number.
189   uint16_t sequenceNumber;
190   /// Indicates whether the message has been retransmitted or not.
191   bool retransmitted;
192   /// List of interfaces which the message has been received on.
193   std::vector<Ipv4Address> ifaceList;
194   /// Time at which this tuple expires and must be removed.
195   Time expirationTime;
196 };
197 
198 static inline bool
199 operator == (const DuplicateTuple &a, const DuplicateTuple &b)
200 {
201   return (a.address == b.address
202           && a.sequenceNumber == b.sequenceNumber);
203 }
204 
205 /// \ingroup olsr
206 /// A Topology Tuple
207 struct TopologyTuple
208 {
209   /// Main address of the destination.
210   Ipv4Address destAddr;
211   /// Main address of a node which is a neighbor of the destination.
212   Ipv4Address lastAddr;
213   /// Sequence number.
214   uint16_t sequenceNumber;
215   /// Time at which this tuple expires and must be removed.
216   Time expirationTime;
217 };
218 
219 static inline bool
220 operator == (const TopologyTuple &a, const TopologyTuple &b)
221 {
222   return (a.destAddr == b.destAddr
223           && a.lastAddr == b.lastAddr
224           && a.sequenceNumber == b.sequenceNumber);
225 }
226 
227 static inline std::ostream&
228 operator << (std::ostream &os, const TopologyTuple &tuple)
229 {
230   os << "TopologyTuple(destAddr=" << tuple.destAddr
231      << ", lastAddr=" << tuple.lastAddr
232      << ", sequenceNumber=" << (int) tuple.sequenceNumber
233      << ", expirationTime=" << tuple.expirationTime
234      << ")";
235   return os;
236 }
237 
238 /// \ingroup olsr
239 /// Association
240 struct Association
241 {
242   Ipv4Address networkAddr; //!< IPv4 Network address.
243   Ipv4Mask netmask;        //!< IPv4 Network mask.
244 };
245 
246 static inline bool
247 operator == (const Association &a, const Association &b)
248 {
249   return (a.networkAddr == b.networkAddr
250           && a.netmask == b.netmask);
251 }
252 
253 static inline std::ostream&
254 operator << (std::ostream &os, const Association &tuple)
255 {
256   os << "Association(networkAddr=" << tuple.networkAddr
257      << ", netmask=" << tuple.netmask
258      << ")";
259   return os;
260 }
261 
262 /// \ingroup olsr
263 /// An Association Tuple
264 struct AssociationTuple
265 {
266   /// Main address of the gateway.
267   Ipv4Address gatewayAddr;
268   /// Network Address of network reachable through gatewayAddr
269   Ipv4Address networkAddr;
270   /// Netmask of network reachable through gatewayAddr
271   Ipv4Mask netmask;
272   /// Time at which this tuple expires and must be removed
273   Time expirationTime;
274 };
275 
276 static inline bool
277 operator == (const AssociationTuple &a, const AssociationTuple &b)
278 {
279   return (a.gatewayAddr == b.gatewayAddr
280           && a.networkAddr == b.networkAddr
281           && a.netmask == b.netmask);
282 }
283 
284 static inline std::ostream&
285 operator << (std::ostream &os, const AssociationTuple &tuple)
286 {
287   os << "AssociationTuple(gatewayAddr=" << tuple.gatewayAddr
288      << ", networkAddr=" << tuple.networkAddr
289      << ", netmask=" << tuple.netmask
290      << ", expirationTime=" << tuple.expirationTime
291      << ")";
292   return os;
293 }
294 
295 
296 typedef std::set<Ipv4Address>                   MprSet; //!< MPR Set type.
297 typedef std::vector<MprSelectorTuple>           MprSelectorSet; //!< MPR Selector Set type.
298 typedef std::vector<LinkTuple>                  LinkSet; //!< Link Set type.
299 typedef std::vector<NeighborTuple>              NeighborSet; //!< Neighbor Set type.
300 typedef std::vector<TwoHopNeighborTuple>        TwoHopNeighborSet; //!< 2-hop Neighbor Set type.
301 typedef std::vector<TopologyTuple>              TopologySet; //!< Topology Set type.
302 typedef std::vector<DuplicateTuple>             DuplicateSet; //!< Duplicate Set type.
303 typedef std::vector<IfaceAssocTuple>            IfaceAssocSet; //!< Interface Association Set type.
304 typedef std::vector<AssociationTuple>           AssociationSet; //!< Association Set type.
305 typedef std::vector<Association>                Associations; //!< Association Set type.
306 
307 
308 }
309 }  // namespace ns3, olsr
310 
311 #endif /* OLSR_REPOSITORIES_H */
312