/
static_route.h
127 lines (97 loc) · 3.89 KB
/
static_route.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#ifndef SRC_BGP_ROUTING_INSTANCE_STATIC_ROUTE_H_
#define SRC_BGP_ROUTING_INSTANCE_STATIC_ROUTE_H_
#include <map>
#include <set>
#include "bgp/routing-instance/istatic_route_mgr.h"
#include "bgp/bgp_condition_listener.h"
#include "bgp/inet/inet_route.h"
#include "bgp/inet6/inet6_route.h"
class InetVpnRoute;
class Inet6VpnRoute;
class StaticRouteConfig;
template <typename T> class StaticRoute;
template <typename T1, typename T2, typename T3, typename T4>
struct StaticRouteBase {
typedef T1 RouteT;
typedef T2 VpnRouteT;
typedef T3 PrefixT;
typedef T4 AddressT;
};
class StaticRouteInet : public StaticRouteBase<
InetRoute, InetVpnRoute, Ip4Prefix, Ip4Address> {
};
class StaticRouteInet6 : public StaticRouteBase<
Inet6Route, Inet6VpnRoute, Inet6Prefix, Ip6Address> {
};
typedef ConditionMatchPtr StaticRoutePtr;
struct StaticRouteRequest {
enum RequestType {
NEXTHOP_ADD_CHG,
NEXTHOP_DELETE,
DELETE_STATIC_ROUTE_DONE
};
StaticRouteRequest(RequestType type, BgpTable *table, BgpRoute *route,
StaticRoutePtr info)
: type_(type), table_(table), rt_(route), info_(info) {
}
RequestType type_;
BgpTable *table_;
BgpRoute *rt_;
StaticRoutePtr info_;
private:
DISALLOW_COPY_AND_ASSIGN(StaticRouteRequest);
};
template <typename T>
class StaticRouteMgr : public IStaticRouteMgr {
public:
typedef typename T::RouteT RouteT;
typedef typename T::VpnRouteT VpnRouteT;
typedef typename T::PrefixT PrefixT;
typedef typename T::AddressT AddressT;
typedef StaticRoute<T> StaticRouteT;
// Map of Static Route prefix to the StaticRoute match object
typedef std::map<PrefixT, StaticRoutePtr> StaticRouteMap;
explicit StaticRouteMgr(RoutingInstance *instance);
~StaticRouteMgr();
// Config
virtual void ProcessStaticRouteConfig();
virtual void UpdateStaticRouteConfig();
virtual void FlushStaticRouteConfig();
void EnqueueStaticRouteReq(StaticRouteRequest *req);
const StaticRouteMap &static_route_map() const { return static_route_map_; }
virtual void NotifyAllRoutes();
virtual uint32_t GetRouteCount() const;
virtual uint32_t GetDownRouteCount() const;
virtual bool FillStaticRouteInfo(RoutingInstance *rtinstance,
StaticRouteEntriesInfo *info) const;
Address::Family GetFamily() const;
AddressT GetAddress(IpAddress addr) const;
private:
template <typename U> friend class StaticRouteTest;
// All static route related actions are performed in the context
// of this task. This task has exclusion with db::DBTable task.
static int static_route_task_id_;
void LocateStaticRoutePrefix(const StaticRouteConfig &cfg);
void RemoveStaticRoutePrefix(const PrefixT &static_route);
void StopStaticRouteDone(BgpTable *table, ConditionMatch *info);
bool ResolvePendingStaticRouteConfig();
bool StaticRouteEventCallback(StaticRouteRequest *req);
virtual void DisableResolveTrigger() { resolve_trigger_->set_disable(); }
virtual void EnableResolveTrigger() { resolve_trigger_->set_enable(); }
virtual void DisableQueue() { static_route_queue_->set_disable(true); }
virtual void EnableQueue() { static_route_queue_->set_disable(false); }
virtual bool IsQueueEmpty() { return static_route_queue_->IsQueueEmpty(); }
RoutingInstance *routing_instance() { return rtinstance_; }
RoutingInstance *rtinstance_;
BgpConditionListener *listener_;
StaticRouteMap static_route_map_;
WorkQueue<StaticRouteRequest *> *static_route_queue_;
boost::scoped_ptr<TaskTrigger> resolve_trigger_;
DISALLOW_COPY_AND_ASSIGN(StaticRouteMgr);
};
typedef StaticRouteMgr<StaticRouteInet> StaticRouteMgrInet;
typedef StaticRouteMgr<StaticRouteInet6> StaticRouteMgrInet6;
#endif // SRC_BGP_ROUTING_INSTANCE_STATIC_ROUTE_H_