Skip to content

Commit

Permalink
Add LocalSecGrpClassifierCounter
Browse files Browse the repository at this point in the history
- added as an extension of SecGrpClassifierCounter
- added make checks as a copy of SecGrpStatsManager_test.cpp,
  replacing all the classifiers with Local, and convert the
  called functions to use template arguments.
- The make checks cover the prometheus tests
- this would also result in pushing the LocalSecGrpClassifierCounter
  to the leaf, should we decide to push the local secgrps to the
  leaf, we can strip the Local before sending it.

Signed-off-by: Madhu Challa <challa@gmail.com>
  • Loading branch information
mchalla committed Aug 1, 2024
1 parent 2ea7e51 commit 37a90a3
Show file tree
Hide file tree
Showing 9 changed files with 520 additions and 49 deletions.
1 change: 1 addition & 0 deletions agent-ovs/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ if RENDERER_OVS
ovs/test/IntFlowManager_test.cpp \
ovs/test/AccessFlowManager_test.cpp \
ovs/test/AccessFlowManager_LocalSG_test.cpp \
ovs/test/SecGrpStatsManager_LocalSG_test.cpp \
ovs/test/PacketInHandler_test.cpp \
ovs/test/AdvertManager_test.cpp \
ovs/test/PortMapper_test.cpp \
Expand Down
7 changes: 7 additions & 0 deletions agent-ovs/lib/include/opflexagent/test/ModbFixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class ModbFixture : public BaseFixture {
std::shared_ptr<modelgbp::gbpe::LocalL24Classifier> local_classifier0;
std::shared_ptr<modelgbp::gbpe::LocalL24Classifier> local_classifier1;
std::shared_ptr<modelgbp::gbpe::LocalL24Classifier> local_classifier2;
std::shared_ptr<modelgbp::gbpe::LocalL24Classifier> local_classifier3;
std::shared_ptr<modelgbp::gbpe::LocalL24Classifier> local_classifier5;
std::shared_ptr<modelgbp::gbpe::LocalL24Classifier> local_classifier6;
std::shared_ptr<modelgbp::gbpe::LocalL24Classifier> local_classifier7;
Expand Down Expand Up @@ -315,6 +316,12 @@ class ModbFixture : public BaseFixture {
local_classifier2 = space->addGbpeLocalL24Classifier("classifier2");
local_classifier2->setEtherT(l2::EtherTypeEnumT::CONST_ARP);

/* classifiers with port ranges */
local_classifier3 = space->addGbpeLocalL24Classifier("classifier3");
local_classifier3->setOrder(10)
.setEtherT(l2::EtherTypeEnumT::CONST_IPV4).setProt(6 /* TCP */)
.setDFromPort(80).setDToPort(85);

/* allow bidirectional FCoE */
local_classifier5 = space->addGbpeLocalL24Classifier("classifier5");
local_classifier5->setOrder(20).setEtherT(l2::EtherTypeEnumT::CONST_FCOE);
Expand Down
81 changes: 60 additions & 21 deletions agent-ovs/ovs/SecGrpStatsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extern "C" {
#include <opflex/modb/Mutator.h>
#include <modelgbp/gbpe/L24Classifier.hpp>
#include <modelgbp/gbpe/SecGrpClassifierCounter.hpp>
#include <modelgbp/gbpe/LocalSecGrpClassifierCounter.hpp>
#include <modelgbp/observer/PolicyStatUniverse.hpp>

namespace opflexagent {
Expand All @@ -46,7 +47,8 @@ using boost::system::error_code;
SecGrpStatsManager::SecGrpStatsManager(Agent* agent_, IdGenerator& idGen_,
SwitchManager& switchManager_,
long timer_interval_)
: PolicyStatsManager(agent_,idGen_,switchManager_,timer_interval_) {
: PolicyStatsManager(agent_,idGen_,switchManager_,timer_interval_),
agent(agent_) {
}


Expand Down Expand Up @@ -122,9 +124,15 @@ void SecGrpStatsManager::on_timer(const error_code& ec) {

void SecGrpStatsManager::clearCounterObject(const string& key,
uint8_t index) {
SecGrpClassifierCounter::remove(agent->getFramework(),
getAgentUUID(),
genIdList_[key]->uidList[index],key);
if (agent->getPolicyManager().useLocalNetpol()) {
LocalSecGrpClassifierCounter::remove(agent->getFramework(),
getAgentUUID(),
genIdList_[key]->uidList[index],key);
} else {
SecGrpClassifierCounter::remove(agent->getFramework(),
getAgentUUID(),
genIdList_[key]->uidList[index],key);
}
}

void SecGrpStatsManager::
Expand All @@ -138,34 +146,60 @@ updatePolicyStatsCounters(const string& l24Classifier,
uint64_t nextId = getNextClsfrGenId();
clearOldCounters(l24Classifier,nextId);
if (newVals1.byte_count && newVals2.byte_count) {
su.get()->addGbpeSecGrpClassifierCounter(getAgentUUID(),
nextId,
l24Classifier)
->setTxpackets(newVals2.packet_count.get())
.setTxbytes(newVals2.byte_count.get())
.setRxpackets(newVals1.packet_count.get())
.setRxbytes(newVals1.byte_count.get());
if (agent->getPolicyManager().useLocalNetpol()) {
su.get()->addGbpeLocalSecGrpClassifierCounter(getAgentUUID(),
nextId,
l24Classifier)
->setTxpackets(newVals2.packet_count.get())
.setTxbytes(newVals2.byte_count.get())
.setRxpackets(newVals1.packet_count.get())
.setRxbytes(newVals1.byte_count.get());
} else {
su.get()->addGbpeSecGrpClassifierCounter(getAgentUUID(),
nextId,
l24Classifier)
->setTxpackets(newVals2.packet_count.get())
.setTxbytes(newVals2.byte_count.get())
.setRxpackets(newVals1.packet_count.get())
.setRxbytes(newVals1.byte_count.get());
}
prometheusManager.addNUpdateSGClassifierCounter(l24Classifier,
newVals1.byte_count.get(),
newVals1.packet_count.get(),
newVals2.byte_count.get(),
newVals2.packet_count.get());
} else if (newVals1.byte_count) {
su.get()->addGbpeSecGrpClassifierCounter(getAgentUUID(),
nextId,
l24Classifier)
->setRxpackets(newVals1.packet_count.get())
.setRxbytes(newVals1.byte_count.get());
if (agent->getPolicyManager().useLocalNetpol()) {
su.get()->addGbpeLocalSecGrpClassifierCounter(getAgentUUID(),
nextId,
l24Classifier)
->setRxpackets(newVals1.packet_count.get())
.setRxbytes(newVals1.byte_count.get());
} else {
su.get()->addGbpeSecGrpClassifierCounter(getAgentUUID(),
nextId,
l24Classifier)
->setRxpackets(newVals1.packet_count.get())
.setRxbytes(newVals1.byte_count.get());
}
prometheusManager.addNUpdateSGClassifierCounter(l24Classifier,
newVals1.byte_count.get(),
newVals1.packet_count.get(),
0, 0);
} else if (newVals2.byte_count) {
su.get()->addGbpeSecGrpClassifierCounter(getAgentUUID(),
nextId,
l24Classifier)
->setTxpackets(newVals2.packet_count.get())
.setTxbytes(newVals2.byte_count.get());
if (agent->getPolicyManager().useLocalNetpol()) {
su.get()->addGbpeLocalSecGrpClassifierCounter(getAgentUUID(),
nextId,
l24Classifier)
->setTxpackets(newVals2.packet_count.get())
.setTxbytes(newVals2.byte_count.get());
} else {
su.get()->addGbpeSecGrpClassifierCounter(getAgentUUID(),
nextId,
l24Classifier)
->setTxpackets(newVals2.packet_count.get())
.setTxbytes(newVals2.byte_count.get());
}
prometheusManager.addNUpdateSGClassifierCounter(l24Classifier,
0, 0,
newVals2.byte_count.get(),
Expand All @@ -182,6 +216,11 @@ void SecGrpStatsManager::objectUpdated(opflex::modb::class_id_t class_id,
removeAllCounterObjects(uri.toString());
prometheusManager.removeSGClassifierCounter(uri.toString());
}
} else if (class_id == LocalL24Classifier::CLASS_ID) {
if (!LocalL24Classifier::resolve(agent->getFramework(),uri)) {
removeAllCounterObjects(uri.toString());
prometheusManager.removeSGClassifierCounter(uri.toString());
}
}
}

Expand Down
1 change: 1 addition & 0 deletions agent-ovs/ovs/include/SecGrpStatsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class SecGrpStatsManager : public PolicyStatsManager {
private:
flowCounterState_t secGrpInState;
flowCounterState_t secGrpOutState;
Agent *agent;
};

} /* namespace opflexagent */
Expand Down
14 changes: 7 additions & 7 deletions agent-ovs/ovs/test/ContractStatsManager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ BOOST_FIXTURE_TEST_CASE(testFlowMatchStats, ContractStatsManagerFixture) {
contractStatsManager.Handle(&integrationPortConn,
OFPTYPE_FLOW_STATS_REPLY, NULL);

testOneFlow<MockContractStatsManager>(integrationPortConn,classifier3,
testOneFlow<MockContractStatsManager,L24Classifier>(integrationPortConn,classifier3,
IntFlowManager::POL_TABLE_ID,
1,
false,
Expand Down Expand Up @@ -314,7 +314,7 @@ BOOST_FIXTURE_TEST_CASE(testFlowRemoved, ContractStatsManagerFixture) {

// Add flows in switchManager
FlowEntryList entryList;
writeClassifierFlows(entryList,
writeClassifierFlows<L24Classifier>(entryList,
IntFlowManager::POL_TABLE_ID,
1,
classifier3,
Expand Down Expand Up @@ -353,7 +353,7 @@ BOOST_FIXTURE_TEST_CASE(testFlowRemoved, ContractStatsManagerFixture) {
// calculate expected packet count and byte count
// that we should have in Genie object

verifyFlowStats(classifier3,
verifyFlowStats<L24Classifier>(classifier3,
LAST_PACKET_COUNT,
LAST_PACKET_COUNT * PACKET_SIZE,
false,
Expand All @@ -371,7 +371,7 @@ BOOST_FIXTURE_TEST_CASE(testCircularBuffer, ContractStatsManagerFixture) {
contractStatsManager.start();
LOG(DEBUG) << "### Contract circbuffer Start";
// Add flows in switchManager
testCircBuffer<MockContractStatsManager>(intPortConn,classifier3,
testCircBuffer<MockContractStatsManager,L24Classifier>(intPortConn,classifier3,
IntFlowManager::POL_TABLE_ID,2,&contractStatsManager,
epg1,epg2,&policyManager);
LOG(DEBUG) << "### Contract circbuffer End";
Expand All @@ -388,7 +388,7 @@ BOOST_FIXTURE_TEST_CASE(testContractDelete, ContractStatsManagerFixture) {
contractStatsManager.Handle(&integrationPortConn,
OFPTYPE_FLOW_STATS_REPLY, NULL);

testOneFlow<MockContractStatsManager>(integrationPortConn,
testOneFlow<MockContractStatsManager,L24Classifier>(integrationPortConn,
classifier3,
IntFlowManager::POL_TABLE_ID,
1,
Expand Down Expand Up @@ -423,7 +423,7 @@ BOOST_FIXTURE_TEST_CASE(testSEpgDelete, ContractStatsManagerFixture) {
contractStatsManager.start();
LOG(DEBUG) << "### Contract SEPG Delete Start";

testOneFlow<MockContractStatsManager>(integrationPortConn,
testOneFlow<MockContractStatsManager,L24Classifier>(integrationPortConn,
classifier3,
IntFlowManager::POL_TABLE_ID,
1,
Expand Down Expand Up @@ -457,7 +457,7 @@ BOOST_FIXTURE_TEST_CASE(testrDSEpgDelete, ContractStatsManagerFixture) {
contractStatsManager.start();
LOG(DEBUG) << "### Contract DSEPG Delete Start";

testOneFlow<MockContractStatsManager>(integrationPortConn,
testOneFlow<MockContractStatsManager,L24Classifier>(integrationPortConn,
classifier3,
IntFlowManager::POL_TABLE_ID,
1,
Expand Down
Loading

0 comments on commit 37a90a3

Please sign in to comment.