Skip to content
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

Truncate and sample #898

Merged
merged 3 commits into from
Jun 9, 2016
Merged

Conversation

petebristow
Copy link
Contributor

2 very basic apps useful for monitoring rather than forwarding traffic.

@eugeneia eugeneia self-assigned this May 2, 2016
function Truncate:push()
for _ = 1, link.nreadable(self.input.input) do
local p = receive(self.input.input)
ffi.fill(p.data, math.min(0, self.n - p.length))
Copy link
Member

Choose a reason for hiding this comment

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

Please don't use the packet fields directly and use the public functions packet.data and packet.length instead. It's a bit more verbose, but as of now the fields are not really part of the public API.

Copy link
Contributor

@wingo wingo May 2, 2016

Choose a reason for hiding this comment

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

Can you point to documentation for this @eugeneia? To me it is useful to know that a packet is just a data and a length, and part of the core Snabb value proposition. I haven't seen a PR that goes by that changes this, though I could have missed something :)

Copy link
Member

Choose a reason for hiding this comment

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

http://snabbco.github.io/#packet-core.packet describes the core.packet API. It doesn't mention the actual packet structure which is why I am uneasy about using the fields directly instead of going through the API functions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I know what you mean. Still, Luke has given several presentations with a lovely slide that's just

// The maximum amount of payload in any given packet.
enum { PACKET_PAYLOAD_SIZE = 10*1024 };

// Packet of network data, with associated metadata.
struct packet {
    unsigned char data[PACKET_PAYLOAD_SIZE];
    uint16_t length;           // data payload length
};

and so I dunno, it's part of the public messaging. There are quite a lot of uses out there already fwiw, and many of them introduced since you made the data/length functions in January last year.

Copy link
Member

Choose a reason for hiding this comment

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

I am in favor of documenting our ABI i.e. the memory layout of these structures.

These basic data structures like packet and link need to be usable by e.g. assembler code and this does not seem compatible with defining them via an abstract Lua API.

Copy link
Member

Choose a reason for hiding this comment

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

I think documenting the ABI is a separate issue, since that would not define the FFI field names (data/length) if I understand correctly(?).

One advantage (imho) of the API functions is that they are read-only. I am fine with documenting the field names as well and encouraging their use, or even getting rid of the API functions. Either way, I would like that API to be defined before I recommend its use.

I have encountered direct uses of the fields before as well, but considered them as semi-bugs until now.

@petebristow
Copy link
Contributor Author

A quick and dirty (so take with a pinch of salt) grep of the source code shows ~10 uses of packet.data() and ~250 uses of p.data. The methods haven't had much impact.
I'm also in favor of documenting the structure, is there consensus enough to put through a PR to update the readme?
Should the API functions remain? They seem slightly redundant if the structure is documented.

@eugeneia
Copy link
Member

eugeneia commented May 4, 2016

I think the best way to find out is to create that PR. I suspect that the PR would be quite involved though as it opens up a can of safety considerations. I also see overlap with: #774 #740 #734 #789

@wingo
Copy link
Contributor

wingo commented May 4, 2016

I don't see any significant safety consideration, for what it's worth, by using well-known names for fields of a struct with a stable, documented ABI, especially considering that we need to access the packet data directly without any out-of-bounds-checking machinery. YMMV of course :)

@eugeneia
Copy link
Member

eugeneia commented May 5, 2016

To avoid stalling this PR I will merge it as is and open a separate PR to discuss the issue at hand.

@eugeneia eugeneia added the merged label May 5, 2016
eugeneia added a commit that referenced this pull request May 5, 2016
@eugeneia eugeneia merged commit 5044726 into snabbco:master Jun 9, 2016
dpino added a commit to dpino/snabb that referenced this pull request Aug 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants