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

Cannot get AVP data in native type #1

Open
ofraiwan opened this issue Jan 23, 2022 · 4 comments
Open

Cannot get AVP data in native type #1

ofraiwan opened this issue Jan 23, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@ofraiwan
Copy link

For example, I have an answer object of type CreditControlAnswer, which has an AVP of type ResultCodeAVP.

I need to check what is the value of that AVP. The data attribute of the ResultCodeAVP returns only the serialized (encoded) data, and there are no methods available to deserialize (decode) that data.

The same applies to all AVP classes of all types.

@heimiricmr
Copy link
Owner

Hi @ofraiwan,

Thanks for your feedback.

Bromélia was designed to store serialized data into instance attributes for all DiameterAVP subclasses. It means all DiameterAVP subclasses will have a data attribute with the encoded AVP data (i.e. in byte stream). It applies to code, flags, length, vendor_id & padding attributes as well.

There are available methods to get DiameterAVP attributes in integer format, except the data one. However, in order to check the value of a given DiameterAVP (data attribute) you may use the defined constants in constants.py module.

For example:

>>> from bromelia.lib.etsi_3gpp_gx import *
>>> cca = CCA()
>>> cca
<Diameter Message: 272 [CCA] PXY, 16777238 [3GPP Gx], 7 AVP(s)>
>>> cca.result_code_avp
<Diameter AVP: 268 [Result-Code] MANDATORY>
>>> cca.result_code_avp.data
b'\x00\x00\x07\xd1'
>>> from bromelia.constants import *
>>> DIAMETER_SUCCESS
b'\x00\x00\x07\xd1'
>>> cca.result_code_avp.data == DIAMETER_SUCCESS
True

Let me know if it works as per you purpose. Otherwise, feel free to give more details on how it would work and why my explanation does not help to do so.

Btw, did you refer to have something like as follows?

>>> cca.result_code_avp.get_data()
'DIAMETER_SUCCESS'

Or

>>> cca.result_code_avp.get_data()
2001

Cheers!

@ofraiwan
Copy link
Author

Hi @heimiricmr
Thank you for the fast reply.

The comparison method mentioned in cca.result_code_avp.data == DIAMETER_SUCCESS does work.

But having something like the suggestion in cca.result_code_avp.get_data() will be helpful to get the result value for purposes like logging, saving in a database, etc.

The same applies to all methods, like get_flags, get_vendor_id, etc.

@heimiricmr
Copy link
Owner

Hi @ofraiwan,

I got your point. It seems to me we may label it as an enhancement, right?

On one hand, I think the __repr__() method already fulfill this requirement for flags and vendor_id attributes. You just need to pass the DiameterAVP object to logging message.

>>> from bromelia.base import DiameterAVP
>>> avp = DiameterAVP()
>>> avp
<Diameter AVP: 0 [Unknown]>
>>> avp.set_mandatory_bit(True)
>>> avp
<Diameter AVP: 0 [Unknown] MANDATORY>
>>> avp.set_vendor_id_bit(True)
>>> avp
<Diameter AVP: 0 [Unknown] VENDOR, MANDATORY>
>>> avp.set_protected_bit(True)
>>> avp
<Diameter AVP: 0 [Unknown] VENDOR, MANDATORY, PROTECTED>

On the other hand, I agree with you a .get_data() could be helpful for logging and saving in database purposes, specially in EnumeratedType based objects.

>>> from bromelia.avps import *
>>> avp = RatTypeAVP(RAT_TYPE_EUTRAN)
>>> avp.data
b'\x00\x00\x03\xec'
>>> avp.get_data()
`EUTRAN`

However, what about other BaseType based objects such as Unsigned32Type, Integer32Type and Unsigned64Type? Should it return its integer value? What about GroupedType based objects? They already provide a way to access its AVPs by attributes and the .avps attribute itself.

I would like your support in order to define how it should work. So we may fine tune the expected requirements.

Let me know your thoughts on each subject.

Cheers!

@ofraiwan
Copy link
Author

ofraiwan commented Jan 24, 2022

Hi @heimiricmr

For the first question, yes, it might be labeled as an enhancement.

Second, the get_data method should do the inverse function of the serializing function. You have two cases:

  1. An AVP that is created directly using the class DiameterAVP. In this case, the get_data method should invert the work done by the setter method of the data attribute
  2. An AVP that is constructed using the inheritance from both: DiameterAVP and a given data type class (Integer32Type). Here the inverting function should be implemented for each data type class

For the GroupedType, you are already using a composite design pattern, so it is up to you how to implement the inverse function and represent the returned data.

@heimiricmr heimiricmr added the enhancement New feature or request label Jan 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants