Skip to content

Commit

Permalink
Merge pull request #283 from FedeParola/router-bug-fixes
Browse files Browse the repository at this point in the history
Router bug fixes
  • Loading branch information
frisso committed Mar 16, 2020
2 parents 49cfb8f + 8c5dfd6 commit 0b5c7f5
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 40 deletions.
3 changes: 3 additions & 0 deletions src/libs/polycube/include/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bcc_exception.h
file_desc.h
table_desc.h
9 changes: 9 additions & 0 deletions src/services/pcn-router/src/Ports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ Ports::Ports(polycube::service::Cube<Ports> &parent,
};

if (!parent_.get_shadow()) {
// Align parameters of the port with the ones of the interface if connected
if (conf.macIsSet()) {
set_peer_parameter("MAC", conf.getMac());
}
if (conf.ipIsSet()) {
set_peer_parameter("IP", conf.getIp());
}

/* Register the new port to IP and MAC notifications arriving from ExtIface
* do not use define because strings are easier to manipulate
* for future extensions */
Expand Down Expand Up @@ -203,6 +211,7 @@ void Ports::doSetIp(const std::string &new_ip) {
r_port value = router_port.get(index);
value.ip = ip_string_to_nbo_uint(ip_address);
value.netmask = ip_string_to_nbo_uint(netmask);
router_port.set(index, value);
} catch (...) {
logger()->error("Port {0} not found in the data path", this->name());
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/pcn-router/src/PortsSecondaryip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ PortsSecondaryip::PortsSecondaryip(Ports &parent, const PortsSecondaryipJsonObje
/*
* Add two routes in the routing table
*/
int index = parent.parent_.Cube::get_port(parent.getName())->index();
int index = parent.index();
parent.parent_.add_local_route(ip_, parent.getName(), index);
}

Expand Down
76 changes: 37 additions & 39 deletions src/services/pcn-router/src/Router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,45 +549,43 @@ void Router::add_local_route(const std::string &interface_ip,
"Added route [network: {0}/32 - nexthop: {1} - interface: {2}]",
ip_route, "0.0.0.0", port_name);

/*
* Add a route to the local network, i.e., to the network directly reachable
* through the inteface
*/

// Add the route in the fast path
uint32_t networkDec = ip_string_to_nbo_uint(ip_route) &
ip_string_to_nbo_uint(netmask_route);
std::string network = nbo_uint_to_ip_string(networkDec);
rt_k key2{
.netmask_len = get_netmask_length(netmask_route),
.network = networkDec,
};

rt_v value2{
.port = uint32_t(port_index),
.nexthop = 0, /* 0.0.0.0 */
.type = TYPE_NOLOCALINTERFACE,
};

routing_table.set(key2, value2);

logger()->info(
"Added route [network: {0}/{1} - nexthop: {2} - interface: {3}]",
network, get_netmask_length(netmask_route), "0.0.0.0", port_name);

// Add the route in the table of the control plane

std::string nexthop("local");
std::string route = network + "/" +
std::to_string(get_netmask_length(netmask_route));
std::tuple<string, string> keyF(route, nexthop);
uint32_t pathcost = 0;

routes_.emplace(std::piecewise_construct, std::forward_as_tuple(keyF),
std::forward_as_tuple(*this, route, nexthop,
port_name, pathcost));

// FIXME: add also the /32 route?
// If the new address is not a /32, add a route to the local network
// (i.e. the network directly reachable through the inteface)
if (netmask_route != "255.255.255.255") {

// Add the route in the fast path
uint32_t networkDec = ip_string_to_nbo_uint(ip_route) &
ip_string_to_nbo_uint(netmask_route);
std::string network = nbo_uint_to_ip_string(networkDec);
rt_k key2{
.netmask_len = get_netmask_length(netmask_route),
.network = networkDec,
};

rt_v value2{
.port = uint32_t(port_index),
.nexthop = 0, /* 0.0.0.0 */
.type = TYPE_NOLOCALINTERFACE,
};

routing_table.set(key2, value2);

logger()->info(
"Added route [network: {0}/{1} - nexthop: {2} - interface: {3}]",
network, get_netmask_length(netmask_route), "0.0.0.0", port_name);

// Add the route in the table of the control plane

std::string nexthop("local");
std::string route = network + "/" +
std::to_string(get_netmask_length(netmask_route));
std::tuple<string, string> keyF(route, nexthop);
uint32_t pathcost = 0;

routes_.emplace(std::piecewise_construct, std::forward_as_tuple(keyF),
std::forward_as_tuple(*this, route, nexthop,
port_name, pathcost));
}
}

/*
Expand Down

0 comments on commit 0b5c7f5

Please sign in to comment.