1*** Settings ***
2Resource                ../lib/utils.robot
3Resource                ../lib/connection_client.robot
4Resource                ../lib/boot_utils.robot
5Library                 ../lib/gen_misc.py
6Library                 ../lib/utils.py
7Library                 ../lib/bmc_network_utils.py
8
9
10*** Keywords ***
11
12Get BMC IPv6 Info
13    [Documentation]  Get system IPv6 address and prefix length.
14
15    # Get system IP address and prefix length details using "ip addr"
16    # Sample Output of "ip addr":
17    # 1: eth0: <BROADCAST,MULTIAST> mtu 1500 qdisc mq state UP qlen 1000
18    #     link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
19    #     inet xx.xx.xx.xx/24 brd xx.xx.xx.xx scope global eth0
20    #     inet6 fe80::xxxx:xxxx:xxxx:xxxx/64 scope link
21    #     inet6 xxxx::xxxx:xxxx:xxxx:xxxx/64 scope global
22
23    ${cmd_output}  ${stderr}  ${rc}=  BMC Execute Command  /sbin/ip addr
24
25    # Get line having IPv6 address details.
26    ${lines}=  Get Lines Containing String  ${cmd_output}  inet6
27
28    # List IP address details.
29    @{ip_components}=  Split To Lines  ${lines}
30
31    @{ipv6_data}=  Create List
32
33    # Get all IP addresses and prefix lengths on system.
34    FOR  ${ip_component}  IN  @{ip_components}
35      @{if_info}=  Split String  ${ip_component}
36      ${ip_n_prefix}=  Get From List  ${if_info}  1
37      Append To List  ${ipv6_data}  ${ip_n_prefix}
38    END
39
40    [Return]  ${ipv6_data}
41
42
43Verify IPv6 On BMC
44    [Documentation]  Verify IPv6 on BMC.
45    [Arguments]  ${ipv6}
46
47    # Description of argument(s):
48    # ipv6  IPv6 address to be verified (e.g. "2001::1234:1234").
49
50    # Get IPv6 address details on BMC using IP command.
51    @{ip_data}=  Get BMC IPv6 Info
52    Should Contain Match  ${ip_data}  ${ipv6}/*
53    ...  msg=IPv6 address does not exist.
54
55
56Verify IPv6 Default Gateway On BMC
57    [Documentation]  Verify IPv6 default gateway on BMC.
58    [Arguments]  ${gateway_ip}=0:0:0:0:0:0:0:0
59
60    # Description of argument(s):
61    # gateway_ip  Gateway IPv6 address.
62
63    ${route_info}=  Get BMC IPv6 Route Info
64
65    # If gateway IP is empty it will not have route entry.
66
67    Run Keyword If  '${gateway_ip}' == '0:0:0:0:0:0:0:0'
68    ...      Pass Execution  Gateway IP is not configured.
69    ...  ELSE
70    ...      Should Contain  ${route_info}  ${gateway_ip}
71    ...      msg=Gateway IP address not matching
72
73
74Get BMC IPv6 Route Info
75    [Documentation]  Get IPv6 route info on BMC.
76
77    # Sample output of "ip -6 route":
78    # unreachable ::/96 dev lo metric 1024 error -113
79    # unreachable ::ffff:0.0.0.0/96 dev lo metric 1024 error -113
80    # 2xxx:xxxx:0:1::/64 dev eth0 proto kernel metric 256
81    # fe80::/64 dev eth1 proto kernel metric 256
82    # fe80::/64 dev eth0 proto kernel metric 256
83    # fe80::/64 dev eth2 proto kernel metric 256
84
85
86    ${cmd_output}  ${stderr}  ${rc}=  BMC Execute Command
87    ...  /sbin/ip -6 route
88
89    [Return]  ${cmd_output}
90