Exemple #1
0
    def verify_traffic(self,
                       sender_vm,
                       receiver_vm,
                       proto,
                       sport,
                       dport,
                       count=None,
                       fip=None):
        # Create stream and profile
        if fip:
            stream = Stream(sport=sport,
                            dport=dport,
                            proto=proto,
                            src=sender_vm.vm_ip,
                            dst=fip)
        else:
            stream = Stream(sport=sport,
                            dport=dport,
                            proto=proto,
                            src=sender_vm.vm_ip,
                            dst=receiver_vm.vm_ip)
        profile_kwargs = {'stream': stream}
        if fip:
            profile_kwargs.update({'listener': receiver_vm.vm_ip})
        if count:
            profile_kwargs.update({'count': count})
            profile = StandardProfile(**profile_kwargs)
        else:
            profile = ContinuousProfile(**profile_kwargs)

        # Set VM credentials
        send_node = Host(
            sender_vm.vm_node_ip,
            self.inputs.host_data[sender_vm.vm_node_ip]['username'],
            self.inputs.host_data[sender_vm.vm_node_ip]['password'])
        recv_node = Host(
            receiver_vm.vm_node_ip,
            self.inputs.host_data[receiver_vm.vm_node_ip]['username'],
            self.inputs.host_data[receiver_vm.vm_node_ip]['password'])
        send_host = Host(sender_vm.local_ip, sender_vm.vm_username,
                         sender_vm.vm_password)
        recv_host = Host(receiver_vm.local_ip, receiver_vm.vm_username,
                         receiver_vm.vm_password)

        # Create send, receive helpers
        sender = Sender("send%s" % proto, profile, send_node, send_host,
                        self.inputs.logger)
        receiver = Receiver("recv%s" % proto, profile, recv_node, recv_host,
                            self.inputs.logger)

        # start traffic
        receiver.start()
        sender.start()
        sleep(5)

        # stop traffic
        sender.stop()
        receiver.stop()
        self.logger.debug("Sent: %s; Received: %s", sender.sent, receiver.recv)
        return (sender.sent, receiver.recv)
    def start_traffic(self,
                      src_vm,
                      dst_vm_list,
                      stream_list,
                      src_ip=None,
                      dst_ip=None):

        self.logger.info("-" * 80)
        self.logger.info('Starting Traffic from %s to %s' % (src_ip, dst_ip))
        self.logger.info("-" * 80)
        profile = {}
        sender = {}
        receiver = {}
        tx_vm_node_ip = self.inputs.host_data[self.nova_h.get_nova_host_of_vm(
            src_vm.vm_obj)]['host_ip']
        tx_local_host = Host(tx_vm_node_ip,
                             self.inputs.host_data[tx_vm_node_ip]['username'],
                             self.inputs.host_data[tx_vm_node_ip]['password'])
        send_host = Host(src_vm.local_ip, src_vm.vm_username,
                         src_vm.vm_password)
        rx_vm_node_ip = {}
        rx_local_host = {}
        recv_host = {}

        for dst_vm in dst_vm_list:
            rx_vm_node_ip[dst_vm] = self.inputs.host_data[
                self.nova_h.get_nova_host_of_vm(dst_vm.vm_obj)]['host_ip']
            rx_local_host[dst_vm] = Host(
                rx_vm_node_ip[dst_vm],
                self.inputs.host_data[rx_vm_node_ip[dst_vm]]['username'],
                self.inputs.host_data[rx_vm_node_ip[dst_vm]]['password'])
            recv_host[dst_vm] = Host(dst_vm.local_ip, dst_vm.vm_username,
                                     dst_vm.vm_password)
        count = 0
        for stream in stream_list:
            profile[stream] = {}
            sender[stream] = {}
            receiver[stream] = {}
            for dst_vm in dst_vm_list:
                count = count + 1
                x = datetime.now().microsecond
                send_filename = "sendudp_" + str(x) + "_" + "%s" % count
                recv_filename = "recvudp_" + str(x) + "_" + "%s" % count
                profile[stream][dst_vm] = ContinuousProfile(
                    stream=stream, listener=dst_vm.vm_ip, chksum=True)
                sender[stream][dst_vm] = Sender(send_filename,
                                                profile[stream][dst_vm],
                                                tx_local_host, send_host,
                                                self.inputs.logger)
                receiver[stream][dst_vm] = Receiver(recv_filename,
                                                    profile[stream][dst_vm],
                                                    rx_local_host[dst_vm],
                                                    recv_host[dst_vm],
                                                    self.inputs.logger)
                receiver[stream][dst_vm].start()
                sender[stream][dst_vm].start()
        return sender, receiver
Exemple #3
0
    def start_traffic_scapy(self, sender_vm, receiver_vm, proto,
				sport, dport, count=None, fip=None,
				payload=None, icmp_type=None, icmp_code=None,
				recvr=True):
        # Create stream and profile
        if fip:
            stream = Stream(
                protocol="ip", sport=sport, dport=dport, proto=proto, src=sender_vm.vm_ip,
                dst=fip,type=icmp_type,code=icmp_code)
        else:
            stream = Stream(
                protocol="ip", sport=sport, dport=dport, proto=proto, src=sender_vm.vm_ip,
                dst=receiver_vm.vm_ip,type=icmp_type,code=icmp_code)
        profile_kwargs = {'stream': stream}
        if fip:
            profile_kwargs.update({'listener': receiver_vm.vm_ip})
        if payload:
            profile_kwargs.update({'payload': payload})
        if count:
            profile_kwargs.update({'count': count})
            profile = StandardProfile(**profile_kwargs)
        else:
            profile = ContinuousProfile(**profile_kwargs)

        # Set VM credentials
        send_node = Host(sender_vm.vm_node_ip,
                         self.inputs.username, self.inputs.password)
        recv_node = Host(receiver_vm.vm_node_ip,
                         self.inputs.username, self.inputs.password)
        send_host = Host(sender_vm.local_ip,
                         sender_vm.vm_username, sender_vm.vm_password)
        recv_host = Host(receiver_vm.local_ip,
                         receiver_vm.vm_username, receiver_vm.vm_password)

        # Create send, receive helpers
        sender = Sender("send%s" %
                        proto, profile, send_node, send_host, self.inputs.logger)
        receiver = Receiver("recv%s" %
                            proto, profile, recv_node, recv_host, self.inputs.logger)

        # start traffic
        if recvr:
            receiver.start()
        sender.start()

        return (sender, receiver)
Exemple #4
0
    def ha_start(self):
        '''
        ha_start will spawn VM's and starts traffic from 
        VM - VM , VM - floating IP.
        '''
        self.vn1_name = 'vn1000'
        self.vn1_subnets = ['20.1.1.0/24']
        self.vn2_name = 'vn2000'
        self.vn2_subnets = ['50.1.1.0/24']
        self.fip_pool_name = self.inputs.fip_pool_name
        self.fvn_name = 'public-vn-200'
        self.fip_subnets = [self.inputs.fip_pool]
        self.vmlist = []
        self.vm_fixture = []
        self.vm_num = 2
        self.jdaf_ip = '6.6.6.1'
        self.public_ip = '8.8.8.8'
        self.mx_rt = self.inputs.mx_rt
        self.secgrp_name = 'default'
        self.sport = 39100
        self.dport = 39200
        self.proto_list = ['tcp', 'icmp']
        self.fip = ""
        self.count = ""
        self.sender = {}
        self.sender_fip = {}
        self.receiver = {}
        self.send_node = {}
        self.send_fip_node = {}
        self.recv_node = {}
        self.send_fip_host = {}
        self.recv_host = {}
        self.send_host = {}
        self.host_list = self.connections.nova_h.get_hosts()

        for i in range(0, self.vm_num):
            val = random.randint(1, 100000)
            self.vmlist.append("vm-test" + str(val))

        # ping gateway from VM's
        self.vn1_fixture = self.useFixture(
            VNFixture(project_name=self.inputs.project_name,
                      connections=self.connections,
                      vn_name=self.vn1_name,
                      inputs=self.inputs,
                      subnets=self.vn1_subnets,
                      router_asn=self.inputs.router_asn,
                      rt_number=self.mx_rt))
        self.vn2_fixture = self.useFixture(
            VNFixture(project_name=self.inputs.project_name,
                      connections=self.connections,
                      vn_name=self.vn2_name,
                      inputs=self.inputs,
                      subnets=self.vn2_subnets,
                      router_asn=self.inputs.router_asn,
                      enable_dhcp=False,
                      disable_gateway=True))
        #        self.fvn_fixture= self.useFixture(VNFixture(project_name= self.inputs.project_name, connections= self.connections,vn_name=self.fvn_name, inputs= self.inputs, subnets= self.fip_subnets,router_asn=self.inputs.router_asn, rt_number=self.mx_rt))
        #        self.fip_fixture = self.useFixture(FloatingIPFixture( project_name=self.inputs.project_name, inputs=self.inputs, connections=self.connections, pool_name=self.fip_pool_name, vn_id=self.fvn_fixture.vn_id))
        assert self.vn1_fixture.verify_on_setup()
        assert self.vn2_fixture.verify_on_setup()
        #        assert self.fvn_fixture.verify_on_setup()
        #        assert self.fip_fixture.verify_on_setup()
        host_cnt = len(self.host_list)
        for i in range(0, self.vm_num):
            node_indx = (i % host_cnt)
            self.vm_fixture.append(
                self.useFixture(
                    VMFixture(
                        project_name=self.inputs.project_name,
                        connections=self.connections,
                        vn_objs=[self.vn1_fixture.obj, self.vn2_fixture.obj],
                        vm_name=self.vmlist[i],
                        flavor='contrail_flavor_large',
                        image_name='ubuntu-traffic',
                        node_name=self.host_list[node_indx])))
#            self.vm_fixture.append(self.useFixture(VMFixture(project_name= self.inputs.project_name, connections= self.connections, vn_objs = [ self.vn1_fixture.obj ], vm_name= self.vmlist[i],flavor='contrail_flavor_large',image_name='ubuntu-traffic',node_name=self.host_list[node_indx])))
        for i in range(0, self.vm_num):
            assert self.vm_fixture[i].verify_on_setup()
        for i in range(0, self.vm_num):
            out1 = self.nova_h.wait_till_vm_is_up(self.vm_fixture[i].vm_obj)
            if out1 == False:
                return {
                    'result': out1,
                    'msg': "%s failed to come up" % self.vm_fixture[i].vm_name
                }
            else:
                sleep(10)
                self.logger.info('Will install Traffic package on %s' %
                                 self.vm_fixture[i].vm_name)
                self.vm_fixture[i].install_pkg("Traffic")
        '''
        self.fip_id = self.fip_fixture.create_and_assoc_fip(self.fvn_fixture.vn_id, self.vm_fixture[0].vm_id)
        self.addCleanup(self.fip_fixture.disassoc_and_delete_fip, self.fip_id)
        sleep(10)
        assert self.fip_fixture.verify_fip(self.fip_id, self.vm_fixture[0], self.fvn_fixture)
        routing_instance = self.fvn_fixture.ri_name
        '''
        #        for i in range(0,self.vm_num):
        #            self.vm_fixture[i].remove_security_group(secgrp='default')
        #       Traffic setup
        #Set VM credentials
        for proto in self.proto_list:
            self.send_node[proto] = []
            self.sender[proto] = []
            if self.fip == 'True':
                self.sender_fip[proto] = []
            self.receiver[proto] = []
            self.send_node[proto] = []
            self.recv_node[proto] = []
            self.send_host[proto] = []
            self.recv_host[proto] = []
            j = self.vm_num - 1
            for i in range(0, ((self.vm_num / 2))):
                if self.fip == 'True' and proto == 'icmp':
                    self.stream_fip = Stream(protocol="ip",
                                             sport=self.sport,
                                             dport=self.dport,
                                             proto=proto,
                                             src=self.vm_fixture[i].vm_ip,
                                             dst=self.public_ip)
                self.stream = Stream(protocol="ip",
                                     sport=self.sport,
                                     dport=self.dport,
                                     proto=proto,
                                     src=self.vm_fixture[i].vm_ip,
                                     dst=self.vm_fixture[j].vm_ip)
                profile_kwargs = {'stream': self.stream}
                profile = ContinuousProfile(**profile_kwargs)
                if self.fip == 'True' and proto == 'icmp':
                    profile_fip_kwargs = {'stream': self.stream_fip}
                    profile_fip = ContinuousProfile(**profile_fip_kwargs)
                self.send_node[proto].append(
                    Host(self.vm_fixture[i].vm_node_ip, self.inputs.username,
                         self.inputs.password))
                self.recv_node[proto].append(
                    Host(self.vm_fixture[j].vm_node_ip, self.inputs.username,
                         self.inputs.password))
                self.send_host[proto].append(
                    Host(self.vm_fixture[i].local_ip,
                         self.vm_fixture[i].vm_username,
                         self.vm_fixture[i].vm_password))
                self.recv_host[proto].append(
                    Host(self.vm_fixture[j].local_ip,
                         self.vm_fixture[j].vm_username,
                         self.vm_fixture[j].vm_password))
                #   Create send, receive helpers
                self.sender[proto].append(
                    Sender("send%s" % proto, profile, self.send_node[proto][i],
                           self.send_host[proto][i], self.inputs.logger))
                if self.fip == 'True' and proto == 'icmp':
                    self.sender_fip[proto].append(
                        Sender("sendfip%s" % proto, profile_fip,
                               self.send_node[proto][i],
                               self.send_host[proto][i], self.inputs.logger))
                self.receiver[proto].append(
                    Receiver("recv%s" % proto, profile,
                             self.recv_node[proto][i],
                             self.recv_host[proto][i], self.inputs.logger))
                #   start traffic
                self.receiver[proto][i].start()
                self.sender[proto][i].start()
                if self.fip == 'True' and proto == 'icmp':
                    self.sender_fip[proto][i].start()
                sleep(10)
                j = j - 1

        return True
Exemple #5
0
    def test_traffic_connections_while_control_nodes_go_down(self):
        """Tests related to connections and traffic while switching from normal mode to headless and back
           i.e. control nodes go down and come online."""

        if len(self.inputs.compute_ips) < 2:
            raise unittest.SkipTest("This test needs atleast 2 compute nodes.")
        else:
            self.logger.info(
                "Required resources are in place to run the test.")

        result = True
        topology_class_name = None

        self.compute_fixture_dict = {}
        for each_compute in self.inputs.compute_ips:
            self.compute_fixture_dict[each_compute] = self.useFixture(
                ComputeNodeFixture(connections=self.connections,
                                   node_ip=each_compute,
                                   username=self.inputs.username,
                                   password=self.inputs.password))
            mode = self.compute_fixture_dict[
                each_compute].get_agent_headless_mode()
            if mode is False:
                self.compute_fixture_dict[
                    each_compute].set_agent_headless_mode()
        #
        # Get config for test from topology
        result = True
        msg = []
        if not topology_class_name:
            topology_class_name = test_headless_vrouter_topo.sdn_headless_vrouter_topo

        self.logger.info("Scenario for the test used is: %s" %
                         (topology_class_name))
        #
        # Create a list of compute node IP's and pass it to topo if you want to pin
        # a vm to a particular node
        topo_obj = topology_class_name(
            compute_node_list=self.inputs.compute_ips)
        #
        # Test setup: Configure policy, VN, & VM
        # return {'result':result, 'msg': err_msg, 'data': [self.topo, config_topo]}
        # Returned topo is of following format:
        # config_topo= {'policy': policy_fixt, 'vn': vn_fixture, 'vm': vm_fixture}
        topo = {}
        topo_objs = {}
        config_topo = {}
        setup_obj = self.useFixture(
            sdnTopoSetupFixture(self.connections, topo_obj))
        out = setup_obj.sdn_topo_setup()
        self.assertEqual(out['result'], True, out['msg'])
        if out['result']:
            topo_objs, config_topo, vm_fip_info = out['data']

        # Start Test
        proj = config_topo.keys()
        vms = config_topo[proj[0]]['vm'].keys()
        src_vm = config_topo[proj[0]]['vm'][vms[0]]
        dest_vm = config_topo[proj[0]]['vm'][vms[1]]
        flow_cache_timeout = 180

        # Setup Traffic.
        stream = Stream(protocol="ip",
                        proto="icmp",
                        src=src_vm.vm_ip,
                        dst=dest_vm.vm_ip)
        profile = ContinuousProfile(stream=stream, count=0, capfilter="icmp")

        tx_vm_node_ip = src_vm.vm_node_ip
        rx_vm_node_ip = dest_vm.vm_node_ip

        tx_local_host = Host(tx_vm_node_ip, self.inputs.username,
                             self.inputs.password)
        rx_local_host = Host(rx_vm_node_ip, self.inputs.username,
                             self.inputs.password)

        send_host = Host(src_vm.local_ip, src_vm.vm_username,
                         src_vm.vm_password)
        recv_host = Host(dest_vm.local_ip, dest_vm.vm_username,
                         dest_vm.vm_password)

        sender = Sender("icmp", profile, tx_local_host, send_host,
                        self.inputs.logger)
        receiver = Receiver("icmp", profile, rx_local_host, recv_host,
                            self.inputs.logger)

        receiver.start()
        sender.start()
        self.logger.info("Waiting for 5 sec for traffic to be setup ...")
        time.sleep(5)

        flow_index_list = headless_vr_utils.get_flow_index_list(
            self, src_vm, dest_vm)

        headless_vr_utils.stop_all_control_services(self)
        self.addCleanup(self.inputs.start_service,
                        'contrail-control',
                        self.inputs.bgp_ips,
                        container='control')

        headless_vr_utils.check_through_tcpdump(self, dest_vm, src_vm)

        flow_index_list2 = headless_vr_utils.get_flow_index_list(
            self, src_vm, dest_vm)

        if flow_index_list == flow_index_list2:
            self.logger.info("Flow indexes have not changed.")
        else:
            self.logger.error(
                "Flow indexes have changed. Test Failed, Exiting")
            return False

        # wait_for_flow_cache_timeout
        time.sleep(flow_cache_timeout)

        # verify_flow_is_not_recreated
        flow_index_list = headless_vr_utils.get_flow_index_list(
            self, src_vm, dest_vm)

        if flow_index_list == flow_index_list2:
            self.logger.info("Flow indexes have not changed.")
        else:
            self.logger.error(
                "Flow indexes have changed. Test Failed, Exiting")
            return False

        receiver.stop()
        sender.stop()

        # wait_for_flow_cache_timeout
        time.sleep(flow_cache_timeout + 5)

        # verify_flow_is_cleared
        flow_index_list = headless_vr_utils.get_flow_index_list(
            self, src_vm, dest_vm)
        if not len(flow_index_list):
            self.logger.info("No flows are present")
        else:
            self.logger.error("Flows are still present.")
            return False

        # start_ping
        receiver.start()
        sender.start()
        self.logger.info("Waiting for 5 sec for traffic to be setup ...")
        time.sleep(5)
        # verify_flow_is_recreated
        flow_index_list = headless_vr_utils.get_flow_index_list(
            self, src_vm, dest_vm)
        if (flow_index_list[0] and flow_index_list[1]):
            self.logger.info("Flows are recreated.")
        else:
            self.logger.error("Flows are still absent.")
            return False

        headless_vr_utils.start_all_control_services(self)

        headless_vr_utils.check_through_tcpdump(self, dest_vm, src_vm)

        # wait_for_flow_cache_timeout
        time.sleep(flow_cache_timeout + 5)

        flow_index_list2 = headless_vr_utils.get_flow_index_list(
            self, src_vm, dest_vm)

        if flow_index_list == flow_index_list2:
            self.logger.info("Flow indexes have not changed.")
        else:
            self.logger.error(
                "Flow indexes have changed. Test Failed, Exiting")
            return False

        receiver.stop()
        sender.stop()

        # wait_for_flow_cache_timeout
        time.sleep(flow_cache_timeout + 5)

        # verify_flow_is_cleared
        flow_index_list = headless_vr_utils.get_flow_index_list(
            self, src_vm, dest_vm)
        if not len(flow_index_list):
            self.logger.info("No flows are present")
        else:
            self.logger.error("Flows are still present.")
            return False

        # start_ping
        receiver.start()
        sender.start()
        self.logger.info("Waiting for 5 sec for traffic to be setup ...")
        time.sleep(5)

        # verify_flow_is_recreated
        flow_index_list = headless_vr_utils.get_flow_index_list(
            self, src_vm, dest_vm)
        if (flow_index_list[0] and flow_index_list[1]):
            self.logger.info("Flows are recreated.")
        else:
            self.logger.error("Flows are still absent.")
            return False

        receiver.stop()
        sender.stop()

        return True
Exemple #6
0
    def test_config_add_change_while_control_nodes_go_down(self):
        """Tests related to configuration add, change, and delete while switching from normal mode
           to headless and back i.e. control nodes go down and come online."""

        if len(self.inputs.compute_ips) < 2:
            raise unittest.SkipTest("This test needs atleast 2 compute nodes.")
        else:
            self.logger.info(
                "Required resources are in place to run the test.")

        result = True
        topology_class_name = None

        self.compute_fixture_dict = {}
        for each_compute in self.inputs.compute_ips:
            self.compute_fixture_dict[each_compute] = self.useFixture(
                ComputeNodeFixture(connections=self.connections,
                                   node_ip=each_compute,
                                   username=self.inputs.username,
                                   password=self.inputs.password))
            mode = self.compute_fixture_dict[
                each_compute].get_agent_headless_mode()
            if mode is False:
                self.compute_fixture_dict[
                    each_compute].set_agent_headless_mode()
        #
        # Get config for test from topology
        result = True
        msg = []
        if not topology_class_name:
            topology_class_name = test_headless_vrouter_topo.sdn_headless_vrouter_topo

        self.logger.info("Scenario for the test used is: %s" %
                         (topology_class_name))
        #
        # Create a list of compute node IP's and pass it to topo if you want to pin
        # a vm to a particular node
        topo_obj = topology_class_name(
            compute_node_list=self.inputs.compute_ips)
        #
        # Test setup: Configure policy, VN, & VM
        # return {'result':result, 'msg': err_msg, 'data': [self.topo, config_topo]}
        # Returned topo is of following format:
        # config_topo= {'policy': policy_fixt, 'vn': vn_fixture, 'vm': vm_fixture}
        topo = {}
        topo_objs = {}
        config_topo = {}
        setup_obj = self.useFixture(
            sdnTopoSetupFixture(self.connections, topo_obj))
        out = setup_obj.sdn_topo_setup()
        self.assertEqual(out['result'], True, out['msg'])
        if out['result']:
            topo_objs, config_topo, vm_fip_info = out['data']

        # Start Test
        proj = config_topo.keys()
        vms = config_topo[proj[0]]['vm'].keys()
        src_vm = config_topo[proj[0]]['vm'][vms[0]]
        dest_vm = config_topo[proj[0]]['vm'][vms[1]]
        flow_cache_timeout = 180

        # Setup Traffic.
        stream = Stream(protocol="ip",
                        proto="icmp",
                        src=src_vm.vm_ip,
                        dst=dest_vm.vm_ip)
        profile = ContinuousProfile(stream=stream, count=0, capfilter="icmp")

        tx_vm_node_ip = src_vm.vm_node_ip
        rx_vm_node_ip = dest_vm.vm_node_ip

        tx_local_host = Host(tx_vm_node_ip, self.inputs.username,
                             self.inputs.password)
        rx_local_host = Host(rx_vm_node_ip, self.inputs.username,
                             self.inputs.password)

        send_host = Host(src_vm.local_ip, src_vm.vm_username,
                         src_vm.vm_password)
        recv_host = Host(dest_vm.local_ip, dest_vm.vm_username,
                         dest_vm.vm_password)

        sender = Sender("icmp", profile, tx_local_host, send_host,
                        self.inputs.logger)
        receiver = Receiver("icmp", profile, rx_local_host, recv_host,
                            self.inputs.logger)

        receiver.start()
        sender.start()
        self.logger.info("Waiting for 5 sec for traffic to be setup ...")
        time.sleep(5)

        #self.start_ping(src_vm, dest_vm)

        flow_index_list = headless_vr_utils.get_flow_index_list(
            self, src_vm, dest_vm)

        headless_vr_utils.stop_all_control_services(self)
        self.addCleanup(self.inputs.start_service,
                        'contrail-control',
                        self.inputs.bgp_ips,
                        container='control')
        time.sleep(10)
        headless_vr_utils.check_through_tcpdump(self, dest_vm, src_vm)

        flow_index_list2 = headless_vr_utils.get_flow_index_list(
            self, src_vm, dest_vm)

        if set(flow_index_list) == set(flow_index_list2):
            self.logger.info("Flow indexes have not changed.")
        else:
            self.logger.error(
                "Flow indexes have changed. Test Failed, Exiting")
            return False

        receiver.stop()
        sender.stop()
        project1_instance = config_topo['project1']['project']['project1']
        project1_instance.get_project_connections()
        vnet2_instance = config_topo['project1']['vn']['vnet2']
        # add VM to existing VN
        VM22_fixture = self.useFixture(
            VMFixture(
                connections=project1_instance.project_connections['juniper'],
                vn_obj=vnet2_instance.obj,
                vm_name='VM22',
                project_name=project1_instance.project_name))

        # create new IPAM
        ipam3_obj = self.useFixture(
            IPAMFixture(project_obj=project1_instance, name='ipam3'))
        ipam4_obj = self.useFixture(
            IPAMFixture(project_obj=project1_instance, name='ipam4'))

        # create new VN
        VN3_fixture = self.useFixture(
            VNFixture(
                project_name=project1_instance.project_name,
                connections=project1_instance.project_connections['juniper'],
                vn_name='VN3',
                inputs=project1_instance.inputs,
                subnets=['10.3.1.0/24'],
                ipam_fq_name=ipam3_obj.fq_name))

        VN4_fixture = self.useFixture(
            VNFixture(
                project_name=project1_instance.project_name,
                connections=project1_instance.project_connections['juniper'],
                vn_name='VN4',
                inputs=project1_instance.inputs,
                subnets=['10.4.1.0/24'],
                ipam_fq_name=ipam4_obj.fq_name))

        # create policy
        policy_name = 'policy34'
        rules = []
        rules = [{
            'direction': '<>',
            'protocol': 'icmp',
            'dest_network': VN4_fixture.vn_fq_name,
            'source_network': VN3_fixture.vn_fq_name,
            'dst_ports': 'any',
            'simple_action': 'pass',
            'src_ports': 'any'
        }, {
            'direction': '<>',
            'protocol': 'icmp',
            'dest_network': VN3_fixture.vn_fq_name,
            'source_network': VN4_fixture.vn_fq_name,
            'dst_ports': 'any',
            'simple_action': 'pass',
            'src_ports': 'any'
        }]

        policy34_fixture = self.useFixture(
            PolicyFixture(
                policy_name=policy_name,
                rules_list=rules,
                inputs=project1_instance.inputs,
                connections=project1_instance.project_connections['juniper'],
                project_fixture=project1_instance))

        # create VN to policy mapping in a dict of policy list.
        vn_policys = {
            VN3_fixture.vn_name: [policy_name],
            VN4_fixture.vn_name: [policy_name]
        }

        # create a policy object list of policies to be attached to a vm
        policy_obj_dict = {}
        policy_obj_dict[VN3_fixture.vn_name] = [policy34_fixture.policy_obj]
        policy_obj_dict[VN4_fixture.vn_name] = [policy34_fixture.policy_obj]

        # vn fixture dictionary.
        vn_obj_dict = {}
        vn_obj_dict[VN3_fixture.vn_name] = VN3_fixture
        vn_obj_dict[VN4_fixture.vn_name] = VN4_fixture

        # attach policy to VN
        VN3_policy_fixture = self.useFixture(
            VN_Policy_Fixture(
                connections=project1_instance.project_connections['juniper'],
                vn_name=VN3_fixture.vn_name,
                policy_obj=policy_obj_dict,
                vn_obj=vn_obj_dict,
                vn_policys=vn_policys[VN3_fixture.vn_name],
                project_name=project1_instance.project_name))

        VN4_policy_fixture = self.useFixture(
            VN_Policy_Fixture(
                connections=project1_instance.project_connections['juniper'],
                vn_name=VN4_fixture.vn_name,
                policy_obj=policy_obj_dict,
                vn_obj=vn_obj_dict,
                vn_policys=vn_policys[VN4_fixture.vn_name],
                project_name=project1_instance.project_name))

        # add VM to new VN
        VM31_fixture = self.useFixture(
            VMFixture(
                connections=project1_instance.project_connections['juniper'],
                vn_obj=VN3_fixture.obj,
                vm_name='VM31',
                project_name=project1_instance.project_name))

        VM41_fixture = self.useFixture(
            VMFixture(
                connections=project1_instance.project_connections['juniper'],
                vn_obj=VN4_fixture.obj,
                vm_name='VM41',
                project_name=project1_instance.project_name))

        # verification routines.
        test_flag = 0
        if ((VN3_fixture.verify_vn_in_api_server())
                and (VN3_fixture.verify_vn_not_in_agent())
                and (VN3_fixture.verify_vn_policy_in_api_server()['result'])):
            self.logger.info(
                "Verification of VN3 PASSED while control nodes down.")
        else:
            self.logger.error(
                "Verification of VN3 FAILED while control nodes down.")
            test_flag = 1

        if ((VN4_fixture.verify_vn_in_api_server())
                and (VN4_fixture.verify_vn_not_in_agent())
                and (VN4_fixture.verify_vn_policy_in_api_server()['result'])):
            self.logger.info(
                "Verification of VN4 PASSED while control nodes down.")
        else:
            self.logger.error(
                "Verification of VN4 FAILED while control nodes down.")
            test_flag = 1

        if ((VM22_fixture.verify_vm_launched())
                and (VM22_fixture.verify_vm_in_api_server())):
            self.logger.info(
                "Verification of VM22 PASSED while control nodes down.")
        else:
            self.logger.error(
                "Verification of VM22 FAILED while control nodes down.")
            test_flag = 1

        if ((VM31_fixture.verify_vm_launched())
                and (VM31_fixture.verify_vm_in_api_server())):
            self.logger.info(
                "Verification of VM31 PASSED while control nodes down.")
        else:
            self.logger.error(
                "Verification of VM31 FAILED while control nodes down.")
            test_flag = 1

        if ((VM41_fixture.verify_vm_launched())
                and (VM41_fixture.verify_vm_in_api_server())):
            self.logger.info(
                "Verification of VM41 PASSED while control nodes down.")
        else:
            self.logger.error(
                "Verification of VM41 FAILED while control nodes down.")
            test_flag = 1

        # start all control services.
        headless_vr_utils.start_all_control_services(self)

        # if something went wrong in the controller down state bail out here.
        if test_flag == 1:
            self.logger.error(
                "Verifications and Test failed while the controllers were down in \
                               headless state of agent. Check earlier error logs"
            )
            return False

        # wait for 3 to 5 sec for configuration sync from control nodes to the
        # agents.
        time.sleep(5)

        # wait till VM's are up.
        VM22_fixture.wait_till_vm_is_up()
        VM31_fixture.wait_till_vm_is_up()
        VM41_fixture.wait_till_vm_is_up()

        # verify vm config gets downloaded to the agents.
        if ((VM22_fixture.verify_vm_in_agent())
                and (VM31_fixture.verify_vm_in_agent())
                and (VM41_fixture.verify_vm_in_agent())):
            self.logger.info("VM verification on the agent PASSED")
        else:
            self.logger.error("VM verification on the agent FAILED")
            return False

        # check ping success between the two VM's
        assert config_topo['project1']['vm']['VM11'].ping_with_certainty(
            VM22_fixture.vm_ip, expectation=True)
        assert VM31_fixture.ping_with_certainty(VM41_fixture.vm_ip,
                                                expectation=True)
        assert VM41_fixture.ping_with_certainty(VM31_fixture.vm_ip,
                                                expectation=True)

        # verification routines.
        if ((VN3_fixture.verify_on_setup()) and (VN4_fixture.verify_on_setup())
                and (VM22_fixture.verify_on_setup())
                and (VM31_fixture.verify_on_setup())
                and (VM41_fixture.verify_on_setup())):
            self.logger.info(
                "All verifications passed after controllers came up in headless agent mode"
            )
        else:
            self.logger.error(
                "Verifications FAILED after controllers came up in headless agent mode"
            )
            return False

        return True
    def start(self,
              sender_vm,
              receiver_vm,
              proto,
              sport,
              dport,
              pkt_count=None,
              fip=None,
              sender_vn_fqname=None,
              receiver_vn_fqname=None,
              af=None,
              interval=0):

        self.sender_vm = sender_vm
        self.receiver_vm = receiver_vm
        self.proto = proto
        self.sport = sport
        self.dport = dport
        self.inputs = sender_vm.inputs
        self.logger = self.inputs.logger
        self.pkt_count = pkt_count
        self.src_ip = sender_vm.get_vm_ips(vn_fq_name=sender_vn_fqname,
                                           af=af)[0]
        recv_ip = receiver_vm.get_vm_ips(vn_fq_name=receiver_vn_fqname,
                                         af=af)[0]
        self.dst_ip = self.recv_ip = recv_ip
        if fip:
            self.dst_ip = fip
        self.interval = interval

        stream = Stream(sport=self.sport,
                        dport=self.dport,
                        proto=self.proto,
                        src=self.src_ip,
                        dst=self.dst_ip,
                        inter=self.interval)
        profile_kwargs = {'stream': stream}
        if fip:
            profile_kwargs.update({'listener': self.recv_ip})
        if self.pkt_count:
            profile_kwargs.update({'count': self.pkt_count})
            profile = StandardProfile(**profile_kwargs)
        else:
            profile = ContinuousProfile(**profile_kwargs)

        # Set VM credentials
        send_node = Host(
            self.sender_vm.vm_node_ip, self.sender_vm.inputs.host_data[
                self.sender_vm.vm_node_ip]['username'],
            self.sender_vm.inputs.host_data[
                self.sender_vm.vm_node_ip]['password'])
        recv_node = Host(
            self.receiver_vm.vm_node_ip, self.sender_vm.inputs.host_data[
                self.receiver_vm.vm_node_ip]['username'],
            self.sender_vm.inputs.host_data[
                self.receiver_vm.vm_node_ip]['password'])
        send_host = Host(self.sender_vm.local_ip, self.sender_vm.vm_username,
                         self.sender_vm.vm_password)
        recv_host = Host(self.receiver_vm.local_ip,
                         self.receiver_vm.vm_username,
                         self.receiver_vm.vm_password)

        # Create send, receive helpers
        random = get_random_name()
        send_name = 'send' + self.proto + '_' + random
        recv_name = 'recv' + self.proto + '_' + random
        sender = Sender(send_name, profile, send_node, send_host, self.logger)
        receiver = Receiver(recv_name, profile, recv_node, recv_host,
                            self.logger)

        # start traffic
        receiver.start()
        sender.start()

        self.sender = sender
        self.receiver = receiver
        return True
    def startTraffic(
        self, name='stream', num_streams=1, start_port=9100, tx_vm_fixture=None,
        rx_vm_fixture=None, stream_proto='udp', vm_fip_info=None,
        packet_size=100, cfg_profile='ContinuousProfile', start_sport=8000,
        total_single_instance_streams=20, chksum=False, pps=100, fip=None,
        tx_vn_fixture=None, rx_vn_fixture=None, af=None):
        ''' Start traffic based on inputs given..
        Return {'status': True, 'msg': None} if traffic started successfully..else return {'status': False, 'msg': err_msg}..
        Details on inputs:
        name    : Stream identifier;    num_streams     : number of separate sendpkts instance streams [will take more memory]
        start_port  : Destination start port if num_streams is used
        tx_vm_fixture & rx_vm_fixture  : Needed for vm_ip and vm_mdata_ip [to access vm from compute]
        stream_proto    : TCP, UDP or ICMP; packet_size : if custom size if needed
        start_sport     : if ContinuousSportRange is used, only supports UDP, starting number for source port
        total_single_instance_streams   : if ContinuousSportRange is used, specify number of streams
        pps             :Number of packets to launch per sec
        ContinuousSportRange launches n streams @defined pps, with one instance of sendpkts..
        '''
        self.logger.info("startTraffic data: name- %s, stream_proto-%s, packet_size-%s, total_single_instance_streams-%s, chksum-%s, pps-%s"
                         % (name, stream_proto, packet_size, total_single_instance_streams, chksum, pps))
        status = True
        msg = None
        self.packet_size = packet_size
        self.chksum = chksum
        self.start_port = start_port
        self.start_sport = start_sport
        self.endport = start_sport + total_single_instance_streams
        self.total_single_instance_streams = total_single_instance_streams
        self.tx_vm_fixture = tx_vm_fixture
        self.rx_vm_fixture = rx_vm_fixture
        tx_vn_fq_name = tx_vn_fixture.get_vn_fq_name() if tx_vn_fixture else None
        rx_vn_fq_name = rx_vn_fixture.get_vn_fq_name() if rx_vn_fixture else None
        af = af if af is not None else self.inputs.get_af()
        self.stream_proto = stream_proto
        self.vm_fip_info = vm_fip_info
        self.traffic_fip = False
        if self.vm_fip_info == None:
            self.traffic_fip = False
        else:
            self.traffic_fip = True
        if not self.traffic_fip:
            self.tx_vm_node_ip = self.tx_vm_fixture.vm_node_ip
            self.rx_vm_node_ip = self.rx_vm_fixture.vm_node_ip
            self.tx_local_host = Host(
                self.tx_vm_node_ip,
                self.inputs.host_data[self.tx_vm_node_ip]['username'],
                self.inputs.host_data[self.tx_vm_node_ip]['password'])
            self.rx_local_host = Host(
                self.rx_vm_node_ip,
                self.inputs.host_data[self.rx_vm_node_ip]['username'],
                self.inputs.host_data[self.rx_vm_node_ip]['password'])
            self.send_host = Host(self.tx_vm_fixture.local_ip,
                                  self.tx_vm_fixture.vm_username, self.tx_vm_fixture.vm_password)
            self.recv_host = Host(self.rx_vm_fixture.local_ip,
                                  self.rx_vm_fixture.vm_username, self.rx_vm_fixture.vm_password)
        else:
            self.tx_vm_node_ip = None
            self.rx_vm_node_ip = None
            self.tx_local_host = Host(
                self.inputs.cfgm_ip,
                self.inputs.host_data[self.tx_vm_node_ip]['username'],
                self.inputs.host_data[self.tx_vm_node_ip]['password'])
            self.rx_local_host = Host(
                self.inputs.cfgm_ip,
                self.inputs.host_data[self.rx_vm_node_ip]['username'],
                self.inputs.host_data[self.rx_vm_node_ip]['password'])
            self.send_host = Host(self.vm_fip_info[self.tx_vm_fixture.vm_name])
            self.recv_host = Host(self.vm_fip_info[self.rx_vm_fixture.vm_name])
        self.sender = list()
        self.receiver = list()
        self.num_streams = 0

        if fip is None:
            self.dst_ips = list(); self.src_ips = list()
            if af == 'dual' or af == 'v4':
                self.src_ips.extend(self.tx_vm_fixture.get_vm_ips(
                                    vn_fq_name=tx_vn_fq_name, af='v4'))
                self.dst_ips.extend(self.rx_vm_fixture.get_vm_ips(
                                    vn_fq_name=rx_vn_fq_name, af='v4'))
            if af == 'dual' or af == 'v6':
                self.src_ips.extend(self.tx_vm_fixture.get_vm_ips(
                                    vn_fq_name=tx_vn_fq_name, af='v6'))
                self.dst_ips.extend(self.rx_vm_fixture.get_vm_ips(
                                    vn_fq_name=rx_vn_fq_name, af='v6'))
        else:
            self.dst_ips = [fip]
            self.src_ips = [self.tx_vm_fixture.vm_ip]
        if len(self.dst_ips) > len(self.src_ips):
            raise Exception('No of destination ips cant be greater than'
                            ' source ips, for multi stream case')

        for index in range(len(self.dst_ips)):
            name = name + '_dst' + str(index) + '_'
            for i in range(num_streams):
                self.name = name + self.stream_proto + str(i)
                self.dport = start_port + i
                m = "Send protocol %s traffic to port %s" % (
                    self.stream_proto, self.dport)
                if self.stream_proto == 'icmp':
                    m = "Send protocol %s traffic" % self.stream_proto
                self.logger.info(m)
                stream = Stream(proto=self.stream_proto,
                                src=self.src_ips[index],
                                dst=self.dst_ips[index],
                                dport=self.dport)
                if fip:
                   listener = self.rx_vm_fixture.vm_ip
                else:
                   listener = self.dst_ips[index]
                # stream profile...
                if cfg_profile == 'ContinuousSportRange':
                    profile = ContinuousSportRange(stream=stream,
                                                   startport=self.start_sport,
                                                   endport=self.endport,
                                                   listener=listener,
                                                   size=self.packet_size,
                                                   chksum=self.chksum, pps=pps)
                elif cfg_profile == 'ContinuousProfile':
                    profile = ContinuousProfile(stream=stream,
                                                listener=listener,
                                                size=self.packet_size,
                                                chksum=self.chksum)
                # sender profile...
                sender = Sender(self.name, profile, self.tx_local_host,
                                self.send_host, self.inputs.logger)
                receiver = Receiver(self.name, profile, self.rx_local_host,
                                    self.recv_host, self.inputs.logger)
                self.logger.info("tx vm - node %s, mdata_ip %s, vm_ip %s" %(
                                 self.tx_local_host.ip, self.send_host.ip,
                                 self.src_ips[index]))
                self.logger.info("rx vm - node %s, mdata_ip %s, vm_ip %s" %(
                                 self.rx_local_host.ip, self.recv_host.ip,
                                 self.dst_ips[index]))
                receiver.start()
                self.logger.info("Starting %s traffic from %s to %s" %(
                                  self.stream_proto, self.src_ips[index],
                                  self.dst_ips[index]))
                sender.start()
                retries = 10
                j = 0
                sender.sent = None
                while j < retries and sender.sent == None:
                    # wait before checking for stats as it takes time for file
                    # update with stats
                    time.sleep(5)
                    sender.poll()
                # end while
                if sender.sent == None:
                    msg = "send %s traffic failure from %s " % (
                        self.stream_proto, self.src_ips[index])
                    self.logger.info(
                        "traffic tx stats not available !!, details: %s" % msg)
                else:
                    self.logger.info(
                        "traffic running good, sent %s pkts so far.." %
                        sender.sent)
                self.sender.append(sender)
                self.receiver.append(receiver)
                self.num_streams += 1
        if msg != None:
            status = False
        return {'status': status, 'msg': msg}