Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for etree extended community Add sticky bit to MacMobility community Add tests for etree Add/Modify tests for MacMobility Change-Id: I4c167ab12a79e89f3e4bcc4b7998cf20814e2a91 Related-bug: #1645092
- Loading branch information
Showing
9 changed files
with
215 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2016 Juniper Networks, Inc. All rights reserved. | ||
*/ | ||
|
||
#include "bgp/extended-community/etree.h" | ||
|
||
#include <stdio.h> | ||
|
||
#include <algorithm> | ||
#include <string> | ||
|
||
|
||
using std::copy; | ||
using std::string; | ||
|
||
ETree::ETree(bool leaf, int label) { | ||
data_[0] = BgpExtendedCommunityType::Evpn; | ||
data_[1] = BgpExtendedCommunityEvpnSubType::ETree; | ||
data_[2] = leaf ? 0x01 : 0x0; // Leaf Indication | ||
data_[3] = 0x00; // Reserved | ||
data_[4] = 0x00; // Reserved | ||
put_value(&data_[5], 3, (label<<4)); // leaf label | ||
} | ||
|
||
ETree::ETree(const bytes_type &data) { | ||
copy(data.begin(), data.end(), data_.begin()); | ||
} | ||
|
||
bool ETree::leaf() const { | ||
uint8_t data[ETree::kSize]; | ||
copy(data_.begin(), data_.end(), &data[0]); | ||
if (data[0] == BgpExtendedCommunityType::Evpn && | ||
data[1] == BgpExtendedCommunityEvpnSubType::ETree) { | ||
return (data[2] & 0x1); | ||
} | ||
return false; | ||
} | ||
|
||
int ETree::label() const { | ||
uint8_t data[ETree::kSize]; | ||
copy(data_.begin(), data_.end(), &data[0]); | ||
if (data[0] == BgpExtendedCommunityType::Evpn && | ||
data[1] == BgpExtendedCommunityEvpnSubType::ETree) { | ||
uint32_t value = get_value(data + 5, 3); | ||
return value >> 4; | ||
} | ||
return false; | ||
} | ||
|
||
std::string ETree::ToString() { | ||
char temp[50]; | ||
snprintf(temp, sizeof(temp), "etree:%s:%d", | ||
(leaf() ? "leaf":"root"), label()); | ||
return string(temp); | ||
} |
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,41 @@ | ||
/* | ||
* Copyright (c) 2016 Juniper Networks, Inc. All rights reserved. | ||
*/ | ||
|
||
#ifndef SRC_BGP_EXTENDED_COMMUNITY_ETREE_H_ | ||
#define SRC_BGP_EXTENDED_COMMUNITY_ETREE_H_ | ||
|
||
#include <boost/array.hpp> | ||
#include <boost/system/error_code.hpp> | ||
|
||
#include <string> | ||
|
||
#include "base/parse_object.h" | ||
#include "bgp/extended-community/types.h" | ||
|
||
class ETree { | ||
public: | ||
static const int kSize = 8; | ||
typedef boost::array<uint8_t, kSize> bytes_type; | ||
|
||
explicit ETree(bool leaf, int label=0); | ||
explicit ETree(const bytes_type &data); | ||
|
||
bool leaf() const; | ||
int label() const; | ||
|
||
const bytes_type &GetExtCommunity() const { | ||
return data_; | ||
} | ||
|
||
const uint64_t GetExtCommunityValue() const { | ||
return get_value(data_.begin(), 8); | ||
} | ||
|
||
std::string ToString(); | ||
|
||
private: | ||
bytes_type data_; | ||
}; | ||
|
||
#endif // SRC_BGP_EXTENDED_COMMUNITY_ETREE_H_ |
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,67 @@ | ||
/* | ||
* Copyright (c) 2016 Juniper Networks, Inc. All rights reserved. | ||
*/ | ||
|
||
#include "bgp/extended-community/etree.h" | ||
|
||
#include "testing/gunit.h" | ||
|
||
using namespace std; | ||
|
||
class ETreeTest : public ::testing::Test { | ||
}; | ||
|
||
TEST_F(ETreeTest, ByteArray_1) { | ||
ETree::bytes_type data = { { | ||
BgpExtendedCommunityType::Evpn, | ||
BgpExtendedCommunityEvpnSubType::ETree, | ||
0x01, 0x00, 0x0, 0x0, 0x0, 0x0 | ||
} }; | ||
ETree etree(data); | ||
EXPECT_EQ("etree:leaf:0", etree.ToString()); | ||
} | ||
|
||
TEST_F(ETreeTest, ByteArray_2) { | ||
ETree::bytes_type data = { { | ||
BgpExtendedCommunityType::Evpn, | ||
BgpExtendedCommunityEvpnSubType::ETree, | ||
0x00, 0x00, 0x0, 0x1, 0x0, 0x0 | ||
} }; | ||
ETree etree(data); | ||
EXPECT_EQ("etree:root:4096", etree.ToString()); | ||
} | ||
|
||
TEST_F(ETreeTest, ByteArray_3) { | ||
ETree::bytes_type data = { { | ||
BgpExtendedCommunityType::Evpn, | ||
BgpExtendedCommunityEvpnSubType::ETree, | ||
0x00, 0x00, 0x0, 0x0, 0x1, 0x0 | ||
} }; | ||
ETree etree(data); | ||
EXPECT_EQ("etree:root:16", etree.ToString()); | ||
} | ||
|
||
|
||
TEST_F(ETreeTest, Init) { | ||
boost::system::error_code ec; | ||
ETree etree(true); | ||
EXPECT_EQ(etree.ToString(), "etree:leaf:0"); | ||
} | ||
|
||
TEST_F(ETreeTest, Init_2) { | ||
boost::system::error_code ec; | ||
ETree etree(false); | ||
EXPECT_EQ(etree.ToString(), "etree:root:0"); | ||
} | ||
|
||
TEST_F(ETreeTest, Init_3) { | ||
boost::system::error_code ec; | ||
ETree etree(false, 100); | ||
EXPECT_EQ(etree.ToString(), "etree:root:100"); | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
::testing::InitGoogleTest(&argc, argv); | ||
int result = RUN_ALL_TESTS(); | ||
return result; | ||
} |
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