Skip to content

Commit

Permalink
Fix address comparison for older versions of Python3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
jadinm committed Aug 7, 2019
1 parent 50bd367 commit d735a6b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 11 additions & 3 deletions ipmininet/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,18 @@ def address_comparator(a, b):
return 1
if b.network.is_global and not a.network.is_global:
return -1
# Otherwise simply rank the IP values
if a > b:
# Compare networks
if b.network.is_global and not a.network.is_global:
return -1
# Compare network values
if a.network < b.network:
return -1
if a.network > b.network:
return 1
return -1 if b > a else 0
# Otherwise simply rank the IP values
if a.ip < b.ip:
return -1
return 1 if a.ip > b.ip else 0


class PhysicalInterface(IPIntf):
Expand Down
4 changes: 4 additions & 0 deletions ipmininet/tests/test_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
[u"100.64.0.1/32", u"10.0.0.1/8"]), # Public before private
([u"100.64.0.1/32", u"10.0.0.1/8"],
[u"100.64.0.1/32", u"10.0.0.1/8"]), # Public before private
([u"2001::1/16", u"2002::1/16"],
[u"2002::1/16", u"2001::1/16"]), # Bigger network value first
([u"2002::1/16", u"2001::1/16"],
[u"2002::1/16", u"2001::1/16"]), # Bigger network value first
([u"2001::1/16", u"2001::2/16"],
[u"2001::2/16", u"2001::1/16"]), # Bigger IP value first
([u"2001::2/16", u"2001::1/16"],
Expand Down

0 comments on commit d735a6b

Please sign in to comment.