blob: 1ae8713ac7d60214a6379933108727959c86c8d7 [file] [log] [blame]
Alexander Afanasyev3875a4b2011-11-10 11:55:53 -08001// -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*-
2//
3// Copyright (c) 2008 University of Washington
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//
19
20#ifndef IPV4_GLOBAL_ROUTING_ORDERED_NEXTHOPS_H
21#define IPV4_GLOBAL_ROUTING_ORDERED_NEXTHOPS_H
22
23#include "ns3/ipv4-global-routing.h"
24#include "ns3/trie.h"
25#include "ns3/ipv4-routing-table-entry.h"
26#include "ns3/simple-ref-count.h"
27
28#include <boost/multi_index_container.hpp>
29#include <boost/multi_index/tag.hpp>
30#include <boost/multi_index/ordered_index.hpp>
31#include <boost/multi_index/mem_fun.hpp>
32#include <boost/multi_index/random_access_index.hpp>
33#include <boost/multi_index/sequenced_index.hpp>
34
35namespace ns3 {
36
37/**
38 * \brief Global routing protocol for IP version 4 stacks.
39 *
40 * Each prefix entry stores a list of ordered by metric next-hops
41 *
42 * This class deals with Ipv4 unicast routes only.
43 *
44 * \see Ipv4GlobalRouting
45 * \see Ipv4RoutingProtocol
46 * \see GlobalRouteManager
47 */
48class Ipv4GlobalRoutingOrderedNexthops : public Ipv4GlobalRouting
49{
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -080050public:
Alexander Afanasyev3875a4b2011-11-10 11:55:53 -080051 class i_iface {};
52 class i_metric {};
53 class i_index {};
54
55 class EntryContainer
56 : public SimpleRefCount<EntryContainer>
57 , public
58 boost::multi_index::multi_index_container<
59 Ipv4RoutingTableEntry,
60 boost::multi_index::indexed_by<
61 // Access elements by interface
62
63 // boost::multi_index::sequenced<
64 // boost::multi_index::tag<i_metric>
65 // >,
66
67 boost::multi_index::ordered_unique<
68 boost::multi_index::tag<i_iface>,
69 BOOST_MULTI_INDEX_CONST_MEM_FUN (Ipv4RoutingTableEntry,uint32_t,GetInterface)
70 >,
71
72 // Keep entries sorted by metric
73 boost::multi_index::ordered_non_unique<
74 boost::multi_index::tag<i_metric>,
75 BOOST_MULTI_INDEX_CONST_MEM_FUN (Ipv4RoutingTableEntry,uint32_t,GetMetric)
76 >,
77
78 // Access elements by metric order
79 boost::multi_index::random_access<
80 boost::multi_index::tag<i_index>
81 >
82 >
83 >
84 {
85 };
86
87public:
88 static TypeId GetTypeId (void);
89
90 Ipv4GlobalRoutingOrderedNexthops ();
91
92 // These methods inherited from base class
93 // from Ipv4RoutingProtocol
94 virtual Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header,
95 Ptr<NetDevice> oif, Socket::SocketErrno &sockerr);
96
97 virtual bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
98 UnicastForwardCallback ucb, MulticastForwardCallback mcb,
99 LocalDeliverCallback lcb, ErrorCallback ecb);
100
101 virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const;
102
103 // from Ipv4GlobalRouting
104 virtual void AddRouteTo (Ipv4Address dest,
105 Ipv4Mask destMask,
106 Ipv4Address nextHop,
107 uint32_t interface,
108 uint32_t metric=0);
109
110 virtual void DeleteRoutes ();
111
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800112 const Ptr<EntryContainer>
113 Lookup (Ipv4Address dest);
114
Alexander Afanasyev3875a4b2011-11-10 11:55:53 -0800115protected:
116 virtual Ptr<Ipv4Route> LookupGlobal (Ipv4Address dest, Ptr<NetDevice> oif = 0);
117
118private:
119 typedef Ipv4AddressTrie<Ptr<EntryContainer> > Ipv4AddressTrieMap;
120 Ipv4AddressTrieMap m_routes;
121};
122
123} // Namespace ns3
124
125#endif /* IPV4_GLOBAL_ROUTING_ORDERED_NEXTHOPS_H */