1 /** @file 2 3 Implementation of nexthop consistent hash selections strategies. 4 5 @section license License 6 7 Licensed to the Apache Software Foundation (ASF) under one 8 or more contributor license agreements. See the NOTICE file 9 distributed with this work for additional information 10 regarding copyright ownership. The ASF licenses this file 11 to you under the Apache License, Version 2.0 (the 12 "License"); you may not use this file except in compliance 13 with the License. You may obtain a copy of the License at 14 15 http://www.apache.org/licenses/LICENSE-2.0 16 17 Unless required by applicable law or agreed to in writing, software 18 distributed under the License is distributed on an "AS IS" BASIS, 19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 See the License for the specific language governing permissions and 21 limitations under the License. 22 */ 23 24 #pragma once 25 26 #include <map> 27 #include <vector> 28 #include "NextHopSelectionStrategy.h" 29 30 enum NHHashKeyType { 31 NH_URL_HASH_KEY = 0, 32 NH_HOSTNAME_HASH_KEY, 33 NH_PATH_HASH_KEY, // default, consistent hash uses the request url path 34 NH_PATH_QUERY_HASH_KEY, 35 NH_PATH_FRAGMENT_HASH_KEY, 36 NH_CACHE_HASH_KEY 37 }; 38 39 class NextHopConsistentHash : public NextHopSelectionStrategy 40 { 41 std::vector<std::shared_ptr<ATSConsistentHash>> rings; 42 43 uint64_t getHashKey(uint64_t sm_id, HttpRequestData *hrdata, ATSHash64 *h); 44 45 public: 46 NHHashKeyType hash_key = NH_PATH_HASH_KEY; 47 48 NextHopConsistentHash() = delete; NextHopConsistentHash(const std::string_view name,const NHPolicyType & policy)49 NextHopConsistentHash(const std::string_view name, const NHPolicyType &policy) : NextHopSelectionStrategy(name, policy) {} 50 ~NextHopConsistentHash(); 51 bool Init(const YAML::Node &n); 52 void findNextHop(TSHttpTxn txnp, void *ih = nullptr, time_t now = 0) override; 53 }; 54