Geneve: Re-write the creation of tunnels in python 67/31167/11
authorTibor Frank <tifrank@cisco.com>
Mon, 8 Feb 2021 16:19:32 +0000 (17:19 +0100)
committerTibor Frank <tifrank@cisco.com>
Tue, 23 Mar 2021 09:28:44 +0000 (09:28 +0000)
Change-Id: I8b20134ad10abd9c021270b98c3110bd186946d5
Signed-off-by: Tibor Frank <tifrank@cisco.com>
resources/libraries/python/GeneveUtil.py
resources/libraries/robot/ip/geneve.robot

index 3c8ebee..d7266f5 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2020 Cisco and/or its affiliates.
+# Copyright (c) 2021 Cisco and/or its affiliates.
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at:
@@ -18,6 +18,7 @@ from ipaddress import ip_address
 from resources.libraries.python.Constants import Constants
 from resources.libraries.python.InterfaceUtil import InterfaceUtil
 from resources.libraries.python.IPAddress import IPAddress
+from resources.libraries.python.IPUtil import IPUtil
 from resources.libraries.python.PapiExecutor import PapiSocketExecutor
 from resources.libraries.python.topology import Topology
 
@@ -124,3 +125,72 @@ class GeneveUtil:
             u"geneve_tunnel_dump",
         ]
         PapiSocketExecutor.dump_and_log(node, cmds)
+
+    @staticmethod
+    def vpp_geneve_add_multiple_tunnels(
+            node, gen_tunnel, n_tunnels, dut_if1, dut_if2, tg_if1_ip4,
+            tg_if2_ip4, tg_pf2_mac, next_idx):
+        """Create multiple GENEVE tunnels.
+
+        :param node: DUT node.
+        :param gen_tunnel: Parameters of the GENEVE tunnel.
+        :param n_tunnels: Number of tunnels.
+        :param dut_if1: The first DUT interface.
+        :param dut_if2: The second DUT interface.
+        :param tg_if1_ip4: TG interface 1 IP address.
+        :param tg_if2_ip4: TG interface 2 IP address.
+        :param tg_pf2_mac: TG interface 2 MAC address.
+        :param next_idx: The index of the next node.
+        :type node: dict
+        :type gen_tunnel: dict
+        :type n_tunnels: int
+        :type dut_if1: str
+        :type dut_if2: str
+        :type tg_if1_ip4: str
+        :type tg_if2_ip4: str
+        :type tg_pf2_mac: str
+        :type next_idx: int
+        """
+
+        src_ip_int = IPUtil.ip_to_int(gen_tunnel[u"src_ip"])
+        dst_ip_int = IPUtil.ip_to_int(gen_tunnel[u"dst_ip"])
+        if_ip_int = IPUtil.ip_to_int(gen_tunnel[u"if_ip"])
+
+        for idx in range(n_tunnels):
+            src_ip = IPUtil.int_to_ip(src_ip_int + idx * 256)
+            dst_ip = IPUtil.int_to_ip(dst_ip_int + idx * 256)
+            if_ip = IPUtil.int_to_ip(if_ip_int + idx * 256)
+
+            IPUtil.vpp_route_add(
+                node, src_ip, gen_tunnel[u"ip_mask"],
+                gateway=tg_if1_ip4, interface=dut_if1
+            )
+            tunnel_sw_index = GeneveUtil.add_geneve_tunnel(
+                node, gen_tunnel[u"local"], gen_tunnel[u"remote"],
+                gen_tunnel[u"vni"] + idx, l3_mode=True, next_index=next_idx
+            )
+            tunnel_if_key = Topology.get_interface_by_sw_index(
+                node, tunnel_sw_index
+            )
+            tunnel_if_mac = Topology.get_interface_mac(
+                node, tunnel_if_key
+            )
+            IPUtil.vpp_interface_set_ip_address(node, tunnel_if_key, if_ip, 24)
+            IPUtil.vpp_add_ip_neighbor(
+                node, tunnel_if_key, tg_if2_ip4, tg_pf2_mac
+            )
+            IPUtil.vpp_route_add(
+                node, dst_ip, gen_tunnel[u"ip_mask"],
+                gateway=tg_if2_ip4, interface=tunnel_if_key
+            )
+            IPUtil.vpp_route_add(
+                node, gen_tunnel[u"remote"], 32,
+                gateway=tg_if2_ip4, interface=dut_if2
+            )
+            IPUtil.vpp_add_ip_neighbor(
+                node, tunnel_if_key, gen_tunnel[u"local"], tunnel_if_mac
+            )
+            IPUtil.vpp_route_add(
+                node, gen_tunnel[u"local"], 32, gateway=if_ip
+            )
+            InterfaceUtil.set_interface_state(node, tunnel_if_key, u"up")
index ffbd506..5edf4f4 100644 (file)
@@ -20,8 +20,6 @@
 | Initialize GENEVE L3 mode in circular topology
 | | [Documentation] | Initialization of GENEVE L3 mode on DUT1.
 | |
-| | [Arguments] | ${with_bypass}=${False}
-| |
 | | Set interfaces in path up
 | |
 | | VPP Interface Set IP Address
 | | ${next_index}= | VPP Add Graph Node Next
 | | ... | ${dut1} | geneve4-input | ethernet-input
 | |
-| | ${src_ip_int} = | IP To Int | ${gen_tunnel.src_ip}
-| | ${dst_ip_int} = | IP To Int | ${gen_tunnel.dst_ip}
-| | ${if_ip_int} = | IP To Int | ${gen_tunnel.if_ip}
+| | VPP GENEVE Add Multiple Tunnels
+| | ... | ${dut1} | ${gen_tunnel} | ${n_tunnels} | ${DUT1_${int}1}[0]
+| | ... | ${DUT1_${int}2}[0] | ${tg_if1_ip4} | ${tg_if2_ip4}
+| | ... | ${TG_pf2_mac}[0] | ${next_index}
 | |
-| | FOR | ${nr} | IN RANGE | 0 | ${n_tunnels}
-| | | ${src_ip} = | Int To IP | ${${src_ip_int} + ${nr} * 256}
-| | | ${dst_ip} = | Int To IP | ${${dst_ip_int} + ${nr} * 256}
-| | | ${if_ip} = | Int To IP | ${${if_ip_int} + ${nr} * 256}
-| | | Vpp Route Add
-| | | ... | ${dut1} | ${src_ip} | ${gen_tunnel.ip_mask}
-| | | ... | gateway=${tg_if1_ip4} | interface=${DUT1_${int}1}[0]
-| | | ${tunnel_sw_index}= | Add Geneve Tunnel
-| | | ... | ${dut1} | ${gen_tunnel.local} | ${gen_tunnel.remote}
-| | | ... | ${${gen_tunnel.vni} + ${nr}} | l3_mode=${True}
-| | | ... | next_index=${next_index}
-| | | ${tunnel_if_key}= | Get Interface By SW Index
-| | | ... | ${dut1} | ${tunnel_sw_index}
-| | | ${tunnel_if_mac}= | Get Interface MAC
-| | | ... | ${dut1} | ${tunnel_if_key}
-| | | VPP Interface Set IP Address
-| | | ... | ${dut1} | ${tunnel_if_key} | ${if_ip} | 24
-| | | VPP Add IP Neighbor
-| | | ... | ${dut1} | ${tunnel_if_key} | ${tg_if2_ip4} | ${TG_pf2_mac}[0]
-| | | Vpp Route Add
-| | | ... | ${dut1} | ${dst_ip} | ${gen_tunnel.ip_mask}
-| | | ... | gateway=${tg_if2_ip4} | interface=${tunnel_if_key}
-| | | Vpp Route Add
-| | | ... | ${dut1} | ${gen_tunnel.remote} | 32
-| | | ... | gateway=${tg_if2_ip4} | interface=${DUT1_${int}2}[0]
-| | | VPP Add IP Neighbor
-| | | ... | ${dut1} | ${tunnel_if_key} | ${gen_tunnel.local} | ${tunnel_if_mac}
-| | | Vpp Route Add
-| | | ... | ${dut1} | ${gen_tunnel.local} | 32 | gateway=${if_ip}
-| | | Set Interface State
-| | | ... | ${dut1} | ${tunnel_if_key} | up
-| | END
 | | All VPP Interfaces Ready Wait | ${nodes} | retries=${60}

©2016 FD.io a Linux Foundation Collaborative Project. All Rights Reserved.
Linux Foundation is a registered trademark of The Linux Foundation. Linux is a registered trademark of Linus Torvalds.
Please see our privacy policy and terms of use.