Пример #1
0
 def test_traff_from_vm_to_allvms(self, vm_name, proto='all'):
     """
     Test Full Mesh Traffic from bw VMs' FIPs
     """
     dest_vm_fips = {}
     dest_vms = self.vm_list
     print 'VM List before Remove', self.vm_list
     dest_vms.remove(vm_name)
     print 'VM List After Remove', self.vm_list
     for vm in dest_vms:
         dest_vm_fips[vm] = self.vm_to_ip_ns[vm][0][1:3]
     print dest_vm_fips
     flattended_dest_vm_fips = [
         fip for x in dest_vm_fips.values() for fip in x
     ]
     print flattended_dest_vm_fips
     dhcp_ns_vm = self.vm_to_ip_ns[vm_name][1]
     vm_pvt_ip = self.vm_to_ip_ns[vm_name][0][0]
     gbppexptraff = gbpExpTraff(self.ntk_node, dhcp_ns_vm, vm_pvt_ip,
                                flattended_dest_vm_fips)
     # Run for all protocols irrespective of the contract type
     results = gbppexptraff.test_run(protocols=['icmp', 'tcp'],
                                     tcp_syn_only=1)
     # Restore the self.vm_list by appending the vm_name which was removed
     # earlier
     self.vm_list.append(vm_name)
     print 'VM List After Restoration', self.vm_list
     if results == {}:
         return 2
     else:
         return self.verify_traff(results, dest_vm_fips, proto)
    def test_traff_anyvm_to_extgw(self, vm_name, extgw, proto='all', jumbo=0):
        """
        Test Traffic from each VM to ExtGW
        """
        for vm in self.vm_list:
            #vm_to_ip_list = self.gbpnova.get_any_vm_property(vm)['networks'][0]
            vm_to_ip_list = self.gbpnova.get_any_vm_property(vm)[0]
            vm_to_ip_list = [ip.encode('ascii') for ip in vm_to_ip_list]
            src_vm_pvt_ip_subnet = re.search(
                '(\d+.\d+.\d+).\d+', vm_to_ip_list[0].encode('ascii'), re.I).group(1)
            src_vm_dhcp_ns = self.gbpcfg.get_netns(vm)
            #src_vm_dhcp_ns = self.gbpcfg.get_netns(
            #    self.ntk_node, src_vm_pvt_ip_subnet)
            self.vm_to_ip_ns[vm] = [vm_to_ip_list, src_vm_dhcp_ns]
        print 'VM-to-IP-NS == %s' % (self.vm_to_ip_ns)

        dhcp_ns_vm = self.vm_to_ip_ns[vm_name][1]
        vm_pvt_ip = self.vm_to_ip_ns[vm_name][0][0]
        print 'EXTERNAL GW IPs from TESTUITE == ', extgw
        gbppexptraff = gbpExpTraff(
            self.ntk_node, dhcp_ns_vm, vm_pvt_ip, extgw)
        # Run for all protocols irrespective of the contract type
        results = gbppexptraff.test_run(
            protocols=['icmp', 'tcp'], tcp_syn_only=1,jumbo=1)
        if results == {}:
           return 2
        else:
           return self.verify_traff(results, extgw, proto)
Пример #3
0
    def test_traff_anyvm_to_extgw(self, vm_name, extgw, proto='all', jumbo=0):
        """
        Test Traffic from each VM to ExtGW
        """
        for vm in self.vm_list:
            #vm_to_ip_list = self.gbpnova.get_any_vm_property(vm)['networks'][0]
            vm_to_ip_list = self.gbpnova.get_any_vm_property(vm)[0]
            vm_to_ip_list = [ip.encode('ascii') for ip in vm_to_ip_list]
            src_vm_pvt_ip_subnet = re.search('(\d+.\d+.\d+).\d+',
                                             vm_to_ip_list[0].encode('ascii'),
                                             re.I).group(1)
            src_vm_dhcp_ns = self.gbpcfg.get_netns(vm)
            #src_vm_dhcp_ns = self.gbpcfg.get_netns(
            #    self.ntk_node, src_vm_pvt_ip_subnet)
            self.vm_to_ip_ns[vm] = [vm_to_ip_list, src_vm_dhcp_ns]
        print 'VM-to-IP-NS == %s' % (self.vm_to_ip_ns)

        dhcp_ns_vm = self.vm_to_ip_ns[vm_name][1]
        vm_pvt_ip = self.vm_to_ip_ns[vm_name][0][0]
        print 'EXTERNAL GW IPs from TESTUITE == ', extgw
        gbppexptraff = gbpExpTraff(self.ntk_node, dhcp_ns_vm, vm_pvt_ip, extgw)
        # Run for all protocols irrespective of the contract type
        results = gbppexptraff.test_run(protocols=['icmp', 'tcp'],
                                        tcp_syn_only=1,
                                        jumbo=1)
        if results == {}:
            return 2
        else:
            return self.verify_traff(results, extgw, proto)
Пример #4
0
    def send_traff_for_aap(self):
	aap_tr = gbpExpTraff(COMPUTE1,self.dhcp_netns,\
			    self.vm_prop[self.vm1]['ip'],
			    self.vm_prop[self.vm1]['ip']
			    )
	if not aap_tr.aap_traff(self.vip):
	    return 0
	return 1
Пример #5
0
 def send_traff_for_aap(self):
     aap_tr = gbpExpTraff(COMPUTE1,self.dhcp_netns,\
           self.vm_prop[self.vm1]['ip'],
           self.vm_prop[self.vm1]['ip']
           )
     if not aap_tr.aap_traff(self.vip):
         return 0
     return 1
Пример #6
0
 def verify_traff(self):
     """
     Verifies the expected traffic result per testcase
     """
     # Incase of Diff PTG Diff L2P and DIff L3P all traffic is disallowed irrespective what Policy-Ruleset is applied
     # Hence verify_traff will check for all protocols including the
     # implicit ones
     if self.vm_loc == 'diff_host_same_leaf' or self.vm_loc == 'diff_host_diff_leaf':
         dest_ip = self.gbpcfg.get_vm_subnet('VM12', ret='ip')
         self._log.debug(
             'VM10-IP: %s, VM10-subnet: %s, Dest-IP: %s, NetNS: %s' %
             (self.vm10_ip, self.vm10_subn, dest_ip, self.dhcp_ns))
         gbppexptraff = gbpExpTraff(self.ntk_node, self.dhcp_ns,
                                    self.vm10_ip, dest_ip)
     if self.vm_loc == 'same_host':
         dest_ip = self.gbpcfg.get_vm_subnet('VM11', ret='ip')
         self._log.debug(
             'VM10-IP: %s, VM10-subnet: %s, Dest-IP: %s, NetNS: %s' %
             (self.vm10_ip, self.vm10_subn, dest_ip, self.dhcp_ns))
         gbppexptraff = gbpExpTraff(self.ntk_node, self.dhcp_ns,
                                    self.vm10_ip, dest_ip)
     results = gbppexptraff.test_run()
     self._log.info("Results from the Testcase == %s" % (results))
     if results == {} or results == 2:
         return 0
     failed = {}
     if type(dest_ip) is list:
         for ip in dest_ip:
             ip_failed = {
                 key: val
                 for key, val in results[ip].iteritems() if val == 1
             }
             if ip_failed:
                 failed[ip] = ip_failed
     else:
         failed = {
             key: val
             for key, val in results[dest_ip].iteritems() if val == 1
         }
     if len(failed) > 0:
         self._log.error('Following traffic_types %s = Failed' % (failed))
         return 0
     else:
         return 1
 def verify_traff(self):
     """
     Verifies the expected traffic result per testcase
     """
     # Incase of Same PTG all traffic is allowed irrespective what Policy-Ruleset is applied
     # Hence verify_traff will check for all protocols including the
     # implicit ones
     if self.vm_loc == 'diff_host_same_leaf' or self.vm_loc == 'diff_host_diff_leaf':
         dest_ip = self.gbpcfg.get_vm_subnet('VM3', ret='ip')
         self._log.debug("VM1-IP: %s, VM1-subnet: %s, Dest-IP: %s, NetNS: %s" %(self.vm1_ip, self.vm1_subn, dest_ip, self.dhcp_ns))
         gbppexptraff = gbpExpTraff(
             self.ntk_node, self.dhcp_ns, self.vm1_ip, dest_ip)
     if self.vm_loc == 'same_host':
         dest_ip = self.gbpcfg.get_vm_subnet('VM2', ret='ip')
         self._log.debug("VM1-IP: %s, VM1-subnet: %s, Dest-IP: %s, NetNS: %s" %(self.vm1_ip, self.vm1_subn, dest_ip, self.dhcp_ns))
         gbppexptraff = gbpExpTraff(
             self.ntk_node, self.dhcp_ns, self.vm1_ip, dest_ip)
     results = gbppexptraff.test_run()
     self._log.info('Results from the Testcase == %s' %(results))
     if results == 2:
         return 2
     if type(dest_ip) is list:
         failed = {}
         for ip in dest_ip:
             ip_failed = {key: val for key, val in results[
                 ip].iteritems() if val == 0}
             if ip_failed:
                 failed[ip] = ip_failed
     else:
         failed = {key: val for key, val in results[
             dest_ip].iteritems() if val == 0}
     if len(failed) > 0:
         self._log.error('Following traffic_types %s = Failed' % (failed))
         return 0
     else:
         return 1
Пример #8
0
 def test_traff_anyvm_to_extgw(self, vm_name, extgw, proto='all', jumbo=0):
     """
     Test Traffic from each VM to ExtGW
     """
     dhcp_ns_vm = self.vm_to_ip_ns[vm_name][1]
     vm_pvt_ip = self.vm_to_ip_ns[vm_name][0][0]
     print 'EXTERNAL GW IPs from TESTUITE == ', extgw
     gbppexptraff = gbpExpTraff(self.ntk_node, dhcp_ns_vm, vm_pvt_ip, extgw)
     # Run for all protocols irrespective of the contract type
     results = gbppexptraff.test_run(protocols=['icmp', 'tcp'],
                                     tcp_syn_only=1,
                                     jumbo=1)
     if results == {}:
         return 2
     else:
         return self.verify_traff(results, extgw, proto)
 def verify_traff(self, proto=['all']):
     """
     Verifies the expected traffic result per testcase
     """
     # Incase of Diff PTG Same L2 & L3P all traffic is dis-allowed by default unless Policy-Ruleset is applied
     # Hence verify_traff will check for all protocols including the
     # implicit ones
     if self.vm_loc == 'diff_host_same_leaf' or self.vm_loc == 'diff_host_diff_leaf':
         dest_ip = self.gbpcfg.get_vm_subnet('VM9', ret='ip')
         self._log.debug('VM7-IP: %s, VM7-subnet: %s, Dest-IP: %s, NetNS: %s' %(self.vm7_ip, self.vm7_subn, dest_ip, self.dhcp_ns))
         gbppexptraff = gbpExpTraff(
             self.ntk_node, self.dhcp_ns, self.vm7_ip, dest_ip)
     if self.vm_loc == 'same_host':
         dest_ip = self.gbpcfg.get_vm_subnet('VM8', ret='ip')
         self._log.debug('VM7-IP: %s, VM7-subnet: %s, Dest-IP: %s, NetNS: %s' %(self.vm7_ip, self.vm7_subn, dest_ip, self.dhcp_ns))
         gbppexptraff = gbpExpTraff(
             self.ntk_node, self.dhcp_ns, self.vm7_ip, dest_ip)
     results = gbppexptraff.test_run()
     self._log.info('Results from the Testcase == %s' %(results))
     if results == 2:
         return 2
     failed = {}
     # In 'all' proto is verified for PTGs with NO_PRS, PRS_NO_RULE,
     # REM_PRS, hence below val ==1, then Fail, because pkts were
     # expected to be dropped but they were NOT(hence the Test should
     # be marked FAIL.
     if proto[0] == 'all':
         if type(dest_ip) is list:
             failed = {}
             for ip in dest_ip:
                 ip_failed = {key: val for key, val in results[
                     ip].iteritems() if val == 1}
                 if ip_failed:
                     failed[ip] = ip_failed
         else:
             failed = {key: val for key, val in results[
                 dest_ip].iteritems() if val == 1}
         if len(failed) > 0:
             self._log.error('For All Protcol Following traffic_types %s = Failed' %(failed))
             return 0
         else:
             return 1
     else:
         implicit_allow = ['arp', 'dhcp', 'dns']
         allow_list = implicit_allow + proto
         if type(dest_ip) is list:
             failed = {}
             for ip in dest_ip:
                 ip_failed = {key: val for key, val in results[
                     ip].iteritems() if val == 0 and key in allow_list}
                 ip_failed.update({key: val for key, val in results[
                               ip].iteritems() if val == 1 and key not in allow_list})
                 if ip_failed:
                     failed[ip] = ip_failed
         else:
             failed = {key: val for key, val in results[
                 dest_ip].iteritems() if val == 0 and key in allow_list}
             failed.update({key: val for key, val in results[
                           dest_ip].iteritems() if val == 1 and key not in allow_list})
         if len(failed) > 0:
             self._log.error('Following traffic_types %s = Failed' %(failed))
             return 0
         else:
             return 1
 def verify_traff(self, proto=['all']):
     """
     Verifies the expected traffic result per testcase
     """
     # Incase of Diff PTG Same L2 & L3P all traffic is dis-allowed by default unless Policy-Ruleset is applied
     # Hence verify_traff will check for all protocols including the
     # implicit ones
     if self.vm_loc == 'diff_host_same_leaf' or self.vm_loc == 'diff_host_diff_leaf':
         dest_ip = self.gbpcfg.get_vm_subnet('VM6', ret='ip')
         self._log.debug(
             'VM4-IP: %s, VM4-subnet: %s, Dest-IP: %s, NetNS: %s' %
             (self.vm4_ip, self.vm4_subn, dest_ip, self.dhcp_ns))
         gbppexptraff = gbpExpTraff(self.ntk_node, self.dhcp_ns,
                                    self.vm4_ip, dest_ip)
     if self.vm_loc == 'same_host':
         dest_ip = self.gbpcfg.get_vm_subnet('VM5', ret='ip')
         self._log.debug(
             'VM4-IP: %s, VM4-subnet: %s, Dest-IP: %s, NetNS: %s' %
             (self.vm4_ip, self.vm4_subn, dest_ip, self.dhcp_ns))
         gbppexptraff = gbpExpTraff(self.ntk_node, self.dhcp_ns,
                                    self.vm4_ip, dest_ip)
     results = gbppexptraff.test_run()
     self._log.info('Results from the Testcase == %s' % (results))
     if results == 2:
         return 2
     failed = {}
     # In 'all' proto is verified for PTGs with NO_PRS, PRS_NO_RULE,
     # REM_PRS, hence below val ==1, then Fail, because pkts were
     # expected to be dropped but they were NOT(hence the Test should
     # be marked FAIL.
     if proto[0] == 'all':
         if type(dest_ip) is list:
             failed = {}
             for ip in dest_ip:
                 ip_failed = {
                     key: val
                     for key, val in results[ip].iteritems() if val == 1
                 }
                 if ip_failed:
                     failed[ip] = ip_failed
         else:
             failed = {
                 key: val
                 for key, val in results[dest_ip].iteritems() if val == 1
             }
         if len(failed) > 0:
             self._log.error(
                 'For All Protcol Following traffic_types %s = Failed' %
                 (failed))
             return 0
         else:
             return 1
     else:
         implicit_allow = ['arp', 'dhcp', 'dns']
         allow_list = implicit_allow + proto
         if type(dest_ip) is list:
             failed = {}
             for ip in dest_ip:
                 ip_failed = {
                     key: val
                     for key, val in results[ip].iteritems()
                     if val == 0 and key in allow_list
                 }
                 ip_failed.update({
                     key: val
                     for key, val in results[ip].iteritems()
                     if val == 1 and key not in allow_list
                 })
                 if ip_failed:
                     failed[ip] = ip_failed
         else:
             failed = {
                 key: val
                 for key, val in results[dest_ip].iteritems()
                 if val == 0 and key in allow_list
             }
             failed.update({
                 key: val
                 for key, val in results[dest_ip].iteritems()
                 if val == 1 and key not in allow_list
             })
         if len(failed) > 0:
             self._log.error('Following traffic_types %s = Failed' %
                             (failed))
             return 0
         else:
             return 1