Commit 2a0dd9c8 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Merge branch 'handle_fqdn_node_id' into 'develop'

Handle fqdn node

See merge request oai/cn5g/oai-cn5g-smf!65
parents 78caddee e90b12f0
......@@ -1041,6 +1041,43 @@ struct node_id_s {
return false;
}
};
bool operator==(const std::string& f) const {
if ((NODE_ID_TYPE_FQDN == this->node_id_type) && (fqdn.compare(f) == 0)) {
return true;
} else {
return false;
}
};
bool operator==(const struct in_addr& a) const {
if ((NODE_ID_TYPE_IPV4_ADDRESS == this->node_id_type) &&
(a.s_addr == u1.ipv4_address.s_addr)) {
return true;
} else {
return false;
}
};
bool operator==(const struct in6_addr& i) const {
if ((NODE_ID_TYPE_IPV6_ADDRESS == this->node_id_type) &&
(i.s6_addr32[0] == this->u1.ipv6_address.s6_addr32[0]) &&
(i.s6_addr32[1] == this->u1.ipv6_address.s6_addr32[1]) &&
(i.s6_addr32[2] == this->u1.ipv6_address.s6_addr32[2]) &&
(i.s6_addr32[3] == this->u1.ipv6_address.s6_addr32[3])) {
return true;
} else {
return false;
}
};
std::string toString() const {
if (NODE_ID_TYPE_FQDN == this->node_id_type) {
return fqdn;
}
if (NODE_ID_TYPE_IPV4_ADDRESS == this->node_id_type) {
return conv::toString(u1.ipv4_address);
} else if (NODE_ID_TYPE_IPV6_ADDRESS == this->node_id_type) {
return conv::toString(u1.ipv6_address);
}
return std::string("Node id - unknown node id type");
}
};
typedef struct node_id_s node_id_t;
//-------------------------------------
......
......@@ -123,6 +123,59 @@ class pfcp_ie : public stream_serializable {
};
static pfcp_ie* new_pfcp_ie_from_stream(std::istream& is);
// from SPGWC
static bool string_to_dotted(const std::string& str, std::string& dotted) {
uint8_t offset = 0;
uint8_t* last_size;
uint8_t word_length = 0;
uint8_t value[str.length() + 1];
dotted = {};
last_size = &value[0];
while (str[offset]) {
// We replace the . by the length of the word
if (str[offset] == '.') {
*last_size = word_length;
word_length = 0;
last_size = &value[offset + 1];
} else {
word_length++;
value[offset + 1] = str[offset];
}
offset++;
}
*last_size = word_length;
dotted.assign((const char*) value, str.length() + 1);
return true;
};
static bool dotted_to_string(const std::string& dot, std::string& no_dot) {
// uint8_t should be enough, but uint16 if length > 255.
uint16_t offset = 0;
bool result = true;
no_dot = {};
while (offset < dot.length()) {
if (dot[offset] < 64) {
if ((offset + dot[offset]) <= dot.length()) {
if (offset) {
no_dot.push_back('.');
}
no_dot.append(&dot[offset + 1], dot[offset]);
}
offset = offset + 1 + dot[offset];
} else {
// should not happen, consume bytes
no_dot.push_back(dot[offset++]);
result = false;
}
}
return result;
};
};
//------------------------------------------------------------------------------
class pfcp_grouped_ie : public pfcp_ie {
......@@ -3354,7 +3407,7 @@ class pfcp_node_id_ie : public pfcp_ie {
ipv6_address = b.u1.ipv6_address;
break;
case pfcp::NODE_ID_TYPE_FQDN:
tlv.add_length(sizeof(b.fqdn));
tlv.add_length(b.fqdn.length() + 1);
fqdn = b.fqdn;
break;
default:;
......@@ -3397,9 +3450,11 @@ class pfcp_node_id_ie : public pfcp_ie {
case pfcp::NODE_ID_TYPE_IPV6_ADDRESS:
ipv6_address_dump_to(os, ipv6_address);
break;
case pfcp::NODE_ID_TYPE_FQDN:
os << fqdn;
break;
case pfcp::NODE_ID_TYPE_FQDN: {
std::string dotted = {};
pfcp_ie::string_to_dotted(fqdn, dotted);
os << dotted;
} break;
default:;
}
}
......@@ -3430,7 +3485,9 @@ class pfcp_node_id_ie : public pfcp_ie {
}
char e[check_length];
is.read(e, check_length);
fqdn.assign(e, check_length);
std::string dot = {};
dot.assign(e, check_length);
pfcp_ie::dotted_to_string(dot, fqdn);
} break;
default:;
}
......
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