10 #include <boost/date_time/posix_time/posix_time.hpp>
23 uint16_t plen = key->
plen();
31 #define SET_SANDESH_FLOW_DATA(agent, data, fe, info) \
32 data.set_vrf(fe->data().vrf); \
33 data.set_sip(fe->key().src_addr.to_string()); \
34 data.set_dip(fe->key().dst_addr.to_string()); \
35 data.set_src_port((unsigned)fe->key().src_port); \
36 data.set_dst_port((unsigned)fe->key().dst_port); \
37 data.set_protocol(fe->key().protocol); \
38 data.set_dest_vrf(fe->data().dest_vrf); \
39 data.set_uuid(UuidToString(fe->uuid())); \
40 data.set_action(fe->match_p().action_info.action); \
41 std::vector<ActionStr> action_str_l; \
42 SetActionStr(fe->match_p().action_info, action_str_l); \
43 if ((fe->match_p().action_info.action & TrafficAction::DROP_FLAGS) != 0) {\
44 data.set_drop_reason(fe->DropReasonStr(fe->data().drop_reason)); \
46 data.set_action_str(action_str_l); \
47 std::vector<MirrorActionSpec>::const_iterator mait; \
48 std::vector<MirrorInfo> mirror_l; \
49 for (mait = fe->match_p().action_info.mirror_l.begin(); \
50 mait != fe->match_p().action_info.mirror_l.end(); \
53 minfo.set_mirror_destination((*mait).ip.to_string()); \
54 minfo.set_mirror_port((*mait).port); \
55 mirror_l.push_back(minfo); \
57 data.set_mirror_l(mirror_l); \
58 if (fe->is_flags_set(FlowEntry::IngressDir)) { \
59 data.set_direction("ingress"); \
61 data.set_direction("egress"); \
64 data.set_stats_bytes(info->bytes()); \
65 data.set_stats_packets(info->packets()); \
67 if (fe->is_flags_set(FlowEntry::NatFlow)) { \
68 data.set_nat("enabled"); \
70 data.set_nat("disabled"); \
72 data.set_gen_id(fe->gen_id()); \
73 data.set_flow_handle(fe->flow_handle()); \
74 data.set_refcount(fe->GetRefCount()); \
75 data.set_implicit_deny(fe->ImplicitDenyFlow() ? "yes" : "no"); \
76 data.set_short_flow( \
77 fe->is_flags_set(FlowEntry::ShortFlow) ? \
78 string("yes (") + fe->DropReasonStr(fe->short_flow_reason()) + \
80 data.set_local_flow(fe->is_flags_set(FlowEntry::LocalFlow) ? "yes" : "no"); \
81 if (!fe->data().OriginVnSrcList().empty()) { \
82 data.set_src_vn_list(fe->data().OriginVnSrcList()); \
84 data.set_src_vn_list(fe->data().SourceVnList()); \
86 if (!fe->data().OriginVnDstList().empty()) { \
87 data.set_dst_vn_list(fe->data().OriginVnDstList()); \
89 data.set_dst_vn_list(fe->data().DestinationVnList()); \
91 if (!fe->data().origin_vn_src.empty()) { \
92 data.set_src_vn_match(fe->data().origin_vn_src); \
94 data.set_src_vn_match(fe->data().source_vn_match); \
96 if (!fe->data().origin_vn_dst.empty()) { \
97 data.set_dst_vn_match(fe->data().origin_vn_dst); \
99 data.set_dst_vn_match(fe->data().dest_vn_match); \
101 if (fe->is_flags_set(FlowEntry::EcmpFlow) && \
102 fe->data().component_nh_idx != CompositeNH::kInvalidComponentNHIdx) { \
103 data.set_ecmp_index(fe->data().component_nh_idx); \
105 data.set_reverse_flow(fe->is_flags_set(FlowEntry::ReverseFlow) ? "yes" : "no"); \
106 Ip4Address fip(fe->fip()); \
107 data.set_fip(fip.to_string()); \
108 uint32_t fip_intf_id = fe->InterfaceKeyToId(agent, fe->fip_vmi()); \
109 data.set_fip_vm_interface_idx(fip_intf_id); \
110 SetAclInfo(data, fe); \
111 data.set_nh(fe->key().nh); \
112 if (fe->data().src_ip_nh.get() != NULL) { \
113 data.set_src_ip_nh(fe->data().src_ip_nh.get()->id()); \
115 if (fe->data().rpf_nh.get() != NULL) { \
116 data.set_rpf_nh(fe->data().rpf_nh.get()->id()); \
118 data.set_peer_vrouter(fe->peer_vrouter()); \
119 data.set_tunnel_type(fe->tunnel_type().ToString()); \
120 data.set_enable_rpf(fe->data().enable_rpf);\
122 data.set_aging_protocol(fe->fsc()->flow_aging_key().proto);\
123 data.set_aging_port(fe->fsc()->flow_aging_key().port);\
125 data.set_l3_flow(fe->l3_flow());\
126 uint16_t id = fe->flow_table()? fe->flow_table()->table_index() : 0xFFFF;\
127 data.set_table_id(id);\
128 data.set_deleted(fe->deleted());\
129 SandeshFlowIndexInfo flow_index_info;\
130 fe->SetEventSandeshData(&flow_index_info);\
131 data.set_flow_index_info(flow_index_info); \
132 data.set_fw_policy_match(fe->fw_policy_name_uuid()); \
133 FlowEntryInfo *mgmt_info = fe->flow_mgmt_info(); \
135 const FlowMgmtKeyTree &key_tree = mgmt_info->tree(); \
136 FlowMgmtKeyTree::const_iterator kt_it = key_tree.begin(); \
137 std::vector<SandeshInetRouteFlowMgmtEntryLink> key_list;\
138 while (kt_it != key_tree.end()) { \
139 InetRouteFlowMgmtKey *key = dynamic_cast<InetRouteFlowMgmtKey *> \
148 string key_str = InetRouteFlowMgmtKeyToString(id, key);\
149 SandeshInetRouteFlowMgmtEntryLink entry;\
150 entry.set_inet_route_flow_mgmt_key(key_str);\
151 key_list.push_back(entry);\
153 data.set_inet_rt_keys(key_list);\
155 data.set_local_tag_list(fe->local_tagset());\
156 data.set_remote_tag_list(fe->remote_tagset());\
157 data.set_remote_prefix(fe->RemotePrefix());\
158 const Interface *itfe = fe->intf_entry();\
159 if (itfe && (itfe->type() == Interface::VM_INTERFACE)) {\
160 const VmInterface *vmi_e = static_cast<const VmInterface *>(itfe);\
161 data.set_vmi(vmi_e->cfg_name());\
163 data.set_underlay_gw_index(fe->data().underlay_gw_index_);\
171 MatchAclParamsList::const_iterator it;
172 std::vector<FlowAclUuid> acl;
174 for (it = acl_list.begin(); it != acl_list.end(); it++) {
179 policy->set_acl(acl);
180 policy->set_action(action);
182 std::vector<ActionStr> action_str_l;
183 for (it = acl_list.begin(); it != acl_list.end(); it++) {
185 action_info.
action = action;
188 policy->set_action_str(action_str_l);
195 data.set_policy(policy);
199 data.set_out_policy(policy);
206 data.set_out_sg(policy);
210 data.set_reverse_sg(policy);
214 data.set_reverse_out_sg(policy);
218 data.set_vrf_assign_acl(policy);
222 std::vector<ActionStr> action_str_l;
224 data.set_sg_action_summary(action_str_l);
228 data.set_mirror(policy);
232 data.set_out_mirror(policy);
236 data.set_policy_set(policy);
240 data.set_out_policy_set(policy);
244 data.set_reverse_policy_set(policy);
248 data.set_reverse_out_policy_set(policy);
251 action_str_l.clear();
253 data.set_aps_action_summary(action_str_l);
257 data.set_fwaas_policy_set(policy);
261 data.set_fwaas_out_policy_set(policy);
265 data.set_fwaas_reverse_policy_set(policy);
269 data.set_fwaas_reverse_out_policy_set(policy);
272 action_str_l.clear();
274 data.set_fwaas_action_summary(action_str_l);
283 std::string resp_ctx, std::string key):
285 0), resp_obj_(obj), resp_data_(resp_ctx),
286 flow_iteration_key_(), key_valid_(false), delete_op_(false), agent_(agent),
300 SandeshFlowData data;
302 list.push_back(data);
312 std::stringstream ss;
317 ss << (uint16_t)key.
protocol << kDelimiter;
324 using std::istringstream;
327 size_t n = std::count(key.begin(), key.end(), ch);
331 std::stringstream ss(key);
332 string item, sip, dip;
335 if (getline(ss, item, ch)) {
338 if (getline(ss, item, ch)) {
341 if (getline(ss, item, ch)) {
344 if (getline(ss, item, ch)) {
347 if (getline(ss, item, ch)) {
348 istringstream(item) >> proto;
350 if (getline(ss, item, ch)) {
353 if (getline(ss, item, ch)) {
356 boost::system::error_code ec;
369 FlowTable::FlowEntryMap::iterator it;
370 std::vector<SandeshFlowData>& list =
371 const_cast<std::vector<SandeshFlowData>&
>(
resp_obj_->get_flow_list());
373 bool flow_key_set =
false;
376 FlowErrorResp *resp =
new FlowErrorResp();
395 FlowErrorResp *resp =
new FlowErrorResp();
430 if (++partition_id_ < agent_->flow_thread_count()) {
452 void NextFlowRecordsSet::HandleRequest()
const {
454 FlowRecordsResp *resp =
new FlowRecordsResp();
461 void FetchAllFlowRecords::HandleRequest()
const {
463 FlowRecordsResp *resp =
new FlowRecordsResp();
470 void DeleteAllFlowRecords::HandleRequest()
const {
471 FlowRecordsResp *resp =
new FlowRecordsResp();
481 void FetchFlowRecord::HandleRequest()
const {
487 boost::system::error_code ec;
488 key.
src_addr = IpAddress::from_string(get_sip(), ec);
489 key.
dst_addr = IpAddress::from_string(get_dip(), ec);
495 key.
src_port = (unsigned)get_src_port();
496 key.
dst_port = (unsigned)get_dst_port();
499 FlowTable::FlowEntryMap::iterator it;
509 FlowRecordResp *flow_resp =
new FlowRecordResp();
516 SandeshFlowData data;
518 flow_resp->set_record(data);
521 resp =
new FlowErrorResp();
531 void FlowAgeTimeReq::HandleRequest()
const {
533 uint32_t age_time = get_new_age_time();
538 FlowAgeTimeResp *resp =
new FlowAgeTimeResp();
544 if (age_time && age_time != resp->get_old_age_time()) {
546 resp->set_new_age_time(age_time);
548 resp->set_new_age_time(resp->get_old_age_time());
551 resp->set_context(context());
552 resp->set_more(
false);
556 void FetchLinkLocalFlowInfo::HandleRequest()
const {
557 LinkLocalFlowInfoResp *resp =
new LinkLocalFlowInfoResp();
558 std::vector<LinkLocalFlowInfo> &list =
559 const_cast<std::vector<LinkLocalFlowInfo>&
>
560 (resp->get_linklocal_flow_list());
564 FlowTable::LinkLocalFlowInfoMap::const_iterator it = flow_map.begin();
565 while (it != flow_map.end()) {
566 LinkLocalFlowInfo info;
568 info.flow_index = it->second.flow_index;
569 info.source_addr = it->second.flow_key.src_addr.to_string();
570 info.dest_addr = it->second.flow_key.dst_addr.to_string();
571 info.protocol = it->second.flow_key.protocol;
572 info.source_port = it->second.flow_key.src_port;
573 info.dest_port = it->second.flow_key.dst_port;
575 list.push_back(info);
579 resp->set_context(context());
580 resp->set_more(
false);
585 std::vector<SandeshFlowData>& list =
586 const_cast<std::vector<SandeshFlowData>&
>(
resp_->get_flow_list());
588 bool flow_key_set =
false;
591 FlowErrorResp *resp =
new FlowErrorResp();
600 FlowErrorResp *resp =
new FlowErrorResp();
605 FlowTable::FlowEntryMap::iterator it;
609 FlowErrorResp *resp =
new FlowErrorResp();
631 std::ostringstream ostr;
634 resp_->set_flow_key(ostr.str());
637 std::ostringstream ostr;
641 resp_->set_flow_key(ostr.str());
648 if (++partition_id_ < agent_->flow_thread_count()) {
662 std::ostringstream ostr;
664 resp_->set_flow_key(ostr.str());
671 size_t n = std::count(key.begin(), key.end(),
':');
675 std::stringstream ss(key);
677 if (getline(ss, item,
':')) {
678 std::istringstream(item) >>
proto_;
680 if (getline(ss, item,
':')) {
681 std::istringstream(item) >>
port_;
683 if (getline(ss, item)) {
690 std::string resp_ctx, std::string key):
699 void ShowFlowStatsCollector::HandleRequest()
const {
701 FlowStatsCollectorRecordsResp *resp =
new FlowStatsCollectorRecordsResp();
703 std::ostringstream ostr;
704 ostr << get_protocol() <<
":" << get_port() <<
":" <<
709 scheduler->Enqueue(task);
712 void NextFlowStatsRecordsSet::HandleRequest()
const {
714 FlowStatsCollectorRecordsResp *resp =
new FlowStatsCollectorRecordsResp();
723 void SandeshFlowTableInfoRequest::HandleRequest()
const {
726 SandeshFlowTableInfoResp *resp =
new SandeshFlowTableInfoResp();
727 resp->set_flow_count(proto->
FlowCount());
731 std::vector<SandeshFlowTableInfo> info_list;
734 SandeshFlowTableInfo info;
736 info.set_count(table->
Size());
740 info_list.push_back(info);
742 resp->set_table_list(info_list);
743 resp->set_context(context());
744 resp->set_more(
false);
751 using std::istringstream;
755 size_t n = std::count(key.begin(), key.end(), ch);
759 std::stringstream ss(key);
762 uint16_t plen = 0, mgr_id = 0;
764 if (getline(ss, item, ch)) {
765 istringstream(item) >> mgr_id;
771 if (getline(ss, item, ch)) {
772 istringstream(item) >> vrf_id;
774 if (getline(ss, item, ch)) {
777 if (getline(ss, item, ch)) {
778 istringstream(item) >> plen;
780 boost::system::error_code ec;
781 IpAddress ip = IpAddress::from_string(ip_str.c_str(), ec);
789 void FlowsPerInetRouteFlowMgmtKeyReq::HandleRequest()
const {
790 FlowsPerInetRouteFlowMgmtKeyResp *resp=
new
791 FlowsPerInetRouteFlowMgmtKeyResp();
792 resp->set_context(context());
793 resp->set_more(
false);
794 std::vector<SandeshFlowData> &resp_list =
795 const_cast<std::vector<SandeshFlowData>&
>(resp->get_flow_list());
805 mgr = agent->pkt()->flow_mgmt_manager(mgr_id);
813 if (entry->
Size() == 0) {
818 FlowMgmtEntry::FlowList::const_iterator it = flow_list.begin();
819 while (it != flow_list.end()) {
822 SandeshFlowData data;
825 resp_list.push_back(data);
831 void Inet4FlowTreeReq::HandleRequest()
const {
833 std::vector<FlowMgmtManager *>::const_iterator it =
835 Inet4FlowTreeResponse *resp =
new Inet4FlowTreeResponse();
836 std::vector<SandeshInetRouteFlowMgmtEntryLink> &resp_list =
837 const_cast<std::vector<SandeshInetRouteFlowMgmtEntryLink>&
>
839 uint16_t mgr_idx = 0;
845 FlowMgmtTree::Tree::iterator tree_it = list.begin();
846 while(tree_it != list.end()) {
850 SandeshInetRouteFlowMgmtEntryLink entry;
851 entry.set_inet_route_flow_mgmt_key(key_str);
852 resp_list.push_back(entry);
857 resp->set_context(context());
858 resp->set_more(
false);
862 void SNatPortConfigRequest::HandleRequest()
const {
867 SNatPortResponse *resp =
new SNatPortResponse();
868 std::vector<PortConfigData> &config_list =
869 const_cast<std::vector<PortConfigData>&
>(resp->get_port_config_list());
871 for(uint16_t protocol = 0; protocol < IPPROTO_MAX; protocol++) {
881 spc.protocol = protocol;
883 std::vector<PortConfig::PortRange>::const_iterator it =
887 pcr.port_start = it->port_start;
888 pcr.port_end = it->port_end;
889 spc.port_range.push_back(pcr);
893 config_list.push_back(spc);
895 resp->set_context(context());
896 resp->set_more(
false);
901 bool match_proto,
bool match_port,
902 std::string context) {
907 SNatPortFlowResponse *resp =
new SNatPortFlowResponse();
908 std::vector<SNatPortFlow> &list =
909 const_cast<std::vector<SNatPortFlow>&
>(resp->get_port_flow_list());
911 uint16_t flow_count = 0;
912 uint16_t next_port = 0;
914 for(; proto < IPPROTO_MAX; proto++) {
917 if (match_proto && proto != protocol) {
921 if (proto < protocol) {
930 std::vector<uint16_t>::const_iterator it = ports.begin();
931 for(; it != ports.end(); it++) {
932 if (match_port && port != *it) {
936 if (match_port && port > *it) {
944 std::vector<FlowKey> flow_list;
946 flow_count += flow_list.size();
950 snf.protocol = proto;
951 std::vector<FlowKey>::iterator flow_it = flow_list.begin();
952 for (; flow_it != flow_list.end(); flow_it++) {
953 SNatFlowKey flow_key;
954 flow_key.nh = flow_it->nh;
955 flow_key.sip = flow_it->src_addr.to_string();
956 flow_key.dip = flow_it->dst_addr.to_string();
957 flow_key.src_port = flow_it->src_port;
958 flow_key.dst_port = flow_it->dst_port;
959 flow_key.protocol = flow_it->protocol;
960 snf.flows.push_back(flow_key);
965 if (flow_count >= 1) {
970 if (it != ports.end() && match_port ==
false) {
974 if (match_port ==
false) {
978 if (flow_count >= 1) {
984 if (match_proto && next_port == 0) {
988 if (proto == IPPROTO_MAX) {
993 std::stringstream str;
994 str << proto <<
":" << next_port <<
":" << match_proto
995 <<
":" << match_port;
996 resp->set_flow_key(str.str());
999 resp->set_context(context);
1000 resp->set_more(
false);
1004 void SNatPerPortFlowList::HandleRequest()
const {
1005 bool match_proto =
false;
1006 if (protocol != 0) {
1010 bool match_port =
false;
1019 void NextPerPortFlowList::HandleRequest()
const {
1020 using std::istringstream;
1024 bool match_proto =
false;
1025 bool match_port =
false;
1028 std::stringstream ss(port_key);
1030 const char ch =
':';
1032 size_t n = std::count(port_key.begin(), port_key.end(), ch);
1037 if (getline(ss, item, ch)) {
1038 istringstream(item) >> proto;
1040 if (getline(ss, item, ch)) {
1041 istringstream(item) >> port;
1043 if (getline(ss, item, ch)) {
1044 istringstream(item) >> match_proto;
1046 if (getline(ss, item, ch)) {
1047 istringstream(item) >> match_port;
1054 FlowErrorResp *resp =
new FlowErrorResp();
1055 resp->set_context(context());
1056 resp->set_more(
false);
virtual bool Run()
Code to execute. Returns true if task is completed. Return false to reschedule the task...
void SendResponse(SandeshResponse *resp)
FlowRecordsResp * resp_obj_
FlowEntryMap flow_entry_map_
MatchAclParamsList m_reverse_acl_l
static Agent * GetInstance()
#define SET_SANDESH_FLOW_DATA(agent, data, fe, info)
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
std::vector< FlowMgmtManager * >::const_iterator flow_mgmt_manager_iterator_end() const
static InetRouteFlowMgmtKey * StringToInetRouteFlowMgmtKey(const string &key, uint16_t *id)
FlowStatsManager * flow_stats_manager() const
static std::string GetFlowKey(const FlowKey &key, uint16_t partition_id)
static const char kDelimiter
static void HandlePortFlowReq(uint16_t protocol, uint16_t port, bool match_proto, bool match_port, std::string context)
bool SetFlowKey(std::string key)
MatchAclParamsList m_vrf_assign_acl_l
FlowMgmtEntry * Find(FlowMgmtKey *key)
uint32_t flow_table_count() const
uint32_t vrf_assign_acl_action
MatchAclParamsList m_acl_l
boost::asio::ip::address IpAddress
AgentStats * stats() const
FlowTable * flow_table(uint16_t index) const
uint64_t flow_created() const
uint16_t table_index() const
static void SetOneAclInfo(FlowAclInfo *policy, uint32_t action, const MatchAclParamsList &acl_list)
static std::string UuidToString(const boost::uuids::uuid &id)
PortTableManager * port_table_manager()
void SetActionStr(const FlowAction &action_info, std::vector< ActionStr > &action_str_l)
void set_delete_op(bool delete_op)
static const std::string start_key
uint32_t total_alloc() const
uint32_t out_mirror_action
const std::string & sg_rule_uuid() const
InetRouteFlowMgmtTree * ip4_route_flow_mgmt_tree()
uint64_t flow_aged() const
MatchAclParamsList m_out_mirror_acl_l
const FlowKey & key() const
FlowTable * GetTable(uint16_t index) const
void UpdateAgeTimeInSeconds(uint32_t age_time)
static const std::string integerToString(const NumberType &num)
boost::intrusive::list< FlowMgmtKeyNode, Node > FlowList
static TaskScheduler * GetInstance()
void Enqueue(Task *task)
Enqueues a task for running. Starts task if all policy rules are met else puts task in waitq...
SessionPolicy fwaas_policy
MatchAclParamsList m_acl_l
MatchAclParamsList m_reverse_out_acl_l
uint32_t free_count() const
static boost::posix_time::ptime UTCUsecToPTime(uint64_t tusec)
uint32_t out_policy_action
static const std::string & NullString()
static const int kMaxFlowResponse
PktSandeshFlowStats(Agent *agent, FlowStatsCollectorRecordsResp *obj, std::string resp_ctx, std::string key)
uint64_t max_flow_count() const
const LinkLocalFlowInfoMap & linklocal_flow_info_map()
const PortConfig * port_config() const
std::map< int, LinkLocalFlowInfo > LinkLocalFlowInfoMap
const FlowList & flow_list() const
const PortTable * GetPortTable(uint8_t proto)
FlowProto * get_flow_proto() const
static string InetRouteFlowMgmtKeyToString(uint16_t id, InetRouteFlowMgmtKey *key)
std::vector< FlowMgmtManager * >::const_iterator flow_mgmt_manager_iterator_begin() const
static void SetAclInfo(SandeshFlowData &data, FlowEntry *fe)
MatchAclParamsList m_mirror_acl_l
uint32_t FlowCount() const
MatchAclParamsList m_out_acl_l
MatchAclParamsList m_out_acl_l
void set_context(std::string context)
bool SetProto(std::string &key)
uint32_t total_free() const
std::list< MatchAclParams > MatchAclParamsList
std::vector< uint16_t > GetPortList() const
FlowStatsCollectorRecordsResp * resp_
FlowKey flow_iteration_key_
const std::string & nw_ace_uuid() const
FlowMgmtManagerList flow_mgmt_manager_list() const
uint32_t reverse_out_action
virtual bool Run()
Code to execute. Returns true if task is completed. Return false to reschedule the task...
PktSandeshFlow(Agent *agent, FlowRecordsResp *obj, std::string resp_ctx, std::string key)
FlowEntry * flow_entry() const
uint16_t flow_thread_count() const
void SetSandeshFlowData(std::vector< SandeshFlowData > &list, FlowEntry *fe, const FlowExportInfo *info)
std::map< FlowMgmtKey *, FlowMgmtEntry *, FlowMgmtKeyCmp > Tree
Task is a wrapper over tbb::task to support policies.
const MatchPolicy & match_p() const
std::vector< PortRange > port_range
const FlowStatsCollectorObject * Find(uint32_t proto, uint32_t port) const
virtual void set_more(const bool val)=0
FlowEntryFreeList * free_list()
bool FindFlowExportInfo(const FlowEntry *fe, FlowEntryTree::iterator &it)
virtual ~PktSandeshFlow()
void GetFlowKeyList(uint16_t port, std::vector< FlowKey > &key) const
uint32_t GetAgeTimeInSeconds() const
FlowStatsCollector * fsc() const
FlowStatsCollectorObject * default_flow_stats_collector_obj()