Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add nexthop strategy plugins #7023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 15 commits into from
Closed
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
36 changes: 36 additions & 0 deletions include/ts/apidefs.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,42 @@ extern tsapi const char *const TS_PROTO_TAG_IPV6;
*/
#define TS_NULL_MLOC ((TSMLoc)0)

/* --------------------------------------------------------------------------
HostStatus types */

typedef enum {
TS_HOST_STATUS_INIT,
TS_HOST_STATUS_DOWN,
TS_HOST_STATUS_UP,
} TSHostStatus;

/* MUST match proxy/HostStatus.h Reason.
* If a value is added here, it MUST be added there with the same value.
*/
typedef enum {
TS_HOST_STATUS_ACTIVE = 0x1,
TS_HOST_STATUS_LOCAL = 0x2,
TS_HOST_STATUS_MANUAL = 0x4,
TS_HOST_STATUS_SELF_DETECT = 0x8,
TS_HOST_STATUS_ALL = 0xf,
} TSHostStatusReason;

/* --------------------------------------------------------------------------
ParentResult API types */

// used in ParentSelection to to set the number of ATSConsistentHashIter's
// used in NextHopSelectionStrategy to limit the host group
// size as well, group size is one to one with the number of rings
#define TS_MAX_GROUP_RINGS 5

typedef enum {
TS_PARENT_UNDEFINED,
TS_PARENT_DIRECT,
TS_PARENT_SPECIFIED,
TS_PARENT_AGENT,
TS_PARENT_FAIL,
} TSParentResultType;

/* --------------------------------------------------------------------------
Interface for the UUID APIs. https://www.ietf.org/rfc/rfc4122.txt. */
typedef enum {
Expand Down
33 changes: 33 additions & 0 deletions include/ts/ts.h
Original file line number Diff line number Diff line change
Expand Up @@ -2609,6 +2609,39 @@ tsapi TSReturnCode TSHttpTxnClientStreamIdGet(TSHttpTxn txnp, uint64_t *stream_i
*/
tsapi TSReturnCode TSHttpTxnClientStreamPriorityGet(TSHttpTxn txnp, TSHttpPriority *priority);

/*
* Returns TS_SUCCESS if hostname is this machine, as used for parent and remap self-detection.
* Returns TS_ERROR if hostname is not this machine.
*/
tsapi TSReturnCode TSHostnameIsSelf(const char *hostname);

/*
* Gets the status of hostname in the outparam status, and the status reason in the outparam reason.
* The reason is a logical-or combination of the reasons in TSHostStatusReason.
* If either outparam is null, it will not be set and no error will be returned.
* Returns TS_SUCCESS if the hostname was a parent and existed in the HostStatus, else TS_ERROR.
*/
tsapi TSReturnCode TSHostStatusGet(const char *hostname, const size_t hostname_len, TSHostStatus *status, unsigned int *reason);

/*
* Sets the status of hostname in status, down_time, and reason.
* The reason is a logical-or combination of the reasons in TSHostStatusReason.
*/
tsapi void TSHostStatusSet(const char *hostname, const size_t hostname_len, TSHostStatus status, const unsigned int down_time,
const unsigned int reason);

struct TSParentResult;

/*
* Gets the Transaction Parent Result pointer.
*/
tsapi void TSHttpTxnParentResultGet(TSHttpTxn txnp, struct TSParentResult *result);

/*
* Sets the Transaction Parent Result pointer.
*/
tsapi void TSHttpTxnParentResultSet(TSHttpTxn txnp, struct TSParentResult *result);

#ifdef __cplusplus
}
#endif /* __cplusplus */
24 changes: 12 additions & 12 deletions include/ts/nexthop.h → include/tscpp/api/nexthop.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@

#include <ts/apidefs.h>

// plugin callback commands.
enum NHCmd { NH_MARK_UP, NH_MARK_DOWN };

struct NHHealthStatus {
virtual bool isNextHopAvailable(TSHttpTxn txn, const char *hostname, const int port, void *ih = nullptr) = 0;
virtual void markNextHop(TSHttpTxn txn, const char *hostname, const int port, const NHCmd status, void *ih = nullptr,
const time_t now = 0) = 0;
virtual ~NHHealthStatus() {}
};
class TSNextHopSelectionStrategy
{
public:
TSNextHopSelectionStrategy(){};
virtual ~TSNextHopSelectionStrategy(){};

struct NHPluginStrategy {
virtual void findNextHop(TSHttpTxn txnp, void *ih = nullptr) = 0;
virtual bool nextHopExists(TSHttpTxn txnp, void *ih = nullptr) = 0;
virtual ~NHPluginStrategy() {}
virtual void findNextHop(TSHttpTxn txnp, time_t now = 0) = 0;
virtual void markNextHop(TSHttpTxn txnp, const char *hostname, const int port, const NHCmd status, const time_t now = 0) = 0;
virtual bool nextHopExists(TSHttpTxn txnp) = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really useful? Why not have findNextHop return bool?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findNextHop modifies the state to be the next parent; nextHopExists returns without modifying state.
I'd be a big +1 on making findNextHop return and be a pure function. But that'd require refactoring how Strategies work and are called in core. Which I'm guessing itself is a reflection of how ParentSelection always did it.

virtual bool responseIsRetryable(unsigned int current_retry_attempts, TSHttpStatus response_code) = 0;
virtual bool onFailureMarkParentDown(TSHttpStatus response_code) = 0;

NHHealthStatus *healthStatus;
virtual bool goDirect() = 0;
virtual bool parentIsProxy() = 0;
};
45 changes: 45 additions & 0 deletions include/tscpp/api/parentresult.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/** @file

@section license License

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#pragma once

#include "ts/apidefs.h"
#include "tscore/ConsistentHash.h"
#include <netinet/in.h>

extern const char *ParentResultStr[];

struct TSParentResult {
const char *hostname;
in_port_t port;
bool retry;
TSParentResultType result;
bool chash_init[TS_MAX_GROUP_RINGS] = {false};
TSHostStatus first_choice_status = TSHostStatus::TS_HOST_STATUS_INIT;
int line_number;
uint32_t last_parent;
uint32_t start_parent;
uint32_t last_group;
bool wrap_around;
bool mapWrapped[2];
int last_lookup;
ATSConsistentHashIter chashIter[TS_MAX_GROUP_RINGS];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the hash values and iterators needed in this result structure? Is this intended as a state object and not just a result?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's a state object. Used by both ParentSelection and Strategies in core (or rather, copied to an identical structure in core).

I.e.
https://github.com/apache/trafficserver/blob/786463/proxy/ParentConsistentHash.cc#L110
https://github.com/apache/trafficserver/blob/786463/proxy/http/remap/NextHopConsistentHash.cc#L335

};
2 changes: 1 addition & 1 deletion iocore/cache/test/stub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ ts::svtoi(TextView src, TextView *out, int base)
}

void
HostStatus::setHostStatus(const char *name, HostStatus_t status, const unsigned int down_time, const unsigned int reason)
HostStatus::setHostStatus(const char *name, TSHostStatus status, const unsigned int down_time, const unsigned int reason)
{
}

Expand Down
10 changes: 5 additions & 5 deletions iocore/net/Socks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ SocksEntry::findServer()

#ifdef SOCKS_WITH_TS
if (nattempts == 1) {
ink_assert(server_result.result == PARENT_UNDEFINED);
ink_assert(server_result.result == TS_PARENT_UNDEFINED);
server_params->findParent(&req_data, &server_result, fail_threshold, retry_time);
} else {
socks_conf_struct *conf = netProcessor.socks_conf_stuff;
Expand All @@ -101,14 +101,14 @@ SocksEntry::findServer()
server_params->markParentDown(&server_result, fail_threshold, retry_time);

if (nattempts > conf->connection_attempts) {
server_result.result = PARENT_FAIL;
server_result.result = TS_PARENT_FAIL;
} else {
server_params->nextParent(&req_data, &server_result, fail_threshold, retry_time);
}
}

switch (server_result.result) {
case PARENT_SPECIFIED:
case TS_PARENT_SPECIFIED:
// Original was inet_addr, but should hostnames work?
// ats_ip_pton only supports numeric (because other clients
// explicitly want to avoid hostname lookups).
Expand All @@ -122,8 +122,8 @@ SocksEntry::findServer()
default:
ink_assert(!"Unexpected event");
// fallthrough
case PARENT_DIRECT:
case PARENT_FAIL:
case TS_PARENT_DIRECT:
case TS_PARENT_FAIL:
memset(&server_addr, 0, sizeof(server_addr));
}
#else
Expand Down
1 change: 1 addition & 0 deletions plugins/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ include experimental/cert_reporting_tool/Makefile.inc
include experimental/collapsed_forwarding/Makefile.inc
include experimental/cookie_remap/Makefile.inc
include experimental/custom_redirect/Makefile.inc
include experimental/nexthop_strategy_consistenthash/Makefile.inc
include experimental/fq_pacing/Makefile.inc
include experimental/geoip_acl/Makefile.inc
include experimental/header_freq/Makefile.inc
Expand Down
29 changes: 29 additions & 0 deletions plugins/experimental/nexthop_strategy_consistenthash/Makefile.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

pkglib_LTLIBRARIES += experimental/nexthop_strategy_consistenthash/nexthop_strategy_consistenthash.la

experimental_nexthop_strategy_consistenthash_nexthop_strategy_consistenthash_la_SOURCES = \
experimental/nexthop_strategy_consistenthash/strategy.cc \
experimental/nexthop_strategy_consistenthash/healthstatus.cc \
experimental/nexthop_strategy_consistenthash/consistenthash.cc \
experimental/nexthop_strategy_consistenthash/consistenthash_config.cc \
experimental/nexthop_strategy_consistenthash/plugin_consistenthash.cc

experimental_nexthop_strategy_consistenthash_nexthop_strategy_consistenthash_la_LDFLAGS = \
$(AM_LDFLAGS)

AM_CPPFLAGS += @YAMLCPP_INCLUDES@ $(TS_INCLUDES)
Loading