<s> from __future__ import print_function <EOL> import unittest <EOL> import logging <EOL> import six <EOL> import struct <EOL> import inspect <EOL> from nose . tools import eq_ , ok_ <EOL> from nose . tools import raises <EOL> from ryu . ofproto import inet <EOL> from ryu . lib . packet import ipv4 <EOL> from ryu . lib . packet import ipv6 <EOL> from ryu . lib . packet import packet <EOL> from ryu . lib . packet import packet_utils <EOL> from ryu . lib . packet import vrrp <EOL> from ryu . lib import addrconv <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class Test_vrrpv2 ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> version = vrrp . VRRP_VERSION_V2 <EOL> type_ = vrrp . VRRP_TYPE_ADVERTISEMENT <EOL> vrid = <NUM_LIT> <EOL> priority = <NUM_LIT:100> <EOL> count_ip = <NUM_LIT:1> <EOL> auth_type = vrrp . VRRP_AUTH_NO_AUTH <EOL> max_adver_int = <NUM_LIT:100> <EOL> checksum = <NUM_LIT:0> <EOL> ip_address = '<STR_LIT>' <EOL> auth_data = ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> vrrpv2 = vrrp . vrrpv2 . create ( type_ , vrid , priority , max_adver_int , <EOL> [ ip_address ] ) <EOL> buf = struct . pack ( vrrp . vrrpv2 . _PACK_STR + '<STR_LIT>' , <EOL> vrrp . vrrp_to_version_type ( vrrp . VRRP_VERSION_V2 , type_ ) , <EOL> vrid , priority , count_ip , <EOL> auth_type , max_adver_int , checksum , <EOL> addrconv . ipv4 . text_to_bin ( ip_address ) , <EOL> auth_data [ <NUM_LIT:0> ] , auth_data [ <NUM_LIT:1> ] ) <EOL> def setUp ( self ) : <EOL> pass <EOL> def tearDown ( self ) : <EOL> pass <EOL> def test_init ( self ) : <EOL> eq_ ( self . type_ , self . vrrpv2 . type ) <EOL> eq_ ( self . vrid , self . vrrpv2 . vrid ) <EOL> eq_ ( self . priority , self . vrrpv2 . priority ) <EOL> eq_ ( self . count_ip , self . vrrpv2 . count_ip ) <EOL> eq_ ( self . auth_type , self . vrrpv2 . auth_type ) <EOL> eq_ ( <NUM_LIT:1> , len ( self . vrrpv2 . ip_addresses ) ) <EOL> eq_ ( self . ip_address , self . vrrpv2 . ip_addresses [ <NUM_LIT:0> ] ) <EOL> eq_ ( self . auth_data , self . vrrpv2 . auth_data ) <EOL> def test_parser ( self ) : <EOL> vrrpv2 , _cls , _ = self . vrrpv2 . parser ( self . buf ) <EOL> eq_ ( self . version , vrrpv2 . version ) <EOL> eq_ ( self . type_ , vrrpv2 . type ) <EOL> eq_ ( self . vrid , vrrpv2 . vrid ) <EOL> eq_ ( self . priority , vrrpv2 . priority ) <EOL> eq_ ( self . count_ip , vrrpv2 . count_ip ) <EOL> eq_ ( self . auth_type , vrrpv2 . auth_type ) <EOL> eq_ ( self . max_adver_int , vrrpv2 . max_adver_int ) <EOL> eq_ ( self . checksum , vrrpv2 . checksum ) <EOL> eq_ ( <NUM_LIT:1> , len ( vrrpv2 . ip_addresses ) ) <EOL> eq_ ( str , type ( vrrpv2 . ip_addresses [ <NUM_LIT:0> ] ) ) <EOL> eq_ ( self . ip_address , vrrpv2 . ip_addresses [ <NUM_LIT:0> ] ) <EOL> eq_ ( self . auth_data , vrrpv2 . auth_data ) <EOL> def test_serialize ( self ) : <EOL> src_ip = '<STR_LIT>' <EOL> dst_ip = vrrp . VRRP_IPV4_DST_ADDRESS <EOL> prev = ipv4 . ipv4 ( <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , vrrp . VRRP_IPV4_TTL , <EOL> inet . IPPROTO_VRRP , <NUM_LIT:0> , src_ip , dst_ip ) <EOL> type_ = vrrp . VRRP_TYPE_ADVERTISEMENT <EOL> vrid = <NUM_LIT:5> <EOL> priority = <NUM_LIT:10> <EOL> max_adver_int = <NUM_LIT:30> <EOL> ip_address = '<STR_LIT>' <EOL> ip_addresses = [ ip_address ] <EOL> vrrp_ = vrrp . vrrpv2 . create ( <EOL> type_ , vrid , priority , max_adver_int , ip_addresses ) <EOL> buf = vrrp_ . serialize ( bytearray ( ) , prev ) <EOL> pack_str = vrrp . vrrpv2 . _PACK_STR + '<STR_LIT>' <EOL> pack_len = struct . calcsize ( pack_str ) <EOL> res = struct . unpack ( pack_str , six . binary_type ( buf ) ) <EOL> eq_ ( res [ <NUM_LIT:0> ] , vrrp . vrrp_to_version_type ( vrrp . VRRP_VERSION_V2 , type_ ) ) <EOL> eq_ ( res [ <NUM_LIT:1> ] , vrid ) <EOL> eq_ ( res [ <NUM_LIT:2> ] , priority ) <EOL> eq_ ( res [ <NUM_LIT:3> ] , len ( ip_addresses ) ) <EOL> eq_ ( res [ <NUM_LIT:4> ] , vrrp . VRRP_AUTH_NO_AUTH ) <EOL> eq_ ( res [ <NUM_LIT:5> ] , max_adver_int ) <EOL> eq_ ( res [ <NUM_LIT:7> ] , addrconv . ipv4 . text_to_bin ( ip_address ) ) <EOL> eq_ ( res [ <NUM_LIT:8> ] , <NUM_LIT:0> ) <EOL> eq_ ( res [ <NUM_LIT:9> ] , <NUM_LIT:0> ) <EOL> eq_ ( len ( buf ) , pack_len ) <EOL> s = packet_utils . checksum ( buf ) <EOL> eq_ ( <NUM_LIT:0> , s ) <EOL> @ raises ( Exception ) <EOL> def test_malformed_vrrpv2 ( self ) : <EOL> m_short_buf = self . buf [ <NUM_LIT:1> : vrrp . vrrpv2 . _MIN_LEN ] <EOL> vrrp . vrrp . parser ( m_short_buf ) <EOL> def test_create_packet ( self ) : <EOL> primary_ip = '<STR_LIT>' <EOL> p0 = self . vrrpv2 . create_packet ( primary_ip ) <EOL> p0 . serialize ( ) <EOL> p1 = packet . Packet ( six . binary_type ( p0 . data ) ) <EOL> p1 . serialize ( ) <EOL> eq_ ( p0 . data , p1 . data ) <EOL> def _test_is_valid ( self , type_ = None , vrid = None , priority = None , <EOL> max_adver_int = None ) : <EOL> if type_ is None : <EOL> type_ = self . type_ <EOL> if vrid is None : <EOL> vrid = self . vrid <EOL> if priority is None : <EOL> priority = self . priority <EOL> if max_adver_int is None : <EOL> max_adver_int = self . max_adver_int <EOL> vrrp_ = vrrp . vrrpv2 . create ( type_ , vrid , priority , max_adver_int , <EOL> [ self . ip_address ] ) <EOL> return vrrp_ . is_valid ( ) <EOL> def test_is_valid_ok ( self ) : <EOL> ok_ ( self . _test_is_valid ( ) ) <EOL> def test_is_valid_ng_type ( self ) : <EOL> ok_ ( not self . _test_is_valid ( type_ = <NUM_LIT:15> ) ) <EOL> def test_is_valid_ng_vrid_min ( self ) : <EOL> vrid = vrrp . VRRP_VRID_MIN - <NUM_LIT:1> <EOL> ok_ ( not self . _test_is_valid ( vrid = vrid ) ) <EOL> def test_is_valid_ng_vrid_max ( self ) : <EOL> vrid = vrrp . VRRP_VRID_MAX + <NUM_LIT:1> <EOL> ok_ ( not self . _test_is_valid ( vrid = vrid ) ) <EOL> def test_is_valid_ng_priority_min ( self ) : <EOL> priority = vrrp . VRRP_PRIORITY_MIN - <NUM_LIT:1> <EOL> ok_ ( not self . _test_is_valid ( priority = priority ) ) <EOL> def test_is_valid_ng_priority_max ( self ) : <EOL> priority = vrrp . VRRP_PRIORITY_MAX + <NUM_LIT:1> <EOL> ok_ ( not self . _test_is_valid ( priority = priority ) ) <EOL> def test_is_valid_ng_adver_min ( self ) : <EOL> max_adver_int = vrrp . VRRP_V2_MAX_ADVER_INT_MIN - <NUM_LIT:1> <EOL> ok_ ( not self . _test_is_valid ( max_adver_int = max_adver_int ) ) <EOL> def test_is_valid_ng_adver_max ( self ) : <EOL> max_adver_int = vrrp . VRRP_V2_MAX_ADVER_INT_MAX + <NUM_LIT:1> <EOL> ok_ ( not self . _test_is_valid ( max_adver_int = max_adver_int ) ) <EOL> def test_to_string ( self ) : <EOL> vrrpv2_values = { '<STR_LIT:version>' : self . version , <EOL> '<STR_LIT:type>' : self . type_ , <EOL> '<STR_LIT>' : self . vrid , <EOL> '<STR_LIT>' : self . priority , <EOL> '<STR_LIT>' : self . count_ip , <EOL> '<STR_LIT>' : self . max_adver_int , <EOL> '<STR_LIT>' : self . vrrpv2 . checksum , <EOL> '<STR_LIT>' : [ self . ip_address ] , <EOL> '<STR_LIT>' : self . auth_type , <EOL> '<STR_LIT>' : self . auth_data , <EOL> '<STR_LIT>' : self . vrrpv2 . identification } <EOL> _vrrpv2_str = '<STR_LIT:U+002C>' . join ( [ '<STR_LIT>' % ( k , repr ( vrrpv2_values [ k ] ) ) <EOL> for k , v in inspect . getmembers ( self . vrrpv2 ) <EOL> if k in vrrpv2_values ] ) <EOL> vrrpv2_str = '<STR_LIT>' % ( vrrp . vrrpv2 . __name__ , _vrrpv2_str ) <EOL> eq_ ( str ( self . vrrpv2 ) , vrrpv2_str ) <EOL> eq_ ( repr ( self . vrrpv2 ) , vrrpv2_str ) <EOL> class Test_vrrpv3_ipv4 ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> version = vrrp . VRRP_VERSION_V3 <EOL> type_ = vrrp . VRRP_TYPE_ADVERTISEMENT <EOL> vrid = <NUM_LIT> <EOL> priority = <NUM_LIT> <EOL> count_ip = <NUM_LIT:1> <EOL> max_adver_int = <NUM_LIT> <EOL> checksum = <NUM_LIT:0> <EOL> ip_address = '<STR_LIT>' <EOL> vrrpv3 = vrrp . vrrpv3 . create ( type_ , vrid , priority , max_adver_int , <EOL> [ ip_address ] ) <EOL> buf = struct . pack ( vrrp . vrrpv3 . _PACK_STR + '<STR_LIT>' , <EOL> vrrp . vrrp_to_version_type ( vrrp . VRRP_VERSION_V3 , type_ ) , <EOL> vrid , priority , count_ip , <EOL> max_adver_int , checksum , <EOL> addrconv . ipv4 . text_to_bin ( ip_address ) ) <EOL> def setUp ( self ) : <EOL> pass <EOL> def tearDown ( self ) : <EOL> pass <EOL> def test_init ( self ) : <EOL> eq_ ( self . type_ , self . vrrpv3 . type ) <EOL> eq_ ( self . vrid , self . vrrpv3 . vrid ) <EOL> eq_ ( self . priority , self . vrrpv3 . priority ) <EOL> eq_ ( self . count_ip , self . vrrpv3 . count_ip ) <EOL> eq_ ( <NUM_LIT:1> , len ( self . vrrpv3 . ip_addresses ) ) <EOL> eq_ ( self . ip_address , self . vrrpv3 . ip_addresses [ <NUM_LIT:0> ] ) <EOL> def test_parser ( self ) : <EOL> vrrpv3 , _cls , _ = self . vrrpv3 . parser ( self . buf ) <EOL> eq_ ( self . version , vrrpv3 . version ) <EOL> eq_ ( self . type_ , vrrpv3 . type ) <EOL> eq_ ( self . vrid , vrrpv3 . vrid ) <EOL> eq_ ( self . priority , vrrpv3 . priority ) <EOL> eq_ ( self . count_ip , vrrpv3 . count_ip ) <EOL> eq_ ( self . max_adver_int , vrrpv3 . max_adver_int ) <EOL> eq_ ( self . checksum , vrrpv3 . checksum ) <EOL> eq_ ( <NUM_LIT:1> , len ( vrrpv3 . ip_addresses ) ) <EOL> eq_ ( str , type ( vrrpv3 . ip_addresses [ <NUM_LIT:0> ] ) ) <EOL> eq_ ( self . ip_address , vrrpv3 . ip_addresses [ <NUM_LIT:0> ] ) <EOL> def test_serialize ( self ) : <EOL> src_ip = '<STR_LIT>' <EOL> dst_ip = vrrp . VRRP_IPV4_DST_ADDRESS <EOL> prev = ipv4 . ipv4 ( <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , vrrp . VRRP_IPV4_TTL , <EOL> inet . IPPROTO_VRRP , <NUM_LIT:0> , src_ip , dst_ip ) <EOL> type_ = vrrp . VRRP_TYPE_ADVERTISEMENT <EOL> vrid = <NUM_LIT:5> <EOL> priority = <NUM_LIT:10> <EOL> max_adver_int = <NUM_LIT:30> <EOL> ip_address = '<STR_LIT>' <EOL> ip_addresses = [ ip_address ] <EOL> vrrp_ = vrrp . vrrpv3 . create ( <EOL> type_ , vrid , priority , max_adver_int , ip_addresses ) <EOL> buf = vrrp_ . serialize ( bytearray ( ) , prev ) <EOL> print ( len ( buf ) , type ( buf ) , buf ) <EOL> pack_str = vrrp . vrrpv3 . _PACK_STR + '<STR_LIT>' <EOL> pack_len = struct . calcsize ( pack_str ) <EOL> res = struct . unpack ( pack_str , six . binary_type ( buf ) ) <EOL> eq_ ( res [ <NUM_LIT:0> ] , vrrp . vrrp_to_version_type ( vrrp . VRRP_VERSION_V3 , type_ ) ) <EOL> eq_ ( res [ <NUM_LIT:1> ] , vrid ) <EOL> eq_ ( res [ <NUM_LIT:2> ] , priority ) <EOL> eq_ ( res [ <NUM_LIT:3> ] , len ( ip_addresses ) ) <EOL> eq_ ( res [ <NUM_LIT:4> ] , max_adver_int ) <EOL> eq_ ( res [ <NUM_LIT:6> ] , addrconv . ipv4 . text_to_bin ( ip_address ) ) <EOL> eq_ ( len ( buf ) , pack_len ) <EOL> print ( res ) <EOL> ph = struct . pack ( '<STR_LIT>' , <EOL> addrconv . ipv4 . text_to_bin ( src_ip ) , <EOL> addrconv . ipv4 . text_to_bin ( dst_ip ) , <EOL> inet . IPPROTO_VRRP , pack_len ) <EOL> s = packet_utils . checksum ( ph + buf ) <EOL> eq_ ( <NUM_LIT:0> , s ) <EOL> @ raises ( Exception ) <EOL> def test_malformed_vrrpv3 ( self ) : <EOL> m_short_buf = self . buf [ <NUM_LIT:1> : vrrp . vrrpv3 . _MIN_LEN ] <EOL> vrrp . vrrp . parser ( m_short_buf ) <EOL> def test_create_packet ( self ) : <EOL> primary_ip = '<STR_LIT>' <EOL> p0 = self . vrrpv3 . create_packet ( primary_ip ) <EOL> p0 . serialize ( ) <EOL> p1 = packet . Packet ( six . binary_type ( p0 . data ) ) <EOL> p1 . serialize ( ) <EOL> eq_ ( p0 . data , p1 . data ) <EOL> def _test_is_valid ( self , type_ = None , vrid = None , priority = None , <EOL> max_adver_int = None ) : <EOL> if type_ is None : <EOL> type_ = self . type_ <EOL> if vrid is None : <EOL> vrid = self . vrid <EOL> if priority is None : <EOL> priority = self . priority <EOL> if max_adver_int is None : <EOL> max_adver_int = self . max_adver_int <EOL> vrrp_ = vrrp . vrrpv3 . create ( type_ , vrid , priority , max_adver_int , <EOL> [ self . ip_address ] ) <EOL> return vrrp_ . is_valid ( ) <EOL> def test_is_valid_ok ( self ) : <EOL> ok_ ( self . _test_is_valid ( ) ) <EOL> def test_is_valid_ng_type ( self ) : <EOL> ok_ ( not self . _test_is_valid ( type_ = <NUM_LIT:15> ) ) <EOL> def test_is_valid_ng_vrid_min ( self ) : <EOL> vrid = vrrp . VRRP_VRID_MIN - <NUM_LIT:1> <EOL> ok_ ( not self . _test_is_valid ( vrid = vrid ) ) <EOL> def test_is_valid_ng_vrid_max ( self ) : <EOL> vrid = vrrp . VRRP_VRID_MAX + <NUM_LIT:1> <EOL> ok_ ( not self . _test_is_valid ( vrid = vrid ) ) <EOL> def test_is_valid_ng_priority_min ( self ) : <EOL> priority = vrrp . VRRP_PRIORITY_MIN - <NUM_LIT:1> <EOL> ok_ ( not self . _test_is_valid ( priority = priority ) ) <EOL> def test_is_valid_ng_priority_max ( self ) : <EOL> priority = vrrp . VRRP_PRIORITY_MAX + <NUM_LIT:1> <EOL> ok_ ( not self . _test_is_valid ( priority = priority ) ) <EOL> def test_is_valid_ng_adver_min ( self ) : <EOL> max_adver_int = vrrp . VRRP_V3_MAX_ADVER_INT_MIN - <NUM_LIT:1> <EOL> ok_ ( not self . _test_is_valid ( max_adver_int = max_adver_int ) ) <EOL> def test_is_valid_ng_adver_max ( self ) : <EOL> max_adver_int = vrrp . VRRP_V3_MAX_ADVER_INT_MAX + <NUM_LIT:1> <EOL> ok_ ( not self . _test_is_valid ( max_adver_int = max_adver_int ) ) <EOL> def test_to_string ( self ) : <EOL> vrrpv3_values = { '<STR_LIT:version>' : self . version , <EOL> '<STR_LIT:type>' : self . type_ , <EOL> '<STR_LIT>' : self . vrid , <EOL> '<STR_LIT>' : self . priority , <EOL> '<STR_LIT>' : self . count_ip , <EOL> '<STR_LIT>' : self . max_adver_int , <EOL> '<STR_LIT>' : self . vrrpv3 . checksum , <EOL> '<STR_LIT>' : [ self . ip_address ] , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : self . vrrpv3 . identification } <EOL> _vrrpv3_str = '<STR_LIT:U+002C>' . join ( [ '<STR_LIT>' % ( k , repr ( vrrpv3_values [ k ] ) ) <EOL> for k , v in inspect . getmembers ( self . vrrpv3 ) <EOL> if k in vrrpv3_values ] ) <EOL> vrrpv3_str = '<STR_LIT>' % ( vrrp . vrrpv3 . __name__ , _vrrpv3_str ) <EOL> eq_ ( str ( self . vrrpv3 ) , vrrpv3_str ) <EOL> eq_ ( repr ( self . vrrpv3 ) , vrrpv3_str ) <EOL> class Test_vrrpv3_ipv6 ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> version = vrrp . VRRP_VERSION_V3 <EOL> type_ = vrrp . VRRP_TYPE_ADVERTISEMENT <EOL> vrid = <NUM_LIT> <EOL> priority = <NUM_LIT> <EOL> count_ip = <NUM_LIT:1> <EOL> max_adver_int = <NUM_LIT> <EOL> checksum = <NUM_LIT:0> <EOL> ip_address = '<STR_LIT>' <EOL> vrrpv3 = vrrp . vrrpv3 . create ( type_ , vrid , priority , max_adver_int , <EOL> [ ip_address ] ) <EOL> buf = struct . pack ( vrrp . vrrpv3 . _PACK_STR + '<STR_LIT>' , <EOL> vrrp . vrrp_to_version_type ( vrrp . VRRP_VERSION_V3 , type_ ) , <EOL> vrid , priority , count_ip , <EOL> max_adver_int , checksum , <EOL> addrconv . ipv6 . text_to_bin ( ip_address ) ) <EOL> def setUp ( self ) : <EOL> pass <EOL> def tearDown ( self ) : <EOL> pass <EOL> def test_init ( self ) : <EOL> eq_ ( self . type_ , self . vrrpv3 . type ) <EOL> eq_ ( self . vrid , self . vrrpv3 . vrid ) <EOL> eq_ ( self . priority , self . vrrpv3 . priority ) <EOL> eq_ ( self . count_ip , self . vrrpv3 . count_ip ) <EOL> eq_ ( <NUM_LIT:1> , len ( self . vrrpv3 . ip_addresses ) ) <EOL> eq_ ( self . ip_address , self . vrrpv3 . ip_addresses [ <NUM_LIT:0> ] ) <EOL> def test_parser ( self ) : <EOL> vrrpv3 , _cls , _ = self . vrrpv3 . parser ( self . buf ) <EOL> eq_ ( self . version , vrrpv3 . version ) <EOL> eq_ ( self . type_ , vrrpv3 . type ) <EOL> eq_ ( self . vrid , vrrpv3 . vrid ) <EOL> eq_ ( self . priority , vrrpv3 . priority ) <EOL> eq_ ( self . count_ip , vrrpv3 . count_ip ) <EOL> eq_ ( self . max_adver_int , vrrpv3 . max_adver_int ) <EOL> eq_ ( self . checksum , vrrpv3 . checksum ) <EOL> eq_ ( <NUM_LIT:1> , len ( vrrpv3 . ip_addresses ) ) <EOL> eq_ ( str , type ( vrrpv3 . ip_addresses [ <NUM_LIT:0> ] ) ) <EOL> eq_ ( self . ip_address , vrrpv3 . ip_addresses [ <NUM_LIT:0> ] ) <EOL> def test_serialize ( self ) : <EOL> src_ip = '<STR_LIT>' <EOL> dst_ip = vrrp . VRRP_IPV6_DST_ADDRESS <EOL> prev = ipv6 . ipv6 ( <NUM_LIT:6> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , inet . IPPROTO_VRRP , <EOL> vrrp . VRRP_IPV6_HOP_LIMIT , src_ip , dst_ip ) <EOL> type_ = vrrp . VRRP_TYPE_ADVERTISEMENT <EOL> vrid = <NUM_LIT:5> <EOL> priority = <NUM_LIT:10> <EOL> max_adver_int = <NUM_LIT:30> <EOL> ip_address = '<STR_LIT>' <EOL> ip_addresses = [ ip_address ] <EOL> vrrp_ = vrrp . vrrpv3 . create ( <EOL> type_ , vrid , priority , max_adver_int , ip_addresses ) <EOL> buf = vrrp_ . serialize ( bytearray ( ) , prev ) <EOL> print ( len ( buf ) , type ( buf ) , buf ) <EOL> pack_str = vrrp . vrrpv3 . _PACK_STR + '<STR_LIT>' <EOL> pack_len = struct . calcsize ( pack_str ) <EOL> res = struct . unpack ( pack_str , six . binary_type ( buf ) ) <EOL> eq_ ( res [ <NUM_LIT:0> ] , vrrp . vrrp_to_version_type ( vrrp . VRRP_VERSION_V3 , type_ ) ) <EOL> eq_ ( res [ <NUM_LIT:1> ] , vrid ) <EOL> eq_ ( res [ <NUM_LIT:2> ] , priority ) <EOL> eq_ ( res [ <NUM_LIT:3> ] , len ( ip_addresses ) ) <EOL> eq_ ( res [ <NUM_LIT:4> ] , max_adver_int ) <EOL> eq_ ( res [ <NUM_LIT:6> ] , addrconv . ipv6 . text_to_bin ( ip_address ) ) <EOL> eq_ ( len ( buf ) , pack_len ) <EOL> print ( res ) <EOL> ph = struct . pack ( '<STR_LIT>' , <EOL> addrconv . ipv6 . text_to_bin ( src_ip ) , <EOL> addrconv . ipv6 . text_to_bin ( dst_ip ) , <EOL> pack_len , inet . IPPROTO_VRRP ) <EOL> s = packet_utils . checksum ( ph + buf ) <EOL> eq_ ( <NUM_LIT:0> , s ) <EOL> @ raises ( Exception ) <EOL> def test_malformed_vrrpv3 ( self ) : <EOL> m_short_buf = self . buf [ <NUM_LIT:1> : vrrp . vrrpv3 . _MIN_LEN ] <EOL> vrrp . vrrp . parser ( m_short_buf ) <EOL> def test_create_packet ( self ) : <EOL> primary_ip = '<STR_LIT>' <EOL> p0 = self . vrrpv3 . create_packet ( primary_ip ) <EOL> p0 . serialize ( ) <EOL> print ( len ( p0 . data ) , p0 . data ) <EOL> p1 = packet . Packet ( six . binary_type ( p0 . data ) ) <EOL> p1 . serialize ( ) <EOL> print ( len ( p0 . data ) , p0 . data ) <EOL> print ( len ( p1 . data ) , p1 . data ) <EOL> eq_ ( p0 . data , p1 . data ) <EOL> def test_to_string ( self ) : <EOL> vrrpv3_values = { '<STR_LIT:version>' : self . version , <EOL> '<STR_LIT:type>' : self . type_ , <EOL> '<STR_LIT>' : self . vrid , <EOL> '<STR_LIT>' : self . priority , <EOL> '<STR_LIT>' : self . count_ip , <EOL> '<STR_LIT>' : self . max_adver_int , <EOL> '<STR_LIT>' : self . vrrpv3 . checksum , <EOL> '<STR_LIT>' : [ self . ip_address ] , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : self . vrrpv3 . identification } <EOL> _vrrpv3_str = '<STR_LIT:U+002C>' . join ( [ '<STR_LIT>' % ( k , repr ( vrrpv3_values [ k ] ) ) <EOL> for k , v in inspect . getmembers ( self . vrrpv3 ) <EOL> if k in vrrpv3_values ] ) <EOL> vrrpv3_str = '<STR_LIT>' % ( vrrp . vrrpv3 . __name__ , _vrrpv3_str ) <EOL> eq_ ( str ( self . vrrpv3 ) , vrrpv3_str ) <EOL> eq_ ( repr ( self . vrrpv3 ) , vrrpv3_str ) </s>
