CSIT-366 IPv4dp - baseline vhost-user
[csit.git] / resources / libraries / python / IPv4Setup.py
index 14179c3..d4be4c6 100644 (file)
@@ -173,29 +173,33 @@ class Dut(IPv4Node):
         # TODO: check return value
         VatExecutor.cmd_from_template(self.node_info, script, **args)
 
-    def set_arp(self, interface, ip_address, mac_address):
+    def set_arp(self, iface_key, ip_address, mac_address, vrf=None):
         """Set entry in ARP cache.
 
-        :param interface: Interface name.
+        :param iface_key: Interface key.
         :param ip_address: IP address.
         :param mac_address: MAC address.
-        :type interface: str
+        :param vrf: VRF table ID (Optional).
+        :type iface_key: str
         :type ip_address: str
         :type mac_address: str
+        :type vrf: int
         """
+        vrf = "vrf {}".format(vrf) if vrf else ''
         self.exec_vat('add_ip_neighbor.vat',
-                      sw_if_index=self.get_sw_if_index(interface),
-                      ip_address=ip_address, mac_address=mac_address)
+                      sw_if_index=self.get_sw_if_index(iface_key),
+                      ip_address=ip_address, mac_address=mac_address,
+                      vrf=vrf)
 
     def set_ip(self, interface, address, prefix_length):
         self.exec_vat('add_ip_address.vat',
                       sw_if_index=self.get_sw_if_index(interface),
                       address=address, prefix_length=prefix_length)
 
-    def set_route(self, network, prefix_length, gateway, interface):
+    def set_route(self, network, prefix_length, gateway, interface, count=1):
         Routing.vpp_route_add(self.node_info,
                               network=network, prefix_len=prefix_length,
-                              gateway=gateway, interface=interface)
+                              gateway=gateway, interface=interface, count=count)
 
     def unset_route(self, network, prefix_length, gateway, interface):
         self.exec_vat('del_route.vat', network=network,
@@ -255,7 +259,8 @@ class IPv4Setup(object):
                     continue
                 if node['type'] != NodeType.DUT:
                     continue
-                get_node(node).set_ip(port['if'], port['addr'], net['prefix'])
+                iface_key = topo.get_interface_by_name(node, port['if'])
+                get_node(node).set_ip(iface_key, port['addr'], net['prefix'])
                 interfaces.append((node, port['if']))
 
         return interfaces
@@ -263,18 +268,19 @@ class IPv4Setup(object):
     @staticmethod
     @keyword('Get IPv4 address of node "${node}" interface "${port}" '
              'from "${nodes_addr}"')
-    def get_ip_addr(node, interface, nodes_addr):
+    def get_ip_addr(node, iface_key, nodes_addr):
         """Return IPv4 address of the node port.
 
         :param node: Node in the topology.
-        :param interface: Interface name of the node.
+        :param iface_key: Interface key of the node.
         :param nodes_addr: Nodes IPv4 addresses.
         :type node: dict
-        :type interface: str
+        :type iface_key: str
         :type nodes_addr: dict
         :return: IPv4 address.
         :rtype: str
         """
+        interface = Topology.get_interface_name(node, iface_key)
         for net in nodes_addr.values():
             for port in net['ports'].values():
                 host = port.get('node')
@@ -305,12 +311,27 @@ class IPv4Setup(object):
         for node in nodes_info.values():
             if node['type'] == NodeType.TG:
                 continue
-            for interface, interface_data in node['interfaces'].iteritems():
-                interface_name = interface_data['name']
+            for iface_key in node['interfaces'].keys():
                 adj_node, adj_int = Topology.\
-                    get_adjacent_node_and_interface(nodes_info, node,
-                                                    interface_name)
-                ip_address = IPv4Setup.get_ip_addr(adj_node, adj_int['name'],
+                    get_adjacent_node_and_interface(nodes_info, node, iface_key)
+                ip_address = IPv4Setup.get_ip_addr(adj_node, adj_int,
                                                    nodes_addr)
-                mac_address = adj_int['mac_address']
-                get_node(node).set_arp(interface_name, ip_address, mac_address)
+                mac_address = Topology.get_interface_mac(adj_node, adj_int)
+                get_node(node).set_arp(iface_key, ip_address, mac_address)
+
+    @staticmethod
+    def add_arp_on_dut(node, iface_key, ip_address, mac_address, vrf=None):
+        """Set ARP cache entree on DUT node.
+
+        :param node: VPP Node in the topology.
+        :param iface_key: Interface key.
+        :param ip_address: IP address of the interface.
+        :param mac_address: MAC address of the interface.
+        :param vrf: VRF table ID (Optional).
+        :type node: dict
+        :type iface_key: str
+        :type ip_address: str
+        :type mac_address: str
+        :type vrf: int
+        """
+        get_node(node).set_arp(iface_key, ip_address, mac_address, vrf)