def p_statement_retrieve(p): "logical_statement : RETRIEVE LPAREN identifier COMMA layer_field_pair COMMA identifier RPAREN" if p[3] != "original": packet_check(p[3], p.lineno(1)) # Check if the variable is reserved if p[7] in reserved_name: print_error("Error: '" + p[7] + "' is a reserved name", str(p.lineno(1)) ) # Check if the variable has been previously declared if p[7] not in symbol_table.keys(): print_error("Error: '" + p[7] + "' undefined variable identifier", str(p.lineno(1)) ) # Check if the name has been previously used to declare a packet if p[7] in symbol_table.keys() and symbol_table[p[7]] != "VAR": print_error("Error: ID overloading is not allowed", str(p.lineno(1)) ) # Check if the layer name is valid if check_layer_name(p[5]) == False: print_error("Error: layer name unknown, you can use only: APP or NET or MAC", str(p.lineno(1))) args = str(p[3]) + ":" + str(p[5]) + ":" + str(p[7]) action = Retrieve(args) actions.append(action)
def p_statement_retrieve(p): "logical_statement : RETRIEVE LPAREN identifier COMMA layer_field_pair COMMA identifier RPAREN" if p[3] != "original": packet_check(p[3], p.lineno(1)) # Check if the variable is reserved if p[7] in reserved_name: print_error("Error: '" + p[7] + "' is a reserved name", str(p.lineno(1)) ) # Check if the variable has been previously declared if p[7] not in symbol_table.keys(): print_error("Error: '" + p[7] + "' undefined variable identifier", str(p.lineno(1)) ) # Check if the name has been previously used to declare a packet if p[7] in symbol_table.keys() and symbol_table[p[7]] != "VAR": print_error("Error: ID overloading is not allowed", str(p.lineno(1)) ) # Check if the layer name is valid if check_layer_name(p[5]) == False: print_error("Error: layer name unknown, you can use only: APP or NET or MAC", str(p.lineno(1))) # Check coerency of layer_field structure "layer.field1.field2.field3 ..." layer_field = str(p[5]) id_counter = 0 while len(layer_field) != 0: # search identifier in the string head try: substring_found = re.search('^[a-zA-Z_][a-zA-Z_0-9]*', layer_field).group(0) id_counter += 1 except AttributeError: print_error("Error: layer.field attribute in retrieve action has a bad structure, id missing", str(p.lineno(1))) # remove substring found layer_field = layer_field.replace(substring_found, "", 1) if len(layer_field) == 0: break; # search '.' in the string head try: substring_found = re.search('^\.', layer_field).group(0) except AttributeError: print_error("Error: layer.field attribute in retrieve action has a bad structure, '.' missing", str(p.lineno(1))) layer_field = layer_field.replace(substring_found, "", 1) if len(layer_field) == 0: print_error("Error: layer.field attribute in retrieve action has a bad structure, id missing", str(p.lineno(1))) if id_counter < 2: print_error("Error: layer.field attribute in retrieve action has a bad structure, field missing", str(p.lineno(1))) # Coerency test passed, build the object args = str(p[3]) + ":" + str(p[5]) + ":" + str(p[7]) action = Retrieve(args) actions.append(action)
def p_statement_create(p): "logical_statement : CREATE LPAREN identifier COMMA create_list RPAREN" packet_check(p[3], p.lineno(1)) args = str(p[3]) + ":" + str(p[5]) action = Create(args) actions.append(action)
def p_statement_send(p): "logical_statement : SEND LPAREN identifier COMMA unsigned_real RPAREN" if p[3] != "original": packet_check(p[3], p.lineno(1)) args = str(p[3]) + ":" + str(p[5]) action = Send(args) actions.append(action)
def p_statement_drop(p): "logical_statement : DROP LPAREN identifier COMMA threshold RPAREN" if p[3] != "original": packet_check(p[3], p.lineno(1)) args = str(p[3]) + ":" + str(p[5]) action = Drop(args) actions.append(action)
def p_statement_retrieve(p): "logical_statement : RETRIEVE LPAREN identifier COMMA layer_field_pair COMMA identifier RPAREN" if p[3] != "original": packet_check(p[3], p.lineno(1)) # Check if the variable is reserved if p[7] in reserved_name: print_error("Error: '" + p[7] + "' is a reserved name", str(p.lineno(1)) ) # Check if the variable has been previously declared if p[7] not in symbol_table.keys(): print_error("Error: '" + p[7] + "' undefined variable identifier", str(p.lineno(1)) ) # Check if the name has been previously used to declare a packet if p[7] in symbol_table.keys() and symbol_table[p[7]] != "VAR": print_error("Error: ID overloading is not allowed", str(p.lineno(1)) ) # Check if the layer name is valid if check_layer_name(p[5]) == False and check_control_structure_name(p[5]) == False: print_error("Error: layer name unknown, you can use only: APP or TRA or NET or MAC or controlInfo", str(p.lineno(1))) # Check coerency of layer_field structure "layer.field1.field2.field3 ..." layer_field = str(p[5]) id_counter = 0 while len(layer_field) != 0: # search identifier in the string head try: substring_found = re.search('^[a-zA-Z_][a-zA-Z_0-9]*', layer_field).group(0) id_counter += 1 except AttributeError: print_error("Error: layer.field attribute in retrieve action has a bad structure, id missing", str(p.lineno(1))) # remove substring found layer_field = layer_field.replace(substring_found, "", 1) if len(layer_field) == 0: break; # search '.' in the string head try: substring_found = re.search('^\.', layer_field).group(0) except AttributeError: print_error("Error: layer.field attribute in retrieve action has a bad structure, '.' missing", str(p.lineno(1))) layer_field = layer_field.replace(substring_found, "", 1) if len(layer_field) == 0: print_error("Error: layer.field attribute in retrieve action has a bad structure, id missing", str(p.lineno(1))) if id_counter < 2: print_error("Error: layer.field attribute in retrieve action has a bad structure, field missing", str(p.lineno(1))) # Coerency test passed, build the object args = str(p[3]) + ":" + str(p[5]) + ":" + str(p[7]) action = Retrieve(args) actions.append(action)
def p_statement_clone(p): "logical_statement : CLONE LPAREN identifier COMMA identifier RPAREN" if p[3] != "original": packet_check(p[3], p.lineno(1)) packet_check(p[5], p.lineno(1)) args = str(p[3]) + ":" + str(p[5]) action = Clone(args) actions.append(action)
def p_statement_put(p): "logical_statement : PUT LPAREN identifier COMMA identifier COMMA direction COMMA boolean COMMA unsigned_real RPAREN" if p[3] != "original": packet_check(p[3], p.lineno(1)) # Check if the list has been already declared if p[5] not in lists.keys(): print_error("Error: list '" + p[5] + "' is not declared", str(p.lineno(1)) ) # Replace the second argument with the list content p[5] = str(lists[str(p[5])]) args = str(p[3]) + ":" + str(p[5]) + ":" + str(p[7]) + ":" + str(p[9]) + ":" + str(p[11]) action = Put(args) actions.append(action)
def p_statement_change(p): "logical_statement : CHANGE LPAREN identifier COMMA layer_field_pair COMMA multi_type RPAREN" # Check the third argument if p[3] != "original": packet_check(p[3], p.lineno(1)) # p[7] is multi_type (NUMBER, STRING, ID) if p[7] not in reserved_name and p[7] not in symbol_table.keys(): re_pattern = r"^-?\d+(\.\d+)?" pattern = re.compile(re_pattern) # Add an entry in the variable table if STRING is not present in it if p[7][0] == "\"" and p[7][-1] == "\"": symbol_table[p[7]] = "VAR" variables[p[7]] = "<value>" + p[7][1:-1] + "</value><type>STRING</type>" # Add an entry in the variable table if NUMBER is not present in it elif re.match(pattern, p[7]): symbol_table[p[7]] = "VAR" variables[p[7]] = "<value>" + p[7] + "</value><type>NUMBER</type>" # Return error if the ID is not declared else: print_error("Error: '" + p[7] + "' undefined variable identifier", str(p.lineno(1)) ) # Check if the variable is initialized if p[7] not in reserved_name: value = variables[p[7]][7] # Variable not initialized if its first char is '<' if value == "<": print_error("Error: variable '" + p[7] + "' must be initialized", str(p.lineno(1)) ) # Check layer name if check_layer_name(p[5]) == False: print_error("Error: layer name unknown, you can use only: APP or NET or MAC", str(p.lineno(1))) args = str(p[3]) + ":" + str(p[5]) + ":" + str(p[7]) action = Change(args) actions.append(action)
def p_statement_change(p): "logical_statement : CHANGE LPAREN identifier COMMA layer_field_pair COMMA multi_type RPAREN" # Check the third argument if p[3] != "original": packet_check(p[3], p.lineno(1)) # p[7] is multi_type (NUMBER, STRING, ID) if p[7] not in reserved_name and p[7] not in symbol_table.keys(): re_pattern = r"^-?\d+(\.\d+)?" pattern = re.compile(re_pattern) # Add an entry in the variable table if STRING is not present in it if p[7][0] == "\"" and p[7][-1] == "\"": symbol_table[p[7]] = "VAR" variables[p[7]] = "<value>" + p[7][1:-1] + "</value><type>STRING</type>" # Add an entry in the variable table if NUMBER is not present in it elif re.match(pattern, p[7]): symbol_table[p[7]] = "VAR" variables[p[7]] = "<value>" + p[7] + "</value><type>NUMBER</type>" # Return error if the ID is not declared else: print_error("Error: '" + p[7] + "' undefined variable identifier", str(p.lineno(1)) ) # Check if the variable is initialized if p[7] not in reserved_name: value = variables[p[7]][7] # Variable not initialized if its first char is '<' if value == "<": print_error("Error: variable '" + p[7] + "' must be initialized", str(p.lineno(1)) ) # Check layer name if check_layer_name(p[5]) == False: print_error("Error: layer name unknown, you can use only: APP or NET or MAC", str(p.lineno(1))) # Check coerency of layer_field structure "layer.field1.field2.field3 ..." layer_field = str(p[5]) id_counter = 0 while len(layer_field) != 0: # search identifier in the string head try: substring_found = re.search('^[a-zA-Z_][a-zA-Z_0-9]*', layer_field).group(0) id_counter += 1 except AttributeError: print_error("Error: layer.field attribute in change action has a bad structure, id missing", str(p.lineno(1))) # remove substring found layer_field = layer_field.replace(substring_found, "", 1) if len(layer_field) == 0: break; # search '.' in the string head try: substring_found = re.search('^\.', layer_field).group(0) except AttributeError: print_error("Error: layer.field attribute in change action has a bad structure, '.' missing", str(p.lineno(1))) layer_field = layer_field.replace(substring_found, "", 1) if len(layer_field) == 0: print_error("Error: layer.field attribute in change action has a bad structure, id missing", str(p.lineno(1))) if id_counter < 2: print_error("Error: layer.field attribute in change action has a bad structure, field missing", str(p.lineno(1))) # Coerency test passed, build the object args = str(p[3]) + ":" + str(p[5]) + ":" + str(p[7]) action = Change(args) actions.append(action)
def p_statement_change(p): "logical_statement : CHANGE LPAREN identifier COMMA layer_field_pair COMMA multi_type RPAREN" # Check the third argument if p[3] != "original": packet_check(p[3], p.lineno(1)) # p[7] is multi_type (NUMBER, STRING, ID) if p[7] not in reserved_name and p[7] not in symbol_table.keys(): re_pattern = r"^-?\d+(\.\d+)?" pattern = re.compile(re_pattern) # Add an entry in the variable table if STRING is not present in it if p[7][0] == "\"" and p[7][-1] == "\"": symbol_table[p[7]] = "VAR" variables[ p[7]] = "<value>" + p[7][1:-1] + "</value><type>STRING</type>" # Add an entry in the variable table if NUMBER is not present in it elif re.match(pattern, p[7]): symbol_table[p[7]] = "VAR" variables[p[7]] = "<value>" + p[7] + "</value><type>NUMBER</type>" # Return error if the ID is not declared else: print_error("Error: '" + p[7] + "' undefined variable identifier", str(p.lineno(1))) # Check if the variable is initialized if p[7] not in reserved_name: value = variables[p[7]][7] # Variable not initialized if its first char is '<' if value == "<": print_error("Error: variable '" + p[7] + "' must be initialized", str(p.lineno(1))) # Check layer name if check_layer_name(p[5]) == False: print_error( "Error: layer name unknown, you can use only: APP or NET or MAC", str(p.lineno(1))) # Check coerency of layer_field structure "layer.field1.field2.field3 ..." layer_field = str(p[5]) id_counter = 0 while len(layer_field) != 0: # search identifier in the string head try: substring_found = re.search('^[a-zA-Z_][a-zA-Z_0-9]*', layer_field).group(0) id_counter += 1 except AttributeError: print_error( "Error: layer.field attribute in change action has a bad structure, id missing", str(p.lineno(1))) # remove substring found layer_field = layer_field.replace(substring_found, "", 1) if len(layer_field) == 0: break # search '.' in the string head try: substring_found = re.search('^\.', layer_field).group(0) except AttributeError: print_error( "Error: layer.field attribute in change action has a bad structure, '.' missing", str(p.lineno(1))) layer_field = layer_field.replace(substring_found, "", 1) if len(layer_field) == 0: print_error( "Error: layer.field attribute in change action has a bad structure, id missing", str(p.lineno(1))) if id_counter < 2: print_error( "Error: layer.field attribute in change action has a bad structure, field missing", str(p.lineno(1))) # Coerency test passed, build the object args = str(p[3]) + ":" + str(p[5]) + ":" + str(p[7]) action = Change(args) actions.append(action)