def test_ip_fragment_multi_sender(self): ''' Test IP fragments with multiple sender ''' vn1_fixture = self.vn1_fixture vm1_fixture = self.vm1_fixture vm2_fixture = self.vm2_fixture image = 'ubuntu-traffic' vm_fixtures = self.create_vms(vn_fixture=vn1_fixture, count=1, image_name=image) self.verify_vms(vm_fixtures) vm3_fixture = vm_fixtures[0] proto = 'icmp' vn_fq_name = vm3_fixture.vn_fq_name pkg = 'sender.py' path = os.getcwd() + '/' + PKG_DIR + '/' + pkg self.logger.info("copying %s to VM %s" % (pkg, vm1_fixture.vm_name)) vm1_fixture.copy_file_to_vm(path, VM_DIR) self.logger.info("copying %s to VM %s" % (pkg, vm2_fixture.vm_name)) vm2_fixture.copy_file_to_vm(path, VM_DIR) #start tcpdump on recvr VM filters = '\'(%s and (src %s or %s) and dst %s)\'' % (proto, vm1_fixture.vm_ip, vm2_fixture.vm_ip, vm3_fixture.vm_ip) session, pcap = start_tcpdump_for_vm_intf(self, vm3_fixture, vn_fq_name, filters=filters) #Start traffic from VM1 pkg_absolute_path = '%s/%s' % (VM_DIR, pkg) log_file = pkg_absolute_path + '-' + get_random_string() + '.log' cmd = 'chmod +x %s;%s %s %s -p %s 2>%s 1>%s' % ( pkg_absolute_path, pkg_absolute_path, vm3_fixture.vm_ip, vm1_fixture.vm_ip, proto, log_file, log_file) output_cmd_dict = vm1_fixture.run_cmd_on_vm(cmds=[cmd], as_sudo=True) self.logger.info(output_cmd_dict) #Start traffic from VM2 pkg_absolute_path = '%s/%s' % (VM_DIR, pkg) log_file = pkg_absolute_path + '-' + get_random_string() + '.log' cmd = 'chmod +x %s;%s %s %s -p %s 2>%s 1>%s' % ( pkg_absolute_path, pkg_absolute_path, vm3_fixture.vm_ip, vm2_fixture.vm_ip, proto, log_file, log_file) output_cmd_dict = vm2_fixture.run_cmd_on_vm(cmds=[cmd], as_sudo=True) self.logger.info(output_cmd_dict) #verify packet count and stop tcpdump assert verify_tcpdump_count(self, session, pcap, exp_count=8, grep_string=vm3_fixture.vm_ip ), "Could not get expected no. of fragments"
def setup_bms(self, interfaces=None): interfaces = interfaces or self.interfaces self.bms_created = True if len(interfaces) > 1: self._interface = self.create_bonding(interfaces) else: host_mac = interfaces[0]['host_mac'] self._interface = get_intf_name_from_mac(self.mgmt_ip, host_mac, username=self.username, password=self.password) self.logger.info('BMS interface: %s' % self._interface) self.run('ip link set dev %s up' % (self._interface)) if self.vlan_id: self.run('vconfig add %s %s' % (self._interface, self.vlan_id)) self.run('ip link set dev %s.%s up' % (self._interface, self.vlan_id)) pvlanintf = '%s.%s'%(self._interface, self.vlan_id) if self.vlan_id\ else self._interface self.run('ip link set dev %s up' % pvlanintf) self.mvlanintf = '%s-%s' % ( pvlanintf, get_random_string(2, chars=string.ascii_letters)) self.logger.info('BMS mvlanintf: %s' % self.mvlanintf) macaddr = 'address %s' % self.bms_mac if self.bms_mac else '' self.run('ip link add %s link %s %s type macvlan mode bridge' % (self.mvlanintf, pvlanintf, macaddr)) self.run('ip netns add %s' % self.namespace) self.run('ip link set netns %s %s' % (self.namespace, self.mvlanintf)) self.run_namespace('ip link set dev %s up' % self.mvlanintf)
def setup_bms(self, interfaces=None): interfaces = interfaces or self.interfaces self.bms_created = True if len(interfaces) > 1: self._interface = self.create_bonding(interfaces) else: host_mac = interfaces[0]['host_mac'] self._interface = get_intf_name_from_mac(self.mgmt_ip, host_mac, username=self.username, password=self.password) self.logger.info('BMS interface: %s' % self._interface) self.run('ip link set dev %s up'%(self._interface)) if self.vlan_id: # self.run('vconfig add %s %s'%(self._interface, self.vlan_id)) # Removing the dependency on vconfig self.run('ip link add link {ifc} name {ifc}.{vlan} type vlan id ' '{vlan}'.format (ifc=self._interface, vlan=self.vlan_id)) self.run('ip link set dev %s.%s up'%(self._interface, self.vlan_id)) pvlanintf = '%s.%s'%(self._interface, self.vlan_id) if self.vlan_id\ else self._interface self.run('ip link set dev %s up'%pvlanintf) mvlanintf = '%s-%s'%(pvlanintf, get_random_string(2, chars=string.ascii_letters)) # Truncate the interface name length to 15 char due to linux limitation self.mvlanintf = mvlanintf[-15:] self.logger.info('BMS mvlanintf: %s' % self.mvlanintf) macaddr = 'address %s'%self.bms_mac if self.bms_mac else '' self.run('ip link add %s link %s %s type macvlan mode bridge'%( self.mvlanintf, pvlanintf, macaddr)) self.run('ip netns add %s'%self.namespace) self.run('ip link set netns %s %s'%(self.namespace, self.mvlanintf)) self.run_namespace('ip link set dev %s up'%self.mvlanintf)
def setup_bms(self): self.bms_created = True if len(self.interfaces) > 1: self._interface = self.create_bonding() else: host_mac = self.interfaces[0]['host_mac'] self._interface = get_intf_name_from_mac(self.mgmt_ip, host_mac, username=self.username, password=self.password) self.logger.info('BMS interface: %s' % self._interface) if self.vlan_id: self.run('vconfig add %s %s' % (self._interface, self.vlan_id)) self.run('ip link set %s.%s up' % (self._interface, self.vlan_id)) pvlanintf = '%s.%s'%(self._interface, self.vlan_id) if self.vlan_id\ else self._interface self.run('ip link set dev %s up' % pvlanintf) self.mvlanintf = '%s-mv%s' % (pvlanintf, get_random_string(4)) self.logger.info('BMS mvlanintf: %s' % self.mvlanintf) macaddr = 'address %s' % self.bms_mac if self.bms_mac else '' self.run('ip link add %s link %s %s type macvlan mode bridge' % (self.mvlanintf, pvlanintf, macaddr)) self.run('ip netns add %s' % self.namespace) self.run('ip link set netns %s %s' % (self.namespace, self.mvlanintf)) self.run_namespace('ip link set dev %s up' % self.mvlanintf) if self.static_ip: addr = self.bms_ip + '/' + str(self.bms_ip_netmask) self.run_namespace('ip addr add %s dev %s' % (addr, self.mvlanintf)) if self.bms_gw_ip is not None: self.run_namespace('ip route add default via %s' % (self.bms_gw_ip))
def test_ip_fragment_in_order(self): ''' Test IP fragments sent in order ''' vn1_fixture = self.vn1_fixture vm1_fixture = self.vm1_fixture vm2_fixture = self.vm2_fixture proto = 'udp' vn_fq_name = vm2_fixture.vn_fq_name order = '0123' pkg = 'sender.py' path = os.getcwd() + '/' + PKG_DIR + '/' + pkg self.logger.info("copying %s to VM %s" % (pkg, vm1_fixture.vm_name)) vm1_fixture.copy_file_to_vm(path, VM_DIR) #Start tcpdump on recvr VM filters = '\'(%s and src host %s and dst host %s)\'' % (proto, vm1_fixture.vm_ip, vm2_fixture.vm_ip) session, pcap = start_tcpdump_for_vm_intf(self, vm2_fixture, vn_fq_name, filters = filters) #Start traffic pkg_absolute_path = '%s/%s' % (VM_DIR, pkg) log_file = pkg_absolute_path + '-' + get_random_string() + '.log' cmd1 = 'chmod +x %s;%s %s %s -p %s -o %s 2>%s 1>%s' % ( pkg_absolute_path, pkg_absolute_path, vm2_fixture.vm_ip, vm1_fixture.vm_ip, proto, order, log_file, log_file) output_cmd_dict = vm1_fixture.run_cmd_on_vm(cmds=[cmd1], as_sudo=True) self.logger.info(output_cmd_dict) #Verify packet count and stop tcpdump assert verify_tcpdump_count(self, session, pcap, exp_count=4, grep_string=vm1_fixture.vm_ip ), "Could not get expected no. of fragments"
def __init__(self, connections, name, is_ironic_node=False, **kwargs ): ''' Either VN or Port Fixture is mandatory ''' self.connections = connections self.inputs = connections.inputs self.logger = connections.logger self.name = name self.is_ironic_node = is_ironic_node bms_dict = self.inputs.bms_data[name] self.interfaces = kwargs.get('interfaces') or bms_dict['interfaces'] self.mgmt_ip = kwargs.get('mgmt_ip') or bms_dict['mgmt_ip'] # Host IP, optional self.username = kwargs.get('username') or bms_dict['username'] self.password = kwargs.get('password') or bms_dict['password'] self.namespace = get_random_name('ns') self.bms_ip = kwargs.get('bms_ip') # BMS VMI IP self.bms_ip6 = kwargs.get('bms_ip6') # BMS VMI IPv6 self.bms_ip_netmask = kwargs.get('bms_ip_netmask', None) self.bms_ip6_netmask = kwargs.get('bms_ip6_netmask', None) self.vn_fixture = kwargs.get('vn_fixture') self.bms_gw_ip = kwargs.get('bms_gw_ip', None) self.bms_gw_ip6 = kwargs.get('bms_gw_ip6', None) self.bms_mac = kwargs.get('bms_mac') # BMS VMI Mac self.static_ip = kwargs.get('static_ip', bool(not self.inputs.get_csn())) self.port_fixture = kwargs.get('port_fixture') self.fabric_fixture = kwargs.get('fabric_fixture') self.security_groups = kwargs.get('security_groups') or list() self.external_dhcp_server = kwargs.get('external_dhcp_server', False) self.vnc_h = connections.orch.vnc_h self.vlan_id = self.port_fixture.vlan_id if self.port_fixture else \ kwargs.get('vlan_id') or 0 self.port_profiles = kwargs.get('port_profiles') or list() self.tor_port_vlan_tag = kwargs.get('tor_port_vlan_tag') self._port_group_name = kwargs.get('port_group_name', None) self.ep_style = kwargs.get('ep_style', True) self._vpg_fixture = None self.bond_name = kwargs.get('bond_name') or 'bond%s'%get_random_string(2, chars=string.ascii_letters) self.bms_created = False self.bond_created = False self.mvlanintf = None self._interface = None self.ironic_node_obj = None self.ironic_node_id = None self.copied_files = dict()
def test_ip_fragment_out_of_order1(self): ''' Test IP fragments sent in below orders: 1. f1,f2,f0 2. f1,f0,f2 3. f0,f2,f1 4. f2,f1,f0 5. f2,f0,f1 ''' vn1_fixture = self.vn1_fixture vm1_fixture = self.vm1_fixture vm2_fixture = self.vm2_fixture proto = 'udp' vn_fq_name = vm2_fixture.vn_fq_name data = "Z"*30 fragsize = 16 pkg = 'sender.py' path = os.getcwd() + '/' + PKG_DIR + '/' + pkg self.logger.info("copying %s to VM %s" % (pkg, vm1_fixture.vm_name)) vm1_fixture.copy_file_to_vm(path, VM_DIR) order_list = ['120', '102', '021', '210', '201'] frags_count = int(math.ceil((8 + len(data))/float(fragsize)))#8 is udp header size filters = '\'(%s and src host %s and dst host %s)\'' % (proto, vm1_fixture.vm_ip, vm2_fixture.vm_ip) for order in order_list: #Start tcpdump on recvr VM session, pcap = start_tcpdump_for_vm_intf(self, vm2_fixture, vn_fq_name, filters = filters) #Start traffic pkg_absolute_path = '%s/%s' % (VM_DIR, pkg) log_file = pkg_absolute_path + '-' + get_random_string() + '.log' cmd1 = 'chmod +x %s;%s %s %s -p %s -o %s -d %s -f %s 2>%s 1>%s' % ( pkg_absolute_path, pkg_absolute_path, vm2_fixture.vm_ip, vm1_fixture.vm_ip, proto, order, data, fragsize, log_file, log_file) output_cmd_dict = vm1_fixture.run_cmd_on_vm(cmds=[cmd1], as_sudo=True) self.logger.info(output_cmd_dict) #Verify packet count and stop tcpdump assert verify_tcpdump_count(self, session, pcap, exp_count=frags_count, grep_string=vm1_fixture.vm_ip), ("Could not get expected no. of" " fragments for order %s" % (order))
def test_ip_fragment_out_of_order_inter_node(self): ''' Test IP fragments sent out of order and inter node ''' compute_hosts = self.orch.get_hosts() if len(compute_hosts) < 2: raise self.skipTest("Skipping test case,\ this test needs atleast 2 compute nodes") vn1_fixture = self.vn1_fixture image = 'ubuntu-traffic' vm1_fixture = self.create_vms(vn_fixture=vn1_fixture, count=1, node_name=compute_hosts[0], image_name=image)[0] vm2_fixture = self.create_vms(vn_fixture=vn1_fixture, count=1, node_name=compute_hosts[1], image_name=image)[0] self.verify_vms([vm1_fixture, vm2_fixture]) proto = 'udp' vn_fq_name = vm2_fixture.vn_fq_name pkg = 'sender.py' path = os.getcwd() + '/' + PKG_DIR + '/' + pkg self.logger.info("copying %s to VM %s" % (pkg, vm1_fixture.vm_name)) vm1_fixture.copy_file_to_vm(path, VM_DIR) #Start tcpdump on recvr VM filters = '\'(%s and src host %s and dst host %s)\'' % (proto, vm1_fixture.vm_ip, vm2_fixture.vm_ip) session, pcap = start_tcpdump_for_vm_intf(self, vm2_fixture, vn_fq_name, filters = filters) #Start traffic pkg_absolute_path = '%s/%s' % (VM_DIR, pkg) log_file = pkg_absolute_path + '-' + get_random_string() + '.log' cmd1 = 'chmod +x %s;%s %s %s -p %s 2>%s 1>%s' % ( pkg_absolute_path, pkg_absolute_path, vm2_fixture.vm_ip, vm1_fixture.vm_ip, proto, log_file, log_file) output_cmd_dict = vm1_fixture.run_cmd_on_vm(cmds=[cmd1], as_sudo=True) self.logger.info(output_cmd_dict) #Verify packet count and stop tcpdump assert verify_tcpdump_count(self, session, pcap, exp_count=4, grep_string=vm1_fixture.vm_ip ), "Could not get expected no. of fragments"
def test_ip_fragment_mixed(self): ''' Test with mixed fragments with different IP id ''' vn1_fixture = self.vn1_fixture vm1_fixture = self.vm1_fixture vm2_fixture = self.vm2_fixture proto = 'icmp' ip_id = randint(0, 65535) vn_fq_name = vm2_fixture.vn_fq_name pkg = 'mixed.py' path = os.getcwd() + '/' + PKG_DIR + '/' + pkg self.logger.info("copying %s to VM %s" % (pkg, vm1_fixture.vm_name)) vm1_fixture.copy_file_to_vm(path, VM_DIR) #Start tcpdump on recvr VM filters = '-v \'(ip[4:2]==%s and %s and src host %s and dst host %s)\'' % ( ip_id, proto, vm1_fixture.vm_ip, vm2_fixture.vm_ip) session1, pcap1 = start_tcpdump_for_vm_intf(self, vm2_fixture, vn_fq_name, filters = filters) filters = '-v \'(ip[4:2]==%s and %s and src host %s and dst host %s)\'' % ( ip_id+1, proto, vm1_fixture.vm_ip, vm2_fixture.vm_ip) session2, pcap2 = start_tcpdump_for_vm_intf(self, vm2_fixture, vn_fq_name, filters = filters) #Start traffic pkg_absolute_path = '%s/%s' % (VM_DIR, pkg) log_file = pkg_absolute_path + '-' + get_random_string() + '.log' cmd1 = 'chmod +x %s;%s %s %s -i %s 2>%s 1>%s' % ( pkg_absolute_path, pkg_absolute_path, vm2_fixture.vm_ip, vm1_fixture.vm_ip, ip_id, log_file, log_file) output_cmd_dict = vm1_fixture.run_cmd_on_vm(cmds=[cmd1], as_sudo=True) self.logger.info(output_cmd_dict) #Verify packet count and stop tcpdump assert verify_tcpdump_count(self, session1, pcap1, exp_count=4, grep_string=vm1_fixture.vm_ip ), "Could not get expected no. of fragments" assert verify_tcpdump_count(self, session2, pcap2, exp_count=4, grep_string=vm1_fixture.vm_ip ), "Could not get expected no. of fragments"
def get_custom_match_stackrc(rand=False): admin = ExampleUser.admin() user_name = get_random_string() if rand else 'test' admin.create_all(user_name=user_name, password='******', role='Member', project_name='test_project', domain_name='test_domain') role_dict = {'type': 'role', 'values': ['Member']} project_dict = {'type': 'project', 'values': ['test_project']} user_dict = {"type": 'user', "values": [user_name]} match = [role_dict, project_dict, user_dict] stackrc_dict = { 'user_name': user_name, 'password': '******', 'project_name': 'test_project', 'domain_name': 'test_domain', 'auth_url': admin.auth_url } return match, stackrc_dict
def setup_bms(self): self.bms_created = True if len(self.interfaces) > 1: interface = self.create_bonding() else: host_mac = self.interfaces[0]['host_mac'] interface = get_intf_name_from_mac(self.mgmt_ip, host_mac, username=self.username, password=self.password) if self.vlan_id: self.run('vconfig add %s %s' % (interface, self.vlan_id)) pvlanintf = '%s.%s'(interface, self.vlan_id) if self.vlan_id\ else interface self.mvlanintf = '%s-mv%s' % (pvlanintf, get_random_string(4)) macaddr = 'address %s' % self.bms_mac if self.bms_mac else '' self.run('ip link add %s link %s %s type macvlan mode bridge' % (self.mvlanintf, pvlanintf, macaddr)) self.run('ip netns add %s' % self.namespace) self.run('ip link set netns %s %s' % (self.namespace, self.mvlanintf)) self.run_namespace('ip link set dev %s up' % self.mvlanintf)
def test_ip_fragment_out_of_order_big_payload(self): ''' Test IP fragments sent out of order with large packets ''' vn1_fixture = self.vn1_fixture vm1_fixture = self.vm1_fixture vm2_fixture = self.vm2_fixture proto = 'udp' vn_fq_name = vm2_fixture.vn_fq_name size = 60000 fragsize = 1300 frags_count = int(math.ceil((8 + size)/float(fragsize)))#8 is udp header size order = 1023 pkg = 'sender.py' path = os.getcwd() + '/' + PKG_DIR + '/' + pkg self.logger.info("copying %s to VM %s" % (pkg, vm1_fixture.vm_name)) vm1_fixture.copy_file_to_vm(path, VM_DIR) #Start tcpdump on recvr VM filters = '\'(%s and src host %s and dst host %s)\'' % (proto, vm1_fixture.vm_ip, vm2_fixture.vm_ip) session, pcap = start_tcpdump_for_vm_intf(self, vm2_fixture, vn_fq_name, filters = filters) #Start traffic pkg_absolute_path = '%s/%s' % (VM_DIR, pkg) log_file = pkg_absolute_path + '-' + get_random_string() + '.log' cmd1 = 'chmod +x %s;%s %s %s -p %s -o %s -f %s -s %s 2>%s 1>%s' % ( pkg_absolute_path, pkg_absolute_path, vm2_fixture.vm_ip, vm1_fixture.vm_ip, proto, order, fragsize, size, log_file, log_file) output_cmd_dict = vm1_fixture.run_cmd_on_vm(cmds=[cmd1], as_sudo=True) self.logger.info(output_cmd_dict) #Verify packet count and stop tcpdump assert verify_tcpdump_count(self, session, pcap, exp_count=frags_count, grep_string=vm1_fixture.vm_ip ), "Could not get expected no. of fragments"
def test_ip_fragment_duplicate_frags(self): ''' Test with duplicate IP fragments ''' vn1_fixture = self.vn1_fixture vm1_fixture = self.vm1_fixture vm2_fixture = self.vm2_fixture proto = 'tcp' vn_fq_name = vm2_fixture.vn_fq_name fragsize = 20 order = 10 data = "Z"*20 duplicate_count = 10 frags_count = int(math.ceil((20 + len(data))/float(fragsize)))#20 is tcp header size pkg = 'sender.py' path = os.getcwd() + '/' + PKG_DIR + '/' + pkg self.logger.info("copying %s to VM %s" % (pkg, vm1_fixture.vm_name)) vm1_fixture.copy_file_to_vm(path, VM_DIR) #Start tcpdump on recvr VM filters = '\'(%s and src host %s and dst host %s)\'' % (proto, vm1_fixture.vm_ip, vm2_fixture.vm_ip) session, pcap = start_tcpdump_for_vm_intf(self, vm2_fixture, vn_fq_name, filters = filters) #Start traffic pkg_absolute_path = '%s/%s' % (VM_DIR, pkg) log_file = pkg_absolute_path + '-' + get_random_string() + '.log' cmd1 = 'chmod +x %s;%s %s %s -p %s -f %s -o %s -c %s 2>%s 1>%s' % ( pkg_absolute_path, pkg_absolute_path, vm2_fixture.vm_ip, vm1_fixture.vm_ip, proto, fragsize, order, duplicate_count, log_file, log_file) output_cmd_dict = vm1_fixture.run_cmd_on_vm(cmds=[cmd1], as_sudo=True) self.logger.info(output_cmd_dict) #Verify packet count and stop tcpdump assert verify_tcpdump_count(self, session, pcap, exp_count=frags_count, grep_string=vm1_fixture.vm_ip ), "Could not get expected no. of fragments" #Send duplicate fragment head followed by rest of the fragments #Receiver VM should receive all the fragments including all the duplicate heads order = '01' #Start tcpdump on recvr VM filters = '\'(%s and src host %s and dst host %s)\'' % (proto, vm1_fixture.vm_ip, vm2_fixture.vm_ip) session, pcap = start_tcpdump_for_vm_intf(self, vm2_fixture, vn_fq_name, filters = filters) #Start traffic pkg_absolute_path = '%s/%s' % (VM_DIR, pkg) log_file = pkg_absolute_path + '-' + get_random_string() + '.log' cmd1 = 'chmod +x %s;%s %s %s -p %s -f %s -o %s -c %s 2>%s 1>%s' % ( pkg_absolute_path, pkg_absolute_path, vm2_fixture.vm_ip, vm1_fixture.vm_ip, proto, fragsize, order, duplicate_count, log_file, log_file) output_cmd_dict = vm1_fixture.run_cmd_on_vm(cmds=[cmd1], as_sudo=True) self.logger.info(output_cmd_dict) #Verify packet count and stop tcpdump assert verify_tcpdump_count(self, session, pcap, exp_count=frags_count+duplicate_count, grep_string=vm1_fixture.vm_ip ), "Could not get expected no. of fragments"