-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fpm] Fix FpmLink to read all netlink messages from FPM message (#2492)
In case of using dplane_fpm_nl zebra plugin we receive RTM_DELROUTE followed by RTM_NEWROUTE in a single FPM message when route attributes change (i.e nexthops change). Current implementation can only read the first one and ignores the rest. What I did I fixed FPM implementation to read multiple nl messages in a single FPM message. Why I did it Trying to move towards using dplane_fpm_nl. How I verified it UT and using dplane_fpm_nl zebra plugin. Details if related
- Loading branch information
1 parent
da56bd6
commit 28aa309
Showing
5 changed files
with
134 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include "fpmsyncd/fpmlink.h" | ||
|
||
#include <swss/netdispatcher.h> | ||
|
||
#include <gtest/gtest.h> | ||
#include <gmock/gmock.h> | ||
|
||
using namespace swss; | ||
|
||
using ::testing::_; | ||
|
||
class MockMsgHandler : public NetMsg | ||
{ | ||
public: | ||
MOCK_METHOD2(onMsg, void(int, nl_object*)); | ||
}; | ||
|
||
class FpmLinkTest : public ::testing::Test | ||
{ | ||
public: | ||
void SetUp() override | ||
{ | ||
NetDispatcher::getInstance().registerMessageHandler(RTM_NEWROUTE, &m_mock); | ||
NetDispatcher::getInstance().registerMessageHandler(RTM_DELROUTE, &m_mock); | ||
} | ||
|
||
void TearDown() override | ||
{ | ||
NetDispatcher::getInstance().unregisterMessageHandler(RTM_NEWROUTE); | ||
NetDispatcher::getInstance().unregisterMessageHandler(RTM_DELROUTE); | ||
} | ||
|
||
FpmLink m_fpm{nullptr}; | ||
MockMsgHandler m_mock; | ||
}; | ||
|
||
TEST_F(FpmLinkTest, SingleNlMessageInFpmMessage) | ||
{ | ||
// Single FPM message containing single RTM_NEWROUTE | ||
alignas(fpm_msg_hdr_t) unsigned char fpmMsgBuffer[] = { | ||
0x01, 0x01, 0x00, 0x40, 0x3C, 0x00, 0x00, 0x00, 0x18, 0x00, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0xE0, | ||
0x12, 0x6F, 0xC4, 0x02, 0x18, 0x00, 0x00, 0xFE, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, | ||
0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x08, 0x00, 0x06, 0x00, 0x14, 0x00, 0x00, 0x00, 0x08, 0x00, 0x05, | ||
0x00, 0xAC, 0x1E, 0x38, 0xA6, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00 | ||
}; | ||
|
||
EXPECT_CALL(m_mock, onMsg(_, _)).Times(1); | ||
|
||
m_fpm.processFpmMessage(reinterpret_cast<fpm_msg_hdr_t*>(static_cast<void*>(fpmMsgBuffer))); | ||
} | ||
|
||
TEST_F(FpmLinkTest, TwoNlMessagesInFpmMessage) | ||
{ | ||
// Single FPM message containing RTM_DELROUTE and RTM_NEWROUTE | ||
alignas(fpm_msg_hdr_t) unsigned char fpmMsgBuffer[] = { | ||
0x01, 0x01, 0x00, 0x6C, 0x2C, 0x00, 0x00, 0x00, 0x19, 0x00, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x12, | ||
0x6F, 0xC4, 0x02, 0x18, 0x00, 0x00, 0xFE, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, | ||
0x01, 0x01, 0x01, 0x00, 0x08, 0x00, 0x06, 0x00, 0x14, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x18, 0x00, | ||
0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x12, 0x6F, 0xC4, 0x02, 0x18, 0x00, 0x00, 0xFE, 0x02, 0x00, 0x01, | ||
0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x08, 0x00, 0x06, 0x00, 0x14, 0x00, | ||
0x00, 0x00, 0x08, 0x00, 0x05, 0x00, 0xAC, 0x1E, 0x38, 0xA7, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00 | ||
}; | ||
|
||
EXPECT_CALL(m_mock, onMsg(_, _)).Times(2); | ||
|
||
m_fpm.processFpmMessage(reinterpret_cast<fpm_msg_hdr_t*>(static_cast<void*>(fpmMsgBuffer))); | ||
} | ||
|