Commit 68a48b5f authored by kevin wilhelm's avatar kevin wilhelm Committed by Stefan Spettel

REMOVE COMMENTS cout and unaccessary logs

add: test, framed routing module, framed routing config setup routing
uplink
refactor: oai_upf cmake-file
parent abf87094
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
#include <utility> #include <utility>
#include <sstream> #include <sstream>
#include <iostream> #include <iostream>
#include <upf_config.hpp>
extern oai::config::upf_config upf_cfg;
namespace fr { namespace fr {
...@@ -13,40 +16,68 @@ FramedRouting::FramedRouting(std::shared_ptr<LocalRouting> localRouting) ...@@ -13,40 +16,68 @@ FramedRouting::FramedRouting(std::shared_ptr<LocalRouting> localRouting)
: localRouting(std::move(localRouting)) {} : localRouting(std::move(localRouting)) {}
void FramedRouting::addFramedRoute( void FramedRouting::addFramedRoute(
const uint32_t ue_ip, const pfcp::framed_route_s& framed_route_s, const uint32_t ue_ip, const pfcp::framed_route_s& framed_route_s) {
uint32_t gatewayIP) {
std::stringstream ss(framed_route_s.framed_route); std::stringstream ss(framed_route_s.framed_route);
const char delimiter = ' ';
std::string ipsubnetmask; std::string ipsubnetmask;
while (std::getline(ss, ipsubnetmask, delimiter)) { while (std::getline(ss, ipsubnetmask, this->pdi_fr_delimeter)) {
std::pair<uint32_t, uint32_t> ipCidr = this->extractIPCidr(ipsubnetmask); std::pair<uint32_t, uint32_t> ipCidr = this->extractIPCidr(ipsubnetmask);
auto key = createFramedRoutingKey(ipCidr); auto key = createFramedRoutingKey(ipCidr);
auto routing_info = createLocalRoutingInformation(ipCidr, gatewayIP); auto routing_info = createLocalRoutingInformation(ipCidr);
auto snat_info = createLocalSnatInformation(ipCidr);
std::cout << "retrieve dest ip subnet: " << ipCidr.second << std::endl;
std::cout << "retrieve network ip: " << key.networkAdress << std::endl;
this->KeyToIp.insert({key, ue_ip}); this->KeyToIp.insert({key, ue_ip});
localRouting->addRoute(routing_info); localRouting->add_route(routing_info);
localRouting->add_source_snat(snat_info);
} }
} }
uint32_t FramedRouting::retrieveFramedUEIp( uint32_t FramedRouting::retrieveUEIp(const uint32_t destination_ip) const {
const uint32_t destination_ip) const { std::cout << "retrieve dest ip " << destination_ip << std::endl;
for (uint32_t i = 32; i > 0; --i) { for (uint32_t i = 32; i > 0; --i) {
FramedRoutingKey framedRoutingKey = FramedRoutingKey framedRoutingKey =
createFramedRoutingKey({destination_ip, i}); createFramedRoutingKey({destination_ip, i});
std::cout << "retrieve dest ip subnet: " << i << std::endl;
std::cout << "retrieve network ip: " << framedRoutingKey.networkAdress
<< std::endl;
auto ip = this->KeyToIp.find(framedRoutingKey); auto ip = this->KeyToIp.find(framedRoutingKey);
if (ip != KeyToIp.end()) { if (ip != KeyToIp.end()) {
std::cout << "find at: " << i << std::endl;
return ip->second; return ip->second;
}; };
}; };
return 0; return 0;
}; };
void FramedRouting::removeEntry(uint32_t ue_ip) { uint32_t FramedRouting::retrieveUEIp(
const pfcp::framed_route_s& framed_route_s) const {
std::cout << framed_route_s.framed_route << std::endl;
std::stringstream ss(framed_route_s.framed_route);
std::string ipsubnetmask;
Logger::pfcp_switch().info(
"Retrieving Frame string: " + framed_route_s.framed_route);
while (std::getline(ss, ipsubnetmask, this->pdi_fr_delimeter)) {
Logger::pfcp_switch().info("Retrieving Frame string: " + ipsubnetmask);
std::pair<uint32_t, uint32_t> ipCidr = this->extractIPCidr(ipsubnetmask);
FramedRoutingKey framedRoutingKey =
createFramedRoutingKey({ipCidr.first, ipCidr.second});
auto ip = this->KeyToIp.find(framedRoutingKey);
if (ip != KeyToIp.end()) {
return ip->second;
}
}
return 0;
};
void FramedRouting::remove_entry(uint32_t ue_ip) {
for (uint32_t i = 32; i > 0; --i) { for (uint32_t i = 32; i > 0; --i) {
FramedRoutingKey framedRoutingKey = createFramedRoutingKey({ue_ip, i}); FramedRoutingKey framedRoutingKey = createFramedRoutingKey({ue_ip, i});
auto ip = this->KeyToIp.find(framedRoutingKey); auto ip = this->KeyToIp.find(framedRoutingKey);
if (ip != KeyToIp.end()) { if (ip != KeyToIp.end()) {
this->KeyToIp.erase(ip); this->KeyToIp.erase(ip);
this->localRouting->deleteRoute(ip->second); this->localRouting->delete_route(ip->second);
}; };
}; };
} }
...@@ -106,20 +137,33 @@ FramedRoutingKey FramedRouting::createFramedRoutingKey( ...@@ -106,20 +137,33 @@ FramedRoutingKey FramedRouting::createFramedRoutingKey(
return FramedRoutingKey{networkAdress, subnet_adress}; return FramedRoutingKey{networkAdress, subnet_adress};
} }
// todo(phine.tech) replace with better method in local routing.
RoutingInformation FramedRouting::createLocalRoutingInformation( RoutingInformation FramedRouting::createLocalRoutingInformation(
const std::pair<uint32_t, uint32_t> ipCidr, const std::pair<uint32_t, uint32_t>& ipCidr) const {
const uint32_t gateway_ip) const {
struct in_addr addr; struct in_addr addr;
addr.s_addr = htonl(ipCidr.first); addr.s_addr = htonl(ipCidr.first);
std::string destination = inet_ntoa(addr); std::string destination = inet_ntoa(addr);
uint32_t netmask = ipCidr.second; uint32_t netmask = ipCidr.second;
std::string device = "tun0"; std::string device = "tun0";
// todo (phine.tech) use correct DNN // todo (phine.tech) use correct DNN
struct in_addr address4_gw = {}; struct in_addr address4_gw = {};
address4_gw.s_addr = gateway_ip; address4_gw.s_addr = upf_cfg.pdns[0].network_ipv4.s_addr + be32toh(1);
std::string gateway_address = inet_ntoa(address4_gw); std::string gateway_address = inet_ntoa(address4_gw);
return fr::RoutingInformation{destination, netmask, device, gateway_address}; return fr::RoutingInformation{destination, netmask, device, gateway_address};
} }
// todo(phine.tech) replace with better method in local routing.
SourceNatInformation FramedRouting::createLocalSnatInformation(
const std::pair<uint32_t, uint32_t>& ipCidr) const {
struct in_addr addr;
addr.s_addr = htonl(ipCidr.first);
std::string destination = inet_ntoa(addr);
uint32_t netmask = ipCidr.second;
std::string device = upf_cfg.n6.if_name;
std::string snat_address = oai::utils::conv::toString(upf_cfg.n6.addr4);
return SourceNatInformation{destination, netmask, device, snat_address};
}
} // namespace fr } // namespace fr
\ No newline at end of file
...@@ -22,15 +22,18 @@ namespace fr { ...@@ -22,15 +22,18 @@ namespace fr {
virtual ~FramedRouting() = default; virtual ~FramedRouting() = default;
[[nodiscard]] uint32_t [[nodiscard]] uint32_t
retrieveFramedUEIp(const uint32_t destination_ip) const; retrieveUEIp(const uint32_t destination_ip) const;
void addFramedRoute(uint32_t ue_ip, const pfcp::framed_route_s &framed_route_s,uint32_t gatewayIP); [[nodiscard]] uint32_t retrieveUEIp(const pfcp::framed_route_s &framed_route_s) const;
void removeEntry(uint32_t ue_ip); void addFramedRoute(uint32_t ue_ip, const pfcp::framed_route_s &framed_route_s);
void remove_entry(uint32_t ue_ip);
// todo(kw) create a facade for fr options. // todo(kw) create a facade for fr options.
private: private:
const char pdi_fr_delimeter = ' ';
// todo(kw) discuss size or use constant // todo(kw) discuss size or use constant
std::shared_ptr<LocalRouting> localRouting; std::shared_ptr<LocalRouting> localRouting;
...@@ -43,7 +46,13 @@ namespace fr { ...@@ -43,7 +46,13 @@ namespace fr {
[[nodiscard]] std::pair<uint32_t, uint32_t> extractIPCidr(const std::string &fr_subnet) const; [[nodiscard]] std::pair<uint32_t, uint32_t> extractIPCidr(const std::string &fr_subnet) const;
[[nodiscard]] FramedRoutingKey createFramedRoutingKey(std::pair<uint32_t, uint32_t> ipCidr) const; [[nodiscard]] FramedRoutingKey createFramedRoutingKey(std::pair<uint32_t, uint32_t> ipCidr) const;
[[nodiscard]] RoutingInformation createLocalRoutingInformation(std::pair<uint32_t, uint32_t> ipCidr, uint32_t gateway_ip) const;
[[nodiscard]] RoutingInformation
createLocalRoutingInformation(const std::pair<uint32_t, uint32_t> &ipCidr) const;
[[nodiscard]] SourceNatInformation
createLocalSnatInformation(const std::pair<uint32_t, uint32_t> &ipCidr) const;
}; };
......
...@@ -10,40 +10,62 @@ ...@@ -10,40 +10,62 @@
namespace fr { namespace fr {
void LocalRouting::addRoute(const RoutingInformation& routing_information) { void LocalRouting::add_route(const RoutingInformation& routing_information) {
auto original_cerr_streambuf = std::cerr.rdbuf(nullptr ); auto original_cerr_streambuf = std::cerr.rdbuf(nullptr);
auto cmd = fmt::format( auto cmd = fmt::format(
"ip route add {}/{} via {} dev tun0", routing_information.destination, "ip route add {}/{} via {} dev tun0", routing_information.destination,
routing_information.netmask, routing_information.gateway_address); routing_information.netmask, routing_information.gateway_address);
auto rc = system((const char*) cmd.c_str()); auto rc = system((const char*) cmd.c_str());
if (rc == 0) { if (rc == 0) {
Logger::pfcp_switch().info( Logger::pfcp_switch().info("Route created");
"Route created"); this->routeInfoToRtEntry.insert(
this->routeInfoToRtEntry.insert({routing_information.destination,routing_information}); {routing_information.destination, routing_information});
} else {
Logger::pfcp_switch().warn("Route information not correct or does exists!");
} }
Logger::pfcp_switch().warn(
"Route information not correct or does not exists!");
} }
void LocalRouting::deleteRoute(const uint32_t& network_address) { void LocalRouting::delete_route(const uint32_t& network_address) {
// todo(phine.tech) create function remove dublicated_code // todo(phine.tech) create function remove dublicated_code
auto original_cerr_streambuf = std::cerr.rdbuf(nullptr ); auto original_cerr_streambuf = std::cerr.rdbuf(nullptr);
struct in_addr addr; std::string destination = convert_s_addr_to_string(network_address);
addr.s_addr = htonl(network_address); auto routing_info_iterator = this->routeInfoToRtEntry.find(destination);
std::string destination = inet_ntoa(addr);
auto routing_info_iterator = this->routeInfoToRtEntry.find(destination);
if (routing_info_iterator != routeInfoToRtEntry.end()) { if (routing_info_iterator != routeInfoToRtEntry.end()) {
const auto routing_information = routing_info_iterator->second; const auto routing_information = routing_info_iterator->second;
auto cmd = fmt::format( auto cmd = fmt::format(
"ip route del {}/{} via {} dev tun0", routing_information.destination, "ip route del {}/{} via {} dev tun0", routing_information.destination,
routing_information.netmask, routing_information.gateway_address); routing_information.netmask, routing_information.gateway_address);
auto rc = system((const char*) cmd.c_str() ); const auto rc = system((const char*) cmd.c_str());
if (rc == 0) { if (rc == 0) {
Logger::pfcp_switch().info( Logger::pfcp_switch().info("Route deleted");
"Route deleted"); } else {
}
Logger::pfcp_switch().warn( Logger::pfcp_switch().warn(
"Route information not correct or does not exists!"); "Route information not correct or does not exists!");
}
} }
}; };
void LocalRouting::add_source_snat(
const SourceNatInformation& source_nat_information) {
const std::string cmd = fmt::format(
"iptables -t nat -A POSTROUTING -s {}/{} -o {} -j SNAT --to "
"{}",
source_nat_information.destination, source_nat_information.netmask,
source_nat_information.device, source_nat_information.snat_address);
const auto rc = system((const char*) cmd.c_str());
if (rc == 0) {
Logger::pfcp_switch().info("Source NAT added");
} else {
Logger::pfcp_switch().warn("Source NAT not correct or does exists!");
}
}
void LocalRouting::delete_ssnat(const uint32_t& network_address) {}
std::string LocalRouting::convert_s_addr_to_string(
const uint32_t& network_address) {
struct in_addr addr;
addr.s_addr = htonl(network_address);
return inet_ntoa(addr);
}
} // namespace fr } // namespace fr
\ No newline at end of file
...@@ -11,25 +11,35 @@ ...@@ -11,25 +11,35 @@
namespace fr { namespace fr {
struct RoutingInformation { struct RoutingInformation {
std::string destination; std::string destination;
uint32_t netmask; uint32_t netmask =0;
std::string device; std::string device;
std::string gateway_address; std::string gateway_address;
}; };
struct SourceNatInformation {
std::string destination;
uint32_t netmask =0;
std::string device;
std::string snat_address;
};
//todo (kw) rename class //todo (kw) rename class
class LocalRouting { class LocalRouting {
public: public:
virtual void addRoute(const RoutingInformation &routing_information); virtual void add_route(const RoutingInformation &routing_information);
virtual void deleteRoute(const uint32_t & network_address); virtual void delete_route(const uint32_t & network_address);
private: virtual void add_source_snat(const SourceNatInformation &source_nat_information);
std::unordered_map<std::string, RoutingInformation> routeInfoToRtEntry{};
// todo(phine.tech) implement delete if needed
virtual void delete_ssnat(const uint32_t & network_address);
short getInterfaceIndex(const std::string& interfaceName); private:
std::unordered_map<std::string, RoutingInformation> routeInfoToRtEntry{};
std::string convert_s_addr_to_string(const uint32_t &network_address);
}; };
} // fr } // fr
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
using namespace pfcp; using namespace pfcp;
using namespace oai::upf::app; using namespace oai::upf::app;
extern upf_n4* upf_n4_inst; extern upf_n4* upf_n4_inst;
extern oai::config::upf_config upf_cfg; extern oai::config::upf_config upf_cfg;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -66,8 +65,8 @@ bool pfcp_pdr::look_up_pack_in_access( ...@@ -66,8 +65,8 @@ bool pfcp_pdr::look_up_pack_in_access(
if (!pdi.second.ue_ip_address.second.v4) { if (!pdi.second.ue_ip_address.second.v4) {
return false; return false;
} }
if (!upf_cfg.enable_fr&&pdi.second.ue_ip_address.second.ipv4_address.s_addr != iph->saddr) { if (pdi.second.ue_ip_address.second.ipv4_address.s_addr != iph->saddr) {
return false; return false;
} }
} }
// SDF filter // SDF filter
...@@ -103,7 +102,8 @@ bool pfcp_pdr::look_up_pack_in_core( ...@@ -103,7 +102,8 @@ bool pfcp_pdr::look_up_pack_in_core(
return false; return false;
} }
if (!upf_cfg.enable_fr&& pdi.second.ue_ip_address.second.ipv4_address.s_addr != iph->daddr) { if (!upf_cfg.enable_fr &&
pdi.second.ue_ip_address.second.ipv4_address.s_addr != iph->daddr) {
// Logger::pfcp_switch().info( "look_up_pack_in_core failed PDR id %4x, // Logger::pfcp_switch().info( "look_up_pack_in_core failed PDR id %4x,
// cause PDR ue_ip_address %8X do not match IP dest %8X of packet ", // cause PDR ue_ip_address %8X do not match IP dest %8X of packet ",
// pdr_id.rule_id, pdi.second.ue_ip_address.second.ipv4_address.s_addr, // pdr_id.rule_id, pdi.second.ue_ip_address.second.ipv4_address.s_addr,
......
...@@ -333,17 +333,15 @@ void pfcp_switch::setup_pdn_interfaces() { ...@@ -333,17 +333,15 @@ void pfcp_switch::setup_pdn_interfaces() {
oai::utils::conv::toString(it.network_ipv4), oai::utils::conv::toString(it.network_ipv4),
static_cast<uint32_t>(it.prefix_ipv4), "tun0", static_cast<uint32_t>(it.prefix_ipv4), "tun0",
oai::utils::conv::toString(address4_gw)}; oai::utils::conv::toString(address4_gw)};
local_routing->addRoute(routing_info); local_routing->add_route(routing_info);
} }
if (upf_cfg.enable_snat) { if (upf_cfg.enable_snat) {
cmd = fmt::format( auto snat_info = fr::SourceNatInformation{
"iptables -t nat -A POSTROUTING -s {}/{} -o {} -j SNAT --to " oai::utils::conv::toString(it.network_ipv4),
"{}", static_cast<uint32_t>(it.prefix_ipv4), upf_cfg.n6.if_name,
oai::utils::conv::toString(it.network_ipv4).c_str(), it.prefix_ipv4, oai::utils::conv::toString(upf_cfg.n6.addr4)};
upf_cfg.n6.if_name.c_str(), local_routing->add_source_snat(snat_info);
oai::utils::conv::toString(upf_cfg.n6.addr4).c_str());
rc = system((const char*) cmd.c_str());
} }
} }
if (it.prefix_ipv6) { if (it.prefix_ipv6) {
...@@ -631,9 +629,11 @@ void pfcp_switch::add_pfcp_dl_pdr_by_ue_ip( ...@@ -631,9 +629,11 @@ void pfcp_switch::add_pfcp_dl_pdr_by_ue_ip(
entry(ue_ip, pdrs); entry(ue_ip, pdrs);
ue_ipv4_hbo2pfcp_pdr.insert(entry); ue_ipv4_hbo2pfcp_pdr.insert(entry);
if (upf_cfg.enable_fr) { if (upf_cfg.enable_fr) {
fr->addFramedRoute( Logger::pfcp_switch().info("fr_ue_ip %4x ", ue_ip);
ue_ip, pdr->pdi.second.framed_route.second, Logger::pfcp_switch().info(
upf_cfg.pdns[0].network_ipv4.s_addr + be32toh(1)); "framed routing ip: " +
pdr->pdi.second.framed_route.second.framed_route);
fr->addFramedRoute(ue_ip, pdr->pdi.second.framed_route.second);
} }
// Logger::pfcp_switch().info( "add_pfcp_dl_pdr_by_ue_ip UE IP %8x", ue_ip); // Logger::pfcp_switch().info( "add_pfcp_dl_pdr_by_ue_ip UE IP %8x", ue_ip);
} else { } else {
...@@ -656,7 +656,8 @@ void pfcp_switch::add_pfcp_dl_pdr_by_ue_ip( ...@@ -656,7 +656,8 @@ void pfcp_switch::add_pfcp_dl_pdr_by_ue_ip(
void pfcp_switch::remove_pfcp_dl_pdrs_by_ue_ip(const uint32_t ue_ip) { void pfcp_switch::remove_pfcp_dl_pdrs_by_ue_ip(const uint32_t ue_ip) {
ue_ipv4_hbo2pfcp_pdr.erase(ue_ip); ue_ipv4_hbo2pfcp_pdr.erase(ue_ip);
if (upf_cfg.enable_fr) { if (upf_cfg.enable_fr) {
this->fr->removeEntry(ue_ip); std::cout << "remove fr entry" << std::endl;
this->fr->remove_entry(ue_ip);
} }
} }
...@@ -1140,17 +1141,43 @@ void pfcp_switch::handle_pfcp_session_deletion_request( ...@@ -1140,17 +1141,43 @@ void pfcp_switch::handle_pfcp_session_deletion_request(
void pfcp_switch::pfcp_session_look_up_pack_in_access( void pfcp_switch::pfcp_session_look_up_pack_in_access(
struct iphdr* const iph, const std::size_t num_bytes, struct iphdr* const iph, const std::size_t num_bytes,
const endpoint& r_endpoint, const uint32_t tunnel_id) { const endpoint& r_endpoint, const uint32_t tunnel_id) {
bool isInAccess = false;
if (!upf_cfg.nsf.bypass_ul_pfcp_rules) { if (!upf_cfg.nsf.bypass_ul_pfcp_rules) {
std::shared_ptr<std::vector<std::shared_ptr<pfcp::pfcp_pdr>>> pdrs = {}; std::shared_ptr<std::vector<std::shared_ptr<pfcp::pfcp_pdr>>> pdrs = {};
if (get_pfcp_ul_pdrs_by_up_teid(tunnel_id, pdrs)) { if (get_pfcp_ul_pdrs_by_up_teid(tunnel_id, pdrs)) {
bool nocp = false; bool nocp = false;
bool buff = false; bool buff = false;
for (std::vector<std::shared_ptr<pfcp::pfcp_pdr>>::iterator it_pdr = for (auto it_pdr = pdrs->begin(); it_pdr < pdrs->end(); ++it_pdr) {
pdrs->begin(); // todo (kw) framed route ip
it_pdr < pdrs->end(); ++it_pdr) { isInAccess = (*it_pdr)->look_up_pack_in_access(
if ((*it_pdr)->look_up_pack_in_access( iph, num_bytes, r_endpoint, tunnel_id);
iph, num_bytes, r_endpoint, tunnel_id) || if (upf_cfg.enable_fr) {
(upf_cfg.enable_fr && fr->retrieveFramedUEIp(iph->saddr) > 0)) { std::cout
<< it_pdr->get()->pdi.second.framed_route.second.framed_route
<< std::endl;
const auto fr_ue_ip = fr->retrieveUEIp(be32toh(iph->saddr));
Logger::pfcp_switch().info(
"iph->saddr %d ",
it_pdr->get()->pdi.second.framed_route.second.framed_route);
Logger::pfcp_switch().info("iph->daddr %4x ", iph->daddr);
Logger::pfcp_switch().info("iph->saddr %4x ", iph->saddr);
Logger::pfcp_switch().info("fr_ue_ip %4x ", fr_ue_ip);
Logger::pfcp_switch().info(
"ipv4_address.s_addr: %4x ",
it_pdr->get()
->pdi.second.ue_ip_address.second.ipv4_address.s_addr);
isInAccess =
fr_ue_ip ==
it_pdr->get()
->pdi.second.ue_ip_address.second.ipv4_address.s_addr;
}
if (isInAccess) {
Logger::pfcp_switch().info(
"PDR/PDI IP is %4x ",
it_pdr->get()
->pdi.second.ue_ip_address.second.ipv4_address.s_addr);
Logger::pfcp_switch().info("Upstream IP is %4x ", iph->saddr);
std::shared_ptr<pfcp::pfcp_session> ssession = {}; std::shared_ptr<pfcp::pfcp_session> ssession = {};
uint64_t lseid = 0; uint64_t lseid = 0;
if ((*it_pdr)->get(lseid)) { if ((*it_pdr)->get(lseid)) {
...@@ -1218,11 +1245,9 @@ void pfcp_switch::pfcp_session_look_up_pack_in_core( ...@@ -1218,11 +1245,9 @@ void pfcp_switch::pfcp_session_look_up_pack_in_core(
bool is_pdr_ue_ip = get_pfcp_dl_pdrs_by_ue_ip(ue_ip, pdrs); bool is_pdr_ue_ip = get_pfcp_dl_pdrs_by_ue_ip(ue_ip, pdrs);
Logger::pfcp_switch().info("Is PDR", is_pdr_ue_ip); Logger::pfcp_switch().info("Is PDR", is_pdr_ue_ip);
if (!is_pdr_ue_ip && upf_cfg.enable_fr) { if (!is_pdr_ue_ip && upf_cfg.enable_fr) {
uint32_t fr_ip = fr->retrieveFramedUEIp(ue_ip); uint32_t fr_ip = fr->retrieveUEIp(ue_ip);
Logger::pfcp_switch().info("Fr IP", fr_ip); ue_ip = fr_ip != 0 ? fr_ip : ue_ip;
Logger::pfcp_switch().info("UE", ue_ip); is_pdr_ue_ip = get_pfcp_dl_pdrs_by_ue_ip(ue_ip, pdrs);
ue_ip = fr_ip != 0 ? fr_ip : ue_ip;
is_pdr_ue_ip = get_pfcp_dl_pdrs_by_ue_ip(ue_ip, pdrs);
} }
if (is_pdr_ue_ip) { if (is_pdr_ue_ip) {
bool nocp = false; bool nocp = false;
......
...@@ -33,9 +33,8 @@ add_executable( ...@@ -33,9 +33,8 @@ add_executable(
framed_routing/FramedRoutingTest.cpp framed_routing/FramedRoutingTest.cpp
framed_routing/mocks/LocalRoutingMock.h framed_routing/mocks/LocalRoutingMock.h
) )
set_property(TARGET upf PROPERTY ${CMAKE_CURRENT_BINARY_DIR}../upf)
add_dependencies(UPFTest upf) target_link_libraries(UPFTest PUBLIC GTest::gtest_main GTest::gmock_main fmt)
target_link_libraries(UPFTest PUBLIC FRAMED_ROUTING SIMPLE_SWITCH GTest::gtest_main GTest::gmock_main fmt)
include(GoogleTest) include(GoogleTest)
gtest_discover_tests(UPFTest) gtest_discover_tests(UPFTest)
#include <upf_config.hpp>
#include "FramedRoutingTest.h" #include "FramedRoutingTest.h"
extern oai::config::upf_config upf_cfg;
namespace fr { namespace fr {
TEST_F(FramedRoutingTest, CreateFramedRoute) { TEST_F(FramedRoutingTest, CreateFramedRoute) {
...@@ -8,47 +10,46 @@ TEST_F(FramedRoutingTest, CreateFramedRoute) { ...@@ -8,47 +10,46 @@ TEST_F(FramedRoutingTest, CreateFramedRoute) {
} }
TEST_F(FramedRoutingTest, AddRoutes) { TEST_F(FramedRoutingTest, AddRoutes) {
const uint32_t gatewayip = 0x01010102; auto framed_route = pfcp::framed_route_s{
auto framed_route = pfcp::framed_route_s{ "192.168.2.0/24 192.168.1.0/24 12.1.1.0/25 192.168.1.0/25 130.0.0.5 "
"192.168.2.0/24 192.168.1.0/24 12.1.1.0/25 192.168.1.0/25 130.0.0.5 192.168.128.0"}; "192.168.128.0"};
FramedRoutingTest::fr->addFramedRoute(ue_ip_one, framed_route);
FramedRoutingTest::fr->addFramedRoute(ue_ip_one, framed_route, gatewayip);
EXPECT_NO_FATAL_FAILURE(); EXPECT_NO_FATAL_FAILURE();
} }
TEST_F(FramedRoutingTest, AddRoutesEmptyIP) { TEST_F(FramedRoutingTest, AddRoutesEmptyIP) {
auto framed_route = pfcp::framed_route_s{""}; auto framed_route = pfcp::framed_route_s{""};
FramedRoutingTest::fr->addFramedRoute(ue_ip_one, framed_route, 0); FramedRoutingTest::fr->addFramedRoute(ue_ip_one, framed_route);
EXPECT_NO_FATAL_FAILURE(); EXPECT_NO_FATAL_FAILURE();
} }
TEST_F(FramedRoutingTest, AddRoutesDuplicates) { TEST_F(FramedRoutingTest, AddRoutesDuplicates) {
auto framed_route = pfcp::framed_route_s{"192.168.2.10/24 192.168.2.10/24"}; auto framed_route = pfcp::framed_route_s{"192.168.2.10/24 192.168.2.10/24"};
FramedRoutingTest::fr->addFramedRoute(ue_ip_one, framed_route, 0); FramedRoutingTest::fr->addFramedRoute(ue_ip_one, framed_route);
EXPECT_NO_FATAL_FAILURE(); EXPECT_NO_FATAL_FAILURE();
} }
TEST_F(FramedRoutingTest, retrieveSubnetNotExisting) { TEST_F(FramedRoutingTest, retrieveSubnetNotExisting) {
const auto dest_ip = FramedRoutingTest::fr->retrieveFramedUEIp(ue_ip_one); const auto dest_ip = FramedRoutingTest::fr->retrieveUEIp(ue_ip_one);
EXPECT_EQ(dest_ip, 0); EXPECT_EQ(dest_ip, 0);
} }
TEST_F(FramedRoutingTest, retrieveSubnetIP) { TEST_F(FramedRoutingTest, retrieveSubnetIP) {
auto framed_route = pfcp::framed_route_s{"192.168.2.0/25"}; auto framed_route = pfcp::framed_route_s{"192.168.2.0/25"};
FramedRoutingTest::fr->addFramedRoute(ue_ip_one, framed_route, 0); FramedRoutingTest::fr->addFramedRoute(ue_ip_one, framed_route);
uint32_t lookup_ip = 0xc0a8027a; // 192.168.2.122 uint32_t lookup_ip = 0xc0a8027a; // 192.168.2.122
const auto dest_ip = FramedRoutingTest::fr->retrieveFramedUEIp(lookup_ip); const auto dest_ip = FramedRoutingTest::fr->retrieveUEIp(lookup_ip);
EXPECT_EQ(dest_ip, ue_ip_one); EXPECT_EQ(dest_ip, ue_ip_one);
} }
TEST_F(FramedRoutingTest, retrieveSubnetIPWrongSubnet) { TEST_F(FramedRoutingTest, retrieveSubnetIPWrongSubnet) {
auto framed_route = pfcp::framed_route_s{"192.168.2.10/25"}; auto framed_route = pfcp::framed_route_s{"192.168.2.10/25"};
FramedRoutingTest::fr->addFramedRoute(ue_ip_one, framed_route, 0); FramedRoutingTest::fr->addFramedRoute(ue_ip_one, framed_route);
uint32_t lookup_ip = 0xc0a80280; uint32_t lookup_ip = 0xc0a80280;
const auto dest_ip = FramedRoutingTest::fr->retrieveFramedUEIp(lookup_ip); const auto dest_ip = FramedRoutingTest::fr->retrieveUEIp(lookup_ip);
EXPECT_EQ(dest_ip, 0); EXPECT_EQ(dest_ip, 0);
} }
} // namespace fr } // namespace fr
\ No newline at end of file
...@@ -6,16 +6,17 @@ ...@@ -6,16 +6,17 @@
#include "LocalRoutingTest.h" #include "LocalRoutingTest.h"
namespace fr { namespace fr {
TEST_F(LocalRoutingTest, AddAndDeleteRoutes) { TEST_F(LocalRoutingTest, AddAndDeleteRoutes) {
const auto localRouting = std::make_shared<LocalRouting>(); const auto localRouting = std::make_shared<LocalRouting>();
// 0xC0A80232= 192.168.2.50 // 0xC0A80232= 192.168.2.50
const std::string destination_adress = "192.168.128.0"; const std::string destination_adress = "192.168.128.0";
const int network_mask = 24; const int network_mask = 24;
const std::string device = "tun0"; const std::string device = "tun0";
const std::string gateway = "12.1.1.1"; const std::string gateway = "12.1.1.1";
RoutingInformation routingInformation = {destination_adress, network_mask, device, gateway}; RoutingInformation routingInformation = {
localRouting->addRoute(routingInformation); destination_adress, network_mask, device, gateway};
localRouting->deleteRoute(0xC0A88000); localRouting->add_route(routingInformation);
ASSERT_NO_FATAL_FAILURE(); localRouting->delete_route(0xC0A88000);
} ASSERT_NO_FATAL_FAILURE();
} }
\ No newline at end of file } // namespace fr
\ No newline at end of file
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
namespace fr { namespace fr {
class MockLocalRouting : public LocalRouting { class MockLocalRouting : public LocalRouting {
public: public:
MOCK_METHOD(bool, addRoute,(const RoutingInformation & routing_information),(override)); MOCK_METHOD(void, add_route,(const RoutingInformation & routing_information),(override));
MOCK_METHOD(bool, deleteRoute,(const uint32_t & network_address),(override)); MOCK_METHOD(void, delete_route,(const uint32_t & network_address),(override));
}; };
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment