OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
hbf.cc
Go to the documentation of this file.
1 /*
2  * * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * */
4 
5 #include <boost/uuid/uuid_io.hpp>
6 #include <cmn/agent_cmn.h>
7 #include <init/agent_param.h>
8 
9 #include <base/logging.h>
10 #include <oper/operdb_init.h>
11 #include <oper/route_common.h>
12 #include <oper/interface_common.h>
13 #include <oper/vrf.h>
14 #include <oper/agent_sandesh.h>
15 #include <oper/hbf.h>
17 
18 
19 #include <sandesh/sandesh_types.h>
20 #include <sandesh/sandesh_constants.h>
21 #include <sandesh/sandesh.h>
22 #include <sandesh/sandesh_trace.h>
23 
24 #include <string.h>
25 
26 using namespace std;
27 using namespace boost::uuids;
28 
30 
32  agent_(agent),
33  interface_listener_id_(DBTable::kInvalidId) {
34 }
35 
38  boost::bind(&HBFHandler::ModifyVmInterface, this, _1, _2));
39  HBFTRACE(Trace, "HBFHandler registered for interface table");
40 }
41 
44 }
45 
47  return (vm_itf->hbs_intf_type() == VmInterface::HBS_INTF_LEFT);
48 }
49 
51  return (vm_itf->hbs_intf_type() == VmInterface::HBS_INTF_RIGHT);
52 }
53 
54 /* Registered call for VM */
56  DBEntryBase *e)
57 {
58  Interface *intf = static_cast<Interface *>(e);
59  VmInterface *vm_itf;
60 
61  if (intf->type() != Interface::VM_INTERFACE) {
62  return;
63  }
64 
65  vm_itf = static_cast<VmInterface *>(intf);
66  HBFIntfDBState *state = static_cast<HBFIntfDBState *>(
67  vm_itf->GetState(partition->parent(), interface_listener_id_));
68 
69  // When this function is invoked for Delete, VMI's vn can be NULL. Use its
70  // state to figure out if it is HBF VMI
71  if (!IsHBFLInterface(vm_itf) && !IsHBFRInterface(vm_itf) && !state) {
72  return;
73  }
74 
75  HBFTRACE(Trace, "vmi notification for " + vm_itf->ToString());
76  if (intf->IsDeleted() || ((vm_itf->l2_active() == false) &&
77  (vm_itf->ipv4_active() == false) &&
78  (vm_itf->ipv6_active() == false))) {
79  if (state) {
80  vm_itf->ClearState(partition->parent(), interface_listener_id_);
81  HBFVrfWalker *walker = static_cast<HBFVrfWalker*>
82  (state->vrf_walker_.get());
83  if (walker) {
84  HBFTRACE(Trace, "Starting VRF walk for deletion of "
85  + vm_itf->ToString());
86  walker->WalkDoneCallback(boost::bind
88  static_cast<HBFVrfWalker *>( walker)));
90  state->lintf_,
91  state->projname_);
92  }
93  delete state;
94  }
95  return;
96  }
97 
98  if (state == NULL && vm_itf->vn()) {
99  state = new HBFIntfDBState(IsHBFLInterface(vm_itf), vm_itf->vn()->GetProject());
100  state->vrf_walker_.reset(new HBFVrfWalker("HBFVrfWalker", agent_));
102  RegisterWalker(static_cast<AgentRouteWalker *>(state->vrf_walker_.get()));
103  vm_itf->SetState(partition->parent(), interface_listener_id_, state);
104  } else {
105  // Dont have to process Change? TODO
106  return;
107  }
108 
109  if (state->vrf_walker_.get()) {
110  HBFTRACE(Trace, "Starting VRF walk for addition of "
111  + vm_itf->ToString());
112  HBFVrfWalker *walker = static_cast<HBFVrfWalker*>(state->vrf_walker_.get());
113  if (walker) {
114  walker->Start(vm_itf->id(),
115  state->lintf_,
116  state->projname_);
117  }
118  }
119 }
120 
121 HBFVrfWalker::HBFVrfWalker(const std::string &name, Agent *agent) :
122  AgentRouteWalker(name, agent) {
123 }
124 
126 }
127 
129  DBEntryBase *e) {
130  VrfEntry *vrf = dynamic_cast<VrfEntry*>(e);
131 
132  if (vrf && vrf->vn()) {
133  if (projname_ == vrf->vn()->GetProject()) {
134  if (hbf_lintf_) {
135  vrf->set_hbf_lintf(hbf_intf_);
136  std::stringstream ss;
137  ss << "Setting lintf to " << hbf_intf_
138  << " for vrf " << vrf->vrf_id() << " name " << vrf->GetName();
139  HBFTRACE(Trace, ss.str());
140  } else {
141  vrf->set_hbf_rintf(hbf_intf_);
142  std::stringstream ss;
143  ss << "Setting rintf to " << hbf_intf_
144  << " for vrf " << vrf->vrf_id() << " name " << vrf->GetName();
145  HBFTRACE(Trace, ss.str());
146  }
147  }
148 
149  vrf->Notify();
150  }
151  return true;
152 }
153 
154 void HBFVrfWalker::Start(uint32_t hbf_intf, bool hbf_lintf, std::string projname) {
155  hbf_intf_ = hbf_intf;
156  hbf_lintf_ = hbf_lintf;
157  projname_ = projname;
158  StartVrfWalk();
159 }
void Start(uint32_t hbf_intf_, bool hbf_lintf_, std::string projname)
Definition: hbf.cc:154
bool hbf_lintf_
Definition: hbf.h:67
#define HBFTRACE(obj,...)
Definition: hbf.h:17
Type type() const
Definition: interface.h:112
void Register()
Definition: hbf.cc:36
void WalkDoneCallback(WalkDone cb)
Definition: vrf.h:86
DBState * GetState(DBTableBase *tbl_base, ListenerId listener) const
Definition: db_entry.cc:37
AgentRouteWalkerPtr vrf_walker_
Definition: hbf.h:25
const uint32_t id() const
Definition: interface.h:123
SandeshTraceBufferPtr HBFTraceBuf
bool lintf_
Definition: hbf.h:26
bool IsDeleted() const
Definition: db_entry.h:49
void SetState(DBTableBase *tbl_base, ListenerId listener, DBState *state)
Definition: db_entry.cc:22
void Terminate()
Definition: hbf.cc:42
bool l2_active() const
Definition: interface.h:122
HBFHandler(Agent *agent)
Definition: hbf.cc:31
std::string ToString() const
VmInterface::HbsIntfType hbs_intf_type() const
DBTableBase * parent()
InterfaceTable * interface_table() const
Definition: agent.h:465
const string & GetName() const
Definition: vrf.h:100
boost::shared_ptr< TraceBuffer< SandeshTrace > > SandeshTraceBufferPtr
Definition: sandesh_trace.h:18
void Unregister(ListenerId listener)
Definition: db_table.cc:186
OperDB * oper_db() const
Definition: agent.cc:1013
ListenerId Register(ChangeCallback callback, const std::string &name="unspecified")
Definition: db_table.cc:181
std::string GetProject() const
Definition: vn.cc:716
std::string projname_
Definition: hbf.h:27
Definition: agent.h:358
AgentRouteWalkerManager * agent_route_walk_manager() const
Definition: operdb_init.h:91
bool ipv4_active() const
Definition: interface.h:116
Definition: trace.h:220
bool IsHBFLInterface(VmInterface *vm_itf)
Definition: hbf.cc:46
const VnEntry * vn() const
std::string projname_
Definition: hbf.h:68
bool IsHBFRInterface(VmInterface *vm_itf)
Definition: hbf.cc:50
const uint32_t vrf_id() const
Definition: vrf.h:99
void ClearState(DBTableBase *tbl_base, ListenerId listener)
Definition: db_entry.cc:73
DBTable::ListenerId interface_listener_id_
Definition: hbf.h:48
uint32_t hbf_intf_
Definition: hbf.h:66
void ModifyVmInterface(DBTablePartBase *partition, DBEntryBase *e)
Definition: hbf.cc:55
virtual ~HBFVrfWalker()
Definition: hbf.cc:125
static const uint32_t kInvalidIndex
Definition: interface.h:70
VnEntry * vn() const
Definition: vrf.h:101
void Notify()
Definition: db_entry.cc:127
void set_hbf_lintf(uint32_t idx)
Definition: vrf.h:225
void set_hbf_rintf(uint32_t idx)
Definition: vrf.h:224
boost::function< void()> WalkDone
virtual bool VrfWalkNotify(DBTablePartBase *partition, DBEntryBase *e)
Definition: hbf.cc:128
bool ipv6_active() const
Definition: interface.h:117
SandeshTraceBufferPtr SandeshTraceBufferCreate(const std::string &buf_name, size_t buf_size, bool trace_enable=true)
Definition: sandesh_trace.h:46
Agent * agent_
Definition: hbf.h:46
HBFVrfWalker(const std::string &name, Agent *agent)
Definition: hbf.cc:121