Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/fil
option java_generic_services = true;
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: TrafficRoutingAssistant]
// [#protodoc-title: Tra]

service TraService {
rpc Create(TraServiceRequest) returns (TraServiceResponse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ message RouteMatch {
// The domain from Request URI or Route Header.
string domain = 1;
}

// The header to get match parameter, default is "Route".
string header = 2;

// The parameter to get domain, default is "host".
string parameter = 3;
}

message RouteAction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ message SipProxy {
// +---------+-------------------------+----------+------------------------------------------------------------------------------+
google.protobuf.Duration transaction_timeout = 1;

// own domain name
string own_domain = 2;
// The service to match for ep insert
repeated LocalService local_services = 2;

// points to domain match with own_domain
string domain_match_parameter_name = 3;
tra.v3alpha.TraServiceConfig tra_service_config = 3;

tra.v3alpha.TraServiceConfig tra_service_config = 4;
// Whether via header is operated, including add via for request and pop via for response
// False: sip service proxy
// True: sip load balancer
bool operate_via = 4;
}

// The human readable prefix to use when emitting statistics.
Expand Down Expand Up @@ -111,14 +113,45 @@ message SipProtocolOptions {
bool registration_affinity = 2;

// Customized affinity
repeated CustomizedAffinity customized_affinity = 3;
CustomizedAffinity customized_affinity = 3;
}

// For affinity
message CustomizedAffinity {
// Affinity rules to conclude the upstream endpoint
repeated CustomizedAffinityEntry entries = 1;

// Configures whether load balance should be stopped or continued after affinity handling.
bool stop_load_balance = 2;
}

message CustomizedAffinityEntry {
// Affinity key for TRA query/subscribe
string key_name = 1;

bool query = 2;
// Whether subscribe to TRA is required
bool subscribe = 2;

// Whether query to TRA is required
bool query = 3;

// Local cache
Cache cache = 4;
}

message Cache {
// Affinity local cache item max number
int32 max_cache_item = 1;

// Whether query result can be added to local cache
bool add_query_to_cache = 2;
}

// Local Service
message LocalService {
//The domain need to matched
string domain = 1;

bool subscribe = 3;
//The parameter to get domain
string parameter = 2;
}
27 changes: 19 additions & 8 deletions contrib/sip_proxy/filters/network/source/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ envoy_cc_library(
srcs = ["app_exception_impl.cc"],
hdrs = ["app_exception_impl.h"],
deps = [
":protocol_interface",
":sip_lib",
":utility_interface",
"//envoy/buffer:buffer_interface",
],
)
Expand All @@ -28,7 +28,7 @@ envoy_cc_contrib_extension(
":app_exception_lib",
":conn_manager_lib",
":decoder_lib",
":protocol_interface",
":utility_interface",
"//contrib/sip_proxy/filters/network/source/filters:filter_config_interface",
"//contrib/sip_proxy/filters/network/source/filters:well_known_names",
"//contrib/sip_proxy/filters/network/source/router:router_lib",
Expand All @@ -48,8 +48,8 @@ envoy_cc_library(
":app_exception_lib",
":decoder_lib",
":encoder_lib",
":protocol_interface",
":stats_lib",
":utility_lib",
"//contrib/sip_proxy/filters/network/source/router:router_interface",
"//contrib/sip_proxy/filters/network/source/tra:tra_lib",
"//envoy/event:deferred_deletable",
Expand Down Expand Up @@ -84,8 +84,8 @@ envoy_cc_library(
hdrs = ["decoder.h"],
deps = [
":app_exception_lib",
":protocol_interface",
":stats_lib",
":utility_interface",
"//contrib/sip_proxy/filters/network/source/filters:filter_interface",
"//source/common/buffer:buffer_lib",
],
Expand All @@ -97,8 +97,8 @@ envoy_cc_library(
hdrs = ["encoder.h"],
deps = [
":app_exception_lib",
":protocol_interface",
":stats_lib",
":utility_interface",
"//contrib/sip_proxy/filters/network/source/filters:filter_interface",
"//source/common/buffer:buffer_lib",
],
Expand All @@ -116,17 +116,26 @@ envoy_cc_library(
"//envoy/buffer:buffer_interface",
"//source/common/common:macros",
"//source/common/http:header_map_lib",
"@envoy_api//contrib/envoy/extensions/filters/network/sip_proxy/v3alpha:pkg_cc_proto",
],
)

envoy_cc_library(
name = "utility_lib",
srcs = ["utility.cc"],
deps = [
":utility_interface",
"//contrib/sip_proxy/filters/network/source/filters:filter_interface",
],
)

envoy_cc_library(
name = "protocol_interface",
name = "utility_interface",
hdrs = [
"protocol.h",
"utility.h",
],
external_deps = ["abseil_optional"],
deps = [
":conn_state_lib",
":decoder_events_lib",
":metadata_lib",
":sip_lib",
Expand All @@ -135,8 +144,10 @@ envoy_cc_library(
"//envoy/registry",
"//source/common/common:assert_lib",
"//source/common/config:utility_lib",
"//source/common/protobuf",
"//source/common/singleton:const_singleton",
"@envoy_api//contrib/envoy/extensions/filters/network/sip_proxy/tra/v3alpha:pkg_cc_proto",
"@envoy_api//contrib/envoy/extensions/filters/network/sip_proxy/v3alpha:pkg_cc_proto",
],
)

Expand Down
74 changes: 71 additions & 3 deletions contrib/sip_proxy/filters/network/source/app_exception_impl.cc
Original file line number Diff line number Diff line change
@@ -1,16 +1,84 @@
#include "contrib/sip_proxy/filters/network/source/app_exception_impl.h"

#include <sstream>

namespace Envoy {
namespace Extensions {
namespace NetworkFilters {
namespace SipProxy {

DirectResponse::ResponseType AppException::encode(MessageMetadata& metadata,
Buffer::Instance& buffer) const {
(void)metadata;
(void)buffer;
std::stringstream output;

// Top line
output << "SIP/2.0 503 Service Unavailable\r\n";

// To
if (!absl::get<VectorHeader>(metadata.msgHeaderList()[HeaderType::To]).empty()) {
auto to = absl::get<VectorHeader>(metadata.msgHeaderList()[HeaderType::To])[0];
output << fmt::format("To: {}", to);

if (to.find("tag=") == absl::string_view::npos) {

// We could simply use the time of day as a tag; however, that is not unique
// enough. So, let's perturb the time of day with a salt to get a better
// unique number. The salt I am using here is the summation of each
// character of the proxy's IP address
output << ";tag=";
if (metadata.ep().has_value() && metadata.ep().value().length() > 0) {
output << fmt::format("{}-", metadata.ep().value());
}
std::time_t t;
long s = 0;
t = time(&t);
s = std::labs(t - s);
output << fmt::format("{}", s);
}
output << "\r\n";
} else {
ENVOY_LOG(error, "No \"To\" in received message");
}

// From
if (!absl::get<VectorHeader>(metadata.msgHeaderList()[HeaderType::From]).empty()) {
output << fmt::format("From: {}\r\n",
absl::get<VectorHeader>(metadata.msgHeaderList()[HeaderType::From])[0]);
} else {
ENVOY_LOG(error, "No \"From\" in received message");
}

// Call-ID
if (!absl::get<VectorHeader>(metadata.msgHeaderList()[HeaderType::From]).empty()) {
output << fmt::format("Call-ID: {}\r\n",
absl::get<VectorHeader>(metadata.msgHeaderList()[HeaderType::CallId])[0]);
} else {
ENVOY_LOG(error, "No \"Call-ID\" in received message");
}

// Via
for (auto via : absl::get<VectorHeader>(metadata.msgHeaderList()[HeaderType::Via])) {
output << fmt::format("Via: {}\r\n", via);
}

// CSeq
if (!absl::get<VectorHeader>(metadata.msgHeaderList()[HeaderType::From]).empty()) {
output << fmt::format("CSeq: {}\r\n",
absl::get<VectorHeader>(metadata.msgHeaderList()[HeaderType::Cseq])[0]);
} else {
ENVOY_LOG(error, "No \"Cseq\" in received message");
}

// Failed Reason
output << fmt::format("Reason: {}\r\n", what());

// Content-length
output << "Content-Length: 0\r\n";

// End
output << "\r\n";

// TODO
buffer.add(output.str());

return DirectResponse::ResponseType::Exception;
}
Expand Down
6 changes: 4 additions & 2 deletions contrib/sip_proxy/filters/network/source/app_exception_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
#include "envoy/common/exception.h"

#include "contrib/sip_proxy/filters/network/source/metadata.h"
#include "contrib/sip_proxy/filters/network/source/protocol.h"
#include "contrib/sip_proxy/filters/network/source/sip.h"
#include "contrib/sip_proxy/filters/network/source/utility.h"

namespace Envoy {
namespace Extensions {
namespace NetworkFilters {
namespace SipProxy {

struct AppException : public EnvoyException, public DirectResponse {
struct AppException : public EnvoyException,
public DirectResponse,
Logger::Loggable<Logger::Id::connection> {
AppException(AppExceptionType type, const std::string& what)
: EnvoyException(what), type_(type) {}
AppException(const AppException& ex) : EnvoyException(ex.what()), type_(ex.type_) {}
Expand Down
22 changes: 8 additions & 14 deletions contrib/sip_proxy/filters/network/source/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,14 @@ addUniqueClusters(absl::flat_hash_set<std::string>& clusters,
ProtocolOptionsConfigImpl::ProtocolOptionsConfigImpl(
const envoy::extensions::filters::network::sip_proxy::v3alpha::SipProtocolOptions& config)
: session_affinity_(config.session_affinity()),
registration_affinity_(config.registration_affinity()) {

for (const auto& affinity : config.customized_affinity()) {
CustomizedAffinity aff(affinity.key_name(), affinity.query(), affinity.subscribe());
customized_affinity_list_.emplace_back(aff);
}
}
registration_affinity_(config.registration_affinity()),
customized_affinity_(config.customized_affinity()) {}

bool ProtocolOptionsConfigImpl::sessionAffinity() const { return session_affinity_; }
bool ProtocolOptionsConfigImpl::registrationAffinity() const { return registration_affinity_; }
const std::vector<CustomizedAffinity>& ProtocolOptionsConfigImpl::customizedAffinityList() const {
return customized_affinity_list_;
const envoy::extensions::filters::network::sip_proxy::v3alpha::CustomizedAffinity&
ProtocolOptionsConfigImpl::customizedAffinity() const {
return customized_affinity_;
}

Network::FilterFactoryCb SipProxyFilterConfigFactory::createFilterFactoryFromProtoTyped(
Expand All @@ -66,9 +62,7 @@ Network::FilterFactoryCb SipProxyFilterConfigFactory::createFilterFactoryFromPro
auto transaction_info_ptr = std::make_shared<Router::TransactionInfo>(
cluster, context.threadLocal(),
static_cast<std::chrono::milliseconds>(
PROTOBUF_GET_MS_OR_DEFAULT(proto_config.settings(), transaction_timeout, 32000)),
proto_config.settings().own_domain(),
proto_config.settings().domain_match_parameter_name());
PROTOBUF_GET_MS_OR_DEFAULT(proto_config.settings(), transaction_timeout, 32000)));
transaction_info_ptr->init();
transaction_infos->emplace(cluster, transaction_info_ptr);
}
Expand Down Expand Up @@ -96,8 +90,8 @@ ConfigImpl::ConfigImpl(
settings_(std::make_shared<SipSettings>(
static_cast<std::chrono::milliseconds>(
PROTOBUF_GET_MS_OR_DEFAULT(config.settings(), transaction_timeout, 32000)),
config.settings().own_domain(), config.settings().domain_match_parameter_name(),
config.settings().tra_service_config())) {
config.settings().local_services(), config.settings().tra_service_config(),
config.settings().operate_via())) {

if (config.sip_filters().empty()) {
ENVOY_LOG(debug, "using default router filter");
Expand Down
6 changes: 4 additions & 2 deletions contrib/sip_proxy/filters/network/source/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ class ProtocolOptionsConfigImpl : public ProtocolOptionsConfig {

bool sessionAffinity() const override;
bool registrationAffinity() const override;
const std::vector<CustomizedAffinity>& customizedAffinityList() const override;
const envoy::extensions::filters::network::sip_proxy::v3alpha::CustomizedAffinity&
customizedAffinity() const override;

private:
bool session_affinity_;
bool registration_affinity_;
std::vector<CustomizedAffinity> customized_affinity_list_;
const envoy::extensions::filters::network::sip_proxy::v3alpha::CustomizedAffinity
customized_affinity_;
};

/**
Expand Down
Loading