Skip to content

Conversation

@ronensc
Copy link
Contributor

@ronensc ronensc commented Jun 9, 2022

This PR changes the type under the hood of the hash from []byte to uint64.

uint64 simplifies the code since its easier to copy than []byte and can serve as a key in a map (in contrast to []byte)

This PR is a follow up on the 2nd point from this review: #220 (comment)

I also changed the hash to use 64 bits instead of 32 bits to reduce the chance of collisions (different connections with the same hash).
Assuming a perfect hash function with uniform distribution of the has values,
for 32 bits we need only 9,300 connections to have 1% chance for collision.
But, for 64 bits we need ~61,000,000 connections to have 1% chance for collision.
I based this on the table from Birthday attack. @kalman Am I correct with my analysis?

@codecov-commenter
Copy link

Codecov Report

Merging #228 (9dd7555) into main (debee4d) will decrease coverage by 0.10%.
The diff coverage is 84.84%.

@@            Coverage Diff             @@
##             main     #228      +/-   ##
==========================================
- Coverage   60.96%   60.86%   -0.11%     
==========================================
  Files          66       66              
  Lines        3784     3774      -10     
==========================================
- Hits         2307     2297      -10     
  Misses       1336     1336              
  Partials      141      141              
Flag Coverage Δ
unittests 60.86% <84.84%> (-0.11%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/pipeline/conntrack/aggregator.go 78.02% <0.00%> (ø)
pkg/pipeline/conntrack/hash.go 83.33% <88.88%> (-2.16%) ⬇️
pkg/pipeline/conntrack/conn.go 86.95% <100.00%> (ø)
pkg/pipeline/conntrack/conntrack.go 89.33% <100.00%> (-0.28%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update debee4d...9dd7555. Read the comment docs.

Copy link

@mariomac mariomac left a comment

Choose a reason for hiding this comment

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

LGTM. Just a minor comment.


func (c *connType) getHash() totalHashType {
return copyTotalHash(c.hash)
return c.hash

Choose a reason for hiding this comment

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

Since this is a private type and attribute, maybe the getHash() method is not needed anymore and you can invoke directly c.hash

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want the API of connection to have the property that once a connection object is created, its hash is read-only.
The other types that interact with connection (e.g. conntrackImpl and aggregators) are doing so using the connection interface rather than the connType struct. So in the current implementation I can't remove the method.


func uint64ToBytes(data uint64) []byte {
b := make([]byte, 8)
binary.BigEndian.PutUint64(b, data)

Choose a reason for hiding this comment

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

I guess the encoding order (little vs big endian) does not matter here, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right.

@ronensc ronensc force-pushed the conntrack-refactor-hashtype branch from 9dd7555 to cb092ec Compare June 15, 2022 11:10
@ronensc ronensc merged commit 217223d into netobserv:main Jun 15, 2022
@ronensc ronensc deleted the conntrack-refactor-hashtype branch June 15, 2022 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants