Looking for IP packet 5-tuple flow hashing function/algorithm

I am looking for a ECMP Load Balancing hashing algorithm/function.
The typical use case is routing packets or connections or flows through multiple next-hops or servers. I am not sure how the hashing and the distribution should work at all.
I tried to look in the Linux kernel sources for the L3 and L4 hashing code but I lost the trace in code… too much code.
I have also tried to look it up in Ha-proxy source code which has couple nice Load Balancing algorithms but got lost in the code.

I don’t know what I am even looking for… so I eventually found the next thread:

but I do not understand what is implemented there and how to implement the same code in GoLang.
The basic struct for a flow tuple would be:

type IPFlowTuple struct {
SrcIP net.IP
DstIP net.IP
SrcPort uint16
DstPort uint16
Proto uint8

It would only work for TCP/UDP/SCTP since only these have source and destination ports.
I have read couple articles but since my math skills are not equal to these of some articles publishers I didn’t managed to grasp the math which they described.
Any help and example on implementing the above and other examples in GoLang would help me.

OK So I tired to learn and understand couple things and managed to implement the function mentioned in the stackoverflow post at:

Now I only left with the actual link/routes balancing function.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.