-
Notifications
You must be signed in to change notification settings - Fork 390
/
routing_policy_match.h
89 lines (77 loc) · 2.52 KB
/
routing_policy_match.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
/*
* Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
*/
#ifndef SRC_BGP_ROUTING_POLICY_ROUTING_POLICY_MATCH_H_
#define SRC_BGP_ROUTING_POLICY_ROUTING_POLICY_MATCH_H_
#include <vector>
#include <string>
#include <typeinfo>
#include <stdint.h>
#include "bgp/bgp_config.h"
#include "bgp/inet/inet_route.h"
#include "bgp/inet6/inet6_route.h"
class BgpAttr;
class BgpRoute;
class Community;
class RoutingPolicyMatch {
public:
virtual std::string ToString() const = 0;
virtual ~RoutingPolicyMatch() {
}
bool operator()(const BgpRoute *route, const BgpAttr *attr) const {
return Match(route, attr);
}
virtual bool Match(const BgpRoute *route, const BgpAttr *attr) const = 0;
virtual bool operator==(const RoutingPolicyMatch &match) const {
if (typeid(match) == typeid(*this))
return(IsEqual(match));
return false;
}
virtual bool IsEqual(const RoutingPolicyMatch &match) const = 0;
};
class MatchCommunity: public RoutingPolicyMatch {
public:
typedef std::vector<uint32_t> CommunityList;
explicit MatchCommunity(const std::vector<std::string> &communities);
virtual ~MatchCommunity();
virtual bool Match(const BgpRoute *route, const BgpAttr *attr) const;
virtual std::string ToString() const;
virtual bool IsEqual(const RoutingPolicyMatch &community) const;
const CommunityList &communities() const {
return to_match_;
}
private:
CommunityList to_match_;
};
template <typename T1, typename T2>
struct PrefixMatchBase {
typedef T1 RouteT;
typedef T2 PrefixT;
};
class InetPrefixMatch : public PrefixMatchBase<InetRoute, Ip4Prefix> {
};
class Inet6PrefixMatch : public PrefixMatchBase<Inet6Route, Inet6Prefix> {
};
template <typename T>
class MatchPrefix : public RoutingPolicyMatch {
public:
typedef typename T::RouteT RouteT;
typedef typename T::PrefixT PrefixT;
enum MatchType {
EXACT,
LONGER,
ORLONGER,
};
typedef std::pair<PrefixT, MatchType> PrefixMatch;
typedef std::vector<PrefixMatch> PrefixMatchList;
explicit MatchPrefix(const PrefixMatchConfigList &list);
virtual ~MatchPrefix();
virtual bool Match(const BgpRoute *route, const BgpAttr *attr) const;
virtual std::string ToString() const;
virtual bool IsEqual(const RoutingPolicyMatch &prefix) const;
private:
PrefixMatchList match_list_;
};
typedef MatchPrefix<InetPrefixMatch> PrefixMatchInet;
typedef MatchPrefix<Inet6PrefixMatch> PrefixMatchInet6;
#endif // SRC_BGP_ROUTING_POLICY_ROUTING_POLICY_MATCH_H_