Skip to content

Commit

Permalink
test case to veriry drop reason with the denied policy
Browse files Browse the repository at this point in the history
  • Loading branch information
bashokba committed Oct 12, 2020
1 parent 170612a commit 5165e5a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 4 deletions.
4 changes: 2 additions & 2 deletions agent-ovs/ovs/PacketLogHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ void PacketLogHandler::getDropReason(ParseInfo &p, std::string &dropReason) {

boost::optional<std::string> ruleUri = idGen.getStringForId((IntFlowManager::getIdNamespace(L24Classifier::CLASS_ID)), p.meta[3]);

if(ruleUri) {
dropReason += " "+ruleUri.get();
if (ruleUri) {
dropReason += " "+ruleUri.get();
}
}

Expand Down
2 changes: 1 addition & 1 deletion agent-ovs/ovs/include/PacketDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ struct ParseInfo {
*/
PacketTuple packetTuple;
/**
* Source Bridge,TableId,CaptureReason,Policies triggered the drop,TBD
* Source Bridge,TableId,CaptureReason,Policies triggered the drop
*/
uint32_t meta[4];
};
Expand Down
2 changes: 1 addition & 1 deletion agent-ovs/ovs/ovs-shim.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ void act_tun_metadata_load_64(struct ofpbuf* buf,
int regId, const void* regValue, const void* mask) {
struct ofpact_set_field *sf =
ofpact_put_reg_load(buf, mf_from_id(regId), NULL, NULL);
memcpy(sf->value, regValue, 4);
memcpy(sf->value, regValue, 8);
memcpy(ofpact_set_field_mask(sf),mask,8);
}

49 changes: 49 additions & 0 deletions agent-ovs/ovs/test/PacketDecoder_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <opflexagent/IdGenerator.h>
BOOST_AUTO_TEST_SUITE(PacketDecoder_test)

using namespace std;
using namespace opflexagent;

/*Dummy io_service objects for constructor*/
Expand Down Expand Up @@ -101,6 +102,34 @@ static const uint8_t igmp_buf[] = {
0x00, 0x00, 0xe0, 0x00, 0x00, 0xfb
};


static const uint8_t arp_stream[] = {
0x22, 0x00, 0x65, 0x58, 0x00, 0x00, 0x01, 0x00,
0xff, 0xff, 0x00, 0x01, 0x00, 0x00, 0x12, 0x34,
0xff, 0xff, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0x02, 0x01, 0x00, 0x00, 0x30, 0x00,
0xff, 0xff, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0x04, 0x01, 0x00, 0x00, 0x00, 0x01,
0xff, 0xff, 0x05, 0x01, 0x00, 0x00, 0x00, 0x01,
0xff, 0xff, 0x06, 0x01, 0x00, 0x00, 0x00, 0x01,
0xff, 0xff, 0x07, 0x01, 0x00, 0x00, 0x00, 0x03,
0xff, 0xff, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0x09, 0x01, 0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0x0a, 0x01, 0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0x0b, 0x04, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x0c, 0x01,
0x00, 0x00, 0x00, 0x0c, 0xff, 0xff, 0x0d, 0x01,
0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0x0e, 0x02,
0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x08, 0x06, 0x00, 0x01,
0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x0a, 0x00, 0x02, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00,
0x02, 0x03
};

BOOST_FIXTURE_TEST_CASE(arp_test, PacketDecoderFixture) {
auto pktDecoder = pktLogger.getDecoder();
ParseInfo p(&pktDecoder);
Expand Down Expand Up @@ -198,4 +227,24 @@ BOOST_FIXTURE_TEST_CASE(ip_options_unrecognized_test, PacketDecoderFixture) {
BOOST_CHECK(p.parsedString == expected);
BOOST_CHECK(p.packetTuple == expectedTuple);
}

BOOST_FIXTURE_TEST_CASE(enhanceDropReason_test, PacketDecoderFixture) {
string dir(".");
string nmspc("l24classifierRule");
string u1("/PolicyUniverse/PolicySpace/test/GbpeL24Classifier/classifier7/");
uint32_t u1_id;
idGen.setPersistLocation(dir);
idGen.initNamespace(nmspc);
u1_id = idGen.getId(nmspc, u1);
BOOST_CHECK(u1_id != 0);
BOOST_CHECK(u1_id == idGen.getId(nmspc, u1));
std::string expected("Int-POL_TABLE DENY /PolicyUniverse/PolicySpace/test/GbpeL24Classifier/classifier7/");
auto pktDecoder = pktLogger.getDecoder();
ParseInfo p(&pktDecoder);
int ret = pktDecoder.decode(arp_stream, 186, p);
BOOST_CHECK(ret == 0);
std::string dropReason;
pktLogger.getDropReason(p, dropReason);
BOOST_CHECK(dropReason == expected);
}
BOOST_AUTO_TEST_SUITE_END()
2 changes: 2 additions & 0 deletions agent-ovs/ovs/test/include/MockPacketLogHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class MockPacketLogHandler: public PacketLogHandler {
"Service source policy missing/incorrect");
TABLE_DESC(intTableDesc, 5, "BRIDGE_TABLE",
"MAC lookup failed");
TABLE_DESC(intTableDesc, 12, "POL_TABLE",
"Denied contract");
TABLE_DESC(accTableDesc, 1, "GROUP_MAP_TABLE",
"Access port incorrect");
TABLE_DESC(accTableDesc, 3, "SEC_GROUP_OUT_TABLE",
Expand Down

0 comments on commit 5165e5a

Please sign in to comment.