On Thu, Jun 20, 2013 at 07:07:25AM +0900, FUJITA Tomonori wrote:
> On Wed, 12 Jun 2013 12:28:33 +0900
> Isaku Yamahata <[email protected]> wrote:
> 
> > On 32bit environment integer representation of ipv4 address can be
> > python int or long. Some unit tests failed.
> > On the other hand 64 bit environment it is int.
> > And some clean up.
> > 
> > FAIL: Failure: AssertionError ()
> > 
> > Traceback (most recent call last):
> >   File "/usr/local/lib/python2.7/dist-packages/nose/loader.py", line 413, in
> > loadTestsFromName
> >     addr.filename, addr.module)
> >   File "/usr/local/lib/python2.7/dist-packages/nose/importer.py", line 47, 
> > in
> > importFromPath
> >     return self.importFromDir(dir_path, fqname)
> >   File "/usr/local/lib/python2.7/dist-packages/nose/importer.py", line 94, 
> > in
> > importFromDir
> >     mod = load_module(part_fqname, fh, filename, desc)
> >   File "/home/oliver/tmp/ryu/ryu/tests/unit/packet/test_vrrp.py", line 38, 
> > in
> > <module>
> >     class Test_vrrpv2(unittest.TestCase):
> >   File "/home/oliver/tmp/ryu/ryu/tests/unit/packet/test_vrrp.py", line 52, 
> > in
> > Test_vrrpv2
> >     [ip_address])
> >   File "/home/oliver/tmp/ryu/ryu/lib/packet/vrrp.py", line 440, in create
> >     auth_data=VRRP_AUTH_DATA)
> >   File "/home/oliver/tmp/ryu/ryu/lib/packet/vrrp.py", line 308, in
> > create_version
> >     auth_type=auth_type, auth_data=auth_data)
> >   File "/home/oliver/tmp/ryu/ryu/lib/packet/vrrp.py", line 272, in __init__
> >     self._is_ipv6 = is_ipv6(self.ip_addresses[0])
> >   File "/home/oliver/tmp/ryu/ryu/lib/packet/vrrp.py", line 172, in is_ipv6
> >     assert type(ip_address) == str
> > AssertionError
> > 
> > Cc: Kei Ohmura <[email protected]>
> > Reported-by: Oren Spector <[email protected]>
> > Signed-off-by: Isaku Yamahata <[email protected]>
> > ---
> >  ryu/lib/packet/vrrp.py             |   31 +++++++++++++++++++++++--------
> >  ryu/tests/unit/packet/test_vrrp.py |    6 +++---
> >  2 files changed, 26 insertions(+), 11 deletions(-)
> > 
> > diff --git a/ryu/lib/packet/vrrp.py b/ryu/lib/packet/vrrp.py
> > index 8b6140a..a197629 100644
> > --- a/ryu/lib/packet/vrrp.py
> > +++ b/ryu/lib/packet/vrrp.py
> > @@ -165,12 +165,29 @@ VRRP_V2_MAX_ADVER_INT_MIN = 1           # don't allow > > 0
> >  VRRP_V2_MAX_ADVER_INT_MAX = 0xff
> >  
> >  
> > +# On 32bit environment, C-uint32_t can be python-long
> > +_IPV4_VALUE_TYPES = list(set((int, type(0xffffffff))))
> > +_IPV6_PACKED_TYPE = type(netaddr.IPAddress('::1').packed)       # = str
> > +_IPV6_PACKED_LEN = len(netaddr.IPAddress('::1').packed)         # = 16
> > +
> > +
> > +def _assert_ipv4_address(ipv4_address):
> > +    assert type(ipv4_address) in _IPV4_VALUE_TYPES
> > +    assert ipv4_address >= 0
> > +    assert ipv4_address <= 0xffffffff
> > +
> > +
> > +def _assert_ipv6_address(ipv6_address):
> > +    assert type(ipv6_address) == _IPV6_PACKED_TYPE
> > +    assert len(ipv6_address) == _IPV6_PACKED_LEN
> > +
> > +
> >  def is_ipv6(ip_address):
> > -    if type(ip_address) == int:
> > +    if type(ip_address) in _IPV4_VALUE_TYPES:
> > +        _assert_ipv4_address(ip_address)
> >          return False
> >  
> > -    assert type(ip_address) == str
> > -    assert len(ip_address) == 16
> > +    _assert_ipv6_address(ip_address)
> >      return True
> >  
> >  
> > @@ -206,8 +223,7 @@ class vrrp(packet_base.PacketBase):
> >      _IPV4_ADDRESS_PACK_STR_RAW = 'I'
> >      _IPV4_ADDRESS_PACK_STR = '!' + _IPV4_ADDRESS_PACK_STR_RAW
> >      _IPV4_ADDRESS_LEN = struct.calcsize(_IPV4_ADDRESS_PACK_STR)
> > -    _IPV6_ADDRESS_LEN = 16
> > -    _IPV6_ADDRESS_PACK_STR_RAW = '%ds' % _IPV6_ADDRESS_LEN
> > +    _IPV6_ADDRESS_PACK_STR_RAW = '%ds' % _IPV6_PACKED_LEN
> >      _IPV6_ADDRESS_PACK_STR = '!' + _IPV6_ADDRESS_PACK_STR_RAW
> >      _IPV6_ADDRESS_LEN = struct.calcsize(_IPV6_ADDRESS_PACK_STR)
> 
> Why this code needs to care about types for a value?

Because vrrp packets includes ipv4 or ipv6 addresses
and the encoding depends on its address type.
-- 
yamahata

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to