11 #include <boost/property_tree/ini_parser.hpp>
12 #include <boost/algorithm/string.hpp>
13 #include <boost/foreach.hpp>
15 #include <pugixml/pugixml.hpp>
26 using namespace boost::property_tree;
27 using namespace boost::uuids;
28 using boost::optional;
33 (
const boost::property_tree::ptree pt) {
34 const std::string gw_str =
"GATEWAY";
36 BOOST_FOREACH(
const ptree::value_type §ion, pt) {
37 if (section.first.compare(0, gw_str.size(), gw_str) != 0) {
41 string interfacestr =
"";
44 BOOST_FOREACH(
const ptree::value_type &key, section.second) {
45 if (key.first.compare(
"routing_instance") == 0) {
46 vrf = key.second.get_value<
string>();
48 if (key.first.compare(
"interface") == 0) {
49 interfacestr = key.second.get_value<
string>();
51 if (key.first.compare(
"ip_blocks") == 0) {
52 BuildSubnetList(key.second.get_value<
string>(), subnets);
54 if (key.first.compare(
"routes") == 0) {
55 BuildSubnetList(key.second.get_value<
string>(), routes);
58 if (vrf ==
"" || interfacestr ==
"" || subnets.size() == 0) {
59 LOG(ERROR,
"Error in config file. Invalid/incomplete gateway "
60 "section" << section.first);
64 std::sort(subnets.begin(), subnets.end());
65 std::sort(routes.begin(), routes.end());
67 subnets, routes, (uint32_t) -1));
76 boost::system::error_code ec;
78 if (!subnets.empty()) {
79 vector<string> tokens;
80 boost::split(tokens, subnets, boost::is_any_of(
" "));
81 vector<string>::iterator it = tokens.begin();
82 while (it != tokens.end()) {
83 std::string str = *it;
84 boost::algorithm::trim(str);
87 if (ec.failed() || plen >= 32) {
88 LOG(ERROR,
"Error in config file. Invalid gateway "
89 "ip_block/route " << str);
99 work_queue_.reset(
new WorkQueue<boost::shared_ptr<VirtualGatewayData> >
100 (agent_->task_scheduler()->GetTaskId(
"db::DBTable"), 0,
103 work_queue_->set_name(
"VGW");
107 work_queue_->Shutdown();
111 boost::shared_ptr<VirtualGatewayData> request) {
112 work_queue_->Enqueue(request);
116 boost::shared_ptr<VirtualGatewayData> request) {
117 switch(request->message_type_) {
120 AddVgw(vgw, request->version_);
131 DeleteAllOldVersionVgw(request->version_);
146 if (agent_->vrouter_on_nic_mode() ||
147 agent_->vrouter_on_host_dpdk()) {
150 if (it == table_.end()) {
160 LOG(DEBUG,
"Virtual Gateway : change of vrf is not allowed; " <<
162 it->vrf_name() <<
" New VRF : " << vgw.
vrf_name_);
166 if (FindChange(it->subnets(), vgw.
subnets_, add_list, del_list)) {
167 agent_->vgw()->SubnetUpdate(*it, add_list, del_list);
173 if (FindChange(it->routes(), vgw.
routes_, add_list, del_list)) {
174 agent_->vgw()->RouteUpdate(*it, vgw.
routes_, add_list, del_list,
true);
177 it->set_version(version);
184 Table::iterator it = table_.find(interface_name);
185 if (it != table_.end()) {
190 LOG(DEBUG,
"Virtual Gateway delete : interface not present; " <<
191 "Interface : " << interface_name);
197 agent_->vgw()->SubnetUpdate(*it, empty_list, it->subnets());
198 agent_->vgw()->RouteUpdate(*it, empty_list, empty_list,
199 it->routes(),
false);
200 agent_->vgw()->DeleteInterface(it->interface_name());
201 agent_->vgw()->DeleteVrf(it->vrf_name());
207 for (Table::iterator it = table_.begin(); it != table_.end();) {
222 VirtualGatewayConfig::SubnetList::const_iterator it_old = old_subnets.begin();
223 VirtualGatewayConfig::SubnetList::const_iterator it_new = new_subnets.begin();
224 while (it_old != old_subnets.end() && it_new != new_subnets.end()) {
225 if (*it_old < *it_new) {
227 del_list.push_back(*it_old);
230 }
else if (*it_new < *it_old) {
232 add_list.push_back(*it_new);
243 for (; it_old != old_subnets.end(); ++it_old) {
244 del_list.push_back(*it_old);
249 for (; it_new != new_subnets.end(); ++it_new) {
250 add_list.push_back(*it_new);
bool DeleteVgw(const std::string &interface_name)
void Enqueue(boost::shared_ptr< VirtualGatewayData > request)
boost::system::error_code Ip4PrefixParse(const string &str, Ip4Address *addr, int *plen)
void DeleteAllOldVersionVgw(uint32_t version)
VirtualGatewayConfig::SubnetList routes_
void InitFromConfig(const boost::property_tree::ptree pt)
bool FindChange(const VirtualGatewayConfig::SubnetList &old_subnets, const VirtualGatewayConfig::SubnetList &new_subnets, VirtualGatewayConfig::SubnetList &add_list, VirtualGatewayConfig::SubnetList &del_list)
bool ProcessRequest(boost::shared_ptr< VirtualGatewayData > request)
boost::asio::ip::address_v4 Ip4Address
bool AddVgw(VirtualGatewayInfo &vgw, uint32_t version)
#define LOG(_Level, _Msg)
std::vector< Subnet > SubnetList
void BuildSubnetList(const std::string &subnets, VirtualGatewayConfig::SubnetList &results)
VirtualGatewayConfig::SubnetList subnets_
void InitDone(Agent *agent)
std::string interface_name_