def format_source_dict(self): source_arp_dict = dict() source_arp_dict['checker_type'] = "ARP" source_arp_dict['packet_type'] = "ARP" source_arp_dict['vm_name'] = self.vm_name source_arp_dict['src_ip_address'] = self.source_port_dict['fixed_ips'][ 0]['ip_address'] source_arp_dict['src_mac_address'] = self.source_port_dict[ 'mac_address'] source_arp_dict['dest_ip_address'] = discovery.get_start_ip( self.network_id, self.neutron) source_arp_dict['host_id'] = self.source_host_id source_arp_dict['port_id'] = self.source_port_dict['id'] source_arp_dict['network_label'] = self.network_label source_arp_dict['network_type'] = self.network_type source_arp_dict['nic_filter'] = "" source_arp_dict['bridge_name'] = discovery.get_bridge_name( self.network_label, self.source_host_id, self.neutron) source_arp_dict['vif_names'] = [] tunnel_ip = discovery.get_tunnel_ip(self.source_host_id, self.neutron) source_arp_dict['tunnel_ip'] = tunnel_ip source_arp_dict['vxlan_filter'] = "src %s and udp port (4789)" % ( source_arp_dict['tunnel_ip']) source_arp_dict['tunnel_port'] = discovery.get_tunnel_port( self.source_host_id, source_arp_dict['tunnel_ip'], self.neutron) source_arp_dict['tag'] = "ARP SOURCE %s" % source_arp_dict['tunnel_ip'] return source_arp_dict
def format_source_dict(self): source_icmp_dict = dict() source_icmp_dict['checker_type'] = "ICMP" source_icmp_dict['packet_type'] = "ICMP" source_icmp_dict['vm_name'] = self.source_vm source_icmp_dict['same_host'] = self.same_host source_icmp_dict['src_ip_address'] = self.source_port_dict[ 'fixed_ips'][0]['ip_address'] source_icmp_dict['src_mac_address'] = self.source_port_dict[ 'mac_address'] source_icmp_dict['dest_ip_address'] = self.dest_port_dict['fixed_ips'][ 0]['ip_address'] source_icmp_dict['dest_mac_address'] = self.dest_port_dict[ 'mac_address'] source_icmp_dict['host_id'] = self.source_host_id source_icmp_dict['port_id'] = self.source_port_dict['id'] source_icmp_dict['network_label'] = self.network_label source_icmp_dict['network_type'] = self.network_type source_icmp_dict[ 'nic_filter'] = "icmp and ((src %s and dst %s) or (src %s and dst %s)) " % ( source_icmp_dict['src_ip_address'], source_icmp_dict['dest_ip_address'], source_icmp_dict['dest_ip_address'], source_icmp_dict['src_ip_address']) source_icmp_dict['bridge_name'] = discovery.get_bridge_name( self.network_label, self.source_host_id, self.neutron) source_icmp_dict['tag'] = "SOURCE" source_icmp_dict['vif_names'] = [] source_icmp_dict['path_type'] = "bidirectional" tunnel_ip = discovery.get_tunnel_ip(self.source_host_id, self.neutron) source_icmp_dict['tunnel_ip'] = tunnel_ip source_icmp_dict[ 'vxlan_filter'] = "(src %s or dst %s) and udp port (4789)" % ( source_icmp_dict['tunnel_ip'], source_icmp_dict['tunnel_ip']) if source_icmp_dict['network_type'] == "vxlan": source_icmp_dict['tunnel_port'] = discovery.get_tunnel_port( self.source_host_id, source_icmp_dict['tunnel_ip'], self.neutron) else: source_icmp_dict['tunnel_port'] = "None" vif_names = discovery.get_vif_names(source_icmp_dict['port_id']) for port_type, vif_name in vif_names.items(): vif = dict() vif[vif_name] = dict() vif[vif_name][ 'filter'] = "icmp and ((src %s and dst %s) or (src %s and dst %s)) " % ( source_icmp_dict['src_ip_address'], source_icmp_dict['dest_ip_address'], source_icmp_dict['dest_ip_address'], source_icmp_dict['src_ip_address']) vif[vif_name]['is_ns'] = "None" vif[vif_name]['port_type'] = port_type source_icmp_dict['vif_names'].append(vif) return source_icmp_dict
def format_vm_dict(self): bridge_name = discovery.get_bridge_name( self.network_label, self.source_port_dict['binding:host_id'], self.neutron) tunnel_ip = discovery.get_tunnel_ip( self.source_port_dict['binding:host_id'], self.neutron) vm_dict = dict() vm_dict['vm_name'] = self.vm_name vm_dict['checker_type'] = "DHCP" vm_dict['packet_type'] = "DHCP" vm_dict['src_mac_address'] = self.source_port_dict['mac_address'] vm_dict['port_id'] = self.source_port_dict['id'] vm_dict['device_id'] = self.source_port_dict['device_id'] vm_dict['host_id'] = self.source_port_dict['binding:host_id'] vm_dict['network_id'] = self.network_id vm_dict['network_type'] = self.network_type vm_dict['network_label'] = self.network_label vm_dict['ip_address'] = self.source_port_dict['fixed_ips'][0][ 'ip_address'] vm_dict[ 'nic_filter'] = "udp port (67 or 68) and ether host %s" % vm_dict[ 'src_mac_address'] vm_dict['vxlan_filter'] = "(src %s or dst %s) and udp port (4789)" % ( tunnel_ip, tunnel_ip) vm_dict['tunnel_ip'] = tunnel_ip vm_dict['tag'] = "VM SOURCE" vm_dict['bridge_name'] = bridge_name vm_dict["num_dhcp"] = len(self.dhcp_ports) vm_dict["local_dhcp"] = self.local_dhcp vm_dict['vif_names'] = self.vif_names if self.network_type == "vxlan": vm_dict['tunnel_port'] = discovery.get_tunnel_port( vm_dict['host_id'], tunnel_ip, self.neutron) else: vm_dict['tunnel_port'] = "None" return vm_dict
def init_remote_snat_process(self): local_listen_dict = dict() local_listen_dict['checker_type'] = "SNAT" local_listen_dict['packet_type'] = "ICMP" local_listen_dict['vm_name'] = self.vm_name local_listen_dict['src_ip_address'] = self.fixed_ip_address local_listen_dict['src_mac_address'] = self.source_port_dict[ 'mac_address'] local_listen_dict['dest_ip_address'] = self.dest_ip_address local_listen_dict['dest_mac_address'] = self.dest_mac_address local_listen_dict['host_id'] = self.source_host_id local_listen_dict['port_id'] = self.source_port_dict['id'] local_listen_dict['network_label'] = discovery.get_network_label( self.tenant_network_id, self.neutron) local_listen_dict['network_type'] = discovery.get_network_type( self.tenant_network_id, self.neutron) local_listen_dict[ 'nic_filter'] = "icmp and ((src %s and dst %s) or (src %s and dst %s)) " % ( self.fixed_ip_address, self.dest_ip_address, self.dest_ip_address, self.fixed_ip_address) local_listen_dict['snat_host'] = "remote" tunnel_ip = discovery.get_tunnel_ip(self.source_host_id, self.neutron) local_listen_dict['tunnel_ip'] = tunnel_ip local_listen_dict[ 'vxlan_filter'] = "(src %s or dst %s) and udp port (4789)" % ( local_listen_dict['tunnel_ip'], local_listen_dict['tunnel_ip']) if local_listen_dict['network_type'] == "vxlan": local_listen_dict['tunnel_port'] = discovery.get_tunnel_port( self.source_host_id, local_listen_dict['tunnel_ip'], self.neutron) else: local_listen_dict['tunnel_port'] = "None" local_listen_dict['bridge_name'] = discovery.get_bridge_name( local_listen_dict['network_label'], self.source_host_id, self.neutron) local_listen_dict['tag'] = "VM SOURCE" local_listen_dict['vif_names'] = self.vif_names local_listen_dict['ns_vif_names'] = [] vif_buffer = self.ns_vif_names for vif in vif_buffer: for vif_name in list(vif.keys()): if "qr" in vif_name: local_listen_dict['ns_vif_names'].append(vif) break remote_listen_dict = dict() remote_listen_dict['checker_type'] = "SNAT" remote_listen_dict['packet_type'] = "ICMP" remote_listen_dict['vm_name'] = self.vm_name remote_listen_dict['src_ip_address'] = self.fixed_ip_address remote_listen_dict['src_mac_address'] = self.source_port_dict[ 'mac_address'] remote_listen_dict['dest_ip_address'] = self.dest_ip_address remote_listen_dict['dest_mac_address'] = self.dest_mac_address remote_listen_dict['host_id'] = self.snat_host_id remote_listen_dict['port_id'] = self.source_port_dict['id'] remote_listen_dict[ 'network_label_remote_ext'] = discovery.get_network_label( self.external_network_id, self.neutron) remote_listen_dict[ 'network_type_remote_ext'] = discovery.get_network_type( self.external_network_id, self.neutron) remote_listen_dict['network_label'] = discovery.get_network_label( self.tenant_network_id, self.neutron) remote_listen_dict['network_type'] = discovery.get_network_type( self.tenant_network_id, self.neutron) remote_listen_dict[ 'nic_filter'] = "icmp and ((src %s and dst %s) or (src %s and dst %s)) " % ( self.fixed_ip_address, self.dest_ip_address, self.dest_ip_address, self.fixed_ip_address) remote_listen_dict[ 'ext_nic_filter'] = "icmp and ((src %s and dst %s) or (src %s and dst %s)) " % ( self.snat_external_ip, self.dest_ip_address, self.dest_ip_address, self.snat_external_ip) tunnel_ip = discovery.get_tunnel_ip(self.snat_host_id, self.neutron) remote_listen_dict['tunnel_ip'] = tunnel_ip remote_listen_dict[ 'vxlan_filter'] = "(src %s or dst %s) and udp port (4789)" % ( remote_listen_dict['tunnel_ip'], remote_listen_dict['tunnel_ip']) if remote_listen_dict['network_type'] == "vxlan": remote_listen_dict['tunnel_port'] = discovery.get_tunnel_port( self.snat_host_id, remote_listen_dict['tunnel_ip'], self.neutron) else: remote_listen_dict['tunnel_port'] = "None" remote_listen_dict['bridge_name'] = discovery.get_bridge_name( remote_listen_dict['network_label'], self.snat_host_id, self.neutron) remote_listen_dict[ 'bridge_name_remote_ext'] = discovery.get_bridge_name( remote_listen_dict['network_label_remote_ext'], self.snat_host_id, self.neutron) remote_listen_dict['tag'] = "SNAT NS" remote_listen_dict['vif_names'] = [] remote_listen_dict['ns_vif_names'] = [] for vif in vif_buffer: for vif_name in list(vif.keys()): if "qg" in vif_name or "sg" in vif_name: remote_listen_dict['ns_vif_names'].append(vif) break return local_listen_dict, remote_listen_dict
def format_dhcp_dicts(self): dhcp_list = [] for dhcp_port in self.dhcp_ports: dhcp_dict = dict() dhcp_host_id = dhcp_port['binding:host_id'] dhcp_bridge_name = discovery.get_bridge_name( self.network_label, dhcp_host_id, self.neutron) dhcp_tunnel_ip = discovery.get_tunnel_ip(dhcp_host_id, self.neutron) if self.network_type == "vxlan": dhcp_tunnel_port = discovery.get_tunnel_port( dhcp_host_id, dhcp_tunnel_ip, self.neutron) else: dhcp_tunnel_port = "None" dhcp_dict = { 'port_id': dhcp_port['id'], 'network_label': self.network_label, 'network_type': self.network_type, 'network_id': self.network_id, 'bridge_name': dhcp_bridge_name, 'host_id': dhcp_host_id, 'src_mac_address': self.source_port_dict['mac_address'], 'tunnel_ip': dhcp_tunnel_ip, 'nic_filter': "udp port (67 or 68) and ether host %s" % self.source_port_dict['mac_address'], 'vxlan_filter': "(src %s or dst %s) and udp port (4789)" % (dhcp_tunnel_ip, dhcp_tunnel_ip), 'tunnel_port': dhcp_tunnel_port, 'checker_type': "DHCP", 'packet_type': "DHCP", 'tag': "DHCP_NS" } full_name = "tap" + dhcp_dict['port_id'] dhcp_tap_device = full_name[:VIF_PREFIX_LEN] dhcp_ns = "qdhcp-" + self.network_id ns_vif_list = [] vif = dict() vif[dhcp_tap_device] = { 'filter': "udp port 67 or 68 and ether host %s" % dhcp_dict['src_mac_address'], 'is_ns': dhcp_ns, 'port_type': dhcp_tap_device } ns_vif_list.append(vif) dhcp_dict['ns_vif_names'] = ns_vif_list dhcp_dict['vif_names'] = [] dhcp_list.append(dhcp_dict) return dhcp_list