-
Notifications
You must be signed in to change notification settings - Fork 444
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
batch of changes related to bagpipe #251
Conversation
Could you please be explain to me why you are using repr and not of str in your own code ? |
|
1 similar comment
|
Hello @tmmorin - merged everything but the repr changes. I propose to change ExaBGP to:
What do you think ? Using str was a bad idea in the first place but it took ExaBGP to become a large(r) program for me to realise it. As I am working on 3.5, this is the ideal time for fix this issue. |
The third issue is in the new code |
When __repr__ is defined and __str__ is not, python will use __repr__ when __str__ is called. This patch modifies changes all __str__ definitions into __repr__ so that all objects have now both a proper implementation of both __repr__ and the __str__ behavior is unchanged.
Same as previous patch, but also uses repr(communitiy) for each community instead of str(community). This is for consistency and should not modify the behavior of current code given that only repr() is now defined for community classes.
- add VPNLabelledPrefix as subclass of MPLS - __init__ can set rd and labels, and unpack leverages this - register this class for the mpls_vpn SAFI - __cmp__ does a proper comparison ignoring the labels, as suitable for bagpipe - useful __repr__ for logging/debugging
Need for bagpipe, because we need Attributes.hash() to gives same values independently of the order of the stored (extended) communities.
* internal rd and mpls fields are RouteDistinguisher and Labels objects * more useful repr
Thanks for merging these pieces! There are two reasons why I ended up changing ExaBGP behavior wrt. repr and str:
The reason why I proposed to use repr instead of str is the following: str(iterable) calls repr on the internal objects, thus str(multivalue attribute) ends up calling repr on each attribute (e.g. for extended communities). By replacing all the I would still like Another thing is, if you drop str and repr, bagpipe would need that
|
|
Are you saying that repr should return a object which can be used by cmp ? I have a wish to undefine all str object and make the printing explicit. I believe using the built-in lead to some issue when it comes to provide backward compatibility as it can not be passed a version number ... Your opinion ? If I have to perform such intrusive change 3.5.0 - which is where we are - is going to be the right moment for it ! |
I am pretty sure I rely on eq to check if two routes are equals. I would need to dig the code. I have only define comparison when it was required - many object have them as I ported your code as it and did not want to remove it. |
No, my idea would be:
The last item I hope we can achieve, but we might fail if exabgp have different needs when comparing objects. The one typical case that I have in mind is the following: bagpipe stores nlris advertised by a peer in a set, a relies on set matching to identify that an already advertised route is withdrawn ; for this to work for MPLS labelled routes, eq and cmp have to ignore the label field. If this is fine for ExaBGP then we are all good, but if exabgp needs to have two MPLS NLRIs differing by their label to be inequal, then the solution will not be trivial.
I don't see such a need right now for bagpipe.
Attribute._eq only compare the attribute id, but does currently not look at the attribute value. |
Would this be acceptable ? For the comparison, I need to look at how your use case but I am sure we can find a way which works for both implementation. I do little comparison of objects and it to know if two attributes are the same or if a route need to be withdrawn/announced so our constraint must be similar. |
For str/repr and text(),yes, that looks good. And for the comparison, it's great if you are able to conclude that our needs are the same. I can push to you the changes I would have for eq/neq/cmp/hash and you will see if you think this will work well for ExaBGP. |
I am closing the pull request as nothing more can be pulled here. |
some changes are not required for ExaBGP but only for BaGPipe BGP
some changes are also required for ExaBGP to properly work (e.g. fixes in RTC class)
some others changes are cosmetic
(please tell me if you prefer multiple pull requests)