X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=resources%2Flibraries%2Fpython%2FIPsecUtil.py;h=123043828dd055c3212b7c279fa603f4f241bba8;hb=82094363f6077e1b28845719db3a6191c0c93a99;hp=c4fdefb1809a0bf6fe8b8d01a8306ebf3bb682c4;hpb=acac11dbf7c5011945b9d5fded1a02aa63b5f964;p=csit.git diff --git a/resources/libraries/python/IPsecUtil.py b/resources/libraries/python/IPsecUtil.py index c4fdefb180..123043828d 100644 --- a/resources/libraries/python/IPsecUtil.py +++ b/resources/libraries/python/IPsecUtil.py @@ -117,15 +117,6 @@ class IPsecUtil(object): """ return CryptoAlg.AES_CBC_128 - @staticmethod - def crypto_alg_aes_cbc_192(): - """Return encryption algorithm aes-cbc-192. - - :returns: CryptoAlg enum AES_CBC_192 objec. - :rtype: CryptoAlg - """ - return CryptoAlg.AES_CBC_192 - @staticmethod def crypto_alg_aes_cbc_256(): """Return encryption algorithm aes-cbc-256. @@ -175,15 +166,6 @@ class IPsecUtil(object): """ return crypto_alg.scapy_name - @staticmethod - def integ_alg_sha1_96(): - """Return integrity algorithm SHA1-96. - - :returns: IntegAlg enum SHA1_96 object. - :rtype: IntegAlg - """ - return IntegAlg.SHA1_96 - @staticmethod def integ_alg_sha_256_128(): """Return integrity algorithm SHA-256-128. @@ -193,15 +175,6 @@ class IPsecUtil(object): """ return IntegAlg.SHA_256_128 - @staticmethod - def integ_alg_sha_384_192(): - """Return integrity algorithm SHA-384-192. - - :returns: IntegAlg enum SHA_384_192 object. - :rtype: IntegAlg - """ - return IntegAlg.SHA_384_192 - @staticmethod def integ_alg_sha_512_256(): """Return integrity algorithm SHA-512-256. @@ -630,7 +603,8 @@ class IPsecUtil(object): tunnel = ( 'exec ipsec policy add spd {spd_id} priority {priority} ' '{direction} action protect sa {sa_id} ' - 'remote-ip-range {raddr_s} - {raddr_e}\n'. + 'remote-ip-range {raddr_s} - {raddr_e} ' + 'local-ip-range 0.0.0.0 - 255.255.255.255\n'. format( spd_id=spd_id, priority=priority, @@ -687,6 +661,18 @@ class IPsecUtil(object): vat = VatExecutor() with open(tmp_fn1, 'w') as tmp_f1, open(tmp_fn2, 'w') as tmp_f2: + tmp_f1.write( + 'exec create loopback interface\n' + 'exec set interface state loop0 up\n' + 'exec set interface ip address {uifc} {iaddr}/24\n' + .format( + iaddr=ip_address(unicode(if2_ip_addr)) - 1, + uifc=Topology.get_interface_name(nodes['DUT1'], if1_key))) + tmp_f2.write( + 'exec set interface ip address {uifc} {iaddr}/24\n' + .format( + iaddr=ip_address(unicode(if2_ip_addr)), + uifc=Topology.get_interface_name(nodes['DUT2'], if2_key))) for i in range(0, n_tunnels): ckey = gen_key(IPsecUtil.get_crypto_alg_key_len(crypto_alg)) ikey = gen_key(IPsecUtil.get_integ_alg_key_len(integ_alg)) @@ -701,7 +687,7 @@ class IPsecUtil(object): local_integ_key=ikey, remote_integ_key=ikey)) tmp_f1.write( - 'exec set interface ip address {uifc} {laddr}/24\n' + 'exec set interface ip address loop0 {laddr}/32\n' 'ipsec_tunnel_if_add_del ' 'local_spi {local_spi} ' 'remote_spi {remote_spi} ' @@ -719,11 +705,10 @@ class IPsecUtil(object): remote_crypto_key=ckey, integ=integ, laddr=ip_address(unicode(if1_ip_addr)) + i * addr_incr, - raddr=ip_address(unicode(if2_ip_addr)) + i * addr_incr, + raddr=ip_address(unicode(if2_ip_addr)), uifc=Topology.get_interface_name(nodes['DUT1'], if1_key))) tmp_f2.write( - 'exec set interface ip address {uifc} {laddr}/24\n' 'ipsec_tunnel_if_add_del ' 'local_spi {local_spi} ' 'remote_spi {remote_spi} ' @@ -740,42 +725,44 @@ class IPsecUtil(object): local_crypto_key=ckey, remote_crypto_key=ckey, integ=integ, - laddr=ip_address(unicode(if2_ip_addr)) + i * addr_incr, - raddr=ip_address(unicode(if1_ip_addr)) + i * addr_incr, - uifc=Topology.get_interface_name(nodes['DUT2'], - if2_key))) - vat.execute_script(tmp_fn1, nodes['DUT1'], timeout=300, json_out=False, + laddr=ip_address(unicode(if2_ip_addr)), + raddr=ip_address(unicode(if1_ip_addr)) + i * addr_incr)) + vat.execute_script(tmp_fn1, nodes['DUT1'], timeout=1800, json_out=False, copy_on_execute=True) - vat.execute_script(tmp_fn2, nodes['DUT2'], timeout=300, json_out=False, + vat.execute_script(tmp_fn2, nodes['DUT2'], timeout=1800, json_out=False, copy_on_execute=True) os.remove(tmp_fn1) os.remove(tmp_fn2) with open(tmp_fn1, 'w') as tmp_f1, open(tmp_fn2, 'w') as tmp_f2: + tmp_f2.write( + 'exec ip route add {raddr} via {uifc} {iaddr}\n' + .format( + raddr=ip_network(unicode(if1_ip_addr+'/8'), False), + iaddr=ip_address(unicode(if2_ip_addr)) - 1, + uifc=Topology.get_interface_name(nodes['DUT2'], if2_key))) for i in range(0, n_tunnels): tmp_f1.write( 'exec set interface unnumbered ipsec{i} use {uifc}\n' 'exec set interface state ipsec{i} up\n' - 'exec ip route add {taddr}/32 via {raddr} ipsec{i}\n' + 'exec ip route add {taddr}/32 via ipsec{i}\n' .format( taddr=ip_address(unicode(raddr_ip2)) + i, - raddr=ip_address(unicode(if2_ip_addr)) + i * addr_incr, i=i, uifc=Topology.get_interface_name(nodes['DUT1'], if1_key))) tmp_f2.write( 'exec set interface unnumbered ipsec{i} use {uifc}\n' 'exec set interface state ipsec{i} up\n' - 'exec ip route add {taddr}/32 via {raddr} ipsec{i}\n' + 'exec ip route add {taddr}/32 via ipsec{i}\n' .format( taddr=ip_address(unicode(raddr_ip1)) + i, - raddr=ip_address(unicode(if1_ip_addr)) + i * addr_incr, i=i, uifc=Topology.get_interface_name(nodes['DUT2'], if2_key))) - vat.execute_script(tmp_fn1, nodes['DUT1'], timeout=300, json_out=False, + vat.execute_script(tmp_fn1, nodes['DUT1'], timeout=1800, json_out=False, copy_on_execute=True) - vat.execute_script(tmp_fn2, nodes['DUT2'], timeout=300, json_out=False, + vat.execute_script(tmp_fn2, nodes['DUT2'], timeout=1800, json_out=False, copy_on_execute=True) os.remove(tmp_fn1) os.remove(tmp_fn2) @@ -837,10 +824,10 @@ class IPsecUtil(object): nodes['DUT1'], spd_id, interface1) IPsecUtil.vpp_ipsec_policy_add( nodes['DUT1'], spd_id, p_hi, PolicyAction.BYPASS, inbound=False, - proto=50) + proto=50, laddr_range='100.0.0.0/8', raddr_range='100.0.0.0/8') IPsecUtil.vpp_ipsec_policy_add( nodes['DUT1'], spd_id, p_hi, PolicyAction.BYPASS, inbound=True, - proto=50) + proto=50, laddr_range='100.0.0.0/8', raddr_range='100.0.0.0/8') IPsecUtil.vpp_ipsec_add_spd( nodes['DUT2'], spd_id) @@ -848,10 +835,10 @@ class IPsecUtil(object): nodes['DUT2'], spd_id, interface2) IPsecUtil.vpp_ipsec_policy_add( nodes['DUT2'], spd_id, p_hi, PolicyAction.BYPASS, inbound=False, - proto=50) + proto=50, laddr_range='100.0.0.0/8', raddr_range='100.0.0.0/8') IPsecUtil.vpp_ipsec_policy_add( nodes['DUT2'], spd_id, p_hi, PolicyAction.BYPASS, inbound=True, - proto=50) + proto=50, laddr_range='100.0.0.0/8', raddr_range='100.0.0.0/8') IPsecUtil.vpp_ipsec_add_sad_entries( nodes['DUT1'], n_tunnels, sa_id_1, spi_1, crypto_alg, crypto_key,