aboutsummaryrefslogtreecommitdiffstats
path: root/app/discover/link_finders/find_links_for_oteps.py
blob: b5d166738b286a0143ce5787a27c175136f2fbbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
###############################################################################
# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems)   #
# and others                                                                  #
#                                                                             #
# All rights reserved. This program and the accompanying materials            #
# are made available under the terms of the Apache License, Version 2.0       #
# which accompanies this distribution, and is available at                    #
# http://www.apache.org/licenses/LICENSE-2.0                                  #
###############################################################################
from discover.link_finders.find_links import FindLinks


class FindLinksForOteps(FindLinks):
    def __init__(self):
        super().__init__()

    def add_links(self):
        self.log.info("adding link types: " +
                      "vedge-otep, otep-vconnector, otep-host_pnic")
        oteps = self.inv.find_items({
            "environment": self.get_env(),
            "type": "otep"
        })
        for otep in oteps:
            self.add_vedge_otep_link(otep)
            self.add_otep_vconnector_link(otep)
            self.add_otep_pnic_link(otep)

    def add_vedge_otep_link(self, otep):
        vedge = self.inv.get_by_id(self.get_env(), otep["parent_id"])
        source = vedge["_id"]
        source_id = vedge["id"]
        target = otep["_id"]
        target_id = otep["id"]
        link_type = "vedge-otep"
        link_name = vedge["name"] + "-otep"
        state = "up"  # TBD
        link_weight = 0  # TBD
        self.create_link(self.get_env(),
                         source, source_id, target, target_id,
                         link_type, link_name, state, link_weight,
                         host=vedge["host"])

    def add_otep_vconnector_link(self, otep):
        if "vconnector" not in otep:
            return
        vconnector = self.inv.find_items({
            "environment": self.get_env(),
            "type": "vconnector",
            "host": otep["host"],
            "name": otep["vconnector"]
        }, get_single=True)
        if not vconnector:
            return
        source = otep["_id"]
        source_id = otep["id"]
        target = vconnector["_id"]
        target_id = vconnector["id"]
        link_type = "otep-vconnector"
        link_name = otep["name"] + "-" + otep["vconnector"]
        state = "up"  # TBD
        link_weight = 0  # TBD
        self.create_link(self.get_env(),
                         source, source_id, target, target_id,
                         link_type, link_name, state, link_weight,
                         host=otep["host"])

    def add_otep_pnic_link(self, otep):
        pnic = self.inv.find_items({
            "environment": self.get_env(),
            "type": "host_pnic",
            "host": otep["host"],
            "IP Address": otep["ip_address"]
        }, get_single=True)
        if not pnic:
            return
        source = otep["_id"]
        source_id = otep["id"]
        target = pnic["_id"]
        target_id = pnic["id"]
        link_type = "otep-host_pnic"
        link_name = otep["host"] + "pnic" + pnic["name"]
        state = "up"  # TBD
        link_weight = 0  # TBD
        self.create_link(self.get_env(),
                         source, source_id, target, target_id,
                         link_type, link_name, state, link_weight,
                         host=otep["host"])
lass="n">join(trex_path, "scripts/ko/src/") self.ssh_helper.execute(self.MAKE_INSTALL.format(ko_src)) def start(self, ports=None, *args, **kwargs): cmd = "sudo fuser -n tcp {0.SYNC_PORT} {0.ASYNC_PORT} -k > /dev/null 2>&1" self.ssh_helper.execute(cmd.format(self)) self.ssh_helper.execute("sudo pkill -9 rex > /dev/null 2>&1") # We MUST default to 1 because TRex won't work on single-queue devices with # more than one core per port # We really should be trying to find the number of queues in the driver, # but there doesn't seem to be a way to do this # TRex Error: the number of cores should be 1 when the driver # support only one tx queue and one rx queue. Please use -c 1 threads_per_port = try_int(self.scenario_helper.options.get("queues_per_port"), 1) trex_path = self.ssh_helper.join_bin_path("trex", "scripts") path = get_nsb_option("trex_path", trex_path) cmd = "./t-rex-64 --no-scapy-server -i -c {} --cfg '{}'".format(threads_per_port, self.CONF_FILE) if self.scenario_helper.options.get("trex_server_debug"): # if there are errors we want to see them redir = "" else: redir = ">/dev/null" # we have to sudo cd because the path might be owned by root trex_cmd = """sudo bash -c "cd '{}' ; {}" {}""".format(path, cmd, redir) LOG.debug(trex_cmd) self.ssh_helper.execute(trex_cmd) def terminate(self): super(TrexResourceHelper, self).terminate() cmd = "sudo fuser -n tcp %s %s -k > /dev/null 2>&1" self.ssh_helper.execute(cmd % (self.SYNC_PORT, self.ASYNC_PORT)) class TrexTrafficGen(SampleVNFTrafficGen): """ This class handles mapping traffic profile and generating traffic for given testcase """ APP_NAME = 'TRex' def __init__(self, name, vnfd, setup_env_helper_type=None, resource_helper_type=None): if resource_helper_type is None: resource_helper_type = TrexResourceHelper if setup_env_helper_type is None: setup_env_helper_type = TrexDpdkVnfSetupEnvHelper super(TrexTrafficGen, self).__init__(name, vnfd, setup_env_helper_type, resource_helper_type) def _check_status(self): return self.resource_helper.check_status() def _start_server(self): super(TrexTrafficGen, self)._start_server() self.resource_helper.start() def scale(self, flavor=""): pass def listen_traffic(self, traffic_profile): pass def terminate(self): self.resource_helper.terminate()