-
Notifications
You must be signed in to change notification settings - Fork 27
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
Issue #368: Bad packet size handling in built-in server handlers #456
base: master
Are you sure you want to change the base?
Changes from 2 commits
180aa55
cedc7cb
ec2ebab
921b1ad
4e12180
e58e893
613da40
4aca498
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,27 +19,48 @@ def __init__(self, input_type=None, output_type=None, **kwargs): | |
If packet is specified but not present in default tlm dict. | ||
""" | ||
super(PacketHandler, self).__init__(input_type, output_type) | ||
self.packet = kwargs.get("packet", None) | ||
self.packet_type = kwargs.get("packet", None) | ||
self.tlm_dict = tlm.getDefaultDict() | ||
|
||
if not self.packet: | ||
msg = 'PacketHandler: No packet name provided in handler config as key "packet"' | ||
if not self.packet_type: | ||
msg = f'PacketHandler: No packet type provided in handler config as key "packet"' | ||
raise ValueError(msg) | ||
|
||
tlm_dict = tlm.getDefaultDict() | ||
if self.packet not in tlm_dict: | ||
msg = "PacketHandler: Packet name {} not present in telemetry dictionary".format( | ||
self.packet | ||
) | ||
msg += " Available packet types are {}".format(tlm_dict.keys()) | ||
if self.packet_type not in self.tlm_dict: | ||
msg = f"PacketHandler: Packet name '{self.packet_type}' not present in telemetry dictionary." | ||
msg += f" Available packet types are {self.tlm_dict.keys()}" | ||
raise ValueError(msg) | ||
|
||
self._pkt_defn = tlm_dict[self.packet] | ||
self._pkt_defn = self.tlm_dict[self.packet_type] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JHofman728 Since you are already grabbing the packet definition here, there really should be no need for the new |
||
|
||
def handle(self, input_data): | ||
def get_packet_lengths(self): | ||
""" | ||
Makes a dictionary of packet.name : number of bytes in the packet | ||
e.g. 'Ethernet_HS_Packet': 37 | ||
|
||
Return: dictionary | ||
|
||
""" | ||
pkt_len_dict = {} | ||
for i in self.tlm_dict.keys(): | ||
pkt_len_dict[i] = self.tlm_dict[i].nbytes | ||
|
||
return pkt_len_dict | ||
|
||
def handle(self, packet): | ||
""" | ||
Params: | ||
input_data: message received by stream | ||
packet: message received by stream (packet) | ||
Returns: | ||
tuple of packet UID and message received by stream | ||
""" | ||
return pickle.dumps((self._pkt_defn.uid, input_data), 2) | ||
|
||
# TODO validate the packet (if this is the place to do the validation) | ||
|
||
defined_packet_lengths = self.get_packet_lengths() | ||
|
||
if defined_packet_lengths[self.packet_type] != packet.nbytes: | ||
nttoole marked this conversation as resolved.
Show resolved
Hide resolved
|
||
msg = f"PacketHandler: Packet length of packet does not match packet definition." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please rephrase to: "PacketHandler: Packet data length does not match packet definition" |
||
raise ValueError(msg) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JimHofman Could this be an error log message instead of thrown error (same as CCSDS handler) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, will work on pickle error before pushing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like the pickle error is coming from the unit tests that test bad packet length. It's is set up by passing a 1552 packet to an Ethernet handler, so it makes sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check doesn't even look valid? You should be checking the length of the received input data not the number of bytes in a packet definition. |
||
|
||
return pickle.dumps((self._pkt_defn.uid, packet), 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please update this field to be
packet_name
?