예제 #1
0
def create_flows_from_rule_and_port(rule, port):
    ethertype = rule['ethertype']
    direction = rule['direction']
    dst_ip_prefix = rule.get('dest_ip_prefix')
    src_ip_prefix = rule.get('source_ip_prefix')

    flow_template = {
        'priority': 70,
        'dl_type': ovsfw_consts.ethertype_to_dl_type_map[ethertype],
        'reg_port': port.ofport,
    }

    if is_valid_prefix(dst_ip_prefix):
        if ip_lib.get_ip_version(dst_ip_prefix) == n_consts.IP_VERSION_4:
            flow_template["nw_dst"] = dst_ip_prefix
        elif ip_lib.get_ip_version(dst_ip_prefix) == n_consts.IP_VERSION_6:
            flow_template["ipv6_dst"] = dst_ip_prefix

    if is_valid_prefix(src_ip_prefix):
        if ip_lib.get_ip_version(src_ip_prefix) == n_consts.IP_VERSION_4:
            flow_template["nw_src"] = src_ip_prefix
        elif ip_lib.get_ip_version(src_ip_prefix) == n_consts.IP_VERSION_6:
            flow_template["ipv6_src"] = src_ip_prefix

    flows = create_protocol_flows(direction, flow_template, port, rule)

    return flows
예제 #2
0
def create_flows_from_rule_and_port(rule, port):
    ethertype = rule['ethertype']
    direction = rule['direction']
    dst_ip_prefix = rule.get('dest_ip_prefix')
    src_ip_prefix = rule.get('source_ip_prefix')

    flow_template = {
        'priority': 70,
        'dl_type': ovsfw_consts.ethertype_to_dl_type_map[ethertype],
        'reg_port': port.ofport,
    }

    if is_valid_prefix(dst_ip_prefix):
        if ip_lib.get_ip_version(dst_ip_prefix) == n_consts.IP_VERSION_4:
            flow_template["nw_dst"] = dst_ip_prefix
        elif ip_lib.get_ip_version(dst_ip_prefix) == n_consts.IP_VERSION_6:
            flow_template["ipv6_dst"] = dst_ip_prefix

    if is_valid_prefix(src_ip_prefix):
        if ip_lib.get_ip_version(src_ip_prefix) == n_consts.IP_VERSION_4:
            flow_template["nw_src"] = src_ip_prefix
        elif ip_lib.get_ip_version(src_ip_prefix) == n_consts.IP_VERSION_6:
            flow_template["ipv6_src"] = src_ip_prefix

    flows = create_protocol_flows(direction, flow_template, port, rule)

    return flows
 def fdb_ip_entry_exists(self, mac, ip, interface):
     ip_version = ip_lib.get_ip_version(ip)
     entry = ip_lib.dump_neigh_entries(ip_version,
                                       interface,
                                       dst=ip,
                                       lladdr=mac)
     return entry != []
예제 #4
0
 def start(self):
     if self.proc and self.proc.is_running:
         raise RuntimeError("This pinger has already a running process")
     ip_version = ip_lib.get_ip_version(self.address)
     ping_exec = 'ping' if ip_version == 4 else 'ping6'
     cmd = [ping_exec, self.address, '-W', str(self.timeout)]
     if self.count:
         cmd.extend(['-c', str(self.count)])
     self.proc = RootHelperProcess(cmd, namespace=self.namespace)
예제 #5
0
 def _add_default_gateway_for_fip(self, gw_ip, ip_device, tbl_index):
     """Adds default gateway for fip based on the tbl_index passed."""
     if tbl_index is None:
         ip_version = ip_lib.get_ip_version(gw_ip)
         tbl_index_list = self.get_fip_table_indexes(ip_version)
         for tbl_index in tbl_index_list:
             ip_device.route.add_gateway(gw_ip, table=tbl_index)
     else:
         ip_device.route.add_gateway(gw_ip, table=tbl_index)
예제 #6
0
 def get_gateway_ips(gateway_port):
     gw_ips = {}
     if gateway_port:
         for subnet in gateway_port.get('subnets', []):
             gateway_ip = subnet.get('gateway_ip', None)
             if gateway_ip:
                 ip_version = ip_lib.get_ip_version(gateway_ip)
                 gw_ips[ip_version] = gateway_ip
     return gw_ips
예제 #7
0
 def start(self):
     if self.proc and self.proc.is_running:
         raise RuntimeError("This pinger has already a running process")
     ip_version = ip_lib.get_ip_version(self.address)
     ping_exec = 'ping' if ip_version == 4 else 'ping6'
     cmd = [ping_exec, self.address, '-W', str(self.timeout)]
     if self.count:
         cmd.extend(['-c', str(self.count)])
     self.proc = RootHelperProcess(cmd, namespace=self.namespace)
예제 #8
0
파일: dvr_fip_ns.py 프로젝트: annp/neutron
 def get_gateway_ips(gateway_port):
     gw_ips = {}
     if gateway_port:
         for subnet in gateway_port.get('subnets', []):
             gateway_ip = subnet.get('gateway_ip', None)
             if gateway_ip:
                 ip_version = ip_lib.get_ip_version(gateway_ip)
                 gw_ips[ip_version] = gateway_ip
     return gw_ips
예제 #9
0
 def _test_icmp_connectivity(self, direction, protocol, src_port, dst_port):
     src_namespace, ip_address = self._get_namespace_and_address(direction)
     ip_version = ip_lib.get_ip_version(ip_address)
     icmp_timeout = ICMP_VERSION_TIMEOUTS[ip_version]
     try:
         net_helpers.assert_ping(src_namespace, ip_address, timeout=icmp_timeout)
     except RuntimeError:
         raise ConnectionTesterException(
             "ICMP packets can't get from %s namespace to %s address" % (src_namespace, ip_address)
         )
예제 #10
0
    def _get_port_devicename_scopemark(self, ports, name_generator):
        devicename_scopemark = {l3_constants.IP_VERSION_4: dict(), l3_constants.IP_VERSION_6: dict()}
        for p in ports:
            device_name = name_generator(p["id"])
            ip_cidrs = common_utils.fixed_ip_cidrs(p["fixed_ips"])
            port_as_marks = self.get_port_address_scope_mark(p)
            for ip_version in {ip_lib.get_ip_version(cidr) for cidr in ip_cidrs}:
                devicename_scopemark[ip_version][device_name] = port_as_marks[ip_version]

        return devicename_scopemark
예제 #11
0
 def _test_icmp_connectivity(self, direction, protocol, src_port, dst_port):
     src_namespace, ip_address = self._get_namespace_and_address(direction)
     ip_version = ip_lib.get_ip_version(ip_address)
     icmp_timeout = ICMP_VERSION_TIMEOUTS[ip_version]
     try:
         net_helpers.assert_ping(src_namespace, ip_address,
                                 timeout=icmp_timeout)
     except RuntimeError:
         raise ConnectionTesterException(
             "ICMP packets can't get from %s namespace to %s address" % (
                 src_namespace, ip_address))
예제 #12
0
    def _get_port_devicename_scopemark(self, ports, name_generator):
        devicename_scopemark = {lib_constants.IP_VERSION_4: dict(),
                                lib_constants.IP_VERSION_6: dict()}
        for p in ports:
            device_name = name_generator(p['id'])
            ip_cidrs = common_utils.fixed_ip_cidrs(p['fixed_ips'])
            port_as_marks = self.get_port_address_scope_mark(p)
            for ip_version in {ip_lib.get_ip_version(cidr)
                               for cidr in ip_cidrs}:
                devicename_scopemark[ip_version][device_name] = (
                    port_as_marks[ip_version])

        return devicename_scopemark
예제 #13
0
def has_expected_arp_entry(device_name, namespace, ip, mac):
    ip_version = ip_lib.get_ip_version(ip)
    entry = ip_lib.dump_neigh_entries(ip_version, device_name, namespace,
                                      dst=ip, lladdr=mac)
    return entry != []
예제 #14
0
 def add_gateway(self, device, gateway_ip):
     table = device.route.table(self.name)
     ip_version = ip_lib.get_ip_version(gateway_ip)
     self._keep.add((constants.IP_ANY[ip_version], device.name))
     table.add_gateway(gateway_ip)
 def add_gateway(self, device, gateway_ip):
     table = device.route.table(self.name)
     ip_version = ip_lib.get_ip_version(gateway_ip)
     self._keep.add((constants.IP_ANY[ip_version], device.name))
     table.add_gateway(gateway_ip)