6 #include <boost/uuid/uuid_io.hpp>
10 #include <vnc_cfg_types.h>
11 #include <agent_types.h>
21 using namespace autogen;
28 (
"/usr/bin/contrail_crypt_tunnel_client.py");
39 return remote_ip_.to_string();
53 UpdateTunnelReference();
58 typedef std::list<TunnelType::Type> TunnelTypeList;
59 TunnelTypeList type_list;
63 for (TunnelTypeList::const_iterator it = type_list.begin();
64 it != type_list.end(); it++) {
68 remote_ip_.to_v4(),
false, *it);
70 nh_req.
key.reset(tnh_key);
76 agent()->ConcurrencyCheck();
79 Input(tpart, NULL, &req);
84 bool &crypt_path_available) {
85 crypt_traffic =
false;
86 crypt_path_available =
false;
111 boost::system::error_code ec;
112 IpAddress ip = IpAddress::from_string(remote_ip, ec);
122 boost::system::error_code ec;
123 IpAddress ip = IpAddress::from_string(remote_ip, ec);
128 req.
data.reset(NULL);
135 boost::system::error_code ec;
136 IpAddress ip = IpAddress::from_string(remote_ip, ec);
147 (
static_cast<DBTable *
>(crypt_tunnel_table))->Init();
148 crypt_tunnel_table_ = crypt_tunnel_table;
149 return crypt_tunnel_table;
155 return std::unique_ptr<DBEntry>(
static_cast<DBEntry *
>(e));
161 ChangeHandler(crypt_tunnel_entry, req);
162 crypt_tunnel_entry->
SendObjectLog(GetOperDBTraceBuf(), AgentLogEvent::ADD);
163 return crypt_tunnel_entry;
182 boost::system::error_code ec;
183 IpAddress source_ip = IpAddress::from_string(agent()->router_id().to_string(), ec);
191 ret = ChangeHandler(crypt_tunnel_entry, req);
195 crypt_tunnel_entry->
SendObjectLog(GetOperDBTraceBuf(), AgentLogEvent::CHANGE);
202 ret = ChangeHandler(crypt_tunnel_entry, req);
205 crypt_tunnel_entry->
SendObjectLog(GetOperDBTraceBuf(), AgentLogEvent::RESYNC);
212 crypt_tunnel_entry->
SendObjectLog(GetOperDBTraceBuf(), AgentLogEvent::DEL);
217 AgentDBTable(db, name), vr_to_vr_crypt_(false), crypt_interface_(NULL),
218 tunnel_event_queue_(agent->task_scheduler()->GetTaskId(
kTaskCryptTunnel), 0,
232 CryptTunnelResp *resp =
static_cast<CryptTunnelResp *
>(sresp);
235 CryptTunnelSandeshData data;
236 data.set_source(std::string());
240 std::vector<CryptTunnelSandeshData> &list =
241 const_cast<std::vector<CryptTunnelSandeshData>&
>(resp->get_crypt_tunnel_list());
242 list.push_back(data);
250 CryptTunnelObjectLogInfo info;
253 case AgentLogEvent::ADD:
254 str.assign(
"Addition");
256 case AgentLogEvent::DEL:
257 str.assign(
"Deletion");
259 case AgentLogEvent::CHANGE:
260 str.assign(
"Modification");
262 case AgentLogEvent::RESYNC:
263 str.assign(
"Resync");
271 info.set_source(std::string());
274 CRYPT_TUNNEL_OBJECT_LOG_LOG(
"CryptTunnel", SandeshLevel::SYS_INFO, info);
275 CRYPT_TUNNEL_TRACE_TRACE(buf, info);
278 void CryptTunnelReq::HandleRequest()
const {
280 sand->DoSandesh(sand);
284 const std::string &context) {
293 const std::string &message) :
294 tunnel_task_(task), entry_(entry), type_(type), message_(message) {
305 entry_(NULL), active_(false), last_update_time_(
"-"), deleted_(false) {
333 std::string str(
"Instance for crypt tunnel ");
334 str +=
entry_->ToString();
390 if (
task_.get() != NULL) {
391 task_->set_pipe_stdout(
true);
392 task_->set_on_data_cb(
394 task_->set_on_exit_cb(
406 if (
task_.get() == NULL) {
432 task_->set_cmd(
"echo success");
435 std::stringstream cmd_str;
440 cmd_str <<
" --oper create ";
445 cmd_str <<
" --oper update ";
450 cmd_str <<
" --oper status ";
455 cmd_str <<
" --oper delete ";
462 cmd_str <<
" --source_ip " <<
entry_->GetSourceIp()->to_string();
463 cmd_str <<
" --remote_ip " <<
entry_->GetRemoteIp()->to_string();
464 task_->set_cmd(cmd_str.str());
468 return (
task_.get() != NULL ?
task_->is_running():
false);
502 switch (event->
type_) {
508 std::string msg =
event->message_;
509 boost::algorithm::to_lower(msg);
510 if (msg.find(
"success") != std::string::npos) {
516 if (msg.find(
"failure") != std::string::npos) {
virtual std::unique_ptr< DBEntry > AllocEntry(const DBRequestKey *k) const
void Delete(const std::string &remote_ip)
virtual KeyPtr GetDBRequestKey() const
void Shutdown(bool delete_entries=true)
void TunnelEventEnqueue(CryptTunnelEvent *event)
virtual bool IsRunning() const
std::string GetString(const std::string &key) const
virtual bool IsLess(const DBEntry &rhs) const
NextHopTable * nexthop_table() const
DBTableBase * get_table() const
virtual DBEntry * Add(const DBRequest *req)
void CryptAvailability(const std::string &remote_ip, bool &crypt_traffic, bool &crypt_path_available)
virtual bool DestroyTunnelTask()
virtual bool DestroyTunnelTask()=0
boost::asio::ip::address IpAddress
virtual bool UpdateTunnelTask()
virtual bool CreateTunnelTask()
std::unique_ptr< DBRequestData > data
virtual bool RunTunnelTask(CommandType cmd_type)
virtual bool CreateTunnelTask()=0
virtual bool StopTunnelTask()
bool GetTunnelAvailable() const
bool IsCryptPathAvailable(const std::string &remote_ip)
virtual ~CryptTunnelTask()
boost::shared_ptr< TraceBuffer< SandeshTrace > > SandeshTraceBufferPtr
void UpdateTunnel(const CryptTunnelEntry *entry, bool available) const
std::unique_ptr< DBRequestKey > KeyPtr
void Process(DBRequest &req)
CryptTunnelEvent(CryptTunnelTaskBase *inst, CryptTunnelEntry *entry, EventType type, const std::string &message)
const IpAddress * GetRemoteIp() const
virtual void SetKey(const DBRequestKey *key)
static CryptTunnelTable * crypt_tunnel_table_
virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args, const std::string &context)
const std::string & fabric_vrf_name() const
bool GetVRToVRCrypt() const
void UpdateTunnelTaskCommand(CommandType cmd_type)
CryptTunnelTaskBase * StartCryptTunnel()
CryptTunnelTask(CryptTunnelEntry *entry)
Ip4Address router_id() const
std::unique_ptr< DBRequestKey > key
EventManager * event_manager() const
SandeshTraceBufferPtr CryptTunnelTraceBuf
CryptTunnelEntryRef entry_
bool TunnelEventProcess(CryptTunnelEvent *event)
void set_tunnel_entry(CryptTunnelEntry *entry)
virtual ~CryptTunnelEvent()
class boost::shared_ptr< AgentSandesh > AgentSandeshPtr
CryptTunnelTaskBase(CryptTunnelEntry *entry)
virtual bool OnChange(DBEntry *entry, const DBRequest *req)
bool IsCryptTraffic(const std::string &remote_ip)
CryptTunnelTask * tunnel_task_
void OnRead(const std::string &data)
CryptTunnelEntry * Find(const std::string &remote_ip)
virtual string ToString() const
void SetTunnelEntry(CryptTunnelEntry *entry)
virtual bool RunTunnelTask(CommandType cmd_type)=0
#define CRYPT_TUNNEL_TASK_TRACE(obj,...)
static uint64_t UTCTimestampUsec()
void Process(DBRequest &req)
bool DBEntrySandesh(Sandesh *sresp, std::string &name) const
virtual bool Resync(DBEntry *entry, const DBRequest *req)
static const std::string kCryptTunnelCmd
CryptTunnelEntry * entry() const
WorkQueue< CryptTunnelEvent * > tunnel_event_queue_
void SendObjectLog(SandeshTraceBufferPtr ptr, AgentLogEvent::type event) const
void Create(const std::string &remote_ip, bool crypt)
void StopTask(CryptTunnelEntry *service)
CryptTunnelTable(Agent *agent, DB *db, const std::string &name)
void OnExit(const boost::system::error_code &ec)
void UpdateTunnelReference()
CryptTunnelEntry * entry_
InstanceTaskExecvp CryptTunnelProcessTunnel
bool Enqueue(QueueEntryT entry)
static DBTableBase * CreateTable(Agent *agent, DB *db, const std::string &name)
bool ChangeHandler(CryptTunnelEntry *entry, const DBRequest *req)
void set_name(const std::string &name)
void set_agent(Agent *agent)
std::string last_update_time_
virtual ~CryptTunnelTaskBase()
SandeshTraceBufferPtr SandeshTraceBufferCreate(const std::string &buf_name, size_t buf_size, bool trace_enable=true)
virtual ~CryptTunnelTable()
static std::string UTCUsecToString(uint64_t tstamp)