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

[TP]: Rewrite to aid maintainability and possiblity to expand with other features #344

Closed
wants to merge 1 commit into from

Conversation

GwnDaan
Copy link
Member

@GwnDaan GwnDaan commented Nov 9, 2023

This is basically a proof of concept that works as far as the unit tests go. Now I seek some feedback if we actually want these changes or not.

What changes:

  • added abstract transport data interface
  • reworked the session storage to hold the objects themselves
  • a lot of refactorizarion such that a session could in theory be initialized and completed for any ECU on the bus

@GwnDaan GwnDaan requested a review from ad3154 November 9, 2023 00:22
@GwnDaan
Copy link
Member Author

GwnDaan commented Nov 9, 2023

Part of me is wondering if we might want to make even a different class from TransportProtocolManager, that somewhat duplicates the functionality but could be optionally linked in to add a "transport protocol listener"

Yeah I see what you mean, when implementing I tried to keep in mind a third "SessionDirection" which would be something like "ListenOnly" but thats not yet in there. But an approach like yours might work as good as well, though it introduces some dupplication when maintaining the stack. Something we already experience quite a bit with the current 3 transport protocols being very similar in some places.

@ad3154
Copy link
Member

ad3154 commented Nov 9, 2023

though it introduces some duplication when maintaining the stack

It would of course, and each protocol is juuuust different enough to make sharing code between them troublesome. The good thing is, the transport layer is quite stable from an ISO/J1939 requirements perspective, and probably won't need to be messed with too often once a listener is working (especially if we can ever hit it with the AEF conformance test tool to get it 100% compliant).

Going back to your (paraphrased) goal with this:

I basically [wanted] to try to make the TP class better suited for sniffing TP sessions between other ecu's on the bus.

This strikes me as a, lets say, abnormal thing to want in a "normal" ISOBUS application but something many people will want regardless of course, so, one thing I really like about a separate object is that it makes it clear when you use it that you are doing things outside the "core" functionality of the stack - something extra with a clearly defined but separate data path. Like, you really have to opt-in. Plus, then the fairly substantial extra storage associated with it becomes more optional, especially if we control linking it with CMake, because sniffing could result in us storing (253 + (253 * 252)) = 63756 sessions!!!! (or, 253+(253!)/(2!*(253-2)!)*2 if you want to be pedantic about your equations).

@ad3154
Copy link
Member

ad3154 commented Nov 9, 2023

I'm sure we can control the memory cost without making it optionally linkable of course, it's just something to think over and consider. No matter what path we go, we may want to not sniff anything unless specifically configured to do so one way or another.

@GwnDaan GwnDaan added the iso: data link Related to the ISO-11783:3 standard label Nov 11, 2023
@GwnDaan GwnDaan force-pushed the daan/cleanup-transport-protocol branch 2 times, most recently from 4de4a21 to 05014db Compare November 25, 2023 22:51
@GwnDaan GwnDaan changed the base branch from main to daan/expanded-message-sending November 25, 2023 22:51
@GwnDaan GwnDaan self-assigned this Nov 25, 2023
@GwnDaan GwnDaan force-pushed the daan/cleanup-transport-protocol branch 4 times, most recently from b8b8926 to 19d2bb3 Compare November 25, 2023 23:17
@GwnDaan GwnDaan marked this pull request as ready for review November 25, 2023 23:19
@GwnDaan
Copy link
Member Author

GwnDaan commented Nov 25, 2023

@ad3154, I still think this is a great addition. I changed a lot and in my opinion it is now more modular and future proof. I can easily implement a message 'sniffer' based on this format that doesn't hurt our performance/memory usage, and is opt-in without too much extra codebase. Though you might still think otherwise, and hence I'm curious for your thoughts on this :)

edit: it most-likely still has some bugs in it that need to be catched

isobus/src/can_message.cpp Outdated Show resolved Hide resolved
@ad3154
Copy link
Member

ad3154 commented Nov 26, 2023

@ad3154, I still think this is a great addition. I changed a lot and in my opinion it is now more modular and future proof. I can easily implement a message 'sniffer' based on this format that doesn't hurt our performance/memory usage, and is opt-in without too much extra codebase. Though you might still think otherwise, and hence I'm curious for your thoughts on this :)

edit: it most-likely still has some bugs in it that need to be catched

Ah, ok, I can take another look and let you know my thoughts 🙂

Copy link
Member

@ad3154 ad3154 left a comment

Choose a reason for hiding this comment

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

I do think there's valuable stuff in here, especially in the TP file and it does make some steps towards multiple goals we wanted.

I would like to do some load testing with it just to make sure it still all works OK with multiple sessions going at once, and of both types of sessions to see if we can provoke any bugs.

My main mental sticking point is still that I don't enjoy too many levels of abstract data types on top of abstract data types. I'm still not sure I grasp the benefit of having things like CANMessageDataVector which inherits from CANMessageData which inherits from a vector, when the data, really, is just a vector. Or CANMessageDataView which inherits from CANMessageData which inherits from CANDataSpan which is really just a templated version of DataSpan, which is just an array of bytes and a size. (I know I'm being a little over-simplify-y here, appologies)

Was your thinking mainly to consolidate CANMessageDataCallback? It just feels like a lot of misdirection which at least kinda feels more confusing to me than just interacting with the native/standard types.

I dunno... I could be convinced I think, maybe I am just not grasping your whole picture here, or maybe you need this to better enable sniffing? I might just need more explaining

isobus/src/can_message.cpp Outdated Show resolved Hide resolved
isobus/include/isobus/isobus/can_transport_protocol.hpp Outdated Show resolved Hide resolved
isobus/src/can_transport_protocol.cpp Outdated Show resolved Hide resolved
isobus/src/can_transport_protocol.cpp Outdated Show resolved Hide resolved
isobus/src/can_transport_protocol.cpp Outdated Show resolved Hide resolved
isobus/src/can_transport_protocol.cpp Outdated Show resolved Hide resolved
isobus/src/can_transport_protocol.cpp Outdated Show resolved Hide resolved
isobus/src/can_transport_protocol.cpp Outdated Show resolved Hide resolved
@GwnDaan
Copy link
Member Author

GwnDaan commented Dec 1, 2023

Was your thinking mainly to consolidate CANMessageDataCallback? It just feels like a lot of misdirection which at least kinda feels more confusing to me than just interacting with the native/standard types.

Yeah that's basically one of the two main reasons I think:

  • It provides one common interface to get the data from. This can be the same interface throughout all protocols. When one needs to get some data, there is no need to do a cumbersome check to know where to get the data from. The data is just there, only one function away.
  • By passing/moving around an instance of a class, you can't accidentally modify the data it holds. That is because you explicitly can't, unlike raw pointers. Ofcourse proper code reviews shouldn't let that happen in the first place, but we're still human after all and mistakes will happen haha.

I feel like it will reduce the chance of failures in the future, at least from inside the stack. Not that, that was a problem in the first place, but a little more robust structure should not harm.

My main mental sticking point is still that I don't enjoy too many levels of abstract data types on top of abstract data types. I'm still not sure I grasp the benefit of having things like CANMessageDataVector which inherits from CANMessageData which inherits from a vector, when the data, really, is just a vector. Or CANMessageDataView which inherits from CANMessageData which inherits from CANDataSpan which is really just a templated version of DataSpan, which is just an array of bytes and a size. (I know I'm being a little over-simplify-y here, appologies)

Yeah definitely, though I think it's better to think of it as a simple 'interface'. No need to worry about the levels of abstraction beneath it. How I like to think about it:

  • CANMessageData: hey, a interface class that has a few functions to access some data (idc where it's from)
  • CANMessageDataView: oh cool, a class implementing the CANMessageData interface that allows us to 'look' at data stored somewhere in memory.
  • CANMessageDataVector: ahh, another class implementing the CANMessageData interface, but now instead of 'looking' at the data, we actually 'own' it. Allows us to unrestrictively modify the data.
  • CANMessageDataCallback: another class implementing the CANMessageData interface, but instead of representing data in memory, we can just request chunks of data from somewhere.

So no need to worry about all the ADT's behind it, I know we still are low level developers by heart, but let's appreciate a bit of abstraction here hahah.

@GwnDaan GwnDaan changed the title Refactor transport protocol [TP]: Rewrite to aid maintainability and possiblity to expand with other features Dec 2, 2023
@GwnDaan GwnDaan force-pushed the daan/cleanup-transport-protocol branch from 0e674bb to a3f7248 Compare December 2, 2023 13:28
@ad3154
Copy link
Member

ad3154 commented Dec 7, 2023

I appreciate your explanations, they do help me see what you mean, and I do feel a bit better about it now...

Like I mentioned I'd like to run some tests just because I am paranoid about changing TP, but then I think I'm OK with it and will give it one last look over.

Sorry I'm stalling, haha

@GwnDaan
Copy link
Member Author

GwnDaan commented Dec 7, 2023

Yeah no worries, I was planning on trying to cover it with unit tests first as well. But I'm not sure where to start to be completely honest. Since the TP probably won't change in the mean time, i'm fine with leaving it open a little longer to be sure there are no issues.

@GwnDaan GwnDaan force-pushed the daan/cleanup-transport-protocol branch 2 times, most recently from 94f8c7b to b0301bd Compare December 9, 2023 11:48
@GwnDaan
Copy link
Member Author

GwnDaan commented Dec 9, 2023

In b0301bd I removed the CANNetworkManager dependency, this should make it a lot easier to unit-test the implementation.

There's still a list I want to do before thinking about merging this into main:

  • rewrite ExtendedTransportProtocol to match the new style
  • rewrite FastPacketProtocol to match the new style
  • unit-test all implementations

@GwnDaan GwnDaan force-pushed the daan/cleanup-transport-protocol branch from f97bb58 to 7f22945 Compare December 12, 2023 14:05
@GwnDaan GwnDaan changed the base branch from daan/expanded-message-sending to daan/cleanup-unit-tests-1 December 13, 2023 22:00
@GwnDaan GwnDaan force-pushed the daan/cleanup-transport-protocol branch from b7ebe5a to 07bb2d7 Compare December 13, 2023 22:06
@GwnDaan GwnDaan force-pushed the daan/cleanup-transport-protocol branch 7 times, most recently from 07dc021 to 92f4717 Compare December 13, 2023 23:21
@GwnDaan GwnDaan closed this Dec 13, 2023
@GwnDaan GwnDaan force-pushed the daan/cleanup-transport-protocol branch from 92f4717 to 4e47e6e Compare December 13, 2023 23:22
@GwnDaan GwnDaan reopened this Dec 13, 2023
Base automatically changed from daan/cleanup-unit-tests-1 to main December 16, 2023 08:38
@GwnDaan GwnDaan force-pushed the daan/cleanup-transport-protocol branch 2 times, most recently from 9b7cfdf to f294c79 Compare December 16, 2023 10:39
@GwnDaan GwnDaan force-pushed the daan/cleanup-transport-protocol branch from b804c00 to 721f36c Compare December 16, 2023 10:57
Copy link

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

23 New issues
0 Security Hotspots
74.8% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

@GwnDaan
Copy link
Member Author

GwnDaan commented Jan 6, 2024

Replaced by #391

@GwnDaan GwnDaan closed this Jan 6, 2024
@GwnDaan GwnDaan deleted the daan/cleanup-transport-protocol branch January 30, 2024 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iso: data link Related to the ISO-11783:3 standard
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants