@@ -52,30 +52,39 @@ class ContractStatsManagerFixture : public PolicyStatsManagerFixture {
52
52
53
53
public:
54
54
ContractStatsManagerFixture () : PolicyStatsManagerFixture(),
55
+ intFlowManager (agent, switchManager, idGen,
56
+ ctZoneManager, tunnelEpManager),
55
57
contractStatsManager(&agent, idGen,
56
58
switchManager, 10 ),
57
59
policyManager(agent.getPolicyManager()) {
60
+ switchManager.setMaxFlowTables (IntFlowManager::NUM_FLOW_TABLES);
61
+ intFlowManager.start ();
58
62
createObjects ();
59
63
createPolicyObjects ();
60
64
idGen.initNamespace (" l24classifierRule" );
61
65
idGen.initNamespace (" routingDomain" );
62
66
switchManager.setMaxFlowTables (IntFlowManager::NUM_FLOW_TABLES);
63
67
}
64
68
virtual ~ContractStatsManagerFixture () {
69
+ intFlowManager.stop ();
65
70
stop ();
66
71
}
67
72
void verifyRoutingDomainDropStats (shared_ptr<RoutingDomain> rd,
68
73
uint32_t packet_count,
69
74
uint32_t byte_count);
75
+ void waitForRdDropEntry (void );
70
76
#ifdef HAVE_PROMETHEUS_SUPPORT
71
77
virtual void verifyPromMetrics (shared_ptr<L24Classifier> classifier,
72
78
uint32_t pkts,
73
79
uint32_t bytes,
74
80
bool isTx=false ) override ;
81
+ void verifyRdDropPromMetrics (uint32_t pkts, uint32_t bytes);
75
82
#endif
83
+ IntFlowManager intFlowManager;
76
84
ContractStatsManager contractStatsManager;
77
85
PolicyManager& policyManager;
78
86
private:
87
+ bool checkNewFlowMapSize (size_t pol_table_size);
79
88
};
80
89
81
90
#ifdef HAVE_PROMETHEUS_SUPPORT
@@ -103,6 +112,23 @@ verifyPromMetrics (shared_ptr<L24Classifier> classifier,
103
112
pos = output.find (s_bytes);
104
113
BOOST_CHECK_NE (pos, std::string::npos);
105
114
}
115
+
116
+ void ContractStatsManagerFixture::
117
+ verifyRdDropPromMetrics (uint32_t pkts,
118
+ uint32_t bytes)
119
+ {
120
+ const std::string& s_pkts = " opflex_policy_drop_packets{routing_domain=\" tenant0:rd0\" } " \
121
+ + boost::lexical_cast<std::string>(pkts) + " .000000" ;
122
+ const std::string& s_bytes = " opflex_policy_drop_bytes{routing_domain=\" tenant0:rd0\" } " \
123
+ + boost::lexical_cast<std::string>(bytes) + " .000000" ;
124
+
125
+ const std::string& output = BaseFixture::getOutputFromCommand (cmd);
126
+ size_t pos = std::string::npos;
127
+ pos = output.find (s_pkts);
128
+ BOOST_CHECK_NE (pos, std::string::npos);
129
+ pos = output.find (s_bytes);
130
+ BOOST_CHECK_NE (pos, std::string::npos);
131
+ }
106
132
#endif
107
133
108
134
void ContractStatsManagerFixture::
@@ -115,21 +141,26 @@ verifyRoutingDomainDropStats(shared_ptr<RoutingDomain> rd,
115
141
116
142
auto uuid =
117
143
boost::lexical_cast<string>(contractStatsManager.getAgentUUID ());
144
+ WAIT_FOR_DO_ONFAIL (su.get ()->resolveGbpeRoutingDomainDropCounter (uuid,
145
+ contractStatsManager.getCurrDropGenId (),
146
+ rd->getURI ().toString ()),
147
+ 500 ,, LOG (ERROR) << " Obj not resolved" ;);
118
148
optional<shared_ptr<RoutingDomainDropCounter> > myCounter =
119
149
su.get ()->resolveGbpeRoutingDomainDropCounter (uuid,
120
150
contractStatsManager
121
151
.getCurrDropGenId (),
122
152
rd->getURI ().toString ());
123
- if (myCounter) {
124
- BOOST_CHECK_EQUAL (myCounter.get ()->getPackets ().get (),
125
- packet_count);
126
- BOOST_CHECK_EQUAL (myCounter.get ()->getBytes ().get (),
127
- byte_count);
128
- }
153
+ BOOST_CHECK (myCounter);
154
+ BOOST_CHECK_EQUAL (myCounter.get ()->getPackets ().get (), packet_count);
155
+ BOOST_CHECK_EQUAL (myCounter.get ()->getBytes ().get (), byte_count);
156
+
157
+ #ifdef HAVE_PROMETHEUS_SUPPORT
158
+ verifyRdDropPromMetrics (packet_count, byte_count);
159
+ #endif
129
160
}
130
161
131
162
struct ofpbuf *makeFlowStatReplyMessage (MockConnection *pConn,
132
- uint32_t priority, uint32_t cookie,
163
+ uint32_t priority, uint64_t cookie,
133
164
uint32_t packet_count,
134
165
uint32_t byte_count,
135
166
uint32_t reg0, uint32_t reg2,
@@ -159,7 +190,7 @@ struct ofpbuf *makeFlowStatReplyMessage(MockConnection *pConn,
159
190
bzero (fs, sizeof (struct ofputil_flow_stats ));
160
191
fs->table_id = IntFlowManager::POL_TABLE_ID;
161
192
fs->priority = priority;
162
- fs->cookie = ovs_htonll (( uint64_t ) cookie) ;
193
+ fs->cookie = cookie;
163
194
fs->packet_count = packet_count;
164
195
fs->byte_count = byte_count;
165
196
fs->flags = OFPUTIL_FF_SEND_FLOW_REM;
@@ -179,6 +210,44 @@ struct ofpbuf *makeFlowStatReplyMessage(MockConnection *pConn,
179
210
180
211
}
181
212
213
+ bool ContractStatsManagerFixture::checkNewFlowMapSize (size_t pol_table_size)
214
+ {
215
+ // Call on_timer function to process the flow entries received from
216
+ // switchManager.
217
+ boost::system::error_code ec;
218
+ ec = make_error_code (boost::system::errc::success);
219
+ contractStatsManager.on_timer (ec);
220
+
221
+ std::lock_guard<std::mutex> lock (contractStatsManager.pstatMtx );
222
+ if (contractStatsManager.contractState .newFlowCounterMap .size () == pol_table_size)
223
+ return true ;
224
+
225
+ return false ;
226
+ }
227
+
228
+ // Wait for IntFlowManager to create rddrop flow and stats tables to get initialized
229
+ void ContractStatsManagerFixture::waitForRdDropEntry (void )
230
+ {
231
+ // 1 table-drop static entry in POL table with stats enabled
232
+ WAIT_FOR_DO_ONFAIL (checkNewFlowMapSize (1 ),
233
+ 500 ,,
234
+ LOG (ERROR) << " ##### flow state not fully setup ####" ;);
235
+
236
+ intFlowManager.domainUpdated (RoutingDomain::CLASS_ID, rd0->getURI ());
237
+
238
+ // 1 entry is installed in policy table per VRF for collecting rddrop stats
239
+ WAIT_FOR_DO_ONFAIL (checkNewFlowMapSize (2 ),
240
+ 500 ,,
241
+ LOG (ERROR) << " ##### flow state not fully setup ####" ;);
242
+
243
+ // rdid for this rd should have been allocated
244
+ WAIT_FOR_DO_ONFAIL (
245
+ (idGen.getIdNoAlloc (IntFlowManager::getIdNamespace (RoutingDomain::CLASS_ID),
246
+ rd0->getURI ().toString ()) != (uint32_t )-1 ),
247
+ 500 ,,
248
+ LOG (ERROR) << " rdId not yet alloc'd for rd0" );
249
+ }
250
+
182
251
BOOST_AUTO_TEST_SUITE (ContractStatsManager_test)
183
252
184
253
BOOST_FIXTURE_TEST_CASE (testFlowMatchStats, ContractStatsManagerFixture) {
@@ -209,21 +278,25 @@ BOOST_FIXTURE_TEST_CASE(testRdDropStats, ContractStatsManagerFixture) {
209
278
contractStatsManager.registerConnection (&integrationPortConn);
210
279
contractStatsManager.start ();
211
280
LOG (DEBUG) << " ### rddrop stats start" ;
281
+ waitForRdDropEntry ();
212
282
213
283
// get rdId
214
284
uint32_t rdId =
215
- idGen.getId (IntFlowManager::getIdNamespace (RoutingDomain::CLASS_ID),
216
- rd0->getURI ().toString ());
285
+ idGen.getIdNoAlloc (IntFlowManager::getIdNamespace (RoutingDomain::CLASS_ID),
286
+ rd0->getURI ().toString ());
217
287
uint32_t priority = 1 ;
218
288
uint32_t packet_count = 39 ;
219
289
uint32_t byte_count = 6994 ;
220
290
221
291
/* create per RD flow drop stats */
222
292
struct ofpbuf *res_msg = makeFlowStatReplyMessage (&integrationPortConn,
223
- priority, 0 ,
293
+ priority,
294
+ flow::cookie::RD_POL_DROP_FLOW,
224
295
packet_count, byte_count,
225
296
0 , 0 , rdId);
226
297
BOOST_REQUIRE (res_msg!=0 );
298
+ ofp_header *msgHdr = (ofp_header *)res_msg->data ;
299
+ contractStatsManager.testInjectTxnId (msgHdr->xid );
227
300
228
301
contractStatsManager.Handle (&integrationPortConn,
229
302
OFPTYPE_FLOW_STATS_REPLY, res_msg);
0 commit comments