예제 #1
0
def update_ovs_side(entity_zoo):
    global had_clean_ovs_flows
    # we must lock the whole process of generating flow and sweepping zoo
    # otherwise we may mark some new entities to State_NO, without generating
    # any ovs flows
    with entity_zoo.lock:
        start_time = time.time()
        lflow.build_flows(Table, Priority, Match, Action, State)
        lflows = zip(Table.data, Priority.data, Match.data,
                     Action.data, State.data)
        # must insert const flows in init stage
        if not had_clean_ovs_flows:
            lflow.build_const_flows(Table, Priority, Match, Action)
            static_lflows = zip(Table.data, Priority.data, Match.data,
                                Action.data, [1]*len(Table.data))
            lflows += static_lflows
        cost_time = time.time() - start_time
        config_tunnel_bfd()
        rebuild_chassis_tunnel()
        entity_zoo.sweep_zoo()

    ovs_flows_add, ovs_flows_del = convert_tuple2flow(lflows)
    # on testing mode, it avoids similar flow replacing the others
    if os.environ.has_key('RUNTEST'):
        ovs_flows_add.sort()
    logger.info("pydatalog cost %fs in generating flows", cost_time)
    if not had_clean_ovs_flows:
        had_clean_ovs_flows = True
        ovs_flows_add += _get_ovs_arp_ip_mac_from_file()
        cm.commit_replaceflows(ovs_flows_add)
    else:
        cm.commit_flows(ovs_flows_add, ovs_flows_del)
    logger.info('insert flow number:%d, del flow number:%d',
                len(ovs_flows_add), len(ovs_flows_del))
예제 #2
0
def update_ovs_side(entity_zoo):
    # we must lock the whole process of generating flow and sweepping zoo
    # otherwise we may mark some new entities to State_NO, without generating
    # any ovs flows
    with entity_zoo.lock:
        start_time = time.time()
        lflow.build_flows(Table, Priority, Match, Action, State)
        lflows = zip(Table.data, Priority.data, Match.data,
                     Action.data, State.data)
        cost_time = time.time() - start_time
        config_tunnel_bfd()
        rebuild_chassis_tunnel()
        entity_zoo.sweep_zoo()

    ovs_flows_add, ovs_flows_del = convert_tuple2flow(lflows)
    # on testing mode, it avoids similar flow replacing the others
    if os.environ.has_key('RUNTEST'):
        ovs_flows_add.sort()
    logger.info('insert flow number:%d, del flow number:%d',
                len(ovs_flows_add), len(ovs_flows_del))
    logger.info("pydatalog cost %fs in generating flows", cost_time)
    cm.commit_flows(ovs_flows_add, ovs_flows_del)
예제 #3
0
def update_ovs_arp_ip_mac(mac_addr, ip_int):
    match = 'table={t},priority=1,ip,reg2={dst},'.format(
        t=flow_common.TABLE_SEARCH_IP_MAC, dst=ip_int)
    action = 'actions=mod_dl_dst:{}'.format(mac_addr)
    flow = match + action
    commit_flows([flow], [])
예제 #4
0
def update_ovs_arp_ip_mac(mac_addr, ip_int):
    flow = _gen_arp_ip_flow(mac_addr, ip_int)
    cm.commit_flows([flow], [])
    with open(MAC_IP_BIND_FILE, 'a') as fd:
        fd.write("{},{}\n".format(mac_addr, ip_int))