2 # Module with common functions that should be used by the test cases.
4 # The module provides a set of tools for setup the test environment
6 from scapy.layers.l2 import Ether, ARP
7 from scapy.layers.inet6 import IPv6, ICMPv6ND_NS, ICMPv6NDOptSrcLLAddr
12 # Test cases that want to use methods defined in Util class should
15 # class Example(Util, VppTestCase):
19 ## Class method to send ARP Request for each VPP IPv4 address in
20 # order to determine VPP interface MAC address to IPv4 bindings.
22 # Resolved MAC address is saved to the VPP_MACS dictionary with interface
23 # index as a key. ARP Request is sent from MAC in MY_MACS dictionary with
24 # interface index as a key.
25 # @param cls The class pointer.
26 # @param args List variable to store indices of VPP interfaces.
28 def resolve_arp(cls, args):
31 cls.log("Sending ARP request for %s on port %u" % (ip, i))
32 arp_req = (Ether(dst="ff:ff:ff:ff:ff:ff", src=cls.MY_MACS[i]) /
33 ARP(op=ARP.who_has, pdst=ip,
34 psrc=cls.MY_IP4S[i], hwsrc=cls.MY_MACS[i]))
35 cls.pg_add_stream(i, arp_req)
36 cls.pg_enable_capture([i])
38 cls.cli(2, "trace add pg-input 1")
40 arp_reply = cls.pg_get_capture(i)[0]
41 if arp_reply[ARP].op == ARP.is_at:
42 cls.log("VPP pg%u MAC address is %s " % (i, arp_reply[ARP].hwsrc))
43 cls.VPP_MACS[i] = arp_reply[ARP].hwsrc
45 cls.log("No ARP received on port %u" % i)
46 cls.cli(2, "show trace")
48 # <TODO add description>
50 # <TODO add description>
52 # <TODO add description>
54 # <TODO add description>
56 ## Class method to send ND request for each VPP IPv6 address in
57 # order to determine VPP MAC address to IPv6 bindings.
59 # Resolved MAC address is saved to the VPP_MACS dictionary with interface
60 # index as a key. ND Request is sent from MAC in MY_MACS dictionary with
61 # interface index as a key.
62 # @param cls The class pointer.
63 # @param args List variable to store indices of VPP interfaces.
65 def resolve_icmpv6_nd(cls, args):
68 cls.log("Sending ICMPv6ND_NS request for %s on port %u" % (ip, i))
69 nd_req = (Ether(dst="ff:ff:ff:ff:ff:ff", src=cls.MY_MACS[i]) /
70 IPv6(src=cls.MY_IP6S[i], dst=ip) /
72 ICMPv6NDOptSrcLLAddr(lladdr=cls.MY_MACS[i]))
73 cls.pg_add_stream(i, nd_req)
74 cls.pg_enable_capture([i])
76 cls.cli(2, "trace add pg-input 1")
78 nd_reply = cls.pg_get_capture(i)[0]
79 icmpv6_na = nd_reply['ICMPv6 Neighbor Discovery - Neighbor Advertisement']
80 dst_ll_addr = icmpv6_na['ICMPv6 Neighbor Discovery Option - Destination Link-Layer Address']
81 cls.VPP_MACS[i] = dst_ll_addr.lladdr
83 # <TODO add description>
85 # <TODO add description>
87 # <TODO add description>
89 # <TODO add description>
91 # <TODO add description>
93 # <TODO add description>
95 ## Class method to configure IPv4 addresses on VPP interfaces.
97 # Set dictionary variables MY_IP4S and VPP_IP4S to IPv4 addresses
98 # calculated using interface VPP interface index as a parameter.
99 # /24 IPv4 prefix is used, with VPP interface address host part set
100 # to .1 and MY address set to .2.
101 # Used IPv4 prefix scheme: 172.16.{VPP-interface-index}.0/24.
102 # @param cls The class pointer.
103 # @param args List variable to store indices of VPP interfaces.
105 def config_ip4(cls, args):
107 cls.MY_IP4S[i] = "172.16.%u.2" % i
108 cls.VPP_IP4S[i] = "172.16.%u.1" % i
109 cls.api("sw_interface_add_del_address pg%u %s/24" % (i, cls.VPP_IP4S[i]))
110 cls.log("My IPv4 address is %s" % (cls.MY_IP4S[i]))
112 # Dictionary variable to store host IPv4 addresses connected to packet
113 # generator interfaces.
115 # Dictionary variable to store VPP IPv4 addresses of the packet
116 # generator interfaces.
118 ## Class method to configure IPv6 addresses on VPP interfaces.
120 # Set dictionary variables MY_IP6S and VPP_IP6S to IPv6 addresses
121 # calculated using interface VPP interface index as a parameter.
122 # /64 IPv6 prefix is used, with VPP interface address host part set
123 # to ::1 and MY address set to ::2.
124 # Used IPv6 prefix scheme: fd10:{VPP-interface-index}::0/64.
125 # @param cls The class pointer.
126 # @param args List variable to store indices of VPP interfaces.
128 def config_ip6(cls, args):
130 cls.MY_IP6S[i] = "fd10:%u::2" % i
131 cls.VPP_IP6S[i] = "fd10:%u::1" % i
132 cls.api("sw_interface_add_del_address pg%u %s/64" % (i, cls.VPP_IP6S[i]))
133 cls.log("My IPv6 address is %s" % (cls.MY_IP6S[i]))
135 # Dictionary variable to store host IPv6 addresses connected to packet
136 # generator interfaces.
138 # Dictionary variable to store VPP IPv6 addresses of the packet
139 # generator interfaces.