Skip to content

Commit 0b5c7f5

Browse files
authored
Merge pull request #283 from FedeParola/router-bug-fixes
Router bug fixes
2 parents 49cfb8f + 8c5dfd6 commit 0b5c7f5

File tree

4 files changed

+50
-40
lines changed

4 files changed

+50
-40
lines changed

src/libs/polycube/include/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bcc_exception.h
2+
file_desc.h
3+
table_desc.h

src/services/pcn-router/src/Ports.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ Ports::Ports(polycube::service::Cube<Ports> &parent,
142142
};
143143

144144
if (!parent_.get_shadow()) {
145+
// Align parameters of the port with the ones of the interface if connected
146+
if (conf.macIsSet()) {
147+
set_peer_parameter("MAC", conf.getMac());
148+
}
149+
if (conf.ipIsSet()) {
150+
set_peer_parameter("IP", conf.getIp());
151+
}
152+
145153
/* Register the new port to IP and MAC notifications arriving from ExtIface
146154
* do not use define because strings are easier to manipulate
147155
* for future extensions */
@@ -203,6 +211,7 @@ void Ports::doSetIp(const std::string &new_ip) {
203211
r_port value = router_port.get(index);
204212
value.ip = ip_string_to_nbo_uint(ip_address);
205213
value.netmask = ip_string_to_nbo_uint(netmask);
214+
router_port.set(index, value);
206215
} catch (...) {
207216
logger()->error("Port {0} not found in the data path", this->name());
208217
}

src/services/pcn-router/src/PortsSecondaryip.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ PortsSecondaryip::PortsSecondaryip(Ports &parent, const PortsSecondaryipJsonObje
3636
/*
3737
* Add two routes in the routing table
3838
*/
39-
int index = parent.parent_.Cube::get_port(parent.getName())->index();
39+
int index = parent.index();
4040
parent.parent_.add_local_route(ip_, parent.getName(), index);
4141
}
4242

src/services/pcn-router/src/Router.cpp

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -549,45 +549,43 @@ void Router::add_local_route(const std::string &interface_ip,
549549
"Added route [network: {0}/32 - nexthop: {1} - interface: {2}]",
550550
ip_route, "0.0.0.0", port_name);
551551

552-
/*
553-
* Add a route to the local network, i.e., to the network directly reachable
554-
* through the inteface
555-
*/
556-
557-
// Add the route in the fast path
558-
uint32_t networkDec = ip_string_to_nbo_uint(ip_route) &
559-
ip_string_to_nbo_uint(netmask_route);
560-
std::string network = nbo_uint_to_ip_string(networkDec);
561-
rt_k key2{
562-
.netmask_len = get_netmask_length(netmask_route),
563-
.network = networkDec,
564-
};
565-
566-
rt_v value2{
567-
.port = uint32_t(port_index),
568-
.nexthop = 0, /* 0.0.0.0 */
569-
.type = TYPE_NOLOCALINTERFACE,
570-
};
571-
572-
routing_table.set(key2, value2);
573-
574-
logger()->info(
575-
"Added route [network: {0}/{1} - nexthop: {2} - interface: {3}]",
576-
network, get_netmask_length(netmask_route), "0.0.0.0", port_name);
577-
578-
// Add the route in the table of the control plane
579-
580-
std::string nexthop("local");
581-
std::string route = network + "/" +
582-
std::to_string(get_netmask_length(netmask_route));
583-
std::tuple<string, string> keyF(route, nexthop);
584-
uint32_t pathcost = 0;
585-
586-
routes_.emplace(std::piecewise_construct, std::forward_as_tuple(keyF),
587-
std::forward_as_tuple(*this, route, nexthop,
588-
port_name, pathcost));
589-
590-
// FIXME: add also the /32 route?
552+
// If the new address is not a /32, add a route to the local network
553+
// (i.e. the network directly reachable through the inteface)
554+
if (netmask_route != "255.255.255.255") {
555+
556+
// Add the route in the fast path
557+
uint32_t networkDec = ip_string_to_nbo_uint(ip_route) &
558+
ip_string_to_nbo_uint(netmask_route);
559+
std::string network = nbo_uint_to_ip_string(networkDec);
560+
rt_k key2{
561+
.netmask_len = get_netmask_length(netmask_route),
562+
.network = networkDec,
563+
};
564+
565+
rt_v value2{
566+
.port = uint32_t(port_index),
567+
.nexthop = 0, /* 0.0.0.0 */
568+
.type = TYPE_NOLOCALINTERFACE,
569+
};
570+
571+
routing_table.set(key2, value2);
572+
573+
logger()->info(
574+
"Added route [network: {0}/{1} - nexthop: {2} - interface: {3}]",
575+
network, get_netmask_length(netmask_route), "0.0.0.0", port_name);
576+
577+
// Add the route in the table of the control plane
578+
579+
std::string nexthop("local");
580+
std::string route = network + "/" +
581+
std::to_string(get_netmask_length(netmask_route));
582+
std::tuple<string, string> keyF(route, nexthop);
583+
uint32_t pathcost = 0;
584+
585+
routes_.emplace(std::piecewise_construct, std::forward_as_tuple(keyF),
586+
std::forward_as_tuple(*this, route, nexthop,
587+
port_name, pathcost));
588+
}
591589
}
592590

593591
/*

0 commit comments

Comments
 (0)