def commandTargetMouseHex(pc): game.Game.update() unit = game.Game.getSelectedUnit() #unit being issued the command if not unit: return #no unit selected if (unit.owner == pc and Unit.getStat(unit, 'mp') > 0): mouseHex = game.Game.getMouseHex() newPos = mouseHex unitHere = Unit.Unit.getFromHex(mouseHex) if unitHere: if unitHere.owner == pc: alert("That space is occupied.") return else: #ATTACK!!! action.attack(unit, unitHere, HAND1) return #need to employ pathfinding!!!!! Mouse hover + draw the path char will take. dist = hex_distance(unit.pos, newPos) if (dist <= Unit.getStat(unit, 'mob') and dist <= Unit.getStat(unit, 'mp')): action.move(unit, newPos, dist) selectHex(newPos) else: alert(unit.name + " cannot move that far.") else: if not unit.owner == pc: alert(unit.name + " is not your unit!") elif Unit.getStat(unit, 'mp') <= 0: alert(unit.name + " cannot move anymore this turn.")
def aiBarbarian(plyr): myUnits = [] enemies = [] #first get list of all my available units and all enemies... for unit in Unit.getList(): if unit.dead: continue if unit.owner == plyr: if not game.isOn(unit, SE_KO): myUnits.append(unit) else: #diplomacy settings could go here enemies.append(unit) #find out which tiles are visible to my units #iterate through fighting units... for unit in myUnits: #distances = {} closest = None target = None distMin = 9999999 hpMin = 9999999 noTargetsInRange = True for enemy in enemies: dist = hex_distance(unit.pos, enemy.pos) #distances[unit.id] = dist #in reach of weapon? if dist <= getStat( unit, 'hand1reachMax'): #barb. only attacks w/ mainhand? enemyHP = getStat(enemy, 'hp') if enemyHP < hpMin: hpMin = enemyHP target = enemy noTargetsInRange = False #get closest enemy to move toward if noTargetsInRange: if dist < distMin: distMin = dist closest = enemy #Move if noTargetsInRange: target = closest path = game.aStar(unit.pos, target.pos) #while energy is left, move along the path for _hex in path: #if _hex == unit.pos: continue if getStat(unit, 'mp') <= 0: break action.move(unit, _hex, 1) #print('move') #Attack else: action.attack(unit, target, HAND1)
def run(): while 1 == 1: #截图并读取 os.system('adb shell screencap -p /sdcard/2048.png') os.system('adb pull /sdcard/2048.png') screen_image = cv2.imread('2048.png') #转换为数组 array = getArray2(screen_image) #手势操作 move(array)
def move(mdir): db.cur.execute("select "+mdir+" from world where fromid = \""+find.plLoc()+"\";") newloc = parse.tupleListToList(db.cur.fetchall()) if newloc[0] == None: print("You can't go there.") else: vis = get.visCheck(newloc[0]) if vis == False: print("You cannot go there!") elif vis == True: charid = "player" db.cur.execute("update people set locid = \""+newloc[0]+"\" where charid = \""+charid+"\";") get.allPrints(newloc[0]) # From the new location: automatically print location description, items, people, and available movement action.move(newloc[0])
def run(): lastArray = [] #记录上次移动的数组,用来判断上一步操作是否有效 lastMove = 0 # while 1 == 1: #截图并读取 os.system('adb shell screencap -p /sdcard/2048.png') os.system('adb pull /sdcard/2048.png') screen_image = cv2.imread('2048.png') #转换为数组 array = getArray2(screen_image) #手势操作 lastMove = move(array, lastArray, lastMove) lastArray = array
def run(): while 1 == 1: #截图并读取 os.system('adb shell screencap -p /sdcard/2048.png') os.system('adb pull /sdcard/2048.png') screen_image = cv2.imread('2048.png') #转换为数组 array = getArray2(screen_image) #手势操作 move(array) run() #单步操作 os.system('adb shell screencap -p /sdcard/2048.png') os.system('adb pull /sdcard/2048.png') screen_image = cv2.imread('2048.png') #转换为数组 array = getArray2(screen_image) #手势操作 move(array)
def init_physical_flow_clause(options): # handle tunnel port ingress traffic convert_phy_logical(Priority, Match, Action, State) <= ( (Priority == 2) & remote_chassis(UUID_CHASSIS, PHY_CHASSIS, State) & (State != 0) & match.in_port(PHY_CHASSIS[PCH_OFPORT], Match) & action.resubmit_table(TABLE_EXTRACT_METADATA, Action1) & action.load( 1, NXM_Reg(REG_FLAG_IDX, FLAG_LOOPBACK_BIT_IDX, FLAG_LOOPBACK_BIT_IDX), Action2) & action.resubmit_table(TABLE_PIPELINE_FORWARD, Action3) & (Action == Action1 + Action2 + Action3)) # handle regular port ingress traffic convert_phy_logical(Priority, Match, Action, State) <= ( (Priority == 2) & local_bond_lsp(LSP, LS, State) & (State != 0) & match.in_port(LSP[LSP_OFPORT], Match) & action.load(LSP[LSP_PORTID], NXM_Reg(REG_SRC_IDX), Action1) & action.load(LS[LS_ID], NXM_Reg(REG_DP_IDX), Action2) & action.resubmit_next(Action3) & (Action == Action1 + Action2 + Action3)) # it helps reduce time-cost _arp_ip_mac(IP, IP_INT, MAC, MAC_INT, LS, State) <= (active_lsp(LSP, LS, UUID_LS, State) & (State != 0) & (IP == LSP[LSP_IP]) & (IP_INT == LSP[LSP_IP_INT]) & (MAC == LSP[LSP_MAC]) & (MAC_INT == LSP[LSP_MAC_INT])) _arp_ip_mac(IP, IP_INT, MAC, MAC_INT, LS, State) <= ( lnat_data(LNAT, LR, XLATE_TYPE, UUID_LR, State1) & lsp_link_lrp( LSP, LS, UUID_LS, LRP, LR, UUID_LR, UUID_LR_CHASSIS, State2) & (State == State1 + State2) & (State != 0) & (IP == LNAT[LNAT_XLATE_IP]) & (IP_INT == LNAT[LNAT_XLATE_IP_INT]) & (MAC == LNAT[LNAT_XLATE_MAC]) & (MAC_INT == LNAT[LNAT_XLATE_MAC_INT])) # regular lsp arp feedback arp_feedback_construct(LS, Priority, Match, Action, State) <= ( (Priority == 0) & _arp_ip_mac(IP, IP_INT, MAC, MAC_INT, LS, State) & match.arp_proto(Match1) & match.arp_tpa(IP, Match2) & match.arp_op(1, Match3) & (Match == Match1 + Match2 + Match3) & action.load( 1, NXM_Reg(REG_FLAG_IDX, FLAG_LOOPBACK_BIT_IDX, FLAG_LOOPBACK_BIT_IDX), Action1) & action.move(NXM_Reg(ETH_SRC_IDX), NXM_Reg(ETH_DST_IDX), Action2) & action.mod_dl_src(MAC, Action3) & action.load(2, NXM_Reg(ARP_OP_IDX), Action4) & action.move(NXM_Reg(ARP_SHA_IDX), NXM_Reg(ARP_THA_IDX), Action5) & action.load(MAC_INT, NXM_Reg(ARP_SHA_IDX), Action6) & action.move(NXM_Reg(ARP_SPA_IDX), NXM_Reg(ARP_TPA_IDX), Action7) & action.load(IP_INT, NXM_Reg(ARP_SPA_IDX), Action8) & action.move(NXM_Reg(REG_SRC_IDX), NXM_Reg(REG_DST_IDX), Action9) & (Action == Action1 + Action2 + Action3 + Action4 + Action5 + Action6 + Action7 + Action8 + Action9)) output_pkt_by_reg(Priority, Match, Action) <= ( (Priority == 1) & match.reg_outport(st.TP_OFPORT_NONE, Match) & action.resubmit_table(TABLE_DROP_PACKET, Action)) output_pkt_by_reg(Priority, Match, Action) <= ( (Priority == 0) & match.match_none(Match) & action.output_reg(NXM_Reg(REG_OUTPORT_IDX), Action))
def stateless(bot): # desire to move in a particular coordinate desires = Desires(wander=7) # listen to events '''lis=rog.listen(bot) if lis: for ev in lis: if rog.can_see(bot,ev.x,ev.y): continue # hearing if not ev.volume: continue if rog.can_hear(bot, ev.x,ev.y, ev.volume): interest=5 _add_desire_direction( desires, bot.x,bot.y, ev.x,ev.y, interest) rog.clear_listen_events(bot)''' # iterate through each tile in sight and see what is there... # is there a better way to do this? # This code is a little slow. sight = bot.stats.sight for x in range(bot.x - sight, bot.x + sight + 1): for y in range(bot.y - sight, bot.y + sight + 1): if (not rog.is_in_grid(x, y) #out of bounds or (x == bot.x and y == bot.y)): #ignore self continue if not rog.can_see(bot, x, y): continue #bot can't see it here = rog.thingat(x, y) if here: # decide what it is and what to do about it if rog.is_creature(here): if rog.on(here, DEAD): continue #no interest in dead things interest = 0 #desire to fight if here.faction == FACT_ROGUE: interest = 1000 #desire to run away #elif here.type == '@': # interest=-1000 #grouping behavior elif here.type == bot.type: interest = 5 if (interest > 0): _add_desire_direction(desires, bot.x, bot.y, x, y, interest) elif (interest < 0): _add_fear_direction(desires, bot.x, bot.y, x, y, interest) #if thing is inanimate else: #food desire if hungry #treasure desire pass # pick the direction it wants to move in the most highest = -999 for i in range(3): for j in range(3): new = desires.get(j - 1, i - 1) if new > highest: highest = new coords = ( j - 1, i - 1, ) dx, dy = coords xto = bot.x + dx yto = bot.y + dy # out of bounds if not rog.is_in_grid(xto, yto): return # fight if there is a monster present mon = rog.monat(xto, yto) if (mon and mon is not bot): if not mon.type == bot.type: ##TEMPORARY action.fight(bot, mon) return # or move elif not rog.solidat(xto, yto): if action.move(bot, dx, dy): return # if no action was done, just wait action.wait(bot)
def commands(pc, pcAct): world = rog.world() for act, arg in pcAct: rog.update_base() # actions that take multiple turns busyTask = rog.occupations(pc) if busyTask: if not rog.occupation_elapse_turn(pc): # interrupted ## rog.Input("") pass #----------------# # convert action # #----------------# if act == 'target': act = directional_command #----------------# # perform action # #----------------# #-----------MOUSE ACTION----------------------------# if act == 'lclick': mousex, mousey, z = arg if rog.wallat(mousex, mousey): return pos = world.component_for_entity(pc, cmp.Position) rog.path_compute(pc.path, pos.x, pos.y, rog.mapx(mousex), rog.mapy(mousey)) #rog.occupation_set(pc,'path') if act == 'rclick': pass #------------OTHER ACTION--------------------------# if act == 'move': dx, dy, dz = arg pos = world.component_for_entity(pc, cmp.Position) actor = world.component_for_entity(pc, cmp.Actor) xto = pos.x + dx yto = pos.y + dy # wait if (xto == pos.x and yto == pos.y): actor.ap = 0 return # out of bounds if (not rog.is_in_grid_x(xto) or not rog.is_in_grid_y(yto)): return # fight if there is a monster present mon = rog.monat(xto, yto) if (mon and mon is not pc): action.fight(pc, mon) # or move elif not rog.solidat(xto, yto): # space is free, so we can move if action.move(pc, dx, dy): rog.view_center_player() if act == "get": action.pickup_pc(pc) return if act == "open": #open or close action.open_pc(pc) return if act == "sprint": #begin sprinting action.sprint_pc(pc) return if act == "throw": #throw an object action.throw_pc(pc) return #unused actions '''if act == "bomb": action.bomb_pc(pc) return''' # # # special actions # # if act == 'find player': #useful to immediately show where the player is pos = world.component_for_entity(pc, cmp.Position) rog.view_center_player() rog.update_game() rog.update_final() rog.update_base() rog.game_update() #call all the updates rog.alert('press any key to continue...') rog.Input(rog.getx(pos.x), rog.gety(pos.y), mode='wait') rog.update_base() rog.alert('') return if act == "look": pos = world.component_for_entity(pc, cmp.Position) rog.routine_look(pos.x, pos.y) return if act == "move view": rog.routine_move_view() return if act == "fixed view": rog.fixedViewMode_toggle() return if act == 'select': # TESTING print(rog.Input(0, 0, 20)) return if act == 'exit': return
def commands(pc, pcAct): world = rog.world() directional_command = 'move' for act,arg in pcAct: ## print(act) ## print(arg) rog.update_base() #----------------# # convert action # #----------------# if act =='context-dir': act=directional_command ## if act =='context': ## pass # moving using the menu move keys if (act =='menu-nav' and rog.game_state()=="normal"): act=directional_command #----------------# # perform action # #----------------# #-----------MOUSE ACTION----------------------------# if act == 'lclick': mousex,mousey,z=arg if rog.wallat(mousex,mousey): return pos = world.component_for_entity(pc, cmp.Position) print("Left click unimplemented") ## rog.path_compute(pc.path, pos.x,pos.y, rog.mapx(mousex), rog.mapy(mousey)) #rog.occupation_set(pc,'path') if act == 'rclick': pass #------------OTHER ACTION--------------------------# if act == 'help': rog.help() # "move-prompt" : True # prompt for a direction # and then perform the move action in that direction if act == 'move-prompt': pass # "attack-prompt" : True # prompt for a direction # and then perform the attack action in that direction if act == 'attack-prompt': pass # "move" : (x_change, y_change, z_change,) if act == 'move': _Update() dx,dy,dz=arg pos = world.component_for_entity(pc, cmp.Position) actor = world.component_for_entity(pc, cmp.Actor) xto=pos.x + dx yto=pos.y + dy # wait if (xto==pos.x and yto==pos.y): actor.ap = 0 return # out of bounds if ( not rog.is_in_grid_x(xto) or not rog.is_in_grid_y(yto) ): return # warning for slow move speed if rog.allow_warning_msp(): msp=rog.getms(pc, 'msp') if msp <= 10: inp=rog.prompt( 0,0,rog.window_w(), 6, mode='wait', q='''Warning: your movement speed is critically slow (MSP: {}). Are you sure you want to move? y/n'''.format(msp) ) if inp!='y': return else: rog.expire_warning_msp() #TODO: when is best time to reset this warning? # end if # choose context-sensitive action # # fight if there is a monster present mon = rog.monat(xto,yto) if mon: # and mon != pc): action.fight(pc,mon) # or move elif not rog.solidat(xto,yto): # space is free, so we can move if action.move(pc, dx,dy): rog.view_center_player() else: rog.alert("That space is occupied.") # end conditional # "attack" : (x, y, z,) if act == 'attack': _Update() xto,yto,zto=arg pos = world.component_for_entity(pc, cmp.Position) actor = world.component_for_entity(pc, cmp.Actor) # out of bounds if ( not rog.is_in_grid_x(xto) or not rog.is_in_grid_y(yto) ): return # fight if there is a monster present mon = rog.monat(xto,yto) # ... but don't attack yourself! if mon == pc: rog.alert("You can't fight yourself!") return if mon: action.fight(pc,mon) else: ent = rog.thingat(xto,yto) if ent: action.fight(pc,ent) else: rog.msg("You strike out at thin air, losing your balance.") actor.ap = 0 rog.set_status( pc, cmp.StatusOffBalance, t=2, q=-MISS_BAL_PENALTY ) # end conditional # chat with closest speaking entity; # if multiple good options, prompt for which one. if act == "chat-context": action.chat_context(pc) _Update() return if act == "change-pos": # change body position action.change_bodypos_pc(pc) _Update() return if act == "change-msp": # change speed of movement (walking, running, jogging, etc.) action.change_speed_pc(pc) _Update() return if act == "msp-up": # change from walk to powerwalk, to trot, jog, etc. action.speed_up_pc(pc) _Update() return if act == "msp-down": # change from sprint to run, to jog, to trot, etc. action.slow_down_pc(pc) _Update() return if act == "target-prompt": #target entity + fire / throw / attack action.target_pc_generic(pc) _Update() return if act == "get-prompt": action.pickup_pc(pc) _Update() return if act == "openclose-prompt": #open or close action.open_pc(pc) _Update() return if act == "open-prompt": #open or close action.open_pc(pc) _Update() return if act == "close-prompt": #open or close action.open_pc(pc) _Update() return if act == "jog": #begin jogging action.jog_pc(pc) _Update() return if act == "run": #begin running action.run_pc(pc) _Update() return if act == "sprint": #begin sprinting action.sprint_pc(pc) _Update() return #unused actions '''if act == "bomb": action.bomb_pc(pc) return''' # # # special actions # # if act == 'find player': #useful to immediately show where the player is pos = world.component_for_entity(pc, cmp.Position) rog.view_center_player() rog.update_game() rog.update_final() rog.game_update() #call all the updates rog.alert('press any key to continue...') rog.Input(rog.getx(pos.x), rog.gety(pos.y), mode='wait') rog.update_base() rog.alert('') return if act == "look": pos = world.component_for_entity(pc, cmp.Position) rog.routine_look(pos.x,pos.y) return if act == "move view": rog.routine_move_view() return if act == "fixed view": rog.fixedViewMode_toggle() return if act == 'select': # TESTING print(rog.Input(0,0,20)) return if act == 'exit': return
def init_build_flows_clause(options): action.init_action_clause() match.init_match_clause() init_entity_clause(options) physical_flow.init_physical_flow_clause(options) lsp_ingress.init_lsp_ingress_clause(options) lsp_egress.init_lsp_egress_clause(options) lrp_ingress.init_lrp_ingress_clause(options) lrp_egress.init_lrp_egress_clause(options) build_flows(Table, Priority, Match, Action, State) <= ( build_flows_lrp(Table, Priority, Match, Action, State)) build_flows(Table, Priority, Match, Action, State) <= ( build_flows_lsp(Table, Priority, Match, Action, State)) build_flows(Table, Priority, Match, Action, State) <= ( build_flows_phy(Table, Priority, Match, Action, State)) build_flows(Table, Priority, Match, Action, State) <= ( build_flows_mid(Table, Priority, Match, Action, State)) # build const flows which were executed only once build_const_flows(Table, Priority, Match, Action) <= ( build_flows_drop(Table, Priority, Match, Action)) build_const_flows(Table, Priority, Match, Action) <= ( build_flows_phy(Table, Priority, Match, Action)) build_const_flows(Table, Priority, Match, Action) <= ( build_flows_lsp(Table, Priority, Match, Action)) build_const_flows(Table, Priority, Match, Action) <= ( build_flows_lrp(Table, Priority, Match, Action)) build_const_flows(Table, Priority, Match, Action) <= ( build_flows_mid(Table, Priority, Match, Action)) # build physical flows build_flows_phy(Table, Priority, Match, Action, State) <= ( (Table == TABLE_CONVERT_PHY_LOGICAL) & physical_flow.convert_phy_logical(Priority, Match, Action1, State) & action.note(flows_note2idx('convert_phy_logical'), Action2) & (Action == Action1 + Action2) ) build_flows_phy(Table, Priority, Match, Action, State) <= ( physical_flow.arp_feedback_construct(LS, Priority, Match2, Action, State) & # TODO adding note here introduce performance regression # should figure out the root cause match.datapath(LS[LS_ID], Match1) & (Match == Match1 + Match2) & (Table == TABLE_ARP_FEEDBACK_CONSTRUCT) ) build_flows_phy(Table, Priority, Match, Action) <= ( physical_flow.output_pkt_by_reg(Priority, Match, Action1) & action.note(flows_note2idx('output_pkt'), Action2) & (Action == Action1 + Action2) & (Table == TABLE_OUTPUT_PKT) ) build_flows_phy(Table, Priority, Match, Action) <= ( pkt_trace.trace_pipeline_module(Match1, Action1) & # NOTE: refresh TUN_METADATA0_IDX, may output to remote chassis action.move(NXM_Reg(REG_FLAG_IDX, 0, 31), NXM_Reg(TUN_METADATA0_IDX, 32, 63), Action2) & physical_flow.output_pkt_by_reg(Priority1, Match2, Action3) & (Priority == Priority1 + 10) & action.note(flows_note2idx('pkt_trace_output_pkt'), Action4) & (Match == Match1 + Match2) & (Action == Action1 + Action2 + Action3 + Action4) & (Table == TABLE_OUTPUT_PKT) ) # build middle table flows build_flows_mid(Table, Priority, Match, Action) <= ( mid.embed_metadata(Priority, Match, Action1) & action.note(flows_note2idx('embed_metadata'), Action2) & (Action == Action1 + Action2) & (Table == TABLE_EMBED2_METADATA) ) build_flows_mid(Table, Priority, Match, Action) <= ( mid.extract_metadata(Priority, Match, Action1) & action.note(flows_note2idx('extract_metadata'), Action2) & (Action == Action1 + Action2) & (Table == TABLE_EXTRACT_METADATA) ) build_flows_mid(Table, Priority, Match, Action) <= ( mid.pipeline_forward(Priority, Match, Action1) & action.note(flows_note2idx('pipeline_forward'), Action2) & (Action == Action1 + Action2) & (Table == TABLE_PIPELINE_FORWARD) ) build_flows_mid(Table, Priority, Match, Action, State) <= ( mid.redirect_other_chassis(Priority, Match, Action1, State) & action.note(flows_note2idx('redirect_other_chassis'), Action2) & (Action == Action1 + Action2) & (Table == TABLE_REDIRECT_CHASSIS) ) # const flow build_flows_mid(Table, Priority, Match, Action) <= ( mid.redirect_other_chassis(Priority, Match, Action1) & action.note(flows_note2idx('redirect_other_chassis'), Action2) & (Action == Action1 + Action2) & (Table == TABLE_REDIRECT_CHASSIS) ) # build flows for logical port ingress pipline build_flows_lsp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LSP_INGRESS_UNTUNNEL) & lsp_ingress.lsp_untunnel_deliver(LS, Priority, Match2, Action1, State) & action.note(flows_note2idx('lsp_untunnel_deliver'), Action2) & (Action == Action1 + Action2) & (match.datapath(LS[LS_ID], Match1)) & (Match == Match1 + Match2) ) build_flows_lsp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LSP_INGRESS_OUTPUT_DST_PORT) & lsp_ingress.lsp_output_dst_port(LS, Priority, Match2, Action1, State) & action.note(flows_note2idx('lsp_output_dst_port'), Action2) & (Action == Action1 + Action2) & (match.datapath(LS[LS_ID], Match1)) & (Match == Match1 + Match2) ) build_flows_lsp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LSP_INGRESS_LOOKUP_DST_PORT) & lsp_ingress.lsp_lookup_dst_port(LS, Priority, Match2, Action1, State) & action.note(flows_note2idx('lsp_lookup_dst_port'), Action2) & (Action == Action1 + Action2) & (match.datapath(LS[LS_ID], Match1)) & (Match == Match1 + Match2) ) build_flows_lsp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LSP_INGRESS_ARP_CONTROLLER) & lsp_ingress.lsp_arp_controller(LS, Priority, Match2, Action1, State) & action.note(flows_note2idx('lsp_arp_controller'), Action2) & (Action == Action1 + Action2) & (match.datapath(LS[LS_ID], Match1)) & (Match == Match1 + Match2) ) build_flows_lsp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LSP_INGRESS_ARP_RESPONSE) & lsp_ingress.lsp_arp_response(LS, Priority, Match2, Action1, State) & action.note(flows_note2idx('lsp_arp_response'), Action2) & (Action == Action1 + Action2) & (match.datapath(LS[LS_ID], Match1)) & (Match == Match1 + Match2) ) # build flows for logical port egress pipline build_flows_lsp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LSP_EGRESS_JUDGE_LOOPBACK) & lsp_egress.lsp_judge_loopback(LS, Priority, Match2, Action1, State) & action.note(flows_note2idx('lsp_judge_loopback'), Action2) & (Action == Action1 + Action2) & (match.datapath(LS[LS_ID], Match1)) & (Match == Match1 + Match2) ) build_flows_lsp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LSP_EGRESS_FORWARD_PACKET) & lsp_egress.lsp_forward_packet(LS, Priority, Match2, Action1, State) & action.note(flows_note2idx('lsp_forward_packet'), Action2) & (Action == Action1 + Action2) & (match.datapath(LS[LS_ID], Match1)) & (Match == Match1 + Match2) ) build_flows_lsp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LSP_EGRESS_PUSHOUT) & lsp_egress.lsp_pushout_packet(LS, Priority, Match2, Action1, State) & action.note(flows_note2idx('lsp_pushout_packet'), Action2) & (Action == Action1 + Action2) & (match.datapath(LS[LS_ID], Match1)) & (Match == Match1 + Match2) ) # build const trace flow in first stage of lsp ingress build_flows_lsp(Table, Priority, Match, Action) <= ( (Table == TABLE_LSP_TRACE_INGRESS_IN) & action.load(0, NXM_Reg(REG_DST_IDX), Action1) & pkt_trace.trace_pipeline_start(Priority, Match, Action2) & action.note(flows_note2idx('pkt_trace_lsp_ingress_in'), Action3) & (Action == Action1 + Action2 + Action3) ) # build trace flow for in end stage of lsp ingress # because the end stage of lsp ingress has no uniq path, so # we have to add similar flows(simliar to regular flow) to trace build_flows_lsp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LSP_TRACE_INGRESS_OUT) & pkt_trace.trace_pipeline_module(Match1, Action1) & lsp_ingress.lsp_output_dst_port(LS, Priority1, Match2, Action2, State) & (Priority == Priority1 + 10) & (match.datapath(LS[LS_ID], Match3)) & (Match == Match1 + Match2 + Match3) & action.note(flows_note2idx('pkt_trace_lsp_output_dst_port'), Action3) & (Action == Action1 + Action2 + Action3) ) # build const trace flow in first stage of lsp egress build_flows_lsp(Table, Priority, Match, Action) <= ( (Table == TABLE_LSP_TRACE_EGRESS_IN) & pkt_trace.trace_pipeline_start(Priority, Match, Action1) & action.note(flows_note2idx('pkt_trace_lsp_egress_in'), Action2) & (Action == Action1 + Action2) ) # build const flows to forward packet to third party table build_flows_lsp(Table, Priority, Match, Action) <= ( (Table == TABLE_LSP_INGRESS_PROCESS_EXT_LOGIC) & (Priority == 0) & match.match_none(Match) & action.resubmit_table(TABLE_THIRD_PARTY, Action1) & action.note(flows_note2idx('process_third_logic'), Action2) & (Action == Action1 + Action2) ) build_flows_lsp(Table, Priority, Match, Action) <= ( (Table == TABLE_THIRD_PARTY) & (Priority == 0) & match.match_none(Match) & action.resubmit_table(TABLE_LSP_INGRESS_PROCESS_EXT_LOGIC+1, Action1) & action.note(flows_note2idx('process_third_logic'), Action2) & (Action == Action1 + Action2) ) # build trace flow in end stage of lsp egress # build trace flow in end stage of lsp egress # build trace flow in end stage of lsp egress # because the end stage of lsp egress has no uniq path, so # we have to add similar flows(simliar to regular flow) to trace build_flows_lsp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LSP_TRACE_EGRESS_OUT) & pkt_trace.trace_pipeline_module(Match1, Action1) & lsp_egress.lsp_pushout_packet(LS, Priority1, Match2, Action2, State) & action.note(flows_note2idx('pkt_trace_lsp_pushout_packet'), Action3) & (Priority == Priority1 + 10) & (match.datapath(LS[LS_ID], Match3)) & (Match == Match1 + Match2 + Match3) & (Action == Action1 + Action2 + Action3) ) #-----------------------------LRP--------------------------------------------- #build flows for logical router port ingress pipline build_flows_lrp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LRP_INGRESS_PKT_RESPONSE) & lrp_ingress.lrp_pkt_response(LR, Priority, Match2, Action1, State) & action.note(flows_note2idx('lrp_pkt_response'), Action2) & (Action == Action1 + Action2) & match.datapath(LR[LR_ID], Match1) & (Match == Match1 + Match2) ) build_flows_lrp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LRP_INGRESS_DROP_UNEXPECT) & lrp_ingress.lrp_drop_unexpect(LR, Priority, Match2, Action1, State) & action.note(flows_note2idx('lrp_drop_unexpect'), Action2) & (Action == Action1 + Action2) & match.datapath(LR[LR_ID], Match1) & (Match == Match1 + Match2) ) build_flows_lrp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LRP_INGRESS_UNSNAT_STAGE1) & lrp_ingress.lrp_ip_unsnat_stage1(LR, Priority, Match2, Action1, State) & action.note(flows_note2idx('lrp_ip_unsnat_stage1'), Action2) & (Action == Action1 + Action2) & match.datapath(LR[LR_ID], Match1) & (Match == Match1 + Match2) ) build_flows_lrp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LRP_INGRESS_UNSNAT_STAGE2) & lrp_ingress.lrp_ip_unsnat_stage2(LR, Priority, Match2, Action1, State) & action.note(flows_note2idx('lrp_ip_unsnat_stage2'), Action2) & (Action == Action1 + Action2) & match.datapath(LR[LR_ID], Match1) & (Match == Match1 + Match2) ) build_flows_lrp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LRP_INGRESS_DNAT_STAGE1) & lrp_ingress.lrp_ip_dnat_stage1(LR, Priority, Match2, Action1, State) & action.note(flows_note2idx('lrp_ip_dnat_stage1'), Action2) & (Action == Action1 + Action2) & match.datapath(LR[LR_ID], Match1) & (Match == Match1 + Match2) ) build_flows_lrp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LRP_INGRESS_DNAT_STAGE2) & lrp_ingress.lrp_ip_dnat_stage2(LR, Priority, Match2, Action1, State) & action.note(flows_note2idx('lrp_ip_dnat_stage2'), Action2) & (Action == Action1 + Action2) & match.datapath(LR[LR_ID], Match1) & (Match == Match1 + Match2) ) build_flows_lrp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LRP_INGRESS_IP_ROUTE) & lrp_ingress.lrp_ip_route(LR, Priority, Match2, Action1, State) & action.note(flows_note2idx('lrp_ip_route'), Action2) & (Action == Action1 + Action2) & match.datapath(LR[LR_ID], Match1) & (Match == Match1 + Match2) ) build_flows_lrp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LRP_INGRESS_ECMP) & lrp_ingress.lrp_ecmp_judge(LR, Priority, Match2, Action1, State) & action.note(flows_note2idx('lrp_ecmp_judge'), Action2) & (Action == Action1 + Action2) & match.datapath(LR[LR_ID], Match1) & (Match == Match1 + Match2) ) #build flows for logical router port egress pipline build_flows_lrp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LRP_EGRESS_UPDATE_ETH_DST) & lrp_egress.lrp_update_eth_dst(LR, Priority, Match2, Action1, State) & action.note(flows_note2idx('lrp_update_eth_dst'), Action2) & (Action == Action1 + Action2) & match.datapath(LR[LR_ID], Match1) & (Match == Match1 + Match2) ) build_flows_lrp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LRP_EGRESS_UNDNAT_STAGE1) & lrp_egress.lrp_ip_undnat_stage1(LR, Priority, Match2, Action1, State) & action.note(flows_note2idx('lrp_ip_undnat_stage1'), Action2) & (Action == Action1 + Action2) & match.datapath(LR[LR_ID], Match1) & (Match == Match1 + Match2) ) build_flows_lrp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LRP_EGRESS_UNDNAT_STAGE2) & lrp_egress.lrp_ip_undnat_stage2(LR, Priority, Match2, Action1, State) & action.note(flows_note2idx('lrp_ip_undnat_stage2'), Action2) & (Action == Action1 + Action2) & match.datapath(LR[LR_ID], Match1) & (Match == Match1 + Match2) ) build_flows_lrp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LRP_EGRESS_SNAT_STAGE1) & lrp_egress.lrp_ip_snat_stage1(LR, Priority, Match2, Action1, State) & action.note(flows_note2idx('lrp_ip_snat_stage1'), Action2) & (Action == Action1 + Action2) & match.datapath(LR[LR_ID], Match1) & (Match == Match1 + Match2) ) build_flows_lrp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LRP_EGRESS_SNAT_STAGE2) & lrp_egress.lrp_ip_snat_stage2(LR, Priority, Match2, Action1, State) & action.note(flows_note2idx('lrp_ip_snat_stage2'), Action2) & (Action == Action1 + Action2) & match.datapath(LR[LR_ID], Match1) & (Match == Match1 + Match2) ) build_flows_lrp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LRP_EGRESS_HANDLE_UNK_PKT) & lrp_egress.lrp_handle_unknow_dst_pkt(LR, Priority, Match2, Action1, State) & action.note(flows_note2idx('lrp_handle_unknow_dst_pkt'), Action2) & (Action == Action1 + Action2) & match.datapath(LR[LR_ID], Match1) & (Match == Match1 + Match2) ) build_flows_lrp(Table, Priority, Match, Action, State) <= ( (Table == TABLE_LRP_EGRESS_FORWARD_PACKET) & lrp_egress.lrp_forward_packet(LR, Priority, Match2, Action1, State) & action.note(flows_note2idx('lrp_forward_packet'), Action2) & (Action == Action1 + Action2) & match.datapath(LR[LR_ID], Match1) & (Match == Match1 + Match2) ) # build const trace flow in first stage of lrp ingress build_flows_lrp(Table, Priority, Match, Action) <= ( (Table == TABLE_LRP_TRACE_INGRESS_IN) & action.load(0, NXM_Reg(REG_DST_IDX), Action1) & pkt_trace.trace_pipeline_start(Priority, Match, Action2) & action.note(flows_note2idx('pkt_trace_lrp_ingress_in'), Action3) & (Action == Action1 + Action2 + Action3) ) # build const trace flow in last stage of lrp ingress build_flows_lrp(Table, Priority, Match, Action) <= ( (Table == TABLE_LRP_TRACE_INGRESS_OUT) & pkt_trace.trace_pipeline_end(Priority, Match, Action1) & action.resubmit_table(TABLE_LRP_EGRESS_FIRST, Action2) & action.note(flows_note2idx('pkt_trace_lrp_ingress_out'), Action3) & (Action == Action1 + Action2 + Action3) ) # build const trace flow in first stage of lrp egress build_flows_lrp(Table, Priority, Match, Action) <= ( (Table == TABLE_LRP_TRACE_EGRESS_IN) & pkt_trace.trace_pipeline_start(Priority, Match, Action1) & action.note(flows_note2idx('pkt_trace_lrp_egress_in'), Action2) & (Action == Action1 + Action2) ) # build const trace flow in last stage of lrp egress build_flows_lrp(Table, Priority, Match, Action) <= ( (Table == TABLE_LRP_TRACE_EGRESS_OUT) & pkt_trace.trace_pipeline_end(Priority, Match, Action1) & action.resubmit_table(TABLE_LSP_INGRESS_FIRST, Action2) & action.note(flows_note2idx('pkt_trace_lrp_egress_out'), Action3) & (Action == Action1 + Action2 + Action3) ) #---------------------const drop table-------------------------------- build_flows_drop(Table, Priority, Match, Action) <= ( (Priority == 0) & (Table == TABLE_DROP_PACKET) & match.match_none(Match) & action.drop(Action) ) build_flows_drop(Table, Priority, Match, Action) <= ( (Priority == 1) & (Table == TABLE_DROP_PACKET) & # we do not add drop action, because drop action # must not be accompanied by any other action or instruction # so we just add packet tracing action. pkt_trace.trace_pipeline_module(Match, Action1) & action.note(flows_note2idx('pkt_trace_drop_packet'), Action2) & (Action == Action1 + Action2) )
redirect_other_chassis(Priority, Match, Action, State) <= ( (Priority == 1) & (gateway_ofport[X] == OFPORT) & (State == X[1]) & (State != 0) & match.match_none(Match) & action.load( 1, NXM_Reg(REG_FLAG_IDX, FLAG_REDIRECT_BIT_IDX, FLAG_REDIRECT_BIT_IDX), Action1) & action.bundle_load(NXM_Reg(REG_OUTPORT_IDX), OFPORT, Action2) & action.resubmit_table(TABLE_EMBED2_METADATA, Action3) & action.resubmit_table(TABLE_OUTPUT_PKT, Action4) & (Action == Action1 + Action2 + Action3 + Action4)) redirect_other_chassis(Priority, Match, Action) <= ( (Priority == 0) & match.match_none(Match) & action.resubmit_table(TABLE_DROP_PACKET, Action)) embed_metadata(Priority, Match, Action) <= ( (Priority == 0) & match.match_none(Match) & action.move( NXM_Reg(REG_DP_IDX, 0, 23), NXM_Reg(TUN_ID_IDX, 0, 23), Action1) & action.move(NXM_Reg(REG_SRC_IDX, 0, 15), NXM_Reg(TUN_METADATA0_IDX, 0, 15), Action2) & action.move(NXM_Reg(REG_DST_IDX, 0, 15), NXM_Reg(TUN_METADATA0_IDX, 16, 31), Action3) & action.move(NXM_Reg(REG_FLAG_IDX, 0, 31), NXM_Reg(TUN_METADATA0_IDX, 32, 63), Action4) & (Action == Action1 + Action2 + Action3 + Action4)) extract_metadata(Priority, Match, Action) <= ( (Priority == 0) & match.match_none(Match) & action.move( NXM_Reg(TUN_ID_IDX, 0, 23), NXM_Reg(REG_DP_IDX, 0, 23), Action1) & action.move(NXM_Reg(TUN_METADATA0_IDX, 0, 15), NXM_Reg( REG_SRC_IDX, 0, 15), Action2) & action.move( NXM_Reg(TUN_METADATA0_IDX, 16, 31), NXM_Reg(REG_DST_IDX, 0, 15), Action3) & action.move(NXM_Reg(TUN_METADATA0_IDX, 32, 63),
def init_lrp_ingress_clause(options): init_ecmp_clause(options) # response ICMP packet if receiving ICMP request lrp_pkt_response(LR, Priority, Match, Action, State) <= ( (Priority == 3) & lsp_link_lrp(LSP, LS, UUID_LS, LRP, LR, UUID_LR, UUID_LR_CHASSIS, State) & (State != 0) & match.icmp_proto(Match1) & match.icmp_type(8, Match2) & match.icmp_code(0, Match3) & match.ip_dst(LRP[LRP_IP], Match4) & (Match == Match1 + Match2 + Match3 + Match4) & action.exchange(NXM_Reg(IP_SRC_IDX), NXM_Reg(IP_DST_IDX), Action1) & action.load(0xff, NXM_Reg(IP_TTL_IDX), Action2) & action.load(0, NXM_Reg(ICMP_TYPE_IDX), Action3) & action.move(NXM_Reg(REG_SRC_IDX), NXM_Reg(REG_DST_IDX), Action4) & action.load(1, NXM_Reg(REG_FLAG_IDX, FLAG_LOOPBACK_BIT_IDX, FLAG_LOOPBACK_BIT_IDX), Action5) & action.resubmit_next(Action6) & (Action == Action1 + Action2 + Action3 + Action4 + Action5 + Action6) ) lrp_pkt_response(LR, Priority, Match, Action, State) <= ( (Priority == 0) & lr_array(LR, UUID_LR, State) & (State != 0) & match.ip_proto(Match) & action.resubmit_next(Action)) lrp_drop_unexpect(LR, Priority, Match, Action, State) <= ( (Priority == 2) & lr_array(LR, UUID_LR, State) & (State != 0) & match.ip_proto(Match1) & match.ip_ttl(1, Match2) & (Match == Match1 + Match2) & action.resubmit_table(TABLE_DROP_PACKET, Action) ) lrp_drop_unexpect(LR, Priority, Match, Action, State) <= ( (Priority == 0) & lr_array(LR, UUID_LR, State) & (State != 0) & match.ip_proto(Match) & action.dec_ttl(Action1) & action.resubmit_next(Action2) & (Action == Action1 + Action2) ) lrp_ip_unsnat_stage1(LR, Priority, Match, Action, State) <= ( nat.lunsnat_xlate_stage1(LR, Priority, Match, Action, State)) lrp_ip_unsnat_stage2(LR, Priority, Match, Action, State) <= ( nat.lunsnat_xlate_stage2(LR, Priority, Match, Action, State)) lrp_ip_dnat_stage1(LR, Priority, Match, Action, State) <= ( nat.ldnat_xlate_stage1(LR, Priority, Match, Action, State)) lrp_ip_dnat_stage2(LR, Priority, Match, Action, State) <= ( nat.ldnat_xlate_stage2(LR, Priority, Match, Action, State)) #automatic route lrp_ip_route(LR, Priority, Match, Action, State) <= ( lsp_link_lrp(LSP, LS, UUID_LS, LRP, LR, UUID_LR, UUID_LR_CHASSIS, State) & (State != 0) & (Priority == LRP[LRP_PREFIX] * 3) & match.ip_proto(Match1) & match.ip_dst_prefix(LRP[LRP_IP], LRP[LRP_PREFIX], Match2) & (Match == Match1 + Match2) & action.load(LRP[LRP_PORTID], NXM_Reg(REG_DST_IDX), Action1) & action.load(LRP[LRP_MAC_INT], NXM_Reg(ETH_SRC_IDX), Action2) & action.move(NXM_Reg(IP_DST_IDX), NXM_Reg(REG2_IDX), Action3) & # lrp_handle_unknow_dst_pkt may use it to modify IP to # construct right arp request action.load(LRP[LRP_IP_INT], NXM_Reg(REG3_IDX), Action4) & action.resubmit_next(Action5) & (Action == Action1 + Action2 + Action3 + Action4 + Action5) ) #static route lrp_ip_route(LR, Priority, Match, Action, State) <= ( lsp_link_lrp(LSP, LS, UUID_LS, LRP, LR, UUID_LR, UUID_LR_CHASSIS, State1) & (lroute_array(Route, UUID_LR, State2)) & (State == State1 + State2) & (State != 0) & (UUID_LR == LR[LR_UUID]) & # only match the first outport (LRP[LRP_UUID] == Route[LSR_OUTPORT]) & (Priority == 1 + Route[LSR_PREFIX] * 3) & match.ip_proto(Match1) & match.ip_dst_prefix(Route[LSR_IP], Route[LSR_PREFIX], Match2) & (Match == Match1 + Match2) & action.load(LRP[LRP_PORTID], NXM_Reg(REG_DST_IDX), Action1) & action.load(LRP[LRP_MAC_INT], NXM_Reg(ETH_SRC_IDX), Action2) & action.load(Route[LSR_NEXT_HOP_INT], NXM_Reg(REG2_IDX), Action3) & # lrp_handle_unknow_dst_pkt may use it to modify IP to # construct right arp request action.load(LRP[LRP_IP_INT], NXM_Reg(REG3_IDX), Action4) & action.resubmit_next(Action5) & (Action == Action1 + Action2 + Action3 + Action4 + Action5) ) # gateway chassis no need to consider ecmp if not options.has_key('GATEWAY'): lrp_ip_route(LR, Priority, Match, Action, State) <= ( ecmp_static_route(LR, Priority, Match, Action, State) ) lrp_ecmp_judge(LR, Priority, Match, Action, State) <= ( ecmp_static_route_judge(LR, Priority, Match, Action, State) ) # drop packet if we cannot found route for this packet lrp_ip_route(LR, Priority, Match, Action, State) <= ( (Priority == 0) & lr_array(LR, UUID_LR, State) & (State != 0) & match.match_none(Match) & action.resubmit_table(TABLE_DROP_PACKET, Action) )
def init_lrp_ingress_clause(options): init_ecmp_clause(options) if options.has_key('GATEWAY'): _live_lsp_link_lrp( LSP, LS, UUID_LS, LRP, LR, UUID_LR, None, State) <= (lsp_link_lrp( LSP, LS, UUID_LS, LRP, LR, UUID_LR, None, State)) _live_lsp_link_lrp( LSP, LS, UUID_LS, LRP, LR, UUID_LR, UUID_LR_CHASSIS, State) <= (lsp_link_lrp(LSP, LS, UUID_LS, LRP, LR, UUID_LR, UUID_LR_CHASSIS, State1) & chassis_array(PHY_CHASSIS, UUID_LR_CHASSIS, State2) & (State == State1 + State2)) else: _live_lsp_link_lrp(LSP, LS, UUID_LS, LRP, LR, UUID_LR, UUID_LR_CHASSIS, State) <= (lsp_link_lrp( LSP, LS, UUID_LS, LRP, LR, UUID_LR, UUID_LR_CHASSIS, State)) # response ICMP packet if receiving ICMP request lrp_pkt_response(LR, Priority, Match, Action, State) <= ( (Priority == 3) & _live_lsp_link_lrp(LSP, LS, UUID_LS, LRP, LR, UUID_LR, UUID_LR_CHASSIS, State) & (State != 0) & match.icmp_proto(Match1) & match.icmp_type(8, Match2) & match.icmp_code(0, Match3) & match.ip_dst(LRP[LRP_IP], Match4) & (Match == Match1 + Match2 + Match3 + Match4) & action.exchange(NXM_Reg(IP_SRC_IDX), NXM_Reg(IP_DST_IDX), Action1) & action.load(0xff, NXM_Reg(IP_TTL_IDX), Action2) & action.load(0, NXM_Reg(ICMP_TYPE_IDX), Action3) & action.move( NXM_Reg(REG_SRC_IDX), NXM_Reg(REG_DST_IDX), Action4) & action.load( 1, NXM_Reg(REG_FLAG_IDX, FLAG_LOOPBACK_BIT_IDX, FLAG_LOOPBACK_BIT_IDX), Action5) & action.resubmit_next(Action6) & (Action == Action1 + Action2 + Action3 + Action4 + Action5 + Action6)) lrp_pkt_response(LR, Priority, Match, Action, State) <= ( (Priority == 0) & lr_array(LR, UUID_LR, State) & (State != 0) & match.ip_proto(Match) & action.resubmit_next(Action)) lrp_drop_unexpect(LR, Priority, Match, Action, State) <= ( (Priority == 2) & lr_array(LR, UUID_LR, State) & (State != 0) & match.ip_proto(Match1) & match.ip_ttl(1, Match2) & (Match == Match1 + Match2) & action.resubmit_table(TABLE_DROP_PACKET, Action)) lrp_drop_unexpect(LR, Priority, Match, Action, State) <= ( (Priority == 0) & lr_array(LR, UUID_LR, State) & (State != 0) & match.ip_proto(Match) & action.dec_ttl(Action1) & action.resubmit_next(Action2) & (Action == Action1 + Action2)) lrp_ip_unsnat_stage1(LR, Priority, Match, Action, State) <= (nat.lunsnat_xlate_stage1( LR, Priority, Match, Action, State)) lrp_ip_unsnat_stage2(LR, Priority, Match, Action, State) <= (nat.lunsnat_xlate_stage2( LR, Priority, Match, Action, State)) lrp_ip_dnat_stage1(LR, Priority, Match, Action, State) <= (nat.ldnat_xlate_stage1( LR, Priority, Match, Action, State)) lrp_ip_dnat_stage2(LR, Priority, Match, Action, State) <= (nat.ldnat_xlate_stage2( LR, Priority, Match, Action, State)) #automatic route lrp_ip_route(LR, Priority, Match, Action, State) <= ( lsp_link_lrp(LSP, LS, UUID_LS, LRP, LR, UUID_LR, UUID_LR_CHASSIS, State) & (State != 0) & (Priority == _cal_priority(LRP[LRP_PREFIX], 0, LRP[LRP_ILK_IDX])) & match.ip_proto(Match1) & match.ip_dst_prefix(LRP[LRP_IP], LRP[LRP_PREFIX], Match2) & (Match == Match1 + Match2) & action.load(LRP[LRP_PORTID], NXM_Reg(REG_DST_IDX), Action1) & action.load(LRP[LRP_MAC_INT], NXM_Reg(ETH_SRC_IDX), Action2) & action.move(NXM_Reg(IP_DST_IDX), NXM_Reg(REG2_IDX), Action3) & # lrp_handle_unknow_dst_pkt may use it to modify IP to # construct right arp request action.load(LRP[LRP_IP_INT], NXM_Reg(REG3_IDX), Action4) & action.resubmit_next(Action5) & (Action == Action1 + Action2 + Action3 + Action4 + Action5)) if options.has_key('GATEWAY'): _static_route_changed(Route, LR, LRP, State) <= ( local_system_id(UUID_CHASSIS) & lroute_array(Route, UUID_LR, State1) & lsp_link_lrp( LSP, LS, UUID_LS, LRP, LR, UUID_LR, UUID_CHASSIS, State2) & (Route[LSR_OUTPORT] == LRP[LRP_UUID]) & local_patchport(LSP1, LS, State3) & (State == State1 + State2 + State3) & (State != 0)) _next_live_hop_lr(UUID_LRP, LRP, LR, LR_NEXT, State) <= (next_hop_lr(UUID_LRP, LRP, LR, LR_NEXT, State) & (LR_NEXT[LR_CHASSIS_UUID] == None)) # if next LR is pining on a chassis, tuplenet have to verify if the geneve # tunnel port had been create. Otherwise, some packet may deliver to this # LR which has no tunnel port to remote chassis. It cause packet drop once # a gateway chassis was re-add. _next_live_hop_lr(UUID_LRP, LRP, LR, LR_NEXT, State) <= ( next_hop_lr(UUID_LRP, LRP, LR, LR_NEXT, State1) & (LR_NEXT[LR_CHASSIS_UUID] != None) & remote_chassis( LR_NEXT[LR_CHASSIS_UUID], PHY_CHASSIS_WITH_OFPORT, State2) & (State == State1 + State2)) _next_live_hop_lr(UUID_LRP, LRP, LR, LR_NEXT, State) <= (next_hop_lr(UUID_LRP, LRP, LR, LR_NEXT, State) & local_system_id(LR_NEXT[LR_CHASSIS_UUID])) _static_route_changed(Route, LR, LRP, State) <= ( lroute_array(Route, UUID_LR, State1) & _next_live_hop_lr(Route[LSR_OUTPORT], LRP, LR, LR_NEXT, State2) & (State == State1 + State2) & (State != 0)) #static route lrp_ip_route(LR, Priority, Match, Action, State) <= ( _static_route_changed(Route, LR, LRP, State) & (Priority == _cal_priority(Route[LSR_PREFIX], 1, Route[LSR_ILK_IDX])) & match.ip_proto(Match1) & match.ip_dst_prefix(Route[LSR_IP], Route[LSR_PREFIX], Match2) & (Match == Match1 + Match2) & action.load(LRP[LRP_PORTID], NXM_Reg(REG_DST_IDX), Action1) & action.load(LRP[LRP_MAC_INT], NXM_Reg(ETH_SRC_IDX), Action2) & action.load(Route[LSR_NEXT_HOP_INT], NXM_Reg(REG2_IDX), Action3) & # lrp_handle_unknow_dst_pkt may use it to modify IP to # construct right arp request action.load(LRP[LRP_IP_INT], NXM_Reg(REG3_IDX), Action4) & action.resubmit_next(Action5) & (Action == Action1 + Action2 + Action3 + Action4 + Action5)) # gateway chassis no need to consider ecmp if not options.has_key('GATEWAY'): lrp_ip_route(LR, Priority, Match, Action, State) <= (ecmp_static_route( LR, Priority, Match, Action, State)) lrp_ecmp_judge(LR, Priority, Match, Action, State) <= (ecmp_static_route_judge( LR, Priority, Match, Action, State)) # drop packet if we cannot found route for this packet lrp_ip_route(LR, Priority, Match, Action, State) <= ((Priority == 0) & lr_array(LR, UUID_LR, State) & (State != 0) & match.match_none(Match) & action.resubmit_table(TABLE_DROP_PACKET, Action))
def stateless(bot): ''' Dumb temporary NPC controller function implementing a simple 8-directional desire system ''' world = rog.world() desires = Desires(wander=7) sight = rog.getms(bot, "sight") pos = world.component_for_entity(bot, cmp.Position) botCreature = world.component_for_entity(bot, cmp.Creature) ## botType=world.component_for_entity(bot, cmp.Draw).char #should not depend on draw component # Where should this go???? ## rog.run_fov_manager(bot) # moved to can_see # TODO: write this function def isFoe(myFaction, theirFaction): return True # TODO: re-implement listening # listen to events '''lis=rog.listen(bot) if lis: for ev in lis: if rog.can_see(bot,ev.x,ev.y): continue # hearing if not ev.volume: continue if rog.can_hear(bot, ev.x,ev.y, ev.volume): interest=5 _add_desire_direction( desires, bot.x,bot.y, ev.x,ev.y, interest) rog.clear_listen_events(bot)''' # iterate through each tile in sight and see what is there... # is there a better way to do this? # This code is a little slow. for x in range(pos.x - sight, pos.x + sight + 1): for y in range(pos.y - sight, pos.y + sight + 1): if (not rog.is_in_grid(x, y) # out of bounds or (x == pos.x and y == pos.y)): # ignore self continue if not rog.can_see(bot, x, y, sight): continue # can't see it here = rog.thingat(x, y) if here: isCreature = world.has_component(here, cmp.Creature) # decide what it is and what to do about it if isCreature: creature = world.component_for_entity(here, cmp.Creature) if rog.on(here, DEAD): continue # no interest in dead things interest = 0 #desire to fight if creature.faction == FACT_ROGUE: interest = 1000 #grouping behavior elif creature.faction == botCreature.faction: interest = 5 if (interest > 0): _add_desire_direction(desires, pos.x, pos.y, x, y, interest) elif (interest < 0): _add_fear_direction(desires, pos.x, pos.y, x, y, interest) #if thing is inanimate else: #food desire if hungry #treasure desire pass # pick the direction it wants to move in the most highest = -999 for i in range(3): for j in range(3): new = desires.get(j - 1, i - 1) if new > highest: highest = new coords = ( j - 1, i - 1, ) dx, dy = coords xto = pos.x + dx yto = pos.y + dy # out of bounds if not rog.is_in_grid(xto, yto): return # fight if there is a foe present mon = rog.monat(xto, yto) if (mon and mon is not bot): monFaction = world.component_for_entity(mon, cmp.Creature).faction if isFoe(botCreature.faction, monFaction): action.fight(bot, mon) return # or move elif not rog.solidat(xto, yto): if action.move(bot, dx, dy): return # if no action was done, just wait action.wait(bot)
action.bundle_load(NXM_Reg(REG_OUTPORT_IDX), OFPORT, Action2) & action.resubmit_table(TABLE_EMBED2_METADATA, Action3) & action.resubmit_table(TABLE_OUTPUT_PKT, Action4) & (Action == Action1 + Action2 + Action3 + Action4) ) redirect_other_chassis(Priority, Match, Action) <= ( (Priority == 0) & match.match_none(Match) & action.resubmit_table(TABLE_DROP_PACKET, Action) ) embed_metadata(Priority, Match, Action) <= ( (Priority == 0) & match.match_none(Match) & action.move(NXM_Reg(REG_DP_IDX, 0, 23), NXM_Reg(TUN_ID_IDX, 0, 23), Action1) & action.move(NXM_Reg(REG_SRC_IDX, 0, 15), NXM_Reg(TUN_METADATA0_IDX, 0, 15), Action2) & action.move(NXM_Reg(REG_DST_IDX, 0, 15), NXM_Reg(TUN_METADATA0_IDX, 16, 31), Action3) & action.move(NXM_Reg(REG_FLAG_IDX, 0, 31), NXM_Reg(TUN_METADATA0_IDX, 32, 63), Action4) & (Action == Action1 + Action2 + Action3 + Action4) ) extract_metadata(Priority, Match, Action) <= ( (Priority == 0) & match.match_none(Match) & action.move(NXM_Reg(TUN_ID_IDX, 0, 23), NXM_Reg(REG_DP_IDX, 0, 23), Action1) & action.move(NXM_Reg(TUN_METADATA0_IDX, 0, 15),
def run(self): if self.FirstMove: self.particles = self.map.generateRandom(NumberOfParticles) #self.map.showMap(self.iter,self.particles) self.map.writeMap2file(self.iter, self.particles) self.iter = self.iter + 1 print("Iteration:", self.iter) kenar = True #reading encoders initial value self.robot.step(TimeStep) self.l0 = self.positionSensors["left"].getValue() self.r0 = self.positionSensors["right"].getValue() print("l0:", self.l0, "r0:", self.r0) #reading sensors self.sonarSensorsValues = self.sonarSensors.readSensors(self.robot) print("Sensor values:", self.sonarSensorsValues) self.DistanceValues = self.sensorModel.SensorValuesToDistance( self.sonarSensorsValues) print("Sensor distance values:", self.DistanceValues) bestSensorIndex = self.DistanceValues.index(min(self.DistanceValues)) print("Best sensor index:", bestSensorIndex) if self.DistanceValues[bestSensorIndex] > MaxReading: kenar = False #updating weights based on measurments if kenar: for i in range(len(self.particles[0])): self.particles[4][i] = self.map.getDistanceToNearestWall( self.particles[0][i], self.particles[1][i], self.sonarSensors.sensorPositions[bestSensorIndex] + self.particles[2][i]) self.sensorModel.DistanceToSensorValue(self.particles[4][i], bestSensorIndex) self.UpdateWeights(self.sensorModel, bestSensorIndex) self.Mean = getMean(self.particles[3]) print("Mean of weights:", self.Mean) self.Median = median(self.particles[3]) print("Median of weights:", self.Median) #showing weights '''a = plt.hist(self.particles[3]) plt.show(a) print("weights",self.particles[3])''' #deleting particles by a cutoff on their weight if kenar: self.numOfDeletedParticles = self.deleteParticles(self.Median / 2) print("Num of deletd partciles by cutoff:", self.numOfDeletedParticles) else: self.numOfDeletedParticles = 0 #making a decision for robot's next move if (self.FirstMove == True): decision = FirstAction(self.sensorModel, self.DistanceValues) self.FirstMove = False else: decision = decideAction(self.sensorModel, self.DistanceValues) print("Decision:", decision) rotation = decision["rotation"] linearMove = decision["move"] #moving robot odeometryResult = rotate(rotation, self.l0, self.r0, self.motors["left"], self.motors["right"], self.positionSensors["left"], self.positionSensors["right"], self.robot) self.l0 = odeometryResult[0] self.r0 = odeometryResult[1] da = odeometryResult[2] print("da:", da) odeometryResult = move(linearMove, self.l0, self.r0, self.motors["left"], self.motors["right"], self.positionSensors["left"], self.positionSensors["right"], self.robot, self.sonarSensors, self.sensorModel) self.l0 = odeometryResult[0] self.r0 = odeometryResult[1] dx = odeometryResult[2] print("dx:", dx) #moving particles num = self.MotionModel.moveParticles(self.particles, dx, rotation, self.map) self.numOfDeletedParticles = self.numOfDeletedParticles + num #printing some data print("Num of deleted partciles by move:", num) print("Num of deleted particles:", self.numOfDeletedParticles) print("Num of paricles after deletions:", len(self.particles[0])) #generating some random particles newParticels1 = self.map.generateRandom(randomPerIter) #resampling if kenar: newParticels2 = self.resample(self.Mean, self.map) for i in range(len(newParticels1)): newParticels1[i].extend(newParticels2[i]) self.combineOldAndNewParticles(newParticels1) else: self.combineOldAndNewParticles(newParticels1) print("Num of paricles after gen:", len(self.particles[0])) #visualizing #self.map.showMap(self.iter,self.particles) self.map.writeMap2file(self.iter, self.particles)
def init_lsp_egress_clause(way): lsp_judge_loopback(LS, Priority, Match, Action, State) <= ( (Priority == 2) & ls_array(LS, UUID_LS, State) & (State != 0) & match.reg_flag(FLAG_LOOPBACK, Match) & # load 0xffff(OFPP_NONE) -> inport to avoid dropping loopback packet action.load(st.TP_OFPORT_NONE, NXM_Reg(IN_PORT_IDX), Action1) & action.resubmit_next(Action2) & (Action == Action1 + Action2)) lsp_judge_loopback(LS, Priority, Match, Action, State) <= ( (Priority == 0) & ls_array(LS, UUID_LS, State) & (State != 0) & match.match_none(Match) & action.resubmit_next(Action)) # output packet to local ovs-port lsp_forward_packet(LS, Priority, Match, Action, State) <= ( (Priority == 3) & local_bond_lsp(LSP, LS, State) & (State != 0) & match.reg_dst(LSP[LSP_PORTID], Match) & action.load(1, NXM_Reg(REG5_IDX), Action1) & action.load(LSP[LSP_OFPORT], NXM_Reg(REG_OUTPORT_IDX), Action2) & action.resubmit_next(Action3) & (Action == Action1 + Action2 + Action3)) # set the packet's destination, the destination is next LR's LRP lsp_forward_packet(LS, Priority, Match, Action, State) <= ( (Priority == 2) & lsp_link_lrp(LSP, LS, UUID_LS, LRP, LR, UUID_LR, UUID_LR_CHASSIS, State) & (State != 0) & match.reg_dst(LSP[LSP_PORTID], Match) & # load next LR's ID to reg6, next stage's flow will move reg6 --> DP # load next LR's port to reg7, next stage's flow will move reg7 # --> REG_SRC_IDX action.load(LR[LR_ID], NXM_Reg(REG6_IDX), Action1) & action.load(LRP[LRP_PORTID], NXM_Reg(REG7_IDX), Action2) & action.resubmit_next(Action3) & (Action == Action1 + Action2 + Action3)) # if above flows are not hit, then it means the destination is not # on this host and this packet must be a redirect packet. We should # send it to lsp_lookup_dst_port, then lsp_output_dst_port will use # output action to output packet later. # And we decrease ttl the packet.(we assume all packet comes in lsp # egress should be IP packet). lsp_forward_packet(LS, Priority, Match, Action, State) <= ( (Priority == 0) & ls_array(LS, UUID_LS, State) & (State != 0) & match.ip_proto(Match) & # we set REDIRECT bit again, just try to avoid infinite loop action.load( 1, NXM_Reg(REG_FLAG_IDX, FLAG_REDIRECT_BIT_IDX, FLAG_REDIRECT_BIT_IDX), Action1) & action.resubmit_table(TABLE_LSP_INGRESS_LOOKUP_DST_PORT, Action2) & (Action == Action1 + Action2)) # if above flows are not hit, then it means the destination is not # on this host and this packet must be a redirect packet. We should # convert this arp request into arp response and send it back to # tunnel port which it comes from lsp_forward_packet(LS, Priority, Match, Action, State) <= ( (Priority == 0) & ls_array(LS, UUID_LS, State) & (State != 0) & match.arp_proto(Match1) & match.arp_op(1, Match2) & (Match == Match1 + Match2) & # set REDIRECT bit again to avoid infinite loop action.load( 1, NXM_Reg(REG_FLAG_IDX, FLAG_REDIRECT_BIT_IDX, FLAG_REDIRECT_BIT_IDX), Action1) & action.resubmit_table(TABLE_ARP_FEEDBACK_CONSTRUCT, Action2) & action.resubmit_table(TABLE_LSP_INGRESS_LOOKUP_DST_PORT, Action3) & (Action == Action1 + Action2 + Action3)) lsp_pushout_packet(LS, Priority, Match, Action, State) <= ( (Priority == 2) & ls_array(LS, UUID_LS, State) & (State != 0) & match.reg_5(1, Match) & action.resubmit_table(TABLE_OUTPUT_PKT, Action)) lsp_pushout_packet(LS, Priority, Match, Action, State) <= ( (Priority == 1) & ls_array(LS, UUID_LS, State) & (State != 0) & match.match_none(Match) & action.move( NXM_Reg(REG6_IDX, 0, 23), NXM_Reg(REG_DP_IDX, 0, 23), Action1) & action.move(NXM_Reg(REG7_IDX), NXM_Reg(REG_SRC_IDX), Action2) & # set reg6 back to 0 action.load(0, NXM_Reg(REG6_IDX), Action3) & action.load(0, NXM_Reg(REG7_IDX), Action4) & action.resubmit_table(TABLE_LRP_TRACE_INGRESS_IN, Action5) & (Action == Action1 + Action2 + Action3 + Action4 + Action5))