diff --git a/src/bgp/bgp_config.h b/src/bgp/bgp_config.h
index 299c02759e4..d7ff99f00bc 100644
--- a/src/bgp/bgp_config.h
+++ b/src/bgp/bgp_config.h
@@ -171,11 +171,15 @@ class BgpNeighborConfig {
const IpAddress &peer_address() const { return address_; }
void set_peer_address(const IpAddress &address) { address_ = address; }
+ std::string peer_address_string() const { return address_.to_string(); }
uint32_t peer_identifier() const { return identifier_; }
void set_peer_identifier(uint32_t identifier) {
identifier_ = identifier;
}
+ std::string peer_identifier_string() const {
+ return Ip4Address(ntohl(identifier_)).to_string();
+ }
int port() const { return port_; }
void set_port(int port) { port_ = port; }
@@ -193,6 +197,9 @@ class BgpNeighborConfig {
void set_local_identifier(uint32_t identifier) {
local_identifier_ = identifier;
}
+ std::string local_identifier_string() const {
+ return Ip4Address(ntohl(local_identifier_)).to_string();
+ }
const AuthenticationData &auth_data() const {
return auth_data_;
diff --git a/src/bgp/bgp_config_ifmap.cc b/src/bgp/bgp_config_ifmap.cc
index 1ca6a71e000..96177e27212 100644
--- a/src/bgp/bgp_config_ifmap.cc
+++ b/src/bgp/bgp_config_ifmap.cc
@@ -89,6 +89,17 @@ static void BuildKeyChain(BgpNeighborConfig *neighbor,
neighbor->set_keydata(keydata);
}
+//
+// Check if the family is allowed to be configured for BgpNeighborConfig.
+// Only families inet and inet6 are allowed on non-master instances.
+//
+static bool AddressFamilyIsValid(BgpNeighborConfig *neighbor,
+ const string &family) {
+ if (neighbor->instance_name() == BgpConfigManager::kMasterInstance)
+ return true;
+ return (family == "inet" || family == "inet6");
+}
+
//
// Build list of BgpFamilyAttributesConfig elements from the list of address
// families. This is provided for backward compatibility with configurations
@@ -98,6 +109,8 @@ static void BuildFamilyAttributesList(BgpNeighborConfig *neighbor,
const BgpNeighborConfig::AddressFamilyList &family_list) {
BgpNeighborConfig::FamilyAttributesList family_attributes_list;
BOOST_FOREACH(const string &family, family_list) {
+ if (!AddressFamilyIsValid(neighbor, family))
+ continue;
BgpFamilyAttributesConfig family_attributes(family);
family_attributes_list.push_back(family_attributes);
}
@@ -119,6 +132,8 @@ static void BuildFamilyAttributesList(BgpNeighborConfig *neighbor,
BgpNeighborConfig::FamilyAttributesList family_attributes_list;
BOOST_FOREACH(const autogen::BgpFamilyAttributes &family_config,
attributes->family_attributes) {
+ if (!AddressFamilyIsValid(neighbor, family_config.address_family))
+ continue;
BgpFamilyAttributesConfig family_attributes(
family_config.address_family);
family_attributes.loop_count = family_config.loop_count;
@@ -155,7 +170,8 @@ static void NeighborSetSessionAttributes(
const autogen::BgpSessionAttributes *attr = iter.operator->();
if (attr->bgp_router.empty()) {
common = attr;
- } else if (attr->bgp_router == localname) {
+ } else if (attr->bgp_router == localname ||
+ attr->bgp_router == "BGPaaS") {
local = attr;
}
}
@@ -183,8 +199,9 @@ static void NeighborSetSessionAttributes(
static BgpNeighborConfig *MakeBgpNeighborConfig(
const BgpIfmapInstanceConfig *instance,
- const string &remote_name,
+ const BgpIfmapInstanceConfig *master_instance,
const string &local_name,
+ const string &remote_name,
const autogen::BgpRouter *local_router,
const autogen::BgpRouter *remote_router,
const autogen::BgpSession *session) {
@@ -236,10 +253,12 @@ static BgpNeighborConfig *MakeBgpNeighborConfig(
NeighborSetSessionAttributes(neighbor, local_name, session);
}
- // Get the local identifier and local as from the protocol config.
- const BgpIfmapProtocolConfig *protocol = instance->protocol_config();
- if (protocol && protocol->bgp_router()) {
- const autogen::BgpRouterParams ¶ms = protocol->router_params();
+ // Get the local identifier and local as from the master protocol config.
+ const BgpIfmapProtocolConfig *master_protocol =
+ master_instance->protocol_config();
+ if (master_protocol && master_protocol->bgp_router()) {
+ const autogen::BgpRouterParams ¶ms =
+ master_protocol->router_params();
if (params.admin_down) {
neighbor->set_admin_down(true);
}
@@ -252,7 +271,16 @@ static BgpNeighborConfig *MakeBgpNeighborConfig(
} else {
neighbor->set_local_as(params.autonomous_system);
}
+ if (instance != master_instance) {
+ neighbor->set_passive(true);
+ }
+ }
+ // Get other parameters from the instance protocol config.
+ // Note that there's no instance protocol config for non-master instances.
+ const BgpIfmapProtocolConfig *protocol = instance->protocol_config();
+ if (protocol && protocol->bgp_router()) {
+ const autogen::BgpRouterParams ¶ms = protocol->router_params();
if (neighbor->family_attributes_list().empty()) {
BuildFamilyAttributesList(neighbor, params.address_families.family);
}
@@ -272,19 +300,22 @@ static BgpNeighborConfig *MakeBgpNeighborConfig(
//
// Build map of BgpNeighborConfigs based on the data in autogen::BgpPeering.
//
-void BgpIfmapPeeringConfig::BuildNeighbors(BgpConfigManager *manager,
+void BgpIfmapPeeringConfig::BuildNeighbors(BgpIfmapConfigManager *manager,
const autogen::BgpRouter *local_rt_config,
const string &peername, const autogen::BgpRouter *remote_rt_config,
const autogen::BgpPeering *peering, NeighborMap *map) {
+ const BgpIfmapInstanceConfig *master_instance =
+ manager->config()->FindInstance(BgpConfigManager::kMasterInstance);
+
// If there are one or more autogen::BgpSessions for the peering, use
// those to create the BgpNeighborConfigs.
const autogen::BgpPeeringAttributes &attr = peering->data();
for (autogen::BgpPeeringAttributes::const_iterator iter = attr.begin();
iter != attr.end(); ++iter) {
BgpNeighborConfig *neighbor = MakeBgpNeighborConfig(
- instance_, peername, manager->localname(), local_rt_config,
- remote_rt_config, iter.operator->());
+ instance_, master_instance, manager->localname(), peername,
+ local_rt_config, remote_rt_config, iter.operator->());
map->insert(make_pair(neighbor->name(), neighbor));
}
@@ -292,17 +323,17 @@ void BgpIfmapPeeringConfig::BuildNeighbors(BgpConfigManager *manager,
// no per-session configuration.
if (map->empty()) {
BgpNeighborConfig *neighbor = MakeBgpNeighborConfig(
- instance_, peername, manager->localname(), local_rt_config,
- remote_rt_config, NULL);
+ instance_, master_instance, manager->localname(), peername,
+ local_rt_config, remote_rt_config, NULL);
map->insert(make_pair(neighbor->name(), neighbor));
}
}
//
-// Update BgpPeeringConfig based on updated autogen::BgpPeering.
+// Update BgpIfmapPeeringConfig based on updated autogen::BgpPeering.
//
// This mainly involves building future BgpNeighborConfigs and doing a diff of
-// the current and future BgpNeighborConfigs. Note that the BgpIfmapInstanceConfig
+// the current and future BgpNeighborConfigs. Note that BgpIfmapInstanceConfig
// also has references to BgpNeighborConfigs, so it also needs to be updated as
// part of the process.
//
@@ -426,7 +457,9 @@ bool BgpIfmapPeeringConfig::GetRouterPair(DBGraph *db_graph,
continue;
string instance_name(IdentifierParent(adj->name()));
string name = adj->name().substr(instance_name.size() + 1);
- if (name == localname) {
+ if (name == localname ||
+ (instance_name != BgpConfigManager::kMasterInstance &&
+ name == "BGPaaS")) {
local = adj;
} else {
remote = adj;
@@ -1190,19 +1223,19 @@ void BgpIfmapConfigManager::IdentifierMapInit() {
//
// Handler for routing-instance objects.
//
-// Note that the BgpIfmapInstanceConfig object for the master instance is created
+// Note that BgpIfmapInstanceConfig object for the master instance is created
// before we have received any configuration for it i.e. there's no IFMapNode
// or autogen::RoutingInstance for it. However, we will eventually receive a
// delta for the master. The IFMapNodeProxy and autogen::RoutingInstance are
// set at that time.
//
-// For other routing-instances the BgpConfigInstance can get created before we
+// For other routing-instances BgpIfmapConfigInstance can get created before we
// see the IFMapNode for the routing-instance if we see the IFMapNode for the
// local bgp-router in the routing-instance. In this case, the IFMapNodeProxy
// and autogen::RoutingInstance are set when we later see the IFMapNode for the
// routing-instance.
//
-// In all other cases a BgpConfigInstance is created when we see the IFMapNode
+// In all other cases, BgpIfmapConfigInstance is created when we see IFMapNode
// for the routing-instance. The IFMapNodeProxy and autogen::RoutingInstance
// are set right away.
//
@@ -1378,15 +1411,12 @@ void BgpIfmapConfigManager::ProcessBgpProtocol(const BgpConfigDelta &delta) {
//
// Handler for bgp-router objects.
//
-// Note that we don't need to explicitly re-evaluate any bgp-peerings as the
-// BgpConfigListener::DependencyTracker adds any relevant bgp-peerings to the
-// change list.
-//
void BgpIfmapConfigManager::ProcessBgpRouter(const BgpConfigDelta &delta) {
CHECK_CONCURRENCY("bgp::Config");
string instance_name(IdentifierParent(delta.id_name));
- if (instance_name.empty()) {
+ if (instance_name.empty() ||
+ instance_name != BgpConfigManager::kMasterInstance) {
return;
}
@@ -1397,6 +1427,14 @@ void BgpIfmapConfigManager::ProcessBgpRouter(const BgpConfigDelta &delta) {
}
ProcessBgpProtocol(delta);
+
+ // Update all peerings since we use local asn and identifier from master
+ // instance for all neighbors, including those in non-master instances.
+ BOOST_FOREACH(const BgpIfmapConfigData::IfmapPeeringMap::value_type &value,
+ config_->peerings()) {
+ BgpIfmapPeeringConfig *peering = value.second;
+ peering->Update(this, peering->bgp_peering());
+ }
}
//
diff --git a/src/bgp/bgp_config_ifmap.h b/src/bgp/bgp_config_ifmap.h
index 90bf954d28a..0eb730be92d 100644
--- a/src/bgp/bgp_config_ifmap.h
+++ b/src/bgp/bgp_config_ifmap.h
@@ -88,7 +88,7 @@ class BgpIfmapPeeringConfig {
}
private:
- void BuildNeighbors(BgpConfigManager *manager,
+ void BuildNeighbors(BgpIfmapConfigManager *manager,
const autogen::BgpRouter *local_rt_config,
const std::string &peername,
const autogen::BgpRouter *remote_rt_config,
@@ -279,6 +279,7 @@ class BgpIfmapConfigData {
const std::string &start_name = std::string()) const;
const IfmapInstanceMap &instances() const { return instances_; }
+ const IfmapPeeringMap &peerings() const { return peerings_; }
private:
IfmapInstanceMap instances_;
@@ -339,7 +340,7 @@ class BgpIfmapConfigManager : public BgpConfigManager,
DB *database() { return db_; }
DBGraph *graph() { return db_graph_; }
- const BgpIfmapConfigData &config() const { return *config_; }
+ const BgpIfmapConfigData *config() const { return config_.get(); }
private:
friend class BgpConfigListenerTest;
diff --git a/src/bgp/bgp_peer.cc b/src/bgp/bgp_peer.cc
index 0d7befb6045..960ace2e8f6 100644
--- a/src/bgp/bgp_peer.cc
+++ b/src/bgp/bgp_peer.cc
@@ -693,6 +693,14 @@ bool BgpPeer::IsXmppPeer() const {
return false;
}
+uint32_t BgpPeer::local_bgp_identifier() const {
+ return ntohl(local_bgp_id_);
+}
+
+string BgpPeer::local_bgp_identifier_string() const {
+ return Ip4Address(ntohl(local_bgp_id_)).to_string();
+}
+
uint32_t BgpPeer::bgp_identifier() const {
return ntohl(peer_bgp_id_);
}
diff --git a/src/bgp/bgp_peer.h b/src/bgp/bgp_peer.h
index 2599e9f2f12..ef989b7f6f0 100644
--- a/src/bgp/bgp_peer.h
+++ b/src/bgp/bgp_peer.h
@@ -152,6 +152,8 @@ class BgpPeer : public IPeer {
as_t peer_as() const { return peer_as_; }
// The BGP Identifier in host byte order.
+ virtual uint32_t local_bgp_identifier() const;
+ std::string local_bgp_identifier_string() const;
virtual uint32_t bgp_identifier() const;
std::string bgp_identifier_string() const;
diff --git a/src/bgp/test/bgp_config_test.cc b/src/bgp/test/bgp_config_test.cc
index 63af4779ce7..0672cafeda6 100644
--- a/src/bgp/test/bgp_config_test.cc
+++ b/src/bgp/test/bgp_config_test.cc
@@ -315,6 +315,50 @@ TEST_F(BgpConfigTest, MasterNeighbors) {
TASK_UTIL_EXPECT_EQ(2, rti->peer_manager()->size());
}
+TEST_F(BgpConfigTest, InstanceBGPaaSNeighbors) {
+ string content;
+ content = FileRead("controller/src/bgp/testdata/config_test_36a.xml");
+ EXPECT_TRUE(parser_.Parse(content));
+ task_util::WaitForIdle();
+
+ RoutingInstance *rti =
+ server_.routing_instance_mgr()->GetRoutingInstance("test");
+ TASK_UTIL_ASSERT_TRUE(rti != NULL);
+ TASK_UTIL_EXPECT_EQ(2, rti->peer_manager()->size());
+
+ TASK_UTIL_EXPECT_TRUE(rti->peer_manager()->PeerLookup("test:vm1:0") != NULL);
+ BgpPeer *peer1 = rti->peer_manager()->PeerLookup("test:vm1:0");
+ TASK_UTIL_EXPECT_EQ(64512, peer1->local_as());
+ TASK_UTIL_EXPECT_EQ("192.168.1.1", peer1->local_bgp_identifier_string());
+ TASK_UTIL_EXPECT_EQ(65001, peer1->peer_as());
+ TASK_UTIL_EXPECT_EQ("10.0.0.1", peer1->peer_address_string());
+
+ TASK_UTIL_EXPECT_TRUE(rti->peer_manager()->PeerLookup("test:vm2:0") != NULL);
+ BgpPeer *peer2 = rti->peer_manager()->PeerLookup("test:vm2:0");
+ TASK_UTIL_EXPECT_EQ(64512, peer2->local_as());
+ TASK_UTIL_EXPECT_EQ("192.168.1.1", peer2->local_bgp_identifier_string());
+ TASK_UTIL_EXPECT_EQ(65002, peer2->peer_as());
+ TASK_UTIL_EXPECT_EQ("10.0.0.2", peer2->peer_address_string());
+
+ // Change asn and identifier for master.
+ content = FileRead("controller/src/bgp/testdata/config_test_36b.xml");
+ EXPECT_TRUE(parser_.Parse(content));
+ task_util::WaitForIdle();
+
+ // Verify that instance neighbors use the new values.
+ TASK_UTIL_EXPECT_EQ(64513, peer1->local_as());
+ TASK_UTIL_EXPECT_EQ("192.168.1.2", peer1->local_bgp_identifier_string());
+ TASK_UTIL_EXPECT_EQ(64513, peer2->local_as());
+ TASK_UTIL_EXPECT_EQ("192.168.1.2", peer2->local_bgp_identifier_string());
+
+ content = FileRead("controller/src/bgp/testdata/config_test_36a.xml");
+ boost::replace_all(content, "", "");
+ boost::replace_all(content, "", "");
+ EXPECT_TRUE(parser_.Parse(content));
+ task_util::WaitForIdle();
+ TASK_UTIL_EXPECT_EQ(0, rti->peer_manager()->size());
+}
+
TEST_F(BgpConfigTest, MasterNeighborAttributes) {
string content_a = FileRead("controller/src/bgp/testdata/config_test_35a.xml");
EXPECT_TRUE(parser_.Parse(content_a));
diff --git a/src/bgp/test/bgp_ifmap_config_manager_test.cc b/src/bgp/test/bgp_ifmap_config_manager_test.cc
index f07cbaffd60..34390183d8f 100644
--- a/src/bgp/test/bgp_ifmap_config_manager_test.cc
+++ b/src/bgp/test/bgp_ifmap_config_manager_test.cc
@@ -83,11 +83,11 @@ class BgpIfmapConfigManagerTest : public ::testing::Test {
}
size_t GetPeeringCount() {
- return config_manager_->config().PeeringCount();
+ return config_manager_->config()->PeeringCount();
}
const BgpIfmapPeeringConfig *FindPeeringConfig(const string peering_name) {
- return config_manager_->config().FindPeering(peering_name);
+ return config_manager_->config()->FindPeering(peering_name);
}
DB db_;
@@ -123,7 +123,7 @@ class BgpIfmapConfigManagerShowTest : public ::testing::Test {
}
const BgpIfmapPeeringConfig *FindPeeringConfig(const string peering_name) {
- return config_manager_->config().FindPeering(peering_name);
+ return config_manager_->config()->FindPeering(peering_name);
}
EventManager evm_;
@@ -322,7 +322,7 @@ TEST_F(BgpIfmapConfigManagerTest, BgpRouterIdentifierChange) {
EXPECT_TRUE(parser_.Parse(content_a));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
}
@@ -361,7 +361,7 @@ TEST_F(BgpIfmapConfigManagerTest, BgpRouterAutonomousSystemChange) {
EXPECT_TRUE(parser_.Parse(content_a));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
}
@@ -401,7 +401,7 @@ TEST_F(BgpIfmapConfigManagerTest, BgpRouterHoldTimeChange) {
EXPECT_TRUE(parser_.Parse(content_a));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
}
@@ -445,7 +445,7 @@ TEST_F(BgpIfmapConfigManagerTest,
EXPECT_TRUE(parser_.Parse(content_a));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
}
@@ -485,7 +485,7 @@ TEST_F(BgpIfmapConfigManagerTest,
EXPECT_TRUE(parser_.Parse(content_a));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
}
@@ -550,7 +550,7 @@ TEST_F(BgpIfmapConfigManagerTest, MasterNeighbors) {
boost::replace_all(content, "", "");
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.edge_count());
for (DBGraph::edge_iterator edge_iter = db_graph_.edge_list_begin();
@@ -590,7 +590,7 @@ TEST_F(BgpIfmapConfigManagerTest, MasterNeighborsAdd) {
EXPECT_TRUE(parser_.Parse(content_b));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.edge_count());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
@@ -618,7 +618,7 @@ TEST_F(BgpIfmapConfigManagerTest, MasterNeighborsDelete) {
EXPECT_TRUE(parser_.Parse(content_a));
task_util::WaitForIdle();
- EXPECT_EQ(1, config_manager_->config().instances().size());
+ EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.edge_count());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
@@ -670,7 +670,7 @@ TEST_F(BgpIfmapConfigManagerTest, MasterNeighborAttributes) {
EXPECT_TRUE(parser_.Parse(content_b));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.edge_count());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
@@ -719,7 +719,7 @@ TEST_F(BgpIfmapConfigManagerTest, MasterPeeringUpdate1) {
EXPECT_TRUE(parser_.Parse(content_a));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.edge_count());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
@@ -768,7 +768,7 @@ TEST_F(BgpIfmapConfigManagerTest, MasterPeeringUpdate2) {
EXPECT_TRUE(parser_.Parse(content_a));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.edge_count());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
@@ -817,7 +817,7 @@ TEST_F(BgpIfmapConfigManagerTest, MasterPeeringUpdate3) {
EXPECT_TRUE(parser_.Parse(content_a));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.edge_count());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
@@ -913,7 +913,7 @@ TEST_F(BgpIfmapConfigManagerTest, MasterPeeringUpdate4) {
EXPECT_TRUE(parser_.Parse(content_a));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.edge_count());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
@@ -967,7 +967,7 @@ TEST_F(BgpIfmapConfigManagerTest, MasterPeeringUpdate5) {
EXPECT_TRUE(parser_.Parse(content_a));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.edge_count());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
@@ -979,7 +979,7 @@ TEST_F(BgpIfmapConfigManagerTest, InstanceTargetExport1) {
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(2, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(2, config_manager_->config()->instances().size());
const BgpInstanceConfig *red = FindInstanceConfig("red");
TASK_UTIL_ASSERT_TRUE(red != NULL);
@@ -997,7 +997,7 @@ TEST_F(BgpIfmapConfigManagerTest, InstanceTargetExport1) {
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
}
@@ -1006,7 +1006,7 @@ TEST_F(BgpIfmapConfigManagerTest, InstanceTargetExport2) {
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(2, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(2, config_manager_->config()->instances().size());
const BgpInstanceConfig *red = FindInstanceConfig("red");
TASK_UTIL_ASSERT_TRUE(red != NULL);
@@ -1025,7 +1025,7 @@ TEST_F(BgpIfmapConfigManagerTest, InstanceTargetExport2) {
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
}
@@ -1034,7 +1034,7 @@ TEST_F(BgpIfmapConfigManagerTest, InstanceTargetImport1) {
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(2, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(2, config_manager_->config()->instances().size());
const BgpInstanceConfig *red = FindInstanceConfig("red");
TASK_UTIL_ASSERT_TRUE(red != NULL);
@@ -1052,7 +1052,7 @@ TEST_F(BgpIfmapConfigManagerTest, InstanceTargetImport1) {
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
}
@@ -1061,7 +1061,7 @@ TEST_F(BgpIfmapConfigManagerTest, InstanceTargetImport2) {
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(2, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(2, config_manager_->config()->instances().size());
const BgpInstanceConfig *red = FindInstanceConfig("red");
TASK_UTIL_ASSERT_TRUE(red != NULL);
@@ -1080,7 +1080,7 @@ TEST_F(BgpIfmapConfigManagerTest, InstanceTargetImport2) {
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
}
@@ -1089,7 +1089,7 @@ TEST_F(BgpIfmapConfigManagerTest, VirtualNetwork1) {
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(3, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(3, config_manager_->config()->instances().size());
const BgpInstanceConfig *blue = FindInstanceConfig("blue");
TASK_UTIL_ASSERT_TRUE(blue != NULL);
@@ -1106,7 +1106,7 @@ TEST_F(BgpIfmapConfigManagerTest, VirtualNetwork1) {
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
}
@@ -1116,7 +1116,7 @@ TEST_F(BgpIfmapConfigManagerTest, VirtualNetwork2) {
EXPECT_TRUE(parser_.Parse(content_a));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(3, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(3, config_manager_->config()->instances().size());
const BgpInstanceConfig *blue = FindInstanceConfig("blue");
TASK_UTIL_ASSERT_TRUE(blue != NULL);
@@ -1143,7 +1143,7 @@ TEST_F(BgpIfmapConfigManagerTest, VirtualNetwork2) {
EXPECT_TRUE(parser_.Parse(content_b));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
}
@@ -1153,7 +1153,7 @@ TEST_F(BgpIfmapConfigManagerTest, VirtualNetwork3) {
EXPECT_TRUE(parser_.Parse(content_a));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(3, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(3, config_manager_->config()->instances().size());
const BgpInstanceConfig *blue = FindInstanceConfig("blue");
TASK_UTIL_ASSERT_TRUE(blue != NULL);
@@ -1181,7 +1181,7 @@ TEST_F(BgpIfmapConfigManagerTest, VirtualNetwork3) {
EXPECT_TRUE(parser_.Parse(content_b));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
}
@@ -1192,7 +1192,7 @@ TEST_F(BgpIfmapConfigManagerTest, VirtualNetwork4) {
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(3, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(3, config_manager_->config()->instances().size());
const BgpInstanceConfig *blue = FindInstanceConfig("blue");
TASK_UTIL_ASSERT_TRUE(blue != NULL);
@@ -1227,7 +1227,7 @@ TEST_F(BgpIfmapConfigManagerTest, VirtualNetwork4) {
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
}
@@ -1241,7 +1241,7 @@ TEST_F(BgpIfmapConfigManagerTest, Instances) {
boost::replace_all(content, "", "");
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
}
@@ -1292,7 +1292,58 @@ TEST_F(BgpIfmapConfigManagerTest, InstanceNeighbors) {
boost::replace_all(content, "", "");
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
+ TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
+}
+
+TEST_F(BgpIfmapConfigManagerTest, InstanceBGPaaSNeighbors) {
+ string content;
+ content = FileRead("controller/src/bgp/testdata/config_test_36a.xml");
+ EXPECT_TRUE(parser_.Parse(content));
+ task_util::WaitForIdle();
+
+ const BgpInstanceConfig *rti = FindInstanceConfig("test");
+ EXPECT_TRUE(rti != NULL);
+ EXPECT_EQ(2, config_manager_->NeighborCount("test"));
+
+ const BgpNeighborConfig *nbr_config1;
+ nbr_config1 = config_manager_->FindNeighbor("test", "test:vm1:0");
+ EXPECT_TRUE(nbr_config1 != NULL);
+ EXPECT_EQ(64512, nbr_config1->local_as());
+ EXPECT_EQ("192.168.1.1", nbr_config1->local_identifier_string());
+ EXPECT_EQ(65001, nbr_config1->peer_as());
+ EXPECT_EQ("10.0.0.1", nbr_config1->peer_address_string());
+
+ const BgpNeighborConfig *nbr_config2;
+ nbr_config2 = config_manager_->FindNeighbor("test", "test:vm2:0");
+ EXPECT_TRUE(nbr_config2 != NULL);
+ EXPECT_EQ(64512, nbr_config2->local_as());
+ EXPECT_EQ("192.168.1.1", nbr_config2->local_identifier_string());
+ EXPECT_EQ(65002, nbr_config2->peer_as());
+ EXPECT_EQ("10.0.0.2", nbr_config2->peer_address_string());
+
+ // Change asn and identifier for master.
+ content = FileRead("controller/src/bgp/testdata/config_test_36b.xml");
+ EXPECT_TRUE(parser_.Parse(content));
+ task_util::WaitForIdle();
+
+ // Verify that instance neighbors use the new values.
+ nbr_config1 = config_manager_->FindNeighbor("test", "test:vm1:0");
+ EXPECT_TRUE(nbr_config1 != NULL);
+ EXPECT_EQ(64513, nbr_config1->local_as());
+ EXPECT_EQ("192.168.1.2", nbr_config1->local_identifier_string());
+ nbr_config2 = config_manager_->FindNeighbor("test", "test:vm2:0");
+ EXPECT_TRUE(nbr_config2 != NULL);
+ EXPECT_EQ(64513, nbr_config2->local_as());
+ EXPECT_EQ("192.168.1.2", nbr_config1->local_identifier_string());
+
+ content = FileRead("controller/src/bgp/testdata/config_test_36a.xml");
+ boost::replace_all(content, "", "");
+ boost::replace_all(content, "", "");
+ EXPECT_TRUE(parser_.Parse(content));
+ task_util::WaitForIdle();
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
+ TASK_UTIL_EXPECT_EQ(0, config_manager_->NeighborCount("test"));
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
}
@@ -1376,7 +1427,7 @@ TEST_F(BgpIfmapConfigManagerShowTest, ShowInstances1) {
boost::replace_all(content, "", "");
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
}
@@ -1421,7 +1472,7 @@ TEST_F(BgpIfmapConfigManagerShowTest, ShowInstances2) {
boost::replace_all(content, "", "");
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
}
@@ -1466,7 +1517,7 @@ TEST_F(BgpIfmapConfigManagerShowTest, ShowInstances3) {
boost::replace_all(content, "", "");
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
}
@@ -1515,7 +1566,7 @@ TEST_F(BgpIfmapConfigManagerShowTest, ShowNeighbors) {
boost::replace_all(content, "", "");
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
}
@@ -1523,7 +1574,7 @@ TEST_F(BgpIfmapConfigManagerShowTest, ShowPeerings1) {
string content = FileRead("controller/src/bgp/testdata/config_test_27.xml");
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(3, config_manager_->config().PeeringCount());
+ TASK_UTIL_EXPECT_EQ(3, config_manager_->config()->PeeringCount());
BgpSandeshContext sandesh_context;
sandesh_context.bgp_server = &server_;
@@ -1561,7 +1612,7 @@ TEST_F(BgpIfmapConfigManagerShowTest, ShowPeerings1) {
boost::replace_all(content, "", "");
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
}
@@ -1575,7 +1626,7 @@ TEST_F(BgpIfmapConfigManagerShowTest, ShowPeerings2) {
string content = GeneratePeeringConfig(session_mask);
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().PeeringCount());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->PeeringCount());
TASK_UTIL_EXPECT_TRUE(FindPeeringConfig(full_name) != NULL);
const BgpIfmapPeeringConfig *config = FindPeeringConfig(full_name);
TASK_UTIL_EXPECT_EQ(session_mask.count(), config->size());
@@ -1611,7 +1662,7 @@ TEST_F(BgpIfmapConfigManagerShowTest, ShowPeerings2) {
boost::replace_all(content, "", "");
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
- TASK_UTIL_EXPECT_EQ(1, config_manager_->config().instances().size());
+ TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size());
TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count());
}
diff --git a/src/bgp/testdata/config_test_36a.xml b/src/bgp/testdata/config_test_36a.xml
new file mode 100644
index 00000000000..a14ef8fe062
--- /dev/null
+++ b/src/bgp/testdata/config_test_36a.xml
@@ -0,0 +1,66 @@
+
+
+
+ 192.168.1.1
+ 64512
+ 192.168.1.1
+
+
+ target:64512:1
+
+ 64512
+
+
+ inet
+
+
+ inet6
+
+
+ inet-vpn
+
+
+
+
+ inet
+
+
+ inet6
+
+
+ inet-vpn
+
+
+
+
+ 65001
+ 10.0.0.1
+
+
+ inet
+
+
+ inet6
+
+
+ inet-vpn
+
+
+
+
+ 65002
+ 10.0.0.2
+
+
+ inet
+
+
+ inet6
+
+
+ inet-vpn
+
+
+
+
+
diff --git a/src/bgp/testdata/config_test_36b.xml b/src/bgp/testdata/config_test_36b.xml
new file mode 100644
index 00000000000..dd351eb4928
--- /dev/null
+++ b/src/bgp/testdata/config_test_36b.xml
@@ -0,0 +1,8 @@
+
+
+
+ 192.168.1.2
+ 64513
+ 192.168.1.2
+
+