<reponame>preym17/csit
# Copyright (c) 2017 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:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Test data for Honeycomb routing test."""

from resources.libraries.python.topology import Topology


def get_variables(node, ip_version, out_interface):

    out_interface = Topology.convert_interface_reference(
        node, out_interface, "name")

    ip_version = ip_version.lower()
    variables = {}

    # base network settings
    ipv4_base = {
        "dut_to_tg_if1_ip": "172.16.31.10",
        "dut_to_tg_if2_ip": "192.168.3.11",
        "src_ip": "172.16.58.3",
        "dst_ip": "172.16.58.3",
        "dst_net": "192.168.3.11",
        "prefix_len": 24,
        "next_hop": "172.16.58.3",
        "next_hop1": "172.16.31.10",
        "next_hop2": "172.16.17.32",
        "next_hop_mac1": "00:11:22:33:44:55",
        "next_hop_mac2": "11:22:33:44:55:66"
    }

    ipv6_base = {
        "dut_to_tg_if1_ip": "fc00:db20:35b:7399::5",
        "dut_to_tg_if2_ip": "fc00:db20:35b:7399::5",
        "src_ip": "fc00:db20:35b:7399::5",
        "dst_ip": "fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b",
        "dst_net": "12::",
        "prefix_len": 64,
        "next_hop": "fd00:a516:7c1b:17cd:6d81:2137:bd2a:2c5b",
        "next_hop1": "fdf8:f53e:61e4::18",
        "next_hop2": "fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b",
        "next_hop_mac1": "00:11:22:33:44:55",
        "next_hop_mac2": "11:22:33:44:55:66"
    }

    if ip_version == "ipv4":
        variables.update(ipv4_base)
    elif ip_version == "ipv6":
        variables.update(ipv6_base)
    else:
        raise ValueError("IP version must be either IPv4 or IPv6.")

    # route configuration used in tests
    tables_cfg = {
        "table1": {
            "description": "single hop ipv4",
            "destination-prefix":
                "{0}/{1}".format(ipv4_base["dst_net"], ipv4_base["prefix_len"]),
            "next-hop": {
                "next-hop-address": ipv4_base["next_hop"],
                "outgoing-interface": out_interface
            },
            "vpp-ipv4-unicast-routing:vpp-ipv4-route": {}
        },
        "table2": {
            "description": "multi hop ipv4",
            "destination-prefix":
                "{0}/{1}".format(ipv4_base["dst_net"], ipv4_base["prefix_len"]),
            "next-hop":{
                "next-hop-list": {
                    "next-hop": [
                        {
                            "index": "1",
                            "next-hop-address": ipv4_base["next_hop1"],
                            "outgoing-interface": out_interface,
                            "weight": "1"
                        },
                        {
                            "index": "2",
                            "next-hop-address": ipv4_base["next_hop2"],
                            "outgoing-interface": out_interface,
                            "weight": "1"
                        }
                    ]
                }
            }
        },
        "table3": {
            "description": "blackhole ipv4",
            "destination-prefix":
                "{0}/{1}".format(ipv4_base["dst_net"], ipv4_base["prefix_len"]),
            "next-hop": {
                "special-next-hop-enum": "blackhole"
            }
        },
        "table4": {
            "description": "single hop ipv6",
            "destination-prefix":
                "{0}/{1}".format(ipv6_base["dst_net"], ipv6_base["prefix_len"]),
            "next-hop": {
                "next-hop-address": ipv6_base["next_hop"],
                "outgoing-interface": out_interface
            },
            "vpp-ipv6-unicast-routing:vpp-ipv6-route": {}
        },
        "table5": {
            "description": "multi hop ipv6",
            "destination-prefix":
                "{0}/{1}".format(ipv6_base["dst_net"], ipv6_base["prefix_len"]),
            "next-hop":{
                "next-hop-list": {
                    "next-hop": [
                        {
                            "index": "1",
                            "next-hop-address": ipv6_base["next_hop1"],
                            "outgoing-interface": out_interface,
                            "weight": "1"
                        },
                        {
                            "index": "2",
                            "next-hop-address": ipv6_base["next_hop2"],
                            "outgoing-interface": out_interface,
                            "weight": "1"
                        }
                    ]
                }
            }
        },
        "table6": {
            "description": "blackhole ipv6",
            "destination-prefix":
                "{0}/{1}".format(ipv6_base["dst_net"], ipv6_base["prefix_len"]),
            "next-hop":{
                "special-next-hop-enum": "blackhole"
            }
        }
    }

    # expected route operational data
    tables_oper = {
        "table1_oper": {
            "destination-prefix":
                "{0}/{1}".format(ipv4_base["dst_net"], ipv4_base["prefix_len"]),
            "next-hop": {
                "next-hop-address": ipv4_base["next_hop"],
                "outgoing-interface": out_interface
            }
        },
        "table2_oper": {
            "destination-prefix":
                "{0}/{1}".format(ipv4_base["dst_net"], ipv4_base["prefix_len"]),
            "next-hop": {
                "next-hop-list": {
                    "next-hop": [
                        {
                            "index": "2",
                            "next-hop-address": ipv4_base["next_hop2"],
                            "outgoing-interface": out_interface,
                            "vpp-ipv4-unicast-routing:weight": 1
                        },
                        {
                            "index": "1",
                            "next-hop-address": ipv4_base["next_hop1"],
                            "outgoing-interface": out_interface,
                            "vpp-ipv4-unicast-routing:weight": 1
                        }
                    ]
                }
            }
        },
        "table3_oper": {
            "destination-prefix":
                "{0}/{1}".format(ipv4_base["dst_net"], ipv4_base["prefix_len"]),
            "next-hop": {
                "special-next-hop-enum": "blackhole"
            }
        },
        "table4_oper": {
            "destination-prefix":
                "{0}/{1}".format(ipv6_base["dst_net"],
                                 ipv6_base["prefix_len"]),
            "next-hop": {
                "next-hop-address": ipv6_base["next_hop"],
                "outgoing-interface": out_interface
            }
        },
        "table5_oper": {
            "destination-prefix":
                "{0}/{1}".format(ipv6_base["dst_net"],
                                 ipv6_base["prefix_len"]),
            "next-hop": {
                "next-hop-list": {
                    "next-hop": [
                        {
                            "index": "2",
                            "next-hop-address": ipv6_base["next_hop2"],
                            "outgoing-interface": out_interface,
                            "vpp-ipv6-unicast-routing:weight": 1
                        },
                        {
                            "index": "1",
                            "next-hop-address": ipv6_base["next_hop1"],
                            "outgoing-interface": out_interface,
                            "vpp-ipv6-unicast-routing:weight": 1
                        }
                    ]
                }
            }
        },
        "table6_oper": {
            "destination-prefix":
                "{0}/{1}".format(ipv6_base["dst_net"],
                                 ipv6_base["prefix_len"]),
            "next-hop": {
                "special-next-hop-enum": "blackhole"
            }
        }
    }

    for item in tables_oper.values():
        if "next-hop-list" in item.keys():
            item["next-hop-list"]["next-hop"].sort()

    variables.update(tables_cfg)
    variables.update(tables_oper)
    return variables

# Copyright (c) 2017 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:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Test data for Honeycomb routing test."""

from resources.libraries.python.topology import Topology


def get_variables(node, ip_version, out_interface):

    out_interface = Topology.convert_interface_reference(
        node, out_interface, "name")

    ip_version = ip_version.lower()
    variables = {}

    # base network settings
    ipv4_base = {
        "dut_to_tg_if1_ip": "172.16.31.10",
        "dut_to_tg_if2_ip": "192.168.3.11",
        "src_ip": "172.16.58.3",
        "dst_ip": "172.16.58.3",
        "dst_net": "192.168.3.11",
        "prefix_len": 24,
        "next_hop": "172.16.58.3",
        "next_hop1": "172.16.31.10",
        "next_hop2": "172.16.17.32",
        "next_hop_mac1": "00:11:22:33:44:55",
        "next_hop_mac2": "11:22:33:44:55:66"
    }

    ipv6_base = {
        "dut_to_tg_if1_ip": "fc00:db20:35b:7399::5",
        "dut_to_tg_if2_ip": "fc00:db20:35b:7399::5",
        "src_ip": "fc00:db20:35b:7399::5",
        "dst_ip": "fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b",
        "dst_net": "12::",
        "prefix_len": 64,
        "next_hop": "fd00:a516:7c1b:17cd:6d81:2137:bd2a:2c5b",
        "next_hop1": "fdf8:f53e:61e4::18",
        "next_hop2": "fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b",
        "next_hop_mac1": "00:11:22:33:44:55",
        "next_hop_mac2": "11:22:33:44:55:66"
    }

    if ip_version == "ipv4":
        variables.update(ipv4_base)
    elif ip_version == "ipv6":
        variables.update(ipv6_base)
    else:
        raise ValueError("IP version must be either IPv4 or IPv6.")

    # route configuration used in tests
    tables_cfg = {
        "table1": {
            "description": "single hop ipv4",
            "destination-prefix":
                "{0}/{1}".format(ipv4_base["dst_net"], ipv4_base["prefix_len"]),
            "next-hop": {
                "next-hop-address": ipv4_base["next_hop"],
                "outgoing-interface": out_interface
            },
            "vpp-ipv4-unicast-routing:vpp-ipv4-route": {}
        },
        "table2": {
            "description": "multi hop ipv4",
            "destination-prefix":
                "{0}/{1}".format(ipv4_base["dst_net"], ipv4_base["prefix_len"]),
            "next-hop":{
                "next-hop-list": {
                    "next-hop": [
                        {
                            "index": "1",
                            "next-hop-address": ipv4_base["next_hop1"],
                            "outgoing-interface": out_interface,
                            "weight": "1"
                        },
                        {
                            "index": "2",
                            "next-hop-address": ipv4_base["next_hop2"],
                            "outgoing-interface": out_interface,
                            "weight": "1"
                        }
                    ]
                }
            }
        },
        "table3": {
            "description": "blackhole ipv4",
            "destination-prefix":
                "{0}/{1}".format(ipv4_base["dst_net"], ipv4_base["prefix_len"]),
            "next-hop": {
                "special-next-hop-enum": "blackhole"
            }
        },
        "table4": {
            "description": "single hop ipv6",
            "destination-prefix":
                "{0}/{1}".format(ipv6_base["dst_net"], ipv6_base["prefix_len"]),
            "next-hop": {
                "next-hop-address": ipv6_base["next_hop"],
                "outgoing-interface": out_interface
            },
            "vpp-ipv6-unicast-routing:vpp-ipv6-route": {}
        },
        "table5": {
            "description": "multi hop ipv6",
            "destination-prefix":
                "{0}/{1}".format(ipv6_base["dst_net"], ipv6_base["prefix_len"]),
            "next-hop":{
                "next-hop-list": {
                    "next-hop": [
                        {
                            "index": "1",
                            "next-hop-address": ipv6_base["next_hop1"],
                            "outgoing-interface": out_interface,
                            "weight": "1"
                        },
                        {
                            "index": "2",
                            "next-hop-address": ipv6_base["next_hop2"],
                            "outgoing-interface": out_interface,
                            "weight": "1"
                        }
                    ]
                }
            }
        },
        "table6": {
            "description": "blackhole ipv6",
            "destination-prefix":
                "{0}/{1}".format(ipv6_base["dst_net"], ipv6_base["prefix_len"]),
            "next-hop":{
                "special-next-hop-enum": "blackhole"
            }
        }
    }

    # expected route operational data
    tables_oper = {
        "table1_oper": {
            "destination-prefix":
                "{0}/{1}".format(ipv4_base["dst_net"], ipv4_base["prefix_len"]),
            "next-hop": {
                "next-hop-address": ipv4_base["next_hop"],
                "outgoing-interface": out_interface
            }
        },
        "table2_oper": {
            "destination-prefix":
                "{0}/{1}".format(ipv4_base["dst_net"], ipv4_base["prefix_len"]),
            "next-hop": {
                "next-hop-list": {
                    "next-hop": [
                        {
                            "index": "2",
                            "next-hop-address": ipv4_base["next_hop2"],
                            "outgoing-interface": out_interface,
                            "vpp-ipv4-unicast-routing:weight": 1
                        },
                        {
                            "index": "1",
                            "next-hop-address": ipv4_base["next_hop1"],
                            "outgoing-interface": out_interface,
                            "vpp-ipv4-unicast-routing:weight": 1
                        }
                    ]
                }
            }
        },
        "table3_oper": {
            "destination-prefix":
                "{0}/{1}".format(ipv4_base["dst_net"], ipv4_base["prefix_len"]),
            "next-hop": {
                "special-next-hop-enum": "blackhole"
            }
        },
        "table4_oper": {
            "destination-prefix":
                "{0}/{1}".format(ipv6_base["dst_net"],
                                 ipv6_base["prefix_len"]),
            "next-hop": {
                "next-hop-address": ipv6_base["next_hop"],
                "outgoing-interface": out_interface
            }
        },
        "table5_oper": {
            "destination-prefix":
                "{0}/{1}".format(ipv6_base["dst_net"],
                                 ipv6_base["prefix_len"]),
            "next-hop": {
                "next-hop-list": {
                    "next-hop": [
                        {
                            "index": "2",
                            "next-hop-address": ipv6_base["next_hop2"],
                            "outgoing-interface": out_interface,
                            "vpp-ipv6-unicast-routing:weight": 1
                        },
                        {
                            "index": "1",
                            "next-hop-address": ipv6_base["next_hop1"],
                            "outgoing-interface": out_interface,
                            "vpp-ipv6-unicast-routing:weight": 1
                        }
                    ]
                }
            }
        },
        "table6_oper": {
            "destination-prefix":
                "{0}/{1}".format(ipv6_base["dst_net"],
                                 ipv6_base["prefix_len"]),
            "next-hop": {
                "special-next-hop-enum": "blackhole"
            }
        }
    }

    for item in tables_oper.values():
        if "next-hop-list" in item.keys():
            item["next-hop-list"]["next-hop"].sort()

    variables.update(tables_cfg)
    variables.update(tables_oper)
    return variables
# Copyright (c) 2017 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: # #     http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. Test data for Honeycomb routing test. # base network settings # route configuration used in tests # expected route operational data