Example #1
0
def build_north_to_south(dp, route,
                         idle_timeout=0, hard_timeout=0):
    parser = dp.ofproto_parser
    public_ip = ip.ipv4_to_int(route['public_ip'])
    max_link = len(route['endpoints']) - 1
    north_ofport = cfg.CONF.flows.northbound_ofport
    south_ofport = cfg.CONF.flows.southbound_ofport

    for link, endpoint in enumerate(route['endpoints']):
        actions = [parser.NXActionResubmitTable(table=100)]
        match = build_rule(in_port=north_ofport, nw_dst=public_ip)
        add_flow(dp, actions=actions, match=match, cookie=public_ip,
                 idle_timeout=idle_timeout, hard_timeout=hard_timeout)

        # table 100
        bmf = build_multipath
        bmf(dp, public_ip, max_link,
            idle_timeout=idle_timeout, hard_timeout=hard_timeout)

        private_ip = ip.ipv4_to_int(endpoint['private_ip'])

        # table 110
        actions = [parser.OFPActionSetNwDst(private_ip),
                   parser.OFPActionOutput(port=south_ofport)]
        rule = build_rule(registers={1: link}, nw_dst=public_ip)
        add_flow(dp, table_id=110, actions=actions, match=rule,
                 cookie=public_ip, idle_timeout=idle_timeout,
                 hard_timeout=hard_timeout)
Example #2
0
def build_rule(in_port=None, nw_dst=None, nw_src=None, nw_proto=None,
               dl_dst=None, dl_src=None, registers=None, tun_id=None,
               dl_type=None):
    rule = ClsRule()

    if in_port is not None:
        rule.set_in_port(in_port)

    if dl_dst is not None:
        dl_dst = haddr_to_bin(dl_dst)
        rule.set_dl_dst(dl_dst)

    if dl_src is not None:
        dl_src = haddr_to_bin(dl_src)
        rule.set_dl_src(dl_src)

    if dl_type is None and (nw_dst is not None or nw_src is not None):
        dl_type = ether_types.ETH_TYPE_IP

    if dl_type is not None:
        rule.set_dl_type(dl_type)

    if nw_dst is not None:
        if isinstance(nw_dst, dict):
            nw_dst = nw_dst['destination']

        if isinstance(nw_dst, six.string_types):
            nw_dst = ip.ipv4_to_int(nw_dst)

        if isinstance(nw_dst, tuple):
            rule.set_nw_dst_masked(nw_dst[0], nw_dst[1])
        else:
            rule.set_nw_dst(nw_dst)

    if nw_src is not None:
        if isinstance(nw_src, dict):
            nw_src = nw_src['destination']

        if isinstance(nw_src, six.string_types):
            nw_src = ip.ipv4_to_int(nw_src)

        if isinstance(nw_src, tuple):
            rule.set_nw_src_masked(nw_src[0], nw_src[1])
        else:
            rule.set_nw_src(nw_src)

    if registers is not None:
        for k, v in registers.iteritems():
            rule.set_reg(k, v)

    if tun_id is not None:
        rule.set_tun_id(tun_id)

    if nw_proto is not None:
        rule.set_nw_proto(nw_proto)

    return rule
Example #3
0
def build_south_to_north(dp, floating_ip,
                         drop_flows=False, idle_timeout=0, hard_timeout=0):
    parser = dp.ofproto_parser
    public_ip = ip.ipv4_to_int(floating_ip['public_ip'])
    north_ofport = cfg.CONF.flows.northbound_ofport
    south_ofport = cfg.CONF.flows.southbound_ofport

    for endpoint in floating_ip['endpoints']:
        private_ip = ip.ipv4_to_int(endpoint['private_ip'])
        rule = build_rule(in_port=south_ofport, nw_src=private_ip)

        actions = [parser.OFPActionSetNwSrc(public_ip),
                   parser.OFPActionOutput(port=north_ofport)]
        add_flow(dp, actions=actions, match=rule,
                 cookie=public_ip, idle_timeout=idle_timeout,
                 hard_timeout=hard_timeout)
Example #4
0
def build_north_to_south(dp, route, idle_timeout=0, hard_timeout=0):
    parser = dp.ofproto_parser
    public_ip = ip.ipv4_to_int(route['public_ip'])
    max_link = len(route['endpoints']) - 1
    north_ofport = cfg.CONF.flows.northbound_ofport
    south_ofport = cfg.CONF.flows.southbound_ofport

    for link, endpoint in enumerate(route['endpoints']):
        actions = [parser.NXActionResubmitTable(table=100)]
        match = build_rule(in_port=north_ofport, nw_dst=public_ip)
        add_flow(dp,
                 actions=actions,
                 match=match,
                 cookie=public_ip,
                 idle_timeout=idle_timeout,
                 hard_timeout=hard_timeout)

        # table 100
        bmf = build_multipath
        bmf(dp,
            public_ip,
            max_link,
            idle_timeout=idle_timeout,
            hard_timeout=hard_timeout)

        private_ip = ip.ipv4_to_int(endpoint['private_ip'])

        # table 110
        actions = [
            parser.OFPActionSetNwDst(private_ip),
            parser.OFPActionOutput(port=south_ofport)
        ]
        rule = build_rule(registers={1: link}, nw_dst=public_ip)
        add_flow(dp,
                 table_id=110,
                 actions=actions,
                 match=rule,
                 cookie=public_ip,
                 idle_timeout=idle_timeout,
                 hard_timeout=hard_timeout)
Example #5
0
def build_south_to_north(dp,
                         floating_ip,
                         drop_flows=False,
                         idle_timeout=0,
                         hard_timeout=0):
    parser = dp.ofproto_parser
    public_ip = ip.ipv4_to_int(floating_ip['public_ip'])
    north_ofport = cfg.CONF.flows.northbound_ofport
    south_ofport = cfg.CONF.flows.southbound_ofport

    for endpoint in floating_ip['endpoints']:
        private_ip = ip.ipv4_to_int(endpoint['private_ip'])
        rule = build_rule(in_port=south_ofport, nw_src=private_ip)

        actions = [
            parser.OFPActionSetNwSrc(public_ip),
            parser.OFPActionOutput(port=north_ofport)
        ]
        add_flow(dp,
                 actions=actions,
                 match=rule,
                 cookie=public_ip,
                 idle_timeout=idle_timeout,
                 hard_timeout=hard_timeout)
Example #6
0
def build_rule(in_port=None,
               nw_dst=None,
               nw_src=None,
               nw_proto=None,
               dl_dst=None,
               dl_src=None,
               registers=None,
               tun_id=None,
               dl_type=None):
    rule = ClsRule()

    if in_port is not None:
        rule.set_in_port(in_port)

    if dl_dst is not None:
        dl_dst = haddr_to_bin(dl_dst)
        rule.set_dl_dst(dl_dst)

    if dl_src is not None:
        dl_src = haddr_to_bin(dl_src)
        rule.set_dl_src(dl_src)

    if dl_type is None and (nw_dst is not None or nw_src is not None):
        dl_type = ether_types.ETH_TYPE_IP

    if dl_type is not None:
        rule.set_dl_type(dl_type)

    if nw_dst is not None:
        if isinstance(nw_dst, dict):
            nw_dst = nw_dst['destination']

        if isinstance(nw_dst, six.string_types):
            nw_dst = ip.ipv4_to_int(nw_dst)

        if isinstance(nw_dst, tuple):
            rule.set_nw_dst_masked(nw_dst[0], nw_dst[1])
        else:
            rule.set_nw_dst(nw_dst)

    if nw_src is not None:
        if isinstance(nw_src, dict):
            nw_src = nw_src['destination']

        if isinstance(nw_src, six.string_types):
            nw_src = ip.ipv4_to_int(nw_src)

        if isinstance(nw_src, tuple):
            rule.set_nw_src_masked(nw_src[0], nw_src[1])
        else:
            rule.set_nw_src(nw_src)

    if registers is not None:
        for k, v in registers.iteritems():
            rule.set_reg(k, v)

    if tun_id is not None:
        rule.set_tun_id(tun_id)

    if nw_proto is not None:
        rule.set_nw_proto(nw_proto)

    return rule