Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef vnsw_agent_cmn_hpp 6 : #define vnsw_agent_cmn_hpp 7 : 8 : #include <sys/socket.h> 9 : #include <netinet/in.h> 10 : #include <arpa/inet.h> 11 : #include <unistd.h> 12 : 13 : #include <boost/intrusive_ptr.hpp> 14 : #include <boost/bind/bind.hpp> 15 : #include <boost/uuid/uuid.hpp> 16 : #include <boost/uuid/uuid_io.hpp> 17 : #include <boost/uuid/nil_generator.hpp> 18 : 19 : #include <io/event_manager.h> 20 : #include <db/db.h> 21 : #include <db/db_entry.h> 22 : #include <db/db_table.h> 23 : #include <db/db_table_partition.h> 24 : #include <db/db_table_walker.h> 25 : 26 : #include <base/address.h> 27 : #include <base/logging.h> 28 : #include <base/task.h> 29 : #include <base/task_trigger.h> 30 : #include <base/task_annotations.h> 31 : #include <base/dependency.h> 32 : #include <base/lifetime.h> 33 : 34 : #include <ifmap/ifmap_agent_parser.h> 35 : #include <ifmap/ifmap_agent_table.h> 36 : 37 : #include <sandesh/sandesh_trace.h> 38 : #include <sandesh/common/vns_constants.h> 39 : 40 : #include <cmn/agent.h> 41 : #include <cmn/agent_db.h> 42 : #include <cmn/event_notifier.h> 43 : 44 : #include <stdio.h> 45 : #include <execinfo.h> 46 : #include <dlfcn.h> 47 : #include <cxxabi.h> 48 : 49 : using namespace boost::placeholders; 50 : 51 : static inline bool UnregisterDBTable(DBTable *table, 52 : DBTableBase::ListenerId id) { 53 : table->Unregister(id); 54 : return true; 55 : } 56 : 57 : static inline TaskTrigger *SafeDBUnregister(DBTable *table, 58 : DBTableBase::ListenerId id) { 59 : TaskTrigger *trigger = 60 : new TaskTrigger(boost::bind(&UnregisterDBTable, table, id), 61 : TaskScheduler::GetInstance()->GetTaskId("db::DBTable"), 0); 62 : trigger->Set(); 63 : return trigger; 64 : } 65 : 66 1101 : static inline void CfgUuidSet(uint64_t ms_long, uint64_t ls_long, 67 : boost::uuids::uuid &u) { 68 9909 : for (int i = 0; i < 8; i++) { 69 8808 : u.data[7 - i] = ms_long & 0xFF; 70 8808 : ms_long = ms_long >> 8; 71 : } 72 : 73 9909 : for (int i = 0; i < 8; i++) { 74 8808 : u.data[15 - i] = ls_long & 0xFF; 75 8808 : ls_long = ls_long >> 8; 76 : } 77 1101 : } 78 : 79 0 : static inline void CloseTaskFds(void) { 80 0 : int max_open_fds = sysconf(_SC_OPEN_MAX); 81 : int fd; 82 0 : for(fd = 3; fd < max_open_fds; fd++) 83 0 : close(fd); 84 0 : } 85 : 86 : extern SandeshTraceBufferPtr OperConfigTraceBuf; 87 : 88 : #define OPER_IFMAP_TRACE(obj, ...)\ 89 : do {\ 90 : Oper##obj::TraceMsg(OperConfigTraceBuf, __FILE__, __LINE__, __VA_ARGS__);\ 91 : } while (false) 92 : 93 : #define IFMAP_ERROR(obj, ...)\ 94 : do {\ 95 : if (LoggingDisabled()) break;\ 96 : obj::Send(g_vns_constants.CategoryNames.find(Category::IFMAP_AGENT)->second,\ 97 : SandeshLevel::SYS_ERR, __FILE__, __LINE__, ##__VA_ARGS__);\ 98 : } while (false) 99 : 100 : std::string AgentBackTrace(int skip); 101 : #endif // vnsw_agent_cmn_hpp