parameters: (cmds)
return_statement: return generated
docstring: Generates the actual control plane commands.
      This function inserts C code for all the "add" commands that have
      been parsed.
docstring_summary: Generates the actual control plane commands.
      This function inserts C code for all the "add" commands that have
      been parsed.
docstring_tokens: Generates the actual control plane commands . This function inserts C code for all the add commands that have been parsed .
function: def _generate_control_actions(cmds):
      """ Generates the actual control plane commands.
      This function inserts C code for all the "add" commands that have
      been parsed. """
      generated = ""
      for index, cmd in enumerate(cmds):
          key_name = "key_%s%d" % (cmd.table, index)
          value_name = "value_%s%d" % (cmd.table, index)
          if cmd.a_type == "setdefault":
              tbl_name = cmd.table + "_defaultAction"
              generated += "u32 %s = 0;\n\t" % (key_name)
          else:
              generated += "struct %s_key %s = {};\n\t" % (cmd.table, key_name)
              tbl_name = cmd.table
              for key_num, key_field in enumerate(cmd.match):
                  field = key_field[0].split('.')[1]
                  generated += ("%s.%s = %s;\n\t"
                                % (key_name, field, key_field[1]))
          generated += ("tableFileDescriptor = "
                        "BPF_OBJ_GET(MAP_PATH \"/%s\");\n\t" %
                        tbl_name)
          generated += ("if (tableFileDescriptor < 0) {"
                        "fprintf(stderr, \"map %s not loaded\");"
                        " exit(1); }\n\t" % tbl_name)
          generated += ("struct %s_value %s = {\n\t\t" % (
              cmd.table, value_name))
          generated += ".action = %s,\n\t\t" % (cmd.action[0])
          generated += ".u = {.%s = {" % cmd.action[0]
          for val_num, val_field in enumerate(cmd.action[1]):
              generated += "%s," % val_field[1]
          generated += "}},\n\t"
          generated += "};\n\t"
          generated += ("ok = BPF_USER_MAP_UPDATE_ELEM"
                        "(tableFileDescriptor, &%s, &%s, BPF_ANY);\n\t"
                        % (key_name, value_name))
          generated += ("if (ok != 0) { perror(\"Could not write in %s\");"
                        "exit(1); }\n" % tbl_name)
      return generated
function_tokens: def _generate_control_actions ( cmds ) : generated = "" for index , cmd in enumerate ( cmds ) : key_name = "key_%s%d" % ( cmd . table , index ) value_name = "value_%s%d" % ( cmd . table , index ) if cmd . a_type == "setdefault" : tbl_name = cmd . table + "_defaultAction" generated += "u32 %s = 0;\n\t" % ( key_name ) else : generated += "struct %s_key %s = {};\n\t" % ( cmd . table , key_name ) tbl_name = cmd . table for key_num , key_field in enumerate ( cmd . match ) : field = key_field [ 0 ] . split ( '.' ) [ 1 ] generated += ( "%s.%s = %s;\n\t" % ( key_name , field , key_field [ 1 ] ) ) generated += ( "tableFileDescriptor = " "BPF_OBJ_GET(MAP_PATH \"/%s\");\n\t" % tbl_name ) generated += ( "if (tableFileDescriptor < 0) {" "fprintf(stderr, \"map %s not loaded\");" " exit(1); }\n\t" % tbl_name ) generated += ( "struct %s_value %s = {\n\t\t" % ( cmd . table , value_name ) ) generated += ".action = %s,\n\t\t" % ( cmd . action [ 0 ] ) generated += ".u = {.%s = {" % cmd . action [ 0 ] for val_num , val_field in enumerate ( cmd . action [ 1 ] ) : generated += "%s," % val_field [ 1 ] generated += "}},\n\t" generated += "};\n\t" generated += ( "ok = BPF_USER_MAP_UPDATE_ELEM" "(tableFileDescriptor, &%s, &%s, BPF_ANY);\n\t" % ( key_name , value_name ) ) generated += ( "if (ok != 0) { perror(\"Could not write in %s\");" "exit(1); }\n" % tbl_name ) return generated