11 #include <boost/date_time/posix_time/posix_time.hpp>
24 uint16_t plen = key->
plen();
32 #define SET_SANDESH_FLOW_DATA(agent, data, fe, info) \
33 data.set_vrf(fe->data().vrf); \
34 data.set_sip(fe->key().src_addr.to_string()); \
35 data.set_dip(fe->key().dst_addr.to_string()); \
36 data.set_src_port((unsigned)fe->key().src_port); \
37 data.set_dst_port((unsigned)fe->key().dst_port); \
38 data.set_protocol(fe->key().protocol); \
39 data.set_dest_vrf(fe->data().dest_vrf); \
40 data.set_uuid(UuidToString(fe->uuid())); \
41 data.set_action(fe->match_p().action_info.action); \
42 std::vector<ActionStr> action_str_l; \
43 SetActionStr(fe->match_p().action_info, action_str_l); \
44 if ((fe->match_p().action_info.action & TrafficAction::DROP_FLAGS) != 0) {\
45 data.set_drop_reason(fe->DropReasonStr(fe->data().drop_reason)); \
47 data.set_action_str(action_str_l); \
48 std::vector<MirrorActionSpec>::const_iterator mait; \
49 std::vector<MirrorInfo> mirror_l; \
50 for (mait = fe->match_p().action_info.mirror_l.begin(); \
51 mait != fe->match_p().action_info.mirror_l.end(); \
54 minfo.set_mirror_destination((*mait).ip.to_string()); \
55 minfo.set_mirror_port((*mait).port); \
56 mirror_l.push_back(minfo); \
58 data.set_mirror_l(mirror_l); \
59 if (fe->is_flags_set(FlowEntry::IngressDir)) { \
60 data.set_direction("ingress"); \
62 data.set_direction("egress"); \
65 data.set_stats_bytes(info->bytes()); \
66 data.set_stats_packets(info->packets()); \
68 if (fe->is_flags_set(FlowEntry::NatFlow)) { \
69 data.set_nat("enabled"); \
71 data.set_nat("disabled"); \
73 data.set_gen_id(fe->gen_id()); \
74 data.set_flow_handle(fe->flow_handle()); \
75 data.set_refcount(fe->GetRefCount()); \
76 data.set_implicit_deny(fe->ImplicitDenyFlow() ? "yes" : "no"); \
77 data.set_short_flow( \
78 fe->is_flags_set(FlowEntry::ShortFlow) ? \
79 string("yes (") + fe->DropReasonStr(fe->short_flow_reason()) + \
81 data.set_local_flow(fe->is_flags_set(FlowEntry::LocalFlow) ? "yes" : "no"); \
82 if (!fe->data().OriginVnSrcList().empty()) { \
83 data.set_src_vn_list(fe->data().OriginVnSrcList()); \
85 data.set_src_vn_list(fe->data().SourceVnList()); \
87 if (!fe->data().OriginVnDstList().empty()) { \
88 data.set_dst_vn_list(fe->data().OriginVnDstList()); \
90 data.set_dst_vn_list(fe->data().DestinationVnList()); \
92 if (!fe->data().origin_vn_src.empty()) { \
93 data.set_src_vn_match(fe->data().origin_vn_src); \
95 data.set_src_vn_match(fe->data().source_vn_match); \
97 if (!fe->data().origin_vn_dst.empty()) { \
98 data.set_dst_vn_match(fe->data().origin_vn_dst); \
100 data.set_dst_vn_match(fe->data().dest_vn_match); \
102 if (fe->is_flags_set(FlowEntry::EcmpFlow) && \
103 fe->data().component_nh_idx != CompositeNH::kInvalidComponentNHIdx) { \
104 data.set_ecmp_index(fe->data().component_nh_idx); \
106 data.set_reverse_flow(fe->is_flags_set(FlowEntry::ReverseFlow) ? "yes" : "no"); \
107 Ip4Address fip(fe->fip()); \
108 data.set_fip(fip.to_string()); \
109 uint32_t fip_intf_id = fe->InterfaceKeyToId(agent, fe->fip_vmi()); \
110 data.set_fip_vm_interface_idx(fip_intf_id); \
111 SetAclInfo(data, fe); \
112 data.set_nh(fe->key().nh); \
113 if (fe->data().src_ip_nh.get() != NULL) { \
114 data.set_src_ip_nh(fe->data().src_ip_nh.get()->id()); \
116 if (fe->data().rpf_nh.get() != NULL) { \
117 data.set_rpf_nh(fe->data().rpf_nh.get()->id()); \
119 data.set_peer_vrouter(fe->peer_vrouter()); \
120 data.set_tunnel_type(fe->tunnel_type().ToString()); \
121 data.set_enable_rpf(fe->data().enable_rpf);\
123 data.set_aging_protocol(fe->fsc()->flow_aging_key().proto);\
124 data.set_aging_port(fe->fsc()->flow_aging_key().port);\
126 data.set_l3_flow(fe->l3_flow());\
127 uint16_t id = fe->flow_table()? fe->flow_table()->table_index() : 0xFFFF;\
128 data.set_table_id(id);\
129 data.set_deleted(fe->deleted());\
130 SandeshFlowIndexInfo flow_index_info;\
131 fe->SetEventSandeshData(&flow_index_info);\
132 data.set_flow_index_info(flow_index_info); \
133 data.set_fw_policy_match(fe->fw_policy_name_uuid()); \
134 FlowEntryInfo *mgmt_info = fe->flow_mgmt_info(); \
136 const FlowMgmtKeyTree &key_tree = mgmt_info->tree(); \
137 FlowMgmtKeyTree::const_iterator kt_it = key_tree.begin(); \
138 std::vector<SandeshInetRouteFlowMgmtEntryLink> key_list;\
139 while (kt_it != key_tree.end()) { \
140 InetRouteFlowMgmtKey *key = dynamic_cast<InetRouteFlowMgmtKey *> \
149 string key_str = InetRouteFlowMgmtKeyToString(id, key);\
150 SandeshInetRouteFlowMgmtEntryLink entry;\
151 entry.set_inet_route_flow_mgmt_key(key_str);\
152 key_list.push_back(entry);\
154 data.set_inet_rt_keys(key_list);\
156 data.set_local_tag_list(fe->local_tagset());\
157 data.set_remote_tag_list(fe->remote_tagset());\
158 data.set_remote_prefix(fe->RemotePrefix());\
159 const Interface *itfe = fe->intf_entry();\
160 if (itfe && (itfe->type() == Interface::VM_INTERFACE)) {\
161 const VmInterface *vmi_e = static_cast<const VmInterface *>(itfe);\
162 data.set_vmi(vmi_e->cfg_name());\
164 data.set_underlay_gw_index(fe->data().underlay_gw_index_);\
172 MatchAclParamsList::const_iterator it;
173 std::vector<FlowAclUuid> acl;
175 for (it = acl_list.begin(); it != acl_list.end(); it++) {
180 policy->set_acl(acl);
181 policy->set_action(action);
183 std::vector<ActionStr> action_str_l;
184 for (it = acl_list.begin(); it != acl_list.end(); it++) {
186 action_info.
action = action;
189 policy->set_action_str(action_str_l);
196 data.set_policy(policy);
200 data.set_out_policy(policy);
207 data.set_out_sg(policy);
211 data.set_reverse_sg(policy);
215 data.set_reverse_out_sg(policy);
219 data.set_vrf_assign_acl(policy);
223 std::vector<ActionStr> action_str_l;
225 data.set_sg_action_summary(action_str_l);
229 data.set_mirror(policy);
233 data.set_out_mirror(policy);
237 data.set_policy_set(policy);
241 data.set_out_policy_set(policy);
245 data.set_reverse_policy_set(policy);
249 data.set_reverse_out_policy_set(policy);
252 action_str_l.clear();
254 data.set_aps_action_summary(action_str_l);
258 data.set_fwaas_policy_set(policy);
262 data.set_fwaas_out_policy_set(policy);
266 data.set_fwaas_reverse_policy_set(policy);
270 data.set_fwaas_reverse_out_policy_set(policy);
273 action_str_l.clear();
275 data.set_fwaas_action_summary(action_str_l);
284 std::string resp_ctx, std::string key):
286 0), resp_obj_(obj), resp_data_(resp_ctx),
287 flow_iteration_key_(), key_valid_(false), delete_op_(false), agent_(agent),
301 SandeshFlowData data;
303 list.push_back(data);
313 std::stringstream ss;
325 using std::istringstream;
328 size_t n = std::count(key.begin(), key.end(), ch);
332 std::stringstream ss(key);
333 string item, sip, dip;
336 if (getline(ss, item, ch)) {
339 if (getline(ss, item, ch)) {
342 if (getline(ss, item, ch)) {
345 if (getline(ss, item, ch)) {
348 if (getline(ss, item, ch)) {
349 istringstream(item) >> proto;
351 if (getline(ss, item, ch)) {
354 if (getline(ss, item, ch)) {
357 boost::system::error_code ec;
370 FlowTable::FlowEntryMap::iterator it;
371 std::vector<SandeshFlowData>& list =
372 const_cast<std::vector<SandeshFlowData>&
>(
resp_obj_->get_flow_list());
374 bool flow_key_set =
false;
377 FlowErrorResp *resp =
new FlowErrorResp();
396 FlowErrorResp *resp =
new FlowErrorResp();
402 ++partition_id_ < agent_->flow_thread_count()) {
431 if (++partition_id_ < agent_->flow_thread_count()) {
453 void NextFlowRecordsSet::HandleRequest()
const {
455 FlowRecordsResp *resp =
new FlowRecordsResp();
462 void FetchAllFlowRecords::HandleRequest()
const {
464 FlowRecordsResp *resp =
new FlowRecordsResp();
471 void DeleteAllFlowRecords::HandleRequest()
const {
472 FlowRecordsResp *resp =
new FlowRecordsResp();
477 task->set_delete_op(
true);
482 void FetchFlowRecord::HandleRequest()
const {
488 boost::system::error_code ec;
489 key.
src_addr = IpAddress::from_string(get_sip(), ec);
490 key.
dst_addr = IpAddress::from_string(get_dip(), ec);
496 key.
src_port = (unsigned)get_src_port();
497 key.
dst_port = (unsigned)get_dst_port();
500 FlowTable::FlowEntryMap::iterator it;
510 FlowRecordResp *flow_resp =
new FlowRecordResp();
517 SandeshFlowData data;
519 flow_resp->set_record(data);
522 resp =
new FlowErrorResp();
532 void FlowAgeTimeReq::HandleRequest()
const {
534 uint32_t age_time = get_new_age_time();
539 FlowAgeTimeResp *resp =
new FlowAgeTimeResp();
545 if (age_time && age_time != resp->get_old_age_time()) {
547 resp->set_new_age_time(age_time);
549 resp->set_new_age_time(resp->get_old_age_time());
552 resp->set_context(context());
553 resp->set_more(
false);
557 void FetchLinkLocalFlowInfo::HandleRequest()
const {
558 LinkLocalFlowInfoResp *resp =
new LinkLocalFlowInfoResp();
559 std::vector<LinkLocalFlowInfo> &list =
560 const_cast<std::vector<LinkLocalFlowInfo>&
>
561 (resp->get_linklocal_flow_list());
565 FlowTable::LinkLocalFlowInfoMap::const_iterator it = flow_map.begin();
566 while (it != flow_map.end()) {
567 LinkLocalFlowInfo info;
569 info.flow_index = it->second.flow_index;
570 info.source_addr = it->second.flow_key.src_addr.to_string();
571 info.dest_addr = it->second.flow_key.dst_addr.to_string();
572 info.protocol = it->second.flow_key.protocol;
573 info.source_port = it->second.flow_key.src_port;
574 info.dest_port = it->second.flow_key.dst_port;
576 list.push_back(info);
580 resp->set_context(context());
581 resp->set_more(
false);
586 std::vector<SandeshFlowData>& list =
587 const_cast<std::vector<SandeshFlowData>&
>(
resp_->get_flow_list());
589 bool flow_key_set =
false;
592 FlowErrorResp *resp =
new FlowErrorResp();
601 FlowErrorResp *resp =
new FlowErrorResp();
606 FlowTable::FlowEntryMap::iterator it;
610 FlowErrorResp *resp =
new FlowErrorResp();
616 ++partition_id_ < agent_->flow_thread_count()) {
632 std::ostringstream ostr;
635 resp_->set_flow_key(ostr.str());
638 std::ostringstream ostr;
642 resp_->set_flow_key(ostr.str());
649 if (++partition_id_ < agent_->flow_thread_count()) {
663 std::ostringstream ostr;
665 resp_->set_flow_key(ostr.str());
672 size_t n = std::count(key.begin(), key.end(),
':');
676 std::stringstream ss(key);
678 if (getline(ss, item,
':')) {
679 std::istringstream(item) >>
proto_;
681 if (getline(ss, item,
':')) {
682 std::istringstream(item) >>
port_;
684 if (getline(ss, item)) {
691 std::string resp_ctx, std::string key):
700 void ShowFlowStatsCollector::HandleRequest()
const {
702 FlowStatsCollectorRecordsResp *resp =
new FlowStatsCollectorRecordsResp();
704 std::ostringstream ostr;
705 ostr << get_protocol() <<
":" << get_port() <<
":" <<
713 void NextFlowStatsRecordsSet::HandleRequest()
const {
715 FlowStatsCollectorRecordsResp *resp =
new FlowStatsCollectorRecordsResp();
724 void SandeshFlowTableInfoRequest::HandleRequest()
const {
727 SandeshFlowTableInfoResp *resp =
new SandeshFlowTableInfoResp();
728 resp->set_flow_count(proto->
FlowCount());
732 std::vector<SandeshFlowTableInfo> info_list;
735 SandeshFlowTableInfo info;
737 info.set_count(table->
Size());
741 info_list.push_back(info);
743 resp->set_table_list(info_list);
744 resp->set_context(context());
745 resp->set_more(
false);
752 using std::istringstream;
756 size_t n = std::count(key.begin(), key.end(), ch);
760 std::stringstream ss(key);
763 uint16_t plen = 0, mgr_id = 0;
765 if (getline(ss, item, ch)) {
766 istringstream(item) >> mgr_id;
772 if (getline(ss, item, ch)) {
773 istringstream(item) >> vrf_id;
775 if (getline(ss, item, ch)) {
778 if (getline(ss, item, ch)) {
779 istringstream(item) >> plen;
781 boost::system::error_code ec;
782 IpAddress ip = IpAddress::from_string(ip_str.c_str(), ec);
790 void FlowsPerInetRouteFlowMgmtKeyReq::HandleRequest()
const {
791 FlowsPerInetRouteFlowMgmtKeyResp *resp=
new
792 FlowsPerInetRouteFlowMgmtKeyResp();
793 resp->set_context(context());
794 resp->set_more(
false);
795 std::vector<SandeshFlowData> &resp_list =
796 const_cast<std::vector<SandeshFlowData>&
>(resp->get_flow_list());
806 mgr = agent->pkt()->flow_mgmt_manager(mgr_id);
814 if (entry->
Size() == 0) {
819 FlowMgmtEntry::FlowList::const_iterator it = flow_list.begin();
820 while (it != flow_list.end()) {
823 SandeshFlowData data;
826 resp_list.push_back(data);
832 void Inet4FlowTreeReq::HandleRequest()
const {
834 std::vector<FlowMgmtManager *>::const_iterator it =
836 Inet4FlowTreeResponse *resp =
new Inet4FlowTreeResponse();
837 std::vector<SandeshInetRouteFlowMgmtEntryLink> &resp_list =
838 const_cast<std::vector<SandeshInetRouteFlowMgmtEntryLink>&
>
840 uint16_t mgr_idx = 0;
846 FlowMgmtTree::Tree::iterator tree_it = list.begin();
847 while(tree_it != list.end()) {
851 SandeshInetRouteFlowMgmtEntryLink entry;
852 entry.set_inet_route_flow_mgmt_key(key_str);
853 resp_list.push_back(entry);
858 resp->set_context(context());
859 resp->set_more(
false);
863 void SNatPortConfigRequest::HandleRequest()
const {
868 SNatPortResponse *resp =
new SNatPortResponse();
869 std::vector<PortConfigData> &config_list =
870 const_cast<std::vector<PortConfigData>&
>(resp->get_port_config_list());
872 for(uint16_t protocol = 0; protocol < IPPROTO_MAX; protocol++) {
882 spc.protocol = protocol;
884 std::vector<PortConfig::PortRange>::const_iterator it =
888 pcr.port_start = it->port_start;
889 pcr.port_end = it->port_end;
890 spc.port_range.push_back(pcr);
894 config_list.push_back(spc);
896 resp->set_context(context());
897 resp->set_more(
false);
902 bool match_proto,
bool match_port,
903 std::string context) {
908 SNatPortFlowResponse *resp =
new SNatPortFlowResponse();
909 std::vector<SNatPortFlow> &list =
910 const_cast<std::vector<SNatPortFlow>&
>(resp->get_port_flow_list());
912 uint16_t flow_count = 0;
913 uint16_t next_port = 0;
915 for(; proto < IPPROTO_MAX; proto++) {
918 if (match_proto && proto != protocol) {
922 if (proto < protocol) {
931 std::vector<uint16_t>::const_iterator it = ports.begin();
932 for(; it != ports.end(); it++) {
933 if (match_port && port != *it) {
937 if (match_port && port > *it) {
945 std::vector<FlowKey> flow_list;
947 flow_count += flow_list.size();
951 snf.protocol = proto;
952 std::vector<FlowKey>::iterator flow_it = flow_list.begin();
953 for (; flow_it != flow_list.end(); flow_it++) {
954 SNatFlowKey flow_key;
955 flow_key.nh = flow_it->nh;
956 flow_key.sip = flow_it->src_addr.to_string();
957 flow_key.dip = flow_it->dst_addr.to_string();
958 flow_key.src_port = flow_it->src_port;
959 flow_key.dst_port = flow_it->dst_port;
960 flow_key.protocol = flow_it->protocol;
961 snf.flows.push_back(flow_key);
966 if (flow_count >= 1) {
971 if (it != ports.end() && match_port ==
false) {
975 if (match_port ==
false) {
979 if (flow_count >= 1) {
985 if (match_proto && next_port == 0) {
989 if (proto == IPPROTO_MAX) {
994 std::stringstream str;
995 str << proto <<
":" << next_port <<
":" << match_proto
996 <<
":" << match_port;
997 resp->set_flow_key(str.str());
1000 resp->set_context(context);
1001 resp->set_more(
false);
1005 void SNatPerPortFlowList::HandleRequest()
const {
1006 bool match_proto =
false;
1007 if (protocol != 0) {
1011 bool match_port =
false;
1020 void NextPerPortFlowList::HandleRequest()
const {
1021 using std::istringstream;
1025 bool match_proto =
false;
1026 bool match_port =
false;
1029 std::stringstream ss(port_key);
1031 const char ch =
':';
1033 size_t n = std::count(port_key.begin(), port_key.end(), ch);
1038 if (getline(ss, item, ch)) {
1039 istringstream(item) >> proto;
1041 if (getline(ss, item, ch)) {
1042 istringstream(item) >> port;
1044 if (getline(ss, item, ch)) {
1045 istringstream(item) >> match_proto;
1047 if (getline(ss, item, ch)) {
1048 istringstream(item) >> match_port;
1055 FlowErrorResp *resp =
new FlowErrorResp();
1056 resp->set_context(context());
1057 resp->set_more(
false);
boost::asio::ip::address IpAddress
uint64_t flow_created() const
uint64_t flow_aged() const
uint64_t max_flow_count() const
FlowStatsManager * flow_stats_manager() const
uint16_t flow_thread_count() const
static const std::string & NullString()
static Agent * GetInstance()
AgentStats * stats() const
uint32_t total_free() const
uint32_t free_count() const
uint32_t total_alloc() const
const FlowKey & key() const
const std::string & nw_ace_uuid() const
const std::string & sg_rule_uuid() const
const MatchPolicy & match_p() const
FlowStatsCollector * fsc() const
boost::intrusive::list< FlowMgmtKeyNode, Node > FlowList
const FlowList & flow_list() const
FlowEntry * flow_entry() const
InetRouteFlowMgmtTree * ip4_route_flow_mgmt_tree()
FlowMgmtEntry * Find(FlowMgmtKey *key)
std::map< FlowMgmtKey *, FlowMgmtEntry *, FlowMgmtKeyCmp > Tree
FlowTable * GetTable(uint16_t index) const
uint32_t flow_table_count() const
uint32_t FlowCount() const
PortTableManager * port_table_manager()
void UpdateAgeTimeInSeconds(uint32_t age_time)
uint32_t GetAgeTimeInSeconds() const
bool FindFlowExportInfo(const FlowEntry *fe, FlowEntryTree::iterator &it)
const FlowStatsCollectorObject * Find(uint32_t proto, uint32_t port) const
FlowStatsCollectorObject * default_flow_stats_collector_obj()
const LinkLocalFlowInfoMap & linklocal_flow_info_map()
uint16_t table_index() const
FlowEntryFreeList * free_list()
std::map< int, LinkLocalFlowInfo > LinkLocalFlowInfoMap
FlowEntryMap flow_entry_map_
FlowProto * get_flow_proto() const
FlowMgmtManagerList flow_mgmt_manager_list() const
std::vector< FlowMgmtManager * >::const_iterator flow_mgmt_manager_iterator_begin() const
std::vector< FlowMgmtManager * >::const_iterator flow_mgmt_manager_iterator_end() const
FlowTable * flow_table(uint16_t index) const
virtual bool Run()
Code to execute in a task. Returns true if task is completed. Return false to reschedule the task.
bool SetProto(std::string &key)
FlowStatsCollectorRecordsResp * resp_
PktSandeshFlowStats(Agent *agent, FlowStatsCollectorRecordsResp *obj, std::string resp_ctx, std::string key)
static const std::string start_key
FlowKey flow_iteration_key_
static const int kMaxFlowResponse
virtual ~PktSandeshFlow()
void SetSandeshFlowData(std::vector< SandeshFlowData > &list, FlowEntry *fe, const FlowExportInfo *info)
static std::string GetFlowKey(const FlowKey &key, uint16_t partition_id)
virtual bool Run()
Code to execute in a task. Returns true if task is completed. Return false to reschedule the task.
bool SetFlowKey(std::string key)
PktSandeshFlow(Agent *agent, FlowRecordsResp *obj, std::string resp_ctx, std::string key)
void SendResponse(SandeshResponse *resp)
static const char kDelimiter
FlowRecordsResp * resp_obj_
const PortTable * GetPortTable(uint8_t proto)
void GetFlowKeyList(uint16_t port, std::vector< FlowKey > &key) const
std::vector< uint16_t > GetPortList() const
const PortConfig * port_config() const
virtual void set_more(const bool val)=0
void set_context(std::string context)
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
void Enqueue(Task *task)
Enqueues a task for running. Starts task if all policy rules are met else puts task in waitq....
static TaskScheduler * GetInstance()
Task is a class to describe a computational task within OpenSDN control plane applications....
void SetActionStr(const FlowAction &action_info, std::vector< ActionStr > &action_str_l)
std::list< MatchAclParams > MatchAclParamsList
static void SetAclInfo(SandeshFlowData &data, FlowEntry *fe)
static void HandlePortFlowReq(uint16_t protocol, uint16_t port, bool match_proto, bool match_port, std::string context)
static InetRouteFlowMgmtKey * StringToInetRouteFlowMgmtKey(const string &key, uint16_t *id)
#define SET_SANDESH_FLOW_DATA(agent, data, fe, info)
static string InetRouteFlowMgmtKeyToString(uint16_t id, InetRouteFlowMgmtKey *key)
static void SetOneAclInfo(FlowAclInfo *policy, uint32_t action, const MatchAclParamsList &acl_list)
static std::string UuidToString(const boost::uuids::uuid &id)
static const std::string integerToString(const NumberType &num)
uint32_t out_mirror_action
MatchAclParamsList m_mirror_acl_l
MatchAclParamsList m_vrf_assign_acl_l
SessionPolicy fwaas_policy
MatchAclParamsList m_out_acl_l
MatchAclParamsList m_out_mirror_acl_l
MatchAclParamsList m_acl_l
uint32_t vrf_assign_acl_action
uint32_t out_policy_action
std::vector< PortRange > port_range
uint32_t reverse_out_action
MatchAclParamsList m_reverse_out_acl_l
MatchAclParamsList m_reverse_acl_l
MatchAclParamsList m_acl_l
MatchAclParamsList m_out_acl_l
static boost::posix_time::ptime UTCUsecToPTime(uint64_t tusec)