OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tunnel_nh.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef vnsw_agent_tunnel_nh_hpp
6 #define vnsw_agent_tunnel_nh_hpp
7 
8 #include <base/dependency.h>
9 #include <cmn/agent_cmn.h>
10 #include <cmn/agent.h>
11 #include <oper/nexthop.h>
12 #include <oper/agent_route.h>
13 
14 class TunnelNH : public NextHop {
15 public:
16  TunnelNH(VrfEntry *vrf, const Ip4Address &sip, const Ip4Address &dip,
17  bool policy, TunnelType type, const MacAddress &rewrite_dmac);
18  virtual ~TunnelNH();
19 
20  virtual std::string ToString() const {
21  return "Tunnel to " + dip_.to_string() +
22  " rewrite mac " + rewrite_dmac_.ToString();
23  }
24  virtual bool NextHopIsLess(const DBEntry &rhs) const;
25  virtual bool TunnelNextHopIsLess(const DBEntry &rhs) const {
26  return false;
27  }
28  virtual void SetKey(const DBRequestKey *key);
29  virtual bool ChangeEntry(const DBRequest *req);
30  virtual void Delete(const DBRequest *req);
31  virtual KeyPtr GetDBRequestKey() const;
32  virtual bool CanAdd() const;
33 
34  const uint32_t vrf_id() const;
35  const VrfEntry *GetVrf() const {return vrf_.get();};
36  const Ip4Address *GetSip() const {return &sip_;};
37  const Ip4Address *GetDip() const {return &dip_;};
38  const AgentRoute *GetRt() const {return tunnel_dst_rt_;};
39  const MacAddress *GetDmac() const {return &(encap_list_[0]->dmac_);}
40  const bool &IsEncapValid(const uint32_t &i) const {return encap_list_[i]->valid_;}
41  const MacAddress &rewrite_dmac() const {return rewrite_dmac_;}
42  const TunnelType &GetTunnelType() const {return tunnel_type_;};
43  const Interface *GetCryptInterface() const {return crypt_interface_.get();};
44  bool GetCrypt() const {return crypt_;};
46  virtual void SendObjectLog(const NextHopTable *table,
47  AgentLogEvent::type event) const;
48  virtual bool DeleteOnZeroRefCount() const {
49  return true;
50  }
51 
52  virtual bool MatchEgressData(const NextHop *nh) const {
53  const TunnelNH *tun_nh = dynamic_cast<const TunnelNH *>(nh);
54  if (tun_nh && vrf_ == tun_nh->vrf_ && dip_ == tun_nh->dip_) {
55  return true;
56  }
57  return false;
58  }
59  virtual bool NeedMplsLabel() { return false; }
60 
61  struct EncapData {
62  EncapData(NextHop *nh, InterfaceConstRef intf) : arp_rt_(nh), interface_(intf), valid_(false) {}
66  bool valid_;
67  };
68  typedef boost::shared_ptr<EncapData> EncapDataPtr;
69  typedef std::vector<EncapDataPtr> EncapDataList;
70  const EncapDataList GetEncapDataList() const { return encap_list_; };
71 protected:
78  bool crypt_;
82 private:
84 };
85 
86 class LabelledTunnelNH : public TunnelNH {
87 public:
88  LabelledTunnelNH(VrfEntry *vrf, const Ip4Address &sip,
89  const Ip4Address &dip, bool policy, TunnelType type,
90  const MacAddress &rewrite_dmac, uint32_t label);
91  virtual ~LabelledTunnelNH();
92 
93  virtual std::string ToString() const {
94  return "Tunnel to " + GetDip()->to_string() +
95  " rewrite mac " + rewrite_dmac().ToString();
96  }
97  virtual bool TunnelNextHopIsLess(const DBEntry &rhs) const;
98  virtual bool ChangeEntry(const DBRequest *req);
99  virtual KeyPtr GetDBRequestKey() const;
100  uint32_t const GetTransportLabel() const { return transport_mpls_label_;};
101 
102  virtual void SendObjectLog(const NextHopTable *table,
103  AgentLogEvent::type event) const;
104  virtual bool DeleteOnZeroRefCount() const {
105  return true;
106  }
107 
108  virtual bool NeedMplsLabel() { return false; }
110  return transport_tunnel_type_;}
114  }
115 private:
119 };
121 // Mirror NH definition
123 class MirrorNHKey : public NextHopKey {
124 public:
125  MirrorNHKey(const string &vrf_name, const IpAddress &sip,
126  const uint16_t sport, const IpAddress &dip,
127  const uint16_t dport) :
128  NextHopKey(NextHop::MIRROR, false), vrf_key_(vrf_name), sip_(sip),
129  dip_(dip), sport_(sport), dport_(dport){
130  };
131  virtual ~MirrorNHKey() { };
132 
133  virtual NextHop *AllocEntry() const;
134  virtual NextHopKey *Clone() const {
135  return new MirrorNHKey(vrf_key_.name_, sip_, sport_, dip_, dport_);
136  }
137 private:
138  friend class MirrorNH;
142  uint16_t sport_;
143  uint16_t dport_;
145 };
146 
147 class MirrorNHData : public NextHopData {
148 public:
150  virtual ~MirrorNHData() { };
151 private:
152  friend class MirrorNH;
154 };
155 
156 class MirrorNH : public NextHop {
157 public:
158  MirrorNH(const VrfKey &vkey, const IpAddress &sip, uint16_t sport,
159  const IpAddress &dip, uint16_t dport);
160  virtual ~MirrorNH() { }
161 
162  virtual bool NextHopIsLess(const DBEntry &rhs) const;
163  virtual void SetKey(const DBRequestKey *key);
164  virtual bool ChangeEntry(const DBRequest *req);
165  virtual void Delete(const DBRequest *req);
166  virtual KeyPtr GetDBRequestKey() const;
167  virtual bool CanAdd() const;
168 
169  const uint32_t vrf_id() const;
170  const VrfEntry *GetVrf() const {return vrf_.get();}
171  const IpAddress *GetSip() const {return &sip_;}
172  const uint16_t GetSPort() const {return sport_;}
173  const IpAddress *GetDip() const {return &dip_;}
174  const uint16_t GetDPort() const {return dport_;}
175  const AgentRoute *GetRt() const {return arp_rt_.get();}
176  virtual std::string ToString() const {
177  return "Mirror to " + dip_.to_string();
178  }
179  virtual void SendObjectLog(const NextHopTable *table,
180  AgentLogEvent::type event) const;
181  virtual bool DeleteOnZeroRefCount() const {
182  return true;
183  }
184  virtual bool MatchEgressData(const NextHop *nh) const {
185  const MirrorNH *mir_nh = dynamic_cast<const MirrorNH *>(nh);
186  if (mir_nh && vrf_ == mir_nh->vrf_ && dip_ == mir_nh->dip_) {
187  return true;
188  }
189  return false;
190  }
191  virtual bool NeedMplsLabel() { return false; }
192 private:
194  std::string vrf_name_;
197  uint16_t sport_;
199  uint16_t dport_;
204 };
205 #endif
DISALLOW_COPY_AND_ASSIGN(LabelledTunnelNH)
uint32_t const GetTransportLabel() const
Definition: tunnel_nh.h:100
IpAddress sip_
Definition: tunnel_nh.h:196
virtual bool NeedMplsLabel()
Definition: tunnel_nh.h:59
uint16_t sport_
Definition: tunnel_nh.h:142
virtual bool CanAdd() const
Definition: nexthop.cc:1322
bool crypt_
Definition: tunnel_nh.h:78
std::string vrf_name_
Definition: tunnel_nh.h:194
MirrorNHKey(const string &vrf_name, const IpAddress &sip, const uint16_t sport, const IpAddress &dip, const uint16_t dport)
Definition: tunnel_nh.h:125
const VrfEntry * GetVrf() const
Definition: tunnel_nh.h:35
virtual ~TunnelNH()
Definition: nexthop.cc:998
VrfEntryRef vrf_
Definition: tunnel_nh.h:70
Definition: vrf.h:86
virtual bool DeleteOnZeroRefCount() const
Definition: tunnel_nh.h:181
bool GetCrypt() const
Definition: tunnel_nh.h:44
TunnelType tunnel_type_
Definition: tunnel_nh.h:75
virtual bool NeedMplsLabel()
Definition: tunnel_nh.h:108
boost::asio::ip::address IpAddress
Definition: address.h:13
virtual bool TunnelNextHopIsLess(const DBEntry &rhs) const
Definition: nexthop.cc:1267
IpAddress dip_
Definition: tunnel_nh.h:141
TunnelNH(VrfEntry *vrf, const Ip4Address &sip, const Ip4Address &dip, bool policy, TunnelType type, const MacAddress &rewrite_dmac)
Definition: nexthop.cc:985
const AgentRoute * GetRt() const
Definition: tunnel_nh.h:175
MacAddress dmac_
Definition: tunnel_nh.h:202
IpAddress sip_
Definition: tunnel_nh.h:140
virtual void SendObjectLog(const NextHopTable *table, AgentLogEvent::type event) const
Definition: nexthop.cc:1217
const Ip4Address * GetDip() const
Definition: tunnel_nh.h:37
static TypeBmap MplsType()
Definition: nexthop.h:312
ObjectType * get() const
Definition: dependency.h:49
Ip4Address dip_
Definition: tunnel_nh.h:74
bool GetCryptTunnelAvailable() const
Definition: tunnel_nh.h:45
DISALLOW_COPY_AND_ASSIGN(MirrorNHKey)
const bool & IsEncapValid(const uint32_t &i) const
Definition: tunnel_nh.h:40
DISALLOW_COPY_AND_ASSIGN(MirrorNH)
DependencyRef< NextHop, AgentRoute > arp_rt_
Definition: tunnel_nh.h:63
std::unique_ptr< DBRequestKey > KeyPtr
Definition: db_entry.h:25
MacAddress rewrite_dmac_
Definition: tunnel_nh.h:81
Base class for all Route entries in agent.
Definition: agent_route.h:224
uint16_t dport_
Definition: tunnel_nh.h:143
virtual ~LabelledTunnelNH()
Definition: nexthop.cc:1251
std::string ToString() const
Definition: mac_address.cc:53
virtual bool ChangeEntry(const DBRequest *req)
Definition: nexthop.cc:1273
TunnelType::Type const GetTransportTunnelType() const
Definition: tunnel_nh.h:109
virtual void SetKey(const DBRequestKey *key)
Definition: nexthop.cc:1355
virtual bool TunnelNextHopIsLess(const DBEntry &rhs) const
Definition: tunnel_nh.h:25
virtual void SetKey(const DBRequestKey *key)
Definition: nexthop.cc:1048
uint32_t transport_mpls_label_
Definition: tunnel_nh.h:116
string name_
Definition: vrf.h:38
const uint16_t GetSPort() const
Definition: tunnel_nh.h:172
EncapData(NextHop *nh, InterfaceConstRef intf)
Definition: tunnel_nh.h:62
uint8_t type
Definition: load_balance.h:109
MacAddress dmac_
Definition: tunnel_nh.h:65
virtual bool DeleteOnZeroRefCount() const
Definition: tunnel_nh.h:48
const uint32_t vrf_id() const
Definition: nexthop.cc:1351
virtual void SendObjectLog(const NextHopTable *table, AgentLogEvent::type event) const
Definition: nexthop.cc:1479
Definition: vrf.h:22
const TunnelType & GetTunnelType() const
Definition: tunnel_nh.h:42
InetUnicastAgentRouteTable * GetRouteTable()
Definition: nexthop.cc:1371
InterfaceConstRef crypt_interface_
Definition: tunnel_nh.h:80
virtual bool DeleteOnZeroRefCount() const
Definition: tunnel_nh.h:104
virtual NextHop * AllocEntry() const
Definition: nexthop.cc:1333
virtual ~MirrorNHData()
Definition: tunnel_nh.h:150
VrfKey vrf_key_
Definition: tunnel_nh.h:139
boost::intrusive_ptr< const Interface > InterfaceConstRef
Definition: agent.h:51
const VrfEntry * GetVrf() const
Definition: tunnel_nh.h:170
InterfaceConstRef interface_
Definition: tunnel_nh.h:64
DISALLOW_COPY_AND_ASSIGN(TunnelNH)
const Ip4Address * GetSip() const
Definition: tunnel_nh.h:36
virtual bool NextHopIsLess(const DBEntry &rhs) const
Definition: nexthop.cc:1021
EncapDataList encap_list_
Definition: tunnel_nh.h:77
static Type ComputeType(TypeBmap bmap)
Definition: nexthop.cc:33
bool crypt_tunnel_available_
Definition: tunnel_nh.h:79
const MacAddress & rewrite_dmac() const
Definition: tunnel_nh.h:41
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
const AgentRoute * GetRt() const
Definition: tunnel_nh.h:38
DependencyRef< NextHop, AgentRoute > arp_rt_
Definition: tunnel_nh.h:200
const IpAddress * GetSip() const
Definition: tunnel_nh.h:171
virtual std::string ToString() const
Definition: tunnel_nh.h:93
void Delete()
Definition: db_entry.cc:131
virtual KeyPtr GetDBRequestKey() const
Definition: nexthop.cc:1261
IpAddress dip_
Definition: tunnel_nh.h:198
MirrorNH(const VrfKey &vkey, const IpAddress &sip, uint16_t sport, const IpAddress &dip, uint16_t dport)
Definition: nexthop.cc:1312
Ip4Address sip_
Definition: tunnel_nh.h:73
virtual bool MatchEgressData(const NextHop *nh) const
Definition: tunnel_nh.h:52
TunnelType::Type transport_tunnel_type_
Definition: tunnel_nh.h:117
DISALLOW_COPY_AND_ASSIGN(MirrorNHData)
const EncapDataList GetEncapDataList() const
Definition: tunnel_nh.h:70
virtual NextHopKey * Clone() const
Definition: tunnel_nh.h:134
virtual ~MirrorNHKey()
Definition: tunnel_nh.h:131
const uint16_t GetDPort() const
Definition: tunnel_nh.h:174
LabelledTunnelNH(VrfEntry *vrf, const Ip4Address &sip, const Ip4Address &dip, bool policy, TunnelType type, const MacAddress &rewrite_dmac, uint32_t label)
Definition: nexthop.cc:1245
virtual bool NeedMplsLabel()
Definition: tunnel_nh.h:191
virtual void SendObjectLog(const NextHopTable *table, AgentLogEvent::type event) const
Definition: nexthop.cc:1285
std::vector< EncapDataPtr > EncapDataList
Definition: tunnel_nh.h:69
virtual bool CanAdd() const
Definition: nexthop.cc:1001
virtual KeyPtr GetDBRequestKey() const
Definition: nexthop.cc:1059
boost::shared_ptr< EncapData > EncapDataPtr
Definition: tunnel_nh.h:68
const uint32_t vrf_id() const
Definition: nexthop.cc:1065
void SetTransportTunnelType()
Definition: tunnel_nh.h:111
uint16_t sport_
Definition: tunnel_nh.h:197
uint16_t dport_
Definition: tunnel_nh.h:199
const MacAddress * GetDmac() const
Definition: tunnel_nh.h:39
virtual std::string ToString() const
Definition: tunnel_nh.h:20
virtual ~MirrorNH()
Definition: tunnel_nh.h:160
InterfaceConstRef interface_
Definition: tunnel_nh.h:201
VrfEntryRef vrf_
Definition: tunnel_nh.h:195
virtual KeyPtr GetDBRequestKey() const
Definition: nexthop.cc:1365
const IpAddress * GetDip() const
Definition: tunnel_nh.h:173
virtual std::string ToString() const
Definition: tunnel_nh.h:176
virtual bool ChangeEntry(const DBRequest *req)
Definition: nexthop.cc:1381
virtual bool MatchEgressData(const NextHop *nh) const
Definition: tunnel_nh.h:184
virtual bool NextHopIsLess(const DBEntry &rhs) const
Definition: nexthop.cc:1337
const Interface * GetCryptInterface() const
Definition: tunnel_nh.h:43
AgentRoute * tunnel_dst_rt_
Definition: tunnel_nh.h:76
virtual bool ChangeEntry(const DBRequest *req)
Definition: nexthop.cc:1069